'use strict';

exports.__esModule = true;

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; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _Bridge = require('./../Bridge');

var _Bridge2 = _interopRequireDefault(_Bridge);

var _Photos = require('./../Photos');

var _Photos2 = _interopRequireDefault(_Photos);

var _VideoFull = require('./../VideoFull');

var _VideoFull2 = _interopRequireDefault(_VideoFull);

var _instance = require('./../Context/instance.js');

var _instance2 = _interopRequireDefault(_instance);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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 Camera from './../Camera';


var Videos = (0, _react.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 = (0, _react.useContext)(_instance2.default) || {};
  var locale = context.locale || function (key) {
    return key || '';
  };

  var refVideoFull = (0, _react.useRef)(null);
  // h5预览

  var _useState = (0, _react.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) {
      _Bridge2.default.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 _react2.default.createElement(
    _react.Fragment,
    null,
    _react2.default.createElement(_Photos2.default, _extends({
      ref: ref
    }, others, {
      onClick: click
      // onChoose={choose}
      , type: 'video',
      preview: false
    })),
    previewItem && _react2.default.createElement(_VideoFull2.default, {
      ref: refVideoFull,
      portal: document.getElementById('root') || document.body,
      poster: previewItem.thumb,
      src: previewItem.src,
      autoPlay: true,
      bar: _react2.default.createElement('div', { className: 'videofull-close', onClick: closePreview })
    })
  );
});

exports.default = Videos;
module.exports = exports['default'];