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

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

function AdminDivisionDetailMoreUnarchivePage() {
  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 actually archived
          if (divisionData.status !== 3) {
            reject(
              new Error(
                "This division is not archived and cannot be unarchived.",
              ),
            );
            return;
          }
          resolve(divisionData);
        },
        (error) => reject(error),
        () => {},
        onUnauthorized,
      );
    });
  };

  // Execute unarchive action
  const onUnarchiveExecute = async (divisionId, onUnauthorized) => {
    return new Promise((resolve, reject) => {
      divisionManager.unarchiveDivisionWithCallbacks(
        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={ArchiveBoxXMarkIcon}
      actionName="Unarchive"
      actionDescription="Restore this division from archived status to active status."
      actionWarningPoints={[
        "This division will become active again",
        "All associated users will regain access",
        "The division will appear in active searches",
        "All previous settings and data will be restored",
        "Division activities and events will be accessible",
      ]}
      actionButtonText="Unarchive Division"
      actionButtonVariant="success"
      onActionExecute={onUnarchiveExecute}
      successMessage="Division successfully unarchived!"
      redirectPath="/admin/divisions"
    />
  );
}

export default AdminDivisionDetailMoreUnarchivePage;
