import React, { useEffect, useState, useCallback } from 'react'; import NextImage from 'next/image'; import Link from 'next/link'; import { createSlug } from '@/core/utils/slug'; import { Swiper, SwiperSlide } from 'swiper/react'; import 'swiper/css'; import { fetchCategoryManagementSolr } from '../api/categoryManagementApi'; const CategoryDynamicMobile = () => { const [selectedCategory, setSelectedCategory] = useState({}); const [categoryManagement, setCategoryManagement] = useState([]); const [isLoading, setIsLoading] = useState(false); const loadBrand = useCallback(async () => { setIsLoading(true); const items = await fetchCategoryManagementSolr(); setIsLoading(false); setCategoryManagement(items); }, []); useEffect(() => { loadBrand(); }, [loadBrand]); useEffect(() => { const loadPromo = async () => { try { if (categoryManagement?.length > 0) { const initialSelections = categoryManagement.reduce( (acc, category) => { if (category.categories.length > 0) { acc[category.id] = category.categories[0].id_level_2; } return acc; }, {} ); setSelectedCategory(initialSelections); } } catch (loadError) { // console.error("Error loading promo items:", loadError); } }; loadPromo(); }, [categoryManagement]); const handleCategoryLevel2Click = (categoryIdI, idLevel2) => { setSelectedCategory((prev) => ({ ...prev, [categoryIdI]: idLevel2, })); }; return (