import { ReactNode } from "react"; /** One column in the permission matrix — also the key passed to onPermissionChange. */ export type PermissionKey = "read" | "create" | "edit" | "delete" | "import" | "export" | "automation"; /** One row of the permission matrix, keyed by module — booleans mirror PermissionKey (automation is handled specially, see below). */ export type Permission = { /** "Automation" (case-insensitive) is special-cased: every column collapses to the single automation flag below, only the Read cell renders. */ module: string; /** Read cell; for the Automation module it is the only cell shown and reflects `automation`. */ read: boolean; /** Whether the Create cell is checked. */ create: boolean; /** Whether the Edit cell is checked. */ edit: boolean; /** Whether the Delete cell is checked. */ delete: boolean; /** Whether the Import cell is checked; only rendered when `permissionKeys` includes it. */ import?: boolean; /** Whether the Export cell is checked; only rendered when `permissionKeys` includes it. */ export?: boolean; /** Flag the Automation module row reads and toggles instead of the per-column booleans. */ automation?: boolean; }; /** One row in the roles list — the same shape is passed back into onEditRole/onViewRole as the selected role. */ export type RoleData = { /** Shown in the list, truncated with an ellipsis when long. */ roleName: string; /** Shown as given in the Created By column. */ createdBy: string; /** Shown as given, unformatted, in the Created Time column. */ created_at: string; /** The role's matrix rows; not rendered in the list, handed back via `onEditRole`/`onViewRole` to prefill `permissions`. */ permission: Permission[]; /** Coerced via Number() before reaching onDeleteRole — a non-numeric id silently becomes NaN with no error. */ roles_id: string; /** designation/makeSuperAdmin/automation/trackLocation/show_records: never read by this component — pass-through only, for the consumer to prefill its own form state on edit/view. */ designation: string; /** Pass-through for the consumer to prefill its form. */ makeSuperAdmin?: boolean; /** Pass-through for the consumer to prefill its form. */ automation?: boolean; /** Pass-through for the consumer to prefill its form. */ trackLocation?: boolean; /** Pass-through for the consumer to prefill its form. */ show_records?: boolean; }; /** Top-level switch: "list" renders the roles table, "form" renders the create/edit/view role form. */ export type RolesPermissionView = "list" | "form"; /** Only relevant when view is "form" — mode "view" renders the permission form read-only. */ export type RolesPermissionMode = "create" | "edit" | "view"; /** * All user-facing strings. Provide translated values from the host app; every * key has a sensible English default so the component works standalone. */ export type RolesPermissionLabels = { /** Heading of the roles list. */ title?: string; /** Prefix of the role-count badge ("Total Roles: 4"). */ totalRoles?: string; /** Text of the new-role button. */ newRole?: string; /** Serial-number column header. */ sNo?: string; /** Role name column header. */ roleNameColumn?: string; /** Created-by column header. */ createdBy?: string; /** Created-time column header. */ createdTime?: string; /** Actions column header. */ actions?: string; /** Empty-state title when there are no roles. */ noRoles?: string; /** Name and tooltip of the row View icon. */ view?: string; /** Name and tooltip of the row Edit icon. */ edit?: string; /** Name and tooltip of the row Delete icon, and the confirm button of the delete dialog. */ delete?: string; /** Heading of the role details card in the form. */ roleInformation?: string; /** Label of the role name input. */ roleName?: string; /** Placeholder of the role name input. */ roleNamePlaceholder?: string; /** Label of the super-admin checkbox. */ enableAllPermissions?: string; /** Label of the track-location checkbox. */ trackLocation?: string; /** Label of the show-all-records checkbox. */ showAllUserRecords?: string; /** Heading of the permission matrix card. */ permissionSettings?: string; /** Module column header of the matrix. */ moduleName?: string; /** Read column header. */ read?: string; /** Create column header. */ create?: string; /** Edit column header. */ editPermission?: string; /** Delete column header. */ deletePermission?: string; /** Import column header. */ importPermission?: string; /** Export column header. */ exportPermission?: string; /** Shown in the matrix when `permissions` is empty. */ noPermissions?: string; /** Text of the form Cancel button and the delete dialog cancel button. */ cancel?: string; /** Save button text when not `isEditing`. */ saveChanges?: string; /** Save button text when `isEditing`. */ updateChanges?: string; /** Tooltip on the disabled role name input in view mode. */ readOnly?: string; /** Title of the delete confirmation dialog. */ deleteRole?: string; /** Body text of the delete confirmation dialog. */ deleteRoleConfirm?: string; }; /** Role list + role/permission-matrix form in one component (switch via `view`) — manages role definitions only, not user-to-role assignment (that's UserDetails' Change Role). */ export interface RolesPermissionProps { /** Which view to render. */ view: RolesPermissionView; /** Form mode (controls read-only vs editable form). */ mode?: RolesPermissionMode; /** Roles list data. */ roles: RoleData[]; /** Shows skeleton rows instead of the table and hides the role-count badge. */ isRolesLoading?: boolean; /** Permission matrix rows for the form view. */ permissions: Permission[]; /** Columns rendered in the matrix. Defaults to all non-automation keys. */ permissionKeys?: PermissionKey[]; /** Form field values — fully controlled, no internal state; edits are invisible without the matching handler below. */ roleName: string; /** Error text under the role name input; any non-empty value also marks it invalid. */ roleNameError?: string; /** Toggling this does not itself grant matrix permissions — it's cosmetic until the consumer applies that logic. */ isSuperAdmin: boolean; /** Checked state of the track-location checkbox. */ isTrackLocation: boolean; /** Checked state of the show-all-records checkbox. */ isShowRecords: boolean; /** Whether the role is being edited (changes the Save button label). */ isEditing?: boolean; /** Save in-flight flag. */ isSaving?: boolean; /** List actions. */ onNewRole?: () => void; /** Fires with the role when its View icon is pressed. */ onViewRole?: (role: RoleData) => void; /** Fires with the role when its Edit icon is pressed. */ onEditRole?: (role: RoleData) => void; /** Called synchronously right before the modal closes — no await, no loading state; errors must be surfaced outside this flow. */ onDeleteRole?: (roleId: number) => void; /** Back icon renders only when this is provided, not merely disabled when omitted. */ onBack?: () => void; /** Form actions. */ onRoleNameChange?: (value: string) => void; /** Fires with the new checked state of the enable-all-permissions checkbox. */ onToggleSuperAdmin?: (checked: boolean) => void; /** Fires with the new checked state of the track-location checkbox. */ onToggleTrackLocation?: (checked: boolean) => void; /** Fires with the new checked state of the show-all-records checkbox. */ onToggleShowRecords?: (checked: boolean) => void; /** Fires with key "automation" (not "read") for a module named "automation" — see Permission.module. */ onPermissionChange?: (module: string, key: PermissionKey) => void; /** Fires when the Save or Update button is pressed; the footer is hidden in view mode. */ onSave?: () => void; /** Header back icon renders only when set; the footer Cancel button renders outside view mode and no-ops without it. */ onCancelForm?: () => void; /** App-specific sections rendered under the roles list (e.g. ModuleDelete, SignInActivity). */ footerSlot?: ReactNode; /** Icon shown in the matrix for granted permissions in view mode. */ checkIcon?: ReactNode; /** Translated/override strings. */ labels?: RolesPermissionLabels; /** Outer padding override. Defaults to a compact value. */ padding?: string; } /** Plain confirm dialog for one role at a time — no built-in awaiting of onConfirm, so pair it with your own loading/error handling. */ export interface DeleteRoleModalProps { isOpen: boolean; onClose: () => void; onConfirm: () => void; isLoading?: boolean; labels: Required>; }