"use client";
import {
  ArticleAuthorByline,
  DetailPageSkeleton,
  DocSearchBar,
  useDocSearch
} from "../../chunk-TX2VP43R.js";
import {
  useSelfFetch
} from "../../chunk-L4LAAA5Q.js";
import "../../chunk-4XLJWX2N.js";
import {
  EntityAuthorCard,
  EntityVideoSection,
  FilterPillRow,
  LoadError,
  OnboardingGuideCard,
  OnboardingGuideCardSkeleton,
  PageShell,
  SimpleMarkdownRenderer,
  VideoBitesDisplay,
  getCaptionsUrl,
  resolveContentHref,
  useVideoWarmup
} from "../../chunk-HTR3ARN6.js";
import "../../chunk-ZXZJSTNV.js";
import {
  useChatRuntime
} from "../../chunk-4YKGXZ7W.js";
import "../../chunk-LXC6P2EO.js";
import "../../chunk-EL5YVPD5.js";
import {
  useRouter,
  useSearchParams
} from "../../chunk-PLJLE4A4.js";
import {
  EntityTagBadges
} from "../../chunk-FREG2KXV.js";
import "../../chunk-LDEXTWMK.js";
import {
  next_link_default
} from "../../chunk-OHPI2HRK.js";
import "../../chunk-V4IIBNTA.js";
import "../../chunk-XTCBRQN2.js";
import "../../chunk-4WZOFD46.js";
import "../../chunk-6U3IUD57.js";
import "../../chunk-W72U7OU7.js";
import "../../chunk-GGWZFCYS.js";

// src/components/onboarding-guides/onboarding-guides-catalog-view.tsx
import { useMemo, useTransition } from "react";
import { GraduationCap } from "lucide-react";

// src/components/onboarding-guides/onboarding-guides-catalog-skeleton.tsx
import { jsx, jsxs } from "react/jsx-runtime";
function OnboardingGuidesCatalogSkeleton() {
  return /* @__PURE__ */ jsxs("div", { className: "w-full flex flex-col gap-10 animate-pulse", children: [
    /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
      /* @__PURE__ */ jsx("div", { className: "h-12 w-full bg-ods-card border border-ods-border rounded-md" }),
      /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3 p-4 bg-ods-card border border-ods-border rounded-lg", children: [
        /* @__PURE__ */ jsx("div", { className: "h-4 w-14 bg-ods-border/60 rounded" }),
        [0, 1, 2, 3].map((i) => /* @__PURE__ */ jsx(
          "div",
          {
            className: "h-10 w-24 bg-ods-card border border-ods-border rounded-md"
          },
          i
        ))
      ] })
    ] }),
    /* @__PURE__ */ jsx("div", { className: "space-y-10", children: [4, 3, 3].map((cardCount, sectionIdx) => /* @__PURE__ */ jsxs("section", { className: "space-y-4", children: [
      /* @__PURE__ */ jsxs("h2", { className: "text-h3 tracking-[-0.36px] text-ods-text-primary flex items-center gap-2", children: [
        /* @__PURE__ */ jsx("span", { className: "h-6 w-40 bg-ods-border/70 rounded" }),
        /* @__PURE__ */ jsx("span", { className: "h-5 w-8 bg-ods-text-secondary/20 rounded-full" })
      ] }),
      /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-4", children: Array.from({ length: cardCount }).map((_, cardIdx) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(OnboardingGuideCardSkeleton, { size: "catalog" }) }, cardIdx)) })
    ] }, sectionIdx)) })
  ] });
}

