"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkOA2TKY4Kcjs = require('./chunk-OA2TKY4K.cjs');


var _chunkSNSG4HBQcjs = require('./chunk-SNSG4HBQ.cjs');


var _chunkUFU3BYZOcjs = require('./chunk-UFU3BYZO.cjs');


var _chunkWF7Z2VITcjs = require('./chunk-WF7Z2VIT.cjs');


var _chunkRSHN4K6Ncjs = require('./chunk-RSHN4K6N.cjs');


var _chunkGH54P25Bcjs = require('./chunk-GH54P25B.cjs');


var _chunkCDFVRIETcjs = require('./chunk-CDFVRIET.cjs');


var _chunk6VA4SAHQcjs = require('./chunk-6VA4SAHQ.cjs');


var _chunkEDMCWD63cjs = require('./chunk-EDMCWD63.cjs');



var _chunkOBHJBBPCcjs = require('./chunk-OBHJBBPC.cjs');




var _chunkZ6EUSUADcjs = require('./chunk-Z6EUSUAD.cjs');

// src/components/Button.tsx
var _react = require('@emotion/react');
var _styled = require('@emotion/styled'); var _styled2 = _interopRequireDefault(_styled);
var _lodashes = require('lodash-es');




var _react3 = require('react');
var _jsxruntime = require('@emotion/react/jsx-runtime');
var buttonKinds = [
  "secondary",
  "primary",
  "ghost",
  "transparent",
  "green33",
  "green37",
  "purple55",
  "blue43",
  "blue39",
  "linkLight",
  "danger",
  "warning",
  "tertiary",
  "quaternary",
  "roundSingleChar",
  "roundIcon",
  "gray",
  "grayGradient",
  "gray99",
  "white21",
  "locked",
  "warningLight"
];
function resolveBackgroundColorKey(theme, kind, defaultKey) {
  var _a;
  const defaultBackgroundColorKey = (_a = theme.buttons.kinds[kind]) == null ? void 0 : _a[defaultKey];
  let backgroundColorKey = defaultBackgroundColorKey;
  if (!backgroundColorKey && _chunkOBHJBBPCcjs.isThemeOrColorKey.call(void 0, kind)) {
    backgroundColorKey = kind;
  }
  const defaultBackgroundColor = theme.buttons[defaultKey];
  const backgroundColor = _chunkOBHJBBPCcjs.getBackgroundColor.call(void 0, 
    theme,
    backgroundColorKey,
    defaultBackgroundColor
  );
  return backgroundColor;
}
function resolveProp(prop, kind, defaultKey, theme) {
  var _a;
  return (
    /** props may be unset for a given kind but theme defaults always exist,
     * so this will always resolve a value: */
    prop || ((_a = theme.buttons.kinds[kind]) == null ? void 0 : _a[defaultKey]) || theme.buttons[defaultKey]
  );
}
function resolveProps(props, theme) {
  const isSingleCharRoundButton = Boolean(
    props.text && props.text.length === 1 && !props.icon
  );
  const isRoundIconButton = Boolean(!props.text && props.icon);
  const defaultKind = isSingleCharRoundButton ? "roundSingleChar" : isRoundIconButton ? "roundIcon" : "secondary";
  const _a = props, {
    kind = defaultKind,
    size: sizeProp,
    paddingY: paddingYType = "regular",
    borderRadius,
    typography: typographyProp
  } = _a, rest = _chunkZ6EUSUADcjs.__objRest.call(void 0, _a, [
    "kind",
    "size",
    "paddingY",
    "borderRadius",
    "typography"
  ]);
  const size = resolveProp(sizeProp, kind, "defaultSize", theme);
  const defaultPaddingsY = resolveProp(null, kind, "defaultPaddingsY", theme);
  const defaultPaddingY = defaultPaddingsY[size];
  const defaultPaddingsX = resolveProp(null, kind, "defaultPaddingsX", theme);
  const defaultPaddingX = defaultPaddingsX[size];
  const backgroundColor = resolveBackgroundColorKey(
    theme,
    kind,
    "defaultBackgroundColor"
  );
  const borderColor = resolveBackgroundColorKey(
    theme,
    kind,
    "defaultBorderColor"
  );
  const hoverBackgroundColor = resolveBackgroundColorKey(
    theme,
    kind,
    "defaultHoverBackgroundColor"
  );
  const hoverBorderColor = resolveBackgroundColorKey(
    theme,
    kind,
    "defaultHoverBorderColor"
  );
  const activeBackgroundColor = resolveBackgroundColorKey(
    theme,
    kind,
    "defaultActiveBackgroundColor"
  );
  const activeBorderColor = resolveBackgroundColorKey(
    theme,
    kind,
    "defaultActiveBorderColor"
  );
  const typography = {
    type: (typographyProp == null ? void 0 : typographyProp.type) || resolveProp(null, kind, "defaultTypographyType", theme),
    color: (typographyProp == null ? void 0 : typographyProp.color) || resolveProp(null, kind, "defaultColor", theme),
    size
  };
  return _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, rest), {
    kind,
    size,
    typography,
    paddingY: typeof defaultPaddingY === "number" ? defaultPaddingY : defaultPaddingY[paddingYType],
    paddingX: defaultPaddingX,
    borderRadius: kind === "roundSingleChar" || kind === "roundIcon" ? 999 : resolveProp(borderRadius, kind, "defaultBorderRadius", theme),
    backgroundColor,
    borderColor,
    hoverBackgroundColor,
    hoverBorderColor,
    activeBackgroundColor,
    activeBorderColor
  });
}
var Button = _react3.forwardRef.call(void 0, (props, ref) => {
  const theme = _react.useTheme.call(void 0, );
  const {
    kind,
    typography,
    size,
    paddingX,
    paddingY,
    text,
    to,
    id,
    hash,
    externalLink,
    filename,
    toParams,
    onClick,
    onMouseEnter,
    onMouseDown,
    onMouseUp,
    onMouseLeave,
    onFocus,
    onBlur,
    icon,
    backgroundColor,
    borderColor,
    hoverBackgroundColor,
    hoverBorderColor,
    activeBackgroundColor,
    activeBorderColor,
    iconSide = "left",
    loading = false,
    loadingKind = "primary",
    fullWidth = false,
    spaceBetween = false,
    disabled = false,
    mt = 0,
    ml = 0,
    mb = 0,
    type = "button",
    newTab = false,
    zIndex = void 0,
    tooltipText,
    borderRadius
  } = resolveProps(props, theme);
  const tooltipId = _react3.useRef.call(void 0, _lodashes.uniqueId.call(void 0, ));
  const defaultIconWidth = size === "ExtraSmall" ? 12 : 16;
  let currentIcon = null;
  if (loading) {
    currentIcon = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      ButtonIcon,
      {
        iconSide,
        text,
        typography,
        kind,
        paddingX,
        children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkOA2TKY4Kcjs.Loading, { size: defaultIconWidth, center: false, kind: loadingKind })
      }
    );
  } else if (icon) {
    currentIcon = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      ButtonIcon,
      {
        iconSide,
        text,
        typography,
        kind,
        paddingX,
        children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
          _chunkWF7Z2VITcjs.Icon,
          _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, icon), {
            width: icon.width || defaultIconWidth,
            square: icon.square === void 0 ? true : icon.square,
            color: icon.color || typography.color
          })
        )
      }
    );
  }
  const content = /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react3.Fragment, { children: [
    /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, 
      "div",
      _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, tooltipText ? { "data-tooltip-id": tooltipId.current } : {}), {
        css: {
          display: "flex",
          alignItems: "center",
          justifyContent: spaceBetween ? "space-between" : "center",
          gap: "8px"
        },
        children: [
          iconSide === "left" && currentIcon,
          text && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
            "div",
            {
              css: {
                textOverflow: "ellipsis",
                overflow: "hidden"
              },
              children: _chunkCDFVRIETcjs.renderTypography.call(void 0, typography.type, {
                children: text,
                color: typography.color,
                size: typography.size
              })
            }
          ),
          iconSide === "right" && currentIcon
        ]
      })
    ),
    tooltipText ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUFU3BYZOcjs.Tooltip, { id: tooltipId.current, content: tooltipText }) : null
  ] });
  const commonProps = {
    id,
    kind,
    type,
    typography,
    onClick,
    onMouseEnter,
    onMouseDown,
    onMouseUp,
    onMouseLeave,
    onFocus,
    onBlur,
    fullWidth,
    iconSide,
    paddingX,
    paddingY,
    backgroundColor,
    borderColor,
    hoverBackgroundColor,
    hoverBorderColor,
    activeBackgroundColor,
    activeBorderColor,
    isLoading: loading,
    disabled: disabled || loading,
    css: {
      marginTop: mt ? typeof mt === "number" ? `${mt}px` : "auto" : void 0,
      marginLeft: ml ? typeof ml === "number" ? `${ml}px` : "auto" : void 0,
      marginBottom: mb ? typeof mb === "number" ? `${mb}px` : "auto" : void 0
    },
    newTab,
    borderRadius,
    zIndex
  };
  if (to) {
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      ButtonLink,
      _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, commonProps), {
        to,
        params: toParams,
        hash,
        ref,
        children: content
      })
    );
  }
  return externalLink ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
    ButtonHrefLink,
    _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, commonProps), {
      href: externalLink,
      download: filename,
      target: "_blank",
      ref,
      children: content
    })
  ) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, StyledButton, _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, commonProps), { ref, children: content }));
});
Button.displayName = "Button";
var buttonStyle = ({
  paddingX,
  paddingY,
  kind,
  theme,
  disabled,
  isLoading,
  typography,
  fullWidth,
  zIndex,
  iconSide,
  borderColor: borderColorProp,
  borderRadius,
  backgroundColor,
  hoverBackgroundColor,
  hoverBorderColor,
  activeBackgroundColor,
  activeBorderColor
}) => {
  const borderColor = borderColorProp || backgroundColor;
  return _react.css`
    display: inline-flex;
    opacity: ${disabled && !isLoading ? 0.2 : 1};
    transition: opacity 0.2s;
    position: relative;

    ${zIndex && `z-index: ${zIndex};`}

    ${_chunkEDMCWD63cjs.applyTypography.call(void 0, 
    theme,
    typography.type,
    typography.size,
    typography.color
  )}

    &:focus-visible {
      outline: ${_chunkRSHN4K6Ncjs.getFocusOutline.call(void 0, { theme })};
      /* Slightly different offset for buttons so the outline is visible: */
      outline-offset: 0px;
    }

    width: ${fullWidth ? "100%" : "fit-content"};

    & > * {
      width: 100%;
      text-align: center;
      white-space: nowrap;
      background-color: ${backgroundColor};
      box-sizing: content-box;
      border: 1px solid;
      border-color: ${borderColor};
      border-radius: ${typeof borderRadius === "number" ? `${borderRadius}px` : borderRadius};
      padding: ${paddingY}px ${paddingX}px;
      transition:
        background-color 0.2s ease-out,
        border-color 0.2s ease-out;

      &:hover {
        background-color: ${hoverBackgroundColor};
        border-color: ${hoverBorderColor};
      }

      &:active {
        background-color: ${activeBackgroundColor};
        border-color: ${activeBorderColor};
      }
    }
  `;
};
var ButtonIcon = _styled2.default.div`
  display: flex;
  align-items: center;
  justify-content: center;
  ${({ iconSide, paddingX }) => `${iconSide}: ${paddingX}px;`}
`;
var LinkWithoutTypography = _react3.forwardRef.call(void 0, (props, ref) => {
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkGH54P25Bcjs.Link, _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, props), { ref }));
});
var StyledButton = _styled2.default.call(void 0, _chunkSNSG4HBQcjs.UnstyledButton)`
  ${(props) => buttonStyle(props)}
`;
var ButtonLink = _styled2.default.call(void 0, LinkWithoutTypography)`
  ${(props) => buttonStyle(props)}
`;
var ButtonHrefLink = _styled2.default.a`
  ${(props) => buttonStyle(props)}
`;
var ButtonSelector = (prepend = "", append = "") => `${prepend}*:is(${_chunk6VA4SAHQcjs.select.call(void 0, StyledButton)}, ${_chunk6VA4SAHQcjs.select.call(void 0, ButtonLink)}, ${_chunk6VA4SAHQcjs.select.call(void 0, 
  ButtonHrefLink
)})${append}`;






exports.buttonKinds = buttonKinds; exports.Button = Button; exports.StyledButton = StyledButton; exports.ButtonSelector = ButtonSelector;
