import Timeline from "@mui/lab/Timeline";
import TimelineContent from "@mui/lab/TimelineContent";
import TimelineOppositeContent, {
  timelineOppositeContentClasses,
} from "@mui/lab/TimelineOppositeContent";
import {
  // Button,
  Card,
  IconButton,
  // Paper,
  // Step,
  // StepContent,
  // StepLabel,
  // Stepper,
  // ToggleButton,
  // ToggleButtonGroup,
  Typography,
} from "@mui/material";
import { Box } from "@mui/system";
import { SPACING } from "../data/spacing";
import { PropTypes } from "prop-types";
import React, { useEffect } from "react";
import { Grid } from "../components/grid/Grid";
import { useParams } from "react-router-dom";
import { formatTime } from "../utils/formatTime";
import { FileInformation } from "../features/file/components/file-information/FileInformation";
import { CityInformation } from "../features/file/components/city-information/CityInformation";
// import CityFileOperations from "../features/file/components/city-file-operations/CityFileOperations";
// import ProvinceCheckRequest from "../features/file/components/province-check-request/ProvinceCheckRequest";
import { ProvinceInformation } from "../features/file/components/province-information/ProvinceInformation";
import useRequestFile from "../features/file/hooks/useRequestFile";
// import { ProvinceAllocation } from "../features/file/components/province-allocation/ProvinceAllocation";
// import SlaughterCheckRequest from "../features/file/components/slaughter-check-request/SlaughterCheckRequest";
// import SlaughterAssignCar from "../features/file/components/slaughter-assign-car/SlaughterAssignCar";
import useGetAllocationInformation from "../features/file/hooks/useGetAllocationInformation";
// import { SlaughterEnterBarWeight } from "../features/file/components/slaughter-enter-bar-weight/SlaughterEnterBarWeight";
// import { useSlaughterAllocatedRequests } from "../features/file/hooks/useSlaughterAllocatedRequests";
import FinancialCheckRequestInformation from "../features/file/components/financial-check-request-information/FinancialCheckRequestInformation";
import useUserProfile from "../features/authentication/hooks/useUserProfile";
import { FinancialCheckRequestOperation } from "../features/file/components/financial-check-request-operation/FinancialCheckRequestOperation";
import { getRoleFromUrl } from "../utils/getRoleFromUrl";
import { SlaughterPayProvinceFactorForm } from "../features/file/components/slaughter-pay-province-factor-form/SlaughterPayProvinceFactorForm";
import SlaughterPaymentFactor from "../features/file/components/slaughter-payment-factor/SlaughterPaymentFactor";
// import ProvinceFinancialSlaughterCheckRequest from "../features/file/components/province-financial-slaughter-check-request/ProvinceFinancialSlaughterCheckRequest";
import { Factor } from "../features/province-finacial/components/factor/Factor";
import { ProvinceAllocationInformation } from "../features/file/components/province-allocation-information/ProvinceAllocationInformation";
// import { InspectorRequestOperations } from "../features/file/components/inspector-request-operations/InspectorRequestOperations";
// import { useAcceptedSlaughterRequest } from "../features/file/hooks/useAcceptedSlaughterRequest";
// import SlaughterHouseVetCheckRequest from "../features/file/components/slaughter-house-vet-check-request/SlaughterHouseVetCheckRequest";
// import { useAcceptedSlaughterRequest } from "../features/file/hooks/useAcceptedSlaughterRequest";
import NavigateNextIcon from "@mui/icons-material/NavigateNext";
import { useNavigate } from "react-router-dom";
import { useDispatch } from "react-redux";
import { cleanFile } from "../lib/redux/slices/fileSlice";
// import { Timer } from "../components/timer/Timer";
// import moment from "moment";
import { getMonthlyPercent } from "../features/file/services/get-monthly-percent";
// import { SlaughterPayPoultryFactorForm } from "../features/file/components/slaughter-pay-poultry-factor-form/SlaughterPayPoultryFactorForm";
import { SlaughterPaymentFactorPoultry } from "../features/file/components/slaughter-payment-factor-poultry/SlaughterPaymentFactorPoultry";
// import { CityInformationTitle } from "../features/file/components/city-information/CityInformationTitle";
// import { CityInformationContent } from "../features/file/components/city-information/CityInformationContent";
// import { ProvinceInformationTitle } from "../features/file/components/province-information/ProvinceInformationTitle";
// import { ProvinceInformationContent } from "../features/file/components/province-information/ProvinceInformationContent";
// import { ProvinceAllocationTitle } from "../features/file/components/province-allocation/ProvinceAllocationTitle";
// import { ProvinceAllocationContent } from "../features/file/components/province-allocation/ProvinceAllocationContent";
// import { ProvinceAllocationInformationContent } from "../features/file/components/province-allocation-information/ProvinceAllocationInformationContent";
// import FinancialCheckRequestInformationContent from "../features/file/components/financial-check-request-information/FinancialCheckRequestInformationContent";
// import { StateStepper } from "../components/state-stepper/StateStepper";
// import { SlaghterCheckRequestTitle } from "../features/file/components/slaghter-check-request-title/SlaghterCheckRequestTitle";
// import { SlaghterAssignCarTitle } from "../features/file/components/slaughter-assign-car-title/SlaughterAssignCarTitle";
// import { FinancialCreateFactorTitle } from "../features/file/components/financial-create-factor-title/FinancialCreateFactorTitle";
// import { FinancialCheckRequestTitle } from "../features/file/components/financial-check-request-title/FinancialCheckRequestTitle";
// import { FinalFactorTitle } from "../features/file/components/final-factor-title/FinalFactorTitle";
// import { InspectorCheckRequestTitle } from "../features/file/components/inspector-check-request-title/InspectorCheckRequestTitle";
// import CloseFileFinancialInfo from "../features/file/components/close-file-financial-info/CloseFileFinancialInfo";
import { InspectorInformation } from "../features/file/components/inspector-information/InspectorInformation";
import { FileOperatorCheckComplaint } from "../features/file/components/file-operator-check-complaint/FileOperatorCheckComplaint";
import {
  TimelineConnector,
  TimelineDot,
  TimelineItem,
  TimelineSeparator,
} from "@mui/lab";
import { FileComplaint } from "../features/file/components/file-complaint/FileComplaint";

