package templates

import (
	"fmt"

	"prestaproxy/internal/viewmodel"
)

templ CategoryPage(data viewmodel.CategoryPageData, cssPath string, jsPath string) {
	@Layout(data.Category.Name, cssPath, jsPath) {
		<main class="min-h-screen bg-[radial-gradient(circle_at_top_left,_rgba(34,197,94,0.18),_transparent_35%),linear-gradient(180deg,#0b1020,#111827)]">
			<div class="mx-auto flex max-w-7xl flex-col gap-10 px-6 py-10 lg:px-8">
				<header class="rounded-[2rem] border border-emerald-500/20 bg-white/5 p-8 backdrop-blur">
					<p class="text-xs uppercase tracking-[0.32em] text-emerald-300">Category</p>
					<h1 class="mt-4 font-serif text-4xl text-white">{ data.Category.Name }</h1>
					<div class="mt-4 flex items-center justify-between gap-6 text-sm text-slate-300">
						<p>{ fmt.Sprintf("Products loaded: %d", len(data.Category.Products)) }</p>
						if data.Customer != nil {
							<p>{ fmt.Sprintf("%s %s", data.Customer.FirstName, data.Customer.LastName) }</p>
						} else {
							<p>Guest session</p>
						}
					</div>
					if data.Category.Description != "" {
						<div class="prose prose-invert mt-6 max-w-none text-slate-300">
							@templ.Raw(data.Category.Description)
						</div>
					}
				</header>

				<section class="grid gap-5 md:grid-cols-2 xl:grid-cols-3">
					for _, product := range data.Category.Products {
						<article class="group rounded-[1.75rem] border border-white/10 bg-slate-900/70 p-6 shadow-[0_24px_80px_rgba(0,0,0,0.35)] transition hover:-translate-y-1 hover:border-emerald-400/40">
							<p class="text-xs uppercase tracking-[0.28em] text-emerald-300">Product</p>
							<h2 class="mt-3 text-2xl font-semibold text-white">{ product.Name }</h2>
							<p class="mt-4 text-sm leading-7 text-slate-300">{ product.Description }</p>
							<div class="mt-8 flex items-center justify-between gap-4">
								<p class="text-2xl font-semibold text-white">{ fmt.Sprintf("%.2f", product.Price) }</p>
								<a class="rounded-full border border-emerald-400/40 px-4 py-2 text-xs font-semibold uppercase tracking-[0.22em] text-emerald-200 transition hover:bg-emerald-300 hover:text-slate-950" href={ product.URL }>
									View Product
								</a>
							</div>
						</article>
					}
				</section>
			</div>
		</main>
	}
}
