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 { 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 CronContent() {
  const { token } = useAuth();
  const [crons, setCrons] = useState([]);
  const [loading, setLoading] = useState(true);
  const [triggering, setTriggering] = useState(null);
  const headers = { Authorization: `Bearer ${token}` };
  const load = () => {
    fetch("/api/admin/crons", { headers }).then((r) => r.json()).then((res) => setCrons(res.crons || [])).finally(() => setLoading(false));
  };
  useEffect(load, []);
  const trigger = async (name) => {
    setTriggering(name);
    await fetch("/api/admin/crons", {
      method: "POST",
      headers: { ...headers, "Content-Type": "application/json" },
      body: JSON.stringify({ name })
    });
    setTimeout(() => {
      load();
      setTriggering(null);
    }, 1e3);
  };
  const timeAgo = (dt) => {
    if (!dt) return "Nooit";
    const diff = Date.now() - new Date(dt).getTime();
    const h = Math.floor(diff / 36e5);
    if (h < 1) return `${Math.floor(diff / 6e4)}m geleden`;
    if (h < 24) return `${h}u geleden`;
    return `${Math.floor(h / 24)}d geleden`;
  };
  if (loading) return /* @__PURE__ */ jsx(AdminLayout, { title: "Cron Jobs", children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-20", children: /* @__PURE__ */ jsx("div", { className: "w-8 h-8 border-2 border-[#00FF6A] border-t-transparent rounded-full animate-spin" }) }) });
  return /* @__PURE__ */ jsx(AdminLayout, { title: "Cron Jobs", children: /* @__PURE__ */ jsx("div", { className: "space-y-3", children: crons.map((c) => {
    const lr = c.last_run;
    const statusColor = !lr ? "text-[#666]" : lr.status === "ok" ? "text-[#00FF6A]" : lr.status === "error" ? "text-[#FF3B3B]" : "text-[#FFD700]";
    return /* @__PURE__ */ jsxs("div", { className: "bg-[#141414] border border-[#333] rounded-xl p-5", children: [
      /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
            /* @__PURE__ */ jsx("span", { className: `w-2 h-2 rounded-full ${!lr ? "bg-[#666]" : lr.status === "ok" ? "bg-[#00FF6A]" : lr.status === "error" ? "bg-[#FF3B3B]" : "bg-[#FFD700]"}` }),
            /* @__PURE__ */ jsx("span", { className: "text-[#F5F5F5] font-medium", children: c.name }),
            /* @__PURE__ */ jsx("span", { className: "text-xs text-[#666]", children: c.description })
          ] }),
          /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-6 mt-2 text-sm text-[#999]", children: [
            /* @__PURE__ */ jsxs("span", { children: [
              "📅 ",
              c.schedule
            ] }),
            /* @__PURE__ */ jsxs("span", { children: [
              "🕐 ",
              lr ? timeAgo(lr.started_at) : "Nooit gedraaid"
            ] }),
            lr?.duration_secs != null && /* @__PURE__ */ jsxs("span", { children: [
              "⏱️ ",
              Math.round(lr.duration_secs),
              "s"
            ] }),
            /* @__PURE__ */ jsx("span", { className: statusColor, children: lr?.status || "unknown" })
          ] })
        ] }),
        /* @__PURE__ */ jsxs(
          "button",
          {
            onClick: () => trigger(c.name),
            disabled: triggering === c.name,
            className: "px-4 py-2 rounded-lg text-sm bg-[#1A1A1A] border border-[#333] text-[#999] hover:text-[#00FF6A] hover:border-[#00FF6A] transition-colors disabled:opacity-50",
            children: [
              triggering === c.name ? "⏳" : "▶️",
              " Run"
            ]
          }
        )
      ] }),
      lr?.output_summary && /* @__PURE__ */ jsx("div", { className: "mt-3 text-xs text-[#666] bg-[#0A0A0A] p-2 rounded", children: lr.output_summary }),
      lr?.error_message && /* @__PURE__ */ jsx("div", { className: "mt-3 text-xs text-[#FF3B3B] bg-[#FF3B3B]/10 p-2 rounded", children: lr.error_message })
    ] }, c.name);
  }) }) });
}
function CronMonitor() {
  return /* @__PURE__ */ jsx(AuthProvider, { children: /* @__PURE__ */ jsx(AuthGuard, { children: /* @__PURE__ */ jsx(CronContent, {}) }) });
}

const $$Crons = 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>Cron Jobs — SneakerPicks Admin</title>${renderHead()}</head> <body class="min-h-screen bg-[#0A0A0A] text-[#F5F5F5]"> ${renderComponent($$result, "CronMonitor", CronMonitor, { "client:load": true, "client:component-hydration": "load", "client:component-path": "C:/Users/Roel/clawd/sneakerpicks/src/components/admin/CronMonitor", "client:component-export": "default" })} </body></html>`;
}, "C:/Users/Roel/clawd/sneakerpicks/src/pages/admin/crons.astro", void 0);

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

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

const page = () => _page;

export { page };
