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

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

// Step 4: Create memoized content component
const AdminStaffDetailMoreArchivePageContent = memo(
  function AdminStaffDetailMoreArchivePageContent() {
    const staffManager = useStaffManager();

    // Step 6: Wrap event handlers with useCallback
    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],
    );

    const handleArchiveAction = useCallback(
      async (staffId, onUnauthorized) => {
        await staffManager.archiveStaff(staffId, onUnauthorized);
      },
      [staffManager],
    );

    return (
      <EntityActionConfirmationPage
        entityIcon={BriefcaseIcon}
        entityType="Staff Member"
        entityTypePlural="Staff"
        basePath="/admin/staff"
        entityParamName="aid"
        entityManager={staffManager}
        getEntityDetail={getStaffDetailWithManager}
        actionIcon={ArchiveBoxIcon}
        actionName="Archive"
        actionDescription="Archive Staff Member - Are you sure?"
        actionWarningPoints={[
          "The staff member will no longer appear in the active staff list",
          "The staff member will not be able to log in to their account",
          "All current assignments and permissions will be suspended",
          "This action can be undone by contacting a system administrator",
        ]}
        actionButtonText="Confirm and Archive"
        actionButtonVariant="danger"
        onActionExecute={handleArchiveAction}
        successMessage="Staff member has been successfully archived"
        redirectPath="/admin/staff"
      />
    );
  },
);

// Step 3: Wrap main export with UIXThemeProvider
function AdminStaffDetailMoreArchivePage() {
  return (
    <UIXThemeProvider>
      <AdminStaffDetailMoreArchivePageContent />
    </UIXThemeProvider>
  );
}

export default AdminStaffDetailMoreArchivePage;
