import $$1 from 'jquery';
import Pj, { deregister, eventable, register, stateable, styleable } from '@pluginjs/pluginjs';

let Plugin = class Plugin {
  constructor(namespace, element) {
    this.plugin = namespace;
    this.element = element;
    this.$element = $$1(element);
  }

  getDataOptions() {
    const data = this.$element.data();
    let length = 0;
    const newData = {};

    $$1.each(data, () => {
      length++;
    });

    if (length > 0) {
      $$1.each(data, (name, content) => {
        let cache = {};
        const items = name.split('-');
        // let items = name.split('-');

        const deep = items.length;

        if (deep > 1) {
          for (let j = 0; j < deep; j++) {
            const item = items[j].substring(0, 1).toLowerCase() + items[j].substring(1);

            if (j === 0) {
              cache[item] = {};
            } else if (j === deep - 1) {} else {}
          }
        } else if (items[0] === `as${this.plugin.substring(0, 1).toUpperCase()}${this.plugin.substring(1)}`) {
          cache = content;
        } else {
          cache[name] = content;
        }

        $$1.extend(newData, cache);
      });
    }

    return newData;
  }

  destroy() {
    this.plugin = null;
    this.element = null;
    this.$element = null;
  }
};

const namespace = 'video';

const events = {
  READY: 'ready',
  DESTROY: 'destroy',
  LOAD: 'load',
  LOADED: 'loaded',
  PLAY: 'play',
  PAUSE: 'pause',
  STOP: 'stop',
  PLAYEND: 'playend',
  PLAYERR: 'playerr'
};

const classes = {
  NAMESPACE: `pj-${namespace}`,
  THEME: '{namespace}--{theme}',
  POSTER: '{namespace}-poster'
};

const methods = ['enable', 'disable', 'destroy', 'pause', 'load', 'play', 'stop', 'volume'];

const defaults = {
  template() {
    return '<div class="{classes.NAMESPACE}">' + '{poster}' + '</div>';
  },
  templates: { poster() {
      return '<div class="{classes.POSTER}"></div>';
    } },
  url: '',
  id: '',
  type: '',
  autoplay: true,
  loop: true,
  controls: false,
  poster: ''
};

const info = { version: '0.0.1' };

/* eslint no-undef: "off" */

/* Credit to http://featurejs.com MIT */
/**
 * Test if it's an old device that we want to filter out
 */
/**
 * Function that takes a standard CSS property name as a parameter and
 * returns it's prefixed version valid for current browser it runs in
 */
const pfx = function () {
  const prefixes = ['Webkit', 'Moz', 'O', 'ms'];
  const memory = {};
  const style = document.createElement('dummy').style;
  return function (prop) {
    if (typeof memory[prop] === 'undefined') {
      const ucProp = prop.charAt(0).toUpperCase() + prop.substr(1);
      const props = `${prop} ${prefixes.join(`${ucProp} `)}${ucProp}`.split(' ');
      memory[prop] = null;

      for (const i in props) {
        if (style[props[i]] !== undefined) {
          memory[prop] = props[i];
          break;
        }
      }
    }
    return memory[prop];
  };
}();

const transitionEndEvent = () => {
  const eventNames = {
    transition: 'transitionend',
    OTransition: 'oTransitionEnd',
    MozTransition: 'transitionend',
    WebkitTransition: 'webkitTransitionEnd'
  };
  const style = document.createElement('dummy').style;
  for (const i in eventNames) {
    if (eventNames.hasOwnProperty(i)) {
      if (style[i] !== undefined) {
        return eventNames[i];
      }
    }
  }
  return false;
};

