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

import React from "react";
import {
  BuildingOffice2Icon,
  ArchiveBoxIcon,
} from "@heroicons/react/24/outline";
import { useDivisionManager } from "../../../../../../services/Services";
import { EntityActionConfirmationPage } from "../../../../../../components/business/views";

function AdminDivisionDetailMoreArchivePage() {
  const divisionManager = useDivisionManager();

  // Get division detail function
  const getDivisionDetail = async (divisionId, onUnauthorized) => {
    return new Promise((resolve, reject) => {
      divisionManager.getDivisionDetailWithCallbacks(
        divisionId,
        (divisionData) => {
          // Check if division is already archived
          if (divisionData.status === 3) {
            reject(new Error("This division is already archived."));
            return;
          }
          resolve(divisionData);
        },
        (error) => reject(error),
        () => {},
        onUnauthorized,
      );
    });
  };

  // Execute archive action
  const onArchiveExecute = async (divisionId, onUnauthorized) => {
    return new Promise((resolve, reject) => {
      divisionManager.archiveDivisionWithCallbacks(
        divisionId,
        (response) => resolve(response),
        (error) => reject(error),
        () => {},
        onUnauthorized,
      );
    });
  };

  return (
    <EntityActionConfirmationPage
      entityIcon={BuildingOffice2Icon}
      entityType="Division"
      entityTypePlural="Divisions"
      basePath="/admin/division"
      entityParamName="id"
      entityManager={divisionManager}
      getEntityDetail={getDivisionDetail}
      actionIcon={ArchiveBoxIcon}
      actionName="Archive"
      actionDescription="Archive this division and remove it from active lists."
      actionWarningPoints={[
        "The division will no longer appear in the active divisions list",
        "Division members will not be able to access division features",
        "All current data and history will remain but the division cannot perform new operations",
        "This action can be undone by contacting a system administrator",
      ]}
      actionButtonText="Archive Division"
      actionButtonVariant="warning"
      onActionExecute={onArchiveExecute}
      successMessage="Division has been successfully archived!"
      redirectPath="/admin/divisions"
    />
  );
}

export default AdminDivisionDetailMoreArchivePage;
