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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : 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); }
/* eslint-disable no-param-reassign */
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";
import { useSelector, useDispatch } from "react-redux";
import { IconButton } from "@mui/material";
import { makeStyles } from "@mui/styles";
import { MdClose } from "react-icons/md";
import Overlay from "../../components/Overlay/Overlay";
import { setDisplayMenu, setFeatureInfo } from "../../model/app/actions";
import { OVERLAY_MIN_HEIGHT } from "../../utils/constants";
import useHasScreenSize from "../../utils/useHasScreenSize";
const IFRAME_OVERLAY_DEFAULT_HEIGHT = 300;
const boxShadow = "0px 5px 5px -3px rgb(0 0 0 / 20%), 0px 8px 10px 1px rgb(0 0 0 / 14%), 0px 3px 14px 2px rgb(0 0 0 / 12%)";
const stylesContainer = {
  boxSizing: "border-box",
  backgroundColor: "white",
  boxShadow: props => props.displayMenu ? boxShadow : null,
  borderRadius: 8,
  overflow: "hidden"
};
const useStyles = makeStyles(theme => {
  return {
    menuHeader: stylesContainer,
    menuContent: {
      height: props => props.featureSelected && !props.isMobile ? "calc(100vh - 30px)" : "unset"
    },
    menuContentMobile: {
      padding: "50px 0 0"
    },
    featureInfo: _objectSpread(_objectSpread({}, stylesContainer), {}, {
      marginTop: props => props.header ? 15 : 0,
      height: props => "calc(100vh - ".concat(props.header ? props.headerHeight + 40 : 25, "px)"),
      "& > div": {
        scrollbarWidth: "thin",
        "&::-webkit-scrollbar": {
          width: 6
        },
        "&::-webkit-scrollbar-track": {
          background: "rgba(0, 0, 0, 0.1)"
        },
        "&::-webkit-scrollbar-thumb": {
          background: "rgba(0, 0, 0, 0.4)"
        }
      }
    }),
    mobileHandleWrapper: {
      position: "absolute",
      width: "100%",
      height: OVERLAY_MIN_HEIGHT,
      top: 0,
      right: 0,
      zIndex: 1000
    },
    mobileHandle: {
      position: "fixed",
      backgroundColor: "#f5f5f5",
      borderBottom: "1px solid #F0F0F0",
      width: "inherit",
      height: "inherit",
      display: "flex",
      alignItems: "center"
    },
    mobileTitle: {
      padding: "0 15px",
      maxWidth: "calc(100vw - 65px)"
    },
    closeBtn: {
      position: "fixed",
      right: 0,
      padding: "13px 10px",
      marginRight: 2,
      zIndex: 1002,
      height: OVERLAY_MIN_HEIGHT
    },
    hide: {
      display: "none"
    },
    bottomFade: {
      "&::after": _objectSpread(_objectSpread({}, theme.styles.bottomFade["&::after"]), {}, {
        borderRadius: 8
      })
    }
  };
});
function IframeMenu(_ref) {
  let {
    header = null,
    body = null,
    hide = false,
    title = null,
    ResizableProps
  } = _ref;
  const dispatch = useDispatch();
  const featureInfo = useSelector(state => state.app.featureInfo);
  const displayMenu = useSelector(state => state.app.displayMenu);
  const activeTopic = useSelector(state => state.app.activeTopic);
  const isMobile = useHasScreenSize();
  const [headerHeight, setHeaderHeight] = useState(0);
  const classes = useStyles({
    displayMenu,
    featureSelected: featureInfo === null || featureInfo === void 0 ? void 0 : featureInfo.length,
    isMobile,
    headerHeight,
    header,
    title
  });
  useEffect(() => {
    if (featureInfo !== null && featureInfo !== void 0 && featureInfo.length) {
      dispatch(setDisplayMenu(!isMobile));
    }
  }, [featureInfo, isMobile, dispatch]);
  return /*#__PURE__*/React.createElement("div", {
    className: hide ? classes.hide : ""
  }, displayMenu && /*#__PURE__*/React.createElement("div", {
    className: classes.menuContent
  }, /*#__PURE__*/React.createElement("div", {
    className: classes.menuHeader,
    ref: el => setHeaderHeight(el === null || el === void 0 ? void 0 : el.clientHeight)
  }, header), !isMobile && featureInfo !== null && featureInfo !== void 0 && featureInfo.length ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(classes.featureInfo, " ").concat(classes.bottomFade)
  }, title, body) : null), isMobile && featureInfo !== null && featureInfo !== void 0 && featureInfo.length ? /*#__PURE__*/React.createElement(Overlay, {
    elements: activeTopic.elements,
    disablePortal: false,
    transitionDuration: 0,
    ResizableProps: _objectSpread(_objectSpread({}, ResizableProps || {}), {}, {
      defaultSize: _objectSpread({
        height: IFRAME_OVERLAY_DEFAULT_HEIGHT
      }, (ResizableProps === null || ResizableProps === void 0 ? void 0 : ResizableProps.defaultSize) || {}),
      snap: _objectSpread({
        y: [OVERLAY_MIN_HEIGHT, IFRAME_OVERLAY_DEFAULT_HEIGHT, document.documentElement.clientHeight]
      }, (ResizableProps === null || ResizableProps === void 0 ? void 0 : ResizableProps.snap) || {})
    })
  }, /*#__PURE__*/React.createElement("div", {
    className: classes.mobileHandleWrapper
  }, /*#__PURE__*/React.createElement("div", {
    className: classes.mobileHandle
  }, title ? /*#__PURE__*/React.createElement("b", {
    className: classes.mobileTitle
  }, title) : null)), /*#__PURE__*/React.createElement(IconButton, {
    size: "medium",
    className: "wkp-close-bt ".concat(classes.closeBtn),
    title: "Close",
    onClick: () => {
      dispatch(setFeatureInfo());
    }
  }, /*#__PURE__*/React.createElement(MdClose, {
    focusable: false,
    alt: "Close"
  })), /*#__PURE__*/React.createElement("div", {
    className: "".concat(classes.menuContent, " ").concat(classes.menuContentMobile)
  }, body)) : null);
}
IframeMenu.propTypes = {
  header: PropTypes.node,
  body: PropTypes.node,
  hide: PropTypes.bool,
  title: PropTypes.node,
  ResizableProps: PropTypes.shape({
    defaultSize: PropTypes.shape({
      height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
      width: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
    }),
    snap: PropTypes.shape({
      x: PropTypes.arrayOf(PropTypes.number),
      y: PropTypes.arrayOf(PropTypes.number)
    }),
    onResize: PropTypes.func
  })
};
export default IframeMenu;
//# sourceMappingURL=IframeMenu.js.map