<template>
  <w-grid
    ref="gridRef"
    dense-body
    :title="$t('re.resources.grid.title')"
    :config-button="true"
    selection="multiple"
    :checkbox-selection="true"
    :fetch-data-url="Environment.apiContextPath('/api/re/blood/findResourcesByParameterCodeAndNameAndType')"
    :sort-by="['name']"
    :query-form-cols-num="4"
    :query-form-fields="[
      { name: 'code', label: $t('code'), type: 'w-text', queryOperator: 'equals' },
      { name: 'name', label: $t('name'), type: 'w-text' },
      {
        name: 'type',
        label: $t('type'),
        type: 'w-select',
        options: EngineEnums.ParameterType.options,
        clearable: true,
      },
    ]"
    :advanced-query="true"
    :toolbar-configure="{ noIcon: false }"
    :toolbar-actions="['query', 'reset', 'separator', 'view', 'separator', 'export']"
    :columns="[
      {
        width: 400,
        name: 'namec',
        label: $t('name'),
        format: (value: any, row: any) => {
          return row.name;
        },
      },
      {
        width: 80,
        name: 'type',
        label: $t('type'),
        showIf: false,
        format: EngineEnums.ResourceType.formater,
      },
      { width: 150, name: 'code', label: $t('code'), showIf: false },
      { width: 60, name: 'version', label: $t('version'), align: 'right' },
      {
        width: 60,
        name: 'status',
        label: $t('status'),
        align: 'center',
        format: EngineEnums.DeployStatus.formater,
      },
      {
        width: 60,
        name: 'preDeploy',
        label: $t('re.resources.grid.entity.preDeploy'),
        align: 'center',
        sortable: false,
        format: (value) => {
          if (value) {
            return Formater.yesNo()(value);
          }
        },
      },
      { width: 120, name: 'taskName', label: $t('re.resources.grid.entity.taskName'), sortable: false },
      { width: 80, name: 'taskAssignee', label: $t('re.resources.grid.entity.taskAssignee'), sortable: false },
      { width: 100, name: 'lastModifier', label: $t('lastModifier') },
      { width: 140, name: 'lastModifyDate', label: $t('lastModifyDate') },
      {
        width: 80,
        name: 'attachmentCount',
        label: $t('attachment'),
        sortable: false,
        align: 'right',
        format: (value: any, row: any) => {
          if (value > 0) {
            return value;
          } else {
            return '';
          }
        },
      },
    ]"
    :viewer="{
      panel: {
        columnNum: 1,
        fields: [
          { name: 'type', label: $t('type') },
          { name: 'parent', label: $t('parent') },
          { name: 'id', label: $t('id') },
          { name: 'code', label: $t('code') },
          { name: 'name', label: $t('name') },
          { name: 'description', label: $t('description') },
          { name: 'version', label: $t('version') },
          { name: 'status', label: $t('status'), format: Formater.none() },
          { name: 'effectiveDate', label: $t('effectiveDate') },
          { name: 'taskName', label: $t('re.resources.grid.entity.taskName') },
          { name: 'taskAssignee', label: $t('re.resources.grid.entity.taskAssignee') },
          { name: 'attachmentCount', label: $t('attachment') },
          { name: 'imports', label: $t('imports') },
          { name: 'order', label: $t('order') },
          ...CorporationAuditorEntityManager.getViewerFields(),
        ],
      },
    }"
  >
  </w-grid>
</template>
<script setup lang="ts">
import { Environment, Formater, CorporationAuditorEntityManager } from 'platform-core';
import { EngineEnums } from '@/views/shared/enums/EngineEnums';

await EngineEnums.init();
</script>