var asyncGenerator = function () {
  function AwaitValue(value) {
    this.value = value;
  }

  function AsyncGenerator(gen) {
    var front, back;

    function send(key, arg) {
      return new Promise(function (resolve, reject) {
        var request = {
          key: key,
          arg: arg,
          resolve: resolve,
          reject: reject,
          next: null
        };

        if (back) {
          back = back.next = request;
        } else {
          front = back = request;
          resume(key, arg);
        }
      });
    }

    function resume(key, arg) {
      try {
        var result = gen[key](arg);
        var value = result.value;

        if (value instanceof AwaitValue) {
          Promise.resolve(value.value).then(function (arg) {
            resume("next", arg);
          }, function (arg) {
            resume("throw", arg);
          });
        } else {
          settle(result.done ? "return" : "normal", result.value);
        }
      } catch (err) {
        settle("throw", err);
      }
    }

    function settle(type, value) {
      switch (type) {
        case "return":
          front.resolve({
            value: value,
            done: true
          });
          break;

        case "throw":
          front.reject(value);
          break;

        default:
          front.resolve({
            value: value,
            done: false
          });
          break;
      }

      front = front.next;

      if (front) {
        resume(front.key, front.arg);
      } else {
        back = null;
      }
    }

    this._invoke = send;

    if (typeof gen.return !== "function") {
      this.return = undefined;
    }
  }

  if (typeof Symbol === "function" && Symbol.asyncIterator) {
    AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
      return this;
    };
  }

  AsyncGenerator.prototype.next = function (arg) {
    return this._invoke("next", arg);
  };

  AsyncGenerator.prototype.throw = function (arg) {
    return this._invoke("throw", arg);
  };

  AsyncGenerator.prototype.return = function (arg) {
    return this._invoke("return", arg);
  };

  return {
    wrap: function (fn) {
      return function () {
        return new AsyncGenerator(fn.apply(this, arguments));
      };
    },
    await: function (value) {
      return new AwaitValue(value);
    }
  };
}();

/* Credit to https://github.com/jonschlinkert/get-value MIT */
function getValueByPath(obj, path) {
  if (Object(obj) !== obj || typeof path === 'undefined') {
    return obj;
  }

  if (path in obj) {
    return obj[path];
  }

  const segs = path.split('.');
  const length = segs.length;
  if (!length) {
    return undefined;
  }
  let i = -1;

  while (obj && ++i < length) {
    let key = segs[i];
    while (key[key.length - 1] === '\\') {
      key = `${key.slice(0, -1)}.${segs[++i]}`;
    }
    obj = obj[key];
  }
  return obj;
}

const asTransitionEnd = 'asTransitionEnd';

function triggerTransitionEnd(element) {
  $$1(element).trigger(transitionEndEvent());
}
function setTransitionEndSupport() {
  $$1.fn.asTransitionEnd = function (duration) {
    let called = false;

    $$1(this).one(asTransitionEnd, () => {
      called = true;
    });

    setTimeout(() => {
      if (!called) {
        triggerTransitionEnd(this);
      }
    }, duration);

    return this;
  };

  const isTransitionEndEvent = transitionEndEvent();

  if (isTransitionEndEvent) {
    // suport transition end
    $$1.event.special[asTransitionEnd] = {
      bindType: isTransitionEndEvent,
      delegateType: isTransitionEndEvent,
      handle(event) {
        if ($$1(event.target).is(this)) {
          return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params
        }
        return undefined;
      }
    };
  }
}

setTransitionEndSupport();

/* Credit to https://github.com/Matt-Esch/string-template MIT */
const template = function () {
  const pattern = /\{\s*([.0-9a-zA-Z_]+)\s*\}/g;

  function render(string, ...args) {
    if (args.length === 1 && typeof args[0] === 'object') {
      args = args[0];
    }

    if (!args || !args.hasOwnProperty) {
      args = {};
    }

    return string.replace(pattern, (match, i, index) => {
      let result = null;

      if (string[index - 1] === '{' && string[index + match.length] === '}') {
        return i;
      }

      if (args.hasOwnProperty(i)) {
        result = args[i];
      } else if (i.indexOf('.') !== -1) {
        result = getValueByPath(args, i);
      }

      if (result === null || result === undefined) {
        return '';
      }

      return result;
    });
  }

  return {
    render,
    compile(str) {
      return function (...args) {
        return render(str, ...args);
      };
    },
    parse(str) {
      const matches = str.match(pattern);

      if (matches === null) {
        return false;
      }

      const parsed = [];
      for (let i = 0; i < matches.length; i++) {
        if (!matches[i].match(/^\{\{.+\}\}$/g)) {
          parsed.push(matches[i].substring(1, matches[i].length - 1).trim());
        }
      }

      return parsed;
    }
  };
}();

