import { DataViewService, ControlVOBase } from '@core';
import { {{pascalCase ctrl.psAppDataEntity.codeName}}Service } from '@api/{{spinalCase ctrl.psAppDataEntity.codeName}}/{{spinalCase ctrl.psAppDataEntity.codeName}}-service';

export class ControlVO extends ControlVOBase {
  constructor(data: any) {
    super(data);
    //  数据视图部件自持属性
    this.$ownKeys = 
{{~#each ctrl.psDEDataViewDataItems as | dataItem | ~}}
  {{#if @first}}[{{/if~}}
    '{{lowerCase dataItem.name}}'{{#unless @last}},{{/unless}}
  {{~#if @last}}];{{/if~}}
{{/each}}

  }

{{#each ctrl.psDEDataViewDataItems as | dataItem |}}
  {{#if dataItem.psAppDEField}}
  get {{lowerCase dataItem.name}}() {
    return this.$DO.{{lowerCase dataItem.psAppDEField.codeName}};
  }
  set {{lowerCase dataItem.name}}(value: any) {
    this.$DO.{{lowerCase dataItem.psAppDEField.codeName}} = value;
  }
	{{/if}}

{{/each}}
}

export const ctrlState = () => {
  return {
    controlCodeName: '{{ctrl.codeName}}',
    controlName: '{{ctrl.name}}',
    appEntityCodeName: '{{ctrl.psAppDataEntity.codeName}}',
    appDeCodeName:'{{ctrl.psAppDataEntity.codeName}}',
    appDeLogicName: '{{ctrl.psAppDataEntity.logicName}}',
    appDeKeyFieldName: '{{#if ctrl.psAppDataEntity.keyPSAppDEField}}{{ctrl.psAppDataEntity.keyPSAppDEField.codeName}}{{/if}}',
    appDeMajorFieldName: '{{#if ctrl.psAppDataEntity.majorPSAppDEField}}{{ctrl.psAppDataEntity.majorPSAppDEField.codeName}}{{/if}}',
    controlService: new DataViewService<ControlVO>(ControlVO, new {{pascalCase ctrl.psAppDataEntity.codeName}}Service() ),
    selections: [],
    // 多数据部件分组
    mdCtrlGroup: {
      enableGroup: {{ctrl.enableGroup}},
      groupMode: "{{ctrl.groupMode}}",
      groupField: "{{lowerCase ctrl.groupPSAppDEField.codeName}}",
      {{#if ctrl.groupPSCodeList}}
      groupCodeList: {
        codeListTag: "{{ctrl.groupPSCodeList.codeListTag}}",
        codeListType: "{{ctrl.groupPSCodeList.codeListType}}",
      },
      {{/if}}
    },
    // 多数据部件排序
    mdCtrlSort: {
      noSort: {{ctrl.noSort}},
      minorSortDir: "{{#if ctrl.minorSortDir}}{{ctrl.minorSortDir}}{{/if}}",
      minorSortPSDEF: "{{ctrl.minorSortPSAppDEField.codeName}}",
    },
    // 多数据部件分页
    mdCtrlPaging: {
      enablePagingBar: true,
      current: 1,
      pageSize: {{#if ctrl.pagingSize}}{{ctrl.pagingSize}}{{else}}20{{/if}},
      pagination: {}
    },
    {{#if ctrl.quickToolBarItems}}
      {{#ctrl.quickToolBarItems}}
    quickToolbar: [
        {{#items}}
      { id:'{{id}}',name:'{{name}}',caption:'{{caption}}',groupExtractMode:'{{groupExtractMode}}',itemType:'{{itemType}}',noPrivDisplayMode:'{{noPrivDisplayMode}}',showIcon:{{showIcon}},showCaption:{{showCaption}},tooltip:'{{tooltip}}',disabled: false, visible: true, imgPath: '{{imgPath}}',iconClass: '{{iconClass}}',xDataControlName:'{{xDataControlName}}',{{#if uIAction}}uIAction:{codeName:'{{uIAction.codeName}}',fullCodeName:'{{uIAction.fullCodeName}}',uIActionMode:'{{uIAction.uIActionMode}}',actionTarget:'{{uIAction.actionTarget}}',uIActionTag:'{{uIAction.uIActionTag}}',dataAccessAction:'{{uIAction.dataAccessAction}}',uIActionType:'{{uIAction.uIActionType}}'}{{/if}} },
        {{/items}}
    ],
      {{/ctrl.quickToolBarItems}}
    {{/if}}
    {{#if ctrl.batchToolBarItems}}
      {{#ctrl.batchToolBarItems}}
    batchToolbar: [
        {{#items}}
      { id:'{{id}}',name:'{{name}}',caption:'{{caption}}',groupExtractMode:'{{groupExtractMode}}',itemType:'{{itemType}}',noPrivDisplayMode:'{{noPrivDisplayMode}}',showIcon:{{showIcon}},showCaption:{{showCaption}},tooltip:'{{tooltip}}',disabled: false, visible: true, imgPath: '{{imgPath}}',iconClass: '{{iconClass}}',xDataControlName:'{{xDataControlName}}',{{#if uIAction}}uIAction:{codeName:'{{uIAction.codeName}}',fullCodeName:'{{uIAction.fullCodeName}}',uIActionMode:'{{uIAction.uIActionMode}}',actionTarget:'{{uIAction.actionTarget}}',uIActionTag:'{{uIAction.uIActionTag}}',dataAccessAction:'{{uIAction.dataAccessAction}}',uIActionType:'{{uIAction.uIActionType}}'}{{/if}} },
        {{/items}}
    ],
      {{/ctrl.batchToolBarItems}}
    {{/if}}
    //  界面行为
    uIActions: {
      {{#each ctrl.psDEDataViewItems as | dataViewItem |}}
        {{#and (eq dataViewItem.itemType 'ACTIONITEM') dataViewItem.psDEUIActionGroup dataViewItem.psDEUIActionGroup.psUIActionGroupDetails}}
          {{#dataViewItem}}
            {{#each dataViewItem.psDEUIActionGroup.psUIActionGroupDetails as | uiActionDetail |}}
              {{#if uiActionDetail.getPSUIAction}}
                {{#uiActionDetail.getPSUIAction}}
      {{uIActionTag}}: { caption: '{{caption}}', tooltip: '{{tooltip}}', showCaption: {{../showCaption}}, showIcon: {{../showIcon}}, uIActionTag: '{{uIActionTag}}', uIActionType: '{{uIActionType}}', dataAccessAction: '{{dataAccessAction}}', noPrivDisplayMode: '{{noPrivDisplayMode}}', uIActionMode: '{{uIActionMode}}', disabled: false, visible: true, {{#if coutnerId}}counterId: '{{counterId}}', {{/if}}{{#if psSysImage}}cssClass: '{{psSysImage.cssClass}}', {{#if psSysImage.cssClass}}{{/if}}{{#if psSysImage.imagePath}}imagePath: '{{psSysImage.imagePath}}'{{/if}}{{/if}} },
                {{/uiActionDetail.getPSUIAction}}
              {{/if}}
            {{/each}}
          {{/dataViewItem}}
        {{/and}}
      {{/each}}
    }
  }
}