// ../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/components/spinner/spinner.tsx
import { jsx as jsx3 } 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__ */ jsx3("span", { className: classes, ...attributes, children: /* @__PURE__ */ jsx3("span", { className: `${componentClassName}__inner` }) });
};

// ../src/components/button/button-base.tsx
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "preact/jsx-runtime";
var InnerButton = ({ text, isIconButton = false, attributes, icon, loadingHtml }) => {
  let optionalHtml;
  if (!isIconButton && attributes["aria-label"]) {
    optionalHtml = /* @__PURE__ */ jsx4("span", { "aria-hidden": "true", children: text });
  } else if (!isIconButton) {
    optionalHtml = /* @__PURE__ */ jsx4("span", { children: text });
  }
  return /* @__PURE__ */ jsxs2(Fragment, { children: [
    optionalHtml,
    icon,
    loadingHtml
  ] });
};
var ToggleWrapper = ({
  selected = false,
  disabled = false,
  attributes,
  classes,
  onChild,
  offChild,
  loadingHtml
}) => {
  return /* @__PURE__ */ jsxs2("button", { type: "button", role: "switch", "aria-checked": selected, className: classes, ...attributes, disabled, children: [
    /* @__PURE__ */ jsx4("span", { className: "ds-btn__off", "aria-hidden": "true", children: onChild }),
    /* @__PURE__ */ jsx4("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__ */ jsx4(Spinner, { ...{ size: "small", variant: spinnerVariant, forcePx, attributes: { "aria-hidden": "true" } } });
  let icon;
  if (iconName && (iconPosition != "none" || isIconButton == true)) {
    icon = /* @__PURE__ */ jsx4(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__ */ jsx4(IconUse, { iconName });
      offChild = /* @__PURE__ */ jsx4(IconUse, { iconName: selectedIconName });
    } else {
      onChild = /* @__PURE__ */ jsx4("span", { children: text });
      offChild = /* @__PURE__ */ jsxs2(Fragment, { children: [
        /* @__PURE__ */ jsx4(IconUse, { iconName: "check" }),
        /* @__PURE__ */ jsx4("span", { children: selectedText })
      ] });
    }
    buttonToRender = /* @__PURE__ */ jsx4(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__ */ jsx4("a", { href, className: classes, ...attributes, children: /* @__PURE__ */ jsx4(InnerButton, { ...params }) });
    } else {
      buttonToRender = /* @__PURE__ */ jsx4("button", { type, className: classes, ...attributes, disabled, children: /* @__PURE__ */ jsx4(InnerButton, { ...buttonParams }) });
    }
  }
  return /* @__PURE__ */ jsx4(Fragment, { children: buttonToRender });
};

// ../src/components/button-toggle/button-toggle.tsx
import { jsx as jsx5 } 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__ */ jsx5(
    ButtonBase,
    {
      ...{
        selected,
        text,
        disabled,
        variant,
        size,
        fullWidth,
        mobileFullWidth,
        isIconButton,
        iconName,
        selectedIconName,
        loading,
        classNames,
        attributes,
        forcePx,
        isToggle: true,
        selectedText,
        type: "button"
      }
    }
  );
};

// ../src/helpers/formatThousandsWithSpaces.ts
var formatThousandsWithSpaces = (value) => {
  const stringValue = value.toString();
  if (value >= 1e3) {
    return stringValue.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
  }
  return stringValue;
};

// ../src/components/tag-header/tag-header.tsx
import { jsx as jsx6, jsxs as jsxs3 } from "preact/jsx-runtime";
var TagHeader = ({
  title,
  vignetteText,
  vignetteTargetUrl,
  media,
  descriptionHtml,
  articleCount,
  theme,
  toggle = false,
  toggleText,
  toggleSelectedText,
  toggleSelected = false,
  toggleLoading = false,
  toggleClassNames,
  toggleAttributes,
  attributes = {},
  classNames
}) => {
  const componentClassName = "ds-tag-header";
  const classes = formatClassString([
    componentClassName,
    theme && `${componentClassName}--${theme}`,
    (!!descriptionHtml || !!articleCount) && `${componentClassName}--has-border`,
    classNames
  ]);
  return /* @__PURE__ */ jsx6("div", { className: classes, ...attributes, children: /* @__PURE__ */ jsxs3("div", { className: `${componentClassName}__content`, children: [
    /* @__PURE__ */ jsxs3("div", { className: `${componentClassName}__bar`, children: [
      /* @__PURE__ */ jsxs3("div", { className: `${componentClassName}__heading`, children: [
        vignetteText && (vignetteTargetUrl ? /* @__PURE__ */ jsx6("a", { href: vignetteTargetUrl, className: `${componentClassName}__vignette`, children: vignetteText }) : /* @__PURE__ */ jsx6("span", { className: `${componentClassName}__vignette`, children: vignetteText })),
        /* @__PURE__ */ jsx6("h1", { className: `${componentClassName}__title`, children: title }),
        toggle && /* @__PURE__ */ jsx6(
          ButtonToggle,
          {
            variant: "primary",
            size: "md",
            isIconButton: false,
            text: toggleText,
            selectedText: toggleSelectedText || toggleText || "",
            selected: toggleSelected,
            loading: toggleLoading,
            classNames: toggleClassNames,
            attributes: toggleAttributes
          }
        )
      ] }),
      media && /* @__PURE__ */ jsx6("div", { className: `${componentClassName}__media`, children: media })
    ] }),
    descriptionHtml && /* @__PURE__ */ jsx6("div", { className: `${componentClassName}__description`, dangerouslySetInnerHTML: { __html: descriptionHtml } }),
    articleCount && /* @__PURE__ */ jsxs3("p", { className: `${componentClassName}__article-count`, children: [
      formatThousandsWithSpaces(articleCount),
      " ",
      articleCount === 1 ? "artikel" : "artiklar"
    ] })
  ] }) });
};
export {
  TagHeader
};
//# sourceMappingURL=tag-header.js.map
