"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Resizable", {
    enumerable: true,
    get: function() {
        return Resizable;
    }
});
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
var _reresizable = require("re-resizable");
var _Popuptokens = require("../../Popup.tokens");
var _utils = require("../../utils");
var _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;
}
var Resizable = function Resizable(param) {
    var children = param.children, outerResizable = param.resizable, placement = param.placement;
    var _resizable_hiddenIcons, _resizable_icons, _resizable_hiddenIcons1, _resizable_icons1, _resizable_hiddenIcons2, _resizable_icons2, _resizable_hiddenIcons3, _resizable_icons3;
    var resizableContainer = (0, _react.useRef)(null);
    var resizable = typeof outerResizable === 'boolean' ? {
        disabled: !outerResizable
    } : outerResizable;
    var handleResizeStart = function handleResizeStart() {
        if ((resizableContainer === null || resizableContainer === void 0 ? void 0 : resizableContainer.current) && resizableContainer.current.resizable) {
            resizableContainer.current.resizable.classList.toggle(_Popuptokens.classes.resizableContainerNoSelect);
        }
        if (resizable === null || resizable === void 0 ? void 0 : resizable.onResizeStart) {
            resizable.onResizeStart(resizableContainer);
        }
    };
    var handleResizeStop = function handleResizeStop() {
        if ((resizableContainer === null || resizableContainer === void 0 ? void 0 : resizableContainer.current) && resizableContainer.current.resizable) {
            resizableContainer.current.resizable.classList.toggle(_Popuptokens.classes.resizableContainerNoSelect);
        }
        if (resizable === null || resizable === void 0 ? void 0 : 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 === null || resizable === void 0 ? void 0 : resizable.defaultSize,
        minWidth: resizable === null || resizable === void 0 ? void 0 : resizable.minWidth,
        minHeight: resizable === null || resizable === void 0 ? void 0 : resizable.minHeight,
        maxWidth: resizable === null || resizable === void 0 ? void 0 : resizable.maxWidth,
        maxHeight: resizable === null || resizable === void 0 ? void 0 : resizable.maxHeight,
        onResizeStart: handleResizeStart,
        onResizeStop: handleResizeStop,
        handleComponent: {
            topRight: (resizable === null || resizable === void 0 ? void 0 : (_resizable_hiddenIcons = resizable.hiddenIcons) === null || _resizable_hiddenIcons === void 0 ? void 0 : _resizable_hiddenIcons.includes('top-right')) ? undefined : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, (resizable === null || resizable === void 0 ? void 0 : (_resizable_icons = resizable.icons) === null || _resizable_icons === void 0 ? void 0 : _resizable_icons.topRight) || /*#__PURE__*/ _react.default.createElement(_Popupstyles.IconResizeDiagonalStyled, {
                className: _Popuptokens.classes.resizableTopRightIcon,
                color: "inherit",
                size: resizable === null || resizable === void 0 ? void 0 : resizable.iconSize
            })),
            bottomRight: (resizable === null || resizable === void 0 ? void 0 : (_resizable_hiddenIcons1 = resizable.hiddenIcons) === null || _resizable_hiddenIcons1 === void 0 ? void 0 : _resizable_hiddenIcons1.includes('bottom-right')) ? undefined : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, (resizable === null || resizable === void 0 ? void 0 : (_resizable_icons1 = resizable.icons) === null || _resizable_icons1 === void 0 ? void 0 : _resizable_icons1.bottomRight) || /*#__PURE__*/ _react.default.createElement(_Popupstyles.IconResizeDiagonalStyled, {
                className: _Popuptokens.classes.resizableBottomRightIcon,
                color: "inherit",
                size: resizable === null || resizable === void 0 ? void 0 : resizable.iconSize
            })),
            bottomLeft: (resizable === null || resizable === void 0 ? void 0 : (_resizable_hiddenIcons2 = resizable.hiddenIcons) === null || _resizable_hiddenIcons2 === void 0 ? void 0 : _resizable_hiddenIcons2.includes('bottom-left')) ? undefined : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, (resizable === null || resizable === void 0 ? void 0 : (_resizable_icons2 = resizable.icons) === null || _resizable_icons2 === void 0 ? void 0 : _resizable_icons2.bottomLeft) || /*#__PURE__*/ _react.default.createElement(_Popupstyles.IconResizeDiagonalStyled, {
                className: _Popuptokens.classes.resizableBottomLeftIcon,
                color: "inherit",
                size: resizable === null || resizable === void 0 ? void 0 : resizable.iconSize
            })),
            topLeft: (resizable === null || resizable === void 0 ? void 0 : (_resizable_hiddenIcons3 = resizable.hiddenIcons) === null || _resizable_hiddenIcons3 === void 0 ? void 0 : _resizable_hiddenIcons3.includes('top-left')) ? undefined : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, (resizable === null || resizable === void 0 ? void 0 : (_resizable_icons3 = resizable.icons) === null || _resizable_icons3 === void 0 ? void 0 : _resizable_icons3.topLeft) || /*#__PURE__*/ _react.default.createElement(_Popupstyles.IconResizeDiagonalStyled, {
                className: _Popuptokens.classes.resizableTopLeftIcon,
                color: "inherit",
                size: resizable === null || resizable === void 0 ? void 0 : resizable.iconSize
            }))
        },
        className: _Popuptokens.classes.resizableContainer,
        handleStyles: (0, _utils.getHandleStyles)(),
        handleWrapperClass: _Popuptokens.classes.resizableHandleWrapper
    }, children);
};
