"use strict";
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/ExpandableText/index.tsx
var ExpandableText_exports = {};
__export(ExpandableText_exports, {
  ExpandableText: () => ExpandableText
});
module.exports = __toCommonJS(ExpandableText_exports);

// src/components/ExpandableText/ExpandableText.tsx
var import_dedupe7 = __toESM(require("classnames/dedupe"));
var import_react4 = require("react");

// src/hooks/useBreakpoint/useBreakpoint.tsx
var import_mobius_hooks = require("@simplybusiness/mobius-hooks");
var import_react = require("react");
var DEFAULT_BREAKPOINTS = [
  { size: "xs", value: 320 },
  { size: "sm", value: 480 },
  { size: "md", value: 670 },
  { size: "lg", value: 960 },
  { size: "xl", value: 1200 },
  { size: "xxl", value: 1320 }
];
var PASSIVE = { passive: true };
var getBreakpoint = (breakpoints, windowWidth) => {
  const closest = breakpoints.findIndex(
    (breakpoint) => breakpoint.value >= windowWidth + 1
  );
  const smallest = breakpoints[0];
  const largest = breakpoints[breakpoints.length - 1];
  const match = breakpoints[closest - 1];
  if (closest === 0) return smallest;
  if (closest === -1) return largest;
  return match;
};
var useBreakpoint = (customBreakpoints) => {
  const isClientSide = (0, import_mobius_hooks.useIsClient)();
  const breakpoints = customBreakpoints || DEFAULT_BREAKPOINTS;
  const defaultBreakpoint = breakpoints[0];
  const [windowWidth, setWindowWidth] = (0, import_react.useState)(
    typeof globalThis?.window !== "undefined" ? window.innerWidth : defaultBreakpoint.value
  );
  (0, import_mobius_hooks.useWindowEvent)("resize", () => setWindowWidth(window.innerWidth), PASSIVE);
  const debouncedWidth = (0, import_mobius_hooks.useDebouncedValue)(windowWidth, 200);
  const currentBreakpoint = (0, import_react.useMemo)(
    () => !isClientSide || breakpoints.length === 0 ? defaultBreakpoint : getBreakpoint(breakpoints, debouncedWidth),
    [isClientSide, breakpoints, defaultBreakpoint, debouncedWidth]
  );
  const up = (0, import_react.useCallback)(
    (size) => {
      const sizeIndex = breakpoints.findIndex((item) => item.size === size);
      if (sizeIndex === -1) {
        return false;
      }
      const currentIndex = breakpoints.findIndex(
        (item) => item.size === currentBreakpoint.size
      );
      return currentIndex >= sizeIndex;
    },
    [currentBreakpoint, breakpoints]
  );
  const down = (0, import_react.useCallback)(
    (size) => {
      const sizeIndex = breakpoints.findIndex((item) => item.size === size);
      if (sizeIndex === -1) {
        return true;
      }
      const currentIndex = breakpoints.findIndex(
        (item) => item.size === currentBreakpoint.size
      );
      return currentIndex <= sizeIndex;
    },
    [currentBreakpoint, breakpoints]
  );
  return {
    breakpoint: currentBreakpoint,
    up,
    down
  };
};

// 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/Accordion/Accordion.tsx
var import_dedupe4 = __toESM(require("classnames/dedupe"));
var import_react2 = require("react");
var import_mobius_hooks2 = 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/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_react2.useState)({
    open: startOpen,
    withAnimation: false
  });
  const prefersReducedMotion = (0, import_mobius_hooks2.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_react2.useEffect)(() => {
    setAccordionState({
      open: startOpen,
      withAnimation: true
    });
  }, [startOpen]);
  const baseId = (0, import_react2.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/TextOrHTML/TextOrHTML.tsx
var import_dedupe6 = __toESM(require("classnames/dedupe"));
var import_react3 = require("react");

// src/components/Text/Text.tsx
var import_dedupe5 = __toESM(require("classnames/dedupe"));
var import_Text = require("@simplybusiness/mobius/src/components/Text/Text.css");
var import_jsx_runtime5 = require("react/jsx-runtime");
var getElementType = (variant, elementType) => {
  if (elementType) {
    return elementType;
  }
  if (variant && ["h1", "h2", "h3", "h4"].includes(variant)) {
    return variant;
  }
  return "p";
};
var Text = ({ ref, elementType, ...props }) => {
  const { variant, className, spacing, ...otherProps } = props;
  const Element = getElementType(variant, elementType);
  const variantType = variant || Element;
  const classes = (0, import_dedupe5.default)(
    "mobius",
    "mobius-text",
    { [`--is-${variantType}`]: variantType },
    { [`--has-line-height-${spacing}`]: spacing },
    className
  );
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Element, { ref, ...otherProps, className: classes });
};
Text.displayName = "Text";

