import { jsxs as a, jsx as t, Fragment as Qe } from "react/jsx-runtime";
import { useRef as H, useState as c, useEffect as X, useCallback as l } from "react";
import { useNavigate as Ze, useSearchParams as Je } from "react-router-dom";
import { useTranslation as Ye } from "react-i18next";
import { aD as oe, l as le, aw as et, a as tt, t as R, e as ke, aC as ne, aE as rt, P as at } from "./index-CeEMms9z.js";
import { Info as st, ExternalLink as nt, Building2 as ie, Trash2 as we, Check as it, Headset as ct, Bug as ot, Lightbulb as lt, AppWindow as dt, MessageSquare as mt, HelpCircle as ut, ArrowLeft as pt, Image as Ce, Upload as Se, X as Te, Paperclip as ht, Monitor as ft, AlertTriangle as gt, Loader2 as vt, Send as bt, FileText as xt, File as yt } from "lucide-react";
import { S as Nt } from "./ScreenshotAnnotator-mFJbKqEg.js";
function Ie(n) {
  return n instanceof Error ? n.message : typeof n == "string" ? n : n && typeof n == "object" && "message" in n && typeof n.message == "string" ? n.message : String(n);
}
async function kt(n, u, r) {
  try {
    const p = await (await fetch(u)).blob(), m = new File([p], "screenshot.png", { type: "image/png" });
    return await oe.uploadAttachment(n, m, r), null;
  } catch (g) {
    const p = Ie(g);
    return le.logError(
      g instanceof Error ? g : new Error(p),
      "ticketAttachmentUpload.uploadTicketScreenshot",
      { ticketId: n }
    ), { name: "screenshot.png", message: p };
  }
}
async function wt(n, u, r) {
  const g = await Promise.allSettled(
    u.map((m) => oe.uploadAttachment(n, m.file, r))
  ), p = [];
  return g.forEach((m, P) => {
    if (m.status === "rejected") {
      const B = Ie(m.reason), k = u[P];
      le.logError(
        m.reason instanceof Error ? m.reason : new Error(B),
        "ticketAttachmentUpload.uploadTicketAttachments",
        { ticketId: n, fileName: k.name }
      ), p.push({ name: k.name, message: B });
    }
  }), p;
}
const ce = [
  {
    value: "Bug",
    label: "Report a Bug",
    labelKey: "tickets.types.bug",
    description: "Something is not working correctly",
    descriptionKey: "tickets.types.bugDescription",
    icon: ot
  },
  {
    value: "FeatureRequest",
    label: "Request a Feature",
    labelKey: "tickets.types.featureRequest",
    description: "Suggest an improvement or new feature",
    descriptionKey: "tickets.types.featureRequestDescription",
    icon: lt
  },
  {
    value: "ApplicationRequest",
    label: "Request an Application",
    labelKey: "tickets.types.applicationRequest",
    description: "Request access to a new application",
    descriptionKey: "tickets.types.applicationRequestDescription",
    icon: dt
  },
  {
    value: "Support",
    label: "General Support",
    labelKey: "tickets.types.support",
    description: "Need help with something",
    descriptionKey: "tickets.types.supportDescription",
    icon: mt
  },
  {
    value: "Question",
    label: "Ask a Question",
    labelKey: "tickets.types.question",
    description: "Have a question about the platform",
    descriptionKey: "tickets.types.questionDescription",
    icon: ut
  }
], St = [
  { value: "Low", label: "Low", labelKey: "tickets.priority.low", description: "Can wait, not urgent", descriptionKey: "tickets.priority.lowDescription" },
  { value: "Medium", label: "Medium", labelKey: "tickets.priority.medium", description: "Normal priority", descriptionKey: "tickets.priority.mediumDescription" },
  { value: "High", label: "High", labelKey: "tickets.priority.high", description: "Important, needs attention soon", descriptionKey: "tickets.priority.highDescription" },
  { value: "Critical", label: "Critical", labelKey: "tickets.priority.critical", description: "Urgent, blocking work", descriptionKey: "tickets.priority.criticalDescription" }
], De = 10 * 1024 * 1024, w = 5, Q = [".jpg", ".jpeg", ".png", ".gif", ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".txt", ".log", ".zip"], Tt = Q.join(",");
function Dt(n) {
  return n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${(n / 1024).toFixed(1)} KB` : `${(n / (1024 * 1024)).toFixed(1)} MB`;
}
function Ct(n) {
  return n.includes("pdf") ? xt : n.startsWith("image/") ? Ce : yt;
}
function It(n, u) {
  if (!n) return { draft: null, selectedTenant: null };
  const r = R.getDraft(n);
  if (!r) return { draft: null, selectedTenant: null };
  let g = null;
  if (r.tenantId && r.tenantSlug) {
    const p = u.find((m) => m.id === r.tenantId);
    p && (g = p);
  }
  return { draft: r, selectedTenant: g };
}
function At(n) {
  if (!n?.screenshot) return { screenshot: null, autoSelectType: null };
  let u = null;
  return n.recentErrors.length > 0 && (u = "Bug"), { screenshot: n.screenshot, autoSelectType: u };
}
function Lt() {
  const n = Ze(), [u] = Je(), { t: r } = Ye(["support", "common"]), { isGlpi: g, glpiBaseUrl: p } = et(), { currentTenant: m, userTenants: P, isGlobalView: B } = tt(), k = H(null), j = H(null), [F, de] = c(null), [Ae, K] = c(!1), E = m ?? F;
  X(() => {
    !m && B && P.length > 0 && K(!0);
  }, [m, B, P.length]);
  const Z = u.get("draft"), [S, L] = c(1), [h, V] = c(null), [x, J] = c(""), [y, Y] = c(""), [$, ee] = c("Medium"), [me, ue] = c(!1), [pe, v] = c(null), [b, Pe] = c(null), [te, Fe] = c(!0), [he, W] = c(null), [T, q] = c(null), [fe, re] = c(!1), [N, ge] = c([]), [ve, ae] = c(!1), [o, Ee] = c(Z), [Re, be] = c(!1), [Be, xe] = c(!1), f = H(null), ye = H(!1), M = H(!1), U = l(() => {
    if (!o) return !1;
    const e = R.updateDraft(o, {
      type: h,
      title: x,
      description: y,
      priority: $,
      includeScreenshot: !!T,
      includeErrorLogs: !1,
      screenshot: T ?? void 0,
      tenantId: E?.id,
      tenantSlug: E?.slug,
      tenantName: E?.name
    });
    return e.success && (M.current = !1, be(!0), setTimeout(() => be(!1), 2e3)), e.success;
  }, [o, h, x, y, $, T, E]), se = l(() => {
    if (o) return o;
    const e = R.createDraft();
    return Ee(e.id), e.id;
  }, [o]);
  X(() => {
    if (ye.current && !(!h && !x && !y)) {
      if (M.current = !0, !o) {
        se();
        return;
      }
      return f.current && clearTimeout(f.current), f.current = setTimeout(() => {
        U();
      }, 1e3), () => {
        f.current && clearTimeout(f.current);
      };
    }
  }, [h, x, y, $, T, o, U, se]), X(() => {
    const e = () => {
      M.current && o && U();
    };
    return window.addEventListener("beforeunload", e), () => {
      window.removeEventListener("beforeunload", e), M.current && o && U(), f.current && clearTimeout(f.current);
    };
  }, [o, U]);
  const je = l(() => {
    o && R.deleteDraft(o), f.current && (clearTimeout(f.current), f.current = null), n(-1);
  }, [o, n]);
  X(() => {
    const { draft: e, selectedTenant: s } = It(Z, P);
    if (e && (e.type && (V(e.type), L(2)), e.title && J(e.title), e.description && Y(e.description), e.priority && ee(e.priority), e.screenshot && (W(e.screenshot), q(e.screenshot)), s && de(s)), !e) {
      const _ = ["Bug", "FeatureRequest", "Suggestion", "ApplicationRequest", "Support", "Question"], z = u.get("type"), I = u.get("subject"), A = u.get("body");
      z && _.includes(z) && (V(z), L(2)), I && J(decodeURIComponent(I)), A && Y(decodeURIComponent(A));
    }
    const d = ke.loadContext(), { screenshot: i, autoSelectType: D } = At(d);
    i && !T && (W(i), q(i), D && !h && (V(D), ee("High"))), ke.clearContext();
    const C = ne.captureBrowserInfo();
    Pe(C), setTimeout(() => {
      ye.current = !0;
    }, 100);
  }, [Z]);
  const G = l((e) => {
    if (!e.type.startsWith("image/")) {
      v(r("tickets.create.invalidImageType", "Please select a valid image file"));
      return;
    }
    if (e.size > De) {
      v(r("tickets.create.imageTooLarge", "Image must be less than 10MB"));
      return;
    }
    const s = new FileReader();
    s.onload = (d) => {
      const i = d.target?.result;
      W(i), q(i), v(null);
    }, s.onerror = () => {
      v(r("tickets.create.imageReadError", "Failed to read image file"));
    }, s.readAsDataURL(e);
  }, [r]), Ke = l((e) => {
    const s = e.target.files?.[0];
    s && G(s);
  }, [G]), Le = l((e) => {
    e.preventDefault(), e.stopPropagation(), re(!0);
  }, []), $e = l((e) => {
    e.preventDefault(), e.stopPropagation(), re(!1);
  }, []), qe = l((e) => {
    e.preventDefault(), e.stopPropagation(), re(!1);
    const s = e.dataTransfer.files;
    if (s.length > 0) {
      const d = s[0];
      d.type.startsWith("image/") ? G(d) : v(r("tickets.create.invalidImageType", "Please select a valid image file"));
    }
  }, [G, r]), Me = l(() => {
    W(null), q(null), k.current && (k.current.value = "");
  }, []), Ue = l((e) => {
    q(e);
  }, []), Ne = l((e) => {
    if (e.type.startsWith("image/"))
      return !0;
    const s = "." + e.name.split(".").pop()?.toLowerCase();
    return Q.includes(s);
  }, []), O = l((e) => {
    const s = [];
    for (let d = 0; d < e.length; d++) {
      const i = e[d];
      if (N.length + s.length >= w) {
        v(r("tickets.create.maxAttachments", { max: w, defaultValue: `Maximum ${w} attachments allowed` }));
        break;
      }
      if (i.size > De) {
        v(r("tickets.create.fileTooLarge", { fileName: i.name, defaultValue: `File "${i.name}" is too large (max 10MB)` }));
        continue;
      }
      if (!Ne(i)) {
        v(r("tickets.create.invalidFileType", {
          fileName: i.name,
          extensions: Q.join(", "),
          defaultValue: `File type not allowed: ${i.name}. Accepted types: ${Q.join(", ")}`
        }));
        continue;
      }
      N.some((C) => C.name === i.name && C.size === i.size) || s.push({
        id: rt(),
        file: i,
        name: i.name,
        size: i.size,
        type: i.type
      });
    }
    s.length > 0 && (ge((d) => [...d, ...s]), v(null));
  }, [N, Ne, r]), ze = l((e) => {
    const s = e.target.files;
    s && O(s), j.current && (j.current.value = "");
  }, [O]), He = l((e) => {
    e.preventDefault(), e.stopPropagation(), ae(!0);
  }, []), Ve = l((e) => {
    e.preventDefault(), e.stopPropagation(), ae(!1);
  }, []), We = l((e) => {
    e.preventDefault(), e.stopPropagation(), ae(!1);
    const s = e.dataTransfer.files;
    s.length > 0 && O(s);
  }, [O]), Ge = l((e) => {
    ge((s) => s.filter((d) => d.id !== e));
  }, []), Oe = async () => {
    if (!(!h || !x.trim() || !y.trim())) {
      if (!E) {
        K(!0);
        return;
      }
      try {
        ue(!0), v(null);
        let e = y.trim();
        te && b && (e += `

---
**System Information:**
` + ne.formatForDescription(b));
        const s = b || ne.captureBrowserInfo(), d = le.getRecentErrors().slice(0, 5), i = {
          sourceUrl: window.location.href,
          browser: {
            name: s.browser,
            version: s.browserVersion,
            language: s.language
          },
          os: {
            name: s.os,
            version: s.osVersion
          },
          device: {
            type: s.deviceType,
            screenResolution: s.screenResolution
          },
          recentErrors: d.map((A) => ({
            message: A.message,
            stack: A.stack,
            component: A.component,
            timestamp: A.timestamp.toISOString()
          }))
        }, D = await oe.create({
          title: x.trim(),
          description: e,
          type: h,
          priority: $,
          clientContext: i
        }, F?.slug), C = F?.slug, [_, z] = await Promise.all([
          T ? kt(D.id, T, C) : Promise.resolve(null),
          wt(D.id, N, C)
        ]), I = [];
        _ && I.push(_), I.push(...z), o && R.deleteDraft(o), f.current && (clearTimeout(f.current), f.current = null), M.current = !1, n(`/support/my-tickets/${D.id}?tab=submitted`, {
          state: I.length > 0 ? { uploadFailures: I } : void 0
        });
      } catch (e) {
        const s = e && typeof e == "object" && "message" in e ? e.message : null;
        v(s || r("tickets.create.submitError", "Failed to create ticket. Please try again."));
      } finally {
        ue(!1);
      }
    }
  }, _e = () => /* @__PURE__ */ a("div", { className: "space-y-4", children: [
    /* @__PURE__ */ t("h2", { className: "text-lg font-semibold mb-4", children: r("tickets.create.selectType", "What type of request do you have?") }),
    /* @__PURE__ */ t("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: ce.map((e) => /* @__PURE__ */ t(
      "button",
      {
        onClick: () => {
          V(e.value), L(2);
        },
        className: `card p-4 text-left hover:shadow-md transition-shadow ${h === e.value ? "ring-2 ring-[var(--color-primary-600)]" : ""}`,
        children: /* @__PURE__ */ a("div", { className: "flex items-start gap-4", children: [
          /* @__PURE__ */ t("div", { className: "p-3 rounded-lg bg-[var(--bg-secondary)]", children: /* @__PURE__ */ t(e.icon, { className: "w-6 h-6" }) }),
          /* @__PURE__ */ a("div", { children: [
            /* @__PURE__ */ t("h3", { className: "font-medium", children: r(e.labelKey, e.label) }),
            /* @__PURE__ */ t("p", { className: "text-sm text-[var(--text-secondary)]", children: r(e.descriptionKey, e.description) })
          ] })
        ] })
      },
      e.value
    )) })
  ] }), Xe = () => /* @__PURE__ */ a("div", { className: "space-y-6", children: [
    /* @__PURE__ */ a("div", { className: "flex items-center gap-4 mb-6", children: [
      /* @__PURE__ */ t("button", { onClick: () => L(1), className: "btn btn-ghost p-2", children: /* @__PURE__ */ t(pt, { className: "w-5 h-5" }) }),
      /* @__PURE__ */ a("div", { children: [
        /* @__PURE__ */ t("h2", { className: "text-lg font-semibold", children: r(ce.find((e) => e.value === h)?.labelKey || "", { defaultValue: ce.find((e) => e.value === h)?.label }) }),
        /* @__PURE__ */ t("p", { className: "text-sm text-[var(--text-secondary)]", children: r("tickets.create.fillDetails", "Fill in the details below") })
      ] })
    ] }),
    /* @__PURE__ */ a("div", { children: [
      /* @__PURE__ */ a("label", { className: "block text-sm font-medium mb-2", children: [
        r("tickets.form.title", "Title"),
        " ",
        /* @__PURE__ */ t("span", { className: "text-[var(--error-text)]", children: "*" })
      ] }),
      /* @__PURE__ */ t(
        "input",
        {
          type: "text",
          value: x,
          onChange: (e) => J(e.target.value),
          placeholder: r("tickets.create.titlePlaceholder", "Brief summary of your request"),
          className: "input w-full",
          maxLength: 200
        }
      ),
      /* @__PURE__ */ a("p", { className: "text-xs text-[var(--text-secondary)] mt-1", children: [
        x.length,
        "/200 ",
        r("common:text.characters", "characters")
      ] })
    ] }),
    /* @__PURE__ */ a("div", { children: [
      /* @__PURE__ */ a("label", { className: "block text-sm font-medium mb-2", children: [
        r("tickets.create.description", "Description"),
        " ",
        /* @__PURE__ */ t("span", { className: "text-[var(--error-text)]", children: "*" })
      ] }),
      /* @__PURE__ */ t(
        "textarea",
        {
          value: y,
          onChange: (e) => Y(e.target.value),
          placeholder: h === "Bug" ? r("tickets.create.bugPlaceholder", "Please describe the issue in detail. Include steps to reproduce, expected behavior, and actual behavior.") : h === "FeatureRequest" ? r("tickets.create.featurePlaceholder", "Describe the feature you would like to see and why it would be useful.") : h === "ApplicationRequest" ? r("tickets.create.applicationPlaceholder", "Which application do you need access to and why?") : r("tickets.create.defaultPlaceholder", "Please provide as much detail as possible."),
          className: "input w-full h-40",
          maxLength: 5e3
        }
      ),
      /* @__PURE__ */ a("p", { className: "text-xs text-[var(--text-secondary)] mt-1", children: [
        y.length,
        "/5000 ",
        r("common:text.characters", "characters")
      ] })
    ] }),
    /* @__PURE__ */ a("div", { children: [
      /* @__PURE__ */ t("label", { className: "block text-sm font-medium mb-1", children: r("tickets.create.priority", "Priority") }),
      /* @__PURE__ */ t("p", { className: "text-xs text-[var(--text-secondary)] mb-2", children: r("tickets.create.priorityHint", "Indication only — our team reviews and adjusts the priority after analysis.") }),
      /* @__PURE__ */ t("div", { className: "grid grid-cols-2 md:grid-cols-4 gap-2", children: St.map((e) => /* @__PURE__ */ a(
        "button",
        {
          type: "button",
          onClick: () => ee(e.value),
          className: `p-3 rounded-lg border text-center transition-colors ${$ === e.value ? "border-[var(--color-primary-600)] bg-[var(--color-primary-600)]/10" : "border-[var(--border-color)] hover:bg-[var(--bg-hover)]"}`,
          children: [
            /* @__PURE__ */ t("div", { className: "font-medium", children: r(e.labelKey, e.label) }),
            /* @__PURE__ */ t("div", { className: "text-xs text-[var(--text-secondary)]", children: r(e.descriptionKey, e.description) })
          ]
        },
        e.value
      )) })
    ] }),
    /* @__PURE__ */ a("div", { children: [
      /* @__PURE__ */ a("label", { className: "block text-sm font-medium mb-2", children: [
        /* @__PURE__ */ t(Ce, { className: "w-4 h-4 inline mr-2" }),
        r("tickets.create.screenshot", "Screenshot"),
        /* @__PURE__ */ a("span", { className: "text-[var(--text-secondary)] font-normal ml-2", children: [
          "(",
          r("common:text.optional", "optional"),
          ")"
        ] })
      ] }),
      he ? /* @__PURE__ */ a("div", { className: "space-y-3", children: [
        /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
          /* @__PURE__ */ t("span", { className: "text-sm text-[var(--text-secondary)]", children: r("tickets.create.screenshotUploaded", "Screenshot uploaded - you can annotate it below") }),
          /* @__PURE__ */ t(
            "button",
            {
              type: "button",
              onClick: Me,
              className: "btn btn-ghost p-2 text-[var(--error-text)]",
              title: r("tickets.create.removeScreenshot", "Remove screenshot"),
              children: /* @__PURE__ */ t(Te, { className: "w-4 h-4" })
            }
          )
        ] }),
        /* @__PURE__ */ t(
          Nt,
          {
            screenshot: he,
            onAnnotatedScreenshot: Ue
          }
        )
      ] }) : /* @__PURE__ */ a(
        "div",
        {
          className: `border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${fe ? "border-[var(--color-primary-600)] bg-[var(--color-primary-600)]/10" : "border-[var(--border-color)] hover:border-[var(--color-primary-600)] hover:bg-[var(--bg-hover)]"}`,
          onClick: () => k.current?.click(),
          onKeyDown: (e) => {
            (e.key === "Enter" || e.key === " ") && (e.preventDefault(), k.current?.click());
          },
          role: "button",
          tabIndex: 0,
          onDragOver: Le,
          onDragLeave: $e,
          onDrop: qe,
          children: [
            /* @__PURE__ */ t(Se, { className: "w-8 h-8 mx-auto mb-2 text-[var(--text-secondary)]" }),
            /* @__PURE__ */ t("p", { className: "text-sm text-[var(--text-secondary)]", children: fe ? r("tickets.create.dropScreenshotNow", "Drop image here") : r("tickets.create.uploadScreenshot", "Click or drag & drop to upload a screenshot") }),
            /* @__PURE__ */ t("p", { className: "text-xs text-[var(--text-muted)] mt-1", children: r("tickets.create.uploadScreenshotHint", "PNG, JPG, or GIF up to 10MB") }),
            /* @__PURE__ */ t(
              "input",
              {
                ref: k,
                type: "file",
                accept: "image/*",
                onChange: Ke,
                className: "hidden"
              }
            )
          ]
        }
      )
    ] }),
    /* @__PURE__ */ a("div", { children: [
      /* @__PURE__ */ a("label", { className: "flex items-center text-sm font-medium mb-2", children: [
        /* @__PURE__ */ t(ht, { className: "w-4 h-4 mr-2" }),
        r("tickets.create.attachments", "Attachments"),
        /* @__PURE__ */ a("span", { className: "text-[var(--text-secondary)] font-normal ml-2", children: [
          "(",
          r("common:text.optional", "optional"),
          ")"
        ] }),
        /* @__PURE__ */ a("span", { className: `ml-auto text-xs font-normal ${N.length >= w ? "text-[var(--warning-text)]" : "text-[var(--text-muted)]"}`, children: [
          N.length,
          "/",
          w
        ] })
      ] }),
      N.length >= w ? /* @__PURE__ */ t("div", { className: "border-2 border-dashed border-[var(--border-color)] rounded-lg p-4 text-center", children: /* @__PURE__ */ t("p", { className: "text-sm text-[var(--text-muted)]", children: r("tickets.create.attachmentsFull", { max: w, defaultValue: `Maximum of ${w} files reached — remove one to add another.` }) }) }) : /* @__PURE__ */ a(
        "div",
        {
          className: `border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors ${ve ? "border-[var(--color-primary-600)] bg-[var(--color-primary-600)]/10" : "border-[var(--border-color)] hover:border-[var(--color-primary-600)] hover:bg-[var(--bg-hover)]"}`,
          onClick: () => j.current?.click(),
          onKeyDown: (e) => {
            (e.key === "Enter" || e.key === " ") && (e.preventDefault(), j.current?.click());
          },
          role: "button",
          tabIndex: 0,
          onDragOver: He,
          onDragLeave: Ve,
          onDrop: We,
          children: [
            /* @__PURE__ */ t(Se, { className: "w-6 h-6 mx-auto mb-1 text-[var(--text-secondary)]" }),
            /* @__PURE__ */ t("p", { className: "text-sm text-[var(--text-secondary)]", children: ve ? r("tickets.create.dropFilesNow", "Drop files here") : r("tickets.create.uploadAttachments", "Click or drag & drop to add documents") }),
            /* @__PURE__ */ t("p", { className: "text-xs text-[var(--text-muted)] mt-1", children: r("tickets.create.attachmentsHint", "PDF, Word, Excel, TXT, CSV, ZIP (max 10MB each, up to 5 files)") }),
            /* @__PURE__ */ t(
              "input",
              {
                ref: j,
                type: "file",
                multiple: !0,
                accept: Tt,
                onChange: ze,
                className: "hidden"
              }
            )
          ]
        }
      ),
      N.length > 0 && /* @__PURE__ */ t("div", { className: "mt-3 space-y-2", children: N.map((e) => {
        const s = Ct(e.type);
        return /* @__PURE__ */ a(
          "div",
          {
            className: "flex items-center justify-between p-2 rounded-lg bg-[var(--bg-secondary)]",
            children: [
              /* @__PURE__ */ a("div", { className: "flex items-center gap-2 min-w-0", children: [
                /* @__PURE__ */ t(s, { className: "w-4 h-4 text-[var(--text-secondary)] flex-shrink-0" }),
                /* @__PURE__ */ t("span", { className: "text-sm truncate", children: e.name }),
                /* @__PURE__ */ a("span", { className: "text-xs text-[var(--text-muted)] flex-shrink-0", children: [
                  "(",
                  Dt(e.size),
                  ")"
                ] })
              ] }),
              /* @__PURE__ */ t(
                "button",
                {
                  type: "button",
                  onClick: () => Ge(e.id),
                  className: "btn btn-ghost p-1 text-[var(--error-text)]",
                  title: r("tickets.create.removeAttachment", "Remove attachment"),
                  children: /* @__PURE__ */ t(Te, { className: "w-4 h-4" })
                }
              )
            ]
          },
          e.id
        );
      }) })
    ] }),
    b && /* @__PURE__ */ a("div", { className: "border border-[var(--border-color)] rounded-lg p-4", children: [
      /* @__PURE__ */ a("div", { className: "flex items-center justify-between mb-3", children: [
        /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ t(ft, { className: "w-4 h-4 text-[var(--text-secondary)]" }),
          /* @__PURE__ */ t("span", { className: "text-sm font-medium", children: r("tickets.create.systemInfo", "System Information") })
        ] }),
        /* @__PURE__ */ a("label", { className: "flex items-center gap-2 cursor-pointer", children: [
          /* @__PURE__ */ t(
            "input",
            {
              type: "checkbox",
              checked: te,
              onChange: (e) => Fe(e.target.checked),
              className: "rounded border-[var(--border-color)]"
            }
          ),
          /* @__PURE__ */ t("span", { className: "text-xs text-[var(--text-secondary)]", children: r("tickets.create.includeSystemInfo", "Include in ticket") })
        ] })
      ] }),
      /* @__PURE__ */ a("div", { className: `grid grid-cols-2 md:grid-cols-3 gap-3 text-sm ${te ? "" : "opacity-50"}`, children: [
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ a("span", { className: "text-[var(--text-secondary)]", children: [
            r("tickets.create.browser", "Browser"),
            ":"
          ] }),
          /* @__PURE__ */ a("span", { className: "ml-2 font-medium", children: [
            b.browser,
            " ",
            b.browserVersion
          ] })
        ] }),
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ a("span", { className: "text-[var(--text-secondary)]", children: [
            r("tickets.create.os", "OS"),
            ":"
          ] }),
          /* @__PURE__ */ a("span", { className: "ml-2 font-medium", children: [
            b.os,
            " ",
            b.osVersion
          ] })
        ] }),
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ a("span", { className: "text-[var(--text-secondary)]", children: [
            r("tickets.create.device", "Device"),
            ":"
          ] }),
          /* @__PURE__ */ t("span", { className: "ml-2 font-medium", children: b.deviceType })
        ] }),
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ a("span", { className: "text-[var(--text-secondary)]", children: [
            r("tickets.create.screen", "Screen"),
            ":"
          ] }),
          /* @__PURE__ */ t("span", { className: "ml-2 font-medium", children: b.screenResolution })
        ] }),
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ a("span", { className: "text-[var(--text-secondary)]", children: [
            r("tickets.create.language", "Language"),
            ":"
          ] }),
          /* @__PURE__ */ t("span", { className: "ml-2 font-medium", children: b.language })
        ] })
      ] })
    ] }),
    pe && /* @__PURE__ */ a("div", { className: "p-4 rounded-lg bg-[var(--error-bg)] text-[var(--error-text)] flex items-center gap-2", children: [
      /* @__PURE__ */ t(gt, { className: "w-5 h-5" }),
      pe
    ] }),
    /* @__PURE__ */ a("div", { className: "flex items-center justify-between pt-4 border-t border-[var(--border-color)]", children: [
      /* @__PURE__ */ t("button", { onClick: () => L(1), className: "btn btn-secondary", children: r("common:buttons.back", "Back") }),
      /* @__PURE__ */ a(
        "button",
        {
          onClick: Oe,
          disabled: !x.trim() || !y.trim() || me,
          className: "btn btn-primary",
          children: [
            me ? /* @__PURE__ */ t(vt, { className: "w-4 h-4 animate-spin mr-2" }) : /* @__PURE__ */ t(bt, { className: "w-4 h-4 mr-2" }),
            r("tickets.create.submit", "Submit Ticket")
          ]
        }
      )
    ] })
  ] });
  return /* @__PURE__ */ a(
    at,
    {
      title: r("tickets.create.title", "Create New Ticket"),
      subtitle: r("tickets.create.subtitle", "Submit a support request or report an issue"),
      icon: /* @__PURE__ */ t(ct, { className: "w-6 h-6" }),
      contentClassName: "max-w-3xl mx-auto space-y-6",
      actions: /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ a("div", { className: `flex items-center gap-1 text-xs text-[var(--success-text)] transition-opacity duration-300 ${Re ? "opacity-100" : "opacity-0"}`, children: [
          /* @__PURE__ */ t(it, { className: "w-3.5 h-3.5" }),
          /* @__PURE__ */ t("span", { children: r("common:drafts.autoSaved", "Draft saved") })
        ] }),
        o && /* @__PURE__ */ t(
          "button",
          {
            onClick: () => xe(!0),
            className: "btn btn-ghost p-2 text-[var(--text-secondary)] hover:text-[var(--error-text)]",
            title: r("common:drafts.discard", "Discard draft"),
            children: /* @__PURE__ */ t(we, { className: "w-4 h-4" })
          }
        )
      ] }),
      children: [
        g ? /* @__PURE__ */ a("div", { className: "mb-6 p-4 rounded-lg bg-[var(--info-bg)] border border-[var(--info-border)]", children: [
          /* @__PURE__ */ a("div", { className: "flex items-center gap-3 mb-3", children: [
            /* @__PURE__ */ t(st, { className: "w-5 h-5 text-[var(--info-text)] flex-shrink-0" }),
            /* @__PURE__ */ t("p", { className: "font-medium text-[var(--info-text)]", children: r("glpi.cannotCreateTicket", "Tickets are managed by GLPI. Please create tickets directly in GLPI.") })
          ] }),
          p && /* @__PURE__ */ a(
            "a",
            {
              href: p,
              target: "_blank",
              rel: "noopener noreferrer",
              className: "btn btn-primary inline-flex items-center gap-2",
              children: [
                /* @__PURE__ */ t(nt, { className: "w-4 h-4" }),
                r("glpi.openGlpi")
              ]
            }
          )
        ] }) : /* @__PURE__ */ a(Qe, { children: [
          /* @__PURE__ */ a("div", { className: "flex items-center gap-4 mb-8", children: [
            /* @__PURE__ */ a("div", { className: `flex items-center gap-2 ${S >= 1 ? "text-[var(--color-primary-600)]" : "text-[var(--text-secondary)]"}`, children: [
              /* @__PURE__ */ t("div", { className: `w-8 h-8 rounded-full flex items-center justify-center ${S >= 1 ? "bg-[var(--color-primary-600)] text-white" : "bg-[var(--bg-secondary)]"}`, children: "1" }),
              /* @__PURE__ */ t("span", { className: "font-medium", children: r("tickets.create.stepSelectType", "Select Type") })
            ] }),
            /* @__PURE__ */ t("div", { className: `flex-1 h-0.5 ${S >= 2 ? "bg-[var(--color-primary-600)]" : "bg-[var(--border-color)]"}` }),
            /* @__PURE__ */ a("div", { className: `flex items-center gap-2 ${S >= 2 ? "text-[var(--color-primary-600)]" : "text-[var(--text-secondary)]"}`, children: [
              /* @__PURE__ */ t("div", { className: `w-8 h-8 rounded-full flex items-center justify-center ${S >= 2 ? "bg-[var(--color-primary-600)] text-white" : "bg-[var(--bg-secondary)]"}`, children: "2" }),
              /* @__PURE__ */ t("span", { className: "font-medium", children: r("tickets.create.stepDetails", "Details") })
            ] })
          ] }),
          F && !m && /* @__PURE__ */ a("div", { className: "mb-4 p-3 rounded-lg bg-[var(--info-bg)] border border-[var(--info-border)] flex items-center justify-between", children: [
            /* @__PURE__ */ a("div", { className: "flex items-center gap-2 text-sm text-[var(--info-text)]", children: [
              /* @__PURE__ */ t(ie, { className: "w-4 h-4" }),
              /* @__PURE__ */ t("span", { children: r("support:tickets.tenantPicker.creatingFor", "Creating ticket for:") }),
              /* @__PURE__ */ t("span", { className: "font-semibold", children: F.name })
            ] }),
            /* @__PURE__ */ t(
              "button",
              {
                onClick: () => K(!0),
                className: "text-xs text-[var(--info-text)] underline hover:no-underline",
                children: r("common:actions.change", "Change")
              }
            )
          ] }),
          /* @__PURE__ */ a("div", { className: "card p-6", children: [
            S === 1 && _e(),
            S === 2 && Xe()
          ] })
        ] }),
        Be && /* @__PURE__ */ t("div", { className: "fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50 p-4", children: /* @__PURE__ */ a("div", { className: "card w-full max-w-md p-6", children: [
          /* @__PURE__ */ a("div", { className: "flex items-center gap-3 mb-4", children: [
            /* @__PURE__ */ t("div", { className: "w-10 h-10 rounded-full bg-[var(--error-bg)] flex items-center justify-center", children: /* @__PURE__ */ t(we, { className: "w-5 h-5 text-[var(--error-text)]" }) }),
            /* @__PURE__ */ t("h2", { className: "text-xl font-bold", children: r("common:drafts.discardConfirmTitle", "Discard draft?") })
          ] }),
          /* @__PURE__ */ t("p", { className: "text-[var(--text-secondary)] mb-6", children: r("common:drafts.discardConfirmMessage", "This draft will be permanently deleted. This action cannot be undone.") }),
          /* @__PURE__ */ a("div", { className: "flex justify-end gap-3", children: [
            /* @__PURE__ */ t("button", { onClick: () => xe(!1), className: "btn btn-secondary", children: r("common:actions.cancel", "Cancel") }),
            /* @__PURE__ */ t("button", { onClick: je, className: "btn bg-[var(--error-text)] text-white hover:opacity-90", children: r("common:drafts.discard", "Discard") })
          ] })
        ] }) }),
        Ae && /* @__PURE__ */ t("div", { className: "fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50 p-4", children: /* @__PURE__ */ a("div", { className: "card w-full max-w-md p-6", children: [
          /* @__PURE__ */ a("div", { className: "flex items-center gap-3 mb-4", children: [
            /* @__PURE__ */ t("div", { className: "w-10 h-10 rounded-full bg-[var(--info-bg)] flex items-center justify-center", children: /* @__PURE__ */ t(ie, { className: "w-5 h-5 text-[var(--info-text)]" }) }),
            /* @__PURE__ */ a("div", { children: [
              /* @__PURE__ */ t("h2", { className: "text-xl font-bold", children: r("support:tickets.tenantPicker.title", "Select Workspace") }),
              /* @__PURE__ */ t("p", { className: "text-sm text-[var(--text-secondary)]", children: r("support:tickets.tenantPicker.description", "Choose a workspace to create the ticket in") })
            ] })
          ] }),
          /* @__PURE__ */ t("div", { className: "space-y-2 max-h-64 overflow-y-auto", children: P.filter((e) => e.status === "Active").map((e) => /* @__PURE__ */ t(
            "button",
            {
              onClick: () => {
                de(e), K(!1);
                const s = o || se();
                s && R.updateDraft(s, {
                  tenantId: e.id,
                  tenantSlug: e.slug,
                  tenantName: e.name
                });
              },
              className: `w-full p-3 rounded-lg border text-left transition-colors hover:bg-[var(--bg-hover)] ${F?.id === e.id ? "border-[var(--color-primary-600)] bg-[var(--color-primary-600)]/10" : "border-[var(--border-color)]"}`,
              children: /* @__PURE__ */ a("div", { className: "flex items-center gap-3", children: [
                /* @__PURE__ */ t(ie, { className: "w-5 h-5 text-[var(--text-secondary)]" }),
                /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
                  /* @__PURE__ */ t("div", { className: "font-medium truncate", children: e.name }),
                  e.organisationName && /* @__PURE__ */ t("div", { className: "text-xs text-[var(--text-secondary)] truncate", children: e.organisationName })
                ] }),
                /* @__PURE__ */ t("span", { className: `text-xs px-2 py-0.5 rounded-full ${e.type === "Personal" ? "bg-[var(--info-bg)] text-[var(--info-text)]" : "bg-[var(--success-bg)] text-[var(--success-text)]"}`, children: e.type === "Personal" ? r("common:tenant.personal", "Personal") : r("common:tenant.business", "Business") })
              ] })
            },
            e.id
          )) }),
          /* @__PURE__ */ t("div", { className: "flex justify-end gap-3 mt-4 pt-4 border-t border-[var(--border-color)]", children: /* @__PURE__ */ t(
            "button",
            {
              onClick: () => {
                K(!1), E || n(-1);
              },
              className: "btn btn-secondary",
              children: r("common:actions.cancel", "Cancel")
            }
          ) })
        ] }) })
      ]
    }
  );
}
export {
  Lt as UserCreateTicketPage
};
//# sourceMappingURL=UserCreateTicketPage-qlSb_5PN.js.map
