---
import Base from '../layouts/Base.astro';
import { prisma } from '../lib/db.mjs';

const products = await prisma.product.findMany({
    where: { isPublished: true },
    orderBy: { sortOrder: 'asc' },
});

const schemaOrg = {
    "@context": "https://schema.org",
    "@type": "Store",
    "name": "REBOURS Studio",
    "description": "Mobilier d'art contemporain. Space Age × Memphis. Pièces uniques fabriquées à Paris.",
    "url": "https://rebours.studio/",
    "image": "https://rebours.studio/assets/lamp-violet.jpg",
    "address": { "@type": "PostalAddress", "addressLocality": "Paris", "addressCountry": "FR" },
    "hasOfferCatalog": {
        "@type": "OfferCatalog",
        "name": "Collection 001",
        "itemListElement": products.filter(p => p.price).map(p => ({
            "@type": "Offer",
            "itemOffered": {
                "@type": "Product",
                "name": p.productDisplayName,
                "description": p.seoDescription,
                "image": p.ogImage,
            },
            "price": String(p.price! / 100),
            "priceCurrency": p.currency,
            "availability": p.availability,
        })),
    }
};
---

<Base
    title="REBOURS — Mobilier d'art contemporain | Collection 001"
    description="REBOUR Studio crée du mobilier d'art contemporain inspiré du Space Age et du mouvement Memphis. Pièces uniques fabriquées à Paris. Collection 001 en cours."
    canonical="https://rebours.studio/"
