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

export default {
  label: i18n.global.t('buttonMatrix'),
  icon,
  component: LvButtonMatrix,
  key: 'lv_buttonmatrix',
  group: i18n.global.t('basic'),
  sort: 1,
  defaultStyle,
  parts: [
    {
      name: 'main',
      stateList
    },
    {
      name: 'items',
      stateList
    }
  ],
  defaultSchema: {
    name: 'btnmatrix',
    props: {
      x: 0,
      y: 0,
      width: 200,
      height: 150,
      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_WITH_ARROW',
        'LV_OBJ_FLAG_SNAPPABLE',
        'LV_OBJ_FLAG_PRESS_LOCK',
        'LV_OBJ_FLAG_GESTURE_BUBBLE'
      ],
      states: [],
      isCustom: false,
      col: 3,
      group: [
        [
          {
            name: 'btn_1',
            text: '1',
            type: 'button',
            width: 1,
            style: []
          },
          {
            name: 'btn_2',
            text: '2',
            type: 'button',
            width: 1,
            style: []
          },
          {
            name: 'btn_3',
            text: '3',
            type: 'button',
            width: 1,
            style: []
          }
        ],
        [
          {
            name: 'btn_4',
            text: '4',
            type: 'button',
            width: 1,
            style: []
          },
          {
            name: 'btn_5',
            text: '5',
            type: 'button',
            width: 1,
            style: []
          },
          {
            name: 'btn_6',
            text: '6',
            type: 'button',
            width: 1,
            style: []
          }
        ],
        [
          {
            name: 'btn_7',
            text: '7',
            type: 'button',
            width: 1,
            style: []
          },
          {
            name: 'btn_8',
            text: '8',
            type: 'button',
            width: 1,
            style: []
          },
          {
            name: 'btn_9',
            text: '9',
            type: 'button',
            width: 1,
            style: []
          }
        ]
      ]
    },
    styles: [
      {
        part: {
          name: 'main',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#ffffffff',
          image: {
            imgId: '',
            color: '',
            alpha: 255
          }
        },
        border: {
          color: '#c8c8c8ff',
          width: 1,
          radius: 4,
          side: ['all']
        },
        outline: {
          color: '#000000ff',
          width: 0,
          pad: 0
        },
        padding: {
          top: 12,
          right: 12,
          bottom: 12,
          left: 12,
          row: 8,
          column: 8
        },
        transform: {
          width: 0,
          height: 0,
          translateX: 0,
          translateY: 0,
          originX: 0,
          originY: 0,
          rotate: 0,
          scale: 256
        }
      },
      {
        part: {
          name: 'items',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#2092f5ff',
          image: {
            imgId: '',
            recolor: '#00000000',
            alpha: 255
          }
        },
        text: {
          color: '#ffffffff',
          family: 'montserratMedium',
          size: 16,
          align: 'center',
          decoration: 'none'
        },
        border: {
          color: '#c8c8c8ff',
          width: 1,
          radius: 4,
          side: ['all']
        },
        shadow: {
          color: '#2092f5ff',
          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: '列数',
        field: 'props.col',
        valueType: 'number',
        componentProps: {
          min: 1,
          max: 5,
          step: 1
        }
      },
      // {
      //   label: '自定义',
      //   field: 'props.isCustom',
      //   valueType: 'switch'
      // },
      {
        label: '属性',
        field: '',
        valueType: '',
        render: (val) => {
          return <Config values={val} />
        }
      }
    ],
    // 组件样式
    styles: [
      {
        label: '模块状态',
        field: 'part',
        valueType: 'part',
        componentProps: {
          filterPartOptions: (item, formData) => {
            return {
              label: item.name,
              value: item.name,
              disabled: formData.props?.isCustom && item.name === 'items'
            }
          }
        }
      },
      {
        label: '背景',
        field: 'background',
        valueType: 'background'
      },
      {
        label: '边框',
        field: 'border',
        valueType: 'border'
      },
      {
        valueType: 'dependency',
        name: ['part'],
        dependency: ({ part }) => {
          return part?.name === 'items'
            ? [
                {
                  label: '字体',
                  field: 'text',
                  valueType: 'font'
                },
                {
                  label: '阴影',
                  field: 'shadow',
                  valueType: 'shadow'
                }
              ]
            : [
                {
                  label: '轮廓',
                  field: 'outline',
                  valueType: 'outline'
                },
                {
                  label: '内边距',
                  field: 'padding',
                  valueType: 'padding',
                  componentProps: {
                    hasGap: true
                  }
                },
                {
                  label: '变换',
                  field: 'transform',
                  valueType: 'transform'
                }
              ]
        }
      }
    ]
  }
} as IComponentModelConfig
