import useCounter from "@/record-management/components/hooks/useCounter";

export interface CounterProps {
  totalOutgoingRecords: number;
  totalIncomingRecords: number;
  totalInternalRecords: number;
  totalExternalRecords: number;
  totalCcRecords: number;
  totalForYourReferenceRecords: number;
  totalApprovalRecords: number;
  totalReassignedRecords: number;
  totalRejectedRecords: number;
  totalInProgressRecords: number;
  totalAcceptedRecords: number;
  totalInternalInProgressRecords: number;
  totalInternalAcceptedRecords: number;
  totalInternalReassignedRecords: number;
  totalInternalRejectedRecords: number;
  totalIncoming: any[];
  totalOutgoing: any[];
  totalApproval: any[];
}

const UseDashboard = () => {
  const {
    tot,
    TotalExternal,
    TotalInternal,
    TotalCC,
    TotalApproval,
    externalCountReassigned,
    externalCountRejected,
    externalCountAccepted,
    draftCount,
    internalCountReassigned,
    internalCountRejected,
    internalCountAccepted,
    internalCountdraft,
    TotalIncomingRecordsDrafts,
    TotalIncomingRecordsAccepted,
    TotalIncomingRecordsReassigned,
    TotalIncomingRecordsRejected,
    outgoingCounters,
    approvalCounters,
    isLoading,
  } = useCounter();

  const totalForYourReferenceRecords = 0;

  const OutgoingRecords = [
    {
      name: "Draft",
      value: outgoingCounters.Draft || 0,
    },
    {
      name: "Accepted",
      value: outgoingCounters.Accepted || 0,
    },
    {
      name: "Rejected",
      value: outgoingCounters.Rejected || 0,
    },
    {
      name: "Adjustment",
      value: outgoingCounters.Adjustment || 0,
    },
    {
      name: "Sent",
      value: outgoingCounters.Dispatched || 0,
    },
    {
      name: "Submitted",
      value: outgoingCounters.Submitted || 0,
    },
    {
      name: "Approved",
      value: outgoingCounters.Approved || 0,
    },
    {
      name: "Returned",
      value: outgoingCounters.Returned || 0,
    },
  ];

  const IncomingRecords = [
    {
      name: "In Progress",
      value: TotalIncomingRecordsDrafts || 0,
    },
    {
      name: "Accepted",
      value: TotalIncomingRecordsAccepted || 0,
    },
    {
      name: "Rejected",
      value: TotalIncomingRecordsRejected || 0,
    },
    {
      name: "Reassigned",
      value: TotalIncomingRecordsReassigned || 0,
    },
  ];

  const ApprovalRecords = [
    {
      name: "In progress",
      value: approvalCounters.active || 0,
    },
    {
      name: "Accepted",
      value: approvalCounters.accepted || 0,
    },
    {
      name: "Rejected",
      value: approvalCounters.rejected || 0,
    },
    {
      name: "Adjustment",
      value: approvalCounters.adjustment || 0,
    },
    {
      name: "Approved",
      value: approvalCounters.approved || 0,
    },
  ];

  const TotalIncoming = TotalExternal + TotalInternal + TotalCC;

  return {
    totalOutgoingRecords: tot || 0,
    totalIncomingRecords: TotalIncoming || 0,
    totalInternalRecords: TotalInternal || 0,
    totalExternalRecords: TotalExternal || 0,
    totalCcRecords: TotalCC || 0,
    totalApprovalRecords: TotalApproval || 0,
    totalReassignedRecords: externalCountReassigned || 0,
    totalInProgressRecords: draftCount,
    totalAcceptedRecords: externalCountAccepted,
    totalRejectedRecords: externalCountRejected || 0,
    totalInternalInProgressRecords: internalCountdraft || 0,
    totalInternalAcceptedRecords: internalCountAccepted || 0,
    totalInternalReassignedRecords: internalCountReassigned || 0,
    totalInternalRejectedRecords: internalCountRejected || 0,
    totalIncoming: IncomingRecords,
    totalOutgoing: OutgoingRecords,
    totalApproval: ApprovalRecords,
    isLoading: isLoading,
    totalForYourReferenceRecords: totalForYourReferenceRecords || 0,
  };
};

export default UseDashboard;
