import { AssetType } from '@/constant'
import { WidgetType } from '../constant'
import {
  positionConfig,
  toggleTypeConfig
} from './base'

export default {
  type: WidgetType.VIDEO,
  label: '视频',
  icon: 'w-video',
  defaults (scale) {
    return {
      top: 0,
      left: 0,
      width: 300 * scale.width | 0,
      height: 200 * scale.height | 0,
      radius: 0,
      mute: 1,
      sources: [],
      ...toggleTypeConfig.props
    }
  },
  copy ({ sources, mute, ...widget }) {
    widget.sources = sources.map(source => {
      return { ...source }
    })
    widget.mute = 1
    return widget
  },
  options: [
    {
      label: '配置',
      list: [
        {
          key: 'radius',
          label: '圆角',
          type: 'number'
        },
        {
          key: 'mute',
          label: '音频输出',
          type: 'boolean',
          options: {
            display (root) {
              return !root.bgm.length
            },
            callback (root) {
              if (!this.mute) {
                root.widgets.forEach(widget => {
                  if (widget.mute === 0 && widget !== this) {
                    widget.mute = 1
                  }
                })
              }
            },
            active: 0,
            inactive: 1
          }
        },
        ...toggleTypeConfig.options,
        {
          key: 'sources',
          label: '视频',
          type: 'data',
          options: {
            type: [AssetType.VIDEO]
          }
        }
      ]
    },
    positionConfig
  ]
}
