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

// src/components/Button/Button.tsx
var import_dedupe2 = __toESM(require("classnames/dedupe"));

// src/components/Button/Loading.tsx
var import_icons = require("@simplybusiness/icons");

// src/components/Icon/Icon.tsx
var import_dedupe = __toESM(require("classnames/dedupe"));
var import_Icon = require("@simplybusiness/mobius/src/components/Icon/Icon.css");
var import_jsx_runtime = 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_dedupe.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_runtime.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_runtime.jsx)("title", { children: titleText }),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { fill: "currentColor", d: svgPathData })
      ]
    }
  );
}

// src/components/VisuallyHidden/VisuallyHidden.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
function VisuallyHidden(props) {
  const {
    className,
    children,
    elementType: Component = "div",
    ...otherProps
  } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
    Component,
    {
      className,
      style: {
        border: 0,
        clip: "rect(0 0 0 0)",
        clipPath: "inset(50%)",
        height: "1px",
        margin: "-1px",
        overflow: "hidden",
        padding: 0,
        position: "absolute",
        width: "1px",
        whiteSpace: "nowrap"
      },
      ...otherProps,
      children
    }
  );
}

// src/components/Button/Loading.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
var Loading = (props) => {
  const { children } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "mobius-button__icon-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, { icon: import_icons.loading, spin: true, size: "md" }) }),
    /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(VisuallyHidden, { className: "mobius-button__loading-text", children: "Loading" }),
    children
  ] });
};

// src/hooks/useButton/useButton.tsx
var import_react = require("react");
function useButton({
  elementType = "button",
  type = "button",
  isDisabled = false,
  href,
  target,
  rel,
  role,
  name,
  value,
  onClick,
  onPress
}) {
  const realOnClick = (0, import_react.useCallback)(
    (event) => {
      if (isDisabled) {
        return;
      }
      onClick?.(event);
      onPress?.(event);
    },
    [isDisabled, onClick, onPress]
  );
  function getRole() {
    if (role) {
      return role;
    }
    if (elementType === "a") {
      return void 0;
    }
    return "button";
  }
  const extraProps = elementType === "button" ? { type } : {
    role: getRole()
  };
  return {
    buttonProps: {
      href: elementType === "a" ? href : void 0,
      target: elementType === "a" ? target : void 0,
      rel: elementType === "a" ? rel : void 0,
      tabIndex: isDisabled ? -1 : 0,
      disabled: isDisabled || void 0,
      "aria-disabled": isDisabled || void 0,
      name: elementType === "input" || elementType === "button" ? name : void 0,
      value: elementType === "input" || elementType === "button" ? value : void 0,
      ...extraProps,
      onClick: realOnClick
    }
  };
}

// src/components/Button/Success.tsx
var import_icons2 = require("@simplybusiness/icons");
var import_jsx_runtime4 = require("react/jsx-runtime");
var Success = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "mobius-button__icon-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { icon: import_icons2.tick, size: "md" }) }),
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(VisuallyHidden, { className: "mobius-button__success-text", children: "Success" })
] });

// src/components/Button/Button.tsx
var import_Button = require("@simplybusiness/mobius/src/components/Button/Button.css");
var import_jsx_runtime5 = require("react/jsx-runtime");
var Button = ({ ref, ...props }) => {
  const {
    children,
    elementType: Component = "button",
    isDisabled,
    isLoading,
    isSuccess,
    variant = "primary",
    size = "md",
    onPress,
    onClick,
    ...otherProps
  } = props;
  const { buttonProps } = useButton(props);
  otherProps.className = (0, import_dedupe2.default)(
    "mobius",
    "mobius-button",
    `--variant-${variant}`,
    `--size-${size}`,
    {
      "--is-disabled": isDisabled,
      "--is-loading": isLoading,
      "--is-success": isSuccess && !isLoading
    },
    otherProps.className
  );
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Component, { ref, ...buttonProps, ...otherProps, children: [
    isLoading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Loading, { children }) : children,
    isSuccess && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Success, {})
  ] });
};
Button.displayName = "Button";
//# sourceMappingURL=index.js.map
