import { WidgetType } from '../constant'
import { positionConfig } from './base'

export default {
  type: WidgetType.LIVE,
  label: '直播',
  icon: 'w-live',
  defaults (scale) {
    return {
      top: 0,
      left: 0,
      width: 300 * scale.width | 0,
      height: 200 * scale.height | 0,
      radius: 0,
      mute: 1,
      url: ''
    }
  },
  copy ({ mute, ...widget }) {
    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
          }
        },
        {
          key: 'url',
          label: '直播地址',
          type: 'textarea',
          options: {
            singleLine: true
          }
        }
      ]
    },
    positionConfig
  ]
}
