import React, { useEffect, useMemo, useState } from 'react'; import { createRoot } from 'react-dom/client'; import { BarChart3, Home, LayoutDashboard, LogOut, Menu, Package, Plus, Search, Settings, ShoppingBag, Tag, Ticket, Trash2 } from 'lucide-react'; import { db } from './services/store'; import { Banner, Campaign, Category, Product } from './types'; import { money, slugify, today, uid } from './utils/helpers'; import './style.css'; type Route = { page: string; slug?: string; id?: string }; const routeFromHash = (): Route => { const raw = location.hash.replace('#', '') || '/'; const parts = raw.split('/').filter(Boolean); return { page: parts[0] || 'home', slug: parts[1], id: parts[2] }; }; const go = (path: string) => { location.hash = path; }; function useStore() { const [, setTick] = useState(0); useEffect(() => { const fn = () => setTick(x => x + 1); window.addEventListener('tooca:update', fn); window.addEventListener('hashchange', fn); db.init(); return () => { window.removeEventListener('tooca:update', fn); window.removeEventListener('hashchange', fn); }; }, []); return { products: db.products(), categories: db.categories(), banners: db.banners(), campaigns: db.campaigns(), clicks: db.clicks(), settings: db.settings(), route: routeFromHash(), auth: db.isAuth() }; } function Header() { const { settings } = useStore(); return
go('/')}>🛒 {settings.storeName}
; } function Footer() { const { settings } = useStore(); return ; } function Layout({ children }: { children: React.ReactNode }) { return <>
{children}