"use client";
import { Workspace } from './chunk-JBXNEOFB.mjs';
import { HeroSection, CreateActionButton, SearchBar, EntityCard, InlineForm, FormSelect, StatusBadge, GlassModal, FormGrid, FormInput } from './chunk-D5FL3ZHC.mjs';
import { useLocale } from './chunk-7VJ7CMMT.mjs';
import { Button, Badge } from './chunk-WR55H7DH.mjs';
import { useState } from 'react';
import { UserGroupIcon, ShieldCheckIcon } from '@heroicons/react/24/outline';
import { jsxs, jsx } from 'react/jsx-runtime';

var ROLE_OPTIONS = [
  { value: "admin", label: "Admin" },
  { value: "manager", label: "Manager" },
  { value: "analyst", label: "Analyst" },
  { value: "viewer", label: "Viewer" }
];
function UsersPageView({ labels, users, onCreateUser, onUpdateRole }) {
  const [createOpen, setCreateOpen] = useState(false);
  const [searchTerm, setSearchTerm] = useState("");
  const allUsers = users;
  const term = searchTerm.trim().toLowerCase();
  const filteredUsers = term ? allUsers.filter(
    (user) => user.name.toLowerCase().includes(term) || user.email.toLowerCase().includes(term)
  ) : allUsers;
  const isEmpty = allUsers.length === 0;
  const labelsAny = labels;
  return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
    /* @__PURE__ */ jsx(
      HeroSection,
      {
        icon: /* @__PURE__ */ jsx(UserGroupIcon, { className: "h-5 w-5" }),
        label: labels.title,
        title: labels.title,
        subtitle: labels.subtitle,
        gradient: "from-violet-500 to-indigo-600",
        toolbar: !isEmpty ? /* @__PURE__ */ jsx(
          SearchBar,
          {
            searchTerm,
            onSearchChange: setSearchTerm,
            placeholder: labelsAny.searchPlaceholder ?? labels.title,
            noBorder: true
          }
        ) : void 0,
        actions: /* @__PURE__ */ jsx(
          CreateActionButton,
          {
            mode: "desktop",
            label: labels.create,
            onClick: () => setCreateOpen(true),
            accent: "violet"
          }
        )
      }
    ),
    /* @__PURE__ */ jsx(
      CreateActionButton,
      {
        mode: "mobile",
        label: labels.create,
        onClick: () => setCreateOpen(true),
        accent: "violet"
      }
    ),
    /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
      /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-slate-900 dark:text-slate-100", children: labels.list }),
      /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3", children: filteredUsers.map((user) => /* @__PURE__ */ jsx(
        EntityCard,
        {
          accentGradient: "from-violet-500 to-indigo-700",
          icon: /* @__PURE__ */ jsx("div", { className: "flex h-11 w-11 items-center justify-center rounded-lg bg-violet-500/10 text-violet-600 dark:bg-violet-500/20 dark:text-violet-400", children: /* @__PURE__ */ jsx(UserGroupIcon, { className: "h-6 w-6" }) }),
          title: user.name,
          subtitle: user.email,
          status: /* @__PURE__ */ jsx(
            StatusBadge,
            {
              status: user.active ? "active" : "inactive",
              label: user.active ? labels.statusActive : labels.statusInactive,
              size: "sm"
            }
          ),
          footer: /* @__PURE__ */ jsx(
            "form",
            {
              onSubmit: (event) => {
                event.preventDefault();
                const formData = new FormData(event.currentTarget);
                const role = String(formData.get("role") ?? "viewer");
                onUpdateRole({ email: user.email, role });
              },
              children: /* @__PURE__ */ jsxs(InlineForm, { children: [
                /* @__PURE__ */ jsx(FormSelect, { name: "role", options: ROLE_OPTIONS, defaultValue: user.role }),
                /* @__PURE__ */ jsx(Button, { type: "submit", outline: true, size: "sm", children: labels.save })
              ] })
            }
          )
        },
        user.email
      )) })
    ] }),
    /* @__PURE__ */ jsx(
      GlassModal,
      {
        open: createOpen,
        onClose: () => setCreateOpen(false),
        title: labels.create,
        maxWidth: "lg",
        showFormFooter: true,
        cancelLabel: labels.list,
        submitLabel: labels.add,
        onSubmit: (event) => {
          const formData = new FormData(event.currentTarget);
          const name = String(formData.get("name") ?? "").trim();
          const email = String(formData.get("email") ?? "").trim().toLowerCase();
          const role = String(formData.get("role") ?? "viewer");
          if (!name || !email) return;
          onCreateUser({ name, email, role });
          setCreateOpen(false);
        },
        children: /* @__PURE__ */ jsxs(FormGrid, { children: [
          /* @__PURE__ */ jsx(FormInput, { name: "name", label: labels.name, placeholder: labels.userNamePlaceholder, required: true }),
          /* @__PURE__ */ jsx(FormInput, { name: "email", label: labels.email, placeholder: labels.userEmailPlaceholder, required: true, type: "email" }),
          /* @__PURE__ */ jsx(FormSelect, { name: "role", label: labels.role, options: ROLE_OPTIONS })
        ] })
      }
    )
  ] });
}
function RolesPageView({
  labels,
  users,
  onAssignRole,
  roleDefinitions,
  roleOptions
}) {
  const [assignOpen, setAssignOpen] = useState(false);
  const [searchTerm, setSearchTerm] = useState("");
  const allRoleDefinitions = Object.values(roleDefinitions);
  const allUsers = users;
  const term = searchTerm.trim().toLowerCase();
  const filteredRoleDefinitions = term ? allRoleDefinitions.filter((role) => role.label.toLowerCase().includes(term)) : allRoleDefinitions;
  const filteredUsers = term ? allUsers.filter(
    (user) => user.name.toLowerCase().includes(term) || user.email.toLowerCase().includes(term)
  ) : allUsers;
  const isEmpty = allRoleDefinitions.length === 0 && allUsers.length === 0;
  const labelsAny = labels;
  return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
    /* @__PURE__ */ jsx(
      HeroSection,
      {
        icon: /* @__PURE__ */ jsx(ShieldCheckIcon, { className: "h-5 w-5" }),
        label: labels.title,
        title: labels.title,
        subtitle: labels.subtitle,
        gradient: "from-emerald-500 to-teal-600",
        toolbar: !isEmpty ? /* @__PURE__ */ jsx(
          SearchBar,
          {
            searchTerm,
            onSearchChange: setSearchTerm,
            placeholder: labelsAny.searchPlaceholder ?? labels.title,
            noBorder: true
          }
        ) : void 0,
        actions: /* @__PURE__ */ jsx(
          CreateActionButton,
          {
            mode: "desktop",
            label: labels.assign,
            onClick: () => setAssignOpen(true),
            accent: "emerald"
          }
        )
      }
    ),
    /* @__PURE__ */ jsx(
      CreateActionButton,
      {
        mode: "mobile",
        label: labels.assign,
        onClick: () => setAssignOpen(true),
        accent: "emerald"
      }
    ),
    /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
      /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-slate-900 dark:text-slate-100", children: labels.definitions }),
      /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4", children: filteredRoleDefinitions.map((role) => /* @__PURE__ */ jsxs(
        EntityCard,
        {
          accentGradient: "from-emerald-500 to-teal-700",
          icon: /* @__PURE__ */ jsx("div", { className: "flex h-11 w-11 items-center justify-center rounded-lg bg-emerald-500/10 text-emerald-600 dark:bg-emerald-500/20 dark:text-emerald-400", children: /* @__PURE__ */ jsx(ShieldCheckIcon, { className: "h-6 w-6" }) }),
          title: role.label,
          subtitle: role.id,
          children: [
            /* @__PURE__ */ jsx("p", { className: "text-xs text-slate-500 dark:text-slate-400", children: role.description }),
            /* @__PURE__ */ jsx("p", { className: "mt-2 text-xs font-medium text-slate-600 dark:text-slate-300", children: labels.permissionsEnabled })
          ]
        },
        role.id
      )) })
    ] }),
    /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
      /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-slate-900 dark:text-slate-100", children: labels.current }),
      /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3", children: filteredUsers.map((user) => /* @__PURE__ */ jsx(
        EntityCard,
        {
          accentGradient: "from-violet-500 to-indigo-700",
          icon: /* @__PURE__ */ jsx("div", { className: "flex h-11 w-11 items-center justify-center rounded-lg bg-violet-500/10 text-violet-600 dark:bg-violet-500/20 dark:text-violet-400", children: /* @__PURE__ */ jsx(ShieldCheckIcon, { className: "h-6 w-6" }) }),
          title: user.name,
          subtitle: user.email,
          status: /* @__PURE__ */ jsx(Badge, { color: "violet", size: "xs", children: user.role })
        },
        user.email
      )) })
    ] }),
    /* @__PURE__ */ jsx(
      GlassModal,
      {
        open: assignOpen,
        onClose: () => setAssignOpen(false),
        title: labels.assign,
        maxWidth: "lg",
        showFormFooter: true,
        cancelLabel: labels.current,
        submitLabel: labels.apply,
        onSubmit: (event) => {
          const formData = new FormData(event.currentTarget);
          const email = String(formData.get("email") ?? "").trim().toLowerCase();
          const role = String(formData.get("role") ?? "viewer");
          if (!email) return;
          onAssignRole({ email, role });
          setAssignOpen(false);
        },
        children: /* @__PURE__ */ jsxs(FormGrid, { children: [
          /* @__PURE__ */ jsx(FormInput, { name: "email", label: labels.userEmail, placeholder: "user@company.com", required: true }),
          /* @__PURE__ */ jsx(FormSelect, { name: "role", label: labels.role, options: roleOptions })
        ] })
      }
    )
  ] });
}
function WorkflowWorkspace({ graph }) {
  const locale = useLocale();
  return /* @__PURE__ */ jsx(Workspace, { initialGraph: graph, locale });
}

export { RolesPageView, UsersPageView, WorkflowWorkspace };
//# sourceMappingURL=chunk-TZA5T4MJ.mjs.map
//# sourceMappingURL=chunk-TZA5T4MJ.mjs.map