// src/components/TextOrHTML/TextOrHTML.tsx
var import_jsx_runtime6 = require("react/jsx-runtime");
var BLOCK_TAG = /<(div|p|ul|ol|li|h[1-6]|table|tr|td|th|blockquote|pre|hr|dl|dt|dd)[\s>/]/i;
var containsBlockHTML = (text) => BLOCK_TAG.test(text);
var containsHTML = (text) => /<[a-z/]/i.test(text) || /&(?:#\d+|#x[\da-f]+|[a-z]\w*);/i.test(text);
var buildTextClasses = (textProps, htmlClassName) => {
  const { variant, elementType, spacing, className } = textProps;
  const variantType = variant || getElementType(variant, elementType);
  return (0, import_dedupe6.default)(
    "mobius",
    "mobius-text",
    { [`--is-${variantType}`]: variantType },
    { [`--has-line-height-${spacing}`]: spacing },
    className,
    htmlClassName
  );
};
var TextOrHTML = ({
  ref,
  text,
  htmlClassName,
  htmlElementType,
  textWrapper = false,
  autoDetect = false,
  ...textProps
}) => {
  const hasBlockContent = autoDetect && containsBlockHTML(text);
  const dangerousHTML = (0, import_react3.useMemo)(() => ({ __html: text }), [text]);
  if (autoDetect && !hasBlockContent) {
    const { variant, spacing, elementType, className, ...domProps } = textProps;
    const Element = getElementType(variant, elementType);
    const classes = buildTextClasses(textProps, htmlClassName);
    return containsHTML(text) ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
      Element,
      {
        ref,
        ...domProps,
        className: classes,
        dangerouslySetInnerHTML: dangerousHTML
      }
    ) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Element, { ref, ...domProps, className: classes, children: text });
  }
  const DangerousComponent = htmlElementType ?? (hasBlockContent ? "div" : "span");
  const dangerousElement = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
    DangerousComponent,
    {
      className: htmlClassName,
      dangerouslySetInnerHTML: dangerousHTML
    }
  );
  if (textWrapper) {
    return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { ref, ...textProps, children: dangerousElement });
  }
  return dangerousElement;
};
TextOrHTML.displayName = "TextOrHTML";

// src/components/ExpandableText/ExpandableText.tsx
var import_ExpandableText = require("@simplybusiness/mobius/src/components/ExpandableText/ExpandableText.css");
var import_jsx_runtime7 = require("react/jsx-runtime");
var ExpandableText = ({ ref, ...props }) => {
  const {
    text,
    maxLines = 3,
    breakpoint,
    showText = "Read more",
    hideText = "Read less",
    className,
    textProps = {},
    accordionProps = {},
    onToggle,
    ...otherProps
  } = props;
  const [isExpanded, setIsExpanded] = (0, import_react4.useState)(false);
  const [isCollapsed, setIsCollapsed] = (0, import_react4.useState)(false);
  const textRef = (0, import_react4.useRef)(null);
  const { down } = useBreakpoint();
  const baseId = (0, import_react4.useId)();
  const expandButtonId = `expandable-text-expand-${baseId}`;
  const shouldCollapse = breakpoint ? down(breakpoint) : true;
  (0, import_react4.useEffect)(() => {
    if (!shouldCollapse || !textRef.current) {
      setIsCollapsed(false);
      return;
    }
    const element = textRef.current;
    const isOverflowing = element.scrollHeight > element.clientHeight;
    setIsCollapsed(isOverflowing);
  }, [text, shouldCollapse, maxLines]);
  if (breakpoint && !shouldCollapse) {
    return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { ref, className, ...otherProps, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextOrHTML, { text, textWrapper: true, ...textProps }) });
  }
  const handleAccordionChange = (expanded) => {
    setIsExpanded(expanded);
    onToggle?.(expanded);
  };
  const classes = (0, import_dedupe7.default)("mobius-expandable-text", className);
  const textContainerClasses = (0, import_dedupe7.default)("mobius-expandable-text__content", {
    "mobius-expandable-text__content--collapsed": !isExpanded
  });
  const textContainerStyle = {
    "--line-clamp": maxLines
  };
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
    "div",
    {
      ref,
      className: classes,
      "data-testid": "expandable-text",
      ...otherProps,
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
          "div",
          {
            ref: textRef,
            className: textContainerClasses,
            style: textContainerStyle,
            "data-testid": "expandable-text-content",
            "aria-describedby": isCollapsed ? expandButtonId : void 0,
            children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextOrHTML, { elementType: "span", textWrapper: true, text, ...textProps })
          }
        ),
        isCollapsed && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
          Accordion,
          {
            showText,
            hideText,
            headerPosition: "bottom",
            onChange: handleAccordionChange,
            onClick: (e) => {
              e?.stopPropagation();
            },
            id: expandButtonId,
            ...accordionProps
          }
        )
      ]
    }
  );
};
ExpandableText.displayName = "ExpandableText";
//# sourceMappingURL=index.js.map
