"use client" import { useState } from "react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Alert, AlertDescription } from "@/components/ui/alert" import { type User, type UserRole, ROLE_NAMES, ROLE_HIERARCHY } from "@/types/user" interface RoleManagementModalProps { isOpen: boolean onClose: () => void user: User | null adminRole: UserRole onRoleChange: (userId: string, newRole: UserRole) => void } export function RoleManagementModal({ isOpen, onClose, user, adminRole, onRoleChange }: RoleManagementModalProps) { const [selectedRole, setSelectedRole] = useState("") const [loading, setLoading] = useState(false) if (!user) return null const adminLevel = ROLE_HIERARCHY[adminRole] || 0 const availableRoles = (Object.entries(ROLE_NAMES) as [UserRole, string][]).filter(([role]) => { const roleLevel = ROLE_HIERARCHY[role] || 0 return roleLevel < adminLevel }) const handleRoleChange = async () => { if (!selectedRole) return setLoading(true) try { await onRoleChange(user.national_id, selectedRole as UserRole) onClose() } catch (error) { console.error("Error changing role:", error) } finally { setLoading(false) } } return ( שינוי תפקיד - {user.name} בחר תפקיד חדש עבור המשתמש

תפקיד נוכחי:

{ROLE_NAMES[user.role] || user.role}

{selectedRole && ( המשתמש יקבל הרשאות של {ROLE_NAMES[selectedRole as UserRole]} )}
) }