// File Path: monorepo/web/frontend/src/pages/Admin/Staff/Detail/More/Delete/Page.jsx

import React, { useCallback, memo } from "react";
import { BriefcaseIcon, TrashIcon } from "@heroicons/react/24/outline";
import { useStaffManager } from "../../../../../../services/Services";
import { UIXThemeProvider } from "../../../../../../components/UIX";
import { EntityActionConfirmationPage } from "../../../../../../components/business/views";

const AdminStaffDetailMoreDeletePageContent = memo(
  function AdminStaffDetailMoreDeletePageContent() {
    const staffManager = useStaffManager();

    // Get staff detail function that uses the hook - wrapped with useCallback to prevent infinite loops
    const getStaffDetailWithManager = useCallback(
      async (staffId, onUnauthorized) => {
        return new Promise((resolve, reject) => {
          staffManager.getStaffDetailWithCallbacks(
            staffId,
            (staffData) => resolve(staffData), // onSuccess
            (error) => reject(error), // onError
            () => {}, // onDone
            onUnauthorized, // onUnauthorized
          );
        });
      },
      [staffManager],
    );

    // Handle delete action
    const handleDeleteAction = useCallback(
      async (staffId, onUnauthorized) => {
        await staffManager.deleteStaff(staffId, onUnauthorized);
      },
      [staffManager],
    );

    return (
      <EntityActionConfirmationPage
        entityIcon={BriefcaseIcon}
        entityType="Staff Member"
        entityTypePlural="Staff"
        basePath="/admin/staff"
        entityParamName="aid"
        entityManager={staffManager}
        getEntityDetail={getStaffDetailWithManager}
        actionIcon={TrashIcon}
        actionName="Delete"
        actionDescription="Permanently Delete Staff Member - This action cannot be undone!"
        actionWarningPoints={[
          "The staff member will be permanently removed from the system",
          "All associated data, records, and history will be deleted",
          "Any assigned tasks, permissions, and access will be revoked",
          "This action cannot be reversed - the data will be lost forever",
        ]}
        actionButtonText="Permanently Delete"
        actionButtonVariant="danger"
        onActionExecute={handleDeleteAction}
        successMessage="Staff member has been permanently deleted"
        redirectPath="/admin/staff"
      />
    );
  },
);

function AdminStaffDetailMoreDeletePage() {
  return (
    <UIXThemeProvider>
      <AdminStaffDetailMoreDeletePageContent />
    </UIXThemeProvider>
  );
}

export default AdminStaffDetailMoreDeletePage;
