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

import React, { useCallback } from "react";
import {
  TicketIcon,
  EllipsisHorizontalIcon,
  ArchiveBoxIcon,
  ArchiveBoxXMarkIcon,
  TrashIcon,
  EyeIcon,
  DocumentTextIcon,
  ChatBubbleLeftRightIcon,
  PaperClipIcon,
  ChartBarIcon,
} from "@heroicons/react/24/outline";
import {
  useEventContractManager,
} from "../../../../../services/Services";
import { EntityMorePage } from "../../../../../components/business/views";

// EventContract constants
const EVENT_CONTRACT_STATUS_ACTIVE = 1;
const EVENT_CONTRACT_STATUS_ARCHIVED = 2;

const EVENT_CONTRACT_CONSTANTS = {
  EVENT_CONTRACT_STATUS_ACTIVE,
  EVENT_CONTRACT_STATUS_ARCHIVED,
};

// Function to create tab items for event contract
const createEventContractTabItems = (eventContract, eventContractId) => [
  {
    label: "Quick View",
    href: `/admin/event-contract/${eventContract.id}`,
    isActive: false,
    icon: EyeIcon,
  },
  {
    label: "Full Details",
    href: `/admin/event-contract/${eventContract.id}/full`,
    isActive: false,
    icon: DocumentTextIcon,
  },
  {
    label: "Comments",
    href: `/admin/event-contract/${eventContract.id}/comments`,
    isActive: false,
    icon: ChatBubbleLeftRightIcon,
  },
  {
    label: "Attachments",
    href: `/admin/event-contract/${eventContract.id}/attachments`,
    isActive: false,
    icon: PaperClipIcon,
  },
  {
    label: "More",
    href: `/admin/event-contract/${eventContract.id}/more`,
    isActive: true,
    icon: EllipsisHorizontalIcon,
  },
];

// Function to create action cards for event contract
const createEventContractActionCards = (eventContract, eventContractId, constants) => {
  const actionCards = [];

  if (eventContract) {
    // Archive/Unarchive
    if (eventContract.status === constants.EVENT_CONTRACT_STATUS_ARCHIVED) {
      actionCards.push({
        key: "unarchive",
        title: "Unarchive",
        subtitle: "Make event contract visible in list and search results",
        icon: ArchiveBoxXMarkIcon,
        path: `/admin/event-contract/${eventContractId}/more/unarchive`,
        disabled: false,
      });
    } else {
      actionCards.push({
        key: "archive",
        title: "Archive",
        subtitle: "Hide event contract from list and search results",
        icon: ArchiveBoxIcon,
        path: `/admin/event-contract/${eventContractId}/more/archive`,
        disabled: false,
      });
    }

    // Delete - For Executive/Management roles (EntityMorePage will handle role filtering)
    actionCards.push({
      key: "delete",
      title: "Delete",
      subtitle: "Permanently delete this event contract and all related data",
      icon: TrashIcon,
      path: `/admin/event-contract/${eventContractId}/more/delete`,
      disabled: false,
    });
  }

  return actionCards;
};

function AdminEventContractDetailMorePage() {
  const eventContractManager = useEventContractManager();

  // Custom get event contract detail function wrapped with useCallback to prevent infinite loops
  const getEventContractDetailWithManager = useCallback(async (eventContractId, onUnauthorized) => {
    return await eventContractManager.getEventContractDetail(eventContractId, onUnauthorized);
  }, [eventContractManager]);

  return (
    <EntityMorePage
      entityIcon={TicketIcon}
      entityType="Event Contract"
      entityTypePlural="Event Contracts"
      basePath="/admin/event-contracts"
      entityParamName="eventContractID"
      entityManager={eventContractManager}
      getEntityDetail={getEventContractDetailWithManager}
      createTabItems={createEventContractTabItems}
      createActionCards={createEventContractActionCards}
      constants={EVENT_CONTRACT_CONSTANTS}
      infoMessage="Some actions may affect the event contract's visibility or permanently remove data. Executive and Management roles have access to additional administrative actions."
    />
  );
}

export default AdminEventContractDetailMorePage;
