import { e as createComponent, l as renderHead, k as renderComponent, r as renderTemplate } from '../../chunks/astro/server_DePCulMI.mjs';
import 'piccolore';
/* empty css                                     */
import { jsx, jsxs } from 'react/jsx-runtime';
import React, { useState, useEffect } from 'react';
import { A as AuthProvider, a as AuthGuard, u as useAuth } from '../../chunks/AdminAuth_CWvmd3cU.mjs';
import { A as AdminLayout } from '../../chunks/AdminLayout_CZSIXmew.mjs';
export { renderers } from '../../renderers.mjs';

function StatusBadge({ status }) {
  const s = status || "unknown";
  const styles = {
    success: "bg-[#00FF6A]/10 text-[#00FF6A]",
    failed: "bg-[#FF3B3B]/10 text-[#FF3B3B]",
    running: "bg-[#FFD700]/10 text-[#FFD700]",
    unknown: "bg-[#666]/10 text-[#666]"
  };
  return /* @__PURE__ */ jsx("span", { className: `text-xs px-2 py-1 rounded-full ${styles[s] || styles.unknown}`, children: s });
}
function timeAgo(iso) {
  if (!iso) return "Nooit";
  const mins = Math.floor((Date.now() - new Date(iso).getTime()) / 6e4);
  if (mins < 1) return "Zojuist";
  if (mins < 60) return `${mins} min geleden`;
  if (mins < 1440) return `${Math.floor(mins / 60)} uur geleden`;
  return `${Math.floor(mins / 1440)} dagen geleden`;
}
function FeedManagerContent() {
  const { token } = useAuth();
  const [feeds, setFeeds] = useState([]);
  const [loading, setLoading] = useState(true);
  const [syncing, setSyncing] = useState(/* @__PURE__ */ new Set());
  const [logsFor, setLogsFor] = useState(null);
  const [logs, setLogs] = useState([]);
  const [logsLoading, setLogsLoading] = useState(false);
  const headers = { Authorization: `Bearer ${token}`, "Content-Type": "application/json" };
  const loadFeeds = () => {
    fetch("/api/admin/feeds", { headers: { Authorization: `Bearer ${token}` } }).then((r) => r.json()).then((d) => setFeeds(d.feeds || [])).catch(() => {
    }).finally(() => setLoading(false));
  };
  useEffect(() => {
    loadFeeds();
  }, [token]);
  const toggleFeed = async (feed) => {
    await fetch(`/api/admin/feeds/${feed.id}`, {
      method: "PUT",
      headers,
      body: JSON.stringify({ is_enabled: !feed.is_enabled })
    });
    setFeeds((prev) => prev.map((f) => f.id === feed.id ? { ...f, is_enabled: !f.is_enabled } : f));
  };
  const syncFeed = async (id) => {
    setSyncing((prev) => new Set(prev).add(id));
    try {
      await fetch(`/api/admin/feeds/${id}/sync`, { method: "POST", headers });
      loadFeeds();
    } catch {
    }
    setSyncing((prev) => {
      const n = new Set(prev);
      n.delete(id);
      return n;
    });
  };
  const showLogs = async (id) => {
    if (logsFor === id) {
      setLogsFor(null);
      return;
    }
    setLogsFor(id);
    setLogsLoading(true);
    try {
      const res = await fetch(`/api/admin/feeds/${id}/logs?limit=10`, { headers: { Authorization: `Bearer ${token}` } });
      const d = await res.json();
      setLogs(d.logs || []);
    } catch {
      setLogs([]);
    }
    setLogsLoading(false);
  };
  if (loading) return /* @__PURE__ */ jsx(AdminLayout, { title: "Feeds", children: /* @__PURE__ */ jsx("div", { className: "text-[#666] text-center py-12", children: "Laden..." }) });
  return /* @__PURE__ */ jsx(AdminLayout, { title: "Feeds", children: feeds.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-[#141414] border border-[#333] rounded-xl p-8 text-center", children: [
    /* @__PURE__ */ jsx("div", { className: "text-[#666] text-lg mb-2", children: "📡" }),
    /* @__PURE__ */ jsx("div", { className: "text-[#999] text-sm", children: "Geen feeds gevonden" }),
    /* @__PURE__ */ jsx("div", { className: "text-[#666] text-xs mt-1", children: "Feeds worden aangemaakt via de sync engine" })
  ] }) : /* @__PURE__ */ jsx("div", { className: "bg-[#141414] border border-[#333] rounded-xl overflow-hidden", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-sm", children: [
    /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b border-[#333] text-[#999] text-left", children: [
      /* @__PURE__ */ jsx("th", { className: "px-5 py-3 font-medium", children: "Feed" }),
      /* @__PURE__ */ jsx("th", { className: "px-5 py-3 font-medium", children: "Provider" }),
      /* @__PURE__ */ jsx("th", { className: "px-5 py-3 font-medium", children: "Status" }),
      /* @__PURE__ */ jsx("th", { className: "px-5 py-3 font-medium", children: "Producten" }),
      /* @__PURE__ */ jsx("th", { className: "px-5 py-3 font-medium", children: "Laatste sync" }),
      /* @__PURE__ */ jsx("th", { className: "px-5 py-3 font-medium", children: "Acties" })
    ] }) }),
    /* @__PURE__ */ jsx("tbody", { children: feeds.map((feed) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
      /* @__PURE__ */ jsxs("tr", { className: "border-b border-[#222] hover:bg-[#1A1A1A] transition-colors", children: [
        /* @__PURE__ */ jsxs("td", { className: "px-5 py-3", children: [
          /* @__PURE__ */ jsx("div", { className: "text-[#F5F5F5] font-medium", children: feed.name }),
          feed.merchant_name && /* @__PURE__ */ jsx("div", { className: "text-xs text-[#666]", children: feed.merchant_name })
        ] }),
        /* @__PURE__ */ jsx("td", { className: "px-5 py-3 text-[#999]", children: feed.provider_name }),
        /* @__PURE__ */ jsxs("td", { className: "px-5 py-3", children: [
          /* @__PURE__ */ jsx(StatusBadge, { status: feed.is_enabled ? feed.last_sync_status || "unknown" : "disabled" }),
          feed.last_error && /* @__PURE__ */ jsx("div", { className: "text-xs text-[#FF3B3B] mt-1 max-w-[200px] truncate", title: feed.last_error, children: feed.last_error })
        ] }),
        /* @__PURE__ */ jsx("td", { className: "px-5 py-3 text-[#999]", children: feed.product_count.toLocaleString() }),
        /* @__PURE__ */ jsx("td", { className: "px-5 py-3 text-[#999]", children: timeAgo(feed.last_sync_at) }),
        /* @__PURE__ */ jsx("td", { className: "px-5 py-3", children: /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
          /* @__PURE__ */ jsx(
            "button",
            {
              onClick: () => syncFeed(feed.id),
              disabled: syncing.has(feed.id),
              title: "Force sync",
              className: "text-[#999] hover:text-[#00FF6A] transition-colors disabled:opacity-30",
              children: syncing.has(feed.id) ? "⏳" : "🔄"
            }
          ),
          /* @__PURE__ */ jsx(
            "button",
            {
              onClick: () => toggleFeed(feed),
              title: feed.is_enabled ? "Uitschakelen" : "Inschakelen",
              className: "text-[#999] hover:text-[#F5F5F5] transition-colors",
              children: feed.is_enabled ? "⏸" : "▶️"
            }
          ),
          /* @__PURE__ */ jsx(
            "button",
            {
              onClick: () => showLogs(feed.id),
              title: "Sync logs",
              className: `transition-colors ${logsFor === feed.id ? "text-[#00FF6A]" : "text-[#999] hover:text-[#F5F5F5]"}`,
              children: "📋"
            }
          )
        ] }) })
      ] }),
      logsFor === feed.id && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: 6, className: "bg-[#0A0A0A] px-5 py-3", children: logsLoading ? /* @__PURE__ */ jsx("div", { className: "text-[#666] text-xs", children: "Laden..." }) : logs.length === 0 ? /* @__PURE__ */ jsx("div", { className: "text-[#666] text-xs", children: "Geen sync logs" }) : /* @__PURE__ */ jsxs("table", { className: "w-full text-xs", children: [
        /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "text-[#666] text-left", children: [
          /* @__PURE__ */ jsx("th", { className: "py-1 pr-4", children: "Tijd" }),
          /* @__PURE__ */ jsx("th", { className: "py-1 pr-4", children: "Status" }),
          /* @__PURE__ */ jsx("th", { className: "py-1 pr-4", children: "Verwerkt" }),
          /* @__PURE__ */ jsx("th", { className: "py-1 pr-4", children: "Nieuw" }),
          /* @__PURE__ */ jsx("th", { className: "py-1 pr-4", children: "Updated" }),
          /* @__PURE__ */ jsx("th", { className: "py-1", children: "Error" })
        ] }) }),
        /* @__PURE__ */ jsx("tbody", { children: logs.map((log) => /* @__PURE__ */ jsxs("tr", { className: "text-[#999]", children: [
          /* @__PURE__ */ jsx("td", { className: "py-1 pr-4", children: new Date(log.started_at).toLocaleString("nl-NL") }),
          /* @__PURE__ */ jsx("td", { className: "py-1 pr-4", children: /* @__PURE__ */ jsx(StatusBadge, { status: log.status }) }),
          /* @__PURE__ */ jsx("td", { className: "py-1 pr-4", children: log.products_processed || 0 }),
          /* @__PURE__ */ jsx("td", { className: "py-1 pr-4", children: log.products_created || 0 }),
          /* @__PURE__ */ jsx("td", { className: "py-1 pr-4", children: log.products_updated || 0 }),
          /* @__PURE__ */ jsx("td", { className: "py-1 text-[#FF3B3B] max-w-[300px] truncate", children: log.error_message || "-" })
        ] }, log.id)) })
      ] }) }) })
    ] }, feed.id)) })
  ] }) }) });
}
function FeedManagerPage() {
  return /* @__PURE__ */ jsx(AuthProvider, { children: /* @__PURE__ */ jsx(AuthGuard, { children: /* @__PURE__ */ jsx(FeedManagerContent, {}) }) });
}

const $$Feeds = createComponent(($$result, $$props, $$slots) => {
  return renderTemplate`<html lang="nl" class="dark"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Feeds — SneakerPicks Admin</title>${renderHead()}</head> <body class="min-h-screen bg-[#0A0A0A] text-[#F5F5F5]"> ${renderComponent($$result, "FeedManager", FeedManagerPage, { "client:load": true, "client:component-hydration": "load", "client:component-path": "C:/Users/Roel/clawd/sneakerpicks/src/components/admin/FeedManager", "client:component-export": "default" })} </body></html>`;
}, "C:/Users/Roel/clawd/sneakerpicks/src/pages/admin/feeds.astro", void 0);

const $$file = "C:/Users/Roel/clawd/sneakerpicks/src/pages/admin/feeds.astro";
const $$url = "/admin/feeds";

const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
  __proto__: null,
  default: $$Feeds,
  file: $$file,
  url: $$url
}, Symbol.toStringTag, { value: 'Module' }));

const page = () => _page;

export { page };