// src/components/onboarding-guides/onboarding-guides-catalog-view.tsx
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
function OnboardingGuidesCatalogView({
  initialGuides,
  initialSections,
  initialSection = "",
  guidesEndpoint,
  sectionsEndpoint,
  renderCard,
  basePath = "/onboarding-guides"
}) {
  const router = useRouter();
  const searchParams = useSearchParams();
  const [isPending, startTransition] = useTransition();
  const runtime = useChatRuntime();
  const selfFetch = initialGuides === void 0 && guidesEndpoint !== void 0;
  const sectionValue = selfFetch ? searchParams.get("section") ?? "" : initialSection;
  const activeSection = sectionValue || "all";
  const guidesQs = sectionValue ? `?section=${encodeURIComponent(sectionValue)}` : "";
  const guidesRes = useSelfFetch(
    selfFetch && guidesEndpoint ? `${guidesEndpoint}${guidesQs}` : null
  );
  const sectionsRes = useSelfFetch(
    selfFetch && sectionsEndpoint ? sectionsEndpoint : null
  );
  const guides = initialGuides ?? guidesRes.data?.data ?? [];
  const sections = initialSections ?? (Array.isArray(sectionsRes.data) ? sectionsRes.data : []);
  const isLoading = selfFetch ? guidesRes.isLoading : false;
  const grouped = useMemo(() => {
    const map = /* @__PURE__ */ new Map();
    for (const g of guides) {
      const existing = map.get(g.section);
      if (existing) {
        if (g.section_order < existing.section_order) existing.section_order = g.section_order;
        existing.guides.push(g);
      } else {
        map.set(g.section, { section_order: g.section_order, guides: [g] });
      }
    }
    for (const entry of map.values()) {
      entry.guides.sort((a, b) => a.step_order - b.step_order || a.title.localeCompare(b.title));
    }
    return Array.from(map.entries()).map(([section, info]) => ({ section, ...info })).sort((a, b) => a.section_order - b.section_order || a.section.localeCompare(b.section));
  }, [guides]);
  const sectionFilterOptions = useMemo(
    () => [
      { value: "all", label: `All (${guides.length})` },
      ...sections.map((s) => ({ value: s.section, label: `${s.section} (${s.count})` }))
    ],
    [guides.length, sections]
  );
  const setSection = (value) => {
    const params = new URLSearchParams(searchParams.toString());
    if (value === "all") {
      params.delete("section");
    } else {
      params.set("section", value);
    }
    const qs = params.toString();
    startTransition(() => {
      router.push(qs ? `${basePath}?${qs}` : basePath);
    });
  };
  const source = runtime?.source ?? "openframe";
  const docSearch = useDocSearch({
    source,
    baseRoute: basePath,
    onNavigate: (path) => router.push(path),
    tableIds: ["onboarding-guides"]
  });
  const defaultRenderCard = (guide) => {
    const cta = resolveContentHref(runtime?.composeContentUrl, {
      type: "onboarding_guide",
      slug: guide.slug,
      basePath,
      platforms: guide.onboarding_guide_platforms
    });
    return /* @__PURE__ */ jsx2(
      OnboardingGuideCard,
      {
        guide,
        href: cta.href,
        targetPlatform: cta.targetPlatform,
        size: "catalog"
      }
    );
  };
  const renderCardFn = renderCard ?? defaultRenderCard;
  const preControls = /* @__PURE__ */ jsxs2("div", { className: "space-y-4", children: [
    /* @__PURE__ */ jsx2(
      DocSearchBar,
      {
        placeholder: "Search onboarding guides, releases, case studies\u2026",
        query: docSearch.query,
        onQueryChange: docSearch.setQuery,
        results: docSearch.results,
        isLoading: docSearch.isLoading,
        onResultSelect: docSearch.handleResultSelect,
        showDropdown: docSearch.keepDropdownOpen
      }
    ),
    sections.length > 0 && /* @__PURE__ */ jsx2(
      FilterPillRow,
      {
        label: "Section",
        selectedValue: activeSection,
        onValueChange: setSection,
        options: sectionFilterOptions
      }
    )
  ] });
  if (selfFetch && guidesRes.error) {
    return /* @__PURE__ */ jsx2(LoadError, { message: "Failed to load onboarding guides.", onRetry: guidesRes.reload });
  }
  if (selfFetch && guidesRes.data == null && isLoading) {
    return /* @__PURE__ */ jsx2(OnboardingGuidesCatalogSkeleton, {});
  }
  return /* @__PURE__ */ jsxs2("div", { className: "w-full flex flex-col gap-10", children: [
    preControls,
    guides.length === 0 ? /* @__PURE__ */ jsxs2("div", { className: "text-center py-16", children: [
      /* @__PURE__ */ jsx2(GraduationCap, { className: "h-12 w-12 text-ods-text-secondary mx-auto mb-4" }),
      /* @__PURE__ */ jsx2("h2", { className: "text-ods-text-primary font-['DM_Sans'] text-[20px] font-semibold mb-2", children: "No onboarding guides found" }),
      /* @__PURE__ */ jsx2("p", { className: "text-ods-text-secondary font-['DM_Sans'] text-[14px]", children: activeSection !== "all" ? "No guides in this section yet." : "We're working on the onboarding library. Check back soon." })
    ] }) : /* @__PURE__ */ jsx2("div", { className: isPending || isLoading ? "opacity-60 transition-opacity space-y-10" : "space-y-10", children: grouped.map((sec) => /* @__PURE__ */ jsxs2("section", { className: "space-y-4", children: [
      /* @__PURE__ */ jsxs2("h2", { className: "text-h3 tracking-[-0.36px] text-ods-text-primary flex items-center gap-2", children: [
        sec.section,
        /* @__PURE__ */ jsx2("span", { className: "inline-flex items-center justify-center rounded-full bg-ods-text-secondary/20 text-ods-text-secondary text-xs font-medium px-2 py-0.5", children: sec.guides.length })
      ] }),
      /* @__PURE__ */ jsx2("ul", { className: "flex flex-col gap-4", children: sec.guides.map((guide) => /* @__PURE__ */ jsx2("li", { children: renderCardFn(guide) }, guide.id)) })
    ] }, sec.section)) })
  ] });
}

