/* Essentials YOOtheme Pro 2.2.16 build 0813.1608; ZOOlanders https://www.zoolanders.com; Copyright (C) Joolanders, SL; http://www.gnu.org/licenses/gpl.html GNU/GPL */

import './extend';
import './source';

import Vue from 'vue';
import hooks from '@yootheme/hooks';
import essentials from './api';

import * as models from './models';
import * as source from './source';
import * as panels from './panels';
import * as components from './components';

essentials.source = source;

Object.assign(essentials.models, {
    EssentialsLogs: models.LogsModel,
    EssentialsConfig: models.ConfigModel,
    EssentialsCondition: models.ConditionModel,
});

Object.assign(essentials.panels, panels);
Object.assign(essentials.components, components);

Vue.component('yooessentials', panels.EssentialsPanel);
Vue.component('yooessentials-about', panels.AboutPanel);
Vue.component('yooessentials-advanced', panels.AdvancedPanel);

export default essentials;

hooks.before('app.init', ({ extend }) => {
    extend({
        models: essentials.models,
        events: {
            openAdjacentPanel(e, panel) {
                if (essentials.Builder) {
                    essentials.Builder.adjacentOf = panel.adjacentOf;
                }

                this.$trigger('openDynamicPanel', panel);
            },

            openDynamicPanel(e, panel) {
                this.$trigger('openPanel', {
                    name: panel.title,
                    ...panel,
                    component: source.DynamicPanel,
                    props: {
                        builder: essentials.Builder,
                        ...(panel.props || {}),
                    },
                });
            },
        },
    });
});
