import {
    CURRENT_FOOTER_VERSION,
    CURRENT_NAV_VERSION,
    CURRENT_WELCOME_VERSION,
} from './cms-migrator';
import type {
    CustomSection,
    FooterConfig,
    HeaderConfig,
    PageConfig,
} from './cms-types';

/* Defaults used when admin hasn't customized a section yet. Match the copy
 * that was previously hardcoded in shared.tsx so a fresh install renders
 * identically to the pre-CMS state. Admins customize from here.
 *
 * The PHP-side mirror lives at app/Support/MarketingDefaults.php — keep
 * the two in sync when adding/changing keys. */

export const DEFAULT_HEADER: HeaderConfig = {
    version: CURRENT_NAV_VERSION,
    links: [
        { id: 'templates', label: 'Templates', href: '/templates', enabled: true },
        { id: 'pricing', label: 'Pricing', href: '/pricing', enabled: true },
        { id: 'contact', label: 'Contact', href: '/contact', enabled: true },
    ],
};

export const DEFAULT_FOOTER: FooterConfig = {
    version: CURRENT_FOOTER_VERSION,
    tagline:
        'App Store and Play Store screenshots. Design once, every device, every store.',
    columns: [
        {
            id: 'product',
            heading: 'Product',
            links: [
                { id: 'templates', label: 'Templates', href: '/templates', enabled: true },
                { id: 'pricing', label: 'Pricing', href: '/pricing', enabled: true },
                { id: 'register', label: 'Start free', href: '/register', enabled: true },
                { id: 'login', label: 'Sign in', href: '/login', enabled: true },
            ],
        },
        {
            id: 'resources',
            heading: 'Resources',
            links: [
                { id: 'about', label: 'About', href: '/about', enabled: true },
                // Documentation + Changelog disabled by default — admin
                // turns them on once they have real targets to point at.
                { id: 'docs', label: 'Documentation', href: '#', enabled: false },
                { id: 'changelog', label: 'Changelog', href: '#', enabled: false },
                { id: 'contact', label: 'Contact', href: '/contact', enabled: true },
            ],
        },
        {
            id: 'legal',
            heading: 'Legal',
            // Disabled by default — admin enables once real Privacy/Terms/
            // Refunds pages are wired (Stripe + Razorpay onboarding requires
            // these URLs to be live).
            links: [
                { id: 'privacy', label: 'Privacy', href: '#', enabled: false },
                { id: 'terms', label: 'Terms', href: '#', enabled: false },
                { id: 'refunds', label: 'Refunds', href: '#', enabled: false },
            ],
        },
    ],
};

/* Welcome page sections in render order. Each section's `enabled` defaults
 * to true so a fresh install renders the same as the pre-CMS state.
 *
 * Testimonials ships with `items: []` even though enabled — the renderer
 * hides the whole section when no items exist, sidestepping the "fake
 * testimonials shipped with every install" legal/ethics concern. Admin
 * adds real testimonials and the section reveals itself.
 *
 * Mirror this byte-for-byte in MarketingDefaults::welcome() (PHP). */
