import DialogLoading from "@/core/components/DialogLoading";
import { GET_REQUEST_INQUIRY_PRIVACY } from "@/core/utils/routes";
import useRequest from "@/lib/hooks/useRequest";
import { DialogContent, DialogTitle, Typography } from "@mui/material";
import { useEffect, useState } from "react";
import ConfirmRoadSafetyFormContext from "./ConfirmRoadSafetyFormContext";

const ConfirmRoadSafetyDialog = ({ handleClose, rowId, mutate }) => {
    const [loading, setLoading] = useState(true);
    const [data, setData] = useState(null);
    const request = useRequest();

    useEffect(() => {
        const fetchData = async () => {
            try {
                setLoading(true);
                const response = await request(`${GET_REQUEST_INQUIRY_PRIVACY}/${rowId}`);
                setData(response.data.data);
            } catch (error) {
            } finally {
                setLoading(false);
            }
        };

        fetchData();
    }, [rowId]);

    return (
        <>
            <DialogTitle>تاییدیه ضمانت نامه ها</DialogTitle>
            {loading ? (
                <DialogLoading loadingOpen={loading} />
            ) : data ? (
                <ConfirmRoadSafetyFormContext rowId={rowId} mutate={mutate} handleClose={handleClose} />
            ) : (
                <DialogContent>
                    <Typography textAlign={"center"}>اطلاعات درخواست در سامانه یافت نشد</Typography>
                </DialogContent>
            )}
        </>
    );
};
export default ConfirmRoadSafetyDialog;
