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, { useState, useMemo, useRef, useEffect, useContext } from 'react';
import classNames from 'classnames';
import { Radio, Popover } from 'antd';
import "./style/index.less";
import useStyle from "./style/index";
import { FanContext } from "../ConfigContext";
import StandardTitle from "../StandardTitle";
import ButtonGroup from "../ButtonGroup";
var StandardPanel = function StandardPanel(props) {
  var InitFanContext = useContext(FanContext);
  var providerConfig = InitFanContext['StandardPanel'] || {}; // 使用上下文（全局配置）设置扩展的配置项
  var _providerConfig$props = _objectSpread(_objectSpread({}, providerConfig), props),
    className = _providerConfig$props.className,
    style = _providerConfig$props.style,
    height = _providerConfig$props.height,
    children = _providerConfig$props.children,
    title = _providerConfig$props.title,
    titleMark = _providerConfig$props.titleMark,
    _providerConfig$props2 = _providerConfig$props.titleStyleOld,
    titleStyleOld = _providerConfig$props2 === void 0 ? false : _providerConfig$props2,
    badges = _providerConfig$props.badges,
    cateConfig = _providerConfig$props.cateConfig,
    buttonConfig = _providerConfig$props.buttonConfig,
    codes = _providerConfig$props.codes,
    permissionCodes = _providerConfig$props.permissionCodes,
    buttonGroup = _providerConfig$props.buttonGroup,
    buttonGroupConfig = _providerConfig$props.buttonGroupConfig,
    titleExtra = _providerConfig$props.titleExtra,
    titleChildren = _providerConfig$props.titleChildren,
    type = _providerConfig$props.type,
    postfix = _providerConfig$props.postfix,
    bodyStyle = _providerConfig$props.bodyStyle;
  var componentName = 'spec-panel';
  var _useStyle = useStyle(componentName),
    _useStyle2 = _slicedToArray(_useStyle, 2),
    wrapSSR = _useStyle2[0],
    hashId = _useStyle2[1];
  var _useState = useState(56),
    _useState2 = _slicedToArray(_useState, 2),
    headerHeight = _useState2[0],
    setHeaderHeight = _useState2[1];
  var RenderGroupList = function RenderGroupList(values) {
    var list = values.list,
      activeKey = values.activeKey,
      onChange = values.onChange,
      className = values.className,
      size = values.size;
    var handleChange = function handleChange(e) {
      if (onChange) {
        onChange(e.target.value, list.filter(function (data) {
          return data.value === e.target.value;
        })[0]);
      }
    };
    return /*#__PURE__*/React.createElement("div", {
      className: className
    }, /*#__PURE__*/React.createElement(Radio.Group, {
      size: size,
      defaultValue: activeKey,
      buttonStyle: "solid",
      onChange: function onChange(e) {
        return handleChange(e);
      }
    }, list && Array.isArray(list) && list.map(function (item) {
      return /*#__PURE__*/React.createElement(Radio.Button, {
        key: item.value,
        value: item.value
      }, item.label);
    })));
  };

  // 是否显示提示框
  var popoverShow = function popoverShow() {
    return title !== null && title !== void 0 && title.content ? /*#__PURE__*/React.createElement(Popover, {
      content: title.content,
      placement: title === null || title === void 0 ? void 0 : title.placement
    }, " ", title === null || title === void 0 ? void 0 : title.label, " ") : title;
  };
  var panelHeaderRef = useRef();
  var bodyLimitStyle = useMemo(function () {
    if (height) {
      return {
        overflow: 'auto',
        height: "".concat(height - headerHeight, "px")
      };
    }
    return {};
  }, [height, headerHeight]);
  useEffect(function () {
    if (panelHeaderRef && panelHeaderRef.current) {
      setHeaderHeight(panelHeaderRef.current.clientHeight);
    }
  }, [panelHeaderRef]);
  return wrapSSR( /*#__PURE__*/React.createElement("div", {
    className: classNames('spec-panel', hashId, className, type === 'reverse' ? 'spec-panel-reverse' : '', type === 'border' ? 'spec-panel-border' : ''),
    style: _objectSpread(_objectSpread({}, style), {}, {
      height: "".concat(height, "px")
    })
  }, title || cateConfig || buttonConfig || postfix || badges || titleExtra ? /*#__PURE__*/React.createElement("div", {
    className: "spec-panel-header",
    ref: panelHeaderRef
  }, /*#__PURE__*/React.createElement(StandardTitle, {
    title: title,
    mark: titleMark,
    extra: /*#__PURE__*/React.createElement(React.Fragment, null, buttonGroup && /*#__PURE__*/React.createElement(ButtonGroup, _extends({
      options: buttonGroup,
      codes: codes,
      permissionCodes: permissionCodes
    }, buttonGroupConfig)), cateConfig && /*#__PURE__*/React.createElement(RenderGroupList, _extends({
      className: "spec-panel-cate"
    }, cateConfig)), buttonConfig && /*#__PURE__*/React.createElement(RenderGroupList, _extends({
      className: "spec-panel-buttons"
    }, buttonConfig)), titleExtra || postfix && /*#__PURE__*/React.createElement("div", {
      className: "spec-panel-extra"
    }, titleExtra || postfix))
  }, badges && Array.isArray(badges) && /*#__PURE__*/React.createElement("span", {
    className: "badges"
  }, badges.map(function (item) {
    return /*#__PURE__*/React.createElement("span", {
      className: "badges-item",
      key: item.value
    }, /*#__PURE__*/React.createElement("i", {
      style: item.color ? {
        background: item.color
      } : {}
    }), item.label);
  })), titleChildren)) : null, titleStyleOld && title ? /*#__PURE__*/React.createElement("div", {
    className: "spec-panel-header",
    ref: panelHeaderRef
  }, /*#__PURE__*/React.createElement("div", {
    className: "spec-panel-title"
  }, /*#__PURE__*/React.createElement("div", {
    className: classNames(type === 'border' ? 'sub-header-line' : 'sub-header-base')
  }, /*#__PURE__*/React.createElement("span", {
    className: "header-text"
  }, popoverShow()))), /*#__PURE__*/React.createElement("div", {
    className: "spec-panel-inner"
  }, badges && Array.isArray(badges) && /*#__PURE__*/React.createElement("span", {
    className: "badges"
  }, badges.map(function (item) {
    return /*#__PURE__*/React.createElement("span", {
      className: "badges-item",
      key: item.value
    }, /*#__PURE__*/React.createElement("i", {
      style: item.color ? {
        background: item.color
      } : {}
    }), item.label);
  }))), cateConfig && /*#__PURE__*/React.createElement(RenderGroupList, _extends({
    className: "spec-panel-cate"
  }, cateConfig)), buttonConfig && /*#__PURE__*/React.createElement(RenderGroupList, _extends({
    className: "spec-panel-buttons"
  }, buttonConfig)), postfix && /*#__PURE__*/React.createElement("div", {
    className: "spec-panel-extra"
  }, postfix)) : null, /*#__PURE__*/React.createElement("div", {
    className: "spec-panel-body",
    style: _objectSpread(_objectSpread({}, bodyLimitStyle), bodyStyle || {})
  }, children)));
};
export default StandardPanel;