import { useSearchParams, useLocation } from "react-router-dom";
import LetterViewer from "../../common/letterViewer";

const ForYourReferenceViewer = () => {
  const [searchParams] = useSearchParams();
  const location = useLocation();
  const view = searchParams.get("view") || "";
  const pageIndex = searchParams.get("page") || 1;
  const stateBackurl = location.state?.backurl;

  const backurl = stateBackurl
    ? stateBackurl
    : view === "parent"
      ? `/record-management/userIncoming/for-your-reference?page=${pageIndex}&view=parent`
      : `/record-management/userIncoming/for-your-reference?page=${pageIndex}`;

  return (
    <LetterViewer
      backurl={backurl}
      type="cc"
      shouldFetchInstance={false}
      actions="CCIncomingRecordActions"
    />
  );
};

export default ForYourReferenceViewer;
