"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 [devices, setDevices] = useState<any[]>([]);
    const [loading, setLoading] = useState(true);

    useEffect(() => {
        const fetchData = async () => {
            try {
                const res = await axios.get("https://api-a.fomware.com.cn/asset/v1/list", {
                    headers: {
                        "Authorization": "Bearer lIywwAMdrOdsRxuWvRoekdxrPtmIPkxA"
                    }
                })
                console.log("res", res.data.data.devices)
                setDevices(res.data.data.devices);
            } catch (error) {
                console.error("Error fetching data:", error);
            } finally {
                setLoading(false);
            }
        };

        fetchData();
    }, []);

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

export default SungrowAssets;
