'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var ramda = require('ramda');
var framerMotion = require('framer-motion');
var Right = require('@bigbinary/neeto-icons/Right');
require('react-router-dom');
require('@bigbinary/neeto-hotkeys');
require('./overlayManager.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('@bigbinary/neeto-cist');
require('qs');
require('./index-BgzkP01c.js');
require('i18next');
var usePrefersReducedMotion = require('./usePrefersReducedMotion-D2Ck84HM.js');
var jsxRuntime = require('react/jsx-runtime');
require('@babel/runtime/helpers/toConsumableArray');
require('dayjs');
require('dayjs/plugin/localeData');
require('dayjs/plugin/utc');
require('dayjs/plugin/weekday');
require('dayjs/plugin/weekOfYear');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var React__default = /*#__PURE__*/_interopDefault(React);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var Right__default = /*#__PURE__*/_interopDefault(Right);

var _excluded$1 = ["open", "children", "className"];
function ownKeys$2(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$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Collapse = function Collapse(_ref) {
  var _ref$open = _ref.open,
    open = _ref$open === void 0 ? false : _ref$open,
    children = _ref.children,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    otherProps = _objectWithoutProperties__default.default(_ref, _excluded$1);
  var prefersReducedMotion = usePrefersReducedMotion.usePrefersReducedMotion();
  return /*#__PURE__*/jsxRuntime.jsx(framerMotion.AnimatePresence, {
    children: open && /*#__PURE__*/jsxRuntime.jsx(framerMotion.motion.div, _objectSpread$2(_objectSpread$2({
      animate: {
        opacity: 1,
        height: "auto"
      },
      exit: {
        opacity: 0,
        height: 0
      },
      initial: {
        opacity: 0,
        height: 0,
        overflow: "hidden"
      },
      transition: {
        duration: prefersReducedMotion ? 0 : 0.3
      }
    }, otherProps), {}, {
      children: /*#__PURE__*/jsxRuntime.jsx("div", {
        className: className,
        children: children
      })
    }))
  });
};

function ownKeys$1(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$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Item = function Item(_ref) {
  var id = _ref.id,
    _ref$title = _ref.title,
    title = _ref$title === void 0 ? "" : _ref$title,
    _ref$isOpen = _ref.isOpen,
    isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen,
    _ref$onClick = _ref.onClick,
    onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
    children = _ref.children,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$titleProps = _ref.titleProps,
    titleProps = _ref$titleProps === void 0 ? {} : _ref$titleProps,
    _ref$iconProps = _ref.iconProps,
    iconProps = _ref$iconProps === void 0 ? {} : _ref$iconProps;
  var prefersReducedMotion = usePrefersReducedMotion.usePrefersReducedMotion();
  var onKeyDown = function onKeyDown(e) {
    switch (e.key) {
      case " ":
        e.preventDefault();
        onClick();
        break;
      case "Enter":
        onClick();
        break;
    }
  };
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: classnames__default.default("neeto-ui-accordion__wrapper", _defineProperty__default.default({}, className, className)),
    children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
      onClick: onClick,
      onKeyDown: onKeyDown,
      "aria-controls": "neeto-ui-accordion-section-".concat(id),
      "aria-expanded": isOpen,
      id: "neeto-ui-accordion-item-".concat(id),
      role: "button",
      tabIndex: 0,
      className: classnames__default.default("neeto-ui-accordion__item neeto-ui-flex neeto-ui-justify-between neeto-ui-items-center", {
        "neeto-ui-accordion__item--open": isOpen
      }),
      children: [/*#__PURE__*/jsxRuntime.jsx("div", _objectSpread$1(_objectSpread$1({}, titleProps), {}, {
        className: "neeto-ui-accordion__item-handle neeto-ui-flex neeto-ui-flex-grow neeto-ui-items-center neeto-ui-break-words",
        children: title
      })), /*#__PURE__*/jsxRuntime.jsx(framerMotion.motion.div, {
        animate: isOpen ? "open" : "collapsed",
        "aria-hidden": "true",
        className: "neeto-ui-accordion__item-toggle-icon neeto-ui-flex-grow-0",
        transition: {
          duration: prefersReducedMotion ? 0 : 0.3
        },
        variants: {
          open: {
            rotate: 90
          },
          collapsed: {
            rotate: 0
          }
        },
        children: /*#__PURE__*/jsxRuntime.jsx(Right__default.default, _objectSpread$1(_objectSpread$1({
          size: 16
        }, iconProps), {}, {
          "aria-hidden": "true"
        }))
      })]
    }), /*#__PURE__*/jsxRuntime.jsx(Collapse, {
      "aria-labelledby": "neeto-ui-accordion-item-".concat(id),
      className: "neeto-ui-accordion__drop",
      id: "neeto-ui-accordion-section-".concat(id),
      open: isOpen,
      role: "region",
      children: children
    })]
  });
};
Item.displayName = "Accordion.Item";

var _excluded = ["children", "defaultActiveKey", "padded", "style", "className"];
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), true).forEach(function (r) { _defineProperty__default.default(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; }
var ACCORDION_STYLES = {
  primary: "primary",
  secondary: "secondary"
};
var Accordion = function Accordion(_ref) {
  var children = _ref.children,
    _ref$defaultActiveKey = _ref.defaultActiveKey,
    defaultActiveKey = _ref$defaultActiveKey === void 0 ? null : _ref$defaultActiveKey,
    _ref$padded = _ref.padded,
    padded = _ref$padded === void 0 ? false : _ref$padded,
    _ref$style = _ref.style,
    style = _ref$style === void 0 ? ACCORDION_STYLES.primary : _ref$style,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    otherProps = _objectWithoutProperties__default.default(_ref, _excluded);
  var _useState = React.useState(defaultActiveKey),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    openTab = _useState2[0],
    setOpenTab = _useState2[1];
  React.useEffect(function () {
    setOpenTab(defaultActiveKey);
  }, [defaultActiveKey]);
  return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({
    className: classnames__default.default("neeto-ui-accordions-outer-wrapper", _defineProperty__default.default({
      "neeto-ui-accordions-outer-wrapper--padded": padded,
      "neeto-ui-accordions-outer-wrapper--secondary": style === ACCORDION_STYLES.secondary
    }, className, className))
  }, otherProps), {}, {
    children: React__default.default.Children.map(children, function (child, index) {
      var isSingleOrLastChild = ramda.isEmpty(children) || index === children.length - 1;
      return /*#__PURE__*/React__default.default.cloneElement(child, {
        id: index,
        key: index,
        isOpen: openTab === index,
        className: classnames__default.default(child.props.className, {
          "neeto-ui-accordion__wrapper--last-item": isSingleOrLastChild
        }),
        onClick: function onClick() {
          setOpenTab(openTab === index ? null : index);
          child.props.onClick && child.props.onClick();
        }
      });
    })
  }));
};
Accordion.Item = Item;

module.exports = Accordion;
//# sourceMappingURL=Accordion.js.map
