'use client'
import { useEffect, useState } from "react";
import dynamic from "next/dynamic";
import DataService from "@/Config/Axios";
import ImageWithPlaceholder from "@/Components/ImageWithPlaceholder";
import { Card, CardBody, Col, Row } from "reactstrap";
import { toast } from "react-toastify";

const InfoSection = dynamic(() => import('./InfoSection'), { ssr: false })

const UserData = () => {
  const [user, setUser] = useState<any>({})

  const callApi = async () => {
    const userData = JSON.parse(localStorage.getItem('user') ?? '');
    try {
      const response = await DataService.post(`/admins/${userData._id}`);
      console.log(response);
      if (response.data.status) {
        setUser(response.data.data)
      }

    } catch (error: any) {
      toast.error(error?.response?.data?.message ?? "Something went wrong!");
    }
  }

  useEffect(() => {
    callApi()
  }, [])

  return (
    <Col sm="12">
      <Card className="hovercard text-center">
        <div className="cardheader" style={{
          background: "white", maxHeight: '175px', boxShadow: 'inset gray 0px 0px 60px -15px'
        }}>
          {
            user?.coverPhoto &&
            <ImageWithPlaceholder
              src={user?.coverPhoto}
              className="w-100 bg-white object-fit-cover rounded-top"
              style={{ height: "100%", objectFit: 'contain' }}
            />
          }
        </div>
        <div className="user-image">
          <div className="avatar">
            <ImageWithPlaceholder
              className="bg-white shadow object-fit-cover"
              src={user?.profilePhoto}
            />
          </div>
          {/* <div className="icon-wrapper">
            <i className="icofont icofont-pencil-alt-5"></i>
          </div> */}
        </div>
        <div className="info">
          <InfoSection />
        </div>
      </Card>
      <Card>
        <CardBody>
          <Row>
            <Col md="3" sm="3">
              Monthly invoice reminder count: <b>8</b>
            </Col>
          </Row>
        </CardBody>
      </Card>
    </Col >
  );
};

export default UserData;
