<?php

namespace App\Services\PromptLandingPageEditor;

class SectionLibrary
{
    /**
     * @return array{sections: list<array{id: string, label: string, html: string, css: string}>, elements: list<array{id: string, label: string, html: string, css: string}>}
     */
    public function blocks(): array
    {
        return [
            'sections' => $this->sections(),
            'elements' => $this->elements(),
        ];
    }

    /**
     * @return list<array{id: string, label: string, html: string, css: string}>
     */
    private function sections(): array
    {
        return [
            $this->block('hero', 'Hero', <<<'HTML'
<section class="lp-hero" data-lp-section="hero">
    <div class="lp-wrap">
        <p class="lp-kicker">New</p>
        <h1>Grow your business faster</h1>
        <p class="lp-lead">A short supporting line that explains the offer and invites action.</p>
        <a class="lp-btn" href="#contact">Get started</a>
    </div>
</section>
HTML, $this->sectionCss('hero')),
            $this->block('features', 'Features', <<<'HTML'
<section class="lp-section" data-lp-section="features">
    <div class="lp-wrap">
        <h2>Features</h2>
        <div class="lp-grid lp-grid-3">
            <article class="lp-card"><h3>Feature one</h3><p>Describe a capability in one or two sentences.</p></article>
            <article class="lp-card"><h3>Feature two</h3><p>Describe a capability in one or two sentences.</p></article>
            <article class="lp-card"><h3>Feature three</h3><p>Describe a capability in one or two sentences.</p></article>
        </div>
    </div>
</section>
HTML, $this->sectionCss('features')),
            $this->block('benefits', 'Benefits', <<<'HTML'
<section class="lp-section" data-lp-section="benefits">
    <div class="lp-wrap">
        <h2>Benefits</h2>
        <ul class="lp-list">
            <li>Save time on repetitive work</li>
            <li>Keep your brand consistent</li>
            <li>Convert more visitors into leads</li>
        </ul>
    </div>
</section>
HTML, $this->sectionCss('benefits')),
            $this->block('testimonials', 'Testimonials', <<<'HTML'
<section class="lp-section lp-section-alt" data-lp-section="testimonials">
    <div class="lp-wrap">
        <h2>What customers say</h2>
        <div class="lp-grid lp-grid-2">
            <blockquote class="lp-card"><p>“This helped us launch in days, not weeks.”</p><footer>Alex, Operations</footer></blockquote>
            <blockquote class="lp-card"><p>“The page matched our brand and converted immediately.”</p><footer>Jordan, Marketing</footer></blockquote>
        </div>
    </div>
</section>
HTML, $this->sectionCss('testimonials')),
            $this->block('pricing', 'Pricing', <<<'HTML'
<section class="lp-section" data-lp-section="pricing">
    <div class="lp-wrap">
        <h2>Pricing</h2>
        <div class="lp-grid lp-grid-3">
            <article class="lp-card"><h3>Starter</h3><p class="lp-price">$29</p><p>For small teams getting started.</p><a class="lp-btn lp-btn-ghost" href="#contact">Choose starter</a></article>
            <article class="lp-card lp-card-accent"><h3>Growth</h3><p class="lp-price">$79</p><p>For teams ready to scale.</p><a class="lp-btn" href="#contact">Choose growth</a></article>
            <article class="lp-card"><h3>Plus</h3><p class="lp-price">$149</p><p>Advanced support and limits.</p><a class="lp-btn lp-btn-ghost" href="#contact">Choose plus</a></article>
        </div>
    </div>
</section>
HTML, $this->sectionCss('pricing')),
            $this->block('faq', 'FAQ', <<<'HTML'
<section class="lp-section" data-lp-section="faq">
    <div class="lp-wrap">
        <h2>FAQ</h2>
        <details class="lp-faq" open><summary>How does this work?</summary><p>Share your details and our team will follow up with next steps.</p></details>
        <details class="lp-faq"><summary>Can I change this later?</summary><p>Yes. You can update copy, layout, and styles at any time.</p></details>
        <details class="lp-faq"><summary>Is there a contract?</summary><p>No long-term contract is required to get started.</p></details>
    </div>
</section>
HTML, $this->sectionCss('faq')),
            $this->block('comparison', 'Comparison', <<<'HTML'
<section class="lp-section lp-section-alt" data-lp-section="comparison">
    <div class="lp-wrap">
        <h2>Compare</h2>
        <table class="lp-table">
            <thead><tr><th>Capability</th><th>Us</th><th>Typical alternative</th></tr></thead>
            <tbody>
                <tr><td>Setup time</td><td>Same day</td><td>Weeks</td></tr>
                <tr><td>Brand match</td><td>Yes</td><td>Generic</td></tr>
                <tr><td>Lead capture</td><td>Included</td><td>Add-on</td></tr>
            </tbody>
        </table>
    </div>
</section>
HTML, $this->sectionCss('comparison')),
            $this->block('cta', 'CTA', <<<'HTML'
<section class="lp-cta" data-lp-section="cta">
    <div class="lp-wrap">
        <h2>Ready to get started?</h2>
        <p>Tell us what you need and we will take it from there.</p>
        <a class="lp-btn" href="#contact">Get in touch</a>
    </div>
</section>
HTML, $this->sectionCss('cta')),
            $this->block('contact', 'Contact', <<<'HTML'
<section class="lp-section" data-lp-section="contact" id="contact">
    <div class="lp-wrap">
        <h2>Contact</h2>
        <form class="lp-form" method="post">
            <label>Name <input type="text" name="name" required></label>
            <label>Email <input type="email" name="email" required></label>
            <label>Phone <input type="tel" name="phone"></label>
            <label>Message <textarea name="message" rows="4"></textarea></label>
            <button class="lp-btn" type="submit">Send details</button>
        </form>
    </div>
</section>
HTML, $this->sectionCss('contact')),
            $this->block('stats', 'Stats', <<<'HTML'
<section class="lp-section" data-lp-section="stats">
    <div class="lp-wrap lp-grid lp-grid-3">
        <div class="lp-stat"><strong>98%</strong><span>Customer satisfaction</span></div>
        <div class="lp-stat"><strong>12k</strong><span>Leads captured</span></div>
        <div class="lp-stat"><strong>24h</strong><span>Typical response</span></div>
    </div>
</section>
HTML, $this->sectionCss('stats')),
            $this->block('cards', 'Cards', <<<'HTML'
<section class="lp-section" data-lp-section="cards">
    <div class="lp-wrap">
        <h2>Explore</h2>
        <div class="lp-grid lp-grid-3">
            <article class="lp-card"><h3>Card title</h3><p>Short supporting copy for this card.</p><a href="#contact">Learn more</a></article>
            <article class="lp-card"><h3>Card title</h3><p>Short supporting copy for this card.</p><a href="#contact">Learn more</a></article>
            <article class="lp-card"><h3>Card title</h3><p>Short supporting copy for this card.</p><a href="#contact">Learn more</a></article>
        </div>
    </div>
</section>
HTML, $this->sectionCss('cards')),
            $this->block('footer', 'Footer', <<<'HTML'
<footer class="lp-footer" data-lp-section="footer">
    <div class="lp-wrap">
        <p>© 2026 Your brand. All rights reserved.</p>
        <nav><a href="/privacy">Privacy</a> <a href="/terms">Terms</a></nav>
    </div>
</footer>
HTML, $this->sectionCss('footer')),
        ];
    }

