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

const InternalViewer = () => {
  const [searchParams] = useSearchParams();
  const location = useLocation();
  const view = searchParams.get("view") || "";
  const pageIndex = searchParams.get("page") || 1; // default to 'self'
  const stateBackurl = location.state?.backurl;
  const backurl = stateBackurl
    ? stateBackurl
    : view === "parent"
    ? `/record-management/userIncoming/internal?page=${pageIndex}&view=parent`
    : `/record-management/userIncoming/internal?page=${pageIndex}`;
  return (
    <LetterViewer
      backurl={backurl}
      type="internal"
      shouldFetchInstance={true}
      actions="InternalIncomingRecordActions"
    />
  );
};

export default InternalViewer;
