import { defineVxeComponent } from '../../ui/src/comp';
import { globalMixins, createEvent } from '../../ui';
import { assembleSplitterItem, destroySplitterItem } from './util';
import XEUtils from 'xe-utils';
export default {
    name: 'VxeSplitterPanel',
    mixins: [
        globalMixins.sizeMixin
    ],
    props: {
        name: [Number, String],
        width: [Number, String],
        height: [Number, String],
        minWidth: {
            type: [Number, String],
            default: () => null
        },
        minHeight: {
            type: [Number, String],
            default: () => null
        },
        // 已废弃
        showAction: Boolean
    },
    inject: {
        $xeSplitter: {
            default: null
        }
    },
    provide() {
        const $xeSplitterItem = this;
        return {
            $xeSplitterItem
        };
    },
    data() {
        const xID = XEUtils.uniqueId();
        const reactData = {};
        const paneConfig = {
            id: xID,
            name: '',
            width: 0,
            height: 0,
            minWidth: 0,
            minHeight: 0,
            showAction: false,
            isExpand: true,
            renderWidth: 0,
            resizeWidth: 0,
            foldWidth: 0,
            renderHeight: 0,
            resizeHeight: 0,
            foldHeight: 0,
            slots: {}
        };
        return {
            xID,
            reactData,
            paneConfig
        };
    },
    computed: Object.assign({}, {}),
    watch: {
        name(val) {
            const $xeSplitterItem = this;
            const paneConfig = $xeSplitterItem.paneConfig;
            paneConfig.name = val;
        },
        width(val) {
            const $xeSplitterItem = this;
            const paneConfig = $xeSplitterItem.paneConfig;
            paneConfig.width = val;
        },
        height(val) {
            const $xeSplitterItem = this;
            const paneConfig = $xeSplitterItem.paneConfig;
            paneConfig.height = val;
        },
        minWidth(val) {
            const $xeSplitterItem = this;
            const paneConfig = $xeSplitterItem.paneConfig;
            paneConfig.minWidth = val;
        },
        minHeight(val) {
            const $xeSplitterItem = this;
            const paneConfig = $xeSplitterItem.paneConfig;
            paneConfig.minHeight = val;
        },
        showAction(val) {
            const $xeSplitterItem = this;
            const paneConfig = $xeSplitterItem.paneConfig;
            paneConfig.showAction = val;
        }
    },
    methods: {
        //
        // Method
        //
        dispatchEvent(type, params, evnt) {
            const $xeSplitterItem = this;
            $xeSplitterItem.$emit(type, createEvent(evnt, { $splitterPanel: $xeSplitterItem }, params));
        },
        //
        // Render
        //
        renderVN(h) {
            return h('div', {
                ref: 'refElem'
            });
        }
    },
    created() {
        const $xeSplitterItem = this;
        const props = $xeSplitterItem;
        const slots = $xeSplitterItem.$scopedSlots;
        const paneConfig = $xeSplitterItem.paneConfig;
        Object.assign(paneConfig, {
            name: props.name,
            width: props.width,
            height: props.height,
            minWidth: props.minWidth,
            minHeight: props.minHeight,
            showAction: props.showAction,
            slots
        });
    },
    mounted() {
        const $xeSplitterItem = this;
        const slots = $xeSplitterItem.$scopedSlots;
        const paneConfig = $xeSplitterItem.paneConfig;
        const $xeSplitter = $xeSplitterItem.$xeSplitter;
        paneConfig.slots = slots;
        const elem = $xeSplitterItem.$refs.refElem;
        if ($xeSplitter && elem) {
            assembleSplitterItem($xeSplitter, elem, paneConfig);
        }
    },
    beforeDestroy() {
        const $xeSplitterItem = this;
        const paneConfig = $xeSplitterItem.paneConfig;
        const $xeSplitter = $xeSplitterItem.$xeSplitter;
        if ($xeSplitter) {
            destroySplitterItem($xeSplitter, paneConfig);
        }
    },
    render(h) {
        return this.renderVN(h);
    }
};
