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

import React, { useCallback } from "react";
import {
  CurrencyDollarIcon,
  EllipsisHorizontalIcon,
  DocumentDuplicateIcon,
  DocumentIcon,
  DocumentTextIcon,
  ChartBarIcon,
} from "@heroicons/react/24/outline";
import { useEventOrderManager } from "../../../../../services/Services";
import { EntityMorePage } from "../../../../../components/business/views";
import { ORDER_STATUS_ARCHIVED } from "../../../../../constants/Order";

// Financial constants
const FINANCIAL_STATUS_ACTIVE = 1;
const FINANCIAL_STATUS_ARCHIVED = ORDER_STATUS_ARCHIVED;

const FINANCIAL_CONSTANTS = {
  FINANCIAL_STATUS_ACTIVE,
  FINANCIAL_STATUS_ARCHIVED,
};

// Function to create tab items for financial
const createFinancialTabItems = (financial, financialId) => [
  {
    label: "Summary",
    href: `/admin/financial/${financial.id}`,
    isActive: false,
    icon: DocumentTextIcon,
  },
  {
    label: "More",
    href: `/admin/financial/${financial.id}/more`,
    isActive: true,
    icon: EllipsisHorizontalIcon,
  },
];

// Function to create action cards for financial
const createFinancialActionCards = (financial, financialId, constants) => {
  const actionCards = [];

  if (financial) {
    // Clone action - Available for all financial records
    actionCards.push({
      key: "clone",
      title: "Clone",
      subtitle: "Create a copy of this financial record",
      icon: DocumentDuplicateIcon,
      path: `/admin/financial/${financialId}/more/clone`,
      disabled: false,
    });

    // Generate Report action
    actionCards.push({
      key: "report",
      title: "Generate Report",
      subtitle: "Generate a financial report for this record",
      icon: DocumentIcon,
      path: `/admin/financial/${financialId}/report`,
      disabled: false,
    });
  }

  return actionCards;
};

function AdminFinancialDetailMorePage() {
  const orderManager = useEventOrderManager();

  // Custom get financial detail function wrapped with useCallback to prevent infinite loops
  const getFinancialDetailWithManager = useCallback(
    async (financialId, onUnauthorized) => {
      // Financial uses EventOrderManager for data operations
      return await orderManager.getEventOrderDetail(
        financialId,
        onUnauthorized,
      );
    },
    [orderManager],
  );

  return (
    <EntityMorePage
      entityIcon={CurrencyDollarIcon}
      entityType="Financial Record"
      entityTypePlural="Financial Records"
      basePath="/admin/financials"
      entityParamName="oid"
      entityManager={orderManager}
      getEntityDetail={getFinancialDetailWithManager}
      createTabItems={createFinancialTabItems}
      createActionCards={createFinancialActionCards}
      constants={FINANCIAL_CONSTANTS}
      infoMessage="Financial actions allow you to manage and generate reports for financial records."
    />
  );
}

export default AdminFinancialDetailMorePage;
