<template>
  <CollapseItem name="数据设置" :expanded="true">
    左侧线的样式设置
    <div style="overflow-x: auto">
      <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>
            <th>标题宽度</th>
            <th>标题高度</th>
            <th>边框颜色</th>
            <th>边框宽度</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in props.optionData.dataset[0]" :key="index">
            <td>
              {{ index + 1 }}
            </td>
            <td>
              <div style="width: 70px">
                <n-button class="go-ml-2" type="primary" size="small" ghost @click="addLeft(index)">
                  +
                </n-button>
                <n-button
                  class="go-ml-2"
                  type="warning"
                  size="small"
                  ghost
                  :disabled="props.optionData.dataset[0].length === 1"
                  @click="removeLeft(index)"
                >
                  -
                </n-button>
              </div>
            </td>
            <td>
              <n-input style="width: 100px" v-model:value="item.title" type="text" size="small" />
            </td>
            <td>
              <n-color-picker
                style="width: 80px"
                size="small"
                :modes="['hex']"
                v-model:value="item.color"
              ></n-color-picker>
            </td>
            <td>
              <n-input v-model:value="item.lineWidth" type="text" size="small" />
            </td>
            <td>
              <n-input v-model:value="item.lineHeight" type="text" size="small" />
            </td>
            <td>
              <n-color-picker
                style="width: 80px"
                size="small"
                :modes="['hex']"
                v-model:value="item.borderColor"
              ></n-color-picker>
            </td>
            <td>
              <n-input v-model:value="item.borderWidth" type="text" size="small" />
            </td>
          </tr>
        </tbody>
      </n-table>
    </div>
    <br />
    右侧图的样式设置
    <div style="overflow-x: auto">
      <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>图片URL</th>
            <th>图片宽度</th>
            <th>图片高度</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in props.optionData.dataset[1]" :key="index">
            <td>
              {{ index + 1 }}
            </td>
            <td>
              <div style="width: 70px">
                <n-button
                  class="go-ml-2"
                  type="primary"
                  size="small"
                  ghost
                  @click="addRight(index)"
                >
                  +
                </n-button>
                <n-button
                  class="go-ml-2"
                  type="warning"
                  size="small"
                  ghost
                  :disabled="props.optionData.dataset[0].length === 1"
                  @click="removeRight(index)"
                >
                  -
                </n-button>
              </div>
            </td>
            <td>
              <n-input style="width: 100px" v-model:value="item.title" type="text" size="small" />
            </td>
            <td>
              <n-input style="width: 150px" v-model:value="item.url" type="text" size="small" />
            </td>
            <td>
              <n-input v-model:value="item.imageWidth" type="text" size="small" />
            </td>
            <td>
              <n-input v-model:value="item.imageHeight" type="text" size="small" />
            </td>
          </tr>
        </tbody>
      </n-table>
    </div>
  </CollapseItem>
  <CollapseItem name="样式设置" :expanded="true">
    <SettingItemBox name="整体设置">
      <SettingItem name="背景颜色">
        <n-color-picker
          size="small"
          :modes="['rgb']"
          v-model:value="optionData.dataStyle.backgroud"
        ></n-color-picker>
      </SettingItem>
      <SettingItem name="上方距离">
        <n-input-number
          v-model:value="optionData.dataStyle.marginTop"
          :min="0"
          size="small"
          placeholder="上方距离"
        />
      </SettingItem>
      <SettingItem name="左右距离">
        <n-input-number
          v-model:value="optionData.dataStyle.marginLeft"
          :min="0"
          size="small"
          placeholder="左右距离"
        />
      </SettingItem>
    </SettingItemBox>

    <SettingItemBox name="标题设置">
      <SettingItem name="标题名称">
        <n-input
          v-model:value="optionData.dataStyle.name"
          size="small"
          placeholder="标题名称"
        ></n-input>
      </SettingItem>
      <SettingItem name="标题模块高度">
        <n-input-number
          v-model:value="optionData.dataStyle.nameHeight"
          :min="0"
          size="small"
          placeholder="标题模块高度"
        />
      </SettingItem>
      <SettingItem name="标题宽度">
        <n-input-number
          v-model:value="optionData.dataStyle.nameSpanWidth"
          :min="0"
          size="small"
          placeholder="标题宽度"
        />
      </SettingItem>
      <SettingItem name="标题字体大小">
        <n-input-number
          v-model:value="optionData.dataStyle.nameFontSize"
          :min="0"
          size="small"
          placeholder="标题字体大小"
        />
      </SettingItem>
      <SettingItem name="字体颜色（始）">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.dataStyle.nameFontColor1"
        ></n-color-picker>
      </SettingItem>
      <SettingItem>
        <n-button size="small" @click="optionData.dataStyle.nameFontColor1 = '#ffffff'">
          恢复默认
        </n-button>
      </SettingItem>
      <SettingItem name="字体颜色（终）">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.dataStyle.nameFontColor2"
        ></n-color-picker>
      </SettingItem>
      <SettingItem>
        <n-button size="small" @click="optionData.dataStyle.nameFontColor2 = '#019042'">
          恢复默认
        </n-button>
      </SettingItem>
      <SettingItem name="边框宽度">
        <n-input-number
          v-model:value="optionData.dataStyle.nameBorderWidth"
          :min="0"
          size="small"
          placeholder="边框宽度"
        />
      </SettingItem>
      <SettingItem name="边框颜色">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.dataStyle.nameBorderColor"
        ></n-color-picker>
      </SettingItem>
      <SettingItem name="边框与字体的距离">
        <n-input-number
          v-model:value="optionData.dataStyle.nameFontBorderDistance"
          :min="0"
          size="small"
          placeholder="边框与字体的距离"
        />
      </SettingItem>
      <SettingItem name="边框与图例的距离">
        <n-input-number
          v-model:value="optionData.dataStyle.tupianMarginTop"
          :min="0"
          size="small"
          placeholder="边框与图例的距离"
        />
      </SettingItem>
    </SettingItemBox>

    <n-tag type="primary">修改此处，则修改全部图例的线和图的样式</n-tag>
    <SettingItemBox name="图例设置">
      <SettingItem name="单个图例的高度">
        <n-input-number
          v-model:value="optionData.dataStyle.tupianHeight"
          :min="0"
          size="small"
          placeholder="单个图例的高度"
        />
      </SettingItem>
      <SettingItem name="单个图例的宽度">
        <n-input-number
          v-model:value="optionData.dataStyle.tupianWidth"
          :min="0"
          size="small"
          placeholder="单个图例的宽度"
        />
      </SettingItem>
      <SettingItem name="线的宽度">
        <n-input-number
          v-model:value="optionData.dataStyle.lineLeftWidth"
          :min="0"
          size="small"
          placeholder="线的宽度"
        />
      </SettingItem>
      <SettingItem name="线的高度">
        <n-input-number
          v-model:value="optionData.dataStyle.lineLeftHeight"
          :min="0"
          size="small"
          placeholder="线的高度"
        />
      </SettingItem>
      <SettingItem name="图片的宽度">
        <n-input-number
          v-model:value="optionData.dataStyle.imageLeftWidth"
          :min="0"
          size="small"
          placeholder="图片的宽度"
        />
      </SettingItem>
      <SettingItem name="图片的高度">
        <n-input-number
          v-model:value="optionData.dataStyle.imageLeftHeight"
          :min="0"
          size="small"
          placeholder="图片的高度"
        />
      </SettingItem>
    </SettingItemBox>
  </CollapseItem>
</template>

<script setup lang="ts">
  import { PropType, watch, ref } 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 addLeft = (index: number) => {
    props.optionData.dataset[0].splice(index + 1, 0, {
      title: '',
      color: '#FFFFFF',
      lineWidth: 40,
      lineHeight: 3,
      borderColor: '#FFFFFF',
      borderWidth: 0,
    });
  };

  // 减少
  const removeLeft = (index: number) => {
    if (props.optionData.dataset[0].length !== 1) {
      props.optionData.dataset[0].splice(index, 1);
    }
  };

  // 新增
  const addRight = (index: number) => {
    props.optionData.dataset[1].splice(index + 1, 0, {
      title: '',
      url: '',
      imageWidth: 35,
      imageHeight: 35,
    });
  };

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