"use client";
'use strict';

var React = require('react');
var forms = require('@page-speed/forms');
var inputs = require('@page-speed/forms/inputs');
var img = require('@page-speed/img');
var clsx = require('clsx');
var tailwindMerge = require('tailwind-merge');
var classVarianceAuthority = require('class-variance-authority');
var jsxRuntime = require('react/jsx-runtime');
var icon = require('@page-speed/icon');
var reactSlot = require('@radix-ui/react-slot');
var AspectRatioPrimitive = require('@radix-ui/react-aspect-ratio');
var CheckboxPrimitive = require('@radix-ui/react-checkbox');
var LabelPrimitive = require('@radix-ui/react-label');
var integration = require('@page-speed/forms/integration');

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);
var AspectRatioPrimitive__namespace = /*#__PURE__*/_interopNamespace(AspectRatioPrimitive);
var CheckboxPrimitive__namespace = /*#__PURE__*/_interopNamespace(CheckboxPrimitive);
var LabelPrimitive__namespace = /*#__PURE__*/_interopNamespace(LabelPrimitive);

// components/blocks/resource-list/resource-list-hero-filter.tsx
var TextInput = inputs.TextInput;
function cn(...inputs) {
  return tailwindMerge.twMerge(clsx.clsx(inputs));
}
function getNestedCardBg(parentBg, variant = "muted", options) {
  {
    switch (variant) {
      case "muted":
        return "bg-muted";
      case "card":
        return "bg-card";
      case "accent":
        return "bg-accent";
      case "subtle":
        return "bg-muted/50";
    }
  }
}
function getNestedCardTextColor(parentBg, options) {
  const isDark = parentBg === "primary";
  return isDark ? "text-foreground" : "";
}
function normalizePhoneNumber(input) {
  const trimmed = input.trim();
  if (trimmed.toLowerCase().startsWith("tel:")) {
    return trimmed;
  }
  const match = trimmed.match(/^[\s\+\-\(\)]*(\d[\d\s\-\(\)\.]*\d)[\s\-]*(x|ext\.?|extension)?[\s\-]*(\d+)?$/i);
  if (match) {
    const mainNumber = match[1].replace(/[\s\-\(\)\.]/g, "");
    const extension = match[3];
    const normalized = mainNumber.length >= 10 && !trimmed.startsWith("+") ? `+${mainNumber}` : mainNumber;
    const withExtension = extension ? `${normalized};ext=${extension}` : normalized;
    return `tel:${withExtension}`;
  }
  const cleaned = trimmed.replace(/[\s\-\(\)\.]/g, "");
  return `tel:${cleaned}`;
}
function normalizeEmail(input) {
  const trimmed = input.trim();
  if (trimmed.toLowerCase().startsWith("mailto:")) {
    return trimmed;
  }
  return `mailto:${trimmed}`;
}
function isEmail(input) {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailRegex.test(input.trim());
}
function isPhoneNumber(input) {
  const trimmed = input.trim();
  if (trimmed.toLowerCase().startsWith("tel:")) {
    return true;
  }
  const phoneRegex = /^[\s\+\-\(\)]*\d[\d\s\-\(\)\.]*\d[\s\-]*(x|ext\.?|extension)?[\s\-]*\d*$/i;
  return phoneRegex.test(trimmed);
}
function isInternalUrl(href) {
  if (typeof window === "undefined") {
    return href.startsWith("/") && !href.startsWith("//");
  }
  const trimmed = href.trim();
  if (trimmed.startsWith("/") && !trimmed.startsWith("//")) {
    return true;
  }
  try {
    const url = new URL(trimmed, window.location.href);
    const currentOrigin = window.location.origin;
    const normalizeOrigin = (origin) => origin.replace(/^(https?:\/\/)(www\.)?/, "$1");
    return normalizeOrigin(url.origin) === normalizeOrigin(currentOrigin);
  } catch {
    return false;
  }
}
function toRelativePath(href) {
  if (typeof window === "undefined") {
    return href;
  }
  const trimmed = href.trim();
  if (trimmed.startsWith("/") && !trimmed.startsWith("//")) {
    return trimmed;
  }
  try {
    const url = new URL(trimmed, window.location.href);
    const currentOrigin = window.location.origin;
    const normalizeOrigin = (origin) => origin.replace(/^(https?:\/\/)(www\.)?/, "$1");
    if (normalizeOrigin(url.origin) === normalizeOrigin(currentOrigin)) {
      return url.pathname + url.search + url.hash;
    }
  } catch {
  }
  return trimmed;
}
function useNavigation({
  href,
  onClick
} = {}) {
  const linkType = React__namespace.useMemo(() => {
    if (!href || href.trim() === "") {
      return onClick ? "none" : "none";
    }
    const trimmed = href.trim();
    if (trimmed.toLowerCase().startsWith("mailto:") || isEmail(trimmed)) {
      return "mailto";
    }
    if (trimmed.toLowerCase().startsWith("tel:") || isPhoneNumber(trimmed)) {
      return "tel";
    }
    if (isInternalUrl(trimmed)) {
      return "internal";
    }
    try {
      new URL(trimmed, typeof window !== "undefined" ? window.location.href : "http://localhost");
      return "external";
    } catch {
      return "internal";
    }
  }, [href, onClick]);
  const normalizedHref = React__namespace.useMemo(() => {
    if (!href || href.trim() === "") {
      return void 0;
    }
    const trimmed = href.trim();
    switch (linkType) {
      case "tel":
        return normalizePhoneNumber(trimmed);
      case "mailto":
        return normalizeEmail(trimmed);
      case "internal":
        return toRelativePath(trimmed);
      case "external":
        return trimmed;
      default:
        return trimmed;
    }
  }, [href, linkType]);
  const target = React__namespace.useMemo(() => {
    switch (linkType) {
      case "external":
        return "_blank";
      case "internal":
        return "_self";
      case "mailto":
      case "tel":
        return void 0;
      default:
        return void 0;
    }
  }, [linkType]);
  const rel = React__namespace.useMemo(() => {
    if (linkType === "external") {
      return "noopener noreferrer";
    }
    return void 0;
  }, [linkType]);
  const isExternal = linkType === "external";
  const isInternal = linkType === "internal";
  const shouldUseRouter = isInternal && typeof normalizedHref === "string" && normalizedHref.startsWith("/");
  const handleClick = React__namespace.useCallback(
    (event) => {
      if (onClick) {
        try {
          onClick(event);
        } catch (error) {
          console.error("Error in user onClick handler:", error);
        }
      }
      if (event.defaultPrevented) {
        return;
      }
      if (shouldUseRouter && normalizedHref && event.button === 0 && // left-click only
      !event.metaKey && !event.altKey && !event.ctrlKey && !event.shiftKey) {
        if (typeof window !== "undefined") {
          const handler = window.__opensiteNavigationHandler;
          if (typeof handler === "function") {
            try {
              const handled = handler(normalizedHref, event.nativeEvent || event);
              if (handled !== false) {
                event.preventDefault();
              }
            } catch (error) {
              console.error("Error in navigation handler:", error);
            }
          }
        }
      }
    },
    [onClick, shouldUseRouter, normalizedHref]
  );
  return {
    linkType,
    normalizedHref,
    target,
    rel,
    isExternal,
    isInternal,
    shouldUseRouter,
    handleClick
  };
}
var baseStyles = [
  // Layout
  "inline-flex items-center justify-center gap-2 whitespace-nowrap shrink-0",
  // Typography - using CSS variables with sensible defaults
  "font-[var(--button-font-family,inherit)]",
  "font-[var(--button-font-weight,500)]",
  "tracking-[var(--button-letter-spacing,0)]",
  "leading-[var(--button-line-height,1.25)]",
  "[text-transform:var(--button-text-transform,none)]",
  "text-sm",
  // Border radius
  "rounded-[var(--button-radius,var(--radius,0.375rem))]",
  // Smooth transition - using [transition:...] to set full shorthand property (not just transition-property)
  "[transition:var(--button-transition,all_250ms_cubic-bezier(0.4,0,0.2,1))]",
  // Box shadow (master level) - using [box-shadow:...] for complex multi-value shadows
  "[box-shadow:var(--button-shadow,none)]",
  "hover:[box-shadow:var(--button-shadow-hover,var(--button-shadow,none))]",
  // Disabled state
  "disabled:pointer-events-none disabled:opacity-50",
  // SVG handling
  "[&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0",
  // Focus styles
  "outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
  // Invalid state
  "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive"
].join(" ");
var buttonVariants = classVarianceAuthority.cva(baseStyles, {
  variants: {
    variant: {
      // Default (Primary) variant - full customization
      default: [
        "bg-[var(--button-default-bg,hsl(var(--primary)))]",
        "text-[var(--button-default-fg,hsl(var(--primary-foreground)))]",
        "border-[length:var(--button-default-border-width,0px)]",
        "border-[color:var(--button-default-border,transparent)]",
        "[box-shadow:var(--button-default-shadow,var(--button-shadow,none))]",
        "hover:bg-[var(--button-default-hover-bg,hsl(var(--primary)/0.9))]",
        "hover:text-[var(--button-default-hover-fg,var(--button-default-fg,hsl(var(--primary-foreground))))]",
        "hover:border-[color:var(--button-default-hover-border,var(--button-default-border,transparent))]",
        "hover:[box-shadow:var(--button-default-shadow-hover,var(--button-shadow-hover,var(--button-default-shadow,var(--button-shadow,none))))]"
      ].join(" "),
      // Destructive variant - full customization
      destructive: [
        "bg-[var(--button-destructive-bg,hsl(var(--destructive)))]",
        "text-[var(--button-destructive-fg,white)]",
        "border-[length:var(--button-destructive-border-width,0px)]",
        "border-[color:var(--button-destructive-border,transparent)]",
        "[box-shadow:var(--button-destructive-shadow,var(--button-shadow,none))]",
        "hover:bg-[var(--button-destructive-hover-bg,hsl(var(--destructive)/0.9))]",
        "hover:text-[var(--button-destructive-hover-fg,var(--button-destructive-fg,white))]",
        "hover:border-[color:var(--button-destructive-hover-border,var(--button-destructive-border,transparent))]",
        "hover:[box-shadow:var(--button-destructive-shadow-hover,var(--button-shadow-hover,var(--button-destructive-shadow,var(--button-shadow,none))))]",
        "focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",
        "dark:bg-destructive/60"
      ].join(" "),
      // Outline variant - full customization with proper border handling
      outline: [
        "bg-[var(--button-outline-bg,hsl(var(--background)))]",
        "text-[var(--button-outline-fg,inherit)]",
        "border-[length:var(--button-outline-border-width,1px)]",
        "border-[color:var(--button-outline-border,hsl(var(--border)))]",
        "[box-shadow:var(--button-outline-shadow,var(--button-shadow,0_1px_2px_0_rgb(0_0_0/0.05)))]",
        "hover:bg-[var(--button-outline-hover-bg,hsl(var(--accent)))]",
        "hover:text-[var(--button-outline-hover-fg,hsl(var(--accent-foreground)))]",
        "hover:border-[color:var(--button-outline-hover-border,var(--button-outline-border,hsl(var(--border))))]",
        "hover:[box-shadow:var(--button-outline-shadow-hover,var(--button-shadow-hover,var(--button-outline-shadow,var(--button-shadow,none))))]",
        "dark:bg-input/30 dark:border-input dark:hover:bg-input/50"
      ].join(" "),
      // Secondary variant - full customization
      secondary: [
        "bg-[var(--button-secondary-bg,hsl(var(--secondary)))]",
        "text-[var(--button-secondary-fg,hsl(var(--secondary-foreground)))]",
        "border-[length:var(--button-secondary-border-width,0px)]",
        "border-[color:var(--button-secondary-border,transparent)]",
        "[box-shadow:var(--button-secondary-shadow,var(--button-shadow,none))]",
        "hover:bg-[var(--button-secondary-hover-bg,hsl(var(--secondary)/0.8))]",
        "hover:text-[var(--button-secondary-hover-fg,var(--button-secondary-fg,hsl(var(--secondary-foreground))))]",
        "hover:border-[color:var(--button-secondary-hover-border,var(--button-secondary-border,transparent))]",
        "hover:[box-shadow:var(--button-secondary-shadow-hover,var(--button-shadow-hover,var(--button-secondary-shadow,var(--button-shadow,none))))]"
      ].join(" "),
      // Ghost variant - full customization
      ghost: [
        "bg-[var(--button-ghost-bg,transparent)]",
        "text-[var(--button-ghost-fg,inherit)]",
        "border-[length:var(--button-ghost-border-width,0px)]",
        "border-[color:var(--button-ghost-border,transparent)]",
        "[box-shadow:var(--button-ghost-shadow,var(--button-shadow,none))]",
        "hover:bg-[var(--button-ghost-hover-bg,hsl(var(--accent)))]",
        "hover:text-[var(--button-ghost-hover-fg,hsl(var(--accent-foreground)))]",
        "hover:border-[color:var(--button-ghost-hover-border,var(--button-ghost-border,transparent))]",
        "hover:[box-shadow:var(--button-ghost-shadow-hover,var(--button-shadow-hover,var(--button-ghost-shadow,var(--button-shadow,none))))]",
        "dark:hover:bg-accent/50"
      ].join(" "),
      // Link variant - full customization
      link: [
        "bg-[var(--button-link-bg,transparent)]",
        "text-[var(--button-link-fg,hsl(var(--primary)))]",
        "border-[length:var(--button-link-border-width,0px)]",
        "border-[color:var(--button-link-border,transparent)]",
        "[box-shadow:var(--button-link-shadow,none)]",
        "hover:bg-[var(--button-link-hover-bg,transparent)]",
        "hover:text-[var(--button-link-hover-fg,var(--button-link-fg,hsl(var(--primary))))]",
        "hover:[box-shadow:var(--button-link-shadow-hover,none)]",
        "underline-offset-4 hover:underline"
      ].join(" ")
    },
    size: {
      default: [
        "h-[var(--button-height-md,2.25rem)]",
        "px-[var(--button-padding-x-md,1rem)]",
        "py-[var(--button-padding-y-md,0.5rem)]",
        "has-[>svg]:px-[calc(var(--button-padding-x-md,1rem)*0.75)]"
      ].join(" "),
      sm: [
        "h-[var(--button-height-sm,2rem)]",
        "px-[var(--button-padding-x-sm,0.75rem)]",
        "py-[var(--button-padding-y-sm,0.25rem)]",
        "gap-1.5",
        "has-[>svg]:px-[calc(var(--button-padding-x-sm,0.75rem)*0.83)]"
      ].join(" "),
      md: [
        "h-[var(--button-height-md,2.25rem)]",
        "px-[var(--button-padding-x-md,1rem)]",
        "py-[var(--button-padding-y-md,0.5rem)]",
        "has-[>svg]:px-[calc(var(--button-padding-x-md,1rem)*0.75)]"
      ].join(" "),
      lg: [
        "h-[var(--button-height-lg,2.5rem)]",
        "px-[var(--button-padding-x-lg,1.5rem)]",
        "py-[var(--button-padding-y-lg,0.5rem)]",
        "has-[>svg]:px-[calc(var(--button-padding-x-lg,1.5rem)*0.67)]"
      ].join(" "),
      icon: "size-[var(--button-height-md,2.25rem)]",
      "icon-sm": "size-[var(--button-height-sm,2rem)]",
      "icon-lg": "size-[var(--button-height-lg,2.5rem)]"
    }
  },
  defaultVariants: {
    variant: "default",
    size: "default"
  }
});
var Pressable = React__namespace.forwardRef(
  ({
    children,
    className,
    href,
    onClick,
    variant,
    size,
    asButton = false,
    fallbackComponentType = "span",
    componentType,
    "aria-label": ariaLabel,
    "aria-describedby": ariaDescribedby,
    id,
    ...props
  }, ref) => {
    const navigation = useNavigation({ href, onClick });
    const {
      normalizedHref,
      target,
      rel,
      linkType,
      isInternal,
      handleClick
    } = navigation;
    const shouldRenderLink = normalizedHref && linkType !== "none";
    const shouldRenderButton = !shouldRenderLink && onClick;
    const effectiveComponentType = componentType || (shouldRenderLink ? "a" : shouldRenderButton ? "button" : fallbackComponentType);
    const finalComponentType = isInternal && shouldRenderLink ? "a" : effectiveComponentType;
    const shouldApplyButtonStyles = asButton || variant || size;
    const combinedClassName = cn(
      shouldApplyButtonStyles && buttonVariants({ variant, size }),
      className
    );
    const dataProps = Object.fromEntries(
      Object.entries(props).filter(([key]) => key.startsWith("data-"))
    );
    const buttonDataAttributes = shouldApplyButtonStyles ? {
      "data-slot": "button",
      "data-variant": variant ?? "default",
      "data-size": size ?? "default"
    } : {};
    const commonProps = {
      className: combinedClassName,
      onClick: handleClick,
      "aria-label": ariaLabel,
      "aria-describedby": ariaDescribedby,
      id,
      ...dataProps,
      ...buttonDataAttributes
    };
    if (finalComponentType === "a" && shouldRenderLink) {
      return /* @__PURE__ */ jsxRuntime.jsx(
        "a",
        {
          ref,
          href: normalizedHref,
          target,
          rel,
          ...commonProps,
          ...props,
          children
        }
      );
    }
    if (finalComponentType === "button") {
      return /* @__PURE__ */ jsxRuntime.jsx(
        "button",
        {
          ref,
          type: props.type || "button",
          ...commonProps,
          ...props,
          children
        }
      );
    }
    if (finalComponentType === "div") {
      return /* @__PURE__ */ jsxRuntime.jsx(
        "div",
        {
          ref,
          ...commonProps,
          children
        }
      );
    }
    return /* @__PURE__ */ jsxRuntime.jsx(
      "span",
      {
        ref,
        ...commonProps,
        children
      }
    );
  }
);
Pressable.displayName = "Pressable";
var DEFAULT_ICON_API_KEY = "au382bi7fsh96w9h9xlrnat2jglx";
function DynamicIcon({ apiKey, ...props }) {
  return /* @__PURE__ */ jsxRuntime.jsx(icon.Icon, { ...props, apiKey: apiKey ?? DEFAULT_ICON_API_KEY });
}
var badgeVariants = classVarianceAuthority.cva(
  "inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
  {
    variants: {
      variant: {
        default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
        secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
        destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
        outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
      }
    },
    defaultVariants: {
      variant: "default"
    }
  }
);
function Badge({
  className,
  variant,
  asChild = false,
  ...props
}) {
  const Comp = asChild ? reactSlot.Slot : "span";
  return /* @__PURE__ */ jsxRuntime.jsx(
    Comp,
    {
      "data-slot": "badge",
      className: cn(badgeVariants({ variant }), className),
      ...props
    }
  );
}
function Card({ className, ...props }) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    {
      "data-slot": "card",
      className: cn(
        "bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
        className
      ),
      ...props
    }
  );
}
function CardContent({ className, ...props }) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    {
      "data-slot": "card-content",
      className: cn("px-6", className),
      ...props
    }
  );
}
function AspectRatio({
  ...props
}) {
  return /* @__PURE__ */ jsxRuntime.jsx(AspectRatioPrimitive__namespace.Root, { "data-slot": "aspect-ratio", ...props });
}
function Checkbox({
  className,
  ...props
}) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    CheckboxPrimitive__namespace.Root,
    {
      "data-slot": "checkbox",
      className: cn(
        "peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
        className
      ),
      ...props,
      children: /* @__PURE__ */ jsxRuntime.jsx(
        CheckboxPrimitive__namespace.Indicator,
        {
          "data-slot": "checkbox-indicator",
          className: "grid place-content-center text-current transition-none",
          children: /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: "lucide/check", size: 14 })
        }
      )
    }
  );
}
function Label({
  className,
  ...props
}) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    LabelPrimitive__namespace.Root,
    {
      "data-slot": "label",
      className: cn(
        "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
        className
      ),
      ...props
    }
  );
}
function Breadcrumb({ ...props }) {
  return /* @__PURE__ */ jsxRuntime.jsx("nav", { "aria-label": "breadcrumb", "data-slot": "breadcrumb", ...props });
}
function BreadcrumbList({ className, ...props }) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    "ol",
    {
      "data-slot": "breadcrumb-list",
      className: cn(
        "text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5",
        className
      ),
      ...props
    }
  );
}
function BreadcrumbItem({ className, ...props }) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    "li",
    {
      "data-slot": "breadcrumb-item",
      className: cn("inline-flex items-center gap-1.5", className),
      ...props
    }
  );
}
function BreadcrumbLink({
  asChild,
  className,
  ...props
}) {
  const Comp = asChild ? reactSlot.Slot : "a";
  return /* @__PURE__ */ jsxRuntime.jsx(
    Comp,
    {
      "data-slot": "breadcrumb-link",
      className: cn("hover:text-foreground transition-colors", className),
      ...props
    }
  );
}
function BreadcrumbSeparator({
  children,
  className,
  ...props
}) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    "li",
    {
      "data-slot": "breadcrumb-separator",
      role: "presentation",
      "aria-hidden": "true",
      className: cn("[&>svg]:size-3.5", className),
      ...props,
      children: children ?? /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: "lucide/chevron-right", size: 14 })
    }
  );
}

