"use client"
import MasterLayout from "@/masterLayout/MasterLayout";
import { useEffect, useState } from "react";
import client from "@auth";
import PageLoader from "@/components/common-component/PageLoader";
import Breadcrumb from "@/components/Breadcrumb";
import SidesCategoryComponent from "@/components/admin/SidesCategoryComponent";

// export const metadata = {
//   title: "WowDash NEXT JS - Admin Dashboard Multipurpose Bootstrap 5 Template",
//   description:
//     "Wowdash NEXT JS is a developer-friendly, ready-to-use admin template designed for building attractive, scalable, and high-performing web applications.",
// };

const SidesCategoryPage = () => {

    const [sidesCategoryData, setSidesCategoryData] = useState(null);
    const [error, setError] = useState(null);
    const [loading, setLoading] = useState(true);
    const [restaruntBranch, setRestaruntBranch] = useState("")

    useEffect(() => {
        const restarunt = localStorage.getItem("restaurantbranch")
        setRestaruntBranch(restarunt)
    }, [])


    useEffect(() => {
        if (restaruntBranch && restaruntBranch !== "")
            getSidesCategory();
    }, [restaruntBranch]);



    const getSidesCategory = async () => {
        try {
            setLoading(true);
            // const res = await client?.get(`/Dine360 Floor?fields=[\"*\"]&limit_page_length=100`);
            const res = await client?.get(`/Dine360%20Food%20Sides%20Category?fields=[%22*%22]&limit_page_length=100&filters=[["restaurantbranch","=","${restaruntBranch}"]]`);
            setSidesCategoryData(res?.data?.data);
        } catch (error) {
            console.error("Error fetching floor data:", error);
            setError(error?.message || "Failed to fetch floor data");
        } finally {
            setLoading(false);
        }
    };

    console.log("")
    return (
        <>
            <MasterLayout>

                <Breadcrumb title='Floor' />

                {loading ? (
                    <PageLoader />
                ) : (
                    <SidesCategoryComponent sidesCategoryData={sidesCategoryData} getSidesCategory={getSidesCategory} />
                )
                }
            </MasterLayout>
        </>
    );
};

export default SidesCategoryPage;
