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

export default {
  label: i18n.global.t('window'),
  icon,
  component: Window,
  key: 'lv_win',
  group: i18n.global.t('layout'),
  sort: 1,
  hasChildren: true,
  defaultStyle,
  parts: [
    {
      name: 'main',
      stateList
    },
    {
      name: 'content',
      stateList
    },
    {
      name: 'header',
      stateList
    },
    {
      name: 'button',
      stateList
    }
  ],
  defaultSchema: {
    name: 'window',
    props: {
      x: 0,
      y: 0,
      width: 400,
      height: 250,
      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: [],
      scrollbar: 'off',
      title: 'Title',
      titleHeight: 40,
      text: 'Window Text',
      btns: [
        {
          text: 'button_0',
          type: 'symbol',
          width: 40,
          img_symbol: 'LV_SYMBOL_CLOSE',
          img_id: '',
          img_width: 20,
          img_height: 20,
          img_recolor: '#ffffff00',
          img_alpha: 255,
          enableCover: true,
          enableAlpha: true
        }
      ]
    },
    styles: [
      {
        part: {
          name: 'main',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#eeeeeeff',
          image: {
            imgId: '',
            recolor: '#ffffff00',
            alpha: 255
          }
        },
        border: {
          color: '#000000ff',
          width: 0,
          radius: 0,
          side: ['all']
        },
        outline: {
          color: '#000000ff',
          width: 0,
          pad: 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
          },
          {
            field: 'props.width',
            valueType: 'number',
            componentProps: {
              span: 12
            },
            slots: { prefix: 'W' },
            canUseEventSet: true
          },
          {
            field: 'props.height',
            valueType: 'number',
            componentProps: {
              span: 12
            },
            slots: { prefix: 'H' },
            canUseEventSet: true
          }
        ]
      },
      {
        label: '滚动条',
        field: 'props.scrollbar',
        valueType: 'select',
        componentProps: {
          options: [
            { label: 'On', value: 'on' },
            { label: 'Off', value: 'off' },
            { label: 'Auto', value: 'auto' },
            { label: 'Active', value: 'active' }
          ]
        }
      },
      {
        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.title',
        valueType: 'text',
        labelWidth: '80px',
        componentProps: {
          supportLangues: true,
          type: 'text'
        },
        canUseEventSet: true
      },
      {
        label: '标题高度',
        field: 'props.titleHeight',
        valueType: 'number',
        componentProps: {
          min: 1,
          max: 1000
        },
        labelWidth: '80px',
        canUseEventSet: true
      },
      {
        label: '文本',
        field: 'props.text',
        valueType: 'textarea',
        labelWidth: '80px',
        componentProps: {
          supportLangues: true
        },
        canUseEventSet: true
      },
      {
        label: '按钮组',
        field: 'props.btns',
        render: (val) => {
          return <Config values={val} />
        }
      }
    ],
    // 组件样式
    styles: [
      {
        label: '模块状态',
        field: 'part',
        valueType: 'part'
      },
      {
        valueType: 'dependency',
        name: ['part'],
        dependency: ({ part }) => {
          return part?.name === 'main'
            ? [
                {
                  label: '背景',
                  field: 'background',
                  valueType: 'background'
                },
                {
                  label: '边框',
                  field: 'border',
                  valueType: 'border'
                },
                {
                  label: '轮廓',
                  field: 'outline',
                  valueType: 'outline'
                },
                {
                  label: '阴影',
                  field: 'shadow',
                  valueType: 'shadow'
                },
                {
                  label: '变换',
                  field: 'transform',
                  valueType: 'transform'
                }
              ]
            : part?.name === 'content'
              ? [
                  {
                    label: '背景',
                    field: 'background',
                    valueType: 'background'
                  },
                  {
                    label: '字体',
                    field: 'text',
                    valueType: 'font'
                  },
                  {
                    label: '间距',
                    field: 'spacer',
                    valueType: 'spacer'
                  }
                ]
              : part?.name === 'header'
                ? [
                    {
                      label: '背景',
                      field: 'background',
                      valueType: 'background'
                    },
                    {
                      label: '字体',
                      field: 'text',
                      valueType: 'font'
                    },
                    {
                      label: '间距',
                      field: 'spacer',
                      valueType: 'spacer'
                    },
                    {
                      label: '内边距',
                      field: 'padding',
                      valueType: 'padding'
                    }
                  ]
                : [
                    {
                      label: '背景',
                      field: 'background',
                      valueType: 'background'
                    },
                    {
                      label: '边框',
                      field: 'border',
                      valueType: 'border'
                    },
                    {
                      label: '阴影',
                      field: 'shadow',
                      valueType: 'shadow'
                    }
                  ]
        }
      }
    ]
  }
} as IComponentModelConfig
