"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _antd = require("antd");

var _propTypes = _interopRequireDefault(require("prop-types"));

var _ahooks = require("ahooks");

var _vmSubTabs = _interopRequireWildcard(require("../vm-sub-tabs"));

var _api = require("./api");

require("./style");

var _active = _interopRequireDefault(require("../../image/1-active.png"));

var _video = _interopRequireDefault(require("../../image/video.png"));

var _utils = require("@vtx/utils");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var _getUrlParam = (0, _utils.getUrlParam)(),
    tenantId = _getUrlParam.tenantId,
    userId = _getUrlParam.userId;

var AudioContent = function AudioContent(props) {
  var id = props.id,
      code = props.code,
      seed = props.seed;
  var screenList = [{
    id: 1,
    src: _active["default"]
  }];

  var _useSetState = (0, _ahooks.useSetState)({
    activeKey: '',
    src: '',
    // 1分屏地址
    value: ''
  }),
      _useSetState2 = _slicedToArray(_useSetState, 2),
      state = _useSetState2[0],
      setState = _useSetState2[1];

  (0, _react.useEffect)(function () {
    if (seed) setState({
      activeKey: '',
      src: '',
      // 1分屏地址
      value: ''
    });
  }, [seed]);

  var treeData = _api.Audio.useVisTree(code, id);

  var onChange = function onChange(checked) {
    if (checked.length === 0) {
      setState({
        src: '',
        value: []
      });
    } else if (checked.length > 0) {
      setState({
        src: "/vis/video/VIS_H5/bounced.html?videoChannelId=".concat(checked[checked.length - 1], "&tenantId=").concat(tenantId, "&userId=").concat(userId),
        value: [checked[checked.length - 1]]
      });
    }
  };

  var handleTabChange = function handleTabChange(activeKey) {
    setState({
      activeKey: activeKey
    });
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "audio-content",
    style: {
      width: '100%',
      height: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "left"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Checkbox.Group, {
    style: {
      width: '100%'
    },
    onChange: onChange,
    value: state.value
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: 20
  }, (treeData === null || treeData === void 0 ? void 0 : treeData.length) > 0 && treeData.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_antd.Col, {
      span: 24,
      key: item === null || item === void 0 ? void 0 : item.videoChannelId,
      style: {
        marginBottom: 10
      }
    }, /*#__PURE__*/_react["default"].createElement(_antd.Checkbox, {
      value: item === null || item === void 0 ? void 0 : item.videoChannelId
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "text"
    }, item === null || item === void 0 ? void 0 : item.channelName)));
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "right"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "right-tabs"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTabs["default"], {
    onTabClick: handleTabChange,
    activeKey: state.activeKey || '1'
  }, screenList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabPane, {
      key: item.id,
      tab: /*#__PURE__*/_react["default"].createElement("img", {
        src: item.src
      })
    });
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "OCXBody",
    style: {
      width: (state.activeKey || '1') === '1' ? '100%' : (state.activeKey || '1') === '4' ? 'calc(50% -6px)' : 'calc(33% -6px)',
      height: (state.activeKey || '1') === '1' ? '100%' : (state.activeKey || '1') === '4' ? 'calc(50% -6px)' : 'calc(33% -6px)'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "name",
    style: {
      width: '100%',
      height: '100%',
      backgroundColor: 'grey'
    }
  }, state.src === '' ? /*#__PURE__*/_react["default"].createElement("img", {
    src: _video["default"]
  }) : /*#__PURE__*/_react["default"].createElement("iframe", {
    style: {
      width: '100%',
      height: '100%'
    },
    src: state.src
  })))));
};

AudioContent.propTypes = {
  id: _propTypes["default"].string,
  code: _propTypes["default"].string,
  seed: _propTypes["default"].string
};
var _default = AudioContent;
exports["default"] = _default;
//# sourceMappingURL=audio.js.map
