import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import axios from "axios";
import Navbar from "./Navbar";
import Footer from "./Footer";
import "../propertymysqlview.css";
import propertydummy from "../img/propertydummy.jpg";

const PropertyMysqlView = () => {
  const { house_id } = useParams(); // Get house_id from the URL

  console.log("house_id", house_id);
  const [propertyDetails, setPropertyDetails] = useState(null); // State for property details
  const [loading, setLoading] = useState(true); // Loader state

  // Fetch property details from API
  useEffect(() => {
    const fetchPropertyDetails = async () => {
      try {
        const res = await axios.get(
          `${import.meta.env.VITE_REACT_APP_SECRET
          }/mysql/properties/${house_id}`
        );
        setPropertyDetails(res.data); // Set the property details
      } catch (err) {
        console.log("Error fetching property details:", err);
      } finally {
        setLoading(false); // Stop loading
      }
    };

    fetchPropertyDetails();
  }, [house_id]);

  return (
    <>
      <Navbar />
      <br /> <br /> <br /> <br />
 
      <div className="container col-12">
        {loading ? (
          <div className="loader">Loading...</div> // Loader
        ) : propertyDetails ? (
          <div className="py-3 py-md-5 bg-light">
            {/* <div className="container"> */}
            <div className="card-header bg-white">
              <div className="row">
                <div className="col-md-5 mt-3">
                  <div className="bg-white border">
                    <img
                      src={propertydummy}
                      className="w-70"
                      alt="Img"
                      style={{
                        marginTop: "0px",
                        maxWidth: "450px",
                        maxHeight: "450px",
                      }}
                    />
                  </div>
                </div>
                <div className="col-md-7 mt-3">
                  <div className="product-view">
                    <h4
                      className="product-name"
                      style={{ color: "#fda417", fontSize: "25px" }}
                    >
                      {propertyDetails.address}
                      <label className="label-stock bg-success">
                        Verified Property
                      </label>
                    </h4>
                    <hr />
                    <p className="product-path">
                      <span style={{ color: "#fda417", fontSize: "15px" }}>
                        city:{" "}
                      </span>{" "}
                      {propertyDetails.city} /
                      <span style={{ color: "#fda417", fontSize: "15px" }}>
                        County:{" "}
                      </span>{" "}
                      {propertyDetails.county} /
                      <span style={{ color: "#fda417", fontSize: "15px" }}>
                        State:{" "}
                      </span>{" "}
                      {propertyDetails.state} /
                      <span style={{ color: "#fda417", fontSize: "15px" }}>
                        Zipcode:
                      </span>{" "}
                      {propertyDetails.zip}
                    </p>
                    <div>
                      <span
                        className="selling-price"
                        style={{ color: "#fda417", fontSize: "15px" }}
                      >
                        Total Living Square Foot:{" "}
                      </span>
                      {propertyDetails.total_living_sqft}
                      <p></p>
                      <span
                        className=""
                        style={{ color: "#fda417", fontSize: "15px" }}
                      >
                        Cost per Square Foot:{" "}
                      </span>
                      ${propertyDetails.cost_per_sqft}/sqft
                      <p></p>
                      <span
                        className=""
                        style={{ color: "#fda417", fontSize: "15px" }}
                      >
                        Year Built:{" "}
                      </span>
                      {propertyDetails.year_built}
                    </div>

                    <div className="mt-3 card bg-white">
  <h5 className="mb-0" style={{ color: "#fda417", fontSize: "15px" }}>
    Legal Summary report
  </h5>
  <span>
    {propertyDetails.legal_summary_report
      ? propertyDetails.legal_summary_report
      : "No data available"}
  </span>
</div>

                  </div>
                </div>
              </div>
              <div className="row">
                <div className="col-md-12 mt-3">
                  <div className="card">
                    <div className="card-header bg-white">
                      <h4
                        className="product-name"
                        style={{ color: "#fda417", fontSize: "25px" }}
                      >
                        Description
                      </h4>
                    </div>
                    <div className="card-body">
                      <p>
                        Lorem Ipsum is simply dummy text of the printing and
                        typesetting industry. Lorem Ipsum has been the
                        industry's standard dummy text ever since the 1500s,
                        when an unknown printer took a galley of type and
                        scrambled it to make a type specimen book. It has
                        survived not only five centuries, but also the leap into
                        electronic typesetting, remaining essentially unchanged.
                        It was popularised in the 1960s with the release of
                        Letraset sheets containing Lorem Ipsum passages, and
                        more recently with desktop publishing software like
                        Aldus PageMaker including versions of Lorem Ipsum.
                      </p>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        ) : (
          <p>No property details found.</p>
        )}
      </div>
      <Footer />
    </>
  );
};

export default PropertyMysqlView;
