import React, { useEffect, useState, useCallback } from "react"; import { CircularProgress, Box, useTheme, useMediaQuery, Skeleton } from "@mui/material"; import RestaurantProfile from "./RestaurantProfile"; import Setting from "../Settings/AccountProfile"; import authService from "../../../services/authService"; import { useRestaurant } from "../../../contexts/RestaurantContext"; import KitchPlusAppBar from "../AppBar"; import Sidebar from "../SideHome" const drawerWidth = 230; const RestaurantWrapper = () => { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("sm")); const { restaurantId } = useRestaurant(); const [loading, setLoading] = useState(true); const [hasProfile, setHasProfile] = useState(false); const [sidebarOpen, setSidebarOpen] = useState(!isMobile); const fetchProfile = useCallback(async () => { if (!restaurantId) { setLoading(false); return; } setLoading(true); try { const profile = await authService.getRestaurantProfile(restaurantId); setHasProfile(profile && Object.keys(profile).length > 0); } catch (error) { console.error("Error checking restaurant profile:", error); setHasProfile(false); } finally { setLoading(false); } }, [restaurantId]); useEffect(() => { fetchProfile(); }, [fetchProfile]); useEffect(() => { const handleResize = () => setSidebarOpen(window.innerWidth >= theme.breakpoints.values.md); handleResize(); window.addEventListener("resize", handleResize); return () => window.removeEventListener("resize", handleResize); }, [theme.breakpoints.values.md]); const handleDrawerToggle = () => setSidebarOpen(!sidebarOpen); return ( {/* البار الجانبي */} {/* المحتوى الرئيسي */} {/* البار العلوي */} {/* المحتوى حسب وجود البروفايل */} {loading ? ( // Skeleton placeholder ) : hasProfile ? ( ) : ( )} ); }; export default RestaurantWrapper;