import { useNavigate, useSearchParams, useLocation } from "react-router-dom";
import LetterViewer from "../../common/letterViewer";
const IncomingViewer = () => {
  const [searchParams] = useSearchParams();
  const location = useLocation();
  const view = searchParams.get("view") || ""; // default to 'self'
  const pageIndex = searchParams.get("page") || 1;
  const stateBackurl = location.state?.backurl;
  const backurl = stateBackurl
    ? stateBackurl
    : view === "parent"
    ? `/record-management/userIncoming?page=${pageIndex}&view=parent`
    : `/record-management/userIncoming?page=${pageIndex}`;
  return (
    <LetterViewer
      backurl={backurl}
      type="externalincoming"
      shouldFetchInstance={true}
      actions="ExternalIncomingRecordActions"
    />
  )
};

export default IncomingViewer;