// src/components/onboarding-guides/onboarding-guide-detail-view.tsx
import { ArrowLeft } from "lucide-react";
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
function OnboardingGuideDetailView({
  authorHref,
  authorBio,
  fallbackBio,
  initialData,
  slug,
  guideEndpoint,
  related = [],
  MarkdownRenderer = SimpleMarkdownRenderer,
  renderRelatedCard,
  backHref,
  backLabel = "Back to Getting Started",
  basePath = "/onboarding-guides"
}) {
  const resolvedBackHref = backHref ?? basePath;
  const runtime = useChatRuntime();
  const url = initialData ? null : slug && guideEndpoint ? guideEndpoint(slug) : null;
  const { data: guide, isLoading, error, reload } = useSelfFetch(url, { initialData });
  const { ref: videoWarmupRef } = useVideoWarmup({
    videoUrl: guide?.main_video_url,
    supabaseStorageOrigin: runtime?.endpoints.supabaseStorageOrigin
  });
  if (error || !guide && !isLoading) {
    return /* @__PURE__ */ jsx3(LoadError, { message: "Guide not found.", onRetry: reload });
  }
  if (!guide) {
    return /* @__PURE__ */ jsx3(DetailPageSkeleton, { showImageGallery: false });
  }
  const captionsUrl = getCaptionsUrl("onboarding_guide", guide.id, guide.srt_content);
  const videoPoster = guide.main_video_thumbnail || guide.featured_image || guide.og_image_url || runtime?.resolvePlaceholderUrl?.(guide.title, { aspect: "wide" }) || void 0;
  const defaultRenderRelatedCard = (g) => {
    const cta = resolveContentHref(runtime?.composeContentUrl, {
      type: "onboarding_guide",
      slug: g.slug,
      basePath,
      platforms: g.onboarding_guide_platforms
    });
    return /* @__PURE__ */ jsx3(OnboardingGuideCard, { guide: g, href: cta.href, targetPlatform: cta.targetPlatform });
  };
  const renderRelatedCardFn = renderRelatedCard ?? defaultRenderRelatedCard;
  return /* @__PURE__ */ jsx3(PageShell, { children: /* @__PURE__ */ jsxs3("div", { className: "space-y-6 md:space-y-8", children: [
    /* @__PURE__ */ jsxs3(
      next_link_default,
      {
        href: resolvedBackHref,
        className: "inline-flex items-center gap-2 text-ods-text-secondary hover:text-ods-accent transition-colors",
        children: [
          /* @__PURE__ */ jsx3(ArrowLeft, { className: "h-4 w-4" }),
          /* @__PURE__ */ jsx3("span", { className: "text-h5", children: backLabel })
        ]
      }
    ),
    /* @__PURE__ */ jsx3("h1", { className: "text-h1 tracking-[-1.12px] text-ods-text-primary", children: guide.title }),
    /* @__PURE__ */ jsx3(EntityTagBadges, { tags: guide.onboarding_guide_tags }),
    /* @__PURE__ */ jsx3(
      EntityAuthorCard,
      {
        author: guide.author,
        authorHref,
        publishedAt: guide.published_at,
        extraCells: [
          {
            value: `${guide.section} \xB7 Step ${guide.step_order}`,
            label: "Section",
            uppercase: false
          }
        ]
      }
    ),
    (guide.main_video_url || guide.youtube_url) && /* @__PURE__ */ jsx3("div", { ref: videoWarmupRef, children: /* @__PURE__ */ jsx3(
      EntityVideoSection,
      {
        mainVideoUrl: guide.main_video_url,
        youtubeUrl: guide.youtube_url || void 0,
        highlightVideoUrl: guide.highlight_video_url,
        mainVideoPoster: videoPoster,
        highlightVideoThumbnail: guide.highlight_video_thumbnail || void 0,
        videoSummary: void 0,
        videoBites: void 0,
        title: guide.title,
        srtContent: guide.srt_content,
        captionsUrl,
        MarkdownRenderer
      }
    ) }),
    guide.content && /* @__PURE__ */ jsx3("div", { className: "space-y-4", children: /* @__PURE__ */ jsx3(MarkdownRenderer, { content: guide.content }) }),
    guide.video_bites && guide.video_bites.length > 0 && /* @__PURE__ */ jsx3(
      VideoBitesDisplay,
      {
        bites: guide.video_bites,
        filterPublished: true,
        showTitle: false
      }
    ),
    /* @__PURE__ */ jsx3(
      ArticleAuthorByline,
      {
        author: guide.author?.full_name ?? null,
        avatar: guide.author?.avatar_url,
        jobTitle: guide.author?.job_title,
        bio: authorBio ?? guide.author?.about,
        href: authorHref,
        fallbackBio
      }
    ),
    related.length > 0 && /* @__PURE__ */ jsxs3("div", { className: "space-y-4 pt-8 border-t border-ods-border", children: [
      /* @__PURE__ */ jsxs3("h2", { className: "text-h3 tracking-[-0.36px] text-ods-text-primary", children: [
        "More in ",
        guide.section
      ] }),
      /* @__PURE__ */ jsx3("ul", { className: "flex flex-col gap-3", children: related.map((r) => /* @__PURE__ */ jsx3("li", { children: renderRelatedCardFn(r) }, r.id)) })
    ] })
  ] }) });
}

