"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Resizable", {
    enumerable: true,
    get: function() {
        return Resizable;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _reresizable = require("re-resizable");
const _Popuptokens = require("../../Popup.tokens");
const _utils = require("../../utils");
const _Popupstyles = require("../../Popup.styles");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(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 = {
        __proto__: null
    };
    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;
}
const Resizable = ({ children, resizable: outerResizable, placement })=>{
    const resizableContainer = (0, _react.useRef)(null);
    const resizable = typeof outerResizable === 'boolean' ? {
        disabled: !outerResizable
    } : outerResizable;
    const handleResizeStart = ()=>{
        if (resizableContainer?.current && resizableContainer.current.resizable) {
            resizableContainer.current.resizable.classList.toggle(_Popuptokens.classes.resizableContainerNoSelect);
        }
        if (resizable?.onResizeStart) {
            resizable.onResizeStart(resizableContainer);
        }
    };
    const handleResizeStop = ()=>{
        if (resizableContainer?.current && resizableContainer.current.resizable) {
            resizableContainer.current.resizable.classList.toggle(_Popuptokens.classes.resizableContainerNoSelect);
        }
        if (resizable?.onResizeEnd) {
            resizable.onResizeEnd(resizableContainer);
        }
    };
    if (!resizable || resizable.disabled) {
        return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, children);
    }
    return /*#__PURE__*/ _react.default.createElement(_reresizable.Resizable, {
        ref: resizableContainer,
        enable: resizable && !resizable.disabled ? (0, _utils.getResizeDirections)(resizable.directions) : false,
        resizeRatio: (0, _utils.getRatioBasedOnPlacement)(placement),
        defaultSize: resizable?.defaultSize,
        minWidth: resizable?.minWidth,
        minHeight: resizable?.minHeight,
        maxWidth: resizable?.maxWidth,
        maxHeight: resizable?.maxHeight,
        onResizeStart: handleResizeStart,
        onResizeStop: handleResizeStop,
        handleComponent: {
            topRight: resizable?.hiddenIcons?.includes('top-right') ? undefined : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, resizable?.icons?.topRight || /*#__PURE__*/ _react.default.createElement(_Popupstyles.IconResizeDiagonalStyled, {
                className: _Popuptokens.classes.resizableTopRightIcon,
                color: "inherit",
                size: resizable?.iconSize
            })),
            bottomRight: resizable?.hiddenIcons?.includes('bottom-right') ? undefined : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, resizable?.icons?.bottomRight || /*#__PURE__*/ _react.default.createElement(_Popupstyles.IconResizeDiagonalStyled, {
                className: _Popuptokens.classes.resizableBottomRightIcon,
                color: "inherit",
                size: resizable?.iconSize
            })),
            bottomLeft: resizable?.hiddenIcons?.includes('bottom-left') ? undefined : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, resizable?.icons?.bottomLeft || /*#__PURE__*/ _react.default.createElement(_Popupstyles.IconResizeDiagonalStyled, {
                className: _Popuptokens.classes.resizableBottomLeftIcon,
                color: "inherit",
                size: resizable?.iconSize
            })),
            topLeft: resizable?.hiddenIcons?.includes('top-left') ? undefined : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, resizable?.icons?.topLeft || /*#__PURE__*/ _react.default.createElement(_Popupstyles.IconResizeDiagonalStyled, {
                className: _Popuptokens.classes.resizableTopLeftIcon,
                color: "inherit",
                size: resizable?.iconSize
            }))
        },
        className: _Popuptokens.classes.resizableContainer,
        handleStyles: (0, _utils.getHandleStyles)(),
        handleWrapperClass: _Popuptokens.classes.resizableHandleWrapper
    }, children);
};
