<template>
  <w-grid
    ref="gridRef"
    :title="$t('io.sc.engine.mv.config.dataExtractor.grid.title')"
    :config-button="true"
    selection="multiple"
    :checkbox-selection="true"
    :data-url="Environment.apiContextPath('/api/mv/configure/dataExtractor')"
    :pageable="false"
    :toolbar-configure="{ noIcon: false }"
    :toolbar-actions="[
      'refresh',
      'separator',
      'add',
      'edit',
      'remove',
      'separator',
      {
        name: 'example',
        label: $t('io.sc.engine.mv.config.dataExtractor.grid.toolbar.example'),
        icon: 'bi-arrow-right-circle',
        click: () => {
          DialogManager.confirm($t('io.sc.engine.mv.config.dataExtractor.grid.toolbar.example.tip'), () => {
            axios.post(Environment.apiContextPath('/api/mv/configure/dataExtractor/generateSample')).then(() => {
              gridRef.refresh();
            });
          });
        },
      },
      'separator',
      'view',
      'separator',
      'export',
    ]"
    :columns="[
      { width: 100, name: 'name', label: $t('name') },
      { width: 100, name: 'enable', label: $t('status'), format: Formater.enableTag() },
      { width: 120, name: 'order', label: $t('order'), align: 'right' },
      { width: 120, name: 'executeTimeWeight', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.executeTimeWeight'), align: 'right' },
      { width: 120, name: 'datasourceName', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.datasourceName') },
      { width: 100, name: 'lastModifier', label: $t('lastModifier') },
      { width: 150, name: 'lastModifyDate', label: $t('lastModifyDate'), format: Formater.dateOnly() },
    ]"
    :editor="{
      dialog: {
        width: '800px',
        height: '600px',
      },
      form: {
        colsNum: 1,
        fields: [
          { name: 'name', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.name'), type: 'text' },
          { name: 'enable', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.enable'), type: 'checkbox' },
          { name: 'order', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.order'), type: 'text' },
          { name: 'executeTimeWeight', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.executeTimeWeight'), type: 'text' },
          { name: 'datasourceName', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.datasourceName'), type: 'text' },
          { name: 'groovyScript', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.groovyScript'), type: 'textarea', rows: 12 },
        ],
      },
    }"
    :viewer="{
      panel: {
        columnNum: 1,
        fields: [
          { name: 'id', label: $t('id') },
          { name: 'name', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.name') },
          { name: 'enable', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.enable'), format: Formater.none() },
          { name: 'order', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.order') },
          { name: 'executeTimeWeight', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.executeTimeWeight') },
          { name: 'datasourceName', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.datasourceName') },
          { name: 'groovyScript', label: $t('io.sc.engine.mv.config.dataExtractor.grid.entity.groovyScript'), format: Formater.replaceAll() },
          { 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 { ref } from 'vue';
import { axios, Environment, Formater, DialogManager } from 'platform-core';

const gridRef = ref();
</script>
