import useTranslation from "next-translate/useTranslation";
import Link from "next/link";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { useSession } from "next-auth/react";
import { setCurrentView } from "../store/currentView/action";
import { change } from "redux-form";
import { setCurrentSection } from "../store/appealType/action";
import {
setRepresentationCapacity,
setRepresentationSubmit
} from "../store/currentView/action";
import { resolveCaseBreadcrumbState } from "../lib/routing/routeState";
const Breadcrumbs = (props) => {
const {
currentView,
setCurrentSection,
setRepresentationSubmit,
appealType,
showQuestionnaireSection,
setShowQuestionnaireSection
} = props;
const router = useRouter();
let { t } = useTranslation();
const { data: session } = useSession();
const nestedProps = props?.props || {};
const nestedSearchString = nestedProps?.search?.searchString || "";
const nestedCurrentReference =
nestedProps?.currentView?.caseReference?.currentReference || "";
const isWelsh = router.locale === "cy";
const localisedPath = (englishPath, welshSuffixPath) =>
isWelsh ? `/${router.locale}${welshSuffixPath}` : englishPath;
const currentReference =
currentView?.caseReference?.currentReference || nestedCurrentReference;
const fallbackSearchTitle =
props?.searchResultsObj?.searchResultsObj?.value?.[0]?.title || "";
const caseReferenceDisplay = currentReference || fallbackSearchTitle;
const myPortalHref = localisedPath("/myportal", "/fymhorth");
const cyMyPortalHref = myPortalHref;
const pathname = router.pathname;
const isPath = (path) => pathname === path;
const caseReference = currentView?.caseReference || {};
const currentViewState = currentView?.currentView || {};
const repDetails = caseReference?.repDetails;
const hasRepDetails = Object.prototype.hasOwnProperty.call(
caseReference,
"repDetails"
);
const qcount =
caseReference.appealType === 846040000 ||
caseReference.appealType === 846040001 ||
caseReference.appealType === 846040025 ||
caseReference.appealType === 846040004 ||
caseReference.appealType === 846040018 ||
caseReference.appealType === 846040003 ||
caseReference.appealType === 846040009 ||
caseReference.appealType === 846040008
? 7
: caseReference.appealType === 846040005 ||
caseReference.appealType === 846040006 ||
caseReference.appealType === 846040007
? 9
: "";
const hideServiceNamePaths = [
"/myportal/[appealtypes]",
"/newappeal",
"/newappeal/[appealtypes]",
"/myportal/representation"
];
const shouldShowServiceName = !hideServiceNamePaths.includes(pathname);
const getViewAllLabel = (viewKey) => {
const labelsByKey = {
awaitingSubmissionDetails: t(
"myportal:awatitingsubmission-card-title"
),
watchedCases: t("myportal:watchedcases-card-title"),
myCases: t("myportal:mycases-card-title"),
myRepresentations: t("myportal:myrepresentations-card-title"),
mySubmittedReps: "Submitted representations"
};
return labelsByKey[viewKey] || null;
};
const renderMyPortalCrumb = () => (
{t("common:breadcrumb-my-portal")}
);
const renderCaseReferenceCrumb = (referenceValue) => (
{t("common:breadcrumb-case-reference")}: {referenceValue}
);
const renderTextCrumb = (label) => (
{label}
);
const renderLinkCrumb = (href, label, onClick) => (
{label}
);
const { breadcrumbHref, caseResultsHref, breadcrumbLabel } =
resolveCaseBreadcrumbState({
query: router.query,
hasSession: Boolean(session),
getViewAllLabel,
advancedLabel: t("common:breadcrumb-advanced-search-results"),
addressLabel: t("common:breadcrumb-address-search-results"),
defaultLabel: t("common:breadcrumb-search-results")
});
return (
<>
>
);
};
const mapStateToProps = (state) => ({
currentView: state.currentView,
appealType: state.appealType,
searchResultsObj: state.searchResultsObj,
search: state.search
});
const mapDispatchToProps = (dispatch) => {
return {
updateField: (form, field, newValue) =>
dispatch(change(form, field, newValue)),
setRepresentationCapacity: (representationCapacity) => {
//dispatch(reset("representationForm"));
dispatch(setRepresentationCapacity(representationCapacity));
},
setRepresentationSubmit: (representationSubmit) => {
dispatch(setRepresentationSubmit(representationSubmit));
},
setCurrentView: (currentView) => {
dispatch(setCurrentView(currentView));
},
setCurrentSection: (currentSection) => {
dispatch(setCurrentSection(currentSection));
}
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Breadcrumbs);