import { jsx as r, jsxs as t, Fragment as T } from "react/jsx-runtime";
import { useState as l } from "react";
import { useNavigate as J } from "react-router-dom";
import { useTranslation as M } from "react-i18next";
import { AlertTriangle as g, Code as p, Zap as S, Server as j, Database as H, Skull as I, Loader2 as _, Ticket as q, Bomb as d, Bug as R, Trash2 as W } from "lucide-react";
import { l as o, P as Z, e as z, t as P } from "./index-CeEMms9z.js";
function K({ config: c }) {
  const i = new Error(c.message);
  throw i.name = c.type, i;
}
function ar() {
  M(["support", "common"]);
  const c = J(), [i, u] = l([]), [x, A] = l(null), [v, b] = l(!1), [E, G] = l(null), a = (e) => {
    u((n) => [...n, `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] ${e}`]);
  }, N = () => {
    try {
      const e = undefinedVariable.property;
      console.log(e);
    } catch (e) {
      o.logError(e instanceof Error ? e : String(e), "TestBugPage"), a("JavaScript Error logged: undefinedVariable is not defined");
    }
  }, f = () => {
    try {
      null.toString();
    } catch (e) {
      o.logError(e instanceof Error ? e : String(e), "TestBugPage"), a("TypeError logged: Cannot read properties of null");
    }
  }, O = () => {
    try {
      nonExistentFunction();
    } catch (e) {
      o.logError(e instanceof Error ? e : String(e), "TestBugPage"), a("ReferenceError logged: nonExistentFunction is not defined");
    }
  }, B = () => {
    try {
      JSON.parse('{"invalid": }');
    } catch (e) {
      o.logError(e instanceof Error ? e : String(e), "TestBugPage"), a("SyntaxError logged: Unexpected token } in JSON");
    }
  }, w = () => {
    const e = new Error("API Error: 500 Internal Server Error - Failed to fetch user data");
    e.name = "APIError", o.logError(e, "ApiClient"), a("API Error logged: 500 Internal Server Error");
  }, y = () => {
    const e = new Error("Network Error: Failed to fetch - net::ERR_CONNECTION_REFUSED");
    e.name = "NetworkError", o.logError(e, "NetworkService"), a("Network Error logged: Connection refused");
  }, F = () => {
    const e = new Error("Validation Error: Email format is invalid");
    e.name = "ValidationError", o.logError(e, "FormValidator"), a("Validation Error logged: Email format invalid");
  }, D = () => {
    const e = new Error("Timeout Error: Request took longer than 30000ms");
    e.name = "TimeoutError", o.logError(e, "HttpClient"), a("Timeout Error logged: Request timeout");
  }, U = async () => {
    try {
      b(!0), A(null), a("🚨 Generating test errors...");
      const e = new Error("CRITICAL: Application crash detected - Memory heap overflow");
      e.name = "CriticalError", o.logError(e, "TestBugPage");
      const n = new Error("API Error: 500 Internal Server Error - Database connection failed");
      n.name = "APIError", o.logError(n, "ApiClient");
      const C = new Error("Network Error: Failed to fetch - net::ERR_CONNECTION_REFUSED");
      C.name = "NetworkError", o.logError(C, "NetworkService"), a("✅ 3 test errors generated"), a("📸 Capturing screenshot and context...");
      const s = await z.captureContext();
      a(`✅ Context captured: screenshot=${!!s.screenshot}, errors=${s.recentErrors.length}`);
      const h = P.createDraft();
      P.updateDraft(h.id, {
        title: "Critical Error Test - " + (/* @__PURE__ */ new Date()).toLocaleString(),
        type: "Bug",
        priority: "Critical",
        screenshot: s.screenshot,
        errorContext: {
          url: s.url,
          timestamp: s.timestamp.toISOString(),
          recentErrors: s.recentErrors.map((k) => ({
            ...k,
            timestamp: k.timestamp.toISOString()
          })),
          browserInfo: s.browserInfo
        }
      }), a(`✅ Draft created: ${h.id}`), a("🚀 Navigating to ticket creation page..."), c(`/support/tickets/new?draft=${h.id}`);
    } catch (e) {
      a(`❌ Failed to create error context: ${e}`), b(!1);
    }
  }, $ = () => {
    N(), f(), w(), y(), a("--- Multiple errors generated ---");
  }, V = () => {
    u([]);
  }, m = (e, n) => {
    a(`💥 Triggering UNCAUGHT ${e}: ${n}`), a("⚠️ This will crash the component and show the ErrorFallback page..."), setTimeout(() => {
      G({ type: e, message: n });
    }, 100);
  }, L = o.getRecentErrors().length;
  return E ? /* @__PURE__ */ r(K, { config: E }) : /* @__PURE__ */ t(
    Z,
    {
      title: "Test Bug Page - Error Generator",
      subtitle: "This page generates test errors to verify the error capture functionality. After generating errors, click the support button to create a ticket and see the captured errors.",
      icon: /* @__PURE__ */ r(R, { className: "w-6 h-6" }),
      contentClassName: "space-y-6",
      children: [
        /* @__PURE__ */ r("div", { className: "card p-4 mb-6 bg-[var(--error-bg)] border-[var(--error-border)]", children: /* @__PURE__ */ t("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ r(g, { className: "w-6 h-6 text-[var(--error-text)]" }),
          /* @__PURE__ */ t("div", { children: [
            /* @__PURE__ */ t("p", { className: "font-medium", children: [
              "Recent Errors in Memory: ",
              /* @__PURE__ */ r("span", { className: "text-[var(--error-text)]", children: L })
            ] }),
            /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: "These errors will be captured when you create a support ticket" })
          ] })
        ] }) }),
        /* @__PURE__ */ t("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4 mb-8", children: [
          /* @__PURE__ */ t(
            "button",
            {
              onClick: N,
              className: "card p-4 text-left hover:shadow-md transition-shadow hover:border-[var(--error-text)]/50",
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-2", children: [
                  /* @__PURE__ */ r(p, { className: "w-5 h-5 text-[var(--warning-text)]" }),
                  /* @__PURE__ */ r("span", { className: "font-medium", children: "JavaScript Error" })
                ] }),
                /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: 'Generates: "undefinedVariable is not defined"' })
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: f,
              className: "card p-4 text-left hover:shadow-md transition-shadow hover:border-[var(--error-text)]/50",
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-2", children: [
                  /* @__PURE__ */ r(S, { className: "w-5 h-5 text-[var(--warning-text)]" }),
                  /* @__PURE__ */ r("span", { className: "font-medium", children: "Type Error" })
                ] }),
                /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: 'Generates: "Cannot read properties of null"' })
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: O,
              className: "card p-4 text-left hover:shadow-md transition-shadow hover:border-[var(--error-text)]/50",
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-2", children: [
                  /* @__PURE__ */ r(g, { className: "w-5 h-5 text-[var(--error-text)]" }),
                  /* @__PURE__ */ r("span", { className: "font-medium", children: "Reference Error" })
                ] }),
                /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: 'Generates: "nonExistentFunction is not defined"' })
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: B,
              className: "card p-4 text-left hover:shadow-md transition-shadow hover:border-[var(--error-text)]/50",
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-2", children: [
                  /* @__PURE__ */ r(p, { className: "w-5 h-5 text-[var(--info-text)]" }),
                  /* @__PURE__ */ r("span", { className: "font-medium", children: "Syntax Error" })
                ] }),
                /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: 'Generates: "Unexpected end of input"' })
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: w,
              className: "card p-4 text-left hover:shadow-md transition-shadow hover:border-[var(--error-text)]/50",
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-2", children: [
                  /* @__PURE__ */ r(j, { className: "w-5 h-5 text-[var(--info-text)]" }),
                  /* @__PURE__ */ r("span", { className: "font-medium", children: "API Error (500)" })
                ] }),
                /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: 'Generates: "500 Internal Server Error"' })
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: y,
              className: "card p-4 text-left hover:shadow-md transition-shadow hover:border-[var(--error-text)]/50",
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-2", children: [
                  /* @__PURE__ */ r(H, { className: "w-5 h-5 text-[var(--info-text)]" }),
                  /* @__PURE__ */ r("span", { className: "font-medium", children: "Network Error" })
                ] }),
                /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: 'Generates: "Connection refused"' })
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: F,
              className: "card p-4 text-left hover:shadow-md transition-shadow hover:border-[var(--error-text)]/50",
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-2", children: [
                  /* @__PURE__ */ r(g, { className: "w-5 h-5 text-[var(--warning-text)]" }),
                  /* @__PURE__ */ r("span", { className: "font-medium", children: "Validation Error" })
                ] }),
                /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: 'Generates: "Email format is invalid"' })
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: D,
              className: "card p-4 text-left hover:shadow-md transition-shadow hover:border-[var(--error-text)]/50",
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-2", children: [
                  /* @__PURE__ */ r(S, { className: "w-5 h-5 text-[var(--error-text)]" }),
                  /* @__PURE__ */ r("span", { className: "font-medium", children: "Timeout Error" })
                ] }),
                /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: 'Generates: "Request timeout"' })
              ]
            }
          )
        ] }),
        /* @__PURE__ */ t("div", { className: "card p-6 mb-8 border-2 border-[var(--error-border)] bg-[var(--error-bg)]", children: [
          /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-4", children: [
            /* @__PURE__ */ r(I, { className: "w-8 h-8 text-[var(--error-text)]" }),
            /* @__PURE__ */ t("div", { children: [
              /* @__PURE__ */ r("h2", { className: "text-xl font-bold text-[var(--error-text)]", children: "Critical Error Test" }),
              /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: "Generates test errors, captures screenshot + browser info, and opens the ticket creation page with full context" })
            ] })
          ] }),
          /* @__PURE__ */ r(
            "button",
            {
              onClick: U,
              disabled: v,
              className: "btn bg-[var(--error-bg)] text-[var(--error-text)] hover:opacity-90 w-full py-3 text-lg font-semibold disabled:opacity-50 disabled:cursor-not-allowed border border-[var(--error-border)]",
              children: v ? /* @__PURE__ */ t(T, { children: [
                /* @__PURE__ */ r(_, { className: "w-5 h-5 mr-2 animate-spin" }),
                "Capturing context..."
              ] }) : /* @__PURE__ */ t(T, { children: [
                /* @__PURE__ */ r(I, { className: "w-5 h-5 mr-2" }),
                "Generate CRITICAL Error (Opens Ticket Page)"
              ] })
            }
          ),
          x && /* @__PURE__ */ t("div", { className: "mt-4 p-3 bg-[var(--success-bg)] border border-[var(--success-border)] rounded-lg flex items-center gap-2", children: [
            /* @__PURE__ */ r(q, { className: "w-5 h-5 text-[var(--success-text)]" }),
            /* @__PURE__ */ r("span", { className: "font-medium", children: "Ticket created: " }),
            /* @__PURE__ */ r("code", { className: "bg-[var(--bg-secondary)] px-2 py-1 rounded", children: x })
          ] })
        ] }),
        /* @__PURE__ */ t("div", { className: "card p-6 mb-8 border-2 border-[var(--warning-border)] bg-[var(--warning-bg)]", children: [
          /* @__PURE__ */ t("div", { className: "flex items-center gap-3 mb-4", children: [
            /* @__PURE__ */ r(d, { className: "w-8 h-8 text-[var(--warning-text)]" }),
            /* @__PURE__ */ t("div", { children: [
              /* @__PURE__ */ r("h2", { className: "text-xl font-bold text-[var(--warning-text)]", children: "UNCAUGHT Error Test (ErrorBoundary)" }),
              /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: "Triggers a real uncaught error that will be caught by the ErrorBoundary. This displays the error page and automatically creates a support ticket via logService.logCritical()." })
            ] })
          ] }),
          /* @__PURE__ */ t("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-3", children: [
            /* @__PURE__ */ t(
              "button",
              {
                onClick: () => m("ReferenceError", "BookOpen is not defined"),
                className: "btn bg-[var(--warning-bg)] text-[var(--warning-text)] hover:opacity-90 py-3 font-semibold border border-[var(--warning-border)]",
                children: [
                  /* @__PURE__ */ r(d, { className: "w-4 h-4 mr-2" }),
                  "ReferenceError"
                ]
              }
            ),
            /* @__PURE__ */ t(
              "button",
              {
                onClick: () => m("TypeError", "Cannot read properties of undefined (reading 'map')"),
                className: "btn bg-[var(--warning-bg)] text-[var(--warning-text)] hover:opacity-90 py-3 font-semibold border border-[var(--warning-border)]",
                children: [
                  /* @__PURE__ */ r(d, { className: "w-4 h-4 mr-2" }),
                  "TypeError"
                ]
              }
            ),
            /* @__PURE__ */ t(
              "button",
              {
                onClick: () => m("Error", "Critical application failure - memory heap overflow"),
                className: "btn bg-[var(--warning-bg)] text-[var(--warning-text)] hover:opacity-90 py-3 font-semibold border border-[var(--warning-border)]",
                children: [
                  /* @__PURE__ */ r(d, { className: "w-4 h-4 mr-2" }),
                  "Generic Error"
                ]
              }
            )
          ] }),
          /* @__PURE__ */ r("p", { className: "mt-4 text-xs text-[var(--text-tertiary)]", children: 'Warning: Clicking these buttons will crash this component and show the error page. Use the "Retry" button on the error page to come back.' })
        ] }),
        /* @__PURE__ */ t("div", { className: "flex gap-4 mb-8", children: [
          /* @__PURE__ */ t(
            "button",
            {
              onClick: $,
              className: "btn bg-[var(--error-bg)] text-[var(--error-text)] hover:opacity-90",
              children: [
                /* @__PURE__ */ r(R, { className: "w-4 h-4 mr-2" }),
                "Generate Multiple Errors"
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: V,
              className: "btn btn-secondary",
              children: [
                /* @__PURE__ */ r(W, { className: "w-4 h-4 mr-2" }),
                "Clear Console"
              ]
            }
          )
        ] }),
        /* @__PURE__ */ t("div", { className: "card p-4", children: [
          /* @__PURE__ */ t("h2", { className: "font-medium mb-3 flex items-center gap-2", children: [
            /* @__PURE__ */ r(p, { className: "w-5 h-5" }),
            "Console Output"
          ] }),
          /* @__PURE__ */ r("div", { className: "bg-[var(--bg-secondary)] rounded-lg p-4 font-mono text-sm max-h-64 overflow-y-auto", children: i.length === 0 ? /* @__PURE__ */ r("p", { className: "text-[var(--text-secondary)]", children: "Click on error buttons above to generate test errors..." }) : i.map((e, n) => /* @__PURE__ */ r("div", { className: "text-[var(--error-text)] mb-1", children: e }, `line-${n}`)) })
        ] }),
        /* @__PURE__ */ t("div", { className: "mt-8 p-4 bg-[var(--bg-secondary)] rounded-lg", children: [
          /* @__PURE__ */ r("h3", { className: "font-medium mb-2", children: "How to test:" }),
          /* @__PURE__ */ t("ol", { className: "list-decimal list-inside space-y-1 text-sm text-[var(--text-secondary)]", children: [
            /* @__PURE__ */ r("li", { children: "Click on one or more error buttons above to generate test errors" }),
            /* @__PURE__ */ r("li", { children: "Click the support/headset button in the header to create a ticket" }),
            /* @__PURE__ */ r("li", { children: 'The "Recent Errors" section should show the errors you generated' }),
            /* @__PURE__ */ r("li", { children: "The screenshot should capture this page" }),
            /* @__PURE__ */ r("li", { children: "The URL and browser info should be automatically included" })
          ] })
        ] })
      ]
    }
  );
}
export {
  ar as TestBugPage
};
//# sourceMappingURL=TestBugPage-DZfq3vvS.js.map
