// ../src/helpers/formatClassString.ts
var formatClassString = (classesArray) => {
  return classesArray.filter((x) => !!x).join(" ");
};

// ../src/foundations/icons/sprite.svg
import { h } from "preact";
import { jsx, jsxs } from "preact/jsx-runtime";

// ../src/components/icon-sprite/icon-sprite.tsx
import { jsx as jsx2 } from "preact/jsx-runtime";
var IconUse = ({ iconName, classNames, attributes }) => {
  const componentClassName = "ds-icon";
  const classes = formatClassString([
    componentClassName,
    `${componentClassName}--sprite`,
    `${componentClassName}--${iconName}`,
    classNames
  ]);
  return /* @__PURE__ */ jsx2("i", { className: classes, ...attributes, children: /* @__PURE__ */ jsx2("svg", { children: /* @__PURE__ */ jsx2("use", { xlinkHref: `#ds-${iconName}` }) }) });
};

// ../src/assets/form-field/form-field.tsx
import { jsx as jsx3, jsxs as jsxs2 } from "preact/jsx-runtime";
var FormField = ({
  error,
  errorMessage,
  wrapperClasses,
  helpHtml,
  helpText,
  type,
  children
}) => {
  const classes = formatClassString([
    "ds-form-field",
    wrapperClasses,
    error && `ds-form-field__error`,
    type === "hidden" && "hidden"
  ]);
  const showHelp = helpHtml || helpText;
  return /* @__PURE__ */ jsxs2("div", { className: classes, children: [
    children,
    errorMessage && /* @__PURE__ */ jsxs2("div", { className: "ds-form-field__error-message js-field-error", children: [
      /* @__PURE__ */ jsx3(IconUse, { iconName: "info-filled" }),
      /* @__PURE__ */ jsx3("span", { children: errorMessage })
    ] }),
    showHelp && /* @__PURE__ */ jsx3("p", { className: "ds-form-field__help-text", children: helpHtml ? helpHtml : helpText })
  ] });
};

// ../src/components/spinner/spinner.tsx
import { jsx as jsx4 } from "preact/jsx-runtime";
var Spinner = ({ variant = "primary", size = "large", forcePx, classNames, attributes }) => {
  const componentClassName = "ds-spinner";
  const classes = formatClassString([
    `${componentClassName}`,
    `${componentClassName}--${variant}`,
    `${componentClassName}--${size}`,
    forcePx && "ds-force-px",
    classNames
  ]);
  return /* @__PURE__ */ jsx4("span", { className: classes, ...attributes, children: /* @__PURE__ */ jsx4("span", { className: `${componentClassName}__inner` }) });
};

