import HeadingSmall from '@/components/heading-small';
import { Card } from '@/components/ui/card';
import AppLayout from '@/layouts/app-layout';
import PromotionLayout from '@/layouts/settings/promotion-layout';
import { Head, usePage } from '@inertiajs/react';
import { Settings } from 'lucide-react';
import { ReactNode } from 'react';
import HeroSection from './components/HeroSection';

declare const route: (...args: any[]) => string;

interface ThemeMenuItem {
    title: string;
    href: string;
    route_name?: string | null;
    status?: boolean;
}

interface OfferOption {
    value: string;
    label: string;
}

interface BannerRecord {
    id: number;
    offer_id: number | null;
    position: string;
    slider: boolean;
    status: number;
    image_url: string | null;
}

interface PromotionBannerPageProps {
    name?: string | null;
    slug?: string | null;
    theme_id?: number | null;
    menuList?: ThemeMenuItem[];
    offers?: OfferOption[];
    coupons?: OfferOption[];
    flashSales?: OfferOption[];
    banners?: Record<string, BannerRecord>;
    sliderBanners?: BannerRecord[];
}

export default function HomePage() {
    const pageProps = usePage().props as PromotionBannerPageProps;
    const { name, slug, theme_id = null, menuList = [], offers = [], coupons = [], flashSales = [], banners = {}, sliderBanners = [] } = pageProps;

    const mappedMenuList = menuList.map((item) => ({
        title: item.title,
        href: item.href,
        icon: Settings,
        status: item.status ?? true,
    }));

    return (
        <>
            <Head title="Promotion Home - Single Product Theme" />
            <PromotionLayout tab={'platform'} menuList={mappedMenuList}>
                <Card className="space-y-4 px-5 py-3">
                    <div className="mb-3 flex items-center justify-between border-b">
                        <HeadingSmall title="Single Product Theme - Home" description="Top Section Promotion banner" />
                    </div>
                    <HeroSection offers={offers} coupons={coupons} flashSales={flashSales} banners={banners} sliderBanners={sliderBanners} themeId={theme_id} />
                </Card>
            </PromotionLayout>
        </>
    );
}

HomePage.layout = (page: ReactNode) => (
    <AppLayout
        breadcrumbs={[
            { title: 'Home', href: '/' },
            { title: 'Promotion Banner', href: route('promotion.banner.home') },
            { title: 'Home', href: '#' },
        ]}
        title="Single Product Theme - Home"
    >
        {page}
    </AppLayout>
);
