var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React, { forwardRef, useContext, useRef, Fragment, useState } from 'react';
import Bridge from './../Bridge';
import Photos from './../Photos';
import VideoFull from './../VideoFull';
// import Camera from './../Camera';
import Context from './../Context/instance.js';

var Videos = forwardRef(function (_ref, ref) {
  var onClick = _ref.onClick,
      _ref$preview = _ref.preview,
      preview = _ref$preview === undefined ? true : _ref$preview,
      others = _objectWithoutProperties(_ref, ['onClick', 'preview']);

  // context
  var context = useContext(Context) || {};
  var locale = context.locale || function (key) {
    return key || '';
  };

  var refVideoFull = useRef(null);
  // h5预览

  var _useState = useState(null),
      previewItem = _useState[0],
      setPreivewItem = _useState[1];
  // 点击预览


  function click(e, item, index) {
    if (onClick) {
      onClick(e, item, index);
    }
    if (!preview) return;
    if (!item.src) {
      Bridge.showToast(locale('没有参数src', 'no_param_src'), { mask: false });
    }
    // 客户端预览视频有问题, 所以使用h5预览
    setPreivewItem(item);
  }
  // 关闭h5预览
  function closePreview() {
    setPreivewItem(null);
  }
  /*
  // h5录相
  const [showRecord, setShowRecord] = useState(false);
  // 录制视频
  function choose (e) {
    if (Bridge.platform !== 'wq') {
      setShowRecord(true);
      return;
    }
    if (onChoose) {
      onChoose(e);
    }
  }
  // h5录相
  function record (e) {
    if (onChoose) {
      onChoose(e);
    }
  }
  */
  return React.createElement(
    Fragment,
    null,
    React.createElement(Photos, _extends({
      ref: ref
    }, others, {
      onClick: click
      // onChoose={choose}
      , type: 'video',
      preview: false
    })),
    previewItem && React.createElement(VideoFull, {
      ref: refVideoFull,
      portal: document.getElementById('root') || document.body,
      poster: previewItem.thumb,
      src: previewItem.src,
      autoPlay: true,
      bar: React.createElement('div', { className: 'videofull-close', onClick: closePreview })
    })
  );
});

export default Videos;