"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 _components = require("@alicloudfe/components");
require("./index.scss");
var _utils = require("@teamix/utils");
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; }
var FullScreen = function FullScreen(props) {
  var children = props.children,
    visible = props.visible,
    actionRef = props.actionRef;
  var _actionRef$current = actionRef.current,
    normalDataFilterForm = _actionRef$current.normalDataFilterForm,
    fullscreenDataFilterForm = _actionRef$current.fullscreenDataFilterForm,
    filterEnableRef = _actionRef$current.filterEnableRef;
  var closeByESC = function closeByESC(e) {
    if (visible && e.code === 'Escape') {
      var _actionRef$current2, _actionRef$current2$f;
      actionRef === null || actionRef === void 0 ? void 0 : (_actionRef$current2 = actionRef.current) === null || _actionRef$current2 === void 0 ? void 0 : (_actionRef$current2$f = _actionRef$current2.fullScreen) === null || _actionRef$current2$f === void 0 ? void 0 : _actionRef$current2$f.call(_actionRef$current2);
    }
  };
  // 监听esc按钮
  (0, _react.useEffect)(function () {
    window.addEventListener('keydown', closeByESC);
    return function () {
      window.removeEventListener('keydown', closeByESC);
    };
  }, [visible, actionRef]);
  var afterClose = function afterClose() {
    var _document;
    // 判断全屏前后筛选表单值是否有改变
    var n = JSON.stringify((0, _utils.getValidValues)(normalDataFilterForm === null || normalDataFilterForm === void 0 ? void 0 : normalDataFilterForm.values));
    var f = JSON.stringify((0, _utils.getValidValues)(fullscreenDataFilterForm === null || fullscreenDataFilterForm === void 0 ? void 0 : fullscreenDataFilterForm.values));
    if (n === f) {
      // 关闭全屏后，表单值未变化，开启普通表单onFilter
      filterEnableRef.current.normal = true;
    } else {
      // 关闭全屏后，表单值有变化，修改表单值
      normalDataFilterForm === null || normalDataFilterForm === void 0 ? void 0 : normalDataFilterForm.setValues(fullscreenDataFilterForm === null || fullscreenDataFilterForm === void 0 ? void 0 : fullscreenDataFilterForm.values);
    }
    // 关闭全屏后，关闭全屏表单onFilter
    filterEnableRef.current.fullscreen = false;
    // 移除类名
    if (document && ((_document = document) === null || _document === void 0 ? void 0 : _document.body)) {
      document.body.classList.remove('teamix-pro-table-fullscreen');
    }
  };
  // 全屏开启之后
  var afterOpen = function afterOpen() {
    var _document2;
    // 判断全屏前后筛选表单值是否有改变
    var n = JSON.stringify((0, _utils.getValidValues)(normalDataFilterForm === null || normalDataFilterForm === void 0 ? void 0 : normalDataFilterForm.values));
    var f = JSON.stringify((0, _utils.getValidValues)(fullscreenDataFilterForm === null || fullscreenDataFilterForm === void 0 ? void 0 : fullscreenDataFilterForm.values));
    if (n === f) {
      // 全屏后，表单值未变化，开启全屏表单onFilter
      filterEnableRef.current.fullscreen = true;
    } else {
      // 全屏后，表单值变化，修改表单值
      fullscreenDataFilterForm === null || fullscreenDataFilterForm === void 0 ? void 0 : fullscreenDataFilterForm.setValues(normalDataFilterForm === null || normalDataFilterForm === void 0 ? void 0 : normalDataFilterForm.values);
    }
    // 全屏后，关闭普通表单onFilter
    filterEnableRef.current.normal = false;
    // 为 body 添加类名，用于判断是否全屏
    if (document && ((_document2 = document) === null || _document2 === void 0 ? void 0 : _document2.body)) {
      document.body.classList.add('teamix-pro-table-fullscreen');
    }
    // 消息提示
    _components.Message.show({
      type: 'notice',
      content: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", null, (0, _utils.getMessage)('press')), /*#__PURE__*/_react.default.createElement("span", {
        className: "teamix-pro-table-full-screen-message-esc"
      }, /*#__PURE__*/_react.default.createElement("span", {
        className: "teamix-pro-table-full-screen-message-esc-title"
      }, "esc")), /*#__PURE__*/_react.default.createElement("span", null, (0, _utils.getMessage)('toExitFullScreen'))),
      className: 'teamix-pro-table-full-screen-message'
    });
  };
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children(false), /*#__PURE__*/_react.default.createElement(_components.Overlay, {
    canCloseByOutSideClick: false,
    align: "cc cc",
    cache: true,
    v2: false,
    disableScroll: true,
    shouldUpdatePosition: true,
    afterClose: afterClose,
    afterOpen: afterOpen,
    animation: {
      in: 'fadeIn',
      out: 'fadeOut'
    },
    visible: visible,
    wrapperStyle: {
      zIndex: 999
    },
    onRequestClose: function onRequestClose() {
      var _actionRef$current3, _actionRef$current3$f;
      actionRef === null || actionRef === void 0 ? void 0 : (_actionRef$current3 = actionRef.current) === null || _actionRef$current3 === void 0 ? void 0 : (_actionRef$current3$f = _actionRef$current3.fullScreen) === null || _actionRef$current3$f === void 0 ? void 0 : _actionRef$current3$f.call(_actionRef$current3);
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "teamix-pro-table-full-screen"
  }, children(true))));
};
var _default = FullScreen;
exports.default = _default;