    /**
     * @return list<array{id: string, label: string, html: string, css: string}>
     */
    private function elements(): array
    {
        return [
            $this->block('heading', 'Heading', '<h2>Section heading</h2>', ''),
            $this->block('paragraph', 'Paragraph', '<p>Write a short paragraph of supporting copy.</p>', ''),
            $this->block('text', 'Text', '<span>Inline text</span>', ''),
            $this->block('button', 'Button', '<a class="lp-btn" href="#contact">Get started</a>', $this->elementCss()),
            $this->block('link', 'Link', '<a href="#contact">Learn more</a>', ''),
            $this->block('icon', 'Icon', '<span class="lp-icon" aria-hidden="true"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="9"></circle><path d="M8 12l3 3 5-6"></path></svg></span>', '.lp-icon { display: inline-flex; color: var(--theme, currentColor); }'),
            $this->block('divider', 'Divider', '<hr class="lp-divider">', '.lp-divider { border: 0; border-top: 1px solid color-mix(in srgb, var(--text, #111) 16%, transparent); margin: 24px 0; }'),
            $this->block('list', 'List', '<ul class="lp-list"><li>First item</li><li>Second item</li><li>Third item</li></ul>', $this->elementCss()),
            $this->block('container', 'Container', '<div class="lp-wrap"><p>Container</p></div>', $this->elementCss()),
            $this->block('columns', 'Columns', '<div class="lp-grid lp-grid-2"><div><p>Column one</p></div><div><p>Column two</p></div></div>', $this->elementCss()),
            $this->block('card', 'Card', '<article class="lp-card"><h3>Card title</h3><p>Short supporting copy.</p></article>', $this->elementCss()),
            $this->block('form', 'Form', <<<'HTML'
<form class="lp-form" method="post">
    <label>Name <input type="text" name="name" required></label>
    <label>Email <input type="email" name="email" required></label>
    <button class="lp-btn" type="submit">Send details</button>
</form>
HTML, $this->elementCss()),
        ];
    }

