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

export default {
  label: i18n.global.t('checkbox'),
  icon,
  component: Checkbox,
  key: 'lv_checkbox',
  group: i18n.global.t('basic'),
  sort: 1,
  defaultStyle,
  parts: [
    {
      name: 'main',
      stateList
    },
    {
      name: 'indicator',
      stateList
    }
  ],
  defaultSchema: {
    name: 'checkbox',
    props: {
      x: 0,
      y: 0,
      flags: [
        'LV_OBJ_FLAG_CLICKABLE',
        'LV_OBJ_FLAG_CLICK_FOCUSABLE',
        'LV_OBJ_FLAG_CHECKABLE',
        '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: [],
      text: 'checkbox',
      isStaticText: false
    },
    styles: [
      {
        part: {
          name: 'main',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#ffffff00',
          image: {
            imgId: '',
            recolor: '#ffffff00',
            alpha: 255
          }
        },
        text: {
          color: '#000000ff',
          family: 'montserratMedium',
          size: 16,
          align: 'center',
          decoration: 'none'
        },
        spacer: {
          letterSpacing: 0,
          lineHeight: 2
        },
        border: {
          color: '#eeeeeeff',
          width: 0,
          radius: 6,
          side: ['all']
        },
        padding: {
          top: 0,
          right: 0,
          bottom: 0,
          left: 0
        },
        shadow: {
          color: '#2092f5ff',
          offsetX: 0,
          offsetY: 0,
          spread: 0,
          width: 0
        },
        transform: {
          width: 0,
          height: 0,
          translateX: 0,
          translateY: 0,
          originX: 0,
          originY: 0,
          rotate: 0,
          scale: 256
        }
      }
    ]
  },
  config: {
    // 组件属性
    props: [
      {
        label: '名称',
        field: 'name',
        valueType: 'text',
        componentProps: {
          placeholder: '请输入名称',
          type: 'text'
        }
      },
      {
        label: '位置',
        valueType: 'group',
        children: [
          {
            field: 'props.x',
            valueType: 'number',
            componentProps: {
              span: 12
            },
            slots: { prefix: 'X' },
            canUseEventSet: true
          },
          {
            field: 'props.y',
            valueType: 'number',
            componentProps: {
              span: 12
            },
            slots: { prefix: 'Y' },
            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: '文本',
        field: 'props.text',
        valueType: 'text',
        componentProps: {
          supportLangues: true,
          type: 'text'
        },
        canUseEventSet: true
      },
      {
        label: '静态文本',
        field: 'props.isStaticText',
        valueType: 'switch',
        labelWidth: '100px'
      }
    ],
    // 组件样式
    styles: [
      {
        label: '模块/状态',
        field: 'part',
        valueType: 'part'
      },
      {
        valueType: 'dependency',
        name: ['part'],
        dependency: ({ part }) => {
          return part?.name === 'main'
            ? [
                {
                  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'
                },
                {
                  label: '变换',
                  field: 'transform',
                  valueType: 'transform'
                }
              ]
            : [
                {
                  label: '背景',
                  field: 'background',
                  valueType: 'background'
                },
                {
                  label: '边框',
                  field: 'border',
                  valueType: 'border'
                },
                {
                  label: '内边距',
                  field: 'padding',
                  valueType: 'padding',
                  componentProps: {
                    allInOne: true
                  }
                }
              ]
        }
      }
    ]
  }
} as IComponentModelConfig