/*eslint-disable */
/* Credit to http://is.js.org MIT */
const toString = Object.prototype.toString;
const is = {
  // Type checks
  /* -------------------------------------------------------------------------- */
  // is a given value Arguments?
  arguments: function (value) {
    // fallback check is for IE
    return toString.call(value) === '[object Arguments]' || value != null && typeof value === 'object' && 'callee' in value;
  },

  // is a given value Array?
  array: function (val) {
    if (Array.isArray) {
      return Array.isArray(val);
    }
    return toString.call(val) === '[object Array]';
  },

  // is a given value Boolean?
  boolean: function (val) {
    return val === true || val === false || toString.call(val) === '[object Boolean]';
  },

  // is a given value Char?
  char: function (val) {
    return this.string(val) && val.length === 1;
  },

  // is a given value Date Object?
  date: function (value) {
    return toString.call(value) === '[object Date]';
  },

  // is a given object a DOM node?
  domNode: function (object) {
    return this.object(object) && object.nodeType > 0;
  },

  // is a given value Error object?
  error: function (val) {
    return toString.call(val) === '[object Error]';
  },

  // is a given value function?
  function: function (val) {
    // fallback check is for IE
    return toString.call(val) === '[object Function]' || typeof val === 'function';
  },

  // is given value a pure JSON object?
  json: function (value) {
    return toString.call(value) === '[object Object]';
  },

  // is a given value NaN?
  nan: function (val) {
    // NaN is number :) Also it is the only value which does not equal itself
    return val !== val;
  },

  // is a given value null?
  null: function (val) {
    return val === null;
  },

  // is a given value number?
  number: function (val) {
    return !this.nan(val) && toString.call(val) === '[object Number]';
  },

  // is a given value object?
  object: function (val) {
    return Object(val) === val;
  },

  // is a given value empty object?
  emptyObject: function (val) {
    return this.object(val) && Object.getOwnPropertyNames(val).length == 0;
  },

  // is a given value RegExp?
  regexp: function (val) {
    return toString.call(val) === '[object RegExp]';
  },

  // is a given value String?
  string: function (val) {
    return typeof val === 'string' || toString.call(val) === '[object String]';
  },

  // is a given value undefined?
  undefined: function (val) {
    return val === void 0;
  },

  // Arithmetic checks
  /* -------------------------------------------------------------------------- */
  // is a given value numeric?
  numeric: function (n) {
    return (this.number(n) || this.string(n)) && !this.nan(n - parseFloat(n));
  },

  // is a given number percentage?
  percentage: function (n) {
    return typeof n === 'string' && n.indexOf('%') !== -1;
  },

  // is a given number decimal?
  decimal: function (n) {
    return this.number(n) && n % 1 !== 0;
  },

  // is a given number finite?
  finite: function (n) {
    if (isFinite) {
      return isFinite(n);
    }
    return !this.infinite(n) && !this.nan(n);
  },

  // is a given number infinite?
  infinite: function (n) {
    return n === Infinity || n === -Infinity;
  },

  integer: function (n) {
    return this.number(n) && n % 1 === 0;
  },

  // is a given number negative?
  negative: function (n) {
    return this.number(n) && n < 0;
  },

  // is a given number positive?
  positive: function (n) {
    return this.number(n) && n > 0;
  }
};

let Html5 = class Html5 {
  constructor(video, element, options) {
    this.element = element;
    this.options = options;
    this.video = video;
    this.classes = video.classes;
  }

  load() {
    console.log('load html5 html');
    this.$wrap = $(this.createHtml());
    this.$wrap.appendTo(this.element);
    if (this.options.poster) {
      this.$poster = this.$wrap.find(`.${this.video.classes.POSTER}`);
      this.$poster.css({ 'background-image': `url(${this.options.poster})` });
    }

    this.$video = $('<video></video>');
    this.setdefault();
    this.$video.appendTo(this.$wrap);

    this.video.trigger(events.LOAD);
    this.video.trigger(events.LOADED);
    if (this.options.poster) {
      this.$poster.hide();
    }
    this.bind();
  }

  setdefault() {
    if (is.array(this.options.url)) {
      for (let i = 0; i < this.options.url.length; i++) {
        const videoTypeArr = this.options.url[i].split('.');
        const videoType = videoTypeArr[videoTypeArr.length - 1];

        this.addSourceToVideo(this.options.url[i], videoType);
      }
    } else {
      const videoTypeArr = this.options.url.split('.');
      const videoType = videoTypeArr[videoTypeArr.length - 1];

      this.addSourceToVideo(this.options.url, videoType);
    }

    this.$video[0].autoplay = this.options.autoplay;
    this.$video[0].controls = this.options.controls;
    this.$video[0].loop = this.options.loop;
  }

  createHtml() {
    let poster = '';

    if (this.options.poster !== '') {
      poster = template.render(this.options.templates.poster.call(this), { classes: this.classes });
    }

    const html = template.render(this.options.template.call(this), {
      classes: this.classes,
      poster
    });
    return html;
  }

  addSourceToVideo(src, type) {
    const source = document.createElement('source');

    source.src = src;
    source.type = `video/${type}`;

    this.$video[0].appendChild(source);
  }

  setSize(width, height) {
    this.$wrap.css('width', width);
    this.$wrap.css('height', height);
  }

  switchVideo(id) {
    this.$video[0].src = id;
  }

  bind() {
    this.eventListener('play');
    this.eventListener('pause');
    this.eventListener('error');
    // this.eventListener('stalled')
  }

  eventListener(event) {
    const capitalEvent = event.toUpperCase();
    this.$video.on(event, () => {
      this.video.trigger(events[capitalEvent]);
    });
  }

  currentTime() {
    return this.$video[0].currentTime;
  }

  duration() {
    return this.$video[0].duration;
  }

  setCurrentTime(val) {
    this.$video[0].currentTime = val;
  }

  pause() {
    this.$video[0].pause();
  }

  play() {
    this.$video[0].play();
  }

  mute() {
    this.$video[0].muted = true;
  }

  unMute() {
    this.$video[0].muted = false;
  }

  stop() {
    this.$video[0].currentTime = 0;
    this.$video[0].pause();
    this.video.trigger(events.STOP);
  }

  volume(value) {
    this.$video[0].volume = value / 100;
  }

  destroy() {
    const element = this.$wrap.find('video');
    if (element.length) {
      element[0].src = '//about:blank';
    }
    this.$wrap.remove();
  }
};

