function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useContext, useRef, useState, forwardRef, useImperativeHandle, useLayoutEffect } from 'react';
import classNames from 'classnames';
import { Spin } from 'antd';
import DragContent from "../DragContent";
import ContentHeader from "./ContentHeader";
import ContentFooter from "./ContentFooter";
import useStyle from "./styles/Subfield";
// import './styles/index.less';
import { FanContext } from "../ConfigContext";
var SubfieldContent = /*#__PURE__*/forwardRef(function (props, ref) {
  var _proLayoutProps$foote, _proLayoutProps$foote2, _proLayoutProps$heade, _proLayoutProps$heade2;
  var InitFanContext = useContext(FanContext);
  var providerConfig = InitFanContext['SubfieldContent'] || {}; // 使用上下文（全局配置）设置扩展的配置项
  var proLayoutProps = InitFanContext['proLayoutProps'] || {};
  var _providerConfig$props = _objectSpread(_objectSpread({}, providerConfig), props),
    _providerConfig$props2 = _providerConfig$props.leftSiderWidth,
    leftSiderWidth = _providerConfig$props2 === void 0 ? 180 : _providerConfig$props2,
    _providerConfig$props3 = _providerConfig$props.leftSiderNoPadding,
    leftSiderNoPadding = _providerConfig$props3 === void 0 ? false : _providerConfig$props3,
    _providerConfig$props4 = _providerConfig$props.leftSiderStyle,
    leftSiderStyle = _providerConfig$props4 === void 0 ? {} : _providerConfig$props4,
    rightStyle = _providerConfig$props.rightStyle,
    rightContStyle = _providerConfig$props.rightContStyle,
    leftSiderNode = _providerConfig$props.leftSiderNode,
    children = _providerConfig$props.children,
    className = _providerConfig$props.className,
    style = _providerConfig$props.style,
    leftSiderClassName = _providerConfig$props.leftSiderClassName,
    _providerConfig$props5 = _providerConfig$props.loading,
    loading = _providerConfig$props5 === void 0 ? false : _providerConfig$props5,
    loadingTip = _providerConfig$props.loadingTip,
    loadingConfig = _providerConfig$props.loadingConfig,
    loadingArea = _providerConfig$props.loadingArea,
    leftSiderDragDirection = _providerConfig$props.leftSiderDragDirection,
    leftSiderMoveMaxWidth = _providerConfig$props.leftSiderMoveMaxWidth,
    leftSiderMoveMaxHeight = _providerConfig$props.leftSiderMoveMaxHeight,
    header = _providerConfig$props.header,
    watermarkProps = _providerConfig$props.watermarkProps,
    _providerConfig$props6 = _providerConfig$props.leftSiderHide,
    leftSiderHide = _providerConfig$props6 === void 0 ? false : _providerConfig$props6,
    _providerConfig$props7 = _providerConfig$props.leftSiderLoading,
    leftSiderLoading = _providerConfig$props7 === void 0 ? false : _providerConfig$props7,
    footer = _providerConfig$props.footer,
    codes = _providerConfig$props.codes,
    permissionCodes = _providerConfig$props.permissionCodes;
  var _useState = useState(0),
    _useState2 = _slicedToArray(_useState, 2),
    headerHeight = _useState2[0],
    setHeaderHeight = _useState2[1];
  // const [hideSider, setHideSider] = useState(false)
  var componentName = 'spec-grid-content';
  var _useStyle = useStyle(componentName),
    _useStyle2 = _slicedToArray(_useStyle, 2),
    wrapSSR = _useStyle2[0],
    hashId = _useStyle2[1];
  var headerRef = useRef();
  var contentRef = useRef();
  //
  // const changeSiderHide = (hide: boolean) => {
  //   setHideSider(hide)
  // }
  //
  useImperativeHandle(ref, function () {
    return _objectSpread({}, (contentRef === null || contentRef === void 0 ? void 0 : contentRef.current) || {});
  });
  // useImperativeHandle 是一个 React 钩子，它可以用来自定义使用 ref 时暴露给父组件的属性。如果你在自定义组件中使用 useImperativeHandle 来暴露一个方法，并且这个方法依赖于组件的 DOM 节点，比如 clientHeight，那么你可能会遇到在组件挂载之初调用这个方法时取不到 clientHeight 的问题，因为 DOM 节点可能还没有被渲染。
  // 解决这个问题的方法是确保在调用这个方法之前 DOM 节点已经被渲染。你可以通过使用 useLayoutEffect 来确保你的方法在 DOM 更新后执行，例如
  useLayoutEffect(function () {
    if (contentRef.current) {
      // 确保在 DOM 更新后执行的逻辑
      // console.log('更新后执行的逻辑', contentRef.current)
    }
  });
  var contentNode = /*#__PURE__*/React.createElement("div", {
    className: classNames('spec-grid-content-body')
    // style={{ height: `calc(100% - ${headerHeight ? headerHeight + 20 : 0}px` }}
  }, leftSiderNode && /*#__PURE__*/React.createElement(DragContent, {
    direction: leftSiderDragDirection,
    className: classNames('spec-grid-left', leftSiderHide ? 'spec-grid-left-is-hide' : '', leftSiderClassName),
    style: _objectSpread({
      width: "".concat(leftSiderWidth || 180, "px"),
      padding: leftSiderNoPadding ? 0 : ''
    }, leftSiderStyle || {}),
    moveMaxWidth: leftSiderMoveMaxWidth,
    moveMaxHeight: leftSiderMoveMaxHeight
  }, /*#__PURE__*/React.createElement(Spin, {
    spinning: leftSiderLoading,
    wrapperClassName: classNames('spec-grid-left-spinning')
  }, /*#__PURE__*/React.createElement("div", {
    className: 'spec-grid-left-cont'
  }, leftSiderNode))), /*#__PURE__*/React.createElement("div", {
    className: "spec-grid-right",
    style: _objectSpread({}, rightStyle || {})
  }, /*#__PURE__*/React.createElement(Spin, _extends({
    spinning: loadingArea !== 'full' && loading,
    tip: loadingTip
  }, loadingConfig || {}, {
    wrapperClassName: classNames('spec-grid-content-spinning', loadingConfig === null || loadingConfig === void 0 ? void 0 : loadingConfig.wrapperClassName)
  }), /*#__PURE__*/React.createElement("div", {
    className: classNames('spec-grid-right-cont', footer ? 'spec-grid-right-cont-has-footer' : '', proLayoutProps !== null && proLayoutProps !== void 0 && (_proLayoutProps$foote = proLayoutProps.footer) !== null && _proLayoutProps$foote !== void 0 && _proLayoutProps$foote.fixed || footer !== null && footer !== void 0 && footer.fixed ? 'spec-grid-right-cont-fixed' : ''),
    style: _objectSpread({}, rightContStyle || {})
  }, proLayoutProps !== null && proLayoutProps !== void 0 && proLayoutProps.footer || footer ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: 'spec-grid-right-cont-body'
  }, children), proLayoutProps !== null && proLayoutProps !== void 0 && proLayoutProps.footer || footer ? /*#__PURE__*/React.createElement(ContentFooter, _extends({
    className: classNames('spec-grid-right-cont-footer', proLayoutProps !== null && proLayoutProps !== void 0 && (_proLayoutProps$foote2 = proLayoutProps.footer) !== null && _proLayoutProps$foote2 !== void 0 && _proLayoutProps$foote2.fixed || footer !== null && footer !== void 0 && footer.fixed ? 'spec-grid-content-footer-fixed' : ''),
    codes: codes,
    permissionCodes: permissionCodes
  }, (proLayoutProps === null || proLayoutProps === void 0 ? void 0 : proLayoutProps.footer) || {}, footer || {})) : null) : children))));
  return wrapSSR( /*#__PURE__*/React.createElement("div", {
    className: classNames(componentName, className, hashId, proLayoutProps !== null && proLayoutProps !== void 0 && (_proLayoutProps$heade = proLayoutProps.header) !== null && _proLayoutProps$heade !== void 0 && _proLayoutProps$heade.fixed || header !== null && header !== void 0 && header.fixed ? componentName + '-fixed' : ''),
    style: style,
    ref: contentRef
  }, proLayoutProps !== null && proLayoutProps !== void 0 && proLayoutProps.header || header ? /*#__PURE__*/React.createElement(ContentHeader, _extends({
    ref: headerRef
    // getClientHeight={setHeaderHeight}
    ,
    className: classNames('spec-grid-content-header', proLayoutProps !== null && proLayoutProps !== void 0 && (_proLayoutProps$heade2 = proLayoutProps.header) !== null && _proLayoutProps$heade2 !== void 0 && _proLayoutProps$heade2.fixed || header !== null && header !== void 0 && header.fixed ? 'spec-grid-content-header-fixed' : '')
  }, (proLayoutProps === null || proLayoutProps === void 0 ? void 0 : proLayoutProps.header) || {}, header || {})) : null, loadingArea === 'full' ? /*#__PURE__*/React.createElement(Spin, _extends({
    spinning: loadingArea === 'full' && loading,
    tip: loadingTip
  }, loadingConfig || {}, {
    wrapperClassName: classNames('spec-grid-content-full-spinning', loadingConfig === null || loadingConfig === void 0 ? void 0 : loadingConfig.wrapperClassName)
  }), contentNode) : contentNode));
});
export default SubfieldContent;