<template>
  <w-grid
    ref="gridRef"
    :title="$t('re.resources.designer.testCase.grid.title')"
    dense-body
    class="px-1"
    hide-bottom
    :config-button="false"
    selection="multiple"
    :checkbox-selection="false"
    :tree="false"
    :fetch-data-url="Environment.apiContextPath('/api/re/testCase/findByOwnerId?ownerId=' + lib.id)"
    :data-url="Environment.apiContextPath('/api/re/testCase')"
    :pageable="false"
    :toolbar-configure="{ noIcon: false }"
    :toolbar-actions="[
      'refresh',
      'separator',
      'add',
      'clone',
      {
        extend: 'clone',
        name: 'deepClone',
        label: $t('deepClone'),
        icon: 'bi-copy',
        click: (arg) => {},
      },
      'edit',
      'remove',
      'separator',
      {
        name: 'execute',
        label: $t('execute'),
        icon: 'bi-caret-right',
      },
      {
        name: 'executeAll',
        label: $t('executeAll'),
        icon: 'bi-caret-right-fill',
      },
      'view',
      'separator',
      'export',
    ]"
    :columns="[
      { width: 50, name: 'order', label: $t('order'), hidden: true },
      { width: 100, name: 'id', label: $t('id'), hidden: true },
      {
        width: 80,
        name: 'testResult',
        label: $t('re.resources.designer.testCase.grid.entity.testResult'),
        align: 'center',
        sortable: false,
        format: PassOrNotFormater,
      },
      { width: 150, name: 'lastTestDate', label: $t('re.resources.designer.testCase.grid.entity.lastTestDate') },
      { width: 200, name: 'name', label: $t('name') },
      { width: '100%', name: 'description', label: $t('description') },
    ]"
    :editor="{
      dialog: {
        width: '600px',
        height: '250px',
      },
      form: {
        colsNum: 1,
        fields: [
          { name: 'order', label: $t('order'), type: 'text', hidden: true },
          { name: 'id', label: $t('id'), type: 'text', hidden: true },
          { name: 'ownerType', label: $t('ownerType'), type: 'text', defaultValue: 'LIB', hidden: true },
          { name: 'owner', label: $t('owner'), type: 'text', defaultValue: lib.id, hidden: true },
          { name: 'name', label: $t('name'), type: 'text', required: true },
          { name: 'description', label: $t('description'), type: 'text' },
        ],
      },
    }"
    :viewer="{
      panel: {
        columnNum: 1,
        fields: [
          { name: 'order', label: $t('order') },
          { name: 'id', label: $t('id') },
          { name: 'name', label: $t('name') },
          { name: 'description', label: $t('description') },

          { name: 'dataComeFrom', label: $t('dataComeFrom') },
          { name: 'creator', label: $t('creator') },
          { name: 'createDate', label: $t('createDate') },
          { name: 'lastModifier', label: $t('lastModifier') },
          { name: 'lastModifyDate', label: $t('lastModifyDate'), format: Formater.none() },
          { name: 'corporationCode', label: $t('corporationCode') },
        ],
      },
    }"
    v-bind="attrs"
  ></w-grid>
</template>
<script setup lang="ts">
import { onMounted, ref, useAttrs } from 'vue';
import { axios, Environment, EnumTools, Formater, Options, Tools } from 'platform-core';
import PassOrNotFormater from '@/utils/PassOrNotFormater';

const attrs = useAttrs();

const props = defineProps({
  lib: { type: Object, default: undefined },
});

const gridRef = ref();

const refresh = () => {
  gridRef?.value?.refresh();
};

onMounted(() => {
  gridRef?.value?.refresh();
});

defineExpose({
  refresh,
});

const Enums = await EnumTools.fetch([
  'io.sc.platform.core.enums.RoundingMode',
  'io.sc.engine.rule.core.enums.ParameterType',
  'io.sc.engine.rule.core.enums.DeployStatus',
]);
let ValueTypeMap = {};
let ValueTypeList = [];
const response = await axios.get(Environment.apiContextPath('/api/re/dictionary/getAllDictionaryMap'));
if (response && response.data) {
  ValueTypeMap = {};
  ValueTypeList = [];
  for (const item of response.data) {
    ValueTypeMap[item.key] = item.value;
    ValueTypeList.push({ value: item.key, label: item.value });
  }
}
</script>
