import Line from './Line.vue'
import icon from '../assets/icon/icon_20line.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('line'),
  icon,
  component: Line,
  key: 'lv_line',
  group: i18n.global.t('display'),
  sort: 1,
  defaultStyle,
  parts: [
    {
      name: 'main',
      stateList
    }
  ],
  defaultSchema: {
    name: 'line',
    props: {
      x: 0,
      y: 0,
      width: 80,
      height: 80,
      flags: [
        'LV_OBJ_FLAG_CLICKABLE',
        'LV_OBJ_FLAG_CLICK_FOCUSABLE',
        '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: [],
      points: [
        { x: 0, y: 0 },
        { x: 60, y: 60 }
      ]
    },
    styles: [
      {
        part: {
          name: 'main',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#ffffff00',
          image: {
            imgId: '',
            recolor: '#ffffff00',
            alpha: 255
          }
        },
        line: {
          color: '#777777ff',
          width: 2,
          radius: true
        },
        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: [
          {
            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: 'Y轴反转',
        field: 'props.transformY',
        valueType: 'switch',
        // 配置器隐藏
        hideInForm: true,
        canUseEventSet: true
      },
      {
        label: '属性',
        field: 'props.points',
        valueType: '',
        render: (val) => {
          return <Config values={val} />
        }
      }
    ],
    // 组件样式
    styles: [
      {
        label: '模块状态',
        field: 'part',
        valueType: 'part'
      },
      {
        label: '背景',
        field: 'background',
        valueType: 'background'
      },
      {
        label: '直线',
        field: 'line',
        valueType: 'line'
      }
    ]
  }
} as IComponentModelConfig
