<template>
  <collapse-item name="属性" :expanded="true">
    <setting-item-box name="路径" :alone="true">
      <setting-item>
        <n-input v-model:value="optionData.dataset" size="small"></n-input>
        <n-button @click="openModal">修改图片</n-button>
      </setting-item>
    </setting-item-box>
    <setting-item-box name="样式">
      <setting-item name="类型">
        <n-select
          v-model:value="optionData.fit"
          size="small"
          :options="fitList"
        ></n-select>
      </setting-item>
      <setting-item name="圆角">
        <n-input-number
          v-model:value="optionData.borderRadius"
          size="small"
          :min="0"
          placeholder="圆角"
        ></n-input-number>
      </setting-item>
    </setting-item-box>
    <a-modal 
      class="photo-control-modal"
      v-model:open="openChangePhotoModal"
      width="1340px"
      style="top: 90px"
      :footer="null"
      :closable="false"
      :zIndex="3000"
      :destroyOnClose="true"
    >
      <PhotoModal :readonly="true" @closePhotoModal="closePhotoModal" @saveChangePhoto="saveChangePhoto"/>
    </a-modal>
  </collapse-item>
</template>

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

const props = defineProps({
  optionData: {
    type: Object as PropType<typeof option>,
    required: true,
  },
})
const openChangePhotoModal = ref(false)
const closePhotoModal = () => {
  openChangePhotoModal.value = false
}
const saveChangePhoto = (url) => {
  props.optionData.dataset = url
  openChangePhotoModal.value = false
}

// 适应类型
const fitList = [
  {
    value: 'fill',
    label: 'fill'
  },
  {
    value: 'contain',
    label: 'contain'
  },
  {
    value: 'cover',
    label: 'cover'
  },
  {
    value: 'scale-down',
    label: 'scale-down'
  },
  {
    value: 'none',
    label: 'none'
  },
]
const openModal = () => {
  openChangePhotoModal.value = true
}
</script>
