import * as Yup from 'yup';
import { Box, IconButton } from '@mui/material';
import { ArrowBackIosNew } from '@mui/icons-material';
import { yupResolver } from '@hookform/resolvers/yup';
import { Autocomplete, Button, Card, Collapse, Container, Divider, Grid, Stack, Table, TableBody, TableCell, TableRow, TextField, Typography } from '@mui/material';
import { Controller, useForm } from 'react-hook-form';
import { useParams } from 'react-router-dom';
import HeaderBreadcrumbs from '../../components/HeaderBreadcrumbs';
import { FormProvider, RHFCheckbox, RHFSelect, RHFTextField } from '../../components/hook-form';
import Page from '../../components/Page';
import useSettings from '../../hooks/useSettings';
import { useEffect, useMemo, useRef, useState } from 'react';
import MemberSelectDialog from '../../components/dialogs/MemberSelectDialog';
import { styled } from '@mui/system';
import axios from '../../utils/axios';
import { enqueueSnackbar } from 'notistack';
import { LoadingButton } from '@mui/lab';
import { fCurrency } from '../../utils/formatNumber';
import Iconify from '../../components/Iconify';
import { ClaimRequest } from '@/@types/claims';
import FormEdit from './Components/FormEdit';
import FormCreate from './Components/FormCreate';

export default function ClaimsCreateUpdate() {

    const { themeStretch } = useSettings();
    const { id } = useParams();

    const isEdit = id ? true : false;

    const [currentClaim, setCurrentClaim] = useState<ClaimRequest>();

    useEffect(() => {
        if (isEdit) {
        axios.get('/claim-requests/' + id).then((res) => {
            console.log('Yeet', res.data);
            setCurrentClaim(res.data.data);
        });

        console.log(currentClaim)
        }
    }, [id]);


  return (
    <Page title={isEdit ? `Edit Claim Request` : "Create New Claim"}>
      <Container maxWidth={themeStretch ? false : 'xl'}>
        {
            id == undefined
            ?
            (
                <FormCreate />
            )
            :
            (
                <FormEdit isEdit={isEdit} currentClaim={currentClaim} />
            )
        }

      </Container>
    </Page>
  );
}
