import { create } from 'zustand'; import { API_BASE } from '@homaroma/types'; export interface MenuLink { label: Record | string; url?: string; links?: MenuLink[]; imageUrl?: string | null; // รูปที่แสดงเมื่อ Hover ลิงก์ icon?: string; // ชื่อ icon จาก registry (lucide) } export interface MenuColumn { title: Record | string; links: MenuLink[]; iconUrl?: string | null; // รูปประจำคอลัมน์ (1:1) icon?: string; // ชื่อ icon จาก registry (lucide) } export interface MenuFeaturedCard { enabled?: boolean; sectionTitle?: Record | string; badge?: Record | string; title?: Record | string; subtitle?: Record | string; price?: string; imageUrl?: string | null; focalPoint?: { x: string; y: string }; url?: string; ctaLabel?: Record | string; } export interface MegaMenuPayload { id?: string; nodeId?: string; label: Record | string; url?: string; columns?: MenuColumn[]; rootImageUrl?: string | null; // รูปหลักฝั่งซ้ายสุด (1:1) featured?: MenuFeaturedCard; } interface MenuState { megaMenu: MegaMenuPayload[]; isLoading: boolean; fetchMegaMenu: () => Promise; } export const useMenuStore = create((set) => ({ megaMenu: [], isLoading: false, fetchMegaMenu: async () => { set({ isLoading: true }); try { const response = await fetch(`${API_BASE}/menus/main`); const data = await response.json(); set({ megaMenu: data.payload || [], isLoading: false }); } catch (error) { console.error('Failed to fetch mega menu', error); set({ isLoading: false }); } } }));