// lib/patternSvgs.ts
var patternSvgs = {
  dotPattern2: "https://cdn.ing/assets/files/record/286189/arez6gd2s7isn9i1o6c7sexdq7bl"};
var FilterForm = ({ categories, onCategoryChange }) => {
  const [selectedItems, setSelectedItems] = React.useState(["all"]);
  const handleCheckboxChange = React.useCallback(
    (checked, categoryValue) => {
      let updatedValues = checked ? [...selectedItems, categoryValue] : selectedItems.filter((value) => value !== categoryValue);
      if (updatedValues.length === 0) {
        setSelectedItems(["all"]);
        onCategoryChange(["all"]);
        return;
      }
      if (updatedValues.includes("all") && categoryValue !== "all") {
        updatedValues = updatedValues.filter((v) => v !== "all");
      }
      if (categoryValue === "all" && checked) {
        updatedValues = ["all"];
      }
      setSelectedItems(updatedValues);
      onCategoryChange(updatedValues);
    },
    [selectedItems, onCategoryChange]
  );
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-wrap items-center gap-2.5", children: categories.map((category) => {
    const isChecked = selectedItems.includes(category.value);
    return /* @__PURE__ */ jsxRuntime.jsxs(
      Label,
      {
        className: "flex cursor-pointer items-center gap-2.5 rounded-full bg-muted px-2.5 py-1.5",
        children: [
          /* @__PURE__ */ jsxRuntime.jsx("span", { children: category.label }),
          /* @__PURE__ */ jsxRuntime.jsx(
            Checkbox,
            {
              checked: isChecked,
              onCheckedChange: (checked) => handleCheckboxChange(!!checked, category.value)
            }
          )
        ]
      },
      category.value
    );
  }) });
};
var ResourcesResult = ({
  posts,
  categories,
  postsPerPage,
  loadMoreText,
  categoriesClassName,
  postsClassName,
  optixFlowConfig
}) => {
  const [visibleCount, setVisibleCount] = React.useState(postsPerPage);
  const [selectedCategories, setSelectedCategories] = React.useState([
    "all"
  ]);
  const handleCategoryChange = React.useCallback((selected) => {
    setSelectedCategories(selected);
    setVisibleCount(postsPerPage);
  }, [postsPerPage]);
  const handleLoadMore = React.useCallback(() => {
    setVisibleCount((prev) => prev + postsPerPage);
  }, [postsPerPage]);
  const filteredPosts = React.useMemo(() => {
    return posts.filter(
      (post) => selectedCategories.includes(post.category.toLowerCase()) || selectedCategories.includes("all")
    );
  }, [posts, selectedCategories]);
  const postsToDisplay = filteredPosts.length > 0 ? filteredPosts : posts;
  const hasMore = visibleCount < postsToDisplay.length;
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: categoriesClassName, children: /* @__PURE__ */ jsxRuntime.jsx(
      FilterForm,
      {
        categories,
        onCategoryChange: handleCategoryChange
      }
    ) }),
    /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex w-full flex-col gap-4 py-8", postsClassName), children: [
      /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid gap-10 md:grid-cols-2 lg:grid-cols-3", children: postsToDisplay.slice(0, visibleCount).map((post, idx) => /* @__PURE__ */ jsxRuntime.jsx(ResourceCard, { ...post, optixFlowConfig }, idx)) }),
      hasMore && /* @__PURE__ */ jsxRuntime.jsx(
        Pressable,
        {
          className: "w-full",
          variant: "secondary",
          asButton: true,
          onClick: handleLoadMore,
          children: loadMoreText
        }
      )
    ] })
  ] });
};
var BreadcrumbBlog = ({ breadcrumb }) => {
  return /* @__PURE__ */ jsxRuntime.jsx(Breadcrumb, { children: /* @__PURE__ */ jsxRuntime.jsx(BreadcrumbList, { children: breadcrumb.map((item, i) => {
    return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
      /* @__PURE__ */ jsxRuntime.jsx(BreadcrumbItem, { children: /* @__PURE__ */ jsxRuntime.jsx(BreadcrumbLink, { href: item.link, children: item.label }) }),
      i < breadcrumb.length - 1 ? /* @__PURE__ */ jsxRuntime.jsx(BreadcrumbSeparator, { children: /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: "lucide/slash", size: 16 }) }) : null
    ] }, `${item.label}`);
  }) }) });
};
var EmailForm = ({
  emailPlaceholder,
  buttonText,
  formConfig,
  onSubmit,
  onSuccess,
  onError
}) => {
  const form = forms.useForm({
    initialValues: {
      email: ""
    },
    validationSchema: {
      email: (value) => {
        if (!value) return "Email is required";
        if (!integration.isValidEmail(value)) return "Please enter a valid email address";
        return void 0;
      }
    },
    onSubmit: async (values, helpers) => {
      const shouldAutoSubmit = Boolean(formConfig?.endpoint);
      if (!shouldAutoSubmit && !onSubmit) {
        return;
      }
      try {
        let result;
        if (shouldAutoSubmit) {
          result = await integration.submitPageSpeedForm(values, formConfig);
        }
        if (onSubmit) {
          await onSubmit(values.email);
        }
        if (shouldAutoSubmit || onSubmit) {
          if (formConfig?.resetOnSuccess !== false) {
            helpers.resetForm();
          }
          onSuccess?.(result);
        }
      } catch (error) {
        if (error instanceof integration.PageSpeedFormSubmissionError && error.formErrors) {
          helpers.setErrors(error.formErrors);
        }
        onError?.(error);
        throw error;
      }
    }
  });
  const formMethod = formConfig?.method?.toLowerCase() === "get" ? "get" : "post";
  return /* @__PURE__ */ jsxRuntime.jsx(
    forms.Form,
    {
      form,
      action: formConfig?.endpoint,
      method: formMethod,
      className: "w-full",
      children: /* @__PURE__ */ jsxRuntime.jsx(forms.Field, { name: "email", children: ({ field, meta }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full", children: [
        /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex w-full flex-col gap-2 lg:block", children: [
          /* @__PURE__ */ jsxRuntime.jsx(
            TextInput,
            {
              ...field,
              type: "email",
              placeholder: emailPlaceholder,
              error: meta.touched && !!meta.error,
              className: "h-fit bg-background py-4 pr-5 pl-5 lg:pr-55",
              "aria-label": emailPlaceholder
            }
          ),
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "top-1/2 right-2.5 lg:absolute lg:-translate-y-1/2", children: /* @__PURE__ */ jsxRuntime.jsxs(
            Pressable,
            {
              componentType: "button",
              type: "submit",
              className: "w-full rounded-full lg:w-fit",
              variant: "default",
              asButton: true,
              disabled: form.isSubmitting,
              children: [
                buttonText,
                /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: "lucide/arrow-right", size: 16, className: "ml-2" })
              ]
            }
          ) })
        ] }),
        meta.touched && meta.error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "py-1 text-sm text-destructive", children: meta.error })
      ] }) })
    }
  );
};
var ResourceCard = ({
  category,
  categoryLabel,
  title,
  thumbnail,
  summary,
  link,
  cta,
  className,
  optixFlowConfig
}) => {
  return /* @__PURE__ */ jsxRuntime.jsx(Pressable, { href: link, className: cn("block h-full w-full", className), children: /* @__PURE__ */ jsxRuntime.jsx(Card, { className: "size-full border py-0", children: /* @__PURE__ */ jsxRuntime.jsxs(CardContent, { className: "p-0", children: [
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-b p-2.5 text-sm leading-[1.2] font-medium text-muted-foreground", children: categoryLabel ?? category }),
    /* @__PURE__ */ jsxRuntime.jsx(AspectRatio, { ratio: 1.520833333, className: "overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
      img.Img,
      {
        src: thumbnail,
        alt: typeof title === "string" ? title : "Resource",
        className: "block size-full object-cover object-center",
        optixFlowConfig
      }
    ) }),
    /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col gap-5 p-5", children: [
      typeof title === "string" ? /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-lg leading-none font-bold md:text-2xl", children: title }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-lg leading-none font-bold md:text-2xl", children: title }),
      /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full max-w-[20rem]", children: typeof summary === "string" ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm leading-[1.4] font-medium", children: summary }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm leading-[1.4] font-medium", children: summary }) }),
      /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(Badge, { className: "rounded-full", children: [
        cta,
        /* @__PURE__ */ jsxRuntime.jsx(DynamicIcon, { name: "lucide/arrow-right", size: 14, className: "ml-1" })
      ] }) })
    ] })
  ] }) }) });
};
function ResourceListHeroFilter({
  className,
  title,
  titleClassName,
  description,
  descriptionClassName,
  breadcrumb,
  breadcrumbSlot,
  breadcrumbClassName,
  primaryPost,
  primaryPostSlot,
  primaryPostClassName,
  posts,
  postsSlot,
  postsClassName,
  categories,
  categoriesClassName,
  allPostsTitle,
  allPostsTitleClassName,
  emailPlaceholder,
  buttonText,
  postsPerPage = 6,
  loadMoreText,
  heroClassName,
  contentClassName,
  heroPatternUrl,
  heroPatternSize,
  formConfig,
  onSubmit,
  onSuccess,
  onError,
  optixFlowConfig
}) {
  const renderedBreadcrumb = React.useMemo(() => {
    if (breadcrumbSlot) return breadcrumbSlot;
    if (!breadcrumb || breadcrumb.length === 0) return null;
    return /* @__PURE__ */ jsxRuntime.jsx("div", { className: breadcrumbClassName, children: /* @__PURE__ */ jsxRuntime.jsx(BreadcrumbBlog, { breadcrumb }) });
  }, [breadcrumbSlot, breadcrumb, breadcrumbClassName]);
  const renderedPrimaryPost = React.useMemo(() => {
    if (primaryPostSlot) return primaryPostSlot;
    if (!primaryPost) return null;
    return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("w-full max-w-110", primaryPostClassName), children: /* @__PURE__ */ jsxRuntime.jsx(ResourceCard, { ...primaryPost, optixFlowConfig }) });
  }, [primaryPostSlot, primaryPost, primaryPostClassName, optixFlowConfig]);
  const renderedPosts = React.useMemo(() => {
    if (postsSlot) return postsSlot;
    if (!posts || posts.length === 0) return null;
    return /* @__PURE__ */ jsxRuntime.jsx(
      ResourcesResult,
      {
        posts,
        categories: categories ?? [],
        postsPerPage,
        loadMoreText,
        categoriesClassName,
        postsClassName,
        optixFlowConfig
      }
    );
  }, [postsSlot, posts, categories, postsPerPage, loadMoreText, categoriesClassName, postsClassName, optixFlowConfig]);
  return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: cn("pb-32", className), children: [
    /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      {
        className: cn(
          "bg-repeat",
          getNestedCardBg(),
          getNestedCardTextColor(void 0),
          heroClassName
        ),
        style: {
          backgroundImage: `url('${heroPatternUrl ?? patternSvgs.dotPattern2}')`,
          backgroundSize: heroPatternSize
        },
        children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "container flex flex-col items-start justify-start gap-16 py-20 lg:flex-row lg:items-center lg:justify-between", children: [
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-col justify-between gap-12", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-xl flex-col gap-8", children: [
            renderedBreadcrumb,
            /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col gap-5", children: [
              title && (typeof title === "string" ? /* @__PURE__ */ jsxRuntime.jsx("h1", { className: cn("text-[2.5rem] leading-[1.2] font-semibold md:text-5xl lg:text-6xl", titleClassName), children: title }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: titleClassName, children: title })),
              description && (typeof description === "string" ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: cn("text-xl leading-[1.4] font-semibold", descriptionClassName), children: description }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: descriptionClassName, children: description }))
            ] }),
            /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-120", children: /* @__PURE__ */ jsxRuntime.jsx(
              EmailForm,
              {
                emailPlaceholder,
                buttonText,
                formConfig,
                onSubmit,
                onSuccess,
                onError
              }
            ) })
          ] }) }),
          renderedPrimaryPost
        ] })
      }
    ),
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("py-20", contentClassName), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "container flex flex-col gap-8", children: [
      allPostsTitle && (typeof allPostsTitle === "string" ? /* @__PURE__ */ jsxRuntime.jsx("h2", { className: cn("text-[1.75rem] leading-none font-medium md:text-[2.25rem] lg:text-[2rem]", allPostsTitleClassName), children: allPostsTitle }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: allPostsTitleClassName, children: allPostsTitle })),
      /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderedPosts })
    ] }) })
  ] });
}

exports.ResourceListHeroFilter = ResourceListHeroFilter;
