"use client";
// app/(defaults)/sungrow/assets/page.tsx

import ComponentsTablesSimple from "@/components/tables/components-tables-simple";
import axios from "axios";
import React, { useEffect, useState } from "react";

const SungrowAssets =  () => {
    const [sites, setSites] = useState<any[]>([]);
    const [loading, setLoading] = useState(true);

    useEffect(() => {
        const fetchData = async () => {
            try {
                const res = await axios.get("https://api-a.fomware.com.cn/site/v1/list", {
                    headers: {
                        "Authorization": "Bearer " + process.env.NEXT_PUBLIC_CHINT_TOKEN
                    }
                })
                console.log("res", res.data.data.siteInfos)
                setSites(res.data.data.siteInfos)
            } catch (error) {
                console.error("Error fetching data:", error);
            } finally {
                setLoading(false);
            }
        };

        fetchData()
    }, [])

    return (
        <div>
            {loading ? <p>Loading...</p> : <ComponentsTablesSimple tableData={sites} />}
        </div>
    )
}

export default SungrowAssets;