export const DEFAULT_WELCOME: PageConfig = {
    version: CURRENT_WELCOME_VERSION,
    sections: [
        {
            id: 'hero',
            type: 'hero',
            enabled: true,
            eyebrow: 'New: kits + auto-derive across 8 device sizes',
            headline: 'a <em>simple screenshot maker</em> for App Store &amp; Play Store',
            primaryCta: { label: 'Launch App', href: '/register' },
            secondaryCta: { label: 'View Templates', href: '/templates' },
            ctaDisclaimer: '<p>Free for 1 project. No credit card.</p>',
            showVideoPlaceholder: true,
            annotationLeft: '',
            annotationRight: '',
        },
        {
            id: 'logo_wall',
            type: 'logo_wall',
            enabled: true,
            label: 'Powering teams at',
            // Empty by default — section auto-hides until admin adds real
            // logos. Same posture as testimonials: shipping placeholder
            // "customer" logos on every install is a credibility/legal risk.
            items: [],
        },
        {
            id: 'features',
            type: 'features',
            enabled: true,
            eyebrow: '',
            heading: 'Built for the way you <em>ship</em>.',
            subhead:
                '<p>Every feature exists to remove a manual step from your screenshot pipeline.</p>',
            items: [
                {
                    icon: 'Layers',
                    title: 'Project kits',
                    body: '<p>Start from a finished design. Hand-crafted multi-screen kits scaffold every device size, so you brand it and ship.</p>',
                },
                {
                    icon: 'Smartphone',
                    title: 'Eight device sizes',
                    body: '<p>iPhone, iPad, Android phone, Android tablet — landscape and portrait. One canvas, every variant.</p>',
                },
                {
                    icon: 'Package',
                    title: 'Organized exports',
                    body: '<p>Download a clean ZIP with folders per device, ready to upload to App Store Connect and Google Play.</p>',
                },
                {
                    icon: 'MousePointerClick',
                    title: 'Edit everything inline',
                    body: '<p>Click text to retype, drag to move, snap to align. Anchors keep your design lined up across every device size automatically.</p>',
                },
            ],
        },
        {
            id: 'templates_teaser',
            type: 'templates_teaser',
            enabled: true,
            eyebrow: '',
            heading: 'Start from a <em>finished</em> design.',
            subhead:
                '<p>Project kits scaffold every screen across every device. Brand them and ship in minutes.</p>',
            ctaLabel: 'Browse all templates',
        },
        {
            id: 'stats',
            type: 'stats',
            enabled: true,
            items: [
                { value: '20 min', label: 'blank canvas to App Store ZIP' },
                { value: '8 sizes', label: 'auto-derived from one master canvas' },
                { value: '1 click', label: 'exports a ready-to-upload ZIP' },
            ],
        },
        {
            id: 'how_it_works',
            type: 'how_it_works',
            enabled: true,
            eyebrow: '',
            heading: 'Three steps to <em>shipped</em>.',
            subhead:
                '<p>From blank canvas to App Store-ready ZIP. No re-positioning per device. No re-exporting per platform.</p>',
            items: [
                {
                    n: '01',
                    time: '30 seconds',
                    title: 'Pick a kit',
                    body: '<p>Choose from finished templates. Every device size is scaffolded for you.</p>',
                },
                {
                    n: '02',
                    time: '5 minutes',
                    title: 'Brand it',
                    body: '<p>Swap content, drop in your screenshots, tweak fonts and colors. Anchors keep everything aligned.</p>',
                },
                {
                    n: '03',
                    time: '1 click',
                    title: 'Export',
                    body: '<p>One click downloads a fully organized ZIP — folders per device, ready to upload.</p>',
                },
            ],
        },
        {
            id: 'testimonials',
            type: 'testimonials',
            enabled: true,
            eyebrow: 'Testimonials',
            heading: 'Trusted by indie devs <em>and agencies</em>.',
            subhead:
                '<p>How shipping App Store screenshots feels with AppShot in the pipeline.</p>',
            // Empty by default — section auto-hides until admin adds real
            // ones. Fake/canned testimonials shipped on every install would
            // be a legal/ethics problem (FTC + multiple jurisdictions).
            items: [],
        },
        {
            id: 'faq',
            type: 'faq',
            enabled: true,
            eyebrow: '',
            heading: 'Common <em>questions</em>.',
            supportText:
                '<p>Can\'t find what you\'re looking for? Drop a line on the <a href="/contact">contact page</a> — usually answered within 4 hours during weekdays.</p>',
            items: [
                {
                    q: 'Will my screenshots pass App Store and Play Store guidelines?',
                    a: '<p>Yes. AppShot exports at exact required pixel dimensions for every device tier Apple and Google specify — including the most recent iPhone and iPad refreshes. We track Apple and Google updates and ship preset updates when stores bump requirements.</p>',
                },
                {
                    q: 'Do I own the screenshots I create?',
                    a: '<p>Absolutely. Anything you design and export is yours. No watermarks, no licensing strings attached.</p>',
                },
                {
                    q: 'Can I self-host AppShot on my own server?',
                    a: '<p>Yes. AppShot ships in two modes from a single codebase — use our hosted SaaS, or download the ZIP and run on Hostinger-tier shared hosting with zero SSH required. Same features in both modes.</p>',
                },
                {
                    q: 'Can I edit project kits or do I have to use them as-is?',
                    a: '<p>Edit them. Kits scaffold every device size with smart anchors, but every element is fully editable — text, colors, fonts, layouts, screenshots.</p>',
                },
                {
                    q: 'Do I need design skills to use AppShot?',
                    a: "<p>No. Kits ship pre-designed — start from a finished layout, swap in your brand and screenshots, click export. If you'd rather design from scratch, the editor has snap-to-align, anchors, and inline text editing so layouts stay tidy without a Figma background.</p>",
                },
                {
                    q: 'What happens when Apple or Google change screenshot specs?',
                    a: '<p>Your existing projects keep rendering at their original specs — no surprise breakage. When stores add a new device tier, we ship the preset, and projects auto-derive into it via anchors so the layout adapts without manual rework.</p>',
                },
                {
                    q: "What's the refund policy?",
                    a: "<p>7-day money-back guarantee, no questions asked. Email support and you'll get a full refund within one business day.</p>",
                },
            ],
        },
        {
            id: 'final_cta',
            type: 'final_cta',
            enabled: true,
            eyebrow: '',
            heading: 'Ship App Store &amp; Play Store screenshots <em>today</em>.',
            subhead: '<p>Free for 1 project. No credit card to start.</p>',
            primaryCta: { label: 'Launch App', href: '/register' },
            secondaryCta: { label: 'Browse templates', href: '/templates' },
        },
    ],
};

function newId(): string {
    if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
        return crypto.randomUUID();
    }
    return `blk-${Date.now()}-${Math.floor(Math.random() * 1e6)}`;
}

/* Factory for a fresh Custom section. Custom isn't seeded into
 * DEFAULT_WELCOME (it's opt-in — admin adds it from the Add menu). The
 * 3 starter blocks below give admins a non-empty section to riff on
 * rather than an empty box. */
export function defaultCustomSection(): CustomSection {
    return {
        id: newId(),
        type: 'custom',
        enabled: true,
        blocks: [
            { id: newId(), type: 'eyebrow', text: 'Section' },
            { id: newId(), type: 'heading', html: 'Tell your story', size: 'h2' },
            {
                id: newId(),
                type: 'text',
                html: '<p>Customize this section with any combination of blocks. Add headings, paragraphs, buttons, images, and spacers.</p>',
            },
        ],
    };
}
