import { useSearchParams } from "react-router-dom";
import LetterViewer from "../common/letterViewer";
import { useAuthUser } from "@/shared/hooks/useAuthUser";
import { useUnitConfiguration } from "@/shared/hooks/useUnitConfiguration";

const PendingRecords = () => {
  const [searchParams] = useSearchParams();
  const pageIndex = searchParams.get("page") || 1;

  const { userDetails } = useAuthUser();
  const unitId = userDetails?.employee?.[0]?.unitId ?? "";
  const { data: unitConfigData } = useUnitConfiguration(unitId, {
    enabled: !!unitId,
  });
  const canROReturn =
    unitConfigData?.data?.items?.[0]?.canROReturn ?? false;

  const backToTable = `/record-management/pending/?page=${pageIndex}`;

  return (
    <LetterViewer
      backurl={backToTable}
      type="userRecord"
      shouldFetchInstance={false}
      actions="PendingRecordDetailActions"
      actionRowData={{ canROReturn, backToTable }}
    />
  );
};

export default PendingRecords;