// src/components/onboarding-guides/hooks/use-onboarding-guides.ts
import { useQuery } from "@tanstack/react-query";
var onboardingGuideKeys = {
  all: ["onboarding-guides"],
  lists: () => [...onboardingGuideKeys.all, "list"],
  list: (filters) => [...onboardingGuideKeys.lists(), filters],
  details: () => [...onboardingGuideKeys.all, "detail"],
  detail: (slug) => [...onboardingGuideKeys.details(), slug],
  sections: () => [...onboardingGuideKeys.all, "sections"],
  admin: {
    all: ["admin", "onboarding-guides"],
    lists: () => ["admin", "onboarding-guides", "list"],
    detail: (slug) => ["admin", "onboarding-guide", slug],
    stats: () => ["admin", "onboarding-guides", "stats"]
  }
};
function useOnboardingGuides(filters) {
  return useQuery({
    queryKey: onboardingGuideKeys.list(filters || {}),
    queryFn: async () => {
      const params = new URLSearchParams();
      if (filters?.search) params.set("search", filters.search);
      if (filters?.section) params.set("section", filters.section);
      if (filters?.limit) params.set("limit", filters.limit.toString());
      if (filters?.offset) params.set("offset", filters.offset.toString());
      const res = await fetch(`/api/onboarding-guides?${params}`);
      if (!res.ok) throw new Error("Failed to fetch onboarding guides");
      return res.json();
    }
  });
}
function useOnboardingGuide(slug) {
  return useQuery({
    queryKey: onboardingGuideKeys.detail(slug || ""),
    queryFn: async () => {
      const res = await fetch(`/api/onboarding-guides/${slug}`);
      if (!res.ok) throw new Error("Failed to fetch onboarding guide");
      return res.json();
    },
    enabled: !!slug
  });
}
function useOnboardingGuideSections() {
  return useQuery({
    queryKey: onboardingGuideKeys.sections(),
    queryFn: async () => {
      const res = await fetch("/api/onboarding-guides/sections");
      if (!res.ok)
        throw new Error("Failed to fetch onboarding-guide sections");
      return res.json();
    },
    staleTime: 0
  });
}
export {
  OnboardingGuideDetailView,
  OnboardingGuidesCatalogSkeleton,
  OnboardingGuidesCatalogView,
  onboardingGuideKeys,
  useOnboardingGuide,
  useOnboardingGuideSections,
  useOnboardingGuides
};
//# sourceMappingURL=index.js.map