window.AsVimeoAPIReady = false;

let Vimeo = class Vimeo {
  constructor(video, element, options) {
    this.element = element;
    this.options = options;
    this.video = video;
    this.classes = video.classes;
  }

  load() {
    this.$wrap = $$1(this.createHtml());
    this.$wrap.appendTo(this.element);
    if (this.options.poster) {
      this.$poster = this.$wrap.find(`.${this.video.classes.POSTER}`);
      this.$poster.css({ 'background-image': `url(${this.options.poster})` });
    }

    if (window.AsVimeoAPIReady) {
      this.init();
      this.video.trigger(events.LOAD);
    } else {
      this.loadApi();
      Pj.$window.on('AsVideoVimeoAPIReady', () => {
        this.init();
        this.video.trigger(events.LOAD);
      });
    }
  }

  init() {
    const playerSettings = {
      id: this.getId(),
      loop: this.options.loop,
      autoplay: this.options.autoplay,
      // height:400,
      // url:'https://player.vimeo.com/video/76979871',
      title: false, // defaults to true
      portrait: false, // Show the user’s portrait on the video. Defaults to true.
      // maxwidth: '',
      // maxheight '',
      xhtml: false, // Make the embed code XHTML compliant. Defaults to false.
      byline: false, // Show the byline on the video. Defaults to true.
      autopause: false // Pause this video automatically when another one plays. Defaults to true.
    };

    this.media = new window.Vimeo.Player(this.$wrap[0], playerSettings);
    this.bind();
  }

  getId() {
    if (this.options.id) {
      return this.options.id;
    } else if (this.options.url) {
      return this.options.url.split('/')[3].split('?')[0];
    }
    return undefined;
  }

  createHtml() {
    let poster = '';

    if (this.options.poster !== '') {
      poster = template.render(this.options.templates.poster.call(this), { classes: this.classes });
    }

    const html = template.render(this.options.template.call(this), {
      classes: this.classes,
      poster
    });
    return html;
  }

  loadApi() {
    const tag = document.createElement('script');
    tag.src = 'https://player.vimeo.com/api/player.js';
    document.querySelector('body').appendChild(tag);

    const event = document.createEvent('Event');
    event.initEvent('AsVideoVimeoAPIReady', true, true);
    let count = 1;
    const vimeoApiReady = setInterval(() => {
      if (count > 50) {
        clearInterval(vimeoApiReady);
        console.log('loadApi error');
        this.video.destroy();
      }
      count++;
      if (typeof window.Vimeo === 'undefined') {
        return;
      }
      window.AsVimeoAPIReady = true;
      window.dispatchEvent(event);
      clearInterval(vimeoApiReady);
    }, 350);
  }

  bind() {
    this.media.on('play', () => {
      this.video.trigger(events.PLAY);
    });
    this.media.on('pause', () => {
      this.video.trigger(events.PAUSE);
    });
    this.media.on('loaded', () => {
      this.video.trigger(events.LOADED);
      if (this.options.poster) {
        this.$poster.hide();
      }
    });
  }

  setSize(width, height) {
    this.$wrap.css('width', width);
    this.$wrap.css('height', height);
  }

  switchVideo(id) {
    this.media.loadVideo(id);
  }

  _currentTime() {
    this.media.getCurrentTime().then(seconds => {
      this.options.currentTime = seconds;
    });
  }

  currentTime() {
    this._currentTime();
    return this.options.currentTime;
  }

  _duration() {
    return this.media.getDuration().then(duration => {
      this.options.duration = duration;
    });
  }

  duration() {
    this._duration();
    return this.options.duration;
  }

  setCurrentTime(val) {
    this.media.setCurrentTime(val);
  }

  stop() {
    this.media.setCurrentTime(0);
    this.media.pause();
    this.video.trigger(events.STOP);
  }

  mute() {
    this.volume(0);
  }

  unMute() {
    this.volume(50);
  }

  pause() {
    this.media.pause();
    this.video.trigger('pause');
  }

  volume(value) {
    this.media.setVolume(value / 100);
  }

  play() {
    this.media.play();
  }

  destroy() {
    const element = this.$wrap.find('iframe');
    if (element.length) {
      element[0].src = '//about:blank';
    }
    this.$wrap.remove();
  }
};

