import { jsx as e, jsxs as s } from "react/jsx-runtime";
import { useState as y, useCallback as S, useMemo as H, useEffect as X } from "react";
import { useParams as Me, useNavigate as Te } from "react-router-dom";
import { u as ke } from "./useTabNavigation-Bsbskz0i.js";
import { useTranslation as z } from "react-i18next";
import { i as C, k as Ce, h as Le, B as Be } from "./index-Dh9kUeDn.js";
import * as Re from "lucide-react";
import { Loader2 as W, Save as ee, GripVertical as Pe, Layers as Z, ChevronDown as Ee, ChevronRight as Fe, Edit as Ie, Shield as te, Eye as qe, Globe as ae, Building2 as Ue, User as Oe, Settings as $e, Users as ze, Inbox as We, AlertCircle as je, ArrowLeft as Ge, PowerOff as Ke, Power as Ve, AlertTriangle as He, CheckCircle as Ze } from "lucide-react";
import { useSensors as _e, useSensor as Y, PointerSensor as Je, KeyboardSensor as Qe, DndContext as Xe, closestCenter as Ye } from "@dnd-kit/core";
import { sortableKeyboardCoordinates as et, SortableContext as tt, verticalListSortingStrategy as at, arrayMove as st, useSortable as rt } from "@dnd-kit/sortable";
import { CSS as it } from "@dnd-kit/utilities";
import { u as nt, A as lt } from "./useAccessRequests-CaduUjYH.js";
function _(t, n = "w-4 h-4") {
  if (!t) return null;
  if (typeof t == "string") {
    const u = Re[t];
    return u ? /* @__PURE__ */ e(u, { className: n }) : null;
  }
  return /* @__PURE__ */ e(t, { className: n });
}
function ot() {
  const { t } = z("admin"), [n, a] = y(null), [m, u] = y(!1), [o, d] = y(!1), [l, w] = y(null), [r, b] = y(null), [A, i] = y({
    label: "",
    description: "",
    icon: "",
    route: "",
    displayOrder: 0
  }), T = S(async (h) => {
    if (h) {
      u(!0), w(null);
      try {
        const p = await C.applications.getById(h);
        a(p), i({
          label: p.label,
          description: p.description || "",
          icon: p.icon || "",
          route: p.route || "",
          displayOrder: p.displayOrder
        });
      } catch (p) {
        w(p instanceof Error ? p.message : t("applicationDetail.errors.loadFailed"));
      } finally {
        u(!1);
      }
    }
  }, [t]), P = S(async (h, p) => {
    if (!(!h || !n)) {
      d(!0), w(null), b(null);
      try {
        const N = {
          label: p.label,
          description: p.description || void 0,
          icon: p.icon || void 0,
          route: p.route || void 0,
          displayOrder: p.displayOrder
        };
        await C.applications.update(h, N), b(t("applicationDetail.success.saved")), await T(h);
      } catch (N) {
        w(N instanceof Error ? N.message : t("applicationDetail.errors.saveFailed"));
      } finally {
        d(!1);
      }
    }
  }, [n, t, T]), R = S(async (h) => {
    if (!(!h || !n)) {
      d(!0), w(null), b(null);
      try {
        n.isActive ? await C.applications.deactivate(h) : await C.applications.activate(h), b(
          n.isActive ? t("applicationDetail.success.deactivated") : t("applicationDetail.success.activated")
        ), await T(h);
      } catch (p) {
        w(p instanceof Error ? p.message : t("applicationDetail.errors.toggleFailed"));
      } finally {
        d(!1);
      }
    }
  }, [n, t, T]);
  return {
    application: n,
    loading: m,
    saving: o,
    error: l,
    success: r,
    formData: A,
    setFormData: i,
    setError: w,
    setSuccess: b,
    loadApplication: T,
    handleSaveInfo: P,
    handleToggleStatus: R
  };
}
function ct() {
  const [t, n] = y(/* @__PURE__ */ new Set()), [a, m] = y(/* @__PURE__ */ new Map()), [u, o] = y(/* @__PURE__ */ new Set()), [d, l] = y(!1), [w, r] = y(null), [b, A] = y({
    code: "",
    label: "",
    description: "",
    icon: "",
    route: "",
    displayOrder: 0
  }), [i, T] = y(!1), P = S(async (k, c) => {
    const B = !t.has(c);
    if (n((D) => {
      const M = new Set(D);
      return M.has(c) ? M.delete(c) : M.add(c), M;
    }), B && !a.has(c)) {
      o((D) => new Set(D).add(c));
      try {
        const D = await C.applications.getModuleSections(k, c);
        m((M) => new Map(M).set(c, D));
      } catch (D) {
        console.error("Failed to load sections:", D);
      } finally {
        o((D) => {
          const M = new Set(D);
          return M.delete(c), M;
        });
      }
    }
  }, [t, a]), R = S(async (k, c, B) => {
    try {
      await C.applications.updateModule(k, c, {
        label: B.label,
        description: B.description || void 0,
        icon: B.icon || void 0,
        route: B.route || void 0,
        displayOrder: B.displayOrder
      }), T(!1), r(null), E();
    } catch (D) {
      throw console.error("Failed to save module:", D), D;
    }
  }, []), h = S(async (k, c) => {
    const B = c.map((D, M) => ({ ...D, displayOrder: M }));
    l(!0);
    try {
      await C.applications.reorderModules(k, B.map((D, M) => ({ id: D.id, displayOrder: M })));
    } catch (D) {
      throw console.error("Failed to reorder modules:", D), D;
    } finally {
      l(!1);
    }
  }, []), p = S(async (k, c, B) => {
    const D = B.map((M, F) => ({ ...M, displayOrder: F }));
    m((M) => new Map(M).set(c, D)), l(!0);
    try {
      await C.applications.reorderSections(k, c, D.map((M, F) => ({ id: M.id, displayOrder: F })));
    } catch (M) {
      console.error("Failed to reorder sections:", M);
      try {
        const F = await C.applications.getModuleSections(k, c);
        m(($) => new Map($).set(c, F));
      } catch (F) {
        console.error("Failed to reload sections:", F);
      }
      throw M;
    } finally {
      l(!1);
    }
  }, []), N = S((k) => {
    r(k), A({
      code: k.code,
      label: k.label,
      description: k.description || "",
      icon: k.icon || "",
      route: k.route || "",
      displayOrder: k.displayOrder
    }), T(!0);
  }, []), E = S((k) => {
    A({
      code: "",
      label: "",
      description: "",
      icon: "",
      route: "",
      displayOrder: k || 0
    });
  }, []);
  return {
    expandedModules: t,
    moduleSections: a,
    loadingSections: u,
    reordering: d,
    editingModule: w,
    moduleFormData: b,
    showModuleForm: i,
    toggleModuleExpand: P,
    handleSaveModule: R,
    handleModulesReorder: h,
    handleSectionsReorder: p,
    startEditModule: N,
    resetModuleForm: E,
    setShowModuleForm: T,
    setEditingModule: r,
    setModuleFormData: A
  };
}
const dt = (t, n, a) => {
  const m = n.filter((u) => u.permissionIds.includes(t.id)).map((u) => a.find((o) => o.id === u.id)).filter(Boolean);
  return { permission: t, roles: m };
};
function pt() {
  const [t, n] = y([]), [a, m] = y([]), [u, o] = y([]), d = S(async (r) => {
    try {
      const [b, A] = await Promise.all([
        C.permissions.getMatrix(),
        C.roles.getAll()
      ]), i = `${r.code}.`.toLowerCase(), T = b.permissions.filter(
        (R) => R.path.toLowerCase().startsWith(i)
      );
      m(T), n(A);
      const P = T.map(
        (R) => dt(R, b.roles, A)
      );
      o(P);
    } catch (b) {
      throw console.error("Failed to load permissions data:", b), b;
    }
  }, []), l = S(async () => {
    try {
      const r = await C.roles.getAll();
      n(r);
    } catch (r) {
      throw console.error("Failed to load roles:", r), r;
    }
  }, []), w = H(() => {
    if (u.length === 0) return [];
    const r = /* @__PURE__ */ new Map();
    return u.forEach(({ permission: b, roles: A }) => {
      A.forEach((i) => {
        r.has(i.id) || r.set(i.id, { role: i, permissions: [] }), r.get(i.id).permissions.push(b);
      });
    }), Array.from(r.values()).sort(
      (b, A) => A.permissions.length - b.permissions.length
    );
  }, [u]);
  return {
    roles: t,
    permissions: a,
    permissionsWithRoles: u,
    rolesWithAppAccess: w,
    loadPermissionsData: d,
    loadRolesData: l
  };
}
const ut = (t, n) => {
  if (t.id !== n) return t;
  const a = !t.isAssigned;
  return {
    ...t,
    isAssigned: a,
    sections: t.sections.map((m) => ({ ...m, isAssigned: a }))
  };
}, mt = (t, n, a) => {
  if (t.id !== n) return t;
  const m = t.sections.map(
    (o) => o.id === a ? { ...o, isAssigned: !o.isAssigned } : o
  ), u = m.every((o) => o.isAssigned);
  return {
    ...t,
    isAssigned: u,
    sections: m
  };
}, vt = (t) => ({
  ...t,
  isAssigned: !0,
  sections: t.sections.map((n) => ({ ...n, isAssigned: !0 }))
}), bt = (t) => ({
  ...t,
  isAssigned: !1,
  sections: t.sections.map((n) => ({ ...n, isAssigned: !1 }))
});
function gt() {
  const [t, n] = y([]), [a, m] = y([]), [u, o] = y(!1), [d, l] = y([]), [w, r] = y("FullAccess"), [b, A] = y(""), [i, T] = y(!1), [P, R] = y(null), [h, p] = y("full"), [N, E] = y([]), [k, c] = y(/* @__PURE__ */ new Set()), [B, D] = y(!1), [M, F] = y(!1), [$, J] = y("merge"), [re, G] = y(!1), [ie, Q] = y({ modules: 0, sections: 0 }), [j, ne] = y(!1), [le, oe] = y(!1), I = S(async (g) => {
    try {
      const [v, x] = await Promise.all([
        C.applications.getTenants(g),
        C.applications.getAvailableTenants(g)
      ]);
      n(v), m(x.tenants), oe(x.isInDefaultPersonalTemplate);
    } catch (v) {
      console.error("Failed to load publication data:", v);
    }
  }, []), ce = S(async (g) => {
    D(!0);
    try {
      const v = await C.applications.getModules(g), x = [];
      for (const f of v) {
        const q = (await C.applications.getModuleSections(g, f.id)).map((O) => ({
          id: O.id,
          label: O.label,
          code: O.code,
          icon: O.icon,
          isAssigned: !0
        }));
        x.push({
          id: f.id,
          label: f.label,
          code: f.code,
          icon: f.icon,
          isAssigned: !0,
          sections: q
        });
      }
      E(x);
    } catch (v) {
      console.error("Failed to load bulk modules:", v);
    } finally {
      D(!1);
    }
  }, []), de = S((g) => {
    c((v) => {
      const x = new Set(v);
      return x.has(g) ? x.delete(g) : x.add(g), x;
    });
  }, []), pe = S((g) => {
    E((v) => v.map((x) => ut(x, g)));
  }, []), ue = S((g, v) => {
    E((x) => x.map((f) => mt(f, g, v)));
  }, []), me = S((g) => {
    const v = g.sections.filter((x) => x.isAssigned).length;
    return v === 0 ? "unchecked" : v === g.sections.length ? "checked" : "indeterminate";
  }, []), ve = S(() => {
    const g = N.length, v = N.filter((L) => L.isAssigned || L.sections.some((q) => q.isAssigned)).length, x = N.reduce((L, q) => L + q.sections.length, 0), f = N.reduce((L, q) => L + q.sections.filter((O) => O.isAssigned).length, 0);
    return { totalModules: g, assignedModules: v, totalSections: x, assignedSections: f };
  }, [N]), be = S(() => {
    E((g) => g.map((v) => vt(v)));
  }, []), ge = S(() => {
    E((g) => g.map((v) => bt(v)));
  }, []), xe = S((g) => {
    l(
      (v) => v.includes(g) ? v.filter((x) => x !== g) : [...v, g]
    );
  }, []), he = S(() => {
    if (M) {
      const g = t.filter((v) => {
        const x = v.tenantName.toLowerCase().includes(b.toLowerCase()) || v.tenantSlug.toLowerCase().includes(b.toLowerCase()), f = j || v.tenantType !== "Personal";
        return x && f;
      }).map((v) => v.tenantId);
      l(g);
    } else {
      const g = a.filter((v) => {
        const x = v.name.toLowerCase().includes(b.toLowerCase()) || v.slug.toLowerCase().includes(b.toLowerCase()), f = j || v.type !== "Personal";
        return x && f;
      }).map((v) => v.id);
      l(g);
    }
  }, [M, t, a, b, j]), fe = S(() => {
    l([]);
  }, []), K = S(
    async (g, v) => {
      if (!(!g || d.length === 0))
        try {
          const x = {
            tenantIds: d,
            accessLevel: w,
            accessMode: h,
            mergeMode: $
          };
          h === "custom" && (x.moduleIds = N.filter((f) => f.isAssigned).map((f) => f.id), x.sectionIds = N.flatMap(
            (f) => f.sections.filter((L) => L.isAssigned).map((L) => L.id)
          )), await C.applications.bulkAssignTenants(g, x), o(!1), l([]), r("FullAccess"), p("full"), A(""), F(!1), J("merge"), G(!1), await I(g), v && v();
        } catch (x) {
          throw console.error("Failed to update tenant assignments:", x), x;
        }
    },
    [d, w, h, $, N, I]
  ), ye = S(
    async (g, v) => {
      if (!(!g || d.length === 0))
        try {
          const x = {
            tenantIds: d,
            accessLevel: w,
            accessMode: h
          };
          h === "custom" && (x.moduleIds = N.filter((f) => f.isAssigned).map((f) => f.id), x.sectionIds = N.flatMap(
            (f) => f.sections.filter((L) => L.isAssigned).map((L) => L.id)
          )), await C.applications.bulkAssignTenants(g, x), o(!1), l([]), r("FullAccess"), p("full"), A(""), await I(g), v && v();
        } catch (x) {
          throw console.error("Failed to assign tenants:", x), x;
        }
    },
    [d, w, h, N, I]
  ), Ne = S(
    async (g, v) => {
      if (!(!g || d.length === 0)) {
        if ($ === "replace" && h === "custom") {
          let x = 0, f = 0;
          for (const L of d)
            try {
              const q = await C.tenants.getModules(L), O = await C.tenants.getSections(L), De = new Set(N.filter((U) => U.isAssigned).map((U) => U.id)), Se = new Set(N.flatMap((U) => U.sections.filter((V) => V.isAssigned).map((V) => V.id)));
              x += q.filter((U) => !De.has(U.moduleId)).length, f += O.filter((U) => !Se.has(U.sectionId)).length;
            } catch {
            }
          if (x > 0 || f > 0) {
            Q({ modules: x, sections: f }), G(!0);
            return;
          }
        }
        await K(g, v);
      }
    },
    [
      d,
      $,
      h,
      N,
      K
    ]
  ), we = S(
    async (g, v, x) => {
      if (g)
        try {
          await C.applications.removeFromTenant(g, v), await I(g), x && x();
        } catch (f) {
          throw console.error("Failed to remove tenant:", f), f;
        }
    },
    [I]
  ), Ae = S(
    async (g, v, x, f) => {
      if (g)
        try {
          await C.applications.updateTenantAccessLevel(g, v, x), await I(g), f && f();
        } catch (L) {
          throw console.error("Failed to update access level:", L), L;
        }
    },
    [I]
  );
  return {
    // State
    assignedTenants: t,
    availableTenants: a,
    showAssignModal: u,
    selectedTenantIds: d,
    selectedAccessLevel: w,
    tenantSearch: b,
    showCustomizeDrawer: i,
    customizingTenant: P,
    bulkAccessMode: h,
    bulkModules: N,
    bulkExpandedModules: k,
    loadingBulkModules: B,
    isUpdateMode: M,
    updateMergeMode: $,
    showConfirmRemovalDialog: re,
    pendingRemovals: ie,
    includePersonalTenants: j,
    isInDefaultPersonalTemplate: le,
    // Setters
    setAssignedTenants: n,
    setAvailableTenants: m,
    setShowAssignModal: o,
    setSelectedTenantIds: l,
    setSelectedAccessLevel: r,
    setTenantSearch: A,
    setShowCustomizeDrawer: T,
    setCustomizingTenant: R,
    setBulkAccessMode: p,
    setBulkModules: E,
    setBulkExpandedModules: c,
    setIsUpdateMode: F,
    setUpdateMergeMode: J,
    setShowConfirmRemovalDialog: G,
    setPendingRemovals: Q,
    setIncludePersonalTenants: ne,
    // Operations
    loadPublicationData: I,
    loadBulkModules: ce,
    toggleBulkModuleExpand: de,
    toggleBulkModule: pe,
    toggleBulkSection: ue,
    getBulkModuleCheckState: me,
    getBulkStats: ve,
    selectAllBulkModules: be,
    clearBulkModules: ge,
    toggleTenantSelection: xe,
    selectAllFilteredTenants: he,
    clearTenantSelection: fe,
    handleAssignTenants: ye,
    handleUpdateTenants: Ne,
    executeUpdateTenants: K,
    handleRemoveTenant: we,
    handleUpdateAccessLevel: Ae
  };
}
function xt({
  formData: t,
  setFormData: n,
  application: a,
  saving: m,
  onSubmit: u
}) {
  const { t: o } = z("admin");
  return /* @__PURE__ */ s("form", { onSubmit: u, className: "space-y-6", children: [
    /* @__PURE__ */ s("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-6", children: [
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: o("applicationDetail.fields.code") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: a.code,
            disabled: !0,
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-tertiary)] border border-[var(--border-color)] text-[var(--text-muted)] cursor-not-allowed"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: o("applicationDetail.fields.label") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: t.label,
            onChange: (d) => n((l) => ({ ...l, label: d.target.value })),
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent",
            required: !0
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { className: "md:col-span-2", children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: o("applicationDetail.fields.description") }),
        /* @__PURE__ */ e(
          "textarea",
          {
            value: t.description,
            onChange: (d) => n((l) => ({ ...l, description: d.target.value })),
            rows: 3,
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: o("applicationDetail.fields.icon") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: t.icon,
            onChange: (d) => n((l) => ({ ...l, icon: d.target.value })),
            placeholder: o("applicationDetail.fields.icon"),
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: o("applicationDetail.fields.route") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: t.route,
            onChange: (d) => n((l) => ({ ...l, route: d.target.value })),
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: o("applicationDetail.fields.displayOrder") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "number",
            value: t.displayOrder,
            onChange: (d) => n((l) => ({
              ...l,
              displayOrder: parseInt(d.target.value) || 0
            })),
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: o("applicationDetail.fields.zone", "Zone") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: a.zone || "",
            disabled: !0,
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-tertiary)] border border-[var(--border-color)] text-[var(--text-muted)] cursor-not-allowed"
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ e("div", { className: "flex justify-end", children: /* @__PURE__ */ s(
      "button",
      {
        type: "submit",
        disabled: m,
        className: "flex items-center gap-2 px-6 py-2 rounded-[var(--radius-button)] font-medium bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] disabled:opacity-50",
        children: [
          m ? /* @__PURE__ */ e(W, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(ee, { className: "w-4 h-4" }),
          o("applicationDetail.actions.save")
        ]
      }
    ) })
  ] });
}
function ht({ id: t, disabled: n, children: a }) {
  const {
    attributes: m,
    listeners: u,
    setNodeRef: o,
    transform: d,
    transition: l,
    isDragging: w
  } = rt({ id: t, disabled: n }), r = {
    transform: it.Transform.toString(d),
    transition: l,
    opacity: w ? 0.5 : 1,
    zIndex: w ? 1 : 0
  }, b = n ? null : /* @__PURE__ */ e(
    "button",
    {
      type: "button",
      className: "p-1.5 rounded hover:bg-[var(--bg-hover)] cursor-grab active:cursor-grabbing text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors",
      ...m,
      ...u,
      children: /* @__PURE__ */ e(Pe, { className: "w-4 h-4" })
    }
  );
  return /* @__PURE__ */ e("div", { ref: o, style: r, children: a(b) });
}
function se({
  items: t,
  onReorder: n,
  renderItem: a,
  disabled: m = !1
}) {
  const [, u] = y(null), o = _e(
    Y(Je, {
      activationConstraint: {
        distance: 8
      }
    }),
    Y(Qe, {
      coordinateGetter: et
    })
  );
  return /* @__PURE__ */ e(
    Xe,
    {
      sensors: o,
      collisionDetection: Ye,
      onDragStart: (l) => u(l.active.id),
      onDragEnd: (l) => {
        const { active: w, over: r } = l;
        if (u(null), r && w.id !== r.id) {
          const b = t.findIndex((T) => T.id === w.id), A = t.findIndex((T) => T.id === r.id), i = st(t, b, A);
          n(i);
        }
      },
      children: /* @__PURE__ */ e(
        tt,
        {
          items: t.map((l) => l.id),
          strategy: at,
          disabled: m,
          children: /* @__PURE__ */ e("div", { className: "space-y-2", children: t.map((l) => /* @__PURE__ */ e(ht, { id: l.id, disabled: m, children: (w) => a(l, w) }, l.id)) })
        }
      )
    }
  );
}
const ft = (t, n, a, m, u, o) => n.has(t) ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ e(W, { className: "w-5 h-5 animate-spin text-[var(--text-muted)]" }) }) : a.get(t)?.length === 0 ? /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)] py-2", children: o("applicationDetail.modules.noSections", "No sections") }) : a.get(t) ? /* @__PURE__ */ e(
  se,
  {
    items: a.get(t).map((d) => ({ ...d, id: d.id })),
    onReorder: (d) => m(t, d),
    disabled: u,
    renderItem: (d, l) => /* @__PURE__ */ s("div", { className: "flex items-center gap-2 p-2 rounded bg-[var(--bg-secondary)] border border-[var(--border-color)]", children: [
      l,
      /* @__PURE__ */ e("div", { className: "p-1 rounded bg-[var(--bg-tertiary)]", children: _(d.icon, "w-3 h-3") || /* @__PURE__ */ e(Z, { className: "w-3 h-3 text-[var(--text-muted)]" }) }),
      /* @__PURE__ */ s("div", { className: "flex-1", children: [
        /* @__PURE__ */ e("p", { className: "text-sm font-medium text-[var(--text-primary)]", children: d.label }),
        /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-muted)]", children: d.code })
      ] }),
      /* @__PURE__ */ e(
        "span",
        {
          className: `px-2 py-0.5 text-xs rounded-full ${d.isActive ? "bg-[var(--success-bg)] text-[var(--success-text)]" : "bg-[var(--error-bg)] text-[var(--error-text)]"}`,
          children: d.isActive ? o("common:active") : o("common:inactive")
        }
      )
    ] })
  }
) : null;
function yt({
  application: t,
  expandedModules: n,
  moduleSections: a,
  loadingSections: m,
  reordering: u,
  editingModule: o,
  moduleFormData: d,
  showModuleForm: l,
  saving: w,
  onToggleExpand: r,
  onStartEdit: b,
  onSaveModule: A,
  onCancelEdit: i,
  onModulesReorder: T,
  onSectionsReorder: P,
  setModuleFormData: R
}) {
  const { t: h } = z("admin");
  return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
    /* @__PURE__ */ s("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
      h("applicationDetail.modules.title"),
      " (",
      t.modules.length,
      ")"
    ] }),
    l && o && /* @__PURE__ */ s("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--border-color)]", children: [
      /* @__PURE__ */ e("h4", { className: "text-md font-semibold text-[var(--text-primary)] mb-4", children: h("applicationDetail.modules.edit") }),
      /* @__PURE__ */ s("form", { onSubmit: A, className: "space-y-4", children: [
        /* @__PURE__ */ s("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
          /* @__PURE__ */ s("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: h("applicationDetail.fields.code") }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: d.code,
                disabled: !0,
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-tertiary)] border border-[var(--border-color)] text-[var(--text-muted)] cursor-not-allowed"
              }
            )
          ] }),
          /* @__PURE__ */ s("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: h("applicationDetail.fields.label") }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: d.label,
                onChange: (p) => R((N) => ({ ...N, label: p.target.value })),
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)]",
                required: !0
              }
            )
          ] }),
          /* @__PURE__ */ s("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: h("applicationDetail.fields.icon") }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: d.icon,
                onChange: (p) => R((N) => ({ ...N, icon: p.target.value })),
                placeholder: "Users",
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)]"
              }
            )
          ] }),
          /* @__PURE__ */ s("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: h("applicationDetail.fields.route") }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: d.route,
                onChange: (p) => R((N) => ({ ...N, route: p.target.value })),
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)]"
              }
            )
          ] }),
          /* @__PURE__ */ s("div", { className: "md:col-span-2", children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: h("applicationDetail.fields.description") }),
            /* @__PURE__ */ e(
              "textarea",
              {
                value: d.description,
                onChange: (p) => R((N) => ({ ...N, description: p.target.value })),
                rows: 2,
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)]"
              }
            )
          ] })
        ] }),
        /* @__PURE__ */ s("div", { className: "flex justify-end gap-2", children: [
          /* @__PURE__ */ e(
            "button",
            {
              type: "button",
              onClick: i,
              className: "px-4 py-2 rounded-[var(--radius-button)] font-medium text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]",
              children: h("common:cancel")
            }
          ),
          /* @__PURE__ */ s(
            "button",
            {
              type: "submit",
              disabled: w,
              className: "flex items-center gap-2 px-4 py-2 rounded-[var(--radius-button)] font-medium bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] disabled:opacity-50",
              children: [
                w ? /* @__PURE__ */ e(W, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(ee, { className: "w-4 h-4" }),
                h("common:save")
              ]
            }
          )
        ] })
      ] })
    ] }),
    t.modules.length === 0 ? /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-muted)]", children: h("applicationDetail.modules.empty") }) : /* @__PURE__ */ e(
      se,
      {
        items: t.modules.map((p) => ({ ...p, id: p.id })),
        onReorder: T,
        disabled: u,
        renderItem: (p, N) => /* @__PURE__ */ s("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--item-color-border)] hover:border-[var(--color-accent-600)] transition-colors", children: [
          /* @__PURE__ */ s("div", { className: "flex items-center justify-between", children: [
            /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
              N,
              /* @__PURE__ */ e("div", { className: "p-2 rounded-[var(--radius-button)] bg-[var(--bg-tertiary)]", children: _(p.icon, "w-4 h-4") || /* @__PURE__ */ e(Z, { className: "w-4 h-4 text-[var(--text-muted)]" }) }),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => r(p.id),
                  className: "p-1 rounded hover:bg-[var(--bg-hover)]",
                  "aria-expanded": n.has(p.id),
                  "aria-label": h("applicationDetail.modules.toggleExpand", "Toggle sections"),
                  children: n.has(p.id) ? /* @__PURE__ */ e(Ee, { className: "w-4 h-4 text-[var(--text-muted)]" }) : /* @__PURE__ */ e(Fe, { className: "w-4 h-4 text-[var(--text-muted)]" })
                }
              ),
              /* @__PURE__ */ s("div", { children: [
                /* @__PURE__ */ e("p", { className: "font-medium text-[var(--text-primary)]", children: p.label }),
                /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)]", children: p.code })
              ] }),
              /* @__PURE__ */ e(
                "span",
                {
                  className: `ml-2 px-2 py-0.5 text-xs font-medium rounded-full ${p.isActive ? "bg-[var(--success-bg)] text-[var(--success-text)]" : "bg-[var(--error-bg)] text-[var(--error-text)]"}`,
                  children: p.isActive ? h("common:active") : h("common:inactive")
                }
              )
            ] }),
            /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ s("span", { className: "text-sm text-[var(--text-muted)]", children: [
                p.sectionsCount,
                " ",
                h("applicationDetail.modules.sections", "sections")
              ] }),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => b(p),
                  className: "p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] text-[var(--text-secondary)]",
                  "aria-label": h("applicationDetail.modules.edit"),
                  children: /* @__PURE__ */ e(Ie, { className: "w-4 h-4" })
                }
              )
            ] })
          ] }),
          n.has(p.id) && /* @__PURE__ */ s("div", { className: "mt-3 pl-10 pt-3 border-t border-[var(--border-color)]", children: [
            /* @__PURE__ */ s("div", { className: "grid grid-cols-2 gap-4 text-sm mb-4", children: [
              /* @__PURE__ */ s("div", { children: [
                /* @__PURE__ */ s("span", { className: "text-[var(--text-muted)]", children: [
                  h("applicationDetail.fields.description"),
                  ":"
                ] }),
                /* @__PURE__ */ e("p", { className: "text-[var(--text-primary)]", children: p.description || "-" })
              ] }),
              /* @__PURE__ */ s("div", { children: [
                /* @__PURE__ */ s("span", { className: "text-[var(--text-muted)]", children: [
                  h("applicationDetail.fields.route"),
                  ":"
                ] }),
                /* @__PURE__ */ e("p", { className: "text-[var(--text-primary)] font-mono", children: p.route || "-" })
              ] })
            ] }),
            /* @__PURE__ */ s("div", { className: "mt-4", children: [
              /* @__PURE__ */ s("h5", { className: "text-sm font-medium text-[var(--text-secondary)] mb-2", children: [
                h("applicationDetail.modules.sections", "Sections"),
                " (",
                p.sectionsCount,
                ")"
              ] }),
              ft(p.id, m, a, P, u, h)
            ] })
          ] })
        ] })
      }
    )
  ] });
}
function Nt({
  application: t,
  permissions: n,
  permissionsWithRoles: a
}) {
  const { t: m } = z("admin");
  return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
    /* @__PURE__ */ s("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
      m("applicationDetail.permissions.title"),
      " (",
      n.length,
      ")"
    ] }),
    /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)]", children: m("applicationDetail.permissions.description", {
      path: `${t.code}.*`
    }) }),
    n.length === 0 ? /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-muted)]", children: m("applicationDetail.permissions.empty") }) : /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ s("table", { className: "w-full", children: [
      /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ s("tr", { className: "border-b border-[var(--border-color)]", children: [
        /* @__PURE__ */ e("th", { className: "text-left py-3 px-4 text-sm font-medium text-[var(--text-secondary)]", children: m("applicationDetail.permissions.path") }),
        /* @__PURE__ */ e("th", { className: "text-left py-3 px-4 text-sm font-medium text-[var(--text-secondary)]", children: m("applicationDetail.permissions.action") }),
        /* @__PURE__ */ e("th", { className: "text-left py-3 px-4 text-sm font-medium text-[var(--text-secondary)]", children: m("applicationDetail.permissions.type") }),
        /* @__PURE__ */ e("th", { className: "text-left py-3 px-4 text-sm font-medium text-[var(--text-secondary)]", children: m("applicationDetail.permissions.roles") })
      ] }) }),
      /* @__PURE__ */ e("tbody", { children: a.map(({ permission: u, roles: o }) => /* @__PURE__ */ s(
        "tr",
        {
          className: "border-b border-[var(--border-color)] hover:bg-[var(--bg-hover)]",
          children: [
            /* @__PURE__ */ e("td", { className: "py-3 px-4 font-mono text-sm text-[var(--text-primary)]", children: u.path }),
            /* @__PURE__ */ e("td", { className: "py-3 px-4", children: u.action ? /* @__PURE__ */ e("span", { className: "px-2 py-1 text-xs font-medium rounded-full bg-[var(--accent-bg)] text-[var(--accent-text)]", children: u.action }) : "-" }),
            /* @__PURE__ */ e("td", { className: "py-3 px-4", children: u.isWildcard ? /* @__PURE__ */ e("span", { className: "px-2 py-1 text-xs font-medium rounded-full bg-[var(--warning-bg)] text-[var(--warning-text)]", children: m("applicationDetail.permissions.wildcard", "Wildcard") }) : /* @__PURE__ */ e("span", { className: "px-2 py-1 text-xs font-medium rounded-full bg-[var(--bg-tertiary)] text-[var(--text-muted)]", children: m("applicationDetail.permissions.specific", "Specific") }) }),
            /* @__PURE__ */ e("td", { className: "py-3 px-4", children: /* @__PURE__ */ s("div", { className: "flex flex-wrap gap-1", children: [
              o.length === 0 ? /* @__PURE__ */ e("span", { className: "text-[var(--text-muted)] text-sm", children: "-" }) : o.slice(0, 3).map((d) => /* @__PURE__ */ e(
                "span",
                {
                  className: "px-2 py-0.5 text-xs font-medium rounded-full bg-[var(--color-accent-100)] text-[var(--color-accent-700)]",
                  children: d.name
                },
                d.id
              )),
              o.length > 3 && /* @__PURE__ */ s("span", { className: "px-2 py-0.5 text-xs font-medium rounded-full bg-[var(--bg-tertiary)] text-[var(--text-muted)]", children: [
                "+",
                o.length - 3
              ] })
            ] }) })
          ]
        },
        u.id
      )) })
    ] }) })
  ] });
}
function wt({
  rolesWithAppAccess: t,
  onNavigateToRole: n
}) {
  const { t: a } = z("admin");
  return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
    /* @__PURE__ */ s("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
      a("applicationDetail.roles.title"),
      " (",
      t.length,
      ")"
    ] }),
    /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)]", children: a("applicationDetail.roles.description") }),
    t.length === 0 ? /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-muted)]", children: a("applicationDetail.roles.empty") }) : /* @__PURE__ */ e("div", { className: "space-y-3", children: t.map(({ role: m, permissions: u }) => /* @__PURE__ */ s(
      "div",
      {
        className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--item-color-border)] hover:border-[var(--color-accent-600)] transition-colors",
        children: [
          /* @__PURE__ */ s("div", { className: "flex items-center justify-between", children: [
            /* @__PURE__ */ s("div", { className: "flex items-center gap-3", children: [
              /* @__PURE__ */ e("div", { className: "p-2 rounded-[var(--radius-button)] bg-[var(--color-accent-100)]", children: /* @__PURE__ */ e(te, { className: "w-5 h-5 text-[var(--color-accent-600)]" }) }),
              /* @__PURE__ */ s("div", { children: [
                /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
                  /* @__PURE__ */ e("p", { className: "font-medium text-[var(--text-primary)]", children: m.name }),
                  m.isSystem && /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs font-medium rounded-full bg-[var(--warning-bg)] text-[var(--warning-text)]", children: a("applicationDetail.roles.system", "System") })
                ] }),
                /* @__PURE__ */ s("p", { className: "text-sm text-[var(--text-muted)]", children: [
                  m.usersCount,
                  " ",
                  a("applicationDetail.roles.users"),
                  " • ",
                  u.length,
                  " ",
                  a("applicationDetail.roles.permissions")
                ] })
              ] })
            ] }),
            /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ s(
              "button",
              {
                onClick: () => n(m.id),
                className: "flex items-center gap-1 px-3 py-1.5 rounded-[var(--radius-button)] text-sm font-medium text-[var(--color-accent-600)] hover:bg-[var(--color-accent-100)]",
                children: [
                  /* @__PURE__ */ e(qe, { className: "w-4 h-4" }),
                  a("applicationDetail.roles.viewRole")
                ]
              }
            ) })
          ] }),
          /* @__PURE__ */ s("div", { className: "mt-3 flex flex-wrap gap-1", children: [
            u.slice(0, 5).map((o) => /* @__PURE__ */ s(
              "span",
              {
                className: "px-2 py-0.5 text-xs font-mono rounded bg-[var(--bg-tertiary)] text-[var(--text-muted)]",
                children: [
                  o.path.split(".").pop(),
                  o.isWildcard && ".*"
                ]
              },
              o.id
            )),
            u.length > 5 && /* @__PURE__ */ s("span", { className: "px-2 py-0.5 text-xs rounded bg-[var(--bg-tertiary)] text-[var(--text-muted)]", children: [
              "+",
              u.length - 5,
              " ",
              a("applicationDetail.roles.more", "more")
            ] })
          ] })
        ]
      },
      m.id
    )) })
  ] });
}
const At = (t) => {
  switch (t) {
    case "FullAccess":
      return "bg-green-500";
    case "RequestAccess":
      return "bg-amber-500";
    case "Disabled":
      return "bg-gray-400";
    default:
      return "bg-gray-400";
  }
}, Dt = (t) => {
  switch (t) {
    case "FullAccess":
      return "fullAccess";
    case "RequestAccess":
      return "requestAccess";
    case "Disabled":
      return "disabled";
    default:
      return "disabled";
  }
}, St = (t) => t === "Business" ? "bg-blue-500/10" : "bg-violet-500/10", Mt = (t) => t === "Business" ? { Icon: Ue, color: "text-blue-500" } : { Icon: Oe, color: "text-violet-500" }, Tt = ({
  assignedTenants: t
}) => {
  const { t: n } = z("admin");
  return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
    /* @__PURE__ */ s("div", { children: [
      /* @__PURE__ */ s("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
        n("applicationDetail.publication.title", "Tenant Publication"),
        " (",
        t.length,
        ")"
      ] }),
      /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)]", children: n("applicationDetail.publication.description", "Manage which tenants have access to this application") })
    ] }),
    /* @__PURE__ */ s("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-3 p-4 rounded-[var(--radius-card)] bg-[var(--bg-tertiary)] border border-[var(--border-color)]", children: [
      /* @__PURE__ */ s("div", { className: "flex items-start gap-2", children: [
        /* @__PURE__ */ e("div", { className: "w-3 h-3 mt-1 rounded-full bg-green-500 flex-shrink-0" }),
        /* @__PURE__ */ s("div", { children: [
          /* @__PURE__ */ e("p", { className: "text-sm font-medium text-[var(--text-primary)]", children: n("applicationDetail.publication.accessLevels.fullAccess", "Full Access") }),
          /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-muted)]", children: n("applicationDetail.publication.accessLevels.fullAccessDesc", "Users can use all features") })
        ] })
      ] }),
      /* @__PURE__ */ s("div", { className: "flex items-start gap-2", children: [
        /* @__PURE__ */ e("div", { className: "w-3 h-3 mt-1 rounded-full bg-amber-500 flex-shrink-0" }),
        /* @__PURE__ */ s("div", { children: [
          /* @__PURE__ */ e("p", { className: "text-sm font-medium text-[var(--text-primary)]", children: n("applicationDetail.publication.accessLevels.requestAccess", "Request Access") }),
          /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-muted)]", children: n("applicationDetail.publication.accessLevels.requestAccessDesc", "Requires access request") })
        ] })
      ] }),
      /* @__PURE__ */ s("div", { className: "flex items-start gap-2", children: [
        /* @__PURE__ */ e("div", { className: "w-3 h-3 mt-1 rounded-full bg-gray-400 flex-shrink-0" }),
        /* @__PURE__ */ s("div", { children: [
          /* @__PURE__ */ e("p", { className: "text-sm font-medium text-[var(--text-primary)]", children: n("applicationDetail.publication.accessLevels.disabled", "Disabled") }),
          /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-muted)]", children: n("applicationDetail.publication.accessLevels.disabledDesc", "Not visible for tenant") })
        ] })
      ] })
    ] }),
    t.length === 0 ? /* @__PURE__ */ s("div", { className: "text-center py-12", children: [
      /* @__PURE__ */ e(ae, { className: "w-12 h-12 mx-auto text-[var(--text-muted)] mb-4" }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-muted)]", children: n("applicationDetail.publication.empty", "No tenants have access to this application yet") })
    ] }) : /* @__PURE__ */ e("div", { className: "space-y-3", children: t.map((a) => {
      const { Icon: m, color: u } = Mt(a.tenantType), o = a.tenantStatus === "Active" ? "bg-[var(--success-bg)] text-[var(--success-text)]" : "bg-[var(--warning-bg)] text-[var(--warning-text)]";
      return /* @__PURE__ */ s(
        "div",
        {
          className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--item-color-border)] hover:border-[var(--color-accent-600)] transition-colors",
          children: [
            /* @__PURE__ */ s("div", { className: "flex items-center justify-between", children: [
              /* @__PURE__ */ s("div", { className: "flex items-center gap-3", children: [
                /* @__PURE__ */ e("div", { className: `p-2 rounded-[var(--radius-button)] ${St(a.tenantType)}`, children: /* @__PURE__ */ e(m, { className: `w-5 h-5 ${u}` }) }),
                /* @__PURE__ */ s("div", { children: [
                  /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
                    /* @__PURE__ */ e("p", { className: "font-medium text-[var(--text-primary)]", children: a.tenantName }),
                    /* @__PURE__ */ e("span", { className: `px-2 py-0.5 text-xs font-medium rounded-full ${o}`, children: a.tenantStatus })
                  ] }),
                  /* @__PURE__ */ s("p", { className: "text-sm text-[var(--text-muted)]", children: [
                    a.tenantSlug,
                    " • ",
                    a.tenantType
                  ] })
                ] })
              ] }),
              /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
                /* @__PURE__ */ e("div", { className: `w-2.5 h-2.5 rounded-full ${At(a.accessLevel)}` }),
                /* @__PURE__ */ e("span", { className: "px-3 py-1.5 rounded-[var(--radius-input)] bg-[var(--bg-secondary)] border border-[var(--border-color)] text-sm text-[var(--text-primary)]", children: n(`applicationDetail.publication.accessLevels.${Dt(a.accessLevel)}`, a.accessLevel) })
              ] })
            ] }),
            /* @__PURE__ */ s("div", { className: "mt-2 text-xs text-[var(--text-muted)]", children: [
              n("applicationDetail.publication.assignedAt", "Assigned"),
              ": ",
              new Date(a.assignedAt).toLocaleDateString(),
              a.assignedBy && ` ${n("applicationDetail.publication.by", "by")} ${a.assignedBy}`
            ] })
          ]
        },
        a.tenantId
      );
    }) })
  ] });
}, kt = ["info", "modules", "permissions", "roles", "publication", "requests"];
function $t() {
  const { id: t } = Me(), n = Te(), { t: a } = z("admin"), { hasPermission: m } = Ce(), { currentTenant: u, isGlobalView: o } = Le(), d = m("administration.applications.execute"), { activeTab: l, setActiveTab: w } = ke("info", kt), r = ot(), b = ct(), A = pt(), i = gt(), T = nt("application", t), P = H(() => o || !u ? i.availableTenants : i.availableTenants.filter((c) => c.slug === u.slug), [i.availableTenants, o, u]), R = H(() => o || !u ? i.assignedTenants : i.assignedTenants.filter((c) => c.tenantSlug === u.slug), [i.assignedTenants, o, u]);
  X(() => {
    t && r.loadApplication(t);
  }, [t]), X(() => {
    r.application && ((l === "permissions" || l === "roles") && A.permissions.length === 0 && A.loadPermissionsData(r.application), l === "publication" && i.assignedTenants.length === 0 && i.loadPublicationData(t), l === "requests" && T.loadRequests());
  }, [
    l,
    r.application,
    i.assignedTenants.length
  ]);
  const h = [
    { id: "info", label: a("applicationDetail.tabs.info"), icon: $e },
    { id: "modules", label: a("applicationDetail.tabs.modules"), icon: Z },
    { id: "permissions", label: a("applicationDetail.tabs.permissions"), icon: te },
    { id: "roles", label: a("applicationDetail.tabs.roles"), icon: ze },
    { id: "publication", label: a("applicationDetail.tabs.publication"), icon: ae },
    { id: "requests", label: a("applicationDetail.tabs.requests"), icon: We }
  ];
  if (r.loading)
    return /* @__PURE__ */ e("div", { className: "flex items-center justify-center h-64", children: /* @__PURE__ */ e(W, { className: "w-8 h-8 animate-spin text-[var(--color-accent-500)]" }) });
  if (r.error || !r.application)
    return /* @__PURE__ */ s("div", { className: "text-center py-12", children: [
      /* @__PURE__ */ e(je, { className: "w-12 h-12 text-[var(--error-text)] mx-auto mb-4" }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)]", children: r.error || a("applicationDetail.notFound") }),
      /* @__PURE__ */ e(
        "button",
        {
          onClick: () => n("/administration/applications"),
          className: "mt-4 px-4 py-2 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)]",
          children: a("applicationDetail.backToList")
        }
      )
    ] });
  const p = A.permissions.length > 0 || l === "permissions" || l === "roles", N = i.assignedTenants.length > 0 || l === "publication", E = [
    {
      label: a("applicationDetail.stats.modules"),
      value: r.application.modules?.length || 0,
      color: "blue"
    },
    {
      label: a("applicationDetail.stats.permissions"),
      value: p ? A.permissions.length : "—",
      color: "green"
    },
    {
      label: a("applicationDetail.stats.rolesWithAccess"),
      value: p ? A.rolesWithAppAccess.length : "—",
      color: "purple"
    },
    {
      label: a("applicationDetail.stats.assignedTenants"),
      value: N ? R.length : "—",
      color: "yellow"
    },
    {
      label: a("applicationDetail.stats.status"),
      value: r.application.isActive ? a("common:active") : a("common:inactive"),
      color: r.application.isActive ? "green" : "neutral"
    }
  ], k = {
    blue: "bg-[var(--info-bg)] text-[var(--info-text)] border-[var(--info-border)]",
    green: "bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",
    yellow: "bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",
    red: "bg-[var(--error-bg)] text-[var(--error-text)] border-[var(--error-border)]",
    purple: "bg-[var(--accent-bg)] text-[var(--accent-text)] border-[var(--color-accent-300)]",
    neutral: "bg-[var(--bg-secondary)] text-[var(--text-primary)] border-[var(--border-color)]"
  };
  return /* @__PURE__ */ s("div", { className: "space-y-6", children: [
    /* @__PURE__ */ e(
      Be,
      {
        items: [
          { label: a("breadcrumb.admin", { ns: "navigation" }), href: "/administration" },
          { label: a("applications.title"), href: "/administration/applications" },
          { label: r.application.label }
        ]
      }
    ),
    /* @__PURE__ */ s("div", { className: "flex items-center gap-4", children: [
      /* @__PURE__ */ e(
        "button",
        {
          onClick: () => n("/administration/applications"),
          className: "p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] transition-colors",
          "aria-label": a("common:back"),
          children: /* @__PURE__ */ e(Ge, { className: "w-5 h-5 text-[var(--text-secondary)]" })
        }
      ),
      /* @__PURE__ */ s("div", { className: "flex items-center gap-3", children: [
        _(r.application.icon, "w-5 h-5"),
        /* @__PURE__ */ s("div", { className: "flex-1", children: [
          /* @__PURE__ */ e("h1", { className: "text-xl sm:text-2xl font-bold text-[var(--text-primary)]", children: r.application.label }),
          r.application.description && /* @__PURE__ */ e("p", { className: "text-sm sm:text-base text-[var(--text-secondary)]", children: r.application.description })
        ] })
      ] }),
      /* @__PURE__ */ s("div", { className: "flex items-center gap-2 ml-auto", children: [
        /* @__PURE__ */ e(
          "span",
          {
            className: `px-3 py-1 rounded-[var(--radius-badge)] text-sm font-medium ${r.application.isActive ? "bg-[var(--success-bg)] text-[var(--success-text)] border border-[var(--success-border)]" : "bg-[var(--bg-tertiary)] text-[var(--text-secondary)] border border-[var(--border-color)]"}`,
            children: r.application.isActive ? a("common:active") : a("common:inactive")
          }
        ),
        d && /* @__PURE__ */ s(
          "button",
          {
            onClick: () => r.handleToggleStatus(t),
            disabled: r.saving,
            className: `inline-flex items-center gap-2 px-4 py-2 rounded-[var(--radius-button)] font-medium transition-colors ${r.application.isActive ? "bg-[var(--error-bg)] text-[var(--error-text)] border border-[var(--error-border)] hover:bg-[var(--error-border)]" : "bg-[var(--success-bg)] text-[var(--success-text)] border border-[var(--success-border)] hover:bg-[var(--success-border)]"} disabled:opacity-50`,
            children: [
              r.saving && /* @__PURE__ */ e(W, { className: "w-4 h-4 animate-spin" }),
              !r.saving && r.application.isActive && /* @__PURE__ */ e(Ke, { className: "w-4 h-4" }),
              !r.saving && !r.application.isActive && /* @__PURE__ */ e(Ve, { className: "w-4 h-4" }),
              r.application.isActive ? a("applicationDetail.deactivate") : a("applicationDetail.activate")
            ]
          }
        )
      ] })
    ] }),
    r.error && /* @__PURE__ */ s("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--error-bg)] border border-[var(--error-border)] text-[var(--error-text)] flex items-center gap-2", children: [
      /* @__PURE__ */ e(He, { className: "w-5 h-5 flex-shrink-0" }),
      r.error
    ] }),
    r.success && /* @__PURE__ */ s("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--success-bg)] border border-[var(--success-border)] text-[var(--success-text)] flex items-center gap-2", children: [
      /* @__PURE__ */ e(Ze, { className: "w-5 h-5 flex-shrink-0" }),
      r.success
    ] }),
    /* @__PURE__ */ e("div", { className: "grid grid-cols-1 md:grid-cols-3 lg:grid-cols-5 gap-4", children: E.map((c) => /* @__PURE__ */ s(
      "div",
      {
        className: `rounded-[var(--radius-card)] p-4 text-center border ${k[c.color]}`,
        children: [
          /* @__PURE__ */ e("div", { className: "text-2xl font-bold", children: c.value }),
          /* @__PURE__ */ e("div", { className: "text-sm opacity-80", children: c.label })
        ]
      },
      c.label
    )) }),
    /* @__PURE__ */ e(
      "div",
      {
        className: "flex gap-1 p-1 overflow-x-auto bg-[var(--bg-secondary)] rounded-[var(--radius-card)] border border-[var(--border-color)]",
        role: "tablist",
        "aria-label": a("applicationDetail.tabs.label", "Application tabs"),
        children: h.map((c) => {
          const B = c.icon, D = l === c.id;
          return /* @__PURE__ */ s(
            "button",
            {
              role: "tab",
              "aria-selected": D,
              "aria-controls": `tabpanel-${c.id}`,
              onClick: () => w(c.id),
              className: `flex items-center gap-2 px-4 py-2 whitespace-nowrap rounded-[var(--radius-button)] font-medium transition-colors ${D ? "bg-[var(--color-accent-600)] text-white" : "text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]"}`,
              children: [
                /* @__PURE__ */ e(B, { className: "w-4 h-4" }),
                c.label
              ]
            },
            c.id
          );
        })
      }
    ),
    /* @__PURE__ */ s(
      "div",
      {
        className: "bg-[var(--bg-secondary)] rounded-[var(--radius-card)] border border-[var(--border-color)] p-4 sm:p-6",
        role: "tabpanel",
        id: `tabpanel-${l}`,
        "aria-labelledby": l,
        children: [
          l === "info" && /* @__PURE__ */ e(
            xt,
            {
              formData: r.formData,
              setFormData: r.setFormData,
              application: r.application,
              saving: r.saving,
              onSubmit: () => r.handleSaveInfo(t, r.formData)
            }
          ),
          l === "modules" && /* @__PURE__ */ e(
            yt,
            {
              application: r.application,
              expandedModules: b.expandedModules,
              moduleSections: b.moduleSections,
              loadingSections: b.loadingSections,
              reordering: b.reordering,
              editingModule: b.editingModule,
              moduleFormData: b.moduleFormData,
              showModuleForm: b.showModuleForm,
              saving: r.saving,
              onToggleExpand: (c) => b.toggleModuleExpand(t, c),
              onStartEdit: b.startEditModule,
              onSaveModule: async () => {
                await b.handleSaveModule(
                  t,
                  b.editingModule.id,
                  b.moduleFormData
                ), r.setSuccess(a("applicationDetail.success.moduleUpdated")), await r.loadApplication(t);
              },
              onCancelEdit: () => {
                b.setShowModuleForm(!1), b.setEditingModule(null);
              },
              onModulesReorder: async (c) => {
                await b.handleModulesReorder(t, c), await r.loadApplication(t);
              },
              onSectionsReorder: (c, B) => b.handleSectionsReorder(t, c, B),
              setModuleFormData: (c) => b.setModuleFormData(typeof c == "function" ? c(b.moduleFormData) : c)
            }
          ),
          l === "permissions" && /* @__PURE__ */ e(
            Nt,
            {
              application: r.application,
              permissions: A.permissions,
              permissionsWithRoles: A.permissionsWithRoles
            }
          ),
          l === "roles" && /* @__PURE__ */ e(
            wt,
            {
              rolesWithAppAccess: A.rolesWithAppAccess,
              onNavigateToRole: (c) => n(`/administration/permissions/roles/${c}`)
            }
          ),
          l === "publication" && /* @__PURE__ */ e(
            Tt,
            {
              application: r.application,
              assignedTenants: R,
              availableTenants: P,
              showAssignModal: i.showAssignModal,
              selectedTenantIds: i.selectedTenantIds,
              selectedAccessLevel: i.selectedAccessLevel,
              tenantSearch: i.tenantSearch,
              showCustomizeDrawer: i.showCustomizeDrawer,
              customizingTenant: i.customizingTenant,
              bulkAccessMode: i.bulkAccessMode,
              bulkModules: i.bulkModules,
              bulkExpandedModules: i.bulkExpandedModules,
              loadingBulkModules: i.loadingBulkModules,
              isUpdateMode: i.isUpdateMode,
              updateMergeMode: i.updateMergeMode,
              showConfirmRemovalDialog: i.showConfirmRemovalDialog,
              pendingRemovals: i.pendingRemovals,
              saving: r.saving,
              includePersonalTenants: i.includePersonalTenants,
              isInDefaultPersonalTemplate: i.isInDefaultPersonalTemplate,
              onAddTenant: () => {
                i.loadPublicationData(t), i.setShowAssignModal(!0);
              },
              onRemoveTenant: (c) => i.handleRemoveTenant(t, c, () => {
                r.setSuccess(a("applicationDetail.publication.success.removed"));
              }),
              onUpdateAccessLevel: (c, B) => i.handleUpdateAccessLevel(t, c, B, () => {
                r.setSuccess(a("applicationDetail.publication.success.updated"));
              }),
              onCustomizeTenant: (c) => {
                i.setCustomizingTenant(c), i.setShowCustomizeDrawer(!0);
              },
              onCloseCustomizeDrawer: () => {
                i.setShowCustomizeDrawer(!1), i.setCustomizingTenant(null), i.loadPublicationData(t);
              },
              onAssignTenants: () => i.handleAssignTenants(t, () => {
                r.setSuccess(a("applicationDetail.publication.success.assigned")), i.loadPublicationData(t);
              }),
              onUpdateTenants: () => i.handleUpdateTenants(t, () => {
                r.setSuccess(a("applicationDetail.publication.success.updated")), i.loadPublicationData(t);
              }),
              onExecuteUpdateTenants: () => i.executeUpdateTenants(t, () => {
                r.setSuccess(a("applicationDetail.publication.success.updated")), i.loadPublicationData(t);
              }),
              onCancelRemovalDialog: () => {
                i.setShowConfirmRemovalDialog(!1), i.setUpdateMergeMode("merge");
              },
              setShowAssignModal: i.setShowAssignModal,
              setSelectedTenantIds: i.setSelectedTenantIds,
              setSelectedAccessLevel: i.setSelectedAccessLevel,
              setTenantSearch: i.setTenantSearch,
              setBulkAccessMode: i.setBulkAccessMode,
              setIsUpdateMode: i.setIsUpdateMode,
              setUpdateMergeMode: i.setUpdateMergeMode,
              onToggleTenantSelection: i.toggleTenantSelection,
              onSelectAllFilteredTenants: i.selectAllFilteredTenants,
              onClearTenantSelection: i.clearTenantSelection,
              setIncludePersonalTenants: i.setIncludePersonalTenants,
              onLoadBulkModules: () => i.loadBulkModules(t),
              onToggleBulkModuleExpand: i.toggleBulkModuleExpand,
              onToggleBulkModule: i.toggleBulkModule,
              onToggleBulkSection: i.toggleBulkSection,
              onGetBulkModuleCheckState: i.getBulkModuleCheckState,
              onGetBulkStats: i.getBulkStats,
              onSelectAllBulkModules: i.selectAllBulkModules,
              onClearBulkModules: i.clearBulkModules,
              appId: t
            }
          ),
          l === "requests" && /* @__PURE__ */ e(
            lt,
            {
              requests: T.requests,
              loading: T.loading,
              onReload: () => T.loadRequests()
            }
          )
        ]
      }
    )
  ] });
}
export {
  $t as default
};
//# sourceMappingURL=ApplicationDetailPage-DSX3gn7Y.js.map
