<template>
  <CollapseItem name="内容" :expanded="true">
    <SettingItemBox name="ID" :alone="true">
      <n-input
        size="small"
        v-model:value="optionData.boxId"
        :minlength="1"
        type="text"
        placeholder="请输入Id"
      />
    </SettingItemBox> 
  </CollapseItem>
  <CollapseItem name="内容" :expanded="true">
    <SettingItemBox name="文本" :alone="true">
      <n-input
        size="small"
        v-model:value="optionData.labelText"
        :minlength="1"
        type="text"
        placeholder="请输入"
      />
    </SettingItemBox> 
  </CollapseItem>
  <CollapseItem name="样式" :expanded="true">
    <SettingItemBox
      :name="`颜色`"
    >
      <SettingItem name="文字颜色">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.labelColor"
        ></n-color-picker>
      </SettingItem>
      <SettingItem>
        <n-button
          size="small"
          @click="optionData.labelColor = option.labelColor"
        >
          恢复默认
        </n-button>
      </SettingItem>
      <SettingItem name="文字大小">
        <n-input-number
          size="small"
          v-model:value="optionData.labelSize"
          :min="10"
        />
      </SettingItem>
    </SettingItemBox>
  </CollapseItem>
  <CollapseItem name="内容" :expanded="true">
    <SettingItemBox 
      :name="`单位-${index + 1}`"
      v-for="(item, index) in optionData.unitText"
      :key="index"
    >
      <n-input
        size="small"
        v-model:value="optionData.unitText[index]"
        :minlength="1"
        type="text"
        placeholder="请输入"
        
      />
      <n-button ghost @click="optionData.unitText.splice(index, 1)"> - </n-button>
      
    </SettingItemBox> 
    <SettingItem>
      <n-button size="small" @click="optionData.unitText.push('')"> + 新增</n-button>
    </SettingItem>
  </CollapseItem>
  <CollapseItem name="单位样式" :expanded="true">
    <SettingItemBox
      :name="`颜色`"
    >
      <SettingItem name="文字颜色">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.unitColor"
        ></n-color-picker>
      </SettingItem>
      <SettingItem>
        <n-button
          size="small"
          @click="optionData.unitColor = option.unitColor"
        >
          恢复默认
        </n-button>
      </SettingItem>
      <SettingItem name="文字大小">
        <n-input-number
          size="small"
          v-model:value="optionData.unitSize"
          :min="10"
        />
      </SettingItem>
    </SettingItemBox>
  </CollapseItem>
  <CollapseItem name="值样式" :expanded="true">
    <SettingItemBox
      :name="`颜色`"
    >
      <SettingItem name="文字颜色">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.valueColor"
        ></n-color-picker>
      </SettingItem>
      <SettingItem>
        <n-button
          size="small"
          @click="optionData.valueColor = option.valueColor"
        >
          恢复默认
        </n-button>
      </SettingItem>
      <SettingItem name="文字大小">
        <n-input-number
          size="small"
          v-model:value="optionData.valueSize"
          :min="12"
        />
      </SettingItem>
    </SettingItemBox>
  </CollapseItem>
  <CollapseItem name="样式" :expanded="true">
    <SettingItemBox
      :name="`颜色-${index + 1}`"
      v-for="(item, index) in optionData.colors"
      :key="index"
    >
      <SettingItem name="颜色">
        <n-color-picker
          size="small"
          :modes="['hex']"
          v-model:value="optionData.colors[index]"
        ></n-color-picker>
      </SettingItem>
      <SettingItem>
        <n-button
          size="small"
          @click="optionData.colors[index] = option.colors[index]"
        >
          恢复默认
        </n-button>
      </SettingItem>
    </SettingItemBox>
  </CollapseItem>
</template>

<script setup lang="ts">
import { PropType } from 'vue'
import {
  CollapseItem,
  SettingItemBox,
  SettingItem
} from '@/components/Pages/ChartItemSetting'
import { option } from './config'

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