<?php

namespace Database\Seeders;

use App\Models\Media;
use App\Models\Page;
use Illuminate\Database\Seeder;

class PageSeeder extends Seeder
{
    public function run(): void
    {
        Page::firstOrCreate(
            ['slug' => 'home'],
            [
                'title' => 'Home',
                'template' => 'home',
                'content' => '<p>Saleem Sial Analytics helps growth teams build trustworthy measurement across websites, ads, and reporting stacks.</p>',
                'sections' => [
                    'hero' => [
                        'eyebrow' => 'Built for modern measurement',
                        'eyebrow_highlight' => 'Track with confidence',
                        'title_html' => '<span class="ssa-hero-title__prefix">Accurate tracking for every</span><span class="prespa-saas-animated-text" data-typed-words="Analytics|Tracking|Reporting|Advertising|Meta Ads|TikTok Ads|Google Ads|Google Analytics 4">Analytics</span>',
                        'description' => 'From GA4 and GTM to ad pixels, dashboards, and server-side tracking, Saleem Sial Analytics helps you measure what matters and act on data you can trust.',
                        'primary_cta_label' => 'Explore Services',
                        'primary_cta_url' => '/services',
                        'secondary_cta_label' => 'Contact Saleem',
                        'secondary_cta_url' => '/contact',
                        'image_media_id' => $this->preferredMediaId([
                            'uploads/media/QECnMIgrtk0VLvcpm8KtGkzWHw9oEO9Lm1umT2fO.png',
                            'uploads/system/hero-analytics-dashboard.svg',
                        ]),
                        'platforms' => [
                            ['label' => 'GA4', 'media_id' => $this->mediaId('uploads/media/v79FaD7gAYHhwhCVU9jXaW6Wyo19v4wpO9OFcmuQ.png')],
                            ['label' => 'GTM', 'media_id' => $this->mediaId('uploads/media/kiMpmVYtvcfuAtyLh02wRHiwsu2vLmTiV6kQpQYl.jpg')],
                            ['label' => 'Looker Studio', 'media_id' => $this->mediaId('uploads/media/Y4Bi7JUJUcsDY20kUyTIBtVMZKoSRUljI2g5AXoN.png')],
                            ['label' => 'Google Ads', 'media_id' => $this->mediaId('uploads/media/s9G0trlaaAP9twGJP9LWkGaxLMNoMgl0uLnchQ7q.png')],
                            ['label' => 'Meta Ads', 'media_id' => $this->mediaId('uploads/media/HcPhcJm39jfEcKKBzswosdyEpf1uoIXLTLXBaqW5.png')],
                            ['label' => 'TikTok Ads', 'media_id' => $this->mediaId('uploads/media/zYN1PnqHn8r1OPnyHYMS29Xvw8xqA9V1BdRG7NqK.png')],
                            ['label' => 'Server-Side', 'media_id' => $this->mediaId('uploads/media/iJcm5ue8eXcbASnWFv0OMQgo4xkilmSfM3vT7Gd8.png')],
                        ],
                    ],
                    'trusted' => [
                        'title' => 'Trusted by marketing teams that need cleaner reporting and better conversion visibility.',
                        'logos' => [
                            ['label' => 'Trusted logo 1', 'media_id' => $this->mediaId('uploads/system/trusted-1.png')],
                            ['label' => 'Trusted logo 2', 'media_id' => $this->mediaId('uploads/system/trusted-2.png')],
                            ['label' => 'Trusted logo 3', 'media_id' => $this->mediaId('uploads/system/trusted-3.png')],
                            ['label' => 'Trusted logo 4', 'media_id' => $this->mediaId('uploads/system/trusted-4.png')],
                            ['label' => 'Trusted logo 5', 'media_id' => $this->mediaId('uploads/system/trusted-5.png')],
                        ],
                    ],
                    'why_tracking' => [
                        'badge' => 'Why tracking matters',
                        'title' => 'Clear data creates better campaigns, better reporting, and better decisions.',
                        'description' => 'When attribution breaks, every marketing decision gets harder. A strong tracking foundation gives your team visibility into performance, lead quality, and return on ad spend.',
                        'cta_label' => 'About Saleem Sial',
                        'cta_url' => '/about',
                        'items' => [
                            [
                                'media_id' => $this->mediaId('uploads/system/why-tracking-trending.png'),
                                'title' => 'Know what actually converts',
                                'description' => 'Measure critical actions across landing pages, forms, checkout flows, and ad platforms without guesswork.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/why-tracking-cloud.png'),
                                'title' => 'Reduce reporting noise',
                                'description' => 'Bring paid media, analytics, and CRM signals into one cleaner source of truth for faster reporting.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/why-tracking-task.png'),
                                'title' => 'Scale without constant rework',
                                'description' => 'Build GTM containers, naming conventions, and event structures that stay organized as campaigns grow.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/why-tracking-speedometer.png'),
                                'title' => 'Stay accurate in a privacy-first web',
                                'description' => 'Use server-side tracking and better implementation patterns to reduce data loss and improve attribution quality.',
                            ],
                        ],
                    ],
                    'services_intro' => [
                        'badge' => 'Core tracking services',
                        'title' => 'Measurement systems tailored to the platforms you rely on.',
                        'description' => 'Every service below is managed from the database so it can later move directly into a full CMS workflow.',
                    ],
                    'pricing' => [
                        'badge' => 'Pricing & packages',
                        'title' => 'Competitor-aligned starter packages for setup, cleanup, and growth support.',
                        'description' => 'These example packages are positioned around common freelancer and boutique-consultant ranges for GA4, GTM, ads tracking, and reporting support.',
                        'audit_title' => 'Not sure which package fits? Start with a free audit request.',
                        'audit_description' => 'If you already have analytics or paid media running, request a free audit first and get a cleaner recommendation based on your current setup.',
                        'audit_label' => 'Request Free Audit',
                        'packages' => [
                            [
                                'badge' => 'Starter',
                                'name' => 'Tracking Tune-Up',
                                'price' => 'From $149',
                                'timeline' => 'Typical delivery: 2-4 days',
                                'summary' => 'Ideal for fixing GA4 events, cleaning up conversions, or repairing a small GTM setup.',
                                'items' => [
                                    'GA4 or GTM cleanup for one website',
                                    'Conversion checks and QA notes',
                                    'Short Loom or written handoff',
                                ],
                            ],
                            [
                                'badge' => 'Most requested',
                                'featured' => true,
                                'name' => 'Cross-Channel Setup',
                                'price' => 'From $349',
                                'timeline' => 'Typical delivery: 4-7 days',
                                'summary' => 'A stronger package for GA4, GTM, Google Ads, and Meta or TikTok event mapping on active campaigns.',
                                'items' => [
                                    'GA4 + GTM implementation or rebuild',
                                    'Ads platform conversion setup',
                                    'Naming structure, testing, and reporting checks',
                                ],
                            ],
                            [
                                'badge' => 'Advanced',
                                'name' => 'Server-Side & Reporting Build',
                                'price' => 'From $699',
                                'timeline' => 'Typical delivery: 1-2 weeks',
                                'summary' => 'Best for privacy-aware measurement, multi-platform reporting, and more advanced attribution support.',
                                'items' => [
                                    'Server-side or advanced tracking architecture',
                                    'Dashboard/reporting layer setup',
                                    'Implementation plan for scale and governance',
                                ],
                            ],
                        ],
                    ],
                    'security' => [
                        'badge' => 'Security & governance',
                        'title' => 'Cleaner tracking should also be safer, better documented, and easier to control.',
                        'description' => 'The implementation approach focuses on permission control, privacy-aware measurement, and workflows that reduce accidental changes later.',
                        'cta_label' => 'Request Free Audit',
                        'items' => [
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-file.png'),
                                'title' => 'Documented tagging changes',
                                'description' => 'Keep event naming, trigger logic, and reporting notes easier to review before new campaigns launch.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-workflows.png'),
                                'title' => 'Permission-aware GTM workflows',
                                'description' => 'Reduce mistakes by structuring containers and publishing steps around clearer ownership.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-circles.png'),
                                'title' => 'Privacy-ready measurement',
                                'description' => 'Support browser restrictions with better consent-aware implementations and server-side options.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-bar-chart.png'),
                                'title' => 'Safer reporting handoff',
                                'description' => 'Build dashboards and reporting layers that stakeholders can trust without direct tag edits.',
                            ],
                        ],
                    ],
                    'case_studies' => [
                        'badge' => 'Case studies',
                        'title' => 'Dashboard snapshots that show the difference between noisy data and a cleaner setup.',
                        'description' => 'Use before-and-after screenshots to explain how implementation changes improve clarity, attribution, and reporting confidence.',
                        'studies' => [
                            [
                                'label' => 'Lead generation',
                                'title' => 'GA4 + GTM repair for a paid traffic funnel',
                                'summary' => 'The original reporting mixed duplicate events with missing form conversions. After the rebuild, campaign reporting clearly separated qualified leads from low-intent traffic.',
                                'result' => 'Result: cleaner form conversion visibility and faster weekly reporting.',
                                'before_media_id' => $this->mediaId('uploads/system/case-study-1-before.svg'),
                                'after_media_id' => $this->mediaId('uploads/system/case-study-1-after.svg'),
                            ],
                            [
                                'label' => 'Ecommerce tracking',
                                'title' => 'Cross-platform dashboard cleanup for ads and analytics',
                                'summary' => 'The first version forced the team to compare Meta, Google Ads, and GA4 manually. The new dashboard made spend, ROAS, and assisted conversions easier to explain in one place.',
                                'result' => 'Result: clearer paid media reporting and fewer stakeholder questions.',
                                'before_media_id' => $this->mediaId('uploads/system/case-study-2-before.svg'),
                                'after_media_id' => $this->mediaId('uploads/system/case-study-2-after.svg'),
                            ],
                        ],
                    ],
                    'contact_options' => [
                        'badge' => 'Get in touch',
                        'title' => 'Request a free audit, ask about pricing, or message directly.',
                        'description' => 'Use whichever contact option fits your workflow best: contact form, email, WhatsApp, or support chat.',
                        'headline' => 'Choose the fastest route for your tracking question.',
                    ],
                    'benefits' => [
                        'badge' => 'Benefits',
                        'highlight' => 'Built for accurate reporting',
                        'title' => 'Why businesses choose Saleem Sial Analytics',
                        'description' => 'You get a setup that is easier to trust, easier to explain, and easier to scale.',
                        'items' => [
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-bar-chart.png'),
                                'title' => 'Reliable event data',
                                'description' => 'Capture the right user actions and send them to the right destinations with confidence.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-pie-chart.png'),
                                'title' => 'Cross-platform reporting',
                                'description' => 'Connect ad platforms and analytics tools so performance can be reviewed in one place.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-sparkles.png'),
                                'title' => 'Smarter optimization',
                                'description' => 'Improve campaign decisions with cleaner conversion signals and reporting clarity.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-workflows.png'),
                                'title' => 'Repeatable implementation',
                                'description' => 'Documented tagging, naming, and tracking structures that support long-term growth.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-file.png'),
                                'title' => 'Faster stakeholder reporting',
                                'description' => 'Create dashboards and summaries that make performance easier to understand and act on.',
                            ],
                            [
                                'media_id' => $this->mediaId('uploads/system/benefit-circles.png'),
                                'title' => 'Privacy-aware measurement',
                                'description' => 'Support modern browser restrictions with better architecture and server-side options.',
                            ],
                        ],
                    ],
                    'cta' => [
                        'title' => 'Ready to fix your tracking foundation?',
                        'description' => "Let's build a cleaner measurement stack for your website, ads, and reporting workflow.",
                        'button_label' => 'Book a Tracking Consultation',
                        'button_url' => '/contact',
                    ],
                ],
                'meta_title' => 'Saleem Sial Analytics | GA4, GTM and Performance Tracking',
                'meta_description' => 'Saleem Sial Analytics helps businesses implement GA4, GTM, ad tracking, dashboards, and server-side measurement with reliable data.',
            ]
        );

        Page::firstOrCreate(
            ['slug' => 'about'],
            [
                'title' => 'About',
                'template' => 'about',
                'content' => '<p>Saleem Sial Analytics specializes in implementation, measurement strategy, and reporting systems that help businesses understand real performance.</p>',
                'sections' => [
                    'hero' => [
                        'eyebrow' => 'About Saleem Sial Analytics',
                        'title' => 'Measurement strategy built around clarity, trust, and growth.',
                        'description' => 'This practice focuses on helping brands and agencies build dependable tracking systems that support better decisions across analytics, media, and reporting.',
                    ],
                    'intro' => [
                        'title' => 'What we do',
                        'content' => 'We implement GA4, GTM, ad platform tracking, dashboards, and server-side setups so businesses can report with confidence and optimize based on cleaner data.',
                    ],
                    'mission' => [
                        'title' => 'Our mission',
                        'content' => 'To make modern measurement easier to understand and easier to manage by turning fragmented tracking setups into structured, scalable systems.',
                    ],
                    'expertise' => [
                        'title' => 'How we help',
                        'items' => [
                            'Audit tracking setups and find gaps in implementation.',
                            'Build event, conversion, and pixel tracking for websites and campaigns.',
                            'Create reporting layers that turn data into action.',
                        ],
                    ],
                    'why_choose' => [
                        'title' => 'Why choose us',
                        'items' => [
                            'A focused specialization in analytics and tracking.',
                            'Implementation that is built for future CMS and admin workflows.',
                            'Clean documentation and scalable structures that are easier to maintain later.',
                        ],
                    ],
                    'cta' => [
                        'title' => 'Need help improving your measurement stack?',
                        'button_label' => 'Contact Us',
                        'button_url' => '/contact',
                    ],
                ],
                'meta_title' => 'About Saleem Sial Analytics',
                'meta_description' => 'Learn how Saleem Sial Analytics helps teams build reliable tracking and reporting systems.',
            ]
        );

        Page::firstOrCreate(
            ['slug' => 'blog'],
            [
                'title' => 'Blog',
                'template' => 'blog',
                'content' => '<p>Insights and practical notes from Saleem Sial Analytics on measurement, reporting, and analytics implementation.</p>',
                'sections' => [
                    'hero' => [
                        'eyebrow' => 'Blog & Insights',
                        'title' => 'Practical notes on cleaner tracking, reporting, and analytics decisions.',
                        'description' => 'Use this page to share implementation tips, audits, case studies, and strategy insights around GA4, GTM, dashboards, and ad tracking.',
                    ],
                    'featured' => [
                        'badge' => 'Featured guide',
                        'title' => 'How to audit a GA4 and GTM setup before scaling paid traffic',
                        'excerpt' => 'A simple framework for checking events, conversions, tags, naming, and data quality before you make optimization decisions from broken reporting.',
                        'reading_time' => '7 min read',
                        'slug' => 'how-to-audit-a-ga4-and-gtm-setup-before-scaling-paid-traffic',
                        'content' => "Start with the events that matter most to revenue and lead quality.\n\nThen confirm that every conversion action is mapped consistently across GA4, Google Ads, and any supporting CRM or form tools.\n\nFinally, review naming, triggers, and QA notes inside GTM so the setup stays maintainable as campaigns scale.",
                        'media_id' => $this->mediaId('uploads/system/hero-analytics-dashboard.svg'),
                    ],
                    'posts_intro' => [
                        'badge' => 'Latest articles',
                        'title' => 'Topics you can publish and update from the CMS',
                        'description' => 'Use these cards as a starter structure for blog posts, case studies, technical explainers, or performance reporting guides.',
                    ],
                    'posts' => [
                        [
                            'badge' => 'GA4',
                            'title' => 'What to validate after a fresh GA4 implementation',
                            'excerpt' => 'A quick checklist for event naming, conversion setup, enhanced measurement, filters, and reporting sanity checks.',
                            'reading_time' => '5 min read',
                            'slug' => 'what-to-validate-after-a-fresh-ga4-implementation',
                            'content' => "Validate the events first so your reports reflect the actions that actually matter.\n\nThen confirm conversions, filters, and reporting views before anyone uses the data for campaign decisions.",
                        ],
                        [
                            'badge' => 'GTM',
                            'title' => 'How to keep your GTM container organized as campaigns grow',
                            'excerpt' => 'A practical structure for folders, tag naming, triggers, variables, and QA notes so scaling does not create chaos.',
                            'reading_time' => '6 min read',
                            'slug' => 'how-to-keep-your-gtm-container-organized-as-campaigns-grow',
                            'content' => "Use folders, naming conventions, and documentation from the beginning.\n\nA clean GTM workspace makes audits, updates, and handoffs much easier as the account becomes more complex.",
                        ],
                        [
                            'badge' => 'Dashboards',
                            'title' => 'What a useful Looker Studio dashboard should actually include',
                            'excerpt' => 'Build reporting views that help teams act faster by focusing on trend context, conversion quality, and business-ready KPIs.',
                            'reading_time' => '4 min read',
                            'slug' => 'what-a-useful-looker-studio-dashboard-should-actually-include',
                            'content' => "A useful dashboard should explain performance, not just display metrics.\n\nFocus on KPIs, trend context, and the decisions each view is meant to support.",
                        ],
                        [
                            'badge' => 'Server-Side',
                            'title' => 'When server-side tracking is worth the extra setup',
                            'excerpt' => 'Learn when the extra implementation effort improves data quality, privacy compliance, and platform attribution enough to matter.',
                            'reading_time' => '8 min read',
                            'slug' => 'when-server-side-tracking-is-worth-the-extra-setup',
                            'content' => "Server-side tracking is most useful when browser-side loss is affecting attribution and optimization.\n\nThe extra setup pays off when better data quality improves reporting confidence and ad platform feedback loops.",
                        ],
                    ],
                    'cta' => [
                        'title' => 'Need help turning insights into a working setup?',
                        'description' => 'Get support with GA4, GTM, dashboard reporting, and performance tracking that is built for long-term clarity.',
                        'button_label' => 'Contact Saleem',
                        'button_url' => '/contact',
                    ],
                ],
                'meta_title' => 'Blog | Saleem Sial Analytics',
                'meta_description' => 'Read Saleem Sial Analytics insights on GA4, GTM, dashboards, ad tracking, and modern measurement strategy.',
            ]
        );

        Page::firstOrCreate(
            ['slug' => 'services'],
            [
                'title' => 'Tracking and analytics services built for modern growth teams.',
                'template' => 'services',
                'content' => '<p>Browse the full service catalog, filter by category, and request a free audit or direct support from any page.</p>',
                'meta_title' => 'Services',
                'meta_description' => 'Explore GA4, GTM, dashboard, ad tracking, and server-side analytics services from Saleem Sial Analytics.',
            ]
        );
    }

    protected function mediaId(string $path): ?int
    {
        return Media::query()->where('file_path', $path)->value('id');
    }

    protected function preferredMediaId(array $paths): ?int
    {
        foreach ($paths as $path) {
            $id = $this->mediaId($path);

            if ($id) {
                return $id;
            }
        }

        return null;
    }
}
