import { throttle, Util } from '@ibizstudio/runtime';
import { TabExpPanelBase } from '../../../widgets';
/**
 * 分页导航面板部件基类
 *
 * @export
 * @class AppTabExpPanelBase
 * @extends {TabExpPanelBase}
 */
export class AppTabExpPanelBase extends TabExpPanelBase {
    /**
     * 绘制分页导航面板Container
     *
     * @memberof AppTabExpPanelBase
     */
    renderTabPaneContent(tabViewPanel, index) {
        var _a, _b, _c, _d, _e;
        let { targetCtrlParam, targetCtrlEvent, targetCtrlName } = this.computeTargetCtrlData(tabViewPanel);
        Object.assign(targetCtrlParam.staticProps, {
            isActivied: index === 0 ? true : false,
        });
        // 视图面板计数器
        let viewPanelCount = undefined;
        const appCounterRef = tabViewPanel.getPSAppCounterRef();
        if (appCounterRef && tabViewPanel.counterId) {
            const targetCounterService = (_a = Util.findElementByField(this.counterServiceArray, 'id', appCounterRef.id)) === null || _a === void 0 ? void 0 : _a.service;
            viewPanelCount = (_b = targetCounterService === null || targetCounterService === void 0 ? void 0 : targetCounterService.counterData) === null || _b === void 0 ? void 0 : _b[tabViewPanel.counterId.toLowerCase()];
        }
        const tabsName = `${this.appDeCodeName.toLowerCase()}_${(_c = this.controlInstance.controlType) === null || _c === void 0 ? void 0 : _c.toLowerCase()}_${(_d = this.controlInstance.codeName) === null || _d === void 0 ? void 0 : _d.toLowerCase()}`;
        let disabled = this.authResourceObject && ((_e = this.authResourceObject[tabViewPanel.name]) === null || _e === void 0 ? void 0 : _e.disabled);
        const IPSSysImage = tabViewPanel.getPSSysImage();
        return (<tab-pane lazy={true} name={tabViewPanel.name} tab={tabsName} disabled={disabled} label={(h) => {
                var _a;
                return h('div', [
                    IPSSysImage
                        ? IPSSysImage.imagePath
                            ? h('img', {
                                src: IPSSysImage.imagePath,
                                style: {
                                    'margin-right': '2px',
                                },
                            })
                            : h('i', {
                                class: IPSSysImage.cssClass,
                                style: {
                                    'margin-right': '2px',
                                },
                            })
                        : '',
                    h('span', this.$tl((_a = tabViewPanel.getCapPSLanguageRes()) === null || _a === void 0 ? void 0 : _a.lanResTag, tabViewPanel.caption)),
                    h('Badge', {
                        props: {
                            count: viewPanelCount,
                            type: 'primary',
                        },
                    }),
                ]);
            }}>
        {this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: tabViewPanel.name, on: targetCtrlEvent })}
      </tab-pane>);
    }
    /**
     * 绘制分页导航面板
     *
     * @returns {*}
     * @memberof AppTabExpPanelBase
     */
    render() {
        var _a, _b, _c, _d;
        if (!this.controlIsLoaded) {
            return null;
        }
        const { controlClassNames } = this.renderOptions;
        const IPSDETabViewPanel = this.controlInstance.getPSControls();
        const tabsName = `${this.appDeCodeName.toLowerCase()}_${(_b = (_a = this.controlInstance) === null || _a === void 0 ? void 0 : _a.controlType) === null || _b === void 0 ? void 0 : _b.toLowerCase()}_${(_d = (_c = this.controlInstance) === null || _c === void 0 ? void 0 : _c.codeName) === null || _d === void 0 ? void 0 : _d.toLowerCase()}`;
        return (<div class={Object.assign(Object.assign({}, controlClassNames), { tabviewpanel: true })}>
        <tabs value={this.activiedTabViewPanel} animated={false} class='tabexppanel' name={tabsName} on-on-click={($event) => throttle(this.tabPanelClick, [$event], this)}>
          {IPSDETabViewPanel === null || IPSDETabViewPanel === void 0 ? void 0 : IPSDETabViewPanel.map((tabViewPanel, index) => {
                var _a;
                return this.authResourceObject && ((_a = this.authResourceObject[tabViewPanel.name]) === null || _a === void 0 ? void 0 : _a.visabled) ? this.renderTabPaneContent(tabViewPanel, index) : null;
            })}
        </tabs>
      </div>);
    }
}