window.AsYTAPIReady = false;

let Youtube = class Youtube {
  constructor(video, element, options) {
    this.element = element;
    this.options = options;
    this.video = video;
    this.classes = video.classes;
  }

  load() {
    this.$wrap = $$1(this.createHtml());
    this.$wrap.appendTo(this.element);
    if (this.options.poster) {
      this.$poster = this.$wrap.find(`.${this.video.classes.POSTER}`);
      this.$poster.css({ 'background-image': `url(${this.options.poster})` });
    }

    if (window.AsYTAPIReady) {
      this.init();
      this.video.trigger(events.LOAD);
    } else {
      this.loadApi();
    }
  }

  init() {
    this.$iframe = $$1('<div></div>');
    this.$iframe.appendTo(this.$wrap);

    this.setdefault();

    const playerSettings = {
      volume: 0, // 0 - 100
      autohide: 0, // autohide controls
      autoplay: this.options.autoplay, // autoplay on load
      color: 'red', // red, white
      controls: this.options.controls, // show control UI
      disablekb: 0, // enable/disable keyboard control
      enablejsapi: 1,
      fs: 0, // display fullscreen button
      hl: null, // interface language
      // iv_load_policy: 3,
      loop: 1, // loop video flag (doesn't work properly)
      modestbranding: 1, // show/hide youtube logo
      playsinline: 0,
      rel: 0, // shows relative videos
      showinfo: 0,
      start: 0, // set beginning of the video
      end: 0, // set end of the video
      quality: 'default' // small, medium, large, hd720, hd1080, highres or default
    };

    this.media = new YT.Player(this.$iframe[0], {
      videoId: this.getId(),
      mute: true,
      repeat: true,
      playButtonClass: 'YTPlayer-play',
      pauseButtonClass: 'YTPlayer-pause',
      muteButtonClass: 'YTPlayer-mute',
      volumeUpClass: 'YTPlayer-volume-up',
      volumeDownClass: 'YTPlayer-volume-down',
      start: 0,
      pauseOnScroll: false,
      fitToBackground: true,
      playerVars: playerSettings,
      events: { onReady: () => {
          this.video.trigger(events.LOADED);
          if (this.options.poster) {
            this.$poster.hide();
          }
        } }
    });
    this.bind();
  }

  getId() {
    if (this.options.id) {
      return this.options.id;
    } else if (this.options.url) {
      return this.options.url.split('/')[3].split('?v=')[1];
    }
    return undefined;
  }

  loadApi() {
    $$1.getScript('//www.youtube.com/iframe_api', (response, status) => {
      console.log('text status', status);
      window.AsYTAPIReady = true;

      window.onYouTubeIframeAPIReady = () => {
        this.init();
        this.video.trigger(events.LOAD);
      };
    });
  }

  setdefault() {
    this.options.autoplay = this.options.autoplay ? 1 : 0;
    this.options.controls = this.options.controls ? 1 : 0;
  }

  setSize(width, height) {
    this.$wrap.css('width', width);
    this.$wrap.css('height', height);
  }

  switchVideo(id) {
    this.media.loadVideoById({ videoId: id });
  }

  createHtml() {
    let poster = '';

    if (this.options.poster !== '') {
      poster = template.render(this.options.templates.poster.call(this), { classes: this.classes });
    }
    console.log('text', this.classes);
    const html = template.render(this.options.template.call(this), {
      classes: this.classes,
      poster
    });
    return html;
  }

  bind() {
    this.media.addEventListener('onStateChange', event => {
      if (event.data === 1) {
        this.video.trigger(events.PLAY);
      } else if (event.data === 2) {
        this.video.trigger(events.PAUSE);
      } else if (event.data === 0) {
        this.video.trigger(events.PLAYEND);
        if (this.options.loop === true) {
          this.play();
        }
      }
    });
    this.media.addEventListener('onError', () => {
      this.video.trigger(events.PLAYERR);
    });
  }

  currentTime() {
    return this.media.getCurrentTime();
  }

  duration() {
    return this.media.getDuration();
  }

  setCurrentTime(val) {
    this.media.seekTo(val, true);
  }

  volume(value) {
    this.media.setVolume(value);
  }

  mute() {
    this.media.mute();
  }

  unMute() {
    this.media.unMute();
  }

  pause() {
    this.media.pauseVideo();
  }

  stop() {
    this.media.stopVideo();
    this.video.trigger(events.STOP);
  }

  play() {
    this.media.playVideo();
  }

  destroy() {
    const element = this.$wrap.find('iframe');
    if (element.length) {
      element[0].src = '//about:blank';
    }
    this.$wrap.remove();
  }
};

