import { __decorate } from "tslib";
import { AbsoluteLayoutList } from '@ibizstudio/absolute-layout-design';
import { VueLifeCycleProcessing } from '@ibizstudio/dynamic-design';
import { Component, Prop } from 'vue-property-decorator';
let AbsoluteLayoutPanelListItem = class AbsoluteLayoutPanelListItem extends AbsoluteLayoutList {
    /**
     * 获取可创建的项
     *
     * @memberof AbsoluteLayoutPanelItem
     */
    async componentCreated() {
        this.loaded = this.loaded.bind(this);
        this.ctx.ctrl.evt.on('loaded', this.loaded);
        this.ctx.ctrl.itemCtrl.evt.on('added', this.loaded);
    }
    async componentBeforeDestroy() {
        this.ctx.ctrl.evt.off('loaded', this.loaded);
        this.ctx.ctrl.itemCtrl.evt.off('added', this.loaded);
    }
    /**
     * 列表项加载事件
     *
     * @memberof AbsoluteLayoutPanelListItem
     */
    async loaded() {
        const { ctrl } = this.ctx;
        const arr = [];
        let items = await ctrl.itemCtrl.selectPanelItems();
        if (items && items.length > 0) {
            items = items.sort((a, b) => b.srfordervalue - a.srfordervalue);
            arr.push(...items);
            this.items = arr;
            this.$forceUpdate();
        }
    }
    /**
     * 列表项拖拽完成事件
     *
     * @memberof AbsoluteLayoutPanelListItem
     */
    async onDragEnd() {
        for (let i = 0; i < this.items.length; i++) {
            const { ctrl, context } = this.ctx;
            this.items[i].srfordervalue = 100 * (this.items.length - i);
            const res = await ctrl.itemCtrl.s.UpdateTemp(context, this.items[i]);
            if (res.ok) {
                const data = res.data;
                const cell = ctrl.graph.getCellById(data.srfkey);
                cell.setZIndex(data.srfordervalue);
            }
        }
    }
};
__decorate([
    Prop()
], AbsoluteLayoutPanelListItem.prototype, "ctx", void 0);
AbsoluteLayoutPanelListItem = __decorate([
    Component,
    VueLifeCycleProcessing()
], AbsoluteLayoutPanelListItem);
export { AbsoluteLayoutPanelListItem };
