"use client";
import { useImpersonation } from './chunk-ZQRUAXGP.mjs';
import { Button } from './chunk-WR55H7DH.mjs';
import { useState } from 'react';
import { EyeIcon, XMarkIcon } from '@heroicons/react/24/outline';
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';

function ImpersonationBanner({ onExit, className }) {
  const { isImpersonating, claim, exit } = useImpersonation();
  const [isExiting, setIsExiting] = useState(false);
  if (!isImpersonating || !claim) return null;
  const handleExit = async () => {
    setIsExiting(true);
    try {
      await exit();
      onExit?.();
    } finally {
      setIsExiting(false);
    }
  };
  return /* @__PURE__ */ jsxs(
    "div",
    {
      role: "status",
      "aria-live": "polite",
      className: "sticky top-0 z-50 flex items-center justify-between gap-3 border-b border-amber-300 bg-amber-100 px-4 py-2 text-sm text-amber-900 shadow-sm " + (className ?? ""),
      children: [
        /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ jsx(EyeIcon, { "aria-hidden": "true", className: "h-5 w-5 shrink-0" }),
          /* @__PURE__ */ jsxs("span", { children: [
            "Impersonating session \u2014 signed in as the target user by",
            " ",
            /* @__PURE__ */ jsx("strong", { children: claim.email ?? claim.sub }),
            claim.reason ? /* @__PURE__ */ jsxs(Fragment, { children: [
              " \xB7 ",
              /* @__PURE__ */ jsx("span", { className: "italic", children: claim.reason })
            ] }) : null
          ] })
        ] }),
        /* @__PURE__ */ jsxs(
          Button,
          {
            size: "sm",
            color: "ios-glass-red",
            onClick: handleExit,
            disabled: isExiting,
            "aria-label": "Exit impersonation",
            children: [
              /* @__PURE__ */ jsx(XMarkIcon, { "aria-hidden": "true", className: "h-4 w-4" }),
              isExiting ? "Exiting\u2026" : "Exit impersonation"
            ]
          }
        )
      ]
    }
  );
}

export { ImpersonationBanner };
//# sourceMappingURL=chunk-SJ6SUS7H.mjs.map
//# sourceMappingURL=chunk-SJ6SUS7H.mjs.map