import { jsx, jsxs } from "react/jsx-runtime";
import { useQuery } from "@tanstack/react-query";
import { s as supabase } from "./client-CJCZGN4z.js";
import { Link } from "@tanstack/react-router";
import { r as resolveImage, c as categoryName, t as timeAgo } from "./router-CEaBCHfX.js";
const FALLBACK = [
  "Welcome to Malawi Today — your trusted source for national news"
];
function BreakingTicker() {
  const { data } = useQuery({
    queryKey: ["breaking-ticker"],
    queryFn: async () => {
      const { data: data2, error } = await supabase.from("breaking_news").select("message").eq("active", true).order("priority", { ascending: false });
      if (error) throw error;
      return data2.map((d) => d.message);
    },
    staleTime: 6e4
  });
  const messages = data && data.length > 0 ? data : FALLBACK;
  const items = [...messages, ...messages];
  return /* @__PURE__ */ jsx("div", { className: "bg-brand-accent text-white py-2 overflow-hidden", children: /* @__PURE__ */ jsxs("div", { className: "container mx-auto px-4 flex items-center gap-4", children: [
    /* @__PURE__ */ jsx("span", { className: "font-bold uppercase tracking-tight text-[11px] whitespace-nowrap bg-white/20 px-2 py-0.5 rounded shrink-0", children: "Breaking" }),
    /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden relative", children: /* @__PURE__ */ jsx("div", { className: "flex gap-10 animate-ticker whitespace-nowrap will-change-transform", children: items.map((t, i) => /* @__PURE__ */ jsxs("span", { className: "text-sm font-medium", children: [
      "• ",
      t
    ] }, i)) }) })
  ] }) });
}
function ArticleCard({
  article,
  variant = "default"
}) {
  const img = resolveImage(article.image);
  if (variant === "compact") {
    return /* @__PURE__ */ jsxs(Link, { to: "/article/$slug", params: { slug: article.slug }, className: "group block", children: [
      /* @__PURE__ */ jsx("h4", { className: "font-bold leading-tight mb-1 group-hover:text-brand-accent", children: article.title }),
      /* @__PURE__ */ jsxs("span", { className: "text-[10px] text-muted-foreground uppercase font-bold tracking-tight", children: [
        categoryName(article.category),
        " • ",
        timeAgo(article.publishedAt)
      ] })
    ] });
  }
  if (variant === "horizontal") {
    return /* @__PURE__ */ jsxs(
      Link,
      {
        to: "/article/$slug",
        params: { slug: article.slug },
        className: "group grid grid-cols-[120px_1fr] sm:grid-cols-[160px_1fr] gap-4",
        children: [
          /* @__PURE__ */ jsx(
            "img",
            {
              src: img,
              alt: article.imageAlt,
              loading: "lazy",
              width: 400,
              height: 300,
              className: "aspect-[4/3] object-cover rounded-sm bg-muted"
            }
          ),
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("span", { className: "text-brand-accent font-bold text-[11px] uppercase tracking-widest", children: categoryName(article.category) }),
            /* @__PURE__ */ jsx("h4", { className: "font-serif font-bold text-lg leading-tight mt-1 group-hover:text-brand-accent", children: article.title }),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-2 line-clamp-2", children: article.dek })
          ] })
        ]
      }
    );
  }
  return /* @__PURE__ */ jsxs(Link, { to: "/article/$slug", params: { slug: article.slug }, className: "group block", children: [
    /* @__PURE__ */ jsx(
      "img",
      {
        src: img,
        alt: article.imageAlt,
        loading: "lazy",
        width: 800,
        height: 500,
        className: "w-full aspect-video object-cover rounded-sm bg-muted mb-4"
      }
    ),
    /* @__PURE__ */ jsx("span", { className: "text-brand-accent font-bold text-xs uppercase tracking-widest", children: categoryName(article.category) }),
    /* @__PURE__ */ jsx("h4", { className: "font-serif font-bold text-xl leading-tight mt-2 mb-2 group-hover:text-brand-accent", children: article.title }),
    /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground line-clamp-2", children: article.dek })
  ] });
}
function Newsletter() {
  return /* @__PURE__ */ jsxs("section", { className: "bg-brand text-primary-foreground p-8 md:p-12 rounded-sm flex flex-col lg:flex-row items-center gap-8", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
      /* @__PURE__ */ jsx("h3", { className: "font-serif text-2xl md:text-3xl font-black mb-2 italic", children: "The Morning Malawian" }),
      /* @__PURE__ */ jsx("p", { className: "text-white/70", children: "The most important stories in Malawi, delivered to your inbox every morning at 7:00 AM." })
    ] }),
    /* @__PURE__ */ jsxs(
      "form",
      {
        onSubmit: (e) => e.preventDefault(),
        className: "flex-1 w-full flex flex-col sm:flex-row gap-2",
        children: [
          /* @__PURE__ */ jsx(
            "input",
            {
              type: "email",
              required: true,
              placeholder: "your@email.com",
              className: "flex-1 bg-white/10 border border-white/20 px-4 py-3 rounded-sm outline-none focus:bg-white/20 placeholder:text-white/40 text-white transition-all"
            }
          ),
          /* @__PURE__ */ jsx("button", { className: "bg-brand-accent text-white px-8 py-3 font-bold rounded-sm whitespace-nowrap hover:opacity-90", children: "JOIN US" })
        ]
      }
    )
  ] });
}
function AdSlot({ label = "Advertisement", height = "h-64" }) {
  return /* @__PURE__ */ jsx("div", { className: `bg-muted w-full grid place-items-center text-xs text-muted-foreground font-bold uppercase tracking-widest border border-border rounded-sm ${height}`, children: label });
}
export {
  ArticleCard as A,
  BreakingTicker as B,
  Newsletter as N,
  AdSlot as a
};
