import Spinbox from './Spinbox.vue'
import icon from '../assets/icon/icon_28spinbox.svg'
import { flagOptions, stateOptions, stateList, DEFAULT_THEME_KEY } from '@/constants'
import type { IComponentModelConfig } from '../type'
import i18n from '@/locales'
import defaultStyle from './style.json'

export default {
  label: i18n.global.t('spinbox'),
  icon,
  component: Spinbox,
  key: 'lv_spinbox',
  group: i18n.global.t('display'),
  sort: 1,
  hasChildren: false,
  defaultStyle,
  parts: [
    {
      name: 'main',
      stateList
    },
    {
      name: 'cursor',
      stateList
    },
    {
      name: 'leftButton',
      stateList
    },
    {
      name: 'rightButton',
      stateList
    }
  ],
  defaultSchema: {
    name: 'spinbox',
    props: {
      x: 0,
      y: 0,
      width: 160,
      height: 40,
      flags: [
        'LV_OBJ_FLAG_CLICKABLE',
        'LV_OBJ_FLAG_CLICK_FOCUSABLE',
        'LV_OBJ_FLAG_SCROLLABLE',
        'LV_OBJ_FLAG_SCROLL_ELASTIC',
        'LV_OBJ_FLAG_SCROLL_MOMENTUM',
        'LV_OBJ_FLAG_SCROLL_CHAIN_HOR',
        'LV_OBJ_FLAG_SCROLL_CHAIN_VER',
        'LV_OBJ_FLAG_SCROLL_CHAIN',
        'LV_OBJ_FLAG_SCROLL_ON_FOCUS',
        'LV_OBJ_FLAG_SCROLL_WITH_ARROW',
        'LV_OBJ_FLAG_SNAPPABLE',
        'LV_OBJ_FLAG_PRESS_LOCK',
        'LV_OBJ_FLAG_GESTURE_BUBBLE'
      ],
      states: [],
      rangeMin: -100,
      rangeMax: 100,
      step: 1,
      integerDigits: 3,
      decimalPlaces: 2,
      value: 0,
      rollOver: false
    },
    styles: [
      {
        part: {
          name: 'main',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#ffffffff',
          image: {
            imgId: '',
            recolor: '#ffffff00',
            alpha: 255
          }
        },
        text: {
          color: '#212121ff',
          size: 16,
          family: 'montserratMedium',
          align: 'left',
          decoration: 'none'
        },
        spacer: {
          letterSpacing: 0
        },
        border: {
          color: '#e0e0e0ff',
          width: 2,
          radius: 10,
          side: ['all']
        },
        padding: {
          top: 11,
          right: 11,
          bottom: 11,
          left: 11
        },
        shadow: {
          color: '#000000ff',
          offsetX: 0,
          offsetY: 0,
          spread: 0,
          width: 0
        }
      }
    ]
  },
  config: {
    props: [
      {
        label: '名称',
        field: 'name',
        valueType: 'text',
        componentProps: {
          placeholder: '请输入名称',
          type: 'text'
        }
      },
      {
        label: '位置/大小',
        valueType: 'group',
        children: [
          {
            label: '',
            field: 'props.x',
            valueType: 'number',
            componentProps: {
              span: 12,
              min: -10000,
              max: 10000
            },
            slots: { prefix: 'X' },
            canUseEventSet: true
          },
          {
            label: '',
            field: 'props.y',
            valueType: 'number',
            componentProps: {
              span: 12,
              min: -10000,
              max: 10000
            },
            slots: { prefix: 'Y' },
            canUseEventSet: true
          },
          {
            label: '',
            field: 'props.width',
            valueType: 'number',
            componentProps: {
              span: 12,
              min: 1,
              max: 10000
            },
            slots: { prefix: 'W' },
            canUseEventSet: true
          },
          {
            label: '',
            field: 'props.height',
            valueType: 'number',
            componentProps: {
              span: 12,
              min: 1,
              max: 10000
            },
            slots: { prefix: 'H' },
            canUseEventSet: true
          }
        ]
      },
      {
        label: '标识',
        field: 'props.flags',
        valueType: 'checkbox',
        componentProps: {
          options: flagOptions,
          defaultCollapsed: true
        },
        canUseEventSet: true
      },
      {
        label: '状态',
        field: 'props.states',
        valueType: 'checkbox',
        componentProps: {
          options: stateOptions,
          defaultCollapsed: true
        },
        canUseEventSet: true
      }
    ],
    coreProps: [
      {
        label: '范围',
        valueType: 'group',
        canUseEventSet: true,
        children: [
          {
            label: '',
            field: 'props.rangeMin',
            valueType: 'number',
            componentProps: {
              span: 12,
              min: -99999,
              max: 99999
            },
            slots: { prefix: 'min' }
          },
          {
            label: '',
            field: 'props.rangeMax',
            valueType: 'number',
            componentProps: {
              span: 12,
              min: -99999,
              max: 99999
            },
            slots: { prefix: 'max' }
          }
        ]
      },
      {
        label: '步长',
        field: 'props.step',
        valueType: 'number',
        componentProps: {
          min: 1,
          max: 1000
        },
        canUseEventSet: true
      },
      {
        label: '数位',
        valueType: 'group',
        canUseEventSet: true,
        children: [
          {
            label: '',
            field: 'props.integerDigits',
            valueType: 'number',
            componentProps: {
              span: 12,
              min: 1,
              max: 5
            },
            slots: { prefix: '' }
          },
          {
            label: '',
            field: 'props.decimalPlaces',
            valueType: 'number',
            componentProps: {
              span: 12,
              min: 0,
              max: 5
            },
            slots: { prefix: '.' }
          }
        ]
      },
      {
        label: '值',
        field: 'props.value',
        valueType: 'number',
        componentProps: {
          min: -99999,
          max: 99999
        },
        canUseEventSet: true
      },
      {
        label: '值循环',
        field: 'props.rollOver',
        valueType: 'switch',
        canUseEventSet: true
      }
    ],
    styles: [
      {
        label: '模块状态',
        field: 'part',
        valueType: 'part'
      },
      {
        valueType: 'dependency',
        name: ['part'],
        dependency: ({ part }) => {
          if (part?.name === 'main') {
            return [
              {
                label: '背景',
                field: 'background',
                valueType: 'background'
              },
              {
                label: '字体',
                field: 'text',
                valueType: 'font'
              },
              {
                label: '间距',
                field: 'spacer',
                valueType: 'spacer'
              },
              {
                label: '边框',
                field: 'border',
                valueType: 'border'
              },
              {
                label: '内边距',
                field: 'padding',
                valueType: 'padding'
              },
              {
                label: '阴影',
                field: 'shadow',
                valueType: 'shadow'
              }
            ]
          }

          if (part?.name === 'cursor') {
            return [
              {
                label: '背景',
                field: 'background',
                valueType: 'background',
                componentProps: {
                  onlyColor: true
                }
              },
              {
                label: '字体',
                field: 'text',
                valueType: 'font'
              }
            ]
          }

          return [
            {
              label: '背景',
              field: 'background',
              valueType: 'background'
            },
            {
              label: '字体',
              field: 'text',
              valueType: 'font'
            },
            {
              label: '边框',
              field: 'border',
              valueType: 'border'
            },
            {
              label: '阴影',
              field: 'shadow',
              valueType: 'shadow'
            }
          ]
        }
      }
    ]
  }
} as IComponentModelConfig
