import { MDControlBase } from "./md-control-base";
import { AppViewLogicService } from '../app-service/logic-service/app-viewlogic-service';
import { ViewTool, Verify, PanelButtonModel, PanelTabPanelModel, PanelTabPageModel, PanelContainerModel, PanelFieldModel, PanelRawitemModel, PanelControlModel, PanelUserControlModel, LogUtil, Util } from '@ibizstudio/runtime';
import { GlobalService } from '@ibizstudio/runtime';
/**
 * 面板部件基类
 *
 * @export
 * @class PanelControlBase
 * @extends {MDControlBase}
 */
export class PanelControlBase extends MDControlBase {
    constructor() {
        super(...arguments);
        /**
         * 值规则对象
         *
         * @type {*}
         * @memberof PanelControlBase
         */
        this.rules = {};
        /**
         * 数据
         *
         * @type {*}
         * @memberof PanelControlBase
         */
        this.data = {};
        /**
         * 详情模型集合
         *
         * @type {*}
         * @memberof PanelControlBase
         */
        this.detailsModel = {};
        /**
         * 面板成员动态逻辑集合
         *
         * @memberof PanelControlBase
         */
        this.allPanelItemGroupLogic = [];
        /**
         * 是否需要查找属性
         *
         * @type {boolean}
         * @memberof PanelControlBase
         */
        this.needFindDEField = false;
        /**
         * 父容器数据项
         *
         * @type {any[]}
         * @memberof PanelControlBase
         */
        this.parentDataItems = [];
        /**
         * 打开编辑数据视图
         *
         * @param {any[]} args
         * @param {any[]} [fullargs]
         * @param {*} [params]
         * @param {*} [$event]
         * @param {*} [xData]
         * @memberof PanelControlBase
         */
        this.opendata = (args, fullargs, params, $event, xData) => {
            this.$throw(this.$t('app.warn.unopendata'), 'opendata');
        };
        /**
         * 打开新建数据视图
         *
         * @param {any[]} args
         * @param {any[]} [fullargs]
         * @param {*} [params]
         * @param {*} [$event]
         * @param {*} [xData]
         * @memberof PanelControlBase
         */
        this.newdata = (args, fullargs, params, $event, xData) => {
            this.$throw(this.$t('app.warn.unnewdata'), 'newdata');
        };
    }
    /**
     * 监听部件动态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof PanelControlBase
     */
    onDynamicPropsChange(newVal, oldVal) {
        var _a, _b;
        super.onDynamicPropsChange(newVal, oldVal);
        if (this.controlIsLoaded && ((_a = newVal === null || newVal === void 0 ? void 0 : newVal.navdatas) === null || _a === void 0 ? void 0 : _a[0]) != ((_b = oldVal === null || oldVal === void 0 ? void 0 : oldVal.navdatas) === null || _b === void 0 ? void 0 : _b[0])) {
            this.computedUIData();
        }
    }
    /**
     * 监听部件动态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof PanelControlBase
     */
    onStaticPropsChange(newVal, oldVal) {
        super.onStaticPropsChange(newVal, oldVal);
        this.transformData = (newVal === null || newVal === void 0 ? void 0 : newVal.transformData) || this.transformData;
        this.opendata = (newVal === null || newVal === void 0 ? void 0 : newVal.opendata) || this.opendata;
        this.newdata = (newVal === null || newVal === void 0 ? void 0 : newVal.newdata) || this.newdata;
        this.remove = (newVal === null || newVal === void 0 ? void 0 : newVal.remove) || this.remove;
        this.refresh = (newVal === null || newVal === void 0 ? void 0 : newVal.refresh) || this.refresh;
        this.dataMap = newVal === null || newVal === void 0 ? void 0 : newVal.dataMap;
        // 初始化面板详情模型集合
        this.detailsModel = {};
        this.allPanelItemGroupLogic = [];
        this.initDetailsModel(this.controlInstance.getRootPSPanelItems());
    }
    /**
     * 部件模型初始化
     *
     * @param {*} [args]
     * @memberof PanelControlBase
     */
    async ctrlModelInit(args) {
        var _a;
        await super.ctrlModelInit(args);
        if (((_a = this.controlInstance.getRootPSPanelItems()) === null || _a === void 0 ? void 0 : _a.length) > 0) {
            this.initRules(this.controlInstance.getRootPSPanelItems());
        }
        this.computedUIData();
        this.computeButtonState(this.data);
        this.panelLogic({ name: '', newVal: null, oldVal: null });
        this.computeParentDataItems();
    }
    /**
     * 初始化值规则
     *
     * @param {(IPSPanelItem[] | null)} panelItems 面板项
     * @memberof PanelControlBase
     */
    initRules(panelItems) {
        // 初始化非空值规则和数据类型值规则
        panelItems === null || panelItems === void 0 ? void 0 : panelItems.forEach((item) => {
            var _a, _b, _c;
            const panelItem = item;
            if (((_b = (_a = panelItem === null || panelItem === void 0 ? void 0 : panelItem.getPSPanelItems) === null || _a === void 0 ? void 0 : _a.call(panelItem)) === null || _b === void 0 ? void 0 : _b.length) > 0) {
                this.initRules(panelItem.getPSPanelItems());
            }
            else {
                const panelItem = item;
                if ((_c = panelItem === null || panelItem === void 0 ? void 0 : panelItem.getPSEditor) === null || _c === void 0 ? void 0 : _c.call(panelItem)) {
                    let editorRules = Verify.buildVerConditions(panelItem.getPSEditor());
                    this.rules[panelItem.name] = [
                        // 非空值规则
                        { validator: (rule, value, callback) => { return !(this.detailsModel[panelItem.name].required && !value); }, message: `${panelItem.caption} 必须填写` },
                        // 编辑器基础值规则
                        ...editorRules
                    ];
                }
            }
        });
    }
    /**
     * 面板部件初始化
     *
     * @memberof MDControlBase
     */
    ctrlInit() {
        super.ctrlInit();
        // 面板不需要应用全局刷新
        if (this.appStateEvent) {
            this.appStateEvent.unsubscribe();
        }
    }
    /**
     * 初始化表单成员模型
     *
     * @param {(IPSPanelItem[] | null)} panelItems 面板项
     * @memberof PanelControlBase
     */
    initDetailsModel(panelItems) {
        if (panelItems && (panelItems === null || panelItems === void 0 ? void 0 : panelItems.length) > 0) {
            panelItems === null || panelItems === void 0 ? void 0 : panelItems.forEach((panelItem) => {
                var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
                let detailModel = {
                    panel: this,
                    disabled: false,
                    name: panelItem.name,
                    caption: panelItem.caption,
                    itemType: panelItem.itemType,
                    visible: true,
                };
                let model;
                switch (panelItem.itemType) {
                    case 'BUTTON':
                        const panelButtomItem = panelItem;
                        Object.assign(detailModel, {
                            uiaction: {
                                type: (_a = panelButtomItem.getPSUIAction()) === null || _a === void 0 ? void 0 : _a.uIActionType,
                                tag: (_b = panelButtomItem.getPSUIAction()) === null || _b === void 0 ? void 0 : _b.uIActionTag,
                                actiontarget: (_c = panelButtomItem.getPSUIAction()) === null || _c === void 0 ? void 0 : _c.actionTarget,
                                noprivdisplaymode: (_d = panelButtomItem.getPSUIAction()) === null || _d === void 0 ? void 0 : _d.uIActionMode,
                                dataaccaction: (_e = panelButtomItem.getPSUIAction()) === null || _e === void 0 ? void 0 : _e.dataAccessAction,
                                visible: true,
                                disabled: false
                            }
                        });
                        model = new PanelButtonModel(detailModel);
                        break;
                    case 'TABPANEL':
                        const tabPages = panelItem.getPSPanelTabPages() || [];
                        const pageNames = [];
                        if (tabPages.length > 0) {
                            tabPages.forEach((page) => {
                                pageNames.push({ name: page.name });
                            });
                        }
                        Object.assign(detailModel, {
                            tabPages: pageNames
                        });
                        model = new PanelTabPanelModel(detailModel);
                        break;
                    case 'TABPAGE':
                        model = new PanelTabPageModel(detailModel);
                        break;
                    case 'CONTAINER':
                        model = new PanelContainerModel(detailModel);
                        break;
                    case 'FIELD':
                        model = new PanelFieldModel(detailModel);
                        break;
                    case 'RAWITEM':
                        model = new PanelRawitemModel(detailModel);
                        break;
                    case 'CONTROL':
                        model = new PanelControlModel(detailModel);
                        break;
                    case 'USERCONTROL':
                        model = new PanelUserControlModel(detailModel);
                        break;
                }
                this.$set(this.detailsModel, panelItem.name, model);
                if (((_h = (_g = (_f = panelItem).getPSPanelItems) === null || _g === void 0 ? void 0 : _g.call(_f)) === null || _h === void 0 ? void 0 : _h.length) > 0) {
                    this.initDetailsModel((_j = panelItem === null || panelItem === void 0 ? void 0 : panelItem.getPSPanelItems) === null || _j === void 0 ? void 0 : _j.call(panelItem));
                }
                if (((_m = (_l = (_k = panelItem).getPSPanelTabPages) === null || _l === void 0 ? void 0 : _l.call(_k)) === null || _m === void 0 ? void 0 : _m.length) > 0) {
                    (_p = (_o = panelItem).getPSPanelTabPages) === null || _p === void 0 ? void 0 : _p.call(_o).forEach((tabpage) => {
                        var _a;
                        this.initDetailsModel(((_a = tabpage === null || tabpage === void 0 ? void 0 : tabpage.getPSPanelItems) === null || _a === void 0 ? void 0 : _a.call(tabpage)) || []);
                    });
                }
                if (panelItem.getPSPanelItemGroupLogics()) {
                    this.allPanelItemGroupLogic.push({ name: panelItem.name, panelItemGroupLogic: panelItem.getPSPanelItemGroupLogics() });
                }
            });
        }
    }
    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
     * @memberof PanelControlBase
     */
    async remove(datas) {
        this.$throw(this.$t('app.warn.unremove'), 'remove');
    }
    /**
     * 刷新
     *
     * @param {*} [args]
     * @memberof PanelControlBase
     */
    refresh(args) {
        this.$throw(this.$t('app.warn.unrefresh'), 'refresh');
    }
    /**
     * 设置面板编辑项值变更
     *
     * @param data 面板数据
     * @param {{ name: string, value: any }} $event
     * @returns {void}
     * @memberof PanelControlBase
     */
    onPanelItemValueChange(data, $event) {
        if (!$event) {
            return;
        }
        if (!$event.name || Object.is($event.name, '') || !data.hasOwnProperty($event.name)) {
            return;
        }
        data[$event.name] = $event.value;
        this.panelEditItemChange(data, $event.name, $event.value);
    }
    /**
     * 面板编辑项值变化
     *
     * @public
     * @param data 面板数据
     * @param property 编辑项名
     * @param value 编辑项值
     * @returns {void}
     * @memberof PanelControlBase
     */
    panelEditItemChange(data, property, value) {
        // 面板数据变化事件
        if (this.getDataItems().length > 0) {
            let modelitem = this.getDataItems().find((item) => {
                return item.name === property;
            });
            if (modelitem) {
                this.ctrlEvent({
                    controlname: this.controlInstance.controlType,
                    action: 'panelDataChange',
                    data: { [modelitem.prop]: value },
                });
            }
        }
    }
    /**
     * 分页切换事件
     *
     * @param {string} name 分页名
     * @param {*} $event 回调对象
     * @memberof PanelControlBase
     */
    handleTabPanelClick(name, $event) {
        var _a;
        (_a = this.detailsModel[name]) === null || _a === void 0 ? void 0 : _a.clickPage($event.name);
    }
    /**
     * 按钮点击事件
     *
     * @param {string} controlName 部件名称
     * @param {*} data 数据
     * @param {*} $event 事件源
     * @memberof PanelControlBase
     */
    buttonClick(controlName, data, $event) {
        AppViewLogicService.getInstance().executeViewLogic(`${controlName === null || controlName === void 0 ? void 0 : controlName.toLowerCase()}_${data.tag}_click`, $event, this, this.data, this.controlInstance.getPSAppViewLogics());
    }
    /**
     * 面板逻辑
     *
     * @public
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @memberof PanelControlBase
     */
    panelLogic({ name, newVal, oldVal }) {
        const allPanelItemGroupLogic = this.allPanelItemGroupLogic;
        if (allPanelItemGroupLogic.length > 0) {
            allPanelItemGroupLogic.forEach((panelItem) => {
                var _a;
                (_a = panelItem.panelItemGroupLogic) === null || _a === void 0 ? void 0 : _a.forEach((logic) => {
                    if (Object.is(name, '') || Object.is(name, panelItem.name)) {
                        let ret = this.verifyGroupLogic(this.data, logic);
                        switch (logic.logicCat) {
                            // 动态空输入，不满足则必填
                            case 'ITEMBLANK':
                                this.detailsModel[panelItem.name].required = !ret;
                                break;
                            // 动态启用，满足则启用
                            case 'ITEMENABLE':
                                this.detailsModel[panelItem.name].disabled = !ret;
                                break;
                            // 动态显示，满足则显示
                            case 'PANELVISIBLE':
                                this.detailsModel[panelItem.name].visible = ret;
                                break;
                        }
                    }
                });
            });
        }
    }
    /**
     * 校验动态逻辑结果
     *
     * @param {*} data 数据对象
     * @param {*} logic 逻辑对象
     * @returns
     * @memberof PanelControlBase
     */
    verifyGroupLogic(data, logic) {
        var _a, _b, _c;
        if (logic.logicType == 'GROUP' && ((_a = logic === null || logic === void 0 ? void 0 : logic.getPSPanelItemLogics()) === null || _a === void 0 ? void 0 : _a.length) > 0) {
            const _logic = logic;
            let result = true;
            if (_logic.groupOP == 'AND') {
                let falseItem = (_b = _logic === null || _logic === void 0 ? void 0 : _logic.getPSPanelItemLogics()) === null || _b === void 0 ? void 0 : _b.find((childLogic) => {
                    return !this.verifyGroupLogic(data, childLogic);
                });
                result = falseItem == undefined;
            }
            else if (_logic.groupOP == 'OR') {
                let trueItem = (_c = _logic === null || _logic === void 0 ? void 0 : _logic.getPSPanelItemLogics()) === null || _c === void 0 ? void 0 : _c.find((childLogic) => {
                    return this.verifyGroupLogic(data, childLogic);
                });
                result = trueItem != undefined;
            }
            // 是否取反
            return logic.notMode ? !result : result;
        }
        else if (logic.logicType == 'SINGLE') {
            const _logic = logic;
            return Verify.testCond(data[_logic.dstModelField.toLowerCase()], _logic.condOp, _logic.value);
        }
        return false;
    }
    /**
     * 计算UI展示数据
     *
     * @param {*} newVal
     * @memberof PanelControlBase
     */
    async computedUIData(newVal) {
        var _a;
        if (((_a = this.controlInstance) === null || _a === void 0 ? void 0 : _a.getAllPSPanelFields()) && this.getDataItems().length > 0) {
            this.getDataItems().forEach((item) => {
                this.$set(this.data, item.name, null);
            });
        }
        const dataMode = this.controlInstance.dataMode;
        if (dataMode === 3) {
            this.viewCtx.appGlobal[this.controlInstance.M.dataName] = this.data;
        }
        else if (dataMode === 4) {
            this.viewCtx.routeViewGlobal[this.controlInstance.M.dataName] = this.data;
        }
        else if (dataMode === 5) {
            this.viewCtx.viewGlobal[this.controlInstance.M.dataName] = this.data;
        }
        else {
            await this.computeLoadState(dataMode);
        }
    }
    /**
     * 计算数据加载模式
     *
     * @memberof PanelControlBase
     */
    async computeLoadState(dataMode) {
        if (dataMode === 0) {
            //  0：不获取，使用传入数据
            if (this.navdatas && (this.navdatas.length > 0)) {
                this.data = this.navdatas[0];
            }
        }
        else if (dataMode === 1) {
            //  1：存在传入数据时，不获取
            if (this.navdatas && this.navdatas.length > 0) {
                if (this.navdatas && (this.navdatas.length > 0)) {
                    this.data = this.navdatas[0];
                }
            }
            else {
                await this.loadPanelData();
            }
        }
        else if (dataMode === 2) {
            //  2：始终获取
            await this.loadPanelData();
        }
    }
    /**
     * 加载数据
     *
     * @memberof PanelControlBase
     */
    async loadPanelData() {
        var _a, _b, _c, _d, _e;
        const action = ((_e = (_d = (_c = (_b = (_a = this.controlInstance).getGetPSControlAction) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.getPSAppDEMethod) === null || _d === void 0 ? void 0 : _d.call(_c)) === null || _e === void 0 ? void 0 : _e.codeName) || '';
        if (!action) {
            LogUtil.warn(this.$t('app.viewpanel.nofconfig.getaction'));
        }
        const service = await new GlobalService().getService(this.appDeCodeName, this.context);
        if (service[action]) {
            try {
                const response = await service[action](Util.deepCopy(this.context), this.viewparams);
                if (response && response.status == 200 && response.data) {
                    this.fillPanelData(response.data);
                }
            }
            catch (response) {
                this.$throw(response, 'load');
            }
        }
    }
    /**
      * 获取数据项集合
      *
      * @returns {any[]}
      * @memberof AppPanelModel
      */
    getDataItems() {
        var _a, _b;
        let arr = [];
        (_b = (_a = this.controlInstance.M) === null || _a === void 0 ? void 0 : _a.getAllPSPanelFields) === null || _b === void 0 ? void 0 : _b.forEach((datafield) => {
            var _a, _b;
            let obj = {};
            obj.name = (_a = datafield === null || datafield === void 0 ? void 0 : datafield.id) === null || _a === void 0 ? void 0 : _a.toLowerCase();
            obj.prop = (_b = datafield === null || datafield === void 0 ? void 0 : datafield.viewFieldName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
            arr.push(obj);
        });
        return arr;
    }
    /**
     * 填充面板数据
     *
     * @param {*} data
     * @memberof PanelControlBase
     */
    fillPanelData(data) {
        this.getDataItems().forEach((item) => {
            if (item === null || item === void 0 ? void 0 : item.prop) {
                this.data[item.name] = data === null || data === void 0 ? void 0 : data[item.prop];
            }
            else {
                this.data[item.name] = data === null || data === void 0 ? void 0 : data[item.name];
            }
        });
    }
    /**
     * 获取所有代码表
     *
     * @param {Array<any>} codelistArray 代码表模型数组
     * @param {boolean} [reverse=false]
     * @returns {Promise<any>}
     * @memberof PanelControlBase
     */
    getAllCodeList(codelistArray, reverse = false) {
        return new Promise((resolve, reject) => {
            let codeListMap = new Map();
            let promiseArray = [];
            codelistArray.forEach((item) => {
                if (!codeListMap.get(item.tag)) {
                    promiseArray.push(this.getCodeList(item));
                    Promise.all(promiseArray).then((result) => {
                        if (result && result.length > 0) {
                            result.forEach((codeList) => {
                                let tempCodeListMap = new Map();
                                if (codeList.length > 0) {
                                    codeList.forEach((codeListItem) => {
                                        if (reverse) {
                                            tempCodeListMap.set(codeListItem.text, codeListItem.value);
                                        }
                                        else {
                                            tempCodeListMap.set(codeListItem.value, codeListItem.text);
                                        }
                                    });
                                }
                                codeListMap.set(item.tag, tempCodeListMap);
                            });
                            resolve(codeListMap);
                        }
                    });
                }
            });
        });
    }
    /**
     * 获取代码表
     *
     * @param codeListObject 传入代码表对象
     * @memberof PanelControlBase
     */
    getCodeList(codeListObject) {
        return new Promise((resolve, reject) => {
            if (codeListObject.tag && Object.is(codeListObject.codelistType, 'STATIC')) {
                const codelist = this.$store.getters.getCodeList(codeListObject.tag);
                if (codelist) {
                    resolve([...JSON.parse(JSON.stringify(codelist.items))]);
                }
                else {
                    resolve([]);
                }
            }
            else if (codeListObject.tag && Object.is(codeListObject.codelistType, 'DYNAMIC')) {
                this.codeListService
                    .getItems(codeListObject.tag)
                    .then((res) => {
                    resolve(res);
                })
                    .catch((error) => {
                    resolve([]);
                });
            }
        });
    }
    /**
     * 计算面板按钮权限状态
     *
     * @param {*} data
     * @memberof PanelControlBase
     */
    computeButtonState(data) {
        const targetData = this.transformData(data);
        ViewTool.calcActionItemAuthState(targetData, this.actionModel, this.appUIService);
        // 更新detailsModel里的按钮的权限状态值
        if (this.detailsModel && Object.keys(this.detailsModel).length > 0) {
            Object.keys(this.detailsModel).forEach((name) => {
                var _a;
                const model = this.detailsModel[name];
                if ((model === null || model === void 0 ? void 0 : model.itemType) == 'BUTTON' && ((_a = model.uiaction) === null || _a === void 0 ? void 0 : _a.tag)) {
                    model.visible = this.actionModel[model.uiaction.tag].visabled;
                    model.disabled = this.actionModel[model.uiaction.tag].disabled;
                    model.isPower = this.actionModel[model.uiaction.tag].dataActionResult === 1 ? true : false;
                }
            });
        }
    }
    /**
     * 初始化界面行为模型
     *
     * @type {*}
     * @memberof GridControlBase
     */
    initCtrlActionModel() {
        var _a;
        if (((_a = this.controlInstance.getRootPSPanelItems()) === null || _a === void 0 ? void 0 : _a.length) > 0) {
            this.initItemsActionModel(this.controlInstance.getRootPSPanelItems());
        }
    }
    /**
     * 初始化面板项的界面行为模型
     *
     * @param {any[]} panelItems
     * @memberof PanelControlBase
     */
    initItemsActionModel(panelItems) {
        panelItems === null || panelItems === void 0 ? void 0 : panelItems.forEach((item) => {
            var _a, _b;
            const panelItem = item;
            const panelButtomItem = item;
            if (((_b = (_a = panelItem === null || panelItem === void 0 ? void 0 : panelItem.getPSPanelItems) === null || _a === void 0 ? void 0 : _a.call(panelItem)) === null || _b === void 0 ? void 0 : _b.length) > 0) {
                this.initItemsActionModel(panelItem.getPSPanelItems());
            }
            else if ((panelItem === null || panelItem === void 0 ? void 0 : panelItem.itemType) == 'BUTTON' && panelButtomItem.getPSUIAction()) {
                const appUIAction = panelButtomItem.getPSUIAction();
                this.actionModel[appUIAction.uIActionTag] = Object.assign(appUIAction, { disabled: false, visabled: true, getNoPrivDisplayMode: appUIAction.noPrivDisplayMode ? appUIAction.noPrivDisplayMode : 6 });
            }
            else if (item.itemType == 'TABPANEL') {
                const tabPages = item.getPSPanelTabPages() || [];
                tabPages.forEach((page) => {
                    this.initItemsActionModel(page.getPSPanelItems());
                });
            }
        });
    }
    /**
     * 监控数据对象
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof PanelControlBase
     */
    onInputDataChange(newVal, oldVal) { }
    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof PanelControlBase
     */
    getDatas() {
        if (!this.data) {
            return [];
        }
        return [this.data];
    }
    /**
     * 获取单项数据
     *
     * @returns
     * @memberof PanelControlBase
     */
    getData() {
        return this.data;
    }
    /**
     * 计算父容器数据项
     *
     * @param {*} [args]
     * @memberof PanelControlBase
     */
    computeParentDataItems() {
        var _a, _b, _c, _d, _e;
        const parent = (_b = (_a = this.controlInstance).getParentPSModelObject) === null || _b === void 0 ? void 0 : _b.call(_a);
        if (parent.controlType &&
            (parent.controlType == 'DATAVIEW' || parent.controlType == 'LIST' || parent.controlType == 'KANBAN')) {
            this.needFindDEField = true;
        }
        if (!this.needFindDEField) {
            return;
        }
        switch (parent.controlType) {
            case 'DATAVIEW':
                this.parentDataItems = (_c = parent.getPSDEDataViewDataItems) === null || _c === void 0 ? void 0 : _c.call(parent);
                break;
            case 'LIST':
                this.parentDataItems = (_d = parent.getPSDEListDataItems) === null || _d === void 0 ? void 0 : _d.call(parent);
                break;
            case 'KANBAN':
                this.parentDataItems = (_e = parent.getPSDEDataViewDataItems) === null || _e === void 0 ? void 0 : _e.call(parent);
                break;
        }
    }
    /**
     * 面板属性项查找对应父容器实体实体属性项
     *
     * @returns
     * @memberof PanelControlBase
     */
    findDEFieldForPanelField(target) {
        var _a, _b, _c;
        const parent = this.controlInstance.getParentPSModelObject();
        const entity = (_a = parent.getPSAppDataEntity) === null || _a === void 0 ? void 0 : _a.call(parent);
        if (entity && this.parentDataItems.length > 0) {
            const valueItemName = (_c = (_b = this.controlInstance.getAllPSPanelFields()) === null || _b === void 0 ? void 0 : _b.find((item) => Object.is(item.id.toLowerCase(), target.name.toLowerCase()))) === null || _c === void 0 ? void 0 : _c.viewFieldName;
            const dataItem = this.parentDataItems.find((item) => { var _a; return Object.is(valueItemName === null || valueItemName === void 0 ? void 0 : valueItemName.toLowerCase(), (_a = item.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()); });
            if (dataItem) {
                Object.assign(target, {
                    getPSAppDEField: () => {
                        var _a;
                        return (_a = dataItem.getPSAppDEField) === null || _a === void 0 ? void 0 : _a.call(dataItem);
                    }
                });
            }
        }
    }
}
