import React from "react";
import RecordAssignmentStats from "./RecordAssignmentStats";
import RecordAssignmentView from "./RecordAssignmentView";
import { useRecordAssignments } from "@/record-management/components/hooks/useRecordAssignment";
import { useReport } from "../../hooks/useReport";

interface ParentContainerProps {
  recordId: string;
  recordTitle: string;
  recordType: string;
  subject: string;
  createdDate: string;
  referenceNumber?: string;
  showStat?: boolean;
}

export const ParentContainer: React.FC<ParentContainerProps> = ({
  recordId,
  recordTitle,
  recordType,
  subject,
  createdDate,
  referenceNumber,
  showStat = false,
}) => {
  const {
    data: assignments,
    isLoading,
    error,
  } = useRecordAssignments(recordId);
  if (isLoading)
    return (
      <div className="text-gray-600 dark:text-gray-400 p-4">
        Loading assignments...
      </div>
    );
  if (error)
    return (
      <div className="text-red-600 dark:text-red-400 p-4">
        Error loading assignments
      </div>
    );
  if (!assignments)
    return (
      <div className="text-gray-500 dark:text-gray-400 p-4">
        No assignments found.
      </div>
    );
  return (
    <>
      {showStat && <RecordAssignmentStats recordId={recordId} />}

      <RecordAssignmentView
        recordId={recordId}
        recordTitle={recordTitle}
        recordType={recordType}
        subject={subject}
        createdDate={createdDate}
        referenceNumber={referenceNumber}
        assignmentChain={assignments}
        multipleAssignments={[]} // or split as you want
        loading={isLoading}
      />
    </>
  );
};

export default ParentContainer;
