<template>
  <w-grid
    ref="gridRef"
    :title="$t('standard.adminDivision.grid.title')"
    hide-bottom
    :config-button="true"
    selection="multiple"
    :checkbox-selection="true"
    dense
    :tree="true"
    :tree-icon="
      (row) => {
        return { name: 'folder', color: 'amber' };
      }
    "
    primary-key="code"
    :data-url="Environment.apiContextPath('/api/standard/adminDivision')"
    :pageable="false"
    :pagination="{
      sortBy: 'code',
      descending: false,
    }"
    :toolbar-configure="{ noIcon: false }"
    :toolbar-actions="[
      'refresh',
      'separator',
      [
        {
          extend: 'add',
          click: undefined,
        },
        {
          extend: 'addTop',
          label: $t('standard.adminDivision.grid.toolbar.addTop'),
        },
        {
          extend: 'addChild',
          label: $t('standard.adminDivision.grid.toolbar.addChild'),
        },
      ],
      'edit',
      'remove',
      'separator',
      'view',
      'separator',
      'export',
    ]"
    :columns="[
      {
        name: 'target',
        label: $t('standard.entity.target'),
        columns: [
          { width: 300, name: 'name', label: $t('name') },
          { width: 100, name: 'code', label: $t('code') },
        ],
      },
      {
        name: 'source',
        label: $t('standard.entity.source'),
        columns: [
          { width: 300, name: 'mappingName', label: $t('name') },
          { width: 100, name: 'mappingCode', label: $t('code') },
        ],
      },
    ]"
    :editor="{
      dialog: {
        width: '600px',
      },
      form: {
        colsNum: 1,
        fields: [
          { name: 'code', label: $t('standard.entity.code'), type: 'text', required: true },
          { name: 'name', label: $t('standard.entity.name'), type: 'text', required: true },
          { name: 'description', label: $t('standard.entity.description'), type: 'textarea', rows: 3 },
          { name: 'mappingCode', label: $t('standard.entity.mappingCode'), type: 'text', required: true },
          { name: 'mappingName', label: $t('standard.entity.mappingName'), type: 'text' },
          { name: 'mappingDescription', label: $t('standard.entity.mappingDescription'), type: 'textarea', rows: 3 },
        ],
      },
    }"
    :viewer="{
      panel: {
        columnNum: 1,
        fields: [
          { name: 'code', label: $t('standard.entity.code') },
          { name: 'name', label: $t('standard.entity.name') },
          { name: 'description', label: $t('standard.entity.description') },
          { name: 'mappingCode', label: $t('standard.entity.mappingCode') },
          { name: 'mappingName', label: $t('standard.entity.mappingName') },
          { name: 'mappingDescription', label: $t('standard.entity.mappingDescription') },

          { 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() },
        ],
      },
    }"
  ></w-grid>
</template>
<script setup lang="ts">
import { Environment, Formater } from 'platform-core';
</script>
