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

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