    /**
     * @return array{id: string, label: string, html: string, css: string}
     */
    private function block(string $id, string $label, string $html, string $css): array
    {
        return [
            'id' => $id,
            'label' => $label,
            'html' => trim($html),
            'css' => trim($css),
        ];
    }

    private function sectionCss(string $id): string
    {
        return trim($this->sharedCss()."\n".$this->specificCss($id));
    }

    private function elementCss(): string
    {
        return $this->sharedCss();
    }

    private function sharedCss(): string
    {
        return <<<'CSS'
.lp-wrap { width: min(1120px, calc(100% - 48px)); margin: 0 auto; }
.lp-section, .lp-hero, .lp-cta, .lp-footer { padding: 72px 0; background: var(--background, #fff); color: var(--text, #111); }
.lp-section-alt, .lp-hero, .lp-cta { background: color-mix(in srgb, var(--theme, #5b5bd6) 8%, var(--background, #fff)); }
.lp-kicker { letter-spacing: .12em; text-transform: uppercase; font-size: 12px; color: var(--theme, #5b5bd6); margin: 0 0 12px; }
.lp-lead { font-size: 18px; max-width: 42rem; }
.lp-btn { display: inline-flex; align-items: center; justify-content: center; padding: 12px 20px; border-radius: 999px; background: var(--theme, #5b5bd6); color: #fff; text-decoration: none; border: 0; font-weight: 600; }
.lp-btn-ghost { background: transparent; color: var(--theme, #5b5bd6); border: 1px solid var(--theme, #5b5bd6); }
.lp-grid { display: grid; gap: 24px; }
.lp-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.lp-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.lp-card { padding: 24px; border-radius: 16px; background: var(--background, #fff); border: 1px solid color-mix(in srgb, var(--text, #111) 10%, transparent); }
.lp-card-accent { border-color: var(--theme, #5b5bd6); }
.lp-list { padding-left: 1.2rem; }
.lp-form { display: grid; gap: 12px; max-width: 32rem; }
.lp-form label { display: grid; gap: 6px; font-weight: 600; }
.lp-form input, .lp-form textarea { padding: 10px 12px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--text, #111) 18%, transparent); font: inherit; }
.lp-split { display: grid; grid-template-columns: 1.1fr .9fr; gap: 40px; align-items: center; }
.lp-placeholder { min-height: 240px; border-radius: 16px; background: color-mix(in srgb, var(--theme, #5b5bd6) 16%, var(--background, #fff)); }
.lp-footer .lp-wrap, .lp-footer nav { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lp-footer a { color: inherit; }
@media (max-width: 767px) {
  .lp-grid-2, .lp-grid-3, .lp-split { grid-template-columns: 1fr; }
  .lp-section, .lp-hero, .lp-cta, .lp-footer { padding: 48px 0; }
}
CSS;
    }

    private function specificCss(string $id): string
    {
        return match ($id) {
            'hero' => '.lp-hero h1 { font-size: clamp(32px, 6vw, 56px); margin: 0 0 16px; }',
            'pricing' => '.lp-price { font-size: 32px; font-weight: 700; margin: 8px 0; }',
            'faq' => '.lp-faq { border-bottom: 1px solid color-mix(in srgb, var(--text, #111) 12%, transparent); padding: 12px 0; } .lp-faq summary { cursor: pointer; font-weight: 600; }',
            'comparison' => '.lp-table { width: 100%; border-collapse: collapse; } .lp-table th, .lp-table td { padding: 12px; border-bottom: 1px solid color-mix(in srgb, var(--text, #111) 12%, transparent); text-align: left; }',
            'cta' => '.lp-cta { text-align: center; } .lp-cta .lp-btn { margin-top: 8px; }',
            'stats' => '.lp-stat { text-align: center; } .lp-stat strong { display: block; font-size: 40px; color: var(--theme, #5b5bd6); }',
            default => '',
        };
    }
}