// ../src/components/button/button-base.tsx
import { Fragment, jsx as jsx5, jsxs as jsxs3 } from "preact/jsx-runtime";
var InnerButton = ({ text, isIconButton = false, attributes, icon, loadingHtml }) => {
  let optionalHtml;
  if (!isIconButton && attributes["aria-label"]) {
    optionalHtml = /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", children: text });
  } else if (!isIconButton) {
    optionalHtml = /* @__PURE__ */ jsx5("span", { children: text });
  }
  return /* @__PURE__ */ jsxs3(Fragment, { children: [
    optionalHtml,
    icon,
    loadingHtml
  ] });
};
var ToggleWrapper = ({
  selected = false,
  disabled = false,
  attributes,
  classes,
  onChild,
  offChild,
  loadingHtml
}) => {
  return /* @__PURE__ */ jsxs3("button", { type: "button", role: "switch", "aria-checked": selected, className: classes, ...attributes, disabled, children: [
    /* @__PURE__ */ jsx5("span", { className: "ds-btn__off", "aria-hidden": "true", children: onChild }),
    /* @__PURE__ */ jsx5("span", { className: "ds-btn__on", "aria-hidden": "true", children: offChild }),
    loadingHtml
  ] });
};
var ButtonBase = ({
  text,
  disabled = false,
  variant = "primary",
  size = "md",
  fullWidth = false,
  mobileFullWidth = false,
  iconPosition = "none",
  iconName,
  loading = false,
  type = "button",
  href,
  classNames,
  attributes = {},
  forcePx = false,
  isIconButton = false,
  selected = false,
  isToggle = false,
  selectedIconName,
  selectedText
}) => {
  if (isIconButton && text && !attributes["aria-label"]) {
    attributes["aria-label"] = text;
  } else if (isToggle && text && selectedText && !attributes["aria-label"]) {
    attributes["aria-label"] = selected ? selectedText : text;
  }
  let spinnerVariant = "secondary";
  if (variant === "staticWhite" || variant === "transparent") {
    spinnerVariant = "staticBlack";
  } else if (variant === "secondaryFilled" || variant === "secondaryOutline") {
    spinnerVariant = "primary";
  }
  const loadingHtml = /* @__PURE__ */ jsx5(Spinner, { ...{ size: "small", variant: spinnerVariant, forcePx, attributes: { "aria-hidden": "true" } } });
  let icon;
  if (iconName && (iconPosition != "none" || isIconButton == true)) {
    icon = /* @__PURE__ */ jsx5(IconUse, { ...{ iconName, attributes: { "aria-hidden": "true" } } });
  }
  const classNamePrefix = "ds-btn--";
  const classes = formatClassString([
    "ds-btn",
    `${classNamePrefix}${variant}`,
    `${classNamePrefix}${size}`,
    isToggle && selected && `${classNamePrefix}selected`,
    fullWidth && `${classNamePrefix}full-width`,
    mobileFullWidth && `${classNamePrefix}mobile-full-width`,
    icon && !isIconButton && `${classNamePrefix}icon-${iconPosition}`,
    isIconButton && `${classNamePrefix}icon-only`,
    isToggle && `${classNamePrefix}toggle`,
    loading && "ds-loading",
    forcePx && "ds-force-px",
    classNames
  ]);
  let buttonToRender;
  if (isToggle) {
    let onChild, offChild;
    if (isIconButton && iconName && selectedIconName) {
      onChild = /* @__PURE__ */ jsx5(IconUse, { iconName });
      offChild = /* @__PURE__ */ jsx5(IconUse, { iconName: selectedIconName });
    } else {
      onChild = /* @__PURE__ */ jsx5("span", { children: text });
      offChild = /* @__PURE__ */ jsxs3(Fragment, { children: [
        /* @__PURE__ */ jsx5(IconUse, { iconName: "check" }),
        /* @__PURE__ */ jsx5("span", { children: selectedText })
      ] });
    }
    buttonToRender = /* @__PURE__ */ jsx5(ToggleWrapper, { ...{ selected, classes, attributes, disabled, onChild, offChild, loadingHtml } });
  } else {
    const buttonParams = { isIconButton, text, icon, loadingHtml, attributes };
    if (href) {
      const params = { ...buttonParams, loadingHtml: null };
      buttonToRender = /* @__PURE__ */ jsx5("a", { href, className: classes, ...attributes, children: /* @__PURE__ */ jsx5(InnerButton, { ...params }) });
    } else {
      buttonToRender = /* @__PURE__ */ jsx5("button", { type, className: classes, ...attributes, disabled, children: /* @__PURE__ */ jsx5(InnerButton, { ...buttonParams }) });
    }
  }
  return /* @__PURE__ */ jsx5(Fragment, { children: buttonToRender });
};

// ../src/components/button-toggle/button-toggle.tsx
import { jsx as jsx6 } from "preact/jsx-runtime";
var ButtonToggle = ({
  selected = false,
  text,
  selectedText,
  disabled = false,
  variant = "primary",
  size = "md",
  fullWidth = false,
  mobileFullWidth = false,
  isIconButton = false,
  iconName,
  selectedIconName,
  loading = false,
  attributes = {},
  classNames,
  forcePx = false
}) => {
  return /* @__PURE__ */ jsx6(
    ButtonBase,
    {
      ...{
        selected,
        text,
        disabled,
        variant,
        size,
        fullWidth,
        mobileFullWidth,
        isIconButton,
        iconName,
        selectedIconName,
        loading,
        classNames,
        attributes,
        forcePx,
        isToggle: true,
        selectedText,
        type: "button"
      }
    }
  );
};

// ../src/components/text-input/text-input.tsx
import { jsx as jsx7, jsxs as jsxs4 } from "preact/jsx-runtime";
var TextInput = ({
  name,
  type = "text",
  label,
  error,
  errorMessage,
  validation,
  helpText,
  required,
  disabled,
  forcePx,
  autofocus,
  classNames = "",
  attributes
}) => {
  const componentClassName = "ds-text-input";
  const wrapperClasses = formatClassString([componentClassName, forcePx && "ds-force-px", classNames]);
  const password = type === "password";
  return /* @__PURE__ */ jsxs4(FormField, { ...{ error, errorMessage, helpText, wrapperClasses }, children: [
    /* @__PURE__ */ jsx7(
      "input",
      {
        type,
        id: name,
        name,
        className: `${componentClassName}__input js-field-error ${password && "password-toggle"}`,
        "data-validation": validation,
        disabled,
        required,
        autoFocus: autofocus,
        placeholder: " ",
        ...attributes
      }
    ),
    /* @__PURE__ */ jsx7("label", { className: `${componentClassName}__label`, htmlFor: name, children: label }),
    password && /* @__PURE__ */ jsx7(
      ButtonToggle,
      {
        variant: "transparent",
        size: "sm",
        iconName: "visibility",
        selectedIconName: "visibility_off",
        isIconButton: true,
        selected: false,
        classNames: `${componentClassName}__password-toggle`,
        attributes: {
          id: `${name}-password-toggle`,
          "aria-label": "Visa l\xF6senord"
        },
        forcePx
      }
    )
  ] });
};
export {
  TextInput
};
//# sourceMappingURL=text-input.js.map
