import { h } from 'vue'
import Keyboard from './Keyboard.vue'
import Config from './Config.vue'
import icon from '../assets/icon/icon_29keyboad.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('keyboard'),
  icon,
  component: Keyboard,
  key: 'lv_keyboard',
  group: i18n.global.t('display'),
  sort: 1,
  defaultStyle,
  parts: [
    {
      name: 'main',
      stateList
    },
    {
      name: 'items',
      stateList
    }
  ],
  defaultSchema: {
    name: 'keyboard',
    props: {
      x: 0,
      y: 0,
      width: 500,
      height: 200,
      flags: [
        'LV_OBJ_FLAG_CLICKABLE',
        '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: [],
      mode: 'lower',
      showPopovers: false,
      textareaIds: []
    },
    styles: [
      {
        part: {
          name: 'main',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#f5f5f5ff',
          image: {
            imgId: '',
            recolor: '#ffffff00',
            alpha: 255
          }
        },
        border: {
          color: '#000000ff',
          width: 0,
          radius: 0,
          side: ['all']
        },
        outline: {
          color: '#000000ff',
          width: 0,
          pad: 0
        },
        padding: {
          top: 11,
          right: 11,
          bottom: 11,
          left: 11,
          row: 11,
          column: 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: '模式',
        field: 'props.mode',
        labelWidth: '100px',
        valueType: 'select',
        componentProps: {
          options: [
            { label: 'Lower', value: 'lower' },
            { label: 'Upper', value: 'upper' },
            { label: 'Special', value: 'special' },
            { label: 'Number', value: 'number' }
          ]
        },
        canUseEventSet: true
      },
      {
        label: '弹出提示',
        field: 'props.showPopovers',
        labelWidth: '100px',
        valueType: 'switch',
        canUseEventSet: true
      },
      {
        label: '输入框',
        field: 'props.textareaIds',
        valueType: '',
        render: (value) => h(Config, { values: value })
      }
    ],
    styles: [
      {
        label: '模块/状态',
        field: 'part',
        valueType: 'part'
      },
      {
        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: 'outline',
                  valueType: 'outline'
                },
                {
                  label: '内边距',
                  field: 'padding',
                  valueType: 'padding',
                  componentProps: {
                    hasGap: true
                  }
                },
                {
                  label: '阴影',
                  field: 'shadow',
                  valueType: 'shadow'
                }
              ]
        }
      }
    ]
  }
} as IComponentModelConfig
