import { jsx as n, jsxs as S, Fragment as N } from "react/jsx-runtime";
import { useHover as se } from "./index-use-hover.js";
import { classNames as z } from "./index-classNames.js";
import { useState as ue, useRef as _, useCallback as E } from "react";
import { Icon as de, IconSize as G } from "./index-Icon.js";
import { IconNames as me } from "./index-IconNames.js";
import { Text as fe, FontWeights as be } from "./index-Text.js";
import e from "./index-Button.module.scss.js";
import H from "./index-Grow.js";
var u;
(function(r) {
  r.small = "small", r.medium = "medium", r.large = "large", r.extraLarge = "extra-large";
})(u || (u = {}));
var t;
(function(r) {
  r.default = "default", r.secondary = "secondary", r.primary = "primary", r.shimmer = "shimmer", r.muted = "muted";
})(t || (t = {}));
const Ne = (r) => {
  const {
    iconLeft: O,
    iconRight: D,
    children: d,
    disabled: l,
    debounce: M,
    textWrap: T,
    fontWeight: W,
    textType: R,
    className: F,
    visible: q,
    iconSize: w,
    iconFillColor: A,
    iconHasCircle: B,
    iconLargeOnHover: J,
    color: v,
    hoverColor: x,
    isLoading: s,
    testId: g,
    replacements: K,
    type: y = t.primary,
    size: Q = u.medium,
    onClick: P,
    onMouseDown: $,
    uppercase: U,
    w100: V,
    shape: X = "default"
  } = r;
  let {
    icon: o,
    iconPosition: m = "left",
    rounded: L = !1,
    iconColor: a,
    targetRef: C,
    iconHoverColor: i
  } = r;
  const Y = "blurred" in r ? r.blurred : !1, k = "inverted" in r ? r.inverted : !1;
  o || (O && (o = O, m = "left"), D && (o = D, m = "right")), L = L || X === "round";
  const [Z, ee] = ue(0), te = _(null);
  C || (C = te);
  const f = _(null), c = se(C);
  if (s && !o && !a && (o = me.save), !a)
    if (v)
      a = v;
    else
      switch (y) {
        case t.default:
          a = "--button-default-text-color";
          break;
        case t.secondary:
          a = "--button-secondary-text-color";
          break;
        case t.primary:
          a = "--button-primary-text-color";
          break;
        case t.shimmer:
          a = "--button-shimmer-text-color";
          break;
        case t.muted:
          a = k ? "--button-muted-inverted-text-color" : "--button-muted-text-color";
          break;
      }
  if (i)
    switch (y) {
      case t.default:
        i = "--button-default-hover-text-color";
        break;
      case t.secondary:
        i = "--button-default-text-color";
        break;
      case t.primary:
        i = "--button-primary-text-color";
        break;
      case t.shimmer:
        i = "--button-shimmer-text-color";
        break;
      case t.muted:
        a = k ? "--button-muted-inverted-text-color" : "--button-muted-text-color";
        break;
    }
  else if (x)
    i = x;
  else
    switch (y) {
      case t.default:
        i = "--button-default-hover-text-color";
        break;
      case t.secondary:
        i = "--button-secondary-hover-text-color";
        break;
      case t.primary:
        i = "--button-primary-hover-text-color";
        break;
      case t.shimmer:
        i = "--button-shimmer-hover-text-color";
        break;
      case t.muted:
        a = k ? "--button-muted-inverted-text-color" : "--button-muted-text-color";
        break;
    }
  const re = E(() => {
    if (!l)
      return x && c ? x : v;
  }, [l, c, x, v]), ne = E(() => {
    if (!l)
      return i && c ? i : a;
  }, [l, c, i, a]), oe = () => w || G.small, j = () => w === "large" ? !1 : J, ae = () => {
    switch (y) {
      case t.default:
        return e.buttonDefault;
      case t.primary:
        return e.buttonPrimary;
      case t.secondary:
        return e.buttonSecondary;
      case t.shimmer:
        return e.buttonShimmer;
      case t.muted:
        return e.buttonMuted;
      default:
        return e.buttonPrimary;
    }
  }, ie = () => {
    switch (Q) {
      case u.small:
        return e.sizeSmall;
      case u.medium:
        return e.sizeMedium;
      case u.large:
        return e.sizeLarge;
      case u.extraLarge:
        return e.sizeExtraLarge;
      default:
        return e.sizeMedium;
    }
  }, b = (h, I = !1, p = !1) => h ? n("span", {
    className: I || p ? e.buttonIconContainer : "",
    children: n(de, {
      type: p ? G.large : oe(),
      className: z(e.buttonIcon, s ? e.loaderSpinner : ""),
      color: ne(),
      fillColor: A,
      hasCircle: l || s ? !1 : B,
      testId: g ? `${g}_icon` : "",
      children: h
    })
  }) : null, le = (h) => {
    var I;
    if (M) {
      const p = Date.now();
      if (p - Z < M)
        return;
      ee(p);
    }
    l || s || (f && f.current && ((I = f == null ? void 0 : f.current) == null || I.blur()), P && P(h));
  }, ce = (h) => {
    l || s || $ && $(h);
  };
  return q === !1 ? null : n("span", {
    "data-testid": g,
    ref: C,
    className: z(e.buttonContainer, V ? e.buttonContainerFullWidth : ""),
    onClick: le,
    onMouseDown: ce,
    children: n("button", {
      ref: f,
      "data-testid": `${g ? `${g}_` : ""}button`,
      disabled: !!l,
      className: z("material-ripple", e.button, ae(), ie(), F || "", d && (d != null && d.length) ? "" : e.buttonLabelHidden, o && m === "left" ? e.hasIconLeft : "", o && m === "right" ? e.hasIconRight : "", L ? e.shapeRound : "", Y ? e.blurred : "", k ? e.inverted : ""),
      children: S("div", {
        className: e.buttonInnerContainer,
        children: [o && m === "left" ? j() && !s && !l ? S("div", {
          className: e.iconOnHoverContainer,
          children: [n("div", {
            className: e.iconSmallOnHover,
            children: n(H, {
              in: !c,
              children: b(o, !0) ?? n(N, {})
            })
          }), n("div", {
            className: e.iconLargeOnHover,
            children: n(H, {
              in: c,
              children: b(o, !1, !0) ?? n(N, {})
            })
          })]
        }) : b(o) : null, d && n(fe, {
          replacements: K,
          textWrap: T,
          type: R || void 0,
          fontWeight: W || be.medium,
          className: e.buttonText,
          color: re(),
          uppercase: U,
          children: d
        }), o && m === "right" ? j() && !s && !l ? S("div", {
          className: e.iconOnHoverContainer,
          children: [n("div", {
            className: e.iconSmallOnHover,
            children: n(H, {
              in: !c,
              children: b(o, !0) ?? n(N, {})
            })
          }), n("div", {
            className: e.iconLargeOnHover,
            children: n(H, {
              in: c,
              children: b(o, !1, !0) ?? n(N, {})
            })
          })]
        }) : b(o) : null]
      })
    })
  });
};
export {
  Ne as Button,
  u as ButtonSizes,
  t as ButtonTypes
};