>
    <Fragment slot="head">
        <script type="application/ld+json" set:html={JSON.stringify(schemaOrg)} />
    </Fragment>

    <!-- Grid background -->
    <div id="interactive-grid" class="interactive-grid"></div>

    <!-- PRODUCT PANEL (overlay) -->
    <div id="product-panel" class="product-panel" aria-hidden="true">
        <div class="panel-close" id="panel-close">
            <span>← RETOUR</span>
        </div>
        <div class="panel-inner">
            <div class="panel-img-col">
                <img id="panel-img" src="" alt="Image produit REBOURS Studio">
            </div>
            <div class="panel-info-col">
                <p class="panel-index" id="panel-index"></p>
                <h2 id="panel-name"></h2>
                <hr>
                <div class="panel-meta">
                    <div class="panel-meta-row">
                        <span class="meta-key">TYPE</span>
                        <span id="panel-type"></span>
                    </div>
                    <div class="panel-meta-row">
                        <span class="meta-key">MATÉRIAUX</span>
                        <span id="panel-mat"></span>
                    </div>
                    <div class="panel-meta-row">
                        <span class="meta-key">ANNÉE</span>
                        <span id="panel-year"></span>
                    </div>
                    <div class="panel-meta-row">
                        <span class="meta-key">STATUS</span>
                        <span id="panel-status" class="red"></span>
                    </div>
                </div>
                <hr>
                <p id="panel-desc" class="panel-desc"></p>
                <hr>

                <details class="accordion">
                    <summary>SPÉCIFICATIONS TECHNIQUES <span>↓</span></summary>
                    <div class="accordion-body" id="panel-specs"></div>
                </details>
                <details class="accordion">
                    <summary>NOTES DE CONCEPTION <span>↓</span></summary>
                    <div class="accordion-body" id="panel-notes"></div>
                </details>

                <hr>

                <div id="checkout-section" style="display:none;">
                    <div class="checkout-price-line">
                        <span class="checkout-price"></span>
                        <span class="checkout-edition">ÉDITION UNIQUE — 1/1</span>
                    </div>
                    <button id="checkout-toggle-btn" class="checkout-btn">
                        [ COMMANDER CETTE PIÈCE ]
                    </button>
                    <div id="checkout-form-wrap" class="checkout-form-wrap" style="display:none;">
                        <form id="checkout-form" class="checkout-form">
                            <div class="checkout-form-field">
                                <label for="checkout-email">EMAIL *</label>
                                <input type="email" id="checkout-email" name="email" placeholder="votre@email.com" required autocomplete="off">
                            </div>
                            <div class="checkout-form-note">
                                Pièce fabriquée à Paris. Délai : 6 à 8 semaines.<br>
                                Paiement sécurisé via Stripe.
                            </div>
                            <button type="submit" class="checkout-submit" id="checkout-submit-btn">
                                PROCÉDER AU PAIEMENT →
                            </button>
                        </form>
                    </div>
                </div>

                <div class="panel-footer">
                    <span class="blink">■</span> COLLECTION_001 — W.I.P
                </div>
            </div>
        </div>
    </div>

    <div class="page-wrapper">

        <header class="header">
            <a href="/" class="logo-text" aria-label="REBOURS — Accueil">REBOURS</a>
            <nav class="header-nav" aria-label="Navigation principale">
                <a href="#collection">COLLECTION_001</a>
                <a href="#" class="contact-trigger">CONTACT</a>
                <span class="wip-tag"><span class="blink">■</span> W.I.P</span>
            </nav>
        </header>

        <main>

            <!-- HERO -->
            <section class="hero" aria-label="Introduction">
                <div class="hero-left">
                    <p class="label">// ARCHIVE_001 — 2026</p>
                    <h1>REBOURS<br>STUDIO</h1>
                    <p class="hero-sub">Mobilier d'art contemporain.<br>Space Age × Memphis.</p>
                    <p class="hero-sub mono-sm">STATUS: [PROTOTYPE EN COURS]<br>COLLECTION_001 — BIENTÔT DISPONIBLE</p>
                </div>
                <div class="hero-right">
                    <img
                        src="/assets/table-terrazzo.jpg"
                        alt="REBOURS — Table Terrazzo, plateau terrazzo et acier tubulaire, Paris 2026"
                        class="hero-img"
                        width="1024" height="1024"
                        fetchpriority="high">
                </div>
            </section>

            <hr>

            <!-- COLLECTION GRID -->
            <section class="collection" id="collection" aria-label="Collection 001">
                <div class="collection-header">
                    <p class="label">// COLLECTION_001</p>
                    <span class="label">{products.length} OBJETS — CLIQUER POUR OUVRIR</span>
                </div>

                <div class="product-grid">
                    {products.map((p, i) => (
                        <article class="product-card"
                            data-index={p.index}
                            data-name={p.name}
                            data-type={p.type}
                            data-mat={p.materials}
                            data-year={p.year}
                            data-status={p.status}
                            data-desc={p.description}
                            data-specs={p.specs}
                            data-notes={p.notes}
                            data-img={p.imagePath}
                            data-price={p.price ? String(p.price) : ''}
                            data-stripe-key={p.stripeKey ?? ''}
                            data-img-alt={p.imageAlt || `${p.productDisplayName} — mobilier d'art contemporain, REBOURS Studio Paris`}
                            aria-label={`Ouvrir le détail de ${p.productDisplayName}`}>
                            <div class="card-img-wrap">
                                <img src={p.imagePath}
                                     alt={p.imageAlt || `${p.productDisplayName} — mobilier d'art contemporain, REBOURS Studio Paris`}
                                     width="600" height="600"
                                     loading={i === 0 ? "eager" : "lazy"}>
                            </div>
                            <div class="card-meta">
                                <span class="card-index">{String(i + 1).padStart(3, '0')}</span>
                                <span class="card-name">{p.name}</span>
                                <span class="card-arrow">↗</span>
                            </div>
                        </article>
                    ))}
                </div>
            </section>

            <!-- NEWSLETTER -->
            <section class="newsletter" id="contact" aria-label="Accès anticipé">
                <div class="nl-left">
                    <p class="label">// ACCÈS_ANTICIPÉ</p>
                    <h2>REJOINDRE<br>L'EXPÉRIENCE</h2>
                </div>
                <div class="nl-right">
                    <form class="nl-form" onsubmit="event.preventDefault();" aria-label="Inscription newsletter">
                        <label for="nl-email">EMAIL :</label>
                        <div class="nl-row">
                            <input type="email" id="nl-email" name="email" placeholder="votre@email.com" autocomplete="email" required>
                            <button type="submit">ENVOYER →</button>
                        </div>
                        <p class="mono-sm"><span class="blink">■</span> CONNECTION_STATUS: PENDING</p>
                    </form>
                </div>
            </section>

        </main>

        <footer class="footer">
            <span>© 2026 REBOURS STUDIO — PARIS</span>
            <nav aria-label="Liens secondaires">
                <a href="https://instagram.com/rebour.studio" rel="noopener" target="_blank">INSTAGRAM</a>
                &nbsp;/&nbsp;
                <a href="#" class="contact-trigger">CONTACT</a>
            </nav>
        </footer>

    </div>

    <!-- CONTACT MODAL -->
    <div id="contact-modal" class="contact-modal" aria-hidden="true">
        <div class="contact-modal-backdrop"></div>
        <div class="contact-modal-content">
            <div class="contact-modal-header">
                <p class="label">// CONTACT</p>
                <button class="contact-modal-close" aria-label="Fermer">✕</button>
            </div>
            <hr>
            <h2 class="contact-modal-title">ENVOYER<br>UN MESSAGE</h2>
            <form id="contact-form" class="contact-form">
                <div class="contact-field">
                    <label for="contact-name">NOM *</label>
                    <input type="text" id="contact-name" name="name" placeholder="Votre nom" required autocomplete="name">
                </div>
                <div class="contact-field">
                    <label for="contact-email">EMAIL *</label>
                    <input type="email" id="contact-email" name="email" placeholder="votre@email.com" required autocomplete="email">
                </div>
                <div class="contact-field">
                    <label for="contact-subject">OBJET</label>
                    <input type="text" id="contact-subject" name="subject" placeholder="Objet du message" autocomplete="off">
                </div>
                <div class="contact-field">
                    <label for="contact-message">MESSAGE *</label>
                    <textarea id="contact-message" name="message" rows="5" placeholder="Votre message..." required></textarea>
                </div>
                <button type="submit" class="contact-submit">
                    ENVOYER LE MESSAGE →
                </button>
                <p class="mono-sm contact-note"><span class="blink">■</span> REDIRECTION VERS VOTRE CLIENT MAIL</p>
            </form>
        </div>
    </div>

    <div class="cursor-dot"></div>
    <div class="cursor-outline"></div>
</Base>
