import Link from "next/link";
import { useState, useEffect } from "react";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
import jsonpath from "jsonpath";
import _ from "lodash";
import {
Field,
FieldArray,
reduxForm,
formValueSelector,
reset,
} from "redux-form";
import { connect } from "react-redux";
import { useDropzone } from "react-dropzone";
import {
setRepresentationCapacity,
setRepresentationSubmit,
setSubmitBack,
setRepresentationSubmitConfirmation,
} from "../../../store/currentView/action";
import RepCapacitySelection from "./representationCapacitySelection";
import RepDetails from "./representationDetails";
import RepAppellant from "./representationAppellant";
import RepAgent from "./representationAgent";
import RepInterestedPartyPerson from "./representationInterestedPartyPerson";
import RepLandOwner from "./representationLandowner";
import RepCompleteSubmit from "./representationCompleteSubmit";
import { useSession, signIn, signOut } from "next-auth/react";
import {
RenderPickList,
RenderRadioList,
RenderTextfield,
} from "./representationElements";
let MakeRepresentation = (props) => {
let { t } = useTranslation();
const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
const [clearRepForm, setClearRepForm] = useState(false);
const { data: session } = useSession();
const router = useRouter();
const { locale } = router;
const {
caseReference,
myCases,
myRepresentations,
watchedCases,
awaitingSubmission,
searchResultsObj,
representationSubmit,
currentType,
currentView,
setRepresentationCapacity,
setRepresentationSubmit,
setSubmitBack,
handleSubmit,
setRepresentationSubmitConfirmation,
} = props;
const formObj = props.props.form;
let setCaseQueryObj = props[currentType];
var casesObj = {};
currentType == "searchResultsObj"
? (casesObj = jsonpath.query(
setCaseQueryObj,
'$..[?(@.title=="' + caseReference + '")]'
))
: (casesObj = jsonpath.query(
setCaseQueryObj,
'$..[?(@.reference=="' + caseReference + '")]'
));
casesObj = Object.assign({}, ...casesObj);
const capacityOptionsArr = [
"Appellant",
"Agent",
"Interested Party/Person",
"Land Owner",
];
const appellantApplicantRepresentationArr = [
"Other",
"Statement",
"Statement of common ground",
"Written statement of evidence",
];
const interestedPersonRepresentationArr = [
"Interested Party/Person correspondence",
];
const landOwnerRepresentationArr = [
"Other",
"Statement",
"Written statement of evidence",
];
const repCapacityType = () => {
return _.isEmpty(formObj["representationForm"])
? false
: _.isEmpty(formObj["representationForm"].values)
? false
: _.isEmpty(
formObj["representationForm"].values.representationCapacity
)
? false
: formObj["representationForm"].values.representationCapacity
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
.toLowerCase();
};
const whichControl = () => {
switch (currentView.representationCapacity) {
case false:
return (