import Textarea from './Textarea.vue'
import icon from '../assets/icon/icon_label.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('textarea'),
  icon,
  component: Textarea,
  key: 'lv_textarea',
  group: i18n.global.t('basic'),
  sort: 1,
  defaultStyle,
  parts: [
    {
      name: 'main',
      stateList
    },
    {
      name: 'scrollbar',
      stateList
    }
  ],
  defaultSchema: {
    name: 'textarea',
    props: {
      x: 0,
      y: 0,
      width: 260,
      height: 130,
      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_ON_FOCUS',
        'LV_OBJ_FLAG_SNAPPABLE',
        'LV_OBJ_FLAG_PRESS_LOCK',
        'LV_OBJ_FLAG_GESTURE_BUBBLE'
      ],
      states: [],
      text: 'hello world',
      placeholder: '',
      maxLength: 32,
      allowString: '',
      passwordMode: false,
      passwordReplaceText: '',
      nowrap: false
    },
    styles: [
      {
        part: {
          name: 'main',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#ffffffff',
          image: {
            imgId: '',
            recolor: '#ffffff00',
            alpha: 255
          }
        },
        text: {
          color: '#000000ff',
          family: 'montserratMedium',
          size: 12,
          align: 'left',
          decoration: 'none'
        },
        spacer: {
          letterSpacing: 2,
          lineHeight: 0
        },
        border: {
          color: '#e6e6e6ff',
          width: 2,
          radius: 4,
          side: ['all']
        },
        outline: {
          color: '#000000ff',
          width: 0,
          pad: 0
        },
        padding: {
          top: 4,
          right: 4,
          bottom: 4,
          left: 4
        },
        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
        }
      },
      {
        part: {
          name: 'scrollbar',
          state: 'default'
        },
        theme: DEFAULT_THEME_KEY,
        background: {
          color: '#2195f6ff'
        },
        border: {
          radius: 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.text',
        valueType: 'text',
        labelWidth: '80px',
        componentProps: {
          useSymbol: true,
          supportLangues: true,
          type: 'text'
        },
        canUseEventSet: true
      },
      {
        label: '提示文本',
        field: 'props.placeholder',
        valueType: 'text',
        labelWidth: '80px',
        componentProps: {
          supportLangues: true,
          type: 'text'
        },
        canUseEventSet: true
      },
      {
        label: '最大长度',
        field: 'props.maxLength',
        valueType: 'number',
        componentProps: {
          min: 0,
          step: 1
        },
        labelWidth: '80px',
        canUseEventSet: true
      },
      {
        label: '有效字符',
        field: 'props.allowString',
        valueType: 'text',
        labelWidth: '80px',
        canUseEventSet: true
      },
      {
        label: '密码模式',
        field: 'props.passwordMode',
        valueType: 'switch',
        labelWidth: '80px',
        canUseEventSet: true
      },
      {
        valueType: 'dependency',
        name: ['props.passwordMode'],
        dependency: (dependency) => {
          return dependency['props.passwordMode']
            ? [
                {
                  label: '替换字符',
                  field: 'props.passwordReplaceText',
                  valueType: 'text',
                  labelWidth: '80px',
                  componentProps: {
                    maxlength: 10
                  }
                }
              ]
            : []
        }
      },
      {
        label: '单行模式',
        field: 'props.nowrap',
        valueType: 'switch',
        labelWidth: '80px',
        canUseEventSet: true
      }
    ],
    // 组件样式
    styles: [
      {
        label: '模块状态',
        field: 'part',
        valueType: 'part'
      },
      {
        name: ['part'],
        valueType: 'dependency',
        dependency: ({ part }) => {
          return part?.name === 'scrollbar'
            ? [
                {
                  label: '背景',
                  field: 'background',
                  valueType: 'background'
                },
                {
                  label: '边框',
                  field: 'border',
                  valueType: 'border',
                  componentProps: {
                    onlyRadius: true
                  }
                }
              ]
            : [
                {
                  label: '背景',
                  field: 'background',
                  valueType: 'background'
                },
                {
                  label: '字体',
                  field: 'text',
                  valueType: 'font'
                },
                {
                  label: '间距',
                  field: 'spacer',
                  valueType: 'spacer'
                },
                {
                  label: '边框',
                  field: 'border',
                  valueType: 'border'
                },
                {
                  label: '轮廓',
                  field: 'outline',
                  valueType: 'outline'
                },
                {
                  label: '内边距',
                  field: 'padding',
                  valueType: 'padding'
                },
                {
                  label: '阴影',
                  field: 'shadow',
                  valueType: 'shadow'
                },
                {
                  label: '变换',
                  field: 'transform',
                  valueType: 'transform'
                }
              ]
        }
      }
    ]
  }
} as IComponentModelConfig