const NewFile = () => {
  // vertical steppere
  // const [activeStep, setActiveStep] = React.useState(0);

  // const handleReset = () => {
  //   setActiveStep(0);
  // };

  const navigate = useNavigate();
  const dispatch = useDispatch();
  const { id } = useParams();
  const myFile = useRequestFile(id);
  const [roles] = useUserProfile();

  // const slaughterAllocatedRequests = useSlaughterAllocatedRequests(id);
  const process = myFile?.file?.process;
  const { quantity, provinceAssignments } = useGetAllocationInformation(
    process?.poultry?.poultryRequestKey
  );
  useEffect(() => {
    dispatch(getMonthlyPercent());
  }, []);

  const provinceKillRequests = process?.provinceKillRequests;
  // const acceptedSlaughterRequests = useAcceptedSlaughterRequest(id);

  // const showEnterBarInfo = process?.auction
  //   ? !!process?.auction?.filter((item) => item.barInfo === null).length
  //   : provinceKillRequests?.some((killRequest, i) => {
  //       const { killHouseRequests } = killRequest;
  //       if (killHouseRequests) {
  //         return !!killHouseRequests?.filter(
  //           (item) =>
  //             item.barInfo === null ||
  //             item.barInfo?.killHouseAssignmentState === "rejected"
  //         ).length;
  //       }
  //       return false;
  //     });

  // const showSlaughterHouseVetCheckRequest = process?.auction
  //   ? !!process?.auction?.filter((item) => item.barInfo === null).length
  //   : provinceKillRequests?.some((killRequest, i) => {
  //       const { killHouseRequests } = killRequest;
  //       if (killHouseRequests) {
  //         return !!killHouseRequests?.filter((item) => item.barInfo === null)
  //           .length;
  //       }
  //       return false;
  //     });

  useEffect(() => {
    return () => {
      dispatch(cleanFile());
    };
  }, []);

  // const requestInformation = "completed";
  // const city = process?.city === null;
  // const province =
  //   process?.city &&
  //   process?.province?.provinceState !== "reject" &&
  //   process?.province?.provinceState !== "accept";

  // const provinceAllocation =
  //   process?.city &&
  //   process?.province?.provinceState === "accept" &&
  //   quantity !== 0;

  // const slaghterCheckRequestLoop =
  //   provinceAssignments &&
  //   !!provinceKillRequests?.length &&
  //   Boolean(
  //     provinceKillRequests?.filter(
  //       (item) => item.provinceKillReqState !== "accepted"
  //     ).length
  //   );

  // const slaughterAllocation =
  //   acceptedSlaughterRequests.some((item) => item.quantity > 0) ||
  //   (process?.killHouseWinner && process?.killHouseWinner.quantity > 0);

  // const financialCreateAndPayFactor = !!provinceKillRequests?.filter(
  //   (killRequest, i) => {
  //     const { killHouseRequests } = killRequest;
  //     const d = killHouseRequests
  //       ?.filter((item) => item.barInfo !== null)
  //       .filter((item, i) => {
  //         const showSlaughterFactorForm =
  //           (item.barInfo &&
  //             item.provinceFactorToKillHouse &&
  //             (!item.killHouseFactorToProvince ||
  //               item.killHouseFactorToProvince.factorState === "rejected")) ||
  //           (item.provinceFactorToKillHouseForPoultry &&
  //             !item.killHouseFactorToPoultry) ||
  //           item.killHouseFactorToPoultry?.factorState === "rejected";
  //         return showSlaughterFactorForm;
  //       });
  //     return !!d?.length;
  //   }
  // ).length;

  // const financialFactorCheck = !!provinceKillRequests?.filter(
  //   (killRequest, i) => {
  //     const { killHouseRequests } = killRequest;
  //     return !!killHouseRequests
  //       ?.filter(
  //         (item) =>
  //           item?.barInfo &&
  //           (item.killHouseFactorToProvince || item?.killHouseFactorToPoultry)
  //       )
  //       .filter((item) => {
  //         return (
  //           item?.killHouseFactorToPoultry &&
  //           item?.killHouseFactorToPoultry?.factorState === "pending"
  //         );
  //       })
  //       .filter((item) => {
  //         return (
  //           item?.killHouseFactorToProvince &&
  //           item.killHouseFactorToProvince.factorState === "pending"
  //         );
  //       }).length;
  //   }
  // )?.length;

  // const finalFactor = process?.allocation;

  // const inspectorCheckRequest =
  //   process?.allocation &&
  //   process?.poultry?.poultryRequestFinalState === "archive";

  // let cityState,
  //   provinceState,
  //   provinceAllocationState,
  //   slaghterCheckRequestState,
  //   slaghterAllocationState,
  //   financialCreateAndPayFactorState,
  //   financialFactorCheckState,
  //   finalFactorState,
  // inspectorCheckRequestState;

  // cityState = city ? "pending" : "completed";

  // provinceState = province ? "pending" : "completed";
  // if (cityState === "pending") {
  //   provinceState = "locked";
  // }

  // provinceAllocationState = provinceAllocation ? "pending" : "completed";
  // if (provinceState === "pending" || provinceState === "locked") {
  //   provinceAllocationState = "locked";
  // }

  // slaghterCheckRequestState = slaghterCheckRequestLoop
  //   ? "pending"
  //   : "completed";
  // if (
  //   provinceAllocationState === "pending" ||
  //   provinceAllocationState === "locked"
  // ) {
  //   slaghterCheckRequestState = "locked";
  // }

  // slaghterAllocationState =
  //   slaughterAllocation || showEnterBarInfo ? "pending" : "completed";
  // if (
  //   slaghterCheckRequestState === "pending" ||
  //   slaghterCheckRequestState === "locked"
  // ) {
  //   slaghterAllocationState = "locked";
  // }

  // financialCreateAndPayFactorState = financialCreateAndPayFactor
  //   ? "pending"
  //   : "completed";
  // if (
  //   slaghterAllocationState === "pending" ||
  //   slaghterAllocationState === "locked"
  // ) {
  //   financialCreateAndPayFactorState = "locked";
  // }

  // financialFactorCheckState = financialFactorCheck ? "pending" : "completed";
  // if (
  //   financialCreateAndPayFactorState === "pending" ||
  //   financialCreateAndPayFactorState === "locked"
  // ) {
  //   financialFactorCheckState = "locked";
  // }

  // finalFactorState = finalFactor ? "pending" : "completed";
  // if (
  //   financialFactorCheckState === "pending" ||
  //   financialFactorCheckState === "locked"
  // ) {
  //   finalFactorState = "locked";
  // }

  // inspectorCheckRequestState = inspectorCheckRequest ? "completed" : "pending";
  // if (!finalFactorState === "completed") {
  // inspectorCheckRequestState = "locked";
  // }

  // const getStepState = (step) => {
  //   const stepStates = {
  //     0: requestInformation,
  //     1: cityState,
  //     2: provinceState,
  //     3: provinceAllocationState,
  //     4: slaghterCheckRequestState,
  //     5: slaghterAllocationState,
  //     6: financialCreateAndPayFactorState,
  //     7: financialFactorCheckState,
  //     8: finalFactorState,
  //     9: inspectorCheckRequestState,
  //   };
  //   return stepStates[step] ? stepStates[step] : "locked";
  // };

  const sellType = process?.filePaymentType;
  // const paymentPrice = "123000000";

  // const paymentDate = moment(new Date(2022, 11, 24, 10, 33, 30, 0));
  // const currentDate = moment();
  // const diff = paymentDate.diff(currentDate);
  // let paymentRemainedSeconds = moment.duration(diff).asSeconds();

  // let steps = [];
  if (process) {
    // steps = [
    //   {
    //     label: (
    //       <Grid container alignItems="flex-start">
    //         <Grid>
    //           <TimelineOppositeContent>
    //             <Typography variant="body1" fontWeight="bold">
    //               مشخصات درخواست
    //             </Typography>
    //           </TimelineOppositeContent>
    //         </Grid>
    //         <Grid>
    //           <TimelineContent color="textSecondary">
    //             <Grid container gap={SPACING.SMALL}>
    //               <Typography
    //                 variant="body2"
    //                 display="flex"
    //                 gap={SPACING.SMALL}
    //               >
    //                 درخواست در تاریخ
    //               </Typography>
    //               <Typography variant="body2" fontWeight="bold">
    //                 {formatTime(process?.poultry?.poultryRegisterDate)}
    //               </Typography>
    //               <Typography
    //                 variant="body2"
    //                 display="flex"
    //                 gap={SPACING.SMALL}
    //               >
    //                 ثبت شده است.
    //               </Typography>
    //             </Grid>
    //           </TimelineContent>
    //         </Grid>
    //       </Grid>
    //     ),
    //     description: <FileInformation file={process} />,
    //   },
    //   {
    //     label: <CityInformationTitle file={process} />,
    //     description: (
    //       <>
    //         <CityInformationContent file={process} />
    //         {(getRoleFromUrl() === "CityOperator" ||
    //           getRoleFromUrl() === "ProvinceOperator") &&
    //           process.city === null && <CityFileOperations file={process} />}
    //       </>
    //     ),
    //   },
    //   {
    //     label: <ProvinceInformationTitle file={process} />,
    //     description: (
    //       <>
    //         <ProvinceInformationContent file={process} />
    //         {!process.killHouseWinner &&
    //           getRoleFromUrl() === "ProvinceOperator" &&
    //           roles.includes("ProvinceOperator") &&
    //           process?.city &&
    //           process?.province?.provinceState !== "reject" &&
    //           process?.province?.provinceState !== "accept" && (
    //             <ProvinceCheckRequest file={process} />
    //           )}
    //       </>
    //     ),
    //   },
    //   {
    //     label: <ProvinceAllocationTitle file={process} />,
    //     description: (
    //       <>
    //         {!process.killHouseWinner &&
    //           provinceAssignments &&
    //           !!provinceKillRequests?.length &&
    //           provinceAssignments?.map((item, i) => {
    //             return (
    //               <Grid key={"ProvinceAllocationInformation" + i}>
    //                 <ProvinceAllocationInformationContent item={item} i={i} />
    //               </Grid>
    //             );
    //           })}
    //         {!process.auctionsList &&
    //           getRoleFromUrl() === "ProvinceOperator" &&
    //           roles.includes("ProvinceOperator") &&
    //           process?.city &&
    //           process?.province?.provinceState === "accept" &&
    //           quantity !== 0 && <ProvinceAllocationContent file={process} />}
    //       </>
    //     ),
    //   },
    //   {
    //     label: <SlaghterCheckRequestTitle />,
    //     description: (
    //       <>
    //         {!process.killHouseWinner &&
    //           provinceAssignments &&
    //           !!provinceKillRequests?.length &&
    //           provinceAssignments?.map((item, i) => {
    //             return (
    //               <Grid key={"ProvinceAllocationInformation" + i}>
    //                 <Grid>
    //                   <ProvinceAllocationInformationContent item={item} i={i} />
    //                 </Grid>
    //                 <Grid>
    //                   {!process.killHouseWinner &&
    //                     getRoleFromUrl() === "KillHouse" &&
    //                     roles.includes("KillHouse") &&
    //                     Boolean(
    //                       provinceKillRequests?.filter(
    //                         (item) => item.provinceKillReqState !== "accepted"
    //                       ).length
    //                     ) &&
    //                     item.provinceKillRequestState === "pending" && (
    //                       <SlaughterCheckRequest
    //                         key={"SlaughterCheckRequest" + i}
    //                         item={item}
    //                         i={i}
    //                         poultryRequestKey={
    //                           process?.poultry?.poultryRequestKey
    //                         }
    //                       />
    //                     )}
    //                 </Grid>
    //               </Grid>
    //             );
    //           })}
    //       </>
    //     ),
    //   },
    //   {
    //     label: <SlaghterAssignCarTitle />,
    //     description: (
    //       <>
    //         {!process.killHouseWinner &&
    //           provinceAssignments &&
    //           !!provinceKillRequests?.length &&
    //           provinceAssignments?.map((item, i) => {
    //             return (
    //               <Grid key={"ProvinceAllocationInformation" + i}>
    //                 <Grid>
    //                   <ProvinceAllocationInformationContent item={item} i={i} />
    //                 </Grid>
    //                 <Grid>
    //                   {!process.killHouseWinner &&
    //                     getRoleFromUrl() === "KillHouse" &&
    //                     roles.includes("KillHouse") &&
    //                     Boolean(
    //                       provinceKillRequests?.filter(
    //                         (item) => item.provinceKillReqState !== "accepted"
    //                       ).length
    //                     ) &&
    //                     item.provinceKillRequestState === "pending" && (
    //                       <SlaughterCheckRequest
    //                         key={"SlaughterCheckRequest" + i}
    //                         item={item}
    //                         i={i}
    //                         poultryRequestKey={
    //                           process?.poultry?.poultryRequestKey
    //                         }
    //                       />
    //                     )}
    //                 </Grid>
    //               </Grid>
    //             );
    //           })}
    //         {getRoleFromUrl() === "KillHouse" &&
    //           roles.includes("KillHouse") &&
    //           (acceptedSlaughterRequests.some((item) => item.quantity > 0) ||
    //             (process.killHouseWinner &&
    //               process.killHouseWinner.quantity > 0)) && (
    //             <SlaughterAssignCar
    //               file={process}
    //               provinceAllocationLimit={
    //                 provinceAssignments ? provinceAssignments[0]?.quantity : 0
    //               }
    //             />
    //           )}
    //         {(getRoleFromUrl() === "KillHouse" ||
    //           getRoleFromUrl() === "Poultry" ||
    //           getRoleFromUrl() === "ProvinceFinancial") &&
    //           (roles.includes("KillHouse") ||
    //             roles.includes("Poultry") ||
    //             roles.includes("ProvinceFinancial")) &&
    //           !!showEnterBarInfo && <SlaughterEnterBarWeight file={process} />}
    //       </>
    //     ),
    //   },
    //   {
    //     label: <FinancialCreateFactorTitle />,
    //     description: (
    //       <>
    //         {!process.killHouseWinner &&
    //           provinceKillRequests?.map((killRequest, i) => {
    //             const { killHouseRequests } = killRequest;
    //             const d = killHouseRequests
    //               ?.filter((item) => item.barInfo !== null)
    //               .map((item, i) => {
    //                 const showSlaughterFactorForm =
    //                   (item.barInfo &&
    //                     item.provinceFactorToKillHouse &&
    //                     (!item.killHouseFactorToProvince ||
    //                       item.killHouseFactorToProvince.factorState ===
    //                         "rejected")) ||
    //                   (item.provinceFactorToKillHouseForPoultry &&
    //                     !item.killHouseFactorToPoultry) ||
    //                   item.killHouseFactorToPoultry?.factorState === "rejected";
    //                 const data = [
    //                   [
    //                     item.barcod,
    //                     `${item.killHouseName} (${item.killHouseUserProvince}/${item.killHouseUserCity})`,
    //                     item.quantity + " قطعه",
    //                     item.car?.driverName + ` (${item.car?.driverMobile})`,
    //                     `${item.car?.typeCar} با پلاک ${item.car?.pelak}`,
    //                     item.barInfo.killHouseNetWeight + " کیلوگرم",
    //                     item.fee + " ریال",
    //                     <a
    //                       href={item.barInfo.killHouseImageWithoutLoad}
    //                       alt="دانلود سند خودرو بدون بار"
    //                       key="provinceKillRequests"
    //                     >
    //                       <img
    //                         src={item.barInfo.killHouseImageWithoutLoad}
    //                         width="100"
    //                         height="100"
    //                         alt="بدون بار"
    //                         className="images-file"
    //                       />
    //                     </a>,
    //                     <a
    //                       href={item.barInfo.killHouseImageWithLoad}
    //                       alt="دانلود سند خودرو با بار"
    //                       key="provinceKillRequests"
    //                     >
    //                       <img
    //                         src={item.barInfo.killHouseImageWithLoad}
    //                         width="100"
    //                         height="100"
    //                         alt="بدون بار"
    //                         className="images-file"
    //                         key="provinceKillRequests"
    //                       />
    //                     </a>,
    //                   ],
    //                 ];
    //                 return (
    //                   <Grid key={"killHouseRequests" + i}>
    //                     <FinancialCheckRequestInformationContent
    //                       item={data}
    //                       data={item}
    //                       auction={false}
    //                     />
    //                     {getRoleFromUrl() === "ProvinceFinancial" &&
    //                       roles.includes("ProvinceFinancial") &&
    //                       !item.provinceFactorToKillHouse &&
    //                       item.barInfo.killHouseAssignmentState ===
    //                         "pending" && (
    //                         <FinancialCheckRequestOperation
    //                           item={item}
    //                           file={process}
    //                         />
    //                       )}
    //                     {(getRoleFromUrl() === "KillHouse" ||
    //                       getRoleFromUrl() === "ProvinceFinancial") &&
    //                       (roles.includes("KillHouse") ||
    //                         roles.includes("ProvinceFinancial")) &&
    //                       showSlaughterFactorForm && (
    //                         <>
    //                           {item.provinceFactorToKillHouse &&
    //                             (!item.killHouseFactorToProvince ||
    //                               item.killHouseFactorToProvince
    //                                 ?.factorState === "rejected") && (
    //                               <>
    //                                 <SlaughterPayProvinceFactorForm
    //                                   key={`SlaughterPayProvinceFactorForm${i}`}
    //                                   factorKey={
    //                                     item.provinceFactorToKillHouse
    //                                       ?.provinceFactorKey
    //                                   }
    //                                   price={
    //                                     item.provinceFactorToKillHouse?.cost
    //                                   }
    //                                   provinceFactorToKillHouse={
    //                                     item.provinceFactorToKillHouse
    //                                   }
    //                                   isRejected={
    //                                     item?.killHouseFactorToProvince
    //                                       ?.factorState === "rejected"
    //                                   }
    //                                   killHouseFactorToProvince={
    //                                     item.killHouseFactorToProvince
    //                                   }
    //                                 />
    //                               </>
    //                             )}
    //                           {!!item.provinceFactorToKillHouseForPoultry &&
    //                             (!item.killHouseFactorToPoultry ||
    //                               item.killHouseFactorToPoultry?.factorState ===
    //                                 "rejected") && (
    //                               <SlaughterPayPoultryFactorForm
    //                                 key={`SlaughterPayPoultryFactorForm${i}`}
    //                                 factorKey={
    //                                   item.provinceFactorToKillHouseForPoultry
    //                                     ?.provinceFactorKey
    //                                 }
    //                                 price={
    //                                   item.provinceFactorToKillHouseForPoultry
    //                                     ?.cost
    //                                 }
    //                                 provinceFactorToPoultry={
    //                                   item.provinceFactorToKillHouseForPoultry
    //                                 }
    //                                 isRejected={
    //                                   item?.killHouseFactorToPoultry
    //                                     ?.factorState === "rejected"
    //                                 }
    //                                 killHouseFactorToPoultry={
    //                                   item.killHouseFactorToPoultry
    //                                 }
    //                               />
    //                             )}
    //                         </>
    //                       )}
    //                   </Grid>
    //                 );
    //               });
    //             return d;
    //           })}
    //       </>
    //     ),
    //   },
    //   {
    //     label: <FinancialCheckRequestTitle />,
    //     description: (
    //       <>
    //         {provinceKillRequests?.map((killRequest, i) => {
    //           const { killHouseRequests } = killRequest;
    //           return killHouseRequests
    //             ?.filter(
    //               (item) =>
    //                 item.barInfo &&
    //                 (item.killHouseFactorToProvince ||
    //                   item.killHouseFactorToPoultry)
    //             )
    //             .map((item, i) => {
    //               return (
    //                 <>
    //                   {item?.killHouseFactorToProvince && (
    //                     <SlaughterPaymentFactor
    //                       key={`SlaughterPaymentFactor${i}`}
    //                       data={item.killHouseFactorToProvince}
    //                       barCode={item.barcod}
    //                     />
    //                   )}
    //                   {getRoleFromUrl() === "ProvinceFinancial" &&
    //                     roles.includes("ProvinceFinancial") &&
    //                     item?.killHouseFactorToProvince &&
    //                     item.killHouseFactorToProvince.factorState ===
    //                       "pending" && (
    //                       <>
    //                         <ProvinceFinancialSlaughterCheckRequest
    //                           factorKey={
    //                             item.killHouseFactorToProvince?.factorKey
    //                           }
    //                           factorType="province"
    //                         />
    //                       </>
    //                     )}
    //                   {item?.killHouseFactorToPoultry && (
    //                     <SlaughterPaymentFactorPoultry
    //                       key={`SlaughterPaymentFactor${i}`}
    //                       data={item.killHouseFactorToPoultry}
    //                       barCode={item.barcod}
    //                     />
    //                   )}
    //                   {item?.killHouseFactorToPoultry &&
    //                     getRoleFromUrl() === "ProvinceFinancial" &&
    //                     roles.includes("ProvinceFinancial") &&
    //                     item.killHouseFactorToPoultry.factorState ===
    //                       "pending" && (
    //                       <ProvinceFinancialSlaughterCheckRequest
    //                         factorKey={item.killHouseFactorToPoultry?.factorKey}
    //                         factorType="poultry"
    //                       />
    //                     )}
    //                 </>
    //               );
    //             });
    //         })}
    //       </>
    //     ),
    //   },
    //   {
    //     label: <FinalFactorTitle />,
    //     description: (
    //       <>
    //         {process.allocation && (
    //           <Grid xs={12}>
    //             <Factor process={process} />
    //           </Grid>
    //         )}
    //       </>
    //     ),
    //   },
    //   {
    //     label: <InspectorCheckRequestTitle />,
    //     description: (
    //       <>
    //         {getRoleFromUrl() === "ProvinceInspector" &&
    //           roles.includes("ProvinceInspector") &&
    //           process.allocation &&
    //           process?.poultry?.poultryRequestFinalState === "pending" && (
    //             <Grid>
    //               <Grid xs={12}>
    //                 <InspectorRequestOperations process={process} />
    //               </Grid>
    //             </Grid>
    //           )}
    //         {process.provinceIncpector.acceptRejectDate && (
    //           <InspectorInformation data={process.provinceIncpector} />
    //         )}
    //       </>
    //     ),
    //   },
    // ];
  }

  // const [viewType, setViewType] = React.useState("file");

  // const handleChangeViewType = (event, newAlignment) => {
  //   setViewType(newAlignment);
  // };

  // const control = {
  //   value: viewType,
  //   onChange: handleChangeViewType,
  //   exclusive: true,
  // };

  return (
    <>
      {process && (
        <Box mt={SPACING.MEDIUM} display={"flex"} justifyContent="center">
          <Grid
            container
            direction="column"
            justifyContent="center"
            xs={12}
            sm={12}
            md={10}
            lg={10}
          >
            <Grid container justifyContent="space-between" mb={SPACING.SMALL}>
              <Grid container alignItems="center">
                <IconButton
                  aria-label="delete"
                  color="primary"
                  onClick={() => navigate(-1)}
                >
                  <NavigateNextIcon />
                  <Typography>بازگشت</Typography>
                </IconButton>
              </Grid>
              {/* <Grid>
                <ToggleButtonGroup {...control} aria-label="Medium sizes">
                  <ToggleButton value="stepper" key="left">
                    نمایش بصورت مرحله ای
                  </ToggleButton>
                  <ToggleButton value="file" key="center">
                    نمایش بصورت پرونده
                  </ToggleButton>
                </ToggleButtonGroup>
              </Grid> */}
            </Grid>

            <Card>
              <Grid
                container
                px={SPACING.SMALL}
                gap={SPACING.TINY}
                justifyContent="space-between"
                direction="column"
              >
                <Grid container direction="column">
                  <Grid container>
                    <Typography variant="h6">
                      مشخصات پرونده با کد سفارش
                      {process?.poultry?.poultryOrderCode}
                    </Typography>
                  </Grid>
                  <Grid container gap={SPACING.TINY}>
                    <Grid>
                      {!process?.poultry?.poultryAuction ? (
                        <Typography variant="body2" color="secondary">
                          (فروش از طریق اتحادیه)
                        </Typography>
                      ) : (
                        <Typography variant="body2" color="secondary">
                          (فروش از طریق مزایده)
                        </Typography>
                      )}
                    </Grid>
                    <Grid>
                      {sellType === "cash" && (
                        <Typography
                          variant="body2"
                          color={(prop) => prop.palette.warning.dark}
                        >
                          (فروش نقدی)
                        </Typography>
                      )}
                      {sellType === "credit" && (
                        <Typography
                          variant="body2"
                          color={(prop) => prop.palette.warning.dark}
                        >
                          (فروش زمان دار - تا یک ماه)
                        </Typography>
                      )}
                      {sellType === "cash_credit" && (
                        <Typography
                          variant="body2"
                          color={(prop) => prop.palette.warning.dark}
                        >
                          (فروش بصورت نقدی و زمان دار)
                        </Typography>
                      )}
                    </Grid>
                  </Grid>
                </Grid>
              </Grid>

              {/* show file items */}

              <Timeline
                sx={{
                  gap: SPACING.MEDIUM,
                  [`& .${timelineOppositeContentClasses.root}`]: {
                    // flex: 0.2,
                  },
                }}
              >
                <TimelineItem sx={{ alignSelf: "flex-start", width: "100%" }}>
                  <TimelineSeparator>
                    <TimelineDot />
                    <TimelineConnector />
                  </TimelineSeparator>
                  <Grid container direction="column" width="100%">
                    <Grid container>
                      <Grid>
                        <TimelineOppositeContent>
                          <Typography variant="body1" fontWeight="bold">
                            مشخصات درخواست
                          </Typography>
                        </TimelineOppositeContent>
                      </Grid>
                      <Grid>
                        <TimelineContent color="textSecondary">
                          <Grid container gap={SPACING.SMALL}>
                            <Typography
                              variant="body2"
                              display="flex"
                              gap={SPACING.SMALL}
                            >
                              درخواست در تاریخ
                            </Typography>
                            <Typography variant="body2" fontWeight="bold">
                              {formatTime(
                                process?.poultry?.poultryRegisterDate
                              )}
                            </Typography>
                            <Typography
                              variant="body2"
                              display="flex"
                              gap={SPACING.SMALL}
                            >
                              ثبت شده است.
                            </Typography>
                          </Grid>
                        </TimelineContent>
                      </Grid>
                    </Grid>
                    <FileInformation file={process} />
                  </Grid>
                </TimelineItem>

                {/* City Level */}
                <CityInformation file={process} />
                {/* {(getRoleFromUrl() === "CityOperator" ||
                    getRoleFromUrl() === "ProvinceOperator") &&
                    process.city === null && (
                      <CityFileOperations file={process} />
                    )} */}

                {/* {process.auctionsList && process?.poultry?.poultryAuction && (
                  <FileAuctionStatus file={process} />
                )} */}

                {/* {process.killHouseWinner && (
                  <FileAuctionWinner file={process} />
                )} */}

                {/* Province Level */}
                {!process.auctionsList &&
                  !process.killHouseWinner &&
                  process?.city &&
                  process.city.cityState === "accept" && (
                    <ProvinceInformation quantity={quantity} file={process} />
                  )}

                {/* Province Level  */}
                {/* {!process.killHouseWinner &&
                    getRoleFromUrl() === "ProvinceOperator" &&
                    roles.includes("ProvinceOperator") &&
                    process?.city &&
                    process?.province?.provinceState !== "reject" &&
                    process?.province?.provinceState !== "accept" && (
                      <ProvinceCheckRequest file={process} />
                    )} */}
                {/* 
                  {!process.auctionsList &&
                    getRoleFromUrl() === "ProvinceOperator" &&
                    roles.includes("ProvinceOperator") &&
                    process?.city &&
                    process?.province?.provinceState === "accept" &&
                    quantity !== 0 && <ProvinceAllocation file={process} />} */}
                {/* {!process.auctionsList &&
                    getRoleFromUrl() === "ProvinceOperator" &&
                    roles.includes("ProvinceOperator") &&
                    process?.city &&
                    process?.province?.provinceState === "accept" && (
                      <ProvinceAllocation file={process} />
                    )} */}

                {!process.killHouseWinner &&
                  provinceAssignments &&
                  !!provinceKillRequests?.length &&
                  provinceAssignments?.map((item, i) => {
                    return (
                      <Grid key={"ProvinceAllocationInformation" + i}>
                        <Grid>
                          <ProvinceAllocationInformation item={item} i={i} />
                        </Grid>
                        {/* <Grid>
                            {!process.killHouseWinner &&
                              (getRoleFromUrl() === "KillHouse" ||
                                getRoleFromUrl() === "ProvinceOperator") &&
                              (roles.includes("KillHouse") ||
                                roles.includes("ProvinceOperator")) &&
                              Boolean(
                                provinceKillRequests?.filter(
                                  (item) =>
                                    item.provinceKillReqState !== "accepted"
                                ).length
                              ) &&
                              item.provinceKillRequestState === "pending" && (
                                <SlaughterCheckRequest
                                  key={"SlaughterCheckRequest" + i}
                                  item={item}
                                  i={i}
                                  poultryRequestKey={
                                    process?.poultry?.poultryRequestKey
                                  }
                                />
                              )}
                          </Grid> */}
                      </Grid>
                    );
                  })}

                {/* {!process.killHouseWinner &&
                  getRoleFromUrl() === "KillHouse" &&
                  roles.includes("KillHouse") &&
                  Boolean(
                    provinceKillRequests?.filter(
                      (item) => item.provinceKillReqState !== "accepted"
                    ).length
                  ) && <SlaughterCheckRequest file={process} />} */}

                {/* {(getRoleFromUrl() === "KillHouse" ||
                    getRoleFromUrl() === "ProvinceOperator") &&
                    (roles.includes("KillHouse") ||
                      roles.includes("ProvinceOperator")) &&
                    (acceptedSlaughterRequests.some(
                      (item) => item.quantity > 0
                    ) ||
                      (process.killHouseWinner &&
                        process.killHouseWinner.quantity > 0)) &&
                    provinceAssignments?.map((assignment, i) => {
                      return (
                        <SlaughterAssignCar
                          key={i}
                          file={process}
                          assignment={assignment}
                          provinceAllocationLimit={
                            provinceAssignments ? assignment.quantity : 0
                          }
                        />
                      );
                    })} */}

                {/* {showSlaughterHouseVetCheckRequest && (
                    <SlaughterHouseVetCheckRequest file={process} />
                  )} */}

                {/* Submit Bar Weight Level */}
                {/* {(getRoleFromUrl() === "KillHouse" ||
                    getRoleFromUrl() === "Poultry" ||
                    getRoleFromUrl() === "KillHouseVet" ||
                    getRoleFromUrl() === "ProvinceFinancial") &&
                    (roles.includes("KillHouse") ||
                      roles.includes("Poultry") ||
                      roles.includes("KillHouseVet") ||
                      roles.includes("ProvinceFinancial")) &&
                    !!showEnterBarInfo && (
                      <SlaughterEnterBarWeight file={process} />
                    )} */}

                {!process.killHouseWinner &&
                  provinceKillRequests?.map((killRequest) => {
                    const { killHouseRequests } = killRequest;
                    const d = killHouseRequests
                      ?.filter((item) => item.barInfo !== null)
                      .map((item, i) => {
                        const showSlaughterFactorForm =
                          (item.barInfo &&
                            item.provinceFactorToKillHouse &&
                            (!item.killHouseFactorToProvince ||
                              item.killHouseFactorToProvince.factorState ===
                                "rejected")) ||
                          (item.provinceFactorToKillHouseForPoultry &&
                            !item.killHouseFactorToPoultry) ||
                          item.killHouseFactorToPoultry?.factorState ===
                            "rejected";

                        const data = [
                          [
                            item.barcod,
                            `${item.killHouseName} (${item.killHouseUserProvince}/${item.killHouseUserCity})`,
                            item.quantity + " قطعه",
                            item.car?.driverName +
                              ` (${item.car?.driverMobile})`,
                            `${item.car?.typeCar} با پلاک ${item.car?.pelak}`,
                            item.barInfo.killHouseNetWeight + " کیلوگرم",
                            item.fee + " ریال",
                            <a
                              href={item.barInfo.killHouseImageWithoutLoad}
                              alt="دانلود سند خودرو بدون بار"
                              key="provinceKillRequests"
                            >
                              <img
                                src={item.barInfo.killHouseImageWithoutLoad}
                                width="100"
                                height="100"
                                alt="بدون بار"
                                className="images-file"
                              />
                            </a>,
                            <a
                              href={item.barInfo.killHouseImageWithLoad}
                              alt="دانلود سند خودرو با بار"
                              key="provinceKillRequests"
                            >
                              <img
                                src={item.barInfo.killHouseImageWithLoad}
                                width="100"
                                height="100"
                                alt="بدون بار"
                                className="images-file"
                                key="provinceKillRequests"
                              />
                            </a>,
                          ],
                        ];
                        return (
                          <Grid key={"killHouseRequests" + i}>
                            <FinancialCheckRequestInformation
                              item={data}
                              data={item}
                              auction={false}
                            />

                            {item.complaint && (
                              <TimelineItem
                                sx={{
                                  alignSelf: "flex-start",
                                  width: "100%",
                                }}
                              >
                                <TimelineSeparator>
                                  <TimelineDot color="secondary" />
                                  <TimelineConnector />
                                </TimelineSeparator>
                                <Grid xs={12}>
                                  <FileComplaint item={item} />
                                </Grid>
                              </TimelineItem>
                            )}

                            {/* !!item?.complaint && item.complaint?.state === "pending" */}

                            {(getRoleFromUrl() === "ProvinceFinancial" ||
                              getRoleFromUrl() === "ProvinceInspector") &&
                              item.complaint?.state === "pending" && (
                                <FileOperatorCheckComplaint item={item} />
                              )}

                            {/* {getRoleFromUrl() === "ProvinceFinancial" &&
                                roles.includes("ProvinceFinancial") &&
                                !item.provinceFactorToKillHouse &&
                                item.barInfo.killHouseAssignmentState ===
                                  "pending" &&
                                item.complaint?.state !== "pending" && (
                                  <FinancialCheckRequestOperation
                                    item={item}
                                    file={process}
                                  />
                                )} */}

                            {(getRoleFromUrl() === "KillHouse" ||
                              getRoleFromUrl() === "ProvinceFinancial") &&
                              (roles.includes("KillHouse") ||
                                roles.includes("ProvinceFinancial")) &&
                              showSlaughterFactorForm && (
                                <>
                                  {/* {item.provinceFactorToKillHouse &&
                                      (!item.killHouseFactorToProvince ||
                                        item.killHouseFactorToProvince
                                          ?.factorState === "rejected") && (
                                        <SlaughterPayProvinceFactorForm
                                          key={`SlaughterPayProvinceFactorForm${i}`}
                                          factorKey={
                                            item.provinceFactorToKillHouse
                                              ?.provinceFactorKey
                                          }
                                          price={
                                            item.provinceFactorToKillHouse?.cost
                                          }
                                          provinceFactorToKillHouse={
                                            item.provinceFactorToKillHouse
                                          }
                                          isRejected={
                                            item?.killHouseFactorToProvince
                                              ?.factorState === "rejected"
                                          }
                                          killHouseFactorToProvince={
                                            item.killHouseFactorToProvince
                                          }
                                        />
                                      )} */}

                                  {/* {!!item.provinceFactorToKillHouseForPoultry &&
                                      (!item.killHouseFactorToPoultry ||
                                        item.killHouseFactorToPoultry
                                          ?.factorState === "rejected") && (
                                        <SlaughterPayPoultryFactorForm
                                          key={`SlaughterPayPoultryFactorForm${i}`}
                                          factorKey={
                                            item
                                              .provinceFactorToKillHouseForPoultry
                                              ?.provinceFactorKey
                                          }
                                          price={
                                            item
                                              .provinceFactorToKillHouseForPoultry
                                              ?.cost
                                          }
                                          provinceFactorToPoultry={
                                            item.provinceFactorToKillHouseForPoultry
                                          }
                                          isRejected={
                                            item?.killHouseFactorToPoultry
                                              ?.factorState === "rejected"
                                          }
                                          killHouseFactorToPoultry={
                                            item.killHouseFactorToPoultry
                                          }
                                        />
                                      )} */}
                                </>
                              )}
                          </Grid>
                        );
                      });
                    return d;
                  })}

                {process.killHouseWinner &&
                  process.auction
                    ?.filter((item) => item.barInfo !== null)
                    .map((item, i) => {
                      return (
                        <Grid key={"killHouseRequests" + i}>
                          <FinancialCheckRequestInformation
                            data={item}
                            auction={true}
                          />
                          {getRoleFromUrl() === "ProvinceFinancial" &&
                            roles.includes("ProvinceFinancial") &&
                            !item.provinceFactorToKillHouse && (
                              <FinancialCheckRequestOperation item={item} />
                            )}
                        </Grid>
                      );
                    })}

                {process.killHouseWinner &&
                  process.auction &&
                  process.auction
                    ?.filter(
                      (item) =>
                        item.barInfo &&
                        !item.killHouseFactorToProvince &&
                        item.provinceFactorToKillHouse
                    )
                    .map((item, i) => {
                      return (
                        <>
                          <FinancialCheckRequestInformation
                            data={item}
                            auction={true}
                          />
                          {getRoleFromUrl() === "KillHouse" &&
                            roles.includes("KillHouse") && (
                              <SlaughterPayProvinceFactorForm
                                key={`SlaughterPayProvinceFactorForm${i}`}
                                factorKey={
                                  item.provinceFactorToKillHouse
                                    ?.provinceFactorKey
                                }
                                price={item.provinceFactorToKillHouse?.cost}
                                provinceFactorToKillHouse={
                                  item.provinceFactorToKillHouse
                                }
                              />
                            )}
                        </>
                      );
                    })}

                {provinceKillRequests?.map((killRequest) => {
                  const { killHouseRequests } = killRequest;
                  return killHouseRequests
                    ?.filter(
                      (item) =>
                        item.barInfo &&
                        (item.killHouseFactorToProvince ||
                          item.killHouseFactorToPoultry)
                    )
                    .map((item, i) => {
                      return (
                        <>
                          {item?.killHouseFactorToProvince && (
                            <SlaughterPaymentFactor
                              key={`SlaughterPaymentFactor${i}`}
                              data={item.killHouseFactorToProvince}
                              barCode={item.barcod}
                            />
                          )}

                          {/* {getRoleFromUrl() === "ProvinceFinancial" &&
                              roles.includes("ProvinceFinancial") &&
                              item?.killHouseFactorToProvince &&
                              item.killHouseFactorToProvince.factorState ===
                                "pending" && (
                                <>
                                  <ProvinceFinancialSlaughterCheckRequest
                                    factorKey={
                                      item.killHouseFactorToProvince?.factorKey
                                    }
                                    factorType="province"
                                  />
                                </>
                              )} */}

                          {item?.killHouseFactorToPoultry && (
                            <SlaughterPaymentFactorPoultry
                              key={`SlaughterPaymentFactor${i}`}
                              data={item.killHouseFactorToPoultry}
                              barCode={item.barcod}
                            />
                          )}

                          {/* {item?.killHouseFactorToPoultry &&
                              getRoleFromUrl() === "ProvinceFinancial" &&
                              roles.includes("ProvinceFinancial") &&
                              item.killHouseFactorToPoultry.factorState ===
                                "pending" && (
                                <ProvinceFinancialSlaughterCheckRequest
                                  factorKey={
                                    item.killHouseFactorToPoultry?.factorKey
                                  }
                                  factorType="poultry"
                                />
                              )} */}
                        </>
                      );
                    });
                })}

                {process.killHouseWinner &&
                  process.auction
                    ?.filter(
                      (item) => item.barInfo && item.killHouseFactorToProvince
                    )
                    .map((item, i) => {
                      return (
                        <>
                          <SlaughterPaymentFactor
                            key={`SlaughterPaymentFactor${i}`}
                            data={item.killHouseFactorToProvince}
                            barCode={item.barcod}
                          />
                          {/* {getRoleFromUrl() === "ProvinceFinancial" &&
                              roles.includes("ProvinceFinancial") &&
                              item.killHouseFactorToProvince.factorState ===
                                "pending" && (
                                <ProvinceFinancialSlaughterCheckRequest
                                  factorKey={
                                    item.killHouseFactorToProvince?.factorKey
                                  }
                                />
                              )} */}
                        </>
                      );
                    })}

                {process.allocation && (
                  <Grid xs={12}>
                    <Factor process={process} />
                  </Grid>
                )}
                {/* {getRoleFromUrl() === "ProvinceInspector" &&
                    roles.includes("ProvinceInspector") &&
                    process.allocation &&
                    process?.poultry?.poultryRequestFinalState ===
                      "pending" && (
                      <Grid>
                        <Grid xs={12}>
                          <InspectorRequestOperations process={process} />
                        </Grid>
                      </Grid>
                    )} */}

                {process.provinceIncpector.acceptRejectDate && (
                  <InspectorInformation data={process.provinceIncpector} />
                )}
              </Timeline>

              {/* end show file items */}
              {/* show closefile items */}
              {/* {viewType === "closefile" && (
                <>
                  {!process.killHouseWinner &&
                    provinceKillRequests?.map((killRequest, i) => {
                      const { killHouseRequests } = killRequest;
                      const d = killHouseRequests
                        ?.filter((item) => item.barInfo !== null)
                        .map((item, i) => {
                          const data = [
                            [
                              item.barcod,
                              `${item.killHouseName} (${item.killHouseUserProvince}/${item.killHouseUserCity})`,
                              item.quantity + " قطعه",
                              item.car?.driverName +
                                ` (${item.car?.driverMobile})`,
                              `${item.car?.typeCar} با پلاک ${item.car?.pelak}`,
                              item.barInfo.killHouseNetWeight + " کیلوگرم",
                              item.fee + " ریال",
                              <a
                                href={item.barInfo.killHouseImageWithoutLoad}
                                alt="دانلود سند خودرو بدون بار"
                                key="provinceKillRequests"
                              >
                                <img
                                  src={item.barInfo.killHouseImageWithoutLoad}
                                  width="100"
                                  height="100"
                                  alt="بدون بار"
                                  className="images-file"
                                />
                              </a>,
                              <a
                                href={item.barInfo.killHouseImageWithLoad}
                                alt="دانلود سند خودرو با بار"
                                key="provinceKillRequests"
                              >
                                <img
                                  src={item.barInfo.killHouseImageWithLoad}
                                  width="100"
                                  height="100"
                                  alt="بدون بار"
                                  className="images-file"
                                  key="provinceKillRequests"
                                />
                              </a>,
                            ],
                          ];
                          return (
                            <Grid
                              key={"killHouseRequests" + i}
                              mb={SPACING.MEDIUM}
                            >
                              <CloseFileFinancialInfo
                                item={data}
                                data={item}
                                auction={false}
                              />
                            </Grid>
                          );
                        });
                      return d;
                    })}
                </>
              )} */}
            </Card>
          </Grid>
        </Box>
      )}
    </>
  );
};

NewFile.propTypes = {
  id: PropTypes.number,
};
export default NewFile;
