import { jsx, jsxs, Fragment } from "react/jsx-runtime";
import { RemixServer, useLocation, Outlet, Meta, Links, ScrollRestoration, Scripts, useActionData, useNavigation, useSearchParams, Form, useLoaderData } from "@remix-run/react";
import { renderToString } from "react-dom/server";
import { useState, useCallback, useEffect, useRef } from "react";
import { json } from "@remix-run/node";
function handleRequest(request, responseStatusCode, responseHeaders, remixContext, loadContext) {
  let markup = renderToString(
    /* @__PURE__ */ jsx(RemixServer, { context: remixContext, url: request.url })
  );
  responseHeaders.set("Content-Type", "text/html");
  return new Response("<!DOCTYPE html>" + markup, {
    headers: responseHeaders,
    status: responseStatusCode
  });
}
const entryServer = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: handleRequest
}, Symbol.toStringTag, { value: "Module" }));
const styles = "/assets/styles-D7Zjtr3a.css";
function PowerWidget({ apiBase = "/api" }) {
  const [status, setStatus] = useState(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);
  const fetchStatus = useCallback(async () => {
    try {
      const response = await fetch(`${apiBase}/system/ups/status`);
      if (!response.ok) {
        throw new Error(`HTTP ${response.status}`);
      }
      const data = await response.json();
      setStatus(data);
      setError(null);
    } catch (err) {
      setError(err instanceof Error ? err.message : "Failed to fetch");
    } finally {
      setLoading(false);
    }
  }, [apiBase]);
  useEffect(() => {
    fetchStatus();
    let eventSource = null;
    const connectSSE = () => {
      eventSource = new EventSource("/sse/events");
      eventSource.addEventListener("ups_battery", (event) => {
        try {
          const data = JSON.parse(event.data);
          setStatus((prev) => prev ? {
            ...prev,
            battery_percentage: data.percentage,
            voltage: data.voltage
          } : prev);
        } catch (e) {
          console.error("Failed to parse ups_battery event:", e);
        }
      });
      eventSource.addEventListener("ups_warning", () => {
        fetchStatus();
      });
      eventSource.addEventListener("ups_critical", () => {
        fetchStatus();
      });
      eventSource.onerror = () => {
        eventSource == null ? void 0 : eventSource.close();
        setTimeout(connectSSE, 5e3);
      };
    };
    connectSSE();
    const pollInterval = setInterval(fetchStatus, 6e4);
    return () => {
      eventSource == null ? void 0 : eventSource.close();
      clearInterval(pollInterval);
    };
  }, [apiBase, fetchStatus]);
  if (!loading && (!status || !status.is_available)) {
    return null;
  }
  if (loading) {
    return /* @__PURE__ */ jsx("div", { className: "power-widget power-widget--loading", title: "Loading power status...", children: /* @__PURE__ */ jsx("div", { className: "power-widget__icon", children: /* @__PURE__ */ jsx(BatteryIcon, { percentage: 50 }) }) });
  }
  const percentage = Math.round((status == null ? void 0 : status.battery_percentage) ?? 0);
  const isCharging = (status == null ? void 0 : status.power_source) === "ac" || (status == null ? void 0 : status.battery_status) === "charging";
  const isCritical = percentage <= 10;
  const isLow = percentage <= 20;
  const isFull = percentage >= 95 && isCharging;
  let statusClass = "power-widget--normal";
  if (isCritical) {
    statusClass = "power-widget--critical";
  } else if (isLow) {
    statusClass = "power-widget--low";
  } else if (isFull) {
    statusClass = "power-widget--full";
  } else if (isCharging) {
    statusClass = "power-widget--charging";
  }
  const tooltipParts = [
    `Battery: ${percentage}%`,
    `Source: ${(status == null ? void 0 : status.power_source) === "ac" ? "AC Power" : "Battery"}`
  ];
  if ((status == null ? void 0 : status.voltage) && status.voltage > 0) {
    tooltipParts.push(`Voltage: ${(status.voltage / 1e3).toFixed(2)}V`);
  }
  if ((status == null ? void 0 : status.current) !== void 0 && (status == null ? void 0 : status.current) !== null) {
    const absCurrentMa = Math.abs(status.current * 1e3).toFixed(0);
    const direction = status.current >= 0 ? "charging" : "draw";
    tooltipParts.push(`Current: ${absCurrentMa}mA ${direction}`);
  }
  if (status == null ? void 0 : status.time_remaining) {
    const mins = status.time_remaining;
    if (mins < 60) {
      tooltipParts.push(`Est. runtime: ${mins} min`);
    } else {
      const hours = Math.floor(mins / 60);
      const remainMins = mins % 60;
      tooltipParts.push(`Est. runtime: ${hours}h ${remainMins}m`);
    }
  }
  const tooltip = tooltipParts.join("\n");
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: `power-widget ${statusClass}`,
      title: tooltip,
      role: "status",
      "aria-label": `Battery at ${percentage}%${isCharging ? ", plugged in" : ", on battery"}`,
      children: [
        /* @__PURE__ */ jsx("div", { className: "power-widget__icon", children: /* @__PURE__ */ jsx(BatteryIcon, { percentage, isCharging }) }),
        /* @__PURE__ */ jsxs("span", { className: "power-widget__percentage", children: [
          percentage,
          "%"
        ] }),
        isCharging && /* @__PURE__ */ jsx("span", { className: "power-widget__plug-indicator", "aria-label": "Plugged in", title: "AC Power", children: /* @__PURE__ */ jsx(PlugIcon, {}) })
      ]
    }
  );
}
function BatteryIcon({ percentage, isCharging = false }) {
  const fillWidth = Math.max(0, Math.min(100, percentage));
  return /* @__PURE__ */ jsxs(
    "svg",
    {
      className: "battery-icon",
      viewBox: "0 0 24 14",
      fill: "none",
      xmlns: "http://www.w3.org/2000/svg",
      "aria-hidden": "true",
      children: [
        /* @__PURE__ */ jsx(
          "rect",
          {
            x: "0.5",
            y: "0.5",
            width: "20",
            height: "13",
            rx: "2",
            stroke: "currentColor",
            strokeWidth: "1",
            fill: "none"
          }
        ),
        /* @__PURE__ */ jsx(
          "rect",
          {
            x: "21",
            y: "4",
            width: "3",
            height: "6",
            rx: "1",
            fill: "currentColor"
          }
        ),
        /* @__PURE__ */ jsx(
          "rect",
          {
            className: "battery-icon__fill",
            x: "2",
            y: "2",
            width: Math.max(0, fillWidth / 100 * 17),
            height: "10",
            rx: "1",
            fill: "currentColor"
          }
        ),
        isCharging && /* @__PURE__ */ jsx(
          "path",
          {
            className: "battery-icon__bolt",
            d: "M12 1L8 7H11L9 13L14 6H11L12 1Z",
            fill: "var(--color-bg)",
            stroke: "currentColor",
            strokeWidth: "0.5"
          }
        )
      ]
    }
  );
}
function PlugIcon() {
  return /* @__PURE__ */ jsxs(
    "svg",
    {
      className: "plug-icon",
      viewBox: "0 0 12 12",
      fill: "none",
      xmlns: "http://www.w3.org/2000/svg",
      "aria-hidden": "true",
      children: [
        /* @__PURE__ */ jsx("rect", { x: "3", y: "0", width: "2", height: "4", rx: "0.5", fill: "currentColor" }),
        /* @__PURE__ */ jsx("rect", { x: "7", y: "0", width: "2", height: "4", rx: "0.5", fill: "currentColor" }),
        /* @__PURE__ */ jsx("rect", { x: "2", y: "3", width: "8", height: "5", rx: "1", fill: "currentColor" }),
        /* @__PURE__ */ jsx("rect", { x: "5", y: "8", width: "2", height: "4", rx: "0.5", fill: "currentColor" })
      ]
    }
  );
}
const links = () => [
  { rel: "stylesheet", href: styles }
];
function Layout({ children }) {
  return /* @__PURE__ */ jsxs("html", { lang: "en", children: [
    /* @__PURE__ */ jsxs("head", { children: [
      /* @__PURE__ */ jsx("meta", { charSet: "utf-8" }),
      /* @__PURE__ */ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1, maximum-scale=5" }),
      /* @__PURE__ */ jsx("meta", { name: "theme-color", content: "#0a0e1a" }),
      /* @__PURE__ */ jsx("meta", { name: "description", content: "Dangerous Pi - Proxmark3 Management Interface" }),
      /* @__PURE__ */ jsx(Meta, {}),
      /* @__PURE__ */ jsx(Links, {})
    ] }),
    /* @__PURE__ */ jsxs("body", { children: [
      children,
      /* @__PURE__ */ jsx(ScrollRestoration, {}),
      /* @__PURE__ */ jsx(Scripts, {})
    ] })
  ] });
}
function App() {
  const location = useLocation();
  const [theme, setTheme] = useState("dark");
  useEffect(() => {
    const savedTheme = localStorage.getItem("theme");
    if (savedTheme) {
      setTheme(savedTheme);
      document.documentElement.setAttribute("data-theme", savedTheme);
    } else {
      setTheme("dark");
      document.documentElement.setAttribute("data-theme", "dark");
    }
  }, []);
  const toggleTheme = () => {
    const themes = ["dark", "auto", "light"];
    const currentIndex = themes.indexOf(theme);
    const nextTheme = themes[(currentIndex + 1) % themes.length];
    setTheme(nextTheme);
    localStorage.setItem("theme", nextTheme);
    document.documentElement.setAttribute("data-theme", nextTheme);
  };
  const navLinks = [
    { to: "/", label: "Dashboard", icon: "◈" },
    { to: "/commands", label: "Commands", icon: "▶" },
    { to: "/settings", label: "Settings", icon: "⚙" },
    { to: "/updates", label: "Updates", icon: "🔄" },
    { to: "/logs", label: "Logs", icon: "≡" }
  ];
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx("header", { className: "header", children: /* @__PURE__ */ jsxs("div", { className: "header-content", children: [
      /* @__PURE__ */ jsxs("a", { href: "/", className: "logo", children: [
        /* @__PURE__ */ jsx("div", { className: "logo-icon" }),
        /* @__PURE__ */ jsx("span", { children: "Dangerous Pi" })
      ] }),
      /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "0.75rem" }, children: [
        /* @__PURE__ */ jsx(PowerWidget, {}),
        /* @__PURE__ */ jsx(
          "button",
          {
            onClick: toggleTheme,
            className: "btn-secondary",
            style: { minWidth: "44px", padding: "0.5rem" },
            "aria-label": "Toggle theme",
            title: `Current theme: ${theme}`,
            children: theme === "dark" ? "◐" : theme === "light" ? "○" : "◑"
          }
        )
      ] })
    ] }) }),
    /* @__PURE__ */ jsx("nav", { className: "nav", style: { display: "none" }, children: navLinks.map((link) => /* @__PURE__ */ jsxs(
      "a",
      {
        href: link.to,
        className: `nav-link ${location.pathname === link.to ? "active" : ""}`,
        children: [
          /* @__PURE__ */ jsx("span", { style: { fontSize: "1.25rem" }, children: link.icon }),
          /* @__PURE__ */ jsx("span", { children: link.label })
        ]
      },
      link.to
    )) }),
    /* @__PURE__ */ jsx("main", { className: "main", children: /* @__PURE__ */ jsx(Outlet, {}) }),
    /* @__PURE__ */ jsx("nav", { className: "nav", children: navLinks.map((link) => /* @__PURE__ */ jsxs(
      "a",
      {
        href: link.to,
        className: `nav-link ${location.pathname === link.to ? "active" : ""}`,
        children: [
          /* @__PURE__ */ jsx("span", { style: { fontSize: "1.5rem" }, children: link.icon }),
          /* @__PURE__ */ jsx("span", { children: link.label })
        ]
      },
      link.to
    )) }),
    /* @__PURE__ */ jsx("style", { children: `
        @media (min-width: 768px) {
          .nav:first-of-type {
            display: flex !important;
            position: static;
            border: none;
            background: transparent;
            padding: 1rem 0;
            max-width: 1280px;
            margin: 0 auto;
            justify-content: center;
          }

          .nav:last-of-type {
            display: none;
          }

          body {
            padding-bottom: 0;
          }
        }
      ` })
  ] });
}
const route0 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  Layout,
  default: App,
  links
}, Symbol.toStringTag, { value: "Module" }));
function DeviceSelector({
  selectedDeviceId,
  onDeviceSelect,
  showIdentifyButton = true,
  autoSelectSingle = true
}) {
  const [devices, setDevices] = useState([]);
  const [loading, setLoading] = useState(true);
  const [identifying, setIdentifying] = useState(null);
  const [error, setError] = useState(null);
  const fetchDevices = async () => {
    try {
      const response = await fetch("/api/pm3/devices");
      if (!response.ok) {
        throw new Error(`Failed to fetch devices: ${response.statusText}`);
      }
      const data = await response.json();
      const deviceList = data.devices || [];
      setDevices(deviceList);
      if (autoSelectSingle && deviceList.length === 1 && !selectedDeviceId) {
        const device = deviceList[0];
        if (device.status === "connected") {
          onDeviceSelect(device.device_id);
        }
      }
      setError(null);
    } catch (err) {
      console.error("Error fetching devices:", err);
      setError(err instanceof Error ? err.message : "Failed to fetch devices");
      setDevices([]);
    } finally {
      setLoading(false);
    }
  };
  useEffect(() => {
    fetchDevices();
    const interval = setInterval(fetchDevices, 5e3);
    return () => clearInterval(interval);
  }, []);
  const handleIdentify = async (deviceId) => {
    setIdentifying(deviceId);
    try {
      const response = await fetch(`/api/pm3/devices/${deviceId}/identify`, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ duration: 2e3 })
      });
      if (!response.ok) {
        throw new Error("Failed to identify device");
      }
      setTimeout(() => setIdentifying(null), 2100);
    } catch (err) {
      console.error("Error identifying device:", err);
      setIdentifying(null);
    }
  };
  const getStatusColor = (device) => {
    switch (device.status) {
      case "connected":
        return "var(--color-success)";
      case "in_use":
        return "var(--color-warning)";
      case "version_mismatch":
      case "disabled":
        return "var(--color-warning)";
      case "error":
      case "disconnected":
        return "var(--color-error)";
      case "flashing":
        return "var(--color-info)";
      default:
        return "var(--color-border)";
    }
  };
  const getStatusText = (device) => {
    switch (device.status) {
      case "connected":
        return "Connected";
      case "in_use":
        return "In Use";
      case "version_mismatch":
        return "Version Mismatch";
      case "disabled":
        return "Disabled";
      case "error":
        return "Error";
      case "disconnected":
        return "Disconnected";
      case "flashing":
        return "Flashing";
      default:
        return "Unknown";
    }
  };
  const isDeviceSelectable = (device) => {
    return device.status === "connected" || device.status === "in_use" && device.device_id === selectedDeviceId;
  };
  const getDeviceName = (device) => {
    return device.friendly_name || device.device_path;
  };
  if (loading) {
    return /* @__PURE__ */ jsxs("div", { className: "card", children: [
      /* @__PURE__ */ jsxs("h3", { className: "card-title", children: [
        /* @__PURE__ */ jsx("span", { style: { color: "var(--color-primary)" }, children: "📡" }),
        " Proxmark3 Devices"
      ] }),
      /* @__PURE__ */ jsxs("div", { style: { textAlign: "center", padding: "var(--space-6)" }, children: [
        /* @__PURE__ */ jsx("span", { className: "spinner" }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { marginTop: "var(--space-3)" }, children: "Detecting devices..." })
      ] })
    ] });
  }
  if (error) {
    return /* @__PURE__ */ jsxs("div", { className: "card", style: { borderColor: "var(--color-error)" }, children: [
      /* @__PURE__ */ jsxs("h3", { className: "card-title", children: [
        /* @__PURE__ */ jsx("span", { style: { color: "var(--color-error)" }, children: "⚠" }),
        " Device Detection Error"
      ] }),
      /* @__PURE__ */ jsx("p", { className: "text-muted", children: error }),
      /* @__PURE__ */ jsx(
        "button",
        {
          className: "btn btn-secondary",
          style: { marginTop: "var(--space-3)" },
          onClick: fetchDevices,
          children: "Retry"
        }
      )
    ] });
  }
  if (devices.length === 0) {
    return /* @__PURE__ */ jsxs("div", { className: "card", children: [
      /* @__PURE__ */ jsxs("h3", { className: "card-title", children: [
        /* @__PURE__ */ jsx("span", { style: { color: "var(--color-primary)" }, children: "📡" }),
        " Proxmark3 Devices"
      ] }),
      /* @__PURE__ */ jsxs("div", { style: { textAlign: "center", padding: "var(--space-6)" }, children: [
        /* @__PURE__ */ jsx("div", { style: { fontSize: "3rem", marginBottom: "var(--space-3)", opacity: 0.5 }, children: "🔌" }),
        /* @__PURE__ */ jsx("p", { className: "text-secondary", style: { marginBottom: "var(--space-2)" }, children: "No Proxmark3 devices detected" }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.875rem" }, children: "Connect a Proxmark3 device via USB to get started" })
      ] })
    ] });
  }
  return /* @__PURE__ */ jsxs("div", { className: "card", children: [
    /* @__PURE__ */ jsxs("h3", { className: "card-title", children: [
      /* @__PURE__ */ jsx("span", { style: { color: "var(--color-primary)" }, children: "📡" }),
      " Proxmark3 Devices (",
      devices.length,
      ")"
    ] }),
    /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: "var(--space-3)" }, children: devices.map((device) => {
      const isSelected = selectedDeviceId === device.device_id;
      const isSelectable = isDeviceSelectable(device);
      const statusColor = getStatusColor(device);
      return /* @__PURE__ */ jsx(
        "div",
        {
          style: {
            padding: "var(--space-3)",
            border: "2px solid",
            borderColor: isSelected ? "var(--color-primary)" : statusColor,
            borderRadius: "var(--radius)",
            cursor: isSelectable ? "pointer" : "not-allowed",
            opacity: isSelectable ? 1 : 0.6,
            transition: "all 150ms ease",
            background: isSelected ? "rgba(37, 99, 235, 0.05)" : "transparent"
          },
          onClick: () => {
            if (isSelectable && !isSelected) {
              onDeviceSelect(device.device_id);
            }
          },
          children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "flex-start", gap: "var(--space-3)" }, children: [
            /* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
              /* @__PURE__ */ jsxs("div", { style: { fontWeight: 600, fontSize: "1.1rem", marginBottom: "var(--space-1)" }, children: [
                isSelected && /* @__PURE__ */ jsx("span", { style: { color: "var(--color-primary)", marginRight: "var(--space-2)" }, children: "▸" }),
                getDeviceName(device)
              ] }),
              /* @__PURE__ */ jsxs("div", { style: { fontSize: "0.875rem", color: "var(--color-text-muted)", marginBottom: "var(--space-2)" }, children: [
                /* @__PURE__ */ jsx("span", { style: { fontFamily: "var(--font-mono)" }, children: device.device_path }),
                device.serial_number && /* @__PURE__ */ jsxs(Fragment, { children: [
                  " • ",
                  /* @__PURE__ */ jsxs("span", { children: [
                    "SN: ",
                    device.serial_number
                  ] })
                ] })
              ] }),
              /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexWrap: "wrap", gap: "var(--space-2)", alignItems: "center" }, children: [
                /* @__PURE__ */ jsxs(
                  "span",
                  {
                    className: `badge ${device.status === "connected" ? "badge-success" : device.status === "error" || device.status === "disconnected" ? "badge-error" : "badge-warning"}`,
                    children: [
                      /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "●" }),
                      getStatusText(device)
                    ]
                  }
                ),
                device.firmware_info && /* @__PURE__ */ jsx("span", { className: "text-muted", style: { fontSize: "0.75rem" }, children: device.firmware_info.os_version }),
                device.status === "in_use" && device.device_id !== selectedDeviceId && /* @__PURE__ */ jsx("span", { className: "text-muted", style: { fontSize: "0.75rem" }, children: "🔒 Session Active" })
              ] }),
              device.firmware_info && !device.firmware_info.compatible && /* @__PURE__ */ jsxs(
                "div",
                {
                  style: {
                    marginTop: "var(--space-2)",
                    padding: "var(--space-2)",
                    background: "rgba(217, 119, 6, 0.1)",
                    borderLeft: "3px solid var(--color-warning)",
                    borderRadius: "var(--radius)",
                    fontSize: "0.75rem"
                  },
                  children: [
                    /* @__PURE__ */ jsx("div", { style: { fontWeight: 600, marginBottom: "var(--space-1)" }, children: "⚠ Firmware Version Mismatch" }),
                    /* @__PURE__ */ jsxs("div", { className: "text-muted", children: [
                      "Device: ",
                      device.firmware_info.os_version,
                      " • Expected: ",
                      device.firmware_info.client_version
                    ] })
                  ]
                }
              )
            ] }),
            showIdentifyButton && device.status === "connected" && /* @__PURE__ */ jsx(
              "button",
              {
                className: "btn btn-secondary",
                style: {
                  fontSize: "0.875rem",
                  padding: "var(--space-2) var(--space-3)",
                  minWidth: "44px",
                  flexShrink: 0
                },
                onClick: (e) => {
                  e.stopPropagation();
                  handleIdentify(device.device_id);
                },
                disabled: identifying === device.device_id,
                "aria-label": "Identify device with LED blink",
                children: identifying === device.device_id ? /* @__PURE__ */ jsxs(Fragment, { children: [
                  /* @__PURE__ */ jsx("span", { className: "spinner" }),
                  /* @__PURE__ */ jsx("span", { children: "Blinking..." })
                ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
                  /* @__PURE__ */ jsx("span", { children: "💡" }),
                  /* @__PURE__ */ jsx("span", { children: "Identify" })
                ] })
              }
            )
          ] })
        },
        device.device_id
      );
    }) }),
    selectedDeviceId && /* @__PURE__ */ jsxs(
      "div",
      {
        style: {
          marginTop: "var(--space-4)",
          padding: "var(--space-3)",
          background: "var(--color-bg)",
          borderRadius: "var(--radius)",
          fontSize: "0.875rem"
        },
        children: [
          /* @__PURE__ */ jsx("span", { style: { color: "var(--color-success)" }, children: "✓" }),
          " Selected device will be used for all commands"
        ]
      }
    )
  ] });
}
async function action$2({ request }) {
  const formData = await request.formData();
  const command = formData.get("command");
  const sessionId = formData.get("sessionId");
  const deviceId = formData.get("deviceId");
  try {
    const response = await fetch("http://localhost:8000/api/pm3/command", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        command,
        session_id: sessionId,
        device_id: deviceId
      })
    });
    const result = await response.json();
    return json(result);
  } catch (error) {
    return json({
      success: false,
      output: "",
      error: `Failed to execute command: ${error}`
    });
  }
}
function Commands() {
  var _a;
  const actionData = useActionData();
  const navigation = useNavigation();
  const [searchParams] = useSearchParams();
  const [commandHistory, setCommandHistory] = useState([]);
  const [historyIndex, setHistoryIndex] = useState(-1);
  const [sessionId, setSessionId] = useState(null);
  const [selectedDeviceId, setSelectedDeviceId] = useState(null);
  const [sessionError, setSessionError] = useState(null);
  const inputRef = useRef(null);
  const outputRef = useRef(null);
  const isSubmitting = navigation.state === "submitting";
  useEffect(() => {
    if (!selectedDeviceId) {
      setSessionId(null);
      setSessionError(null);
      return;
    }
    async function createSession() {
      try {
        const response = await fetch("/api/system/session/create", {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify({
            device_id: selectedDeviceId,
            force_takeover: false
          })
        });
        const data = await response.json();
        if (data.success) {
          setSessionId(data.session_id);
          setSessionError(null);
        } else {
          setSessionId(null);
          setSessionError(data.error || "Failed to create session");
        }
      } catch (error) {
        console.error("Failed to create session:", error);
        setSessionId(null);
        setSessionError("Network error while creating session");
      }
    }
    createSession();
  }, [selectedDeviceId]);
  const prefilledCommand = ((_a = searchParams.get("cmd")) == null ? void 0 : _a.replace(/\+/g, " ")) || "";
  useEffect(() => {
    if (actionData && "output" in actionData) {
      const form = document.querySelector("form");
      const commandInput = form == null ? void 0 : form.querySelector('input[name="command"]');
      if (commandInput == null ? void 0 : commandInput.value) {
        setCommandHistory((prev) => [commandInput.value, ...prev].slice(0, 50));
        setHistoryIndex(-1);
      }
    }
  }, [actionData]);
  useEffect(() => {
    if (outputRef.current) {
      outputRef.current.scrollTop = outputRef.current.scrollHeight;
    }
  }, [actionData]);
  const handleKeyDown = (e) => {
    if (e.key === "ArrowUp") {
      e.preventDefault();
      if (historyIndex < commandHistory.length - 1) {
        const newIndex = historyIndex + 1;
        setHistoryIndex(newIndex);
        if (inputRef.current) {
          inputRef.current.value = commandHistory[newIndex];
        }
      }
    } else if (e.key === "ArrowDown") {
      e.preventDefault();
      if (historyIndex > 0) {
        const newIndex = historyIndex - 1;
        setHistoryIndex(newIndex);
        if (inputRef.current) {
          inputRef.current.value = commandHistory[newIndex];
        }
      } else if (historyIndex === 0) {
        setHistoryIndex(-1);
        if (inputRef.current) {
          inputRef.current.value = "";
        }
      }
    }
  };
  const quickCommands = [
    { label: "HW Status", cmd: "hw status", icon: "◈" },
    { label: "HW Version", cmd: "hw version", icon: "ⓘ" },
    { label: "HW Tune", cmd: "hw tune", icon: "📡" },
    { label: "HF Search", cmd: "hf search", icon: "🔍" },
    { label: "LF Search", cmd: "lf search", icon: "🔍" },
    { label: "HF List", cmd: "hf list", icon: "≡" }
  ];
  return /* @__PURE__ */ jsxs("div", { className: "container", children: [
    /* @__PURE__ */ jsxs("h1", { style: { marginBottom: "var(--space-6)" }, children: [
      /* @__PURE__ */ jsx("span", { style: { color: "var(--color-accent)" }, children: "▶" }),
      " PM3 Commands"
    ] }),
    /* @__PURE__ */ jsx("div", { style: { marginBottom: "var(--space-4)" }, children: /* @__PURE__ */ jsx(
      DeviceSelector,
      {
        selectedDeviceId,
        onDeviceSelect: setSelectedDeviceId,
        showIdentifyButton: true,
        autoSelectSingle: true
      }
    ) }),
    selectedDeviceId && sessionError && /* @__PURE__ */ jsx("div", { className: "card", style: { marginBottom: "var(--space-4)", borderColor: "var(--color-error)" }, children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-3)" }, children: [
      /* @__PURE__ */ jsx("span", { style: { fontSize: "1.5rem" }, children: "✗" }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("strong", { children: "Session Error" }),
        /* @__PURE__ */ jsx("p", { className: "text-secondary", style: { marginTop: "var(--space-1)", marginBottom: 0 }, children: sessionError })
      ] })
    ] }) }),
    selectedDeviceId && !sessionId && !sessionError && /* @__PURE__ */ jsx("div", { className: "card", style: { marginBottom: "var(--space-4)", borderColor: "var(--color-warning)" }, children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-3)" }, children: [
      /* @__PURE__ */ jsx("span", { style: { fontSize: "1.5rem" }, children: "⚠" }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("strong", { children: "Creating Session..." }),
        /* @__PURE__ */ jsx("p", { className: "text-secondary", style: { marginTop: "var(--space-1)", marginBottom: 0 }, children: "Establishing connection to device..." })
      ] })
    ] }) }),
    /* @__PURE__ */ jsxs("div", { className: "card", style: { marginBottom: "var(--space-4)" }, children: [
      /* @__PURE__ */ jsx("h3", { className: "card-title", children: "Quick Commands" }),
      /* @__PURE__ */ jsx("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(140px, 1fr))", gap: "var(--space-2)" }, children: quickCommands.map((qc) => /* @__PURE__ */ jsxs(
        "button",
        {
          onClick: () => {
            if (inputRef.current) {
              inputRef.current.value = qc.cmd;
              inputRef.current.focus();
            }
          },
          className: "btn btn-secondary",
          style: { fontSize: "0.75rem", padding: "var(--space-2) var(--space-3)" },
          children: [
            /* @__PURE__ */ jsx("span", { children: qc.icon }),
            /* @__PURE__ */ jsx("span", { children: qc.label })
          ]
        },
        qc.cmd
      )) })
    ] }),
    /* @__PURE__ */ jsx("div", { className: "card", style: { marginBottom: "var(--space-4)" }, children: /* @__PURE__ */ jsxs(Form, { method: "post", children: [
      /* @__PURE__ */ jsx("input", { type: "hidden", name: "sessionId", value: sessionId || "" }),
      /* @__PURE__ */ jsx("input", { type: "hidden", name: "deviceId", value: selectedDeviceId || "" }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { htmlFor: "command", className: "label", children: "Command" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "var(--space-2)" }, children: [
          /* @__PURE__ */ jsx(
            "input",
            {
              ref: inputRef,
              type: "text",
              id: "command",
              name: "command",
              className: "input",
              placeholder: !selectedDeviceId ? "Select a device first..." : !sessionId ? "Creating session..." : "Enter PM3 command (e.g., hw status)",
              defaultValue: prefilledCommand,
              onKeyDown: handleKeyDown,
              disabled: !selectedDeviceId || !sessionId || isSubmitting,
              autoComplete: "off",
              autoFocus: !!sessionId,
              style: { flex: 1 }
            }
          ),
          /* @__PURE__ */ jsx(
            "button",
            {
              type: "submit",
              className: "btn btn-primary",
              disabled: !selectedDeviceId || !sessionId || isSubmitting,
              style: { minWidth: "100px" },
              children: isSubmitting ? /* @__PURE__ */ jsxs(Fragment, { children: [
                /* @__PURE__ */ jsx("span", { className: "spinner" }),
                /* @__PURE__ */ jsx("span", { children: "Running..." })
              ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
                /* @__PURE__ */ jsx("span", { children: "▶" }),
                /* @__PURE__ */ jsx("span", { children: "Execute" })
              ] })
            }
          )
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)", marginBottom: 0 }, children: selectedDeviceId && sessionId ? "Use ↑/↓ arrow keys to navigate command history" : !selectedDeviceId ? "Select a Proxmark3 device above to start executing commands" : "Waiting for session..." })
      ] })
    ] }) }),
    /* @__PURE__ */ jsxs("div", { className: "card", children: [
      /* @__PURE__ */ jsx("h3", { className: "card-title", children: "Output" }),
      actionData ? /* @__PURE__ */ jsx("div", { ref: outputRef, className: "terminal", children: actionData.success ? /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsx("div", { style: { color: "var(--color-primary)", marginBottom: "var(--space-2)" }, children: "▸ Command executed successfully" }),
        /* @__PURE__ */ jsx("pre", { style: { margin: 0, whiteSpace: "pre-wrap", wordWrap: "break-word" }, children: actionData.output || "(No output)" })
      ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsx("div", { style: { color: "var(--color-error)", marginBottom: "var(--space-2)" }, children: "✗ Command failed" }),
        /* @__PURE__ */ jsx("pre", { style: { margin: 0, color: "var(--color-error)", whiteSpace: "pre-wrap", wordWrap: "break-word" }, children: actionData.error || "Unknown error" })
      ] }) }) : /* @__PURE__ */ jsxs("div", { className: "terminal", style: { color: "var(--color-text-muted)", fontStyle: "italic" }, children: [
        "Ready. Enter a command above and press Execute.",
        /* @__PURE__ */ jsx("br", {}),
        /* @__PURE__ */ jsx("br", {}),
        /* @__PURE__ */ jsx("span", { style: { color: "var(--color-text-secondary)" }, children: "Examples:" }),
        /* @__PURE__ */ jsx("br", {}),
        "• hw status — Check hardware status",
        /* @__PURE__ */ jsx("br", {}),
        "• hw version — Show firmware version",
        /* @__PURE__ */ jsx("br", {}),
        "• hf search — Search for HF tags",
        /* @__PURE__ */ jsx("br", {}),
        "• lf search — Search for LF tags"
      ] })
    ] }),
    commandHistory.length > 0 && /* @__PURE__ */ jsxs("div", { className: "card", style: { marginTop: "var(--space-4)" }, children: [
      /* @__PURE__ */ jsx("h3", { className: "card-title", children: "Recent Commands" }),
      /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: "var(--space-2)" }, children: commandHistory.slice(0, 10).map((cmd, idx) => /* @__PURE__ */ jsxs(
        "button",
        {
          onClick: () => {
            if (inputRef.current) {
              inputRef.current.value = cmd;
              inputRef.current.focus();
            }
          },
          className: "btn btn-secondary",
          style: {
            justifyContent: "flex-start",
            fontFamily: "var(--font-mono)",
            fontSize: "0.875rem",
            textAlign: "left"
          },
          children: [
            /* @__PURE__ */ jsx("span", { style: { color: "var(--color-text-muted)" }, children: "▸" }),
            /* @__PURE__ */ jsx("span", { children: cmd })
          ]
        },
        idx
      )) })
    ] })
  ] });
}
const route1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  action: action$2,
  default: Commands
}, Symbol.toStringTag, { value: "Module" }));
function ConnectDialog({ network, onClose, isSubmitting }) {
  const [password, setPassword] = useState("");
  const [showPassword, setShowPassword] = useState(false);
  const [hidden, setHidden] = useState(false);
  const [customSSID, setCustomSSID] = useState("");
  if (!network && !hidden) return null;
  const ssid = hidden ? customSSID : (network == null ? void 0 : network.ssid) || "";
  const needsPassword = hidden || ((network == null ? void 0 : network.encrypted) ?? false);
  return /* @__PURE__ */ jsx(
    "div",
    {
      style: {
        position: "fixed",
        top: 0,
        left: 0,
        right: 0,
        bottom: 0,
        background: "rgba(10, 14, 26, 0.9)",
        backdropFilter: "blur(8px)",
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        zIndex: 200,
        padding: "var(--space-4)"
      },
      onClick: onClose,
      children: /* @__PURE__ */ jsxs(
        "div",
        {
          className: "card",
          style: {
            maxWidth: "500px",
            width: "100%",
            margin: 0,
            animation: "toast-in 250ms ease"
          },
          onClick: (e) => e.stopPropagation(),
          children: [
            /* @__PURE__ */ jsxs("h3", { className: "card-title", style: { marginBottom: "var(--space-4)" }, children: [
              /* @__PURE__ */ jsx("span", { style: { color: "var(--color-primary)" }, children: "📡" }),
              " ",
              "Connect to WiFi"
            ] }),
            /* @__PURE__ */ jsxs(Form, { method: "post", children: [
              /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "connect_network" }),
              !hidden ? /* @__PURE__ */ jsxs(Fragment, { children: [
                /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
                  /* @__PURE__ */ jsx("label", { className: "label", children: "Network" }),
                  /* @__PURE__ */ jsx(
                    "div",
                    {
                      style: {
                        padding: "var(--space-3)",
                        background: "var(--color-bg)",
                        border: "1px solid var(--color-border)",
                        borderRadius: "var(--radius)",
                        display: "flex",
                        alignItems: "center",
                        justifyContent: "space-between"
                      },
                      children: /* @__PURE__ */ jsxs("div", { children: [
                        /* @__PURE__ */ jsx("div", { style: { fontWeight: 600 }, children: network == null ? void 0 : network.ssid }),
                        /* @__PURE__ */ jsxs("div", { style: { fontSize: "0.75rem", color: "var(--color-text-muted)" }, children: [
                          (network == null ? void 0 : network.encrypted) ? "🔒 Secured" : "Unsecured",
                          " • ",
                          network == null ? void 0 : network.signal_strength,
                          " dBm"
                        ] })
                      ] })
                    }
                  ),
                  /* @__PURE__ */ jsx("input", { type: "hidden", name: "ssid", value: (network == null ? void 0 : network.ssid) || "" })
                ] }),
                /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: "var(--space-4)" }, children: /* @__PURE__ */ jsx(
                  "button",
                  {
                    type: "button",
                    className: "btn btn-secondary",
                    style: { fontSize: "0.75rem", padding: "var(--space-2) var(--space-3)" },
                    onClick: () => setHidden(true),
                    children: "Connect to hidden network instead"
                  }
                ) })
              ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
                /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
                  /* @__PURE__ */ jsx("label", { htmlFor: "ssid", className: "label", children: "Network Name (SSID)" }),
                  /* @__PURE__ */ jsx(
                    "input",
                    {
                      type: "text",
                      id: "ssid",
                      name: "ssid",
                      className: "input",
                      placeholder: "Enter network name",
                      value: customSSID,
                      onChange: (e) => setCustomSSID(e.target.value),
                      required: true,
                      autoFocus: true
                    }
                  )
                ] }),
                /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: "var(--space-4)" }, children: /* @__PURE__ */ jsx(
                  "button",
                  {
                    type: "button",
                    className: "btn btn-secondary",
                    style: { fontSize: "0.75rem", padding: "var(--space-2) var(--space-3)" },
                    onClick: () => setHidden(false),
                    children: "← Back to scanned networks"
                  }
                ) })
              ] }),
              needsPassword && /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
                /* @__PURE__ */ jsx("label", { htmlFor: "password", className: "label", children: "Password" }),
                /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
                  /* @__PURE__ */ jsx(
                    "input",
                    {
                      type: showPassword ? "text" : "password",
                      id: "password",
                      name: "password",
                      className: "input",
                      placeholder: "Enter network password",
                      value: password,
                      onChange: (e) => setPassword(e.target.value),
                      required: needsPassword,
                      autoComplete: "off",
                      style: { paddingRight: "3rem" }
                    }
                  ),
                  /* @__PURE__ */ jsx(
                    "button",
                    {
                      type: "button",
                      onClick: () => setShowPassword(!showPassword),
                      style: {
                        position: "absolute",
                        right: "var(--space-3)",
                        top: "50%",
                        transform: "translateY(-50%)",
                        background: "transparent",
                        border: "none",
                        color: "var(--color-text-secondary)",
                        cursor: "pointer",
                        fontSize: "1.25rem"
                      },
                      "aria-label": showPassword ? "Hide password" : "Show password",
                      children: showPassword ? "👁" : "👁‍🗨"
                    }
                  )
                ] })
              ] }),
              /* @__PURE__ */ jsx("input", { type: "hidden", name: "hidden", value: hidden ? "true" : "false" }),
              /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "var(--space-2)", marginTop: "var(--space-6)" }, children: [
                /* @__PURE__ */ jsx(
                  "button",
                  {
                    type: "button",
                    className: "btn btn-secondary",
                    style: { flex: 1 },
                    onClick: onClose,
                    disabled: isSubmitting,
                    children: "Cancel"
                  }
                ),
                /* @__PURE__ */ jsx(
                  "button",
                  {
                    type: "submit",
                    className: "btn btn-primary",
                    style: { flex: 1 },
                    disabled: isSubmitting || (!ssid || needsPassword && !password),
                    children: isSubmitting ? /* @__PURE__ */ jsxs(Fragment, { children: [
                      /* @__PURE__ */ jsx("span", { className: "spinner" }),
                      /* @__PURE__ */ jsx("span", { children: "Connecting..." })
                    ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
                      /* @__PURE__ */ jsx("span", { children: "✓" }),
                      /* @__PURE__ */ jsx("span", { children: "Connect" })
                    ] })
                  }
                )
              ] })
            ] }),
            needsPassword && /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-4)", textAlign: "center" }, children: "Your password will be securely stored" })
          ]
        }
      )
    }
  );
}
async function loader$3() {
  try {
    const [configRes, wifiStatusRes, savedNetworksRes] = await Promise.all([
      fetch("http://localhost:8000/api/system/config"),
      fetch("http://localhost:8000/api/wifi/status"),
      fetch("http://localhost:8000/api/wifi/saved")
    ]);
    const config = await configRes.json();
    const wifiStatus = await wifiStatusRes.json();
    const savedNetworksData = await savedNetworksRes.json();
    return json({ config, wifiStatus, savedNetworks: savedNetworksData.networks || [] });
  } catch (error) {
    return json({
      config: {
        pm3_device: "/dev/ttyACM0",
        session_timeout: 300,
        wifi_mode: "auto",
        ble_enabled: true,
        auth_enabled: false,
        https_enabled: false
      },
      wifiStatus: {
        mode: "auto",
        interfaces: [],
        supports_dual: false,
        current_ssid: null,
        current_ip: null,
        ap_ssid: "raspi-webgui",
        ap_ip: "10.3.141.1"
      },
      savedNetworks: []
    });
  }
}
async function action$1({ request }) {
  const formData = await request.formData();
  const action2 = formData.get("_action");
  if (action2 === "restart") {
    try {
      await fetch("http://localhost:8000/api/system/restart", { method: "POST" });
      return json({ success: true, message: "System restart initiated" });
    } catch (error) {
      return json({ success: false, error: "Failed to restart system" });
    }
  }
  if (action2 === "shutdown") {
    try {
      await fetch("http://localhost:8000/api/system/shutdown", { method: "POST" });
      return json({ success: true, message: "System shutdown initiated" });
    } catch (error) {
      return json({ success: false, error: "Failed to shutdown system" });
    }
  }
  if (action2 === "set_wifi_mode") {
    const mode2 = formData.get("mode");
    try {
      const response = await fetch("http://localhost:8000/api/wifi/mode", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ mode: mode2 })
      });
      const result = await response.json();
      return json({ success: true, message: `WiFi mode set to ${mode2}` });
    } catch (error) {
      return json({ success: false, error: "Failed to set WiFi mode" });
    }
  }
  if (action2 === "scan_networks") {
    try {
      const response = await fetch("http://localhost:8000/api/wifi/scan");
      const networks = await response.json();
      return json({ success: true, networks, message: `Found ${networks.length} networks` });
    } catch (error) {
      return json({ success: false, error: "Failed to scan networks" });
    }
  }
  if (action2 === "connect_network") {
    const ssid = formData.get("ssid");
    const password = formData.get("password");
    const hidden = formData.get("hidden") === "true";
    try {
      const response = await fetch("http://localhost:8000/api/wifi/connect", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ ssid, password: password || null, hidden })
      });
      const result = await response.json();
      if (result.success) {
        return json({ success: true, message: `Connected to ${ssid}` });
      } else {
        return json({ success: false, error: "Failed to connect" });
      }
    } catch (error) {
      return json({ success: false, error: "Failed to connect to network" });
    }
  }
  if (action2 === "forget_network") {
    const ssid = formData.get("ssid");
    try {
      const response = await fetch(`http://localhost:8000/api/wifi/saved/${encodeURIComponent(ssid)}`, {
        method: "DELETE"
      });
      const result = await response.json();
      if (result.success) {
        return json({ success: true, message: `Forgot network ${ssid}` });
      } else {
        return json({ success: false, error: "Failed to forget network" });
      }
    } catch (error) {
      return json({ success: false, error: "Failed to forget network" });
    }
  }
  return json({ success: false, error: "Unknown action" });
}
function Settings() {
  const { config, wifiStatus, savedNetworks } = useLoaderData();
  const actionData = useActionData();
  const navigation = useNavigation();
  const [activeSection, setActiveSection] = useState("general");
  const [scannedNetworks, setScannedNetworks] = useState([]);
  const [selectedNetwork, setSelectedNetwork] = useState(null);
  const [showConnectDialog, setShowConnectDialog] = useState(false);
  const isSubmitting = navigation.state === "submitting";
  useEffect(() => {
    if (actionData && "networks" in actionData) {
      setScannedNetworks(actionData.networks);
    }
  }, [actionData]);
  useEffect(() => {
    if (actionData && actionData.success && showConnectDialog) {
      setShowConnectDialog(false);
      setSelectedNetwork(null);
    }
  }, [actionData, showConnectDialog]);
  const handleNetworkClick = (network) => {
    setSelectedNetwork(network);
    setShowConnectDialog(true);
  };
  const handleConnectHidden = () => {
    setSelectedNetwork(null);
    setShowConnectDialog(true);
  };
  const sections = [
    { id: "general", label: "General", icon: "⚙" },
    { id: "wifi", label: "Wi-Fi", icon: "📡" },
    { id: "advanced", label: "Advanced", icon: "◈" },
    { id: "system", label: "System", icon: "⚡" }
  ];
  const getSignalIcon = (strength) => {
    if (strength >= -50) return "▂▃▄▅▆";
    if (strength >= -60) return "▂▃▄▅";
    if (strength >= -70) return "▂▃▄";
    if (strength >= -80) return "▂▃";
    return "▂";
  };
  return /* @__PURE__ */ jsxs("div", { className: "container", children: [
    /* @__PURE__ */ jsxs("h1", { style: { marginBottom: "var(--space-6)" }, children: [
      /* @__PURE__ */ jsx("span", { style: { color: "var(--color-secondary)" }, children: "⚙" }),
      " Settings"
    ] }),
    actionData && "message" in actionData && /* @__PURE__ */ jsx(
      "div",
      {
        className: "card",
        style: {
          marginBottom: "var(--space-4)",
          borderColor: actionData.success ? "var(--color-success)" : "var(--color-error)"
        },
        children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-3)" }, children: [
          /* @__PURE__ */ jsx("span", { style: { fontSize: "1.5rem" }, children: actionData.success ? "✓" : "✗" }),
          /* @__PURE__ */ jsx("span", { children: actionData.message || actionData.error })
        ] })
      }
    ),
    /* @__PURE__ */ jsx("div", { className: "card", style: { marginBottom: "var(--space-4)", padding: "var(--space-2)" }, children: /* @__PURE__ */ jsx("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(100px, 1fr))", gap: "var(--space-2)" }, children: sections.map((section) => /* @__PURE__ */ jsxs(
      "button",
      {
        onClick: () => setActiveSection(section.id),
        className: `btn ${activeSection === section.id ? "btn-primary" : "btn-secondary"}`,
        style: { fontSize: "0.75rem" },
        children: [
          /* @__PURE__ */ jsx("span", { children: section.icon }),
          /* @__PURE__ */ jsx("span", { children: section.label })
        ]
      },
      section.id
    )) }) }),
    activeSection === "general" && /* @__PURE__ */ jsxs("div", { className: "card", children: [
      /* @__PURE__ */ jsx("h3", { className: "card-title", children: "General Settings" }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "Session Timeout" }),
        /* @__PURE__ */ jsx(
          "input",
          {
            type: "number",
            className: "input",
            defaultValue: config.session_timeout,
            disabled: true
          }
        ),
        /* @__PURE__ */ jsxs("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: [
          "Idle session timeout in seconds (currently: ",
          Math.floor(config.session_timeout / 60),
          " minutes)"
        ] })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "Authentication" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-3)" }, children: [
          /* @__PURE__ */ jsx("span", { className: `badge ${config.auth_enabled ? "badge-success" : "badge-info"}`, children: config.auth_enabled ? "Enabled" : "Disabled" }),
          /* @__PURE__ */ jsx("button", { className: "btn btn-secondary", disabled: true, children: "Configure" })
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: "Require password to access the web interface" })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "HTTPS" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-3)" }, children: [
          /* @__PURE__ */ jsx("span", { className: `badge ${config.https_enabled ? "badge-success" : "badge-info"}`, children: config.https_enabled ? "Enabled" : "Disabled" }),
          /* @__PURE__ */ jsx("button", { className: "btn btn-secondary", disabled: true, children: "Configure" })
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: "Use self-signed certificate for secure connections" })
      ] })
    ] }),
    activeSection === "wifi" && /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "var(--space-4)" }, children: [
      /* @__PURE__ */ jsxs("div", { className: "card", children: [
        /* @__PURE__ */ jsx("h3", { className: "card-title", children: "Current Status" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "var(--space-3)" }, children: [
          /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
            /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "Mode" }),
            /* @__PURE__ */ jsx("span", { className: "badge badge-info", style: { textTransform: "uppercase" }, children: wifiStatus.mode })
          ] }),
          wifiStatus.current_ssid && /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
              /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "Connected to" }),
              /* @__PURE__ */ jsx("span", { className: "text-primary", children: wifiStatus.current_ssid })
            ] }),
            /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
              /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "IP Address" }),
              /* @__PURE__ */ jsx("span", { className: "text-primary", style: { fontFamily: "var(--font-mono)" }, children: wifiStatus.current_ip })
            ] })
          ] }),
          wifiStatus.ap_ssid && /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
              /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "AP SSID" }),
              /* @__PURE__ */ jsx("span", { className: "text-primary", children: wifiStatus.ap_ssid })
            ] }),
            /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
              /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "AP IP" }),
              /* @__PURE__ */ jsx("span", { className: "text-primary", style: { fontFamily: "var(--font-mono)" }, children: wifiStatus.ap_ip })
            ] })
          ] }),
          /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
            /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "Interfaces" }),
            /* @__PURE__ */ jsx("span", { className: "text-primary", children: wifiStatus.interfaces.length })
          ] }),
          /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
            /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "Dual Mode Support" }),
            /* @__PURE__ */ jsx("span", { className: `badge ${wifiStatus.supports_dual ? "badge-success" : "badge-info"}`, children: wifiStatus.supports_dual ? "Available" : "Not Available" })
          ] })
        ] })
      ] }),
      wifiStatus.interfaces.length > 0 && /* @__PURE__ */ jsxs("div", { className: "card", children: [
        /* @__PURE__ */ jsx("h3", { className: "card-title", children: "Network Interfaces" }),
        wifiStatus.interfaces.map((iface) => /* @__PURE__ */ jsxs(
          "div",
          {
            style: {
              marginBottom: "var(--space-3)",
              padding: "var(--space-3)",
              border: "1px solid var(--color-border)",
              borderRadius: "var(--radius)"
            },
            children: [
              /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "var(--space-2)" }, children: [
                /* @__PURE__ */ jsxs("span", { style: { fontFamily: "var(--font-mono)", fontWeight: 600 }, children: [
                  iface.name,
                  " ",
                  iface.is_usb && /* @__PURE__ */ jsx("span", { className: "badge badge-info", children: "USB" })
                ] }),
                /* @__PURE__ */ jsx("span", { className: `badge ${iface.is_up ? "badge-success" : "badge-error"}`, children: iface.is_up ? "UP" : "DOWN" })
              ] }),
              /* @__PURE__ */ jsxs("div", { style: { fontSize: "0.875rem", color: "var(--color-text-secondary)" }, children: [
                /* @__PURE__ */ jsxs("div", { children: [
                  "MAC: ",
                  iface.mac
                ] }),
                iface.ip_address && /* @__PURE__ */ jsxs("div", { children: [
                  "IP: ",
                  iface.ip_address
                ] }),
                iface.ssid && /* @__PURE__ */ jsxs("div", { children: [
                  "SSID: ",
                  iface.ssid
                ] })
              ] })
            ]
          },
          iface.name
        ))
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "card", children: [
        /* @__PURE__ */ jsx("h3", { className: "card-title", children: "WiFi Mode" }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.875rem", marginBottom: "var(--space-4)" }, children: "Select how the Pi should handle WiFi connections" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "var(--space-2)" }, children: [
          /* @__PURE__ */ jsxs(Form, { method: "post", children: [
            /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "set_wifi_mode" }),
            /* @__PURE__ */ jsx("input", { type: "hidden", name: "mode", value: "ap" }),
            /* @__PURE__ */ jsxs("button", { type: "submit", className: "btn btn-secondary", style: { width: "100%", justifyContent: "flex-start" }, children: [
              /* @__PURE__ */ jsx("span", { children: "📡" }),
              /* @__PURE__ */ jsxs("div", { style: { textAlign: "left", flex: 1 }, children: [
                /* @__PURE__ */ jsx("div", { children: "Access Point (AP)" }),
                /* @__PURE__ */ jsx("div", { style: { fontSize: "0.75rem", opacity: 0.7 }, children: "Host your own network" })
              ] })
            ] })
          ] }),
          /* @__PURE__ */ jsxs(Form, { method: "post", children: [
            /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "set_wifi_mode" }),
            /* @__PURE__ */ jsx("input", { type: "hidden", name: "mode", value: "client" }),
            /* @__PURE__ */ jsxs("button", { type: "submit", className: "btn btn-secondary", style: { width: "100%", justifyContent: "flex-start" }, children: [
              /* @__PURE__ */ jsx("span", { children: "🌐" }),
              /* @__PURE__ */ jsxs("div", { style: { textAlign: "left", flex: 1 }, children: [
                /* @__PURE__ */ jsx("div", { children: "Client Mode" }),
                /* @__PURE__ */ jsx("div", { style: { fontSize: "0.75rem", opacity: 0.7 }, children: "Connect to existing WiFi" })
              ] })
            ] })
          ] }),
          wifiStatus.supports_dual && /* @__PURE__ */ jsxs(Form, { method: "post", children: [
            /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "set_wifi_mode" }),
            /* @__PURE__ */ jsx("input", { type: "hidden", name: "mode", value: "dual" }),
            /* @__PURE__ */ jsxs("button", { type: "submit", className: "btn btn-secondary", style: { width: "100%", justifyContent: "flex-start" }, children: [
              /* @__PURE__ */ jsx("span", { children: "🔀" }),
              /* @__PURE__ */ jsxs("div", { style: { textAlign: "left", flex: 1 }, children: [
                /* @__PURE__ */ jsx("div", { children: "Dual Mode" }),
                /* @__PURE__ */ jsx("div", { style: { fontSize: "0.75rem", opacity: 0.7 }, children: "AP + Client simultaneously" })
              ] })
            ] })
          ] }),
          /* @__PURE__ */ jsxs(Form, { method: "post", children: [
            /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "set_wifi_mode" }),
            /* @__PURE__ */ jsx("input", { type: "hidden", name: "mode", value: "auto" }),
            /* @__PURE__ */ jsxs("button", { type: "submit", className: "btn btn-secondary", style: { width: "100%", justifyContent: "flex-start" }, children: [
              /* @__PURE__ */ jsx("span", { children: "⚙" }),
              /* @__PURE__ */ jsxs("div", { style: { textAlign: "left", flex: 1 }, children: [
                /* @__PURE__ */ jsx("div", { children: "Auto Mode" }),
                /* @__PURE__ */ jsx("div", { style: { fontSize: "0.75rem", opacity: 0.7 }, children: "Automatically choose best mode" })
              ] })
            ] })
          ] })
        ] })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "card", children: [
        /* @__PURE__ */ jsx("h3", { className: "card-title", children: "Available Networks" }),
        /* @__PURE__ */ jsxs(Form, { method: "post", children: [
          /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "scan_networks" }),
          /* @__PURE__ */ jsx("button", { type: "submit", className: "btn btn-primary", disabled: isSubmitting, children: isSubmitting ? /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx("span", { className: "spinner" }),
            /* @__PURE__ */ jsx("span", { children: "Scanning..." })
          ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx("span", { children: "🔍" }),
            /* @__PURE__ */ jsx("span", { children: "Scan for Networks" })
          ] }) })
        ] }),
        scannedNetworks.length > 0 && /* @__PURE__ */ jsx("div", { style: { marginTop: "var(--space-4)" }, children: scannedNetworks.map((network, idx) => /* @__PURE__ */ jsx(
          "div",
          {
            style: {
              padding: "var(--space-3)",
              border: "1px solid var(--color-border)",
              borderRadius: "var(--radius)",
              marginBottom: "var(--space-2)",
              cursor: "pointer",
              transition: "all var(--transition-fast)"
            },
            onClick: () => handleNetworkClick(network),
            onMouseEnter: (e) => {
              e.currentTarget.style.borderColor = "var(--color-primary)";
              e.currentTarget.style.background = "var(--color-surface-hover)";
            },
            onMouseLeave: (e) => {
              e.currentTarget.style.borderColor = "var(--color-border)";
              e.currentTarget.style.background = "transparent";
            },
            children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
              /* @__PURE__ */ jsxs("div", { children: [
                /* @__PURE__ */ jsxs("div", { style: { fontWeight: 600 }, children: [
                  network.ssid,
                  network.encrypted && /* @__PURE__ */ jsx("span", { style: { marginLeft: "var(--space-2)" }, children: "🔒" })
                ] }),
                /* @__PURE__ */ jsxs("div", { style: { fontSize: "0.75rem", color: "var(--color-text-muted)" }, children: [
                  network.frequency,
                  " MHz • ",
                  network.bssid
                ] })
              ] }),
              /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-2)" }, children: [
                /* @__PURE__ */ jsx("span", { style: { fontSize: "0.75rem", fontFamily: "var(--font-mono)" }, children: getSignalIcon(network.signal_strength) }),
                /* @__PURE__ */ jsxs("span", { style: { fontSize: "0.75rem", color: "var(--color-text-muted)" }, children: [
                  network.signal_strength,
                  " dBm"
                ] })
              ] })
            ] })
          },
          `${network.bssid}-${idx}`
        )) }),
        /* @__PURE__ */ jsx("div", { style: { marginTop: "var(--space-4)", textAlign: "center" }, children: /* @__PURE__ */ jsxs(
          "button",
          {
            type: "button",
            className: "btn btn-secondary",
            onClick: handleConnectHidden,
            children: [
              /* @__PURE__ */ jsx("span", { children: "🔍" }),
              /* @__PURE__ */ jsx("span", { children: "Connect to Hidden Network" })
            ]
          }
        ) }),
        /* @__PURE__ */ jsxs("p", { className: "text-muted", style: { fontSize: "0.875rem", marginTop: "var(--space-4)" }, children: [
          /* @__PURE__ */ jsx("strong", { children: "Note:" }),
          " Legacy WiFi management via RaspAP is still available at",
          " ",
          /* @__PURE__ */ jsx("a", { href: "http://10.3.141.1", target: "_blank", rel: "noopener noreferrer", children: "http://10.3.141.1" })
        ] })
      ] }),
      savedNetworks.length > 0 && /* @__PURE__ */ jsxs("div", { className: "card", children: [
        /* @__PURE__ */ jsx("h3", { className: "card-title", children: "Saved Networks" }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.875rem", marginBottom: "var(--space-4)" }, children: "Networks saved for auto-connect" }),
        savedNetworks.map((network) => /* @__PURE__ */ jsxs(
          "div",
          {
            style: {
              padding: "var(--space-3)",
              border: "1px solid var(--color-border)",
              borderRadius: "var(--radius)",
              marginBottom: "var(--space-2)",
              display: "flex",
              justifyContent: "space-between",
              alignItems: "center"
            },
            children: [
              /* @__PURE__ */ jsxs("div", { children: [
                /* @__PURE__ */ jsx("div", { style: { fontWeight: 600 }, children: network.ssid }),
                /* @__PURE__ */ jsx("div", { style: { fontSize: "0.75rem", color: "var(--color-text-muted)" }, children: network.enabled ? "Enabled" : "Disabled" })
              ] }),
              /* @__PURE__ */ jsxs(Form, { method: "post", children: [
                /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "forget_network" }),
                /* @__PURE__ */ jsx("input", { type: "hidden", name: "ssid", value: network.ssid }),
                /* @__PURE__ */ jsxs(
                  "button",
                  {
                    type: "submit",
                    className: "btn btn-danger",
                    style: { fontSize: "0.75rem", padding: "var(--space-2) var(--space-3)" },
                    onClick: (e) => {
                      if (!confirm(`Forget network "${network.ssid}"?`)) {
                        e.preventDefault();
                      }
                    },
                    children: [
                      /* @__PURE__ */ jsx("span", { children: "🗑" }),
                      /* @__PURE__ */ jsx("span", { children: "Forget" })
                    ]
                  }
                )
              ] })
            ]
          },
          network.id
        ))
      ] })
    ] }),
    showConnectDialog && /* @__PURE__ */ jsx(
      ConnectDialog,
      {
        network: selectedNetwork,
        onClose: () => {
          setShowConnectDialog(false);
          setSelectedNetwork(null);
        },
        isSubmitting
      }
    ),
    activeSection === "advanced" && /* @__PURE__ */ jsxs("div", { className: "card", children: [
      /* @__PURE__ */ jsx("h3", { className: "card-title", children: "Advanced Settings" }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "PM3 Device Path" }),
        /* @__PURE__ */ jsx(
          "input",
          {
            type: "text",
            className: "input",
            defaultValue: config.pm3_device,
            disabled: true,
            style: { fontFamily: "var(--font-mono)" }
          }
        ),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: "Serial device path for Proxmark3" })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "BLE Notifications" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-3)" }, children: [
          /* @__PURE__ */ jsx("span", { className: `badge ${config.ble_enabled ? "badge-success" : "badge-info"}`, children: config.ble_enabled ? "Enabled" : "Disabled" }),
          /* @__PURE__ */ jsx("button", { className: "btn btn-secondary", disabled: true, children: "Configure" })
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: "Send notifications via Bluetooth LE" })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "Automatic Updates" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "var(--space-2)" }, children: [
          /* @__PURE__ */ jsx("button", { className: "btn btn-secondary", disabled: true, children: "Check for Updates" }),
          /* @__PURE__ */ jsx("button", { className: "btn btn-secondary", disabled: true, children: "Auto-Update Settings" })
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: "Check GitHub for new Dangerous Pi releases" })
      ] })
    ] }),
    activeSection === "system" && /* @__PURE__ */ jsxs("div", { className: "card", children: [
      /* @__PURE__ */ jsx("h3", { className: "card-title", children: "System Actions" }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "Restart Backend" }),
        /* @__PURE__ */ jsxs(Form, { method: "post", children: [
          /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "restart" }),
          /* @__PURE__ */ jsxs(
            "button",
            {
              type: "submit",
              className: "btn btn-secondary",
              disabled: isSubmitting,
              children: [
                /* @__PURE__ */ jsx("span", { children: "🔄" }),
                /* @__PURE__ */ jsx("span", { children: "Restart Backend Service" })
              ]
            }
          )
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: "Restart the Dangerous Pi backend service (frontend will remain available)" })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "Shutdown System" }),
        /* @__PURE__ */ jsxs(Form, { method: "post", children: [
          /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "shutdown" }),
          /* @__PURE__ */ jsxs(
            "button",
            {
              type: "submit",
              className: "btn btn-danger",
              disabled: isSubmitting,
              onClick: (e) => {
                if (!confirm("Are you sure you want to shutdown the system?")) {
                  e.preventDefault();
                }
              },
              children: [
                /* @__PURE__ */ jsx("span", { children: "⏻" }),
                /* @__PURE__ */ jsx("span", { children: "Shutdown Pi" })
              ]
            }
          )
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: "Safely shutdown the Raspberry Pi" })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "form-group", children: [
        /* @__PURE__ */ jsx("label", { className: "label", children: "Backup & Restore" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "var(--space-2)", flexWrap: "wrap" }, children: [
          /* @__PURE__ */ jsxs("button", { className: "btn btn-secondary", disabled: true, children: [
            /* @__PURE__ */ jsx("span", { children: "💾" }),
            /* @__PURE__ */ jsx("span", { children: "Create Backup" })
          ] }),
          /* @__PURE__ */ jsxs("button", { className: "btn btn-secondary", disabled: true, children: [
            /* @__PURE__ */ jsx("span", { children: "📥" }),
            /* @__PURE__ */ jsx("span", { children: "Restore Backup" })
          ] })
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.75rem", marginTop: "var(--space-2)" }, children: "Backup and restore system configuration" })
      ] })
    ] })
  ] });
}
const route2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  action: action$1,
  default: Settings,
  loader: loader$3
}, Symbol.toStringTag, { value: "Module" }));
async function loader$2({ request }) {
  try {
    const [updateRes, progressRes] = await Promise.all([
      fetch("http://localhost:8000/api/updates/check"),
      fetch("http://localhost:8000/api/updates/progress")
    ]);
    const updateInfo = await updateRes.json();
    const progressInfo = await progressRes.json();
    return json({ updateInfo, progressInfo });
  } catch (error) {
    console.error("Error loading update info:", error);
    return json({
      updateInfo: null,
      progressInfo: null,
      error: "Failed to load update information"
    });
  }
}
async function action({ request }) {
  const formData = await request.formData();
  const action2 = formData.get("_action");
  try {
    if (action2 === "check_updates") {
      const response = await fetch("http://localhost:8000/api/updates/check", {
        method: "GET"
      });
      const data = await response.json();
      return json({ success: true, message: "Update check complete", data });
    }
    if (action2 === "download_update") {
      const response = await fetch("http://localhost:8000/api/updates/download", {
        method: "POST"
      });
      const data = await response.json();
      return json({ success: true, message: "Download started", data });
    }
    if (action2 === "install_update") {
      const response = await fetch("http://localhost:8000/api/updates/install", {
        method: "POST"
      });
      const data = await response.json();
      return json({ success: true, message: "Installation started", data });
    }
    return json({ success: false, message: "Unknown action" });
  } catch (error) {
    return json({ success: false, message: error.message || "Action failed" });
  }
}
function Updates() {
  const { updateInfo, progressInfo, error } = useLoaderData();
  const actionData = useActionData();
  const navigation = useNavigation();
  const isSubmitting = navigation.state === "submitting";
  const [progress, setProgress] = useState(progressInfo);
  useEffect(() => {
    if (!progress || progress.status !== "downloading" && progress.status !== "installing") {
      return;
    }
    const interval = setInterval(async () => {
      try {
        const response = await fetch("http://localhost:8000/api/updates/progress");
        const data = await response.json();
        setProgress(data);
      } catch (error2) {
        console.error("Error polling progress:", error2);
      }
    }, 1e3);
    return () => clearInterval(interval);
  }, [progress == null ? void 0 : progress.status]);
  const getStatusBadge = (status) => {
    const badges = {
      idle: { text: "Idle", color: "var(--color-text-muted)" },
      checking: { text: "Checking...", color: "var(--color-primary)" },
      available: { text: "Update Available", color: "var(--color-accent)" },
      downloading: { text: "Downloading", color: "var(--color-primary)" },
      installing: { text: "Installing", color: "var(--color-warning)" },
      complete: { text: "Complete", color: "var(--color-success)" },
      failed: { text: "Failed", color: "var(--color-danger)" }
    };
    const badge = badges[status] || badges.idle;
    return /* @__PURE__ */ jsx(
      "span",
      {
        className: "badge",
        style: {
          backgroundColor: `${badge.color}20`,
          color: badge.color,
          border: `1px solid ${badge.color}40`
        },
        children: badge.text
      }
    );
  };
  const formatBytes = (bytes) => {
    if (bytes === 0) return "0 Bytes";
    const k = 1024;
    const sizes = ["Bytes", "KB", "MB", "GB"];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return Math.round(bytes / Math.pow(k, i) * 100) / 100 + " " + sizes[i];
  };
  const formatDate = (dateString) => {
    const date = new Date(dateString);
    return date.toLocaleDateString("en-US", {
      year: "numeric",
      month: "long",
      day: "numeric"
    });
  };
  if (error) {
    return /* @__PURE__ */ jsxs("div", { className: "container", children: [
      /* @__PURE__ */ jsx("h1", { children: "⚠️ Error" }),
      /* @__PURE__ */ jsx("div", { className: "card", children: /* @__PURE__ */ jsx("p", { style: { color: "var(--color-danger)" }, children: error }) })
    ] });
  }
  return /* @__PURE__ */ jsxs("div", { className: "container", children: [
    /* @__PURE__ */ jsxs("div", { style: { marginBottom: "var(--space-6)" }, children: [
      /* @__PURE__ */ jsxs("h1", { style: { marginBottom: "var(--space-2)" }, children: [
        /* @__PURE__ */ jsx("span", { style: { color: "var(--color-primary)" }, children: "🔄" }),
        " System Updates"
      ] }),
      /* @__PURE__ */ jsx("p", { className: "text-muted", children: "Manage system updates from GitHub releases" })
    ] }),
    actionData && /* @__PURE__ */ jsx(
      "div",
      {
        className: "card",
        style: {
          marginBottom: "var(--space-6)",
          backgroundColor: actionData.success ? "var(--color-success-bg)" : "var(--color-danger-bg)",
          borderColor: actionData.success ? "var(--color-success)" : "var(--color-danger)"
        },
        children: /* @__PURE__ */ jsx("p", { style: { margin: 0 }, children: actionData.message })
      }
    ),
    /* @__PURE__ */ jsxs("div", { className: "card", style: { marginBottom: "var(--space-6)" }, children: [
      /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "var(--space-4)" }, children: [
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("h2", { className: "card-title", style: { marginBottom: "var(--space-2)" }, children: "Current Version" }),
          /* @__PURE__ */ jsxs("div", { style: { fontSize: "1.5rem", fontWeight: 700, color: "var(--color-primary)" }, children: [
            "v",
            (progressInfo == null ? void 0 : progressInfo.current_version) || (updateInfo == null ? void 0 : updateInfo.current_version) || "Unknown"
          ] })
        ] }),
        progress && getStatusBadge(progress.status)
      ] }),
      (progressInfo == null ? void 0 : progressInfo.last_check) && /* @__PURE__ */ jsxs("p", { className: "text-muted", style: { fontSize: "0.875rem", marginTop: "var(--space-2)" }, children: [
        "Last checked: ",
        new Date(progressInfo.last_check).toLocaleString()
      ] }),
      /* @__PURE__ */ jsxs(Form, { method: "post", style: { marginTop: "var(--space-4)" }, children: [
        /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "check_updates" }),
        /* @__PURE__ */ jsx(
          "button",
          {
            type: "submit",
            className: "btn btn-secondary",
            disabled: isSubmitting || (progress == null ? void 0 : progress.status) === "checking",
            children: isSubmitting || (progress == null ? void 0 : progress.status) === "checking" ? /* @__PURE__ */ jsxs(Fragment, { children: [
              /* @__PURE__ */ jsx("span", { className: "spinner" }),
              /* @__PURE__ */ jsx("span", { children: "Checking..." })
            ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
              /* @__PURE__ */ jsx("span", { children: "🔍" }),
              /* @__PURE__ */ jsx("span", { children: "Check for Updates" })
            ] })
          }
        )
      ] })
    ] }),
    (updateInfo == null ? void 0 : updateInfo.update_available) && /* @__PURE__ */ jsxs("div", { className: "card", style: { marginBottom: "var(--space-6)", borderColor: "var(--color-accent)" }, children: [
      /* @__PURE__ */ jsxs("h2", { className: "card-title", style: { marginBottom: "var(--space-4)" }, children: [
        /* @__PURE__ */ jsx("span", { style: { color: "var(--color-accent)" }, children: "✨" }),
        " Update Available"
      ] }),
      /* @__PURE__ */ jsxs("div", { style: { marginBottom: "var(--space-4)" }, children: [
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "var(--space-4)", marginBottom: "var(--space-3)" }, children: [
          /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("div", { className: "label", style: { fontSize: "0.75rem" }, children: "New Version" }),
            /* @__PURE__ */ jsxs("div", { style: { fontSize: "1.25rem", fontWeight: 700, color: "var(--color-accent)" }, children: [
              "v",
              updateInfo.latest_version
            ] })
          ] }),
          updateInfo.download_size && /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsx("div", { className: "label", style: { fontSize: "0.75rem" }, children: "Download Size" }),
            /* @__PURE__ */ jsx("div", { style: { fontSize: "1.25rem", fontWeight: 600 }, children: formatBytes(updateInfo.download_size) })
          ] })
        ] }),
        updateInfo.release_date && /* @__PURE__ */ jsxs("p", { className: "text-muted", style: { fontSize: "0.875rem" }, children: [
          "Released: ",
          formatDate(updateInfo.release_date)
        ] }),
        updateInfo.is_prerelease && /* @__PURE__ */ jsx(
          "div",
          {
            className: "badge",
            style: {
              backgroundColor: "var(--color-warning-bg)",
              color: "var(--color-warning)",
              marginTop: "var(--space-2)"
            },
            children: "Pre-release"
          }
        )
      ] }),
      updateInfo.changelog && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "var(--space-4)" }, children: [
        /* @__PURE__ */ jsx("div", { className: "label", style: { marginBottom: "var(--space-2)" }, children: "Release Notes" }),
        /* @__PURE__ */ jsx(
          "div",
          {
            style: {
              padding: "var(--space-3)",
              background: "var(--color-bg)",
              border: "1px solid var(--color-border)",
              borderRadius: "var(--radius)",
              maxHeight: "300px",
              overflowY: "auto",
              fontSize: "0.875rem",
              lineHeight: 1.6,
              whiteSpace: "pre-wrap"
            },
            children: updateInfo.changelog
          }
        )
      ] }),
      /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "var(--space-2)", flexWrap: "wrap" }, children: [
        (progress == null ? void 0 : progress.status) === "available" && /* @__PURE__ */ jsxs(Form, { method: "post", children: [
          /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "download_update" }),
          /* @__PURE__ */ jsx("button", { type: "submit", className: "btn btn-primary", disabled: isSubmitting, children: isSubmitting ? /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx("span", { className: "spinner" }),
            /* @__PURE__ */ jsx("span", { children: "Starting..." })
          ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx("span", { children: "⬇️" }),
            /* @__PURE__ */ jsx("span", { children: "Download Update" })
          ] }) })
        ] }),
        (progress == null ? void 0 : progress.status) === "downloading" && /* @__PURE__ */ jsx("div", { style: { flex: 1 }, children: /* @__PURE__ */ jsxs("div", { style: { marginBottom: "var(--space-2)" }, children: [
          /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", fontSize: "0.875rem" }, children: [
            /* @__PURE__ */ jsx("span", { children: "Downloading..." }),
            /* @__PURE__ */ jsxs("span", { children: [
              Math.round(progress.download_progress),
              "%"
            ] })
          ] }),
          /* @__PURE__ */ jsx(
            "div",
            {
              style: {
                width: "100%",
                height: "8px",
                background: "var(--color-border)",
                borderRadius: "var(--radius)",
                overflow: "hidden",
                marginTop: "var(--space-2)"
              },
              children: /* @__PURE__ */ jsx(
                "div",
                {
                  style: {
                    width: `${progress.download_progress}%`,
                    height: "100%",
                    background: "linear-gradient(90deg, var(--color-primary), var(--color-accent))",
                    transition: "width 0.3s ease"
                  }
                }
              )
            }
          )
        ] }) }),
        ((progress == null ? void 0 : progress.status) === "idle" || (progress == null ? void 0 : progress.download_progress) === 100) && updateInfo.update_available && /* @__PURE__ */ jsxs(Form, { method: "post", children: [
          /* @__PURE__ */ jsx("input", { type: "hidden", name: "_action", value: "install_update" }),
          /* @__PURE__ */ jsx("button", { type: "submit", className: "btn btn-accent", disabled: isSubmitting, children: isSubmitting ? /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx("span", { className: "spinner" }),
            /* @__PURE__ */ jsx("span", { children: "Installing..." })
          ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
            /* @__PURE__ */ jsx("span", { children: "⚡" }),
            /* @__PURE__ */ jsx("span", { children: "Install Update" })
          ] }) })
        ] }),
        (progress == null ? void 0 : progress.status) === "installing" && /* @__PURE__ */ jsxs("div", { className: "btn btn-accent", style: { cursor: "default" }, children: [
          /* @__PURE__ */ jsx("span", { className: "spinner" }),
          /* @__PURE__ */ jsx("span", { children: "Installing Update..." })
        ] }),
        (progress == null ? void 0 : progress.status) === "complete" && /* @__PURE__ */ jsx("div", { style: { flex: 1 }, children: /* @__PURE__ */ jsx(
          "div",
          {
            className: "card",
            style: {
              backgroundColor: "var(--color-success-bg)",
              borderColor: "var(--color-success)",
              padding: "var(--space-3)"
            },
            children: /* @__PURE__ */ jsx("p", { style: { margin: 0 }, children: "✅ Update installed successfully! Please restart the service for changes to take effect." })
          }
        ) })
      ] }),
      (progress == null ? void 0 : progress.error_message) && /* @__PURE__ */ jsx(
        "div",
        {
          className: "card",
          style: {
            marginTop: "var(--space-4)",
            backgroundColor: "var(--color-danger-bg)",
            borderColor: "var(--color-danger)",
            padding: "var(--space-3)"
          },
          children: /* @__PURE__ */ jsxs("p", { style: { margin: 0, color: "var(--color-danger)" }, children: [
            "❌ ",
            progress.error_message
          ] })
        }
      )
    ] }),
    updateInfo && !updateInfo.update_available && updateInfo.message && /* @__PURE__ */ jsx("div", { className: "card", children: /* @__PURE__ */ jsxs("p", { style: { margin: 0, textAlign: "center", color: "var(--color-text-muted)" }, children: [
      "✅ ",
      updateInfo.message
    ] }) })
  ] });
}
const route3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  action,
  default: Updates,
  loader: loader$2
}, Symbol.toStringTag, { value: "Module" }));
async function loader$1() {
  var _a, _b;
  try {
    const [healthRes, devicesRes, systemRes] = await Promise.all([
      fetch("http://localhost:8000/api/health"),
      fetch("http://localhost:8000/api/pm3/devices"),
      fetch("http://localhost:8000/api/system/info")
    ]);
    const health = await healthRes.json();
    const devicesData = await devicesRes.json();
    const rawSystemInfo = await systemRes.json();
    const devices = devicesData.devices || [];
    const systemInfo = {
      hostname: rawSystemInfo.hostname,
      cpu_temp: rawSystemInfo.cpu_temp,
      cpu_per_core: ((_a = rawSystemInfo.cpu) == null ? void 0 : _a.per_core) || [],
      load_average: ((_b = rawSystemInfo.cpu) == null ? void 0 : _b.load_average) || null,
      memory_used: rawSystemInfo.memory_used,
      memory_total: rawSystemInfo.memory_total,
      disk_used: rawSystemInfo.disk_used,
      disk_total: rawSystemInfo.disk_total
    };
    return json({ health, devices, systemInfo });
  } catch (error) {
    return json({
      health: { status: "unknown", version: "0.1.0" },
      devices: [],
      systemInfo: {
        hostname: "dangerous-pi",
        cpu_temp: null,
        cpu_per_core: [],
        load_average: null,
        memory_used: 0,
        memory_total: 0,
        disk_used: 0,
        disk_total: 0
      }
    });
  }
}
function Dashboard() {
  const loaderData = useLoaderData();
  const [eventMessage, setEventMessage] = useState(null);
  const [systemStats, setSystemStats] = useState(null);
  const [pm3Devices, setPm3Devices] = useState(null);
  const data = {
    ...loaderData,
    systemInfo: {
      ...loaderData.systemInfo,
      ...systemStats && {
        cpu_per_core: systemStats.cpu_per_core,
        load_average: systemStats.load_average,
        cpu_temp: systemStats.temperature ?? loaderData.systemInfo.cpu_temp
      }
    },
    devices: pm3Devices ?? loaderData.devices
  };
  useEffect(() => {
    const eventSource = new EventSource("/sse/events");
    eventSource.addEventListener("connected", (e) => {
      console.log("SSE connected:", e.data);
    });
    eventSource.addEventListener("pm3_status", (e) => {
      const eventData = JSON.parse(e.data);
      setEventMessage(`PM3: ${eventData.message}`);
      setTimeout(() => setEventMessage(null), 5e3);
    });
    eventSource.addEventListener("pm3_devices", (e) => {
      const eventData = JSON.parse(e.data);
      setPm3Devices(eventData.devices);
    });
    eventSource.addEventListener("system_stats", (e) => {
      const eventData = JSON.parse(e.data);
      setSystemStats(eventData);
    });
    eventSource.addEventListener("update_available", (e) => {
      const eventData = JSON.parse(e.data);
      setEventMessage(`Update available: ${eventData.version}`);
    });
    eventSource.onerror = () => {
      console.log("SSE connection error, will retry...");
    };
    return () => eventSource.close();
  }, []);
  const formatBytes = (bytes) => {
    if (bytes === 0) return "0 B";
    const k = 1024;
    const sizes = ["B", "KB", "MB", "GB"];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return `${(bytes / Math.pow(k, i)).toFixed(1)} ${sizes[i]}`;
  };
  const memoryPercent = data.systemInfo.memory_total > 0 ? (data.systemInfo.memory_used / data.systemInfo.memory_total * 100).toFixed(1) : "0";
  const diskPercent = data.systemInfo.disk_total > 0 ? (data.systemInfo.disk_used / data.systemInfo.disk_total * 100).toFixed(1) : "0";
  return /* @__PURE__ */ jsxs("div", { className: "container", children: [
    /* @__PURE__ */ jsxs("h1", { style: { marginBottom: "var(--space-6)" }, children: [
      /* @__PURE__ */ jsx("span", { style: { color: "var(--color-primary)" }, children: "▸" }),
      " Dashboard"
    ] }),
    eventMessage && /* @__PURE__ */ jsx("div", { className: "toast", children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-3)" }, children: [
      /* @__PURE__ */ jsx("span", { style: { fontSize: "1.5rem" }, children: "●" }),
      /* @__PURE__ */ jsx("span", { children: eventMessage })
    ] }) }),
    /* @__PURE__ */ jsxs("div", { className: "card-grid", style: { marginBottom: "var(--space-6)" }, children: [
      /* @__PURE__ */ jsxs("div", { className: "card", children: [
        /* @__PURE__ */ jsxs("h3", { className: "card-title", children: [
          /* @__PURE__ */ jsx("span", { style: { color: "var(--color-primary)" }, children: "◈" }),
          " System Status"
        ] }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "var(--space-3)" }, children: [
          /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
            /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "Backend" }),
            /* @__PURE__ */ jsxs("span", { className: `badge ${data.health.status === "healthy" ? "badge-success" : "badge-error"}`, children: [
              /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "●" }),
              data.health.status
            ] })
          ] }),
          /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
            /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "Hostname" }),
            /* @__PURE__ */ jsx("span", { className: "text-primary", children: data.systemInfo.hostname || "unknown" })
          ] }),
          data.systemInfo.cpu_temp && /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
            /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "CPU Temp" }),
            /* @__PURE__ */ jsxs("span", { className: data.systemInfo.cpu_temp > 70 ? "text-warning" : "text-primary", children: [
              data.systemInfo.cpu_temp.toFixed(1),
              "°C"
            ] })
          ] }),
          data.systemInfo.cpu_per_core && data.systemInfo.cpu_per_core.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
            /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "var(--space-2)" }, children: [
              /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "CPU Cores" }),
              data.systemInfo.load_average && /* @__PURE__ */ jsxs("span", { className: "text-muted", style: { fontSize: "0.75rem" }, children: [
                "Load: ",
                data.systemInfo.load_average.map((l) => l.toFixed(2)).join(" / ")
              ] })
            ] }),
            /* @__PURE__ */ jsx("div", { style: { display: "flex", gap: "var(--space-2)", flexWrap: "wrap" }, children: data.systemInfo.cpu_per_core.map((core) => /* @__PURE__ */ jsxs(
              "div",
              {
                className: "cpu-core-bar",
                style: {
                  flex: "1 1 auto",
                  minWidth: "50px",
                  textAlign: "center"
                },
                children: [
                  /* @__PURE__ */ jsx(
                    "div",
                    {
                      style: {
                        height: "4px",
                        background: "var(--color-border)",
                        borderRadius: "2px",
                        overflow: "hidden",
                        marginBottom: "var(--space-1)"
                      },
                      children: /* @__PURE__ */ jsx(
                        "div",
                        {
                          style: {
                            height: "100%",
                            width: `${Math.min(100, core.percent)}%`,
                            background: core.percent > 80 ? "var(--color-error)" : core.percent > 50 ? "var(--color-warning)" : "var(--color-accent)",
                            transition: "width 0.3s ease"
                          }
                        }
                      )
                    }
                  ),
                  /* @__PURE__ */ jsxs("span", { style: { fontSize: "0.7rem", fontFamily: "var(--font-mono)" }, children: [
                    "C",
                    core.core_id,
                    ": ",
                    core.percent.toFixed(0),
                    "%"
                  ] })
                ]
              },
              core.core_id
            )) })
          ] }),
          /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
            /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "Memory" }),
            /* @__PURE__ */ jsxs("span", { className: "text-primary", children: [
              formatBytes(data.systemInfo.memory_used),
              " / ",
              formatBytes(data.systemInfo.memory_total),
              " (",
              memoryPercent,
              "%)"
            ] })
          ] }),
          /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
            /* @__PURE__ */ jsx("span", { className: "text-secondary", children: "Disk" }),
            /* @__PURE__ */ jsxs("span", { className: "text-primary", children: [
              formatBytes(data.systemInfo.disk_used),
              " / ",
              formatBytes(data.systemInfo.disk_total),
              " (",
              diskPercent,
              "%)"
            ] })
          ] })
        ] })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "card", children: [
        /* @__PURE__ */ jsxs("h3", { className: "card-title", children: [
          /* @__PURE__ */ jsx("span", { style: { color: "var(--color-accent)" }, children: "▶" }),
          " Proxmark3 Devices (",
          data.devices.length,
          ")"
        ] }),
        data.devices.length === 0 ? /* @__PURE__ */ jsxs("div", { style: { textAlign: "center", padding: "var(--space-4)" }, children: [
          /* @__PURE__ */ jsx("div", { style: { fontSize: "2rem", marginBottom: "var(--space-2)", opacity: 0.5 }, children: "🔌" }),
          /* @__PURE__ */ jsx("p", { className: "text-secondary", style: { marginBottom: "var(--space-1)" }, children: "No devices detected" }),
          /* @__PURE__ */ jsx("p", { className: "text-muted", style: { fontSize: "0.875rem" }, children: "Connect a Proxmark3 via USB" })
        ] }) : /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: "var(--space-3)" }, children: data.devices.map((device) => {
          const isConnected = device.status === "connected";
          const isInUse = device.status === "in_use";
          const deviceName = device.friendly_name || device.device_path;
          return /* @__PURE__ */ jsxs(
            "div",
            {
              style: {
                padding: "var(--space-3)",
                background: "var(--color-bg)",
                borderRadius: "var(--radius)",
                border: "1px solid var(--color-border)"
              },
              children: [
                /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "var(--space-2)" }, children: [
                  /* @__PURE__ */ jsx("span", { style: { fontWeight: 600, fontSize: "1rem" }, children: deviceName }),
                  /* @__PURE__ */ jsxs(
                    "span",
                    {
                      className: `badge ${isConnected ? "badge-success" : isInUse ? "badge-warning" : "badge-error"} badge-pulse`,
                      children: [
                        /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "●" }),
                        isConnected ? "Connected" : isInUse ? "In Use" : device.status
                      ]
                    }
                  )
                ] }),
                /* @__PURE__ */ jsxs("div", { style: { fontSize: "0.875rem", color: "var(--color-text-muted)" }, children: [
                  /* @__PURE__ */ jsx("div", { style: { marginBottom: "var(--space-1)" }, children: /* @__PURE__ */ jsx("span", { style: { fontFamily: "var(--font-mono)" }, children: device.device_path }) }),
                  device.firmware_info && /* @__PURE__ */ jsx("div", { children: device.firmware_info.os_version })
                ] })
              ]
            },
            device.device_id
          );
        }) }),
        /* @__PURE__ */ jsx("div", { style: { marginTop: "var(--space-4)", display: "flex", gap: "var(--space-2)" }, children: /* @__PURE__ */ jsx("a", { href: "/commands", className: "btn btn-primary", style: { flex: 1 }, children: data.devices.length > 0 ? "Select Device & Start" : "Waiting for Device..." }) })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "card", children: [
        /* @__PURE__ */ jsxs("h3", { className: "card-title", children: [
          /* @__PURE__ */ jsx("span", { style: { color: "var(--color-secondary)" }, children: "⚡" }),
          " Quick Actions"
        ] }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "var(--space-2)" }, children: [
          /* @__PURE__ */ jsxs("a", { href: "/commands?cmd=hf+search", className: "btn btn-secondary", style: { justifyContent: "flex-start" }, children: [
            /* @__PURE__ */ jsx("span", { children: "🔍" }),
            /* @__PURE__ */ jsx("span", { children: "HF Search" })
          ] }),
          /* @__PURE__ */ jsxs("a", { href: "/commands?cmd=lf+search", className: "btn btn-secondary", style: { justifyContent: "flex-start" }, children: [
            /* @__PURE__ */ jsx("span", { children: "🔍" }),
            /* @__PURE__ */ jsx("span", { children: "LF Search" })
          ] }),
          /* @__PURE__ */ jsxs("a", { href: "/commands?cmd=hw+tune", className: "btn btn-secondary", style: { justifyContent: "flex-start" }, children: [
            /* @__PURE__ */ jsx("span", { children: "📡" }),
            /* @__PURE__ */ jsx("span", { children: "Tune Antenna" })
          ] }),
          /* @__PURE__ */ jsxs("a", { href: "/settings", className: "btn btn-secondary", style: { justifyContent: "flex-start" }, children: [
            /* @__PURE__ */ jsx("span", { children: "⚙" }),
            /* @__PURE__ */ jsx("span", { children: "Settings" })
          ] })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxs("div", { style: { textAlign: "center", padding: "var(--space-6) 0", color: "var(--color-text-muted)" }, children: [
      /* @__PURE__ */ jsxs("p", { children: [
        /* @__PURE__ */ jsx("strong", { style: { color: "var(--color-primary)" }, children: "Dangerous Pi" }),
        " v",
        data.health.version
      ] }),
      /* @__PURE__ */ jsxs("p", { style: { fontSize: "0.875rem", marginTop: "var(--space-2)" }, children: [
        "Built for ",
        /* @__PURE__ */ jsx("a", { href: "https://dangerousthings.com", target: "_blank", rel: "noopener noreferrer", children: "Dangerous Things" })
      ] })
    ] })
  ] });
}
const route4 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: Dashboard,
  loader: loader$1
}, Symbol.toStringTag, { value: "Module" }));
async function loader() {
  try {
    const response = await fetch("http://localhost:8000/api/pm3/commands/history?limit=50");
    const data = await response.json();
    return json({ history: data.history || [] });
  } catch (error) {
    return json({
      history: [
        {
          id: 1,
          command: "hw version",
          success: true,
          executed_at: (/* @__PURE__ */ new Date()).toISOString()
        },
        {
          id: 2,
          command: "hw status",
          success: true,
          executed_at: new Date(Date.now() - 3e5).toISOString()
        }
      ]
    });
  }
}
function Logs() {
  const { history } = useLoaderData();
  const formatDate = (dateString) => {
    const date = new Date(dateString);
    return new Intl.DateTimeFormat("en-US", {
      month: "short",
      day: "numeric",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit"
    }).format(date);
  };
  return /* @__PURE__ */ jsxs("div", { className: "container", children: [
    /* @__PURE__ */ jsxs("h1", { style: { marginBottom: "var(--space-6)" }, children: [
      /* @__PURE__ */ jsx("span", { style: { color: "var(--color-info)" }, children: "≡" }),
      " Command Logs"
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "card", children: [
      /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "var(--space-4)" }, children: [
        /* @__PURE__ */ jsx("h3", { className: "card-title", style: { marginBottom: 0 }, children: "Command History" }),
        /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "var(--space-2)" }, children: [
          /* @__PURE__ */ jsxs("button", { className: "btn btn-secondary", disabled: true, children: [
            /* @__PURE__ */ jsx("span", { children: "⬇" }),
            /* @__PURE__ */ jsx("span", { children: "Export CSV" })
          ] }),
          /* @__PURE__ */ jsxs("button", { className: "btn btn-danger", disabled: true, children: [
            /* @__PURE__ */ jsx("span", { children: "🗑" }),
            /* @__PURE__ */ jsx("span", { children: "Clear" })
          ] })
        ] })
      ] }),
      history.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "terminal", style: { textAlign: "center", color: "var(--color-text-muted)" }, children: [
        /* @__PURE__ */ jsx("p", { children: "No command history yet." }),
        /* @__PURE__ */ jsxs("p", { style: { fontSize: "0.875rem", marginTop: "var(--space-2)" }, children: [
          "Execute commands from the",
          " ",
          /* @__PURE__ */ jsx("a", { href: "/commands", children: "Commands page" }),
          " ",
          "to see them here."
        ] })
      ] }) : /* @__PURE__ */ jsx("div", { style: { overflowX: "auto" }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
        /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { style: { borderBottom: "1px solid var(--color-border)" }, children: [
          /* @__PURE__ */ jsx("th", { style: { padding: "var(--space-3)", textAlign: "left", color: "var(--color-text-secondary)", fontSize: "0.75rem", textTransform: "uppercase", letterSpacing: "0.05em" }, children: "Time" }),
          /* @__PURE__ */ jsx("th", { style: { padding: "var(--space-3)", textAlign: "left", color: "var(--color-text-secondary)", fontSize: "0.75rem", textTransform: "uppercase", letterSpacing: "0.05em" }, children: "Command" }),
          /* @__PURE__ */ jsx("th", { style: { padding: "var(--space-3)", textAlign: "left", color: "var(--color-text-secondary)", fontSize: "0.75rem", textTransform: "uppercase", letterSpacing: "0.05em" }, children: "Status" })
        ] }) }),
        /* @__PURE__ */ jsx("tbody", { children: history.map((entry2, idx) => /* @__PURE__ */ jsxs(
          "tr",
          {
            style: {
              borderBottom: "1px solid var(--color-border)",
              transition: "background var(--transition-fast)"
            },
            onMouseEnter: (e) => {
              e.currentTarget.style.background = "var(--color-surface-hover)";
            },
            onMouseLeave: (e) => {
              e.currentTarget.style.background = "transparent";
            },
            children: [
              /* @__PURE__ */ jsx("td", { style: { padding: "var(--space-3)", fontSize: "0.875rem", color: "var(--color-text-secondary)", fontFamily: "var(--font-mono)" }, children: formatDate(entry2.executed_at) }),
              /* @__PURE__ */ jsx("td", { style: { padding: "var(--space-3)", fontFamily: "var(--font-mono)", fontSize: "0.875rem" }, children: /* @__PURE__ */ jsx("code", { style: { color: "var(--color-accent)" }, children: entry2.command }) }),
              /* @__PURE__ */ jsx("td", { style: { padding: "var(--space-3)" }, children: /* @__PURE__ */ jsxs("span", { className: `badge ${entry2.success ? "badge-success" : "badge-error"}`, children: [
                /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: entry2.success ? "✓" : "✗" }),
                entry2.success ? "Success" : "Failed"
              ] }) })
            ]
          },
          entry2.id || idx
        )) })
      ] }) }),
      history.length > 0 && /* @__PURE__ */ jsxs("div", { style: { marginTop: "var(--space-4)", textAlign: "center", color: "var(--color-text-muted)", fontSize: "0.875rem" }, children: [
        "Showing ",
        history.length,
        " recent commands"
      ] })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "card", style: { marginTop: "var(--space-4)" }, children: [
      /* @__PURE__ */ jsx("h3", { className: "card-title", children: "System Logs" }),
      /* @__PURE__ */ jsx("p", { className: "text-muted", children: "System log viewing will be available in a future update." }),
      /* @__PURE__ */ jsxs("button", { className: "btn btn-secondary", disabled: true, children: [
        /* @__PURE__ */ jsx("span", { children: "📄" }),
        /* @__PURE__ */ jsx("span", { children: "View System Logs" })
      ] })
    ] })
  ] });
}
const route5 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: Logs,
  loader
}, Symbol.toStringTag, { value: "Module" }));
const serverManifest = { "entry": { "module": "/assets/entry.client-CkrwxAV0.js", "imports": ["/assets/components-DjjSZ9bp.js"], "css": [] }, "routes": { "root": { "id": "root", "parentId": void 0, "path": "", "index": void 0, "caseSensitive": void 0, "hasAction": false, "hasLoader": false, "hasClientAction": false, "hasClientLoader": false, "hasErrorBoundary": false, "module": "/assets/root-f_Ye4G9l.js", "imports": ["/assets/components-DjjSZ9bp.js"], "css": [] }, "routes/commands": { "id": "routes/commands", "parentId": "root", "path": "commands", "index": void 0, "caseSensitive": void 0, "hasAction": true, "hasLoader": false, "hasClientAction": false, "hasClientLoader": false, "hasErrorBoundary": false, "module": "/assets/commands-DSGkGbDk.js", "imports": ["/assets/components-DjjSZ9bp.js"], "css": [] }, "routes/settings": { "id": "routes/settings", "parentId": "root", "path": "settings", "index": void 0, "caseSensitive": void 0, "hasAction": true, "hasLoader": true, "hasClientAction": false, "hasClientLoader": false, "hasErrorBoundary": false, "module": "/assets/settings-BHbKcVlC.js", "imports": ["/assets/components-DjjSZ9bp.js"], "css": [] }, "routes/updates": { "id": "routes/updates", "parentId": "root", "path": "updates", "index": void 0, "caseSensitive": void 0, "hasAction": true, "hasLoader": true, "hasClientAction": false, "hasClientLoader": false, "hasErrorBoundary": false, "module": "/assets/updates-CNJu1SrW.js", "imports": ["/assets/components-DjjSZ9bp.js"], "css": [] }, "routes/_index": { "id": "routes/_index", "parentId": "root", "path": void 0, "index": true, "caseSensitive": void 0, "hasAction": false, "hasLoader": true, "hasClientAction": false, "hasClientLoader": false, "hasErrorBoundary": false, "module": "/assets/_index-CIJCcFpO.js", "imports": ["/assets/components-DjjSZ9bp.js"], "css": [] }, "routes/logs": { "id": "routes/logs", "parentId": "root", "path": "logs", "index": void 0, "caseSensitive": void 0, "hasAction": false, "hasLoader": true, "hasClientAction": false, "hasClientLoader": false, "hasErrorBoundary": false, "module": "/assets/logs-C_6-dKR0.js", "imports": ["/assets/components-DjjSZ9bp.js"], "css": [] } }, "url": "/assets/manifest-cbba6713.js", "version": "cbba6713" };
const mode = "production";
const assetsBuildDirectory = "build/client";
const basename = "/";
const future = { "v3_fetcherPersist": true, "v3_relativeSplatPath": true, "v3_throwAbortReason": true, "v3_routeConfig": false, "v3_singleFetch": false, "v3_lazyRouteDiscovery": false, "unstable_optimizeDeps": false };
const isSpaMode = false;
const publicPath = "/";
const entry = { module: entryServer };
const routes = {
  "root": {
    id: "root",
    parentId: void 0,
    path: "",
    index: void 0,
    caseSensitive: void 0,
    module: route0
  },
  "routes/commands": {
    id: "routes/commands",
    parentId: "root",
    path: "commands",
    index: void 0,
    caseSensitive: void 0,
    module: route1
  },
  "routes/settings": {
    id: "routes/settings",
    parentId: "root",
    path: "settings",
    index: void 0,
    caseSensitive: void 0,
    module: route2
  },
  "routes/updates": {
    id: "routes/updates",
    parentId: "root",
    path: "updates",
    index: void 0,
    caseSensitive: void 0,
    module: route3
  },
  "routes/_index": {
    id: "routes/_index",
    parentId: "root",
    path: void 0,
    index: true,
    caseSensitive: void 0,
    module: route4
  },
  "routes/logs": {
    id: "routes/logs",
    parentId: "root",
    path: "logs",
    index: void 0,
    caseSensitive: void 0,
    module: route5
  }
};
export {
  serverManifest as assets,
  assetsBuildDirectory,
  basename,
  entry,
  future,
  isSpaMode,
  mode,
  publicPath,
  routes
};
