<template>
  <CollapseItem name="按钮设置" :expanded="true">
    <n-table
      class="go-request-header-table-box"
      style="margin-top: 12px"
      :single-line="false"
      size="small"
    >
      <thead>
        <tr>
          <th></th>
          <th>手动输入名称</th>
          <th>常用字段名称</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item, index) in props.optionData.dataset" :key="index">
          <td>
            {{ index + 1 }}
          </td>
          <td>
            <n-input v-model:value="item.value" type="text" size="small" />
          </td>
          <td>
            <n-select
              style="width: 100px"
              v-model:value="item.value"
              :options="dataList"
              size="small"
            />
          </td>
          <td>
            <div style="width: 70px">
              <n-button class="go-ml-2" type="primary" size="small" ghost @click="add(index)">
                +
              </n-button>
              <n-button
                class="go-ml-2"
                type="warning"
                size="small"
                ghost
                :disabled="props.optionData.dataset.length === 1"
                @click="remove(index)"
              >
                -
              </n-button>
            </div>
          </td>
        </tr>
      </tbody>
    </n-table>

    <SettingItemBox name="样式设置">
      <SettingItem name="背景颜色">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.dataStyle.backgroud"
        ></n-color-picker>
      </SettingItem>
      <SettingItem name="间隔距离">
        <n-input-number
          v-model:value="optionData.dataStyle.gap"
          :min="0"
          size="small"
          placeholder="间隔距离"
        ></n-input-number>
      </SettingItem>
      <SettingItem name="上边距离">
        <n-input-number
          v-model:value="optionData.dataStyle.marginTop"
          :min="0"
          size="small"
          placeholder="上边距离"
        ></n-input-number>
      </SettingItem>
      <SettingItem name="左右距离">
        <n-input-number
          v-model:value="optionData.dataStyle.marginLeft"
          :min="0"
          size="small"
          placeholder="左右距离"
        ></n-input-number>
      </SettingItem>
      <SettingItem name="按钮字体大小">
        <n-input-number
          v-model:value="optionData.dataStyle.fontsize"
          type="text"
          :min="0"
          size="small"
        />
      </SettingItem>
      <SettingItem name="按钮字体颜色">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.dataStyle.fontcolor"
        ></n-color-picker>
      </SettingItem>
    </SettingItemBox>
  </CollapseItem>
</template>

<script setup lang="ts">
  import { PropType, watch, ref, computed } from 'vue';
  import { option } from './config';
  import { cloneDeep } from 'lodash-es';
  import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting';

  const props = defineProps({
    optionData: {
      type: Object as PropType<typeof option>,
      required: true,
    },
  });

  const dataList = [
    { label: '火点上报', value: '火点上报' },
    { label: '实况反馈', value: '实况反馈' },
    { label: '启用预案', value: '启用预案' },
    { label: '作战指令', value: '作战指令' },
    { label: '处理推送', value: '处理推送' },
    { label: '推送消息', value: '推送消息' },
    { label: '前线消息', value: '前线消息' },
  ];

  // 新增
  const add = (index: number) => {
    props.optionData.dataset.splice(index + 1, 0, {
      value: '',
    });
  };

  // 减少
  const remove = (index: number) => {
    if (props.optionData.dataset.length !== 1) {
      props.optionData.dataset.splice(index, 1);
    }
  };
</script>
