import Quill from 'quill';

const BlockEmbed = Quill.import('blots/block/embed')

class Audio extends BlockEmbed {
  static create(value) {
    // console.log(value, 'value')
    const node = super.create(value);
    node.setAttribute('src', value.src);
    node.setAttribute('controls', true);
    node.setAttribute('name', value.name.replace(' ', ''));
    node.setAttribute('id', value.id);
    node.setAttribute('poster', value.poster)
    return node;
  }
  // 添加value获取当前的audio元素。拿到audio元素的属性。
  static value(domNode) {
    // console.log(domNode, 'domNode');
    const value = {
      src: '',
      name: '',
      id: '',
      controls: true,
      poster: ''
    };
    // 这里要加判断。不然会显示undefined
    value.src = domNode.getAttribute('src');
    value.name = domNode.getAttribute('name');
    value.poster = domNode.getAttribute('poster');
    value.id = domNode.getAttribute('id');
    return value;
  }
}

Audio.blotName = 'audio'
Audio.className = 'ql-audio'
Audio.tagName = 'audio'

export default Audio