"use strict";
"use client";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Accordion/AccordionList.tsx
var AccordionList_exports = {};
__export(AccordionList_exports, {
  AccordionList: () => AccordionList
});
module.exports = __toCommonJS(AccordionList_exports);
var import_react2 = require("react");
var import_dedupe6 = __toESM(require("classnames/dedupe"));

// src/components/Accordion/Accordion.tsx
var import_dedupe4 = __toESM(require("classnames/dedupe"));
var import_react = require("react");
var import_mobius_hooks = require("@simplybusiness/mobius-hooks");

// src/components/Accordion/AccordionLink.tsx
var import_dedupe3 = __toESM(require("classnames/dedupe"));

// src/components/Flex/Flex.tsx
var import_dedupe = __toESM(require("classnames/dedupe"));

// src/utils/filterUndefinedProps.ts
var filterUndefinedProps = (props) => {
  const filteredProps = {};
  Object.keys(props).forEach((key) => {
    if (props[key] !== void 0) {
      filteredProps[key] = props[key];
    }
  });
  return filteredProps;
};

// src/utils/getSpacingValue.ts
var getSpacingValue = (padding) => {
  if (typeof padding === "string") {
    return `var(--size-${padding})`;
  }
  if (typeof padding === "number") {
    return `${padding}px`;
  }
  return void 0;
};

// src/components/Flex/propUtils.ts
var buildFlexStyles = (props) => {
  const {
    flexDirection,
    flexWrap,
    flexGrow,
    flex,
    justifyContent,
    alignItems,
    alignContent,
    gap,
    rowGap,
    columnGap
  } = props;
  const styleProps = {
    flexDirection,
    flexWrap,
    flexGrow,
    flex,
    justifyContent,
    alignItems,
    alignContent,
    gap: getSpacingValue(gap),
    columnGap: getSpacingValue(columnGap),
    rowGap: getSpacingValue(rowGap)
  };
  return filterUndefinedProps(styleProps);
};
var splitProps = (props) => {
  const {
    flexDirection,
    flexWrap,
    flexGrow,
    flex,
    justifyContent,
    alignItems,
    alignContent,
    gap,
    rowGap,
    columnGap,
    ...otherProps
  } = props;
  return [
    {
      flexDirection,
      flexWrap,
      flexGrow,
      flex,
      justifyContent,
      alignItems,
      alignContent,
      gap,
      rowGap,
      columnGap
    },
    otherProps
  ];
};

// src/components/Flex/Flex.tsx
var import_Flex = require("@simplybusiness/mobius/src/components/Flex/Flex.css");
var import_jsx_runtime = require("react/jsx-runtime");
var Flex = ({ ref, ...props }) => {
  const {
    elementType: Element = "div",
    style,
    className,
    ...otherProps
  } = props;
  const classes = (0, import_dedupe.default)("mobius", "mobius-flex", className);
  const [styleProps, restProps] = splitProps(otherProps);
  const flexStyles = buildFlexStyles(styleProps);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    Element,
    {
      ref,
      style: {
        ...flexStyles,
        ...style
      },
      className: classes,
      ...restProps
    }
  );
};
Flex.displayName = "Flex";

