<!-- eslint-disable vue/prop-name-casing -->
<script>
import { FieldsPanel } from '@yootheme/sidebar';

export default {
    name: 'BuilderPanel',

    extends: FieldsPanel,

    provide() {
        return {
            $node: this.node,
            Builder: this.builder,
        };
    },

    props: {
        node: Object,
        builder: Object,
    },

    created() {
        if (this.node.type === 'row') {
            // update column widths from row 'layout' preset
            this.$on('change', (value, { name }) => {
                if (name === 'layout') {
                    this.$nextTick(() => this.builder.columnWidths(this.node, value));
                }
            });
        }
    },

    events: {
        'yooessentials-prerequest'(e) {
            e.params[0]['node'] = this.node;
            e.params[0]['form'] = this.values;
        },

        removeNode(e, node) {
            if (node === this.node) {
                this.$trigger('closeSidebarPanel', this.panel);
            }
        },

        resetNode() {
            this.$trigger('closeSidebarPanel', this.panel);
        },
    },
};
</script>
