"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _reactMeasure = _interopRequireDefault(require("react-measure"));
var _constants = require("../../constants");
var _VerticalContext = _interopRequireWildcard(require("../VerticalContext"));
var _jsxRuntime = require("react/jsx-runtime");
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 _interopRequireWildcard(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 = {}; 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; }
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

/**
 * `Columns` component is used for creating of multi-column layouts.
 * @since 2.6.0
 */
const Columns = _ref => {
  let {
    baseClassName = `${_constants.CLS_PREFIX}columns`,
    className,
    children,
    vertical: verticalProp,
    gap,
    ...props
  } = _ref;
  // eslint-disable-next-line prefer-const
  let [vertical, setVertical] = (0, _react.useState)(false);
  const verticalContext = (0, _react.useContext)(_VerticalContext.default);
  if (verticalProp === undefined) {
    verticalProp = typeof verticalContext === 'undefined' ? _VerticalContext.VERTICAL_BREAKPOINT : verticalContext;
  }
  if (typeof verticalProp === 'boolean') {
    vertical = verticalProp;
  }
  const handleResize = _ref2 => {
    let {
      bounds
    } = _ref2;
    setVertical(bounds.width < verticalProp);
  };
  const createRoot = measureRef => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    ref: measureRef,
    className: (0, _classnames.default)(baseClassName, {
      [`${baseClassName}--vertical`]: vertical,
      [`${baseClassName}--gap-${gap}`]: gap
    }, className),
    ...props,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_VerticalContext.default.Provider, {
      value: vertical,
      children: children
    })
  });
  if (typeof verticalProp === 'number') {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactMeasure.default, {
      bounds: true,
      onResize: handleResize,
      children: _ref3 => {
        let {
          measureRef
        } = _ref3;
        return createRoot(measureRef);
      }
    });
  }
  return createRoot();
};
var _default = exports.default = Columns;