// src/components/Icon/Icon.tsx
var import_dedupe2 = __toESM(require("classnames/dedupe"));
var import_Icon = require("@simplybusiness/mobius/src/components/Icon/Icon.css");
var import_jsx_runtime2 = require("react/jsx-runtime");
var ICON_PREFIX = "mobius-icon";
var capitaliseFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
function Icon({
  ref,
  icon,
  className,
  size = "xs",
  color,
  fixedWidth,
  spin,
  spinReverse,
  title,
  ...otherProps
}) {
  if (!icon) {
    throw new Error("Must specify icon object");
  }
  const classes = (0, import_dedupe2.default)(
    "mobius",
    "mobius-icon",
    `svg-inline--${ICON_PREFIX}`,
    `--size-${size}`,
    className,
    {
      [`${ICON_PREFIX}-fw`]: fixedWidth,
      [`${ICON_PREFIX}-spin`]: spin || spinReverse,
      [`${ICON_PREFIX}-spin-reverse`]: spinReverse
    }
  );
  const { iconName, width, height, svgPathData } = icon;
  const formattedIconName = iconName.split("-").join(" ");
  const defaultTitle = `${capitaliseFirstLetter(formattedIconName)} icon`;
  const titleText = title || defaultTitle;
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
    "svg",
    {
      ref,
      focusable: "false",
      "data-icon": iconName,
      className: classes,
      role: "img",
      xmlns: "http://www.w3.org/2000/svg",
      viewBox: `0 0 ${width} ${height}`,
      style: { color },
      ...otherProps,
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("title", { children: titleText }),
        /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { fill: "currentColor", d: svgPathData })
      ]
    }
  );
}

// src/components/Accordion/AccordionLink.tsx
var import_icons = require("@simplybusiness/icons");
var import_jsx_runtime3 = require("react/jsx-runtime");
var AccordionLink = ({
  text,
  elementType: LinkElement = "span",
  toggle,
  onClick,
  headerChildren,
  ariaExpanded,
  accordionId,
  contentId
}) => {
  const linkClasses = (0, import_dedupe3.default)("mobius-accordion__link", {
    "--is-open": ariaExpanded
  });
  const iconClasses = (0, import_dedupe3.default)("mobius-accordion__link-icon", {
    "--is-open": ariaExpanded
  });
  const handleOnClick = (e) => {
    if (onClick) {
      onClick(e);
    }
    toggle();
  };
  const handleKeyDown = (e) => {
    if (e.key === " " || e.key === "Enter") {
      toggle();
    }
  };
  if (headerChildren) {
    return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
      Flex,
      {
        justifyContent: "space-between",
        alignItems: "center",
        className: "mobius-accordion__header",
        children: [
          /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
            "div",
            {
              id: accordionId,
              className: linkClasses,
              onClick: handleOnClick,
              onKeyDown: handleKeyDown,
              role: "button",
              tabIndex: 0,
              "aria-expanded": !!ariaExpanded,
              "aria-controls": contentId,
              children: [
                /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LinkElement, { className: "mobius-accordion__link-text", children: text }),
                /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { icon: import_icons.chevronDown, className: iconClasses })
              ]
            }
          ),
          headerChildren
        ]
      }
    );
  }
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
    "div",
    {
      id: accordionId,
      className: linkClasses,
      onClick: handleOnClick,
      onKeyDown: handleKeyDown,
      role: "button",
      tabIndex: 0,
      "aria-expanded": !!ariaExpanded,
      "aria-controls": contentId,
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LinkElement, { className: "mobius-accordion__link-text", children: text }),
        /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { icon: import_icons.chevronDown, className: iconClasses })
      ]
    }
  );
};

// src/components/Accordion/Accordion.tsx
var import_Accordion = require("@simplybusiness/mobius/src/components/Accordion/Accordion.css");
var import_jsx_runtime4 = require("react/jsx-runtime");
var Accordion = ({ ref, ...props }) => {
  const {
    showText = "See more",
    hideText = "See less",
    headerPosition = "top",
    startOpen = false,
    linkElementType,
    onClick,
    onOpen,
    onClose,
    onChange = () => {
    },
    headerChildren,
    ...rest
  } = props;
  const [accordionState, setAccordionState] = (0, import_react.useState)({
    open: startOpen,
    withAnimation: false
  });
  const prefersReducedMotion = (0, import_mobius_hooks.usePrefersReducedMotion)();
  const containerClasses = (0, import_dedupe4.default)(
    "mobius",
    "mobius-accordion",
    props.className,
    {
      "--should-animate": accordionState.withAnimation && !prefersReducedMotion,
      "--is-open": accordionState.open
    }
  );
  const contentContainerClasses = (0, import_dedupe4.default)(
    "mobius-accordion__content-container",
    {
      "--is-open": accordionState.open
    }
  );
  const contentClasses = (0, import_dedupe4.default)("mobius-accordion__content", {
    "--is-open": accordionState.open
  });
  const linkText = accordionState.open ? hideText : showText;
  const handleChange = () => {
    if (!accordionState.open && onOpen) {
      onOpen();
    }
    if (accordionState.open && onClose) {
      onClose();
    }
    if (onChange) {
      onChange(!accordionState.open);
    }
    setAccordionState({
      open: !accordionState.open,
      withAnimation: true
    });
  };
  (0, import_react.useEffect)(() => {
    setAccordionState({
      open: startOpen,
      withAnimation: true
    });
  }, [startOpen]);
  const baseId = (0, import_react.useId)();
  const accordionId = `accordion-header-${baseId}`;
  const contentId = `accordion-panel-${baseId}`;
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ref, ...rest, className: containerClasses, children: [
    headerPosition === "top" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
      AccordionLink,
      {
        text: linkText,
        elementType: linkElementType,
        toggle: handleChange,
        onClick,
        ariaExpanded: accordionState.open,
        headerChildren,
        accordionId,
        contentId
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
      "div",
      {
        id: contentId,
        className: contentContainerClasses,
        "aria-hidden": !accordionState.open,
        "aria-labelledby": accordionId,
        role: "region",
        children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: contentClasses, children: props.children })
      }
    ),
    headerPosition === "bottom" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
      AccordionLink,
      {
        text: linkText,
        toggle: handleChange,
        onClick,
        ariaExpanded: accordionState.open,
        headerChildren,
        accordionId,
        contentId
      }
    )
  ] });
};
Accordion.displayName = "Accordion";

// src/components/Divider/Divider.tsx
var import_dedupe5 = __toESM(require("classnames/dedupe"));
var import_Divider = require("@simplybusiness/mobius/src/components/Divider/Divider.css");
var import_jsx_runtime5 = require("react/jsx-runtime");
var Divider = ({
  "aria-orientation": ariaOrientation = "horizontal",
  className,
  ...rest
}) => {
  const classes = (0, import_dedupe5.default)("mobius", "mobius-divider", className);
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
    "div",
    {
      className: classes,
      role: "separator",
      "aria-orientation": ariaOrientation,
      ...rest,
      children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mobius-divider__inner" })
    }
  );
};
Divider.displayName = "Divider";

// src/components/Accordion/AccordionList.tsx
var import_AccordionList = require("@simplybusiness/mobius/src/components/Accordion/AccordionList.css");
var import_jsx_runtime6 = require("react/jsx-runtime");
var AccordionList = (props) => {
  const {
    className,
    content,
    onOpen,
    onClose,
    allowMultiple = false,
    ...rest
  } = props;
  const [openIds, setOpenIds] = (0, import_react2.useState)(/* @__PURE__ */ new Set());
  const classes = (0, import_dedupe6.default)("mobius", "mobius-accordion-list", className);
  const handleAccordionChange = (id, isOpen) => {
    setOpenIds((prev) => {
      const newSet = new Set(prev);
      if (isOpen) {
        if (!allowMultiple) {
          newSet.clear();
        }
        newSet.add(id);
      } else {
        newSet.delete(id);
      }
      return newSet;
    });
    if (isOpen) {
      onOpen?.(id);
    } else {
      onClose?.(id);
    }
  };
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: classes, ...rest, children: content.map((item, index) => {
    const { id, header, details } = item;
    const isOpen = openIds.has(id);
    return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react2.Fragment, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
        Accordion,
        {
          startOpen: isOpen,
          showText: header,
          hideText: header,
          onChange: (isOpen2) => handleAccordionChange(id, isOpen2),
          children: details
        }
      ),
      index < content.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Divider, {})
    ] }, id);
  }) });
};
AccordionList.displayName = "AccordionList";
//# sourceMappingURL=AccordionList.js.map
