"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import Link from "next/link";
import { usePathname, useSearchParams } from "next/navigation";
import { AlertTriangle, X } from "lucide-react";
import { Button } from "../../primitives/button.js";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { buildHrefWithReturnTo } from "@open-mercato/shared/lib/navigation/returnTo";
import { dismissPartialIndexWarning, usePartialIndexWarning } from "./store.js";
function PartialIndexBanner() {
  const t = useT();
  const pathname = usePathname();
  const searchParams = useSearchParams();
  const warning = usePartialIndexWarning();
  const returnTo = React.useMemo(() => {
    const query = searchParams?.toString() ?? "";
    if (!pathname) return null;
    return query.length ? `${pathname}?${query}` : pathname;
  }, [pathname, searchParams]);
  const manageIndexesHref = React.useMemo(
    () => buildHrefWithReturnTo("/backend/query-indexes", returnTo),
    [returnTo]
  );
  if (!warning) return null;
  const entityLabel = warning.entityLabel || warning.entity;
  const base = warning.baseCount;
  const indexed = warning.indexedCount;
  const hasCounts = typeof base === "number" && typeof indexed === "number";
  const hasExcessIndexedRows = hasCounts && indexed > base;
  return /* @__PURE__ */ jsxs("div", { className: "mb-4 flex flex-col gap-3 rounded-md border border-status-warning-border bg-status-warning-bg px-3 py-3 text-sm text-status-warning-text md:flex-row md:items-center md:justify-between", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 text-sm", children: [
      /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 font-medium text-status-warning-text", children: [
        /* @__PURE__ */ jsx(AlertTriangle, { className: "size-4", "aria-hidden": "true" }),
        /* @__PURE__ */ jsx("span", { children: t("query_index.banner.partial_title") })
      ] }),
      /* @__PURE__ */ jsx("p", { className: "text-status-warning-text", children: t("query_index.banner.partial_description") }),
      /* @__PURE__ */ jsx("p", { className: "text-xs text-status-warning-text", children: t("query_index.banner.partial_entity", { entity: entityLabel }) }),
      hasCounts && /* @__PURE__ */ jsx("p", { className: "text-xs text-status-warning-text", children: hasExcessIndexedRows ? t("query_index.banner.partial_counts_excess", { indexed, total: base }) : t("query_index.banner.partial_counts", { indexed, total: base }) }),
      warning.scope === "global" && /* @__PURE__ */ jsx("p", { className: "text-xs text-status-warning-text", children: t("query_index.banner.partial_global_note") })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
      /* @__PURE__ */ jsx(
        Button,
        {
          asChild: true,
          variant: "outline",
          size: "sm",
          className: "border-status-warning-border text-status-warning-text hover:bg-status-warning-bg",
          children: /* @__PURE__ */ jsx(Link, { href: manageIndexesHref, children: t("query_index.banner.manage_indexes") })
        }
      ),
      /* @__PURE__ */ jsxs(
        Button,
        {
          variant: "ghost",
          size: "sm",
          type: "button",
          onClick: () => dismissPartialIndexWarning(),
          className: "text-status-warning-text hover:bg-status-warning-bg",
          "aria-label": t("query_index.banner.dismiss"),
          children: [
            /* @__PURE__ */ jsx(X, { className: "mr-1 size-4", "aria-hidden": "true" }),
            t("query_index.banner.dismiss")
          ]
        }
      )
    ] })
  ] });
}
export {
  PartialIndexBanner
};
//# sourceMappingURL=PartialIndexBanner.js.map