var _dec;
var _dec2;
var _dec3;
var _dec4;
var _class;
var _class2;

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
  var desc = {};
  Object['ke' + 'ys'](descriptor).forEach(function (key) {
    desc[key] = descriptor[key];
  });
  desc.enumerable = !!desc.enumerable;
  desc.configurable = !!desc.configurable;

  if ('value' in desc || desc.initializer) {
    desc.writable = true;
  }

  desc = decorators.slice().reverse().reduce(function (desc, decorator) {
    return decorator(target, property, desc) || desc;
  }, desc);

  if (context && desc.initializer !== void 0) {
    desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
    desc.initializer = undefined;
  }

  if (desc.initializer === void 0) {
    Object['define' + 'Property'](target, property, desc);
    desc = null;
  }

  return desc;
}

const sources = {};

let Video = (_dec = styleable(classes), _dec2 = eventable(events), _dec3 = stateable(), _dec4 = register(namespace, {
  defaults: defaults,
  methods: methods
}, info), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = (_class2 = class Video extends Plugin {
  constructor(element, options = {}) {
    super(namespace, element);

    this.options = $$1.extend(true, {}, defaults, options, this.getDataOptions());
    this.initClasses(classes);
    this.initStates();
    this.initialize();
  }

  initialize() {
    if (typeof sources[this.options.type] !== 'undefined') {
      this.player = new sources[this.options.type](this, this.$element, this.options);
    }

    this.enter('initialized');
    this.trigger(events.READY);
  }

  load() {
    if (!this.is('loaded')) {
      this.player.load();
      this.enter('loaded');
    }
  }

  switchVideo(id) {
    this.player.switchVideo(id);
  }

  duration() {
    return this.player.duration();
  }

  currentTime() {
    return this.player.currentTime();
  }

  setCurrentTime(val) {
    this.player.setCurrentTime(val);
  }

  setSize(width, height) {
    this.player.setSize(width, height);
    this.options.width = width;
  }

  play() {
    this.player.play();
  }

  stop() {
    this.player.stop();
  }

  volume(val) {
    this.player.volume(val);
  }

  pause() {
    this.player.pause();
  }

  mute() {
    this.player.mute();
  }

  unMute() {
    this.player.unMute();
  }

  destroy() {
    if (this.is('initialized')) {
      this.leave('initialized');
    }
    if (this.is('loaded')) {
      this.leave('loaded');
      this.player.destroy();
    }

    this.trigger(events.DESTROY);
    super.destroy();
  }

  static registerSource(type, API) {
    sources[type] = API;
  }
}, (_applyDecoratedDescriptor(_class2.prototype, 'destroy', [deregister], Object.getOwnPropertyDescriptor(_class2.prototype, 'destroy'), _class2.prototype)), _class2)) || _class) || _class) || _class) || _class);


Video.registerSource('youtube', Youtube);
Video.registerSource('vimeo', Vimeo);
Video.registerSource('html5', Html5);

export default Video;
