<template>
  <w-grid
    ref="parameterTreeGridRef"
    :title="$t('system.parameter.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',
      {
        extend: 'view',
        enableIf: (selecteds) => {
          if (selecteds && selecteds.length > 0) {
            return !Tools.isUndefinedOrNull(selecteds[0].value);
          }
          return false;
        },
      },
      'separator',
      'export',
    ]"
    :columns="[
      {
        width: 300,
        name: 'name',
        label: $t('name'),
        sortable: false,
        format: (value, row) => {
          return $t(row.code);
        },
      },
      { width: 300, name: 'code', label: $t('code') },
      { width: '100%', name: 'value', label: $t('value') },
      { width: 100, name: 'lastModifier', label: $t('lastModifier') },
      { width: 150, name: 'lastModifyDate', label: $t('lastModifyDate'), 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: 'code', label: $t('code') },
          { name: 'value', label: $t('value') },
          { 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') },
        ],
      },
    }"
    @row-click="(evt, row, index) => {}"
  ></w-grid>
</template>
<script setup lang="ts">
import { Environment, Tools, Formater } from 'platform-core';
</script>
