<template>
  <w-grid
    ref="parameterTreeGridRef"
    :title="$t('system.menu.grid.title')"
    :config-button="true"
    selection="multiple"
    :checkbox-selection="false"
    :tree="true"
    :tree-icon="
      (row) => {
        return { name: 'folder', color: 'amber' };
      }
    "
    default-expand-all
    :data-url="Environment.apiContextPath('/api/system/parameter')"
    :pageable="false"
    :toolbar-configure="{ noIcon: false }"
    :toolbar-actions="[
      'refresh',
      'separator',
      'expand',
      {
        extend: 'edit',
        enableIf: (selecteds) => {
          if (selecteds && selecteds.length > 0) {
            return !Tools.isUndefinedOrNull(selecteds[0].value);
          }
          return false;
        },
      },
      'separator',
      'export',
    ]"
    :columns="[
      {
        width: 300,
        name: 'code',
        label: $t('code'),
        sortable: false,
        format: (value) => {
          return $t(value);
        },
      },
      { width: '100%', name: 'value', label: $t('value'), sortable: false },
      { width: 100, name: 'dataComeFrom', label: $t('dataComeFrom'), sortable: false, format: Formater.enum(DataComeFromEnum) },
      { width: 100, name: 'lastModifier', label: $t('lastModifier'), sortable: false },
      { width: 100, name: 'lastModifyDate', label: $t('lastModifyDate'), sortable: false, format: Formater.dateOnly() },
    ]"
    :editor="{
      dialog: {
        width: '600px',
        height: '250px',
      },
      form: {
        colsNum: 1,
        fields: [
          { name: 'code', label: $t('code'), type: 'text' },
          { name: 'value', label: $t('value'), type: 'text' },
        ],
      },
    }"
    :viewer="{
      panel: {
        columnNum: 1,
        fields: [
          { name: 'id', label: $t('id') },
          { name: 'type', label: $t('type') },
          { name: 'name', label: $t('name') },
          { name: 'titleI18nKey', label: $t('titleI18nKey') },
          { name: 'icon', label: $t('icon') },
          { name: 'enable', label: $t('enable') },
          { name: 'order', label: $t('order') },
          { name: 'javaScript', label: $t('javaScript') },
          { name: 'url', label: $t('url') },
          { name: 'urlOpenType', label: $t('urlOpenType') },
          { name: 'routeName', label: $t('routeName') },
          { name: 'routeQuery', label: $t('routeQuery') },

          { 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') },
          { name: 'corporationCode', label: $t('corporationCode') },
        ],
      },
    }"
    @row-click="(evt, row, index) => {}"
  ></w-grid>
</template>
<script setup lang="ts">
import { Environment, Tools, EnumTools, Formater, Options } from 'platform-core';

const DataComeFromEnum = await EnumTools.fetch('io.sc.platform.orm.api.enums.DataComeFrom');
</script>
