import React from "react";
import { Card, CardHeader, CardTitle, CardBody, Button } from "reactstrap";
import { Formik, Form } from "formik";
import { LoadingButton } from "../../Components/Ui/LoadingButton";
import ProgressBar from "../../Components/Ui/ProgressBar";
import { useLocation, useNavigate } from "react-router-dom";
import { usePageState } from "../../lib/statemangment/LayoutPagestate";
import { useTranslation } from "react-i18next";

type TViewPage ={
  children: React.ReactNode,
  getInitialValues:any,
   getValidationSchema:any,
   handleSubmit:any,
  //  BarStatus:any,
   IsloadingButton:boolean
}

const ViewPage: React.FC<TViewPage>=  ({children,getInitialValues, getValidationSchema,handleSubmit,IsloadingButton})=> {
    
    const {objectToEdit,setObjectToEdit} = usePageState()
    const {t} = useTranslation();
    const navigate = useNavigate();
  // console.log(BarStatus);
  
  const navigateToParent = () => {
    navigate(-1)
    if(objectToEdit){      
      setObjectToEdit([])
    }
  };

  return (
    <Card className="ViewTapPage">
      <CardHeader  className="CardHeader" >
        <CardTitle className="View_information">
          {t("View_information")}
        </CardTitle>
       <Button onClick={() => { navigateToParent()}}>  {t("back")}  </Button>
      </CardHeader>
      <CardBody>
        {
           <Formik
           enableReinitialize
           onSubmit={handleSubmit}
           initialValues={getInitialValues(objectToEdit ?? {})}
           validationSchema={getValidationSchema()}
        >
          {(formik) => (
            <Form>
              {/* <HeadTabs tabs={tabs} /> */}
                {children}
                { 
                  <>
               
                    <div className="d-flex mt-4 justify-content-center align-items-center">
                      <LoadingButton
                        type="submit"
                        color="primary"
                        isLoading={IsloadingButton}
                        
                      >
                        {t("save")}  
                      </LoadingButton>
                      {/* <Button disabled={isLoading}  type="submit" color="primary">  {t("save")}  </Button> */}
                    </div>
                  </>
                }
            </Form>
          )}
        </Formik>
        }
       
      </CardBody>
    </Card>
  );
};


export default ViewPage;
