<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class HomePageContent extends Model
{
    protected $fillable = ['content'];

    protected function casts(): array
    {
        return [
            'content' => 'array',
        ];
    }

    public static function defaults(): array
    {
        return [
            'hero' => [
                'title' => 'Achieve your global dreams with',
                'highlight' => "Mentors' Study Abroad",
                'text' => 'A full landing page arranged for conversion with strong trust blocks, destination cards, institutions, stories, and CTA zones.',
                'image' => 'https://images.unsplash.com/photo-1607013251379-e6eecfffe234?auto=format&fit=crop&w=1200&q=80',
                'sticker_title' => 'Personalized counseling',
                'sticker_text' => 'Using free stock image placeholders so you can replace with your real assets later.',
                'primary_cta' => 'Book Free Consultation',
                'secondary_cta' => 'Explore Countries',
            ],
            'why' => [
                'title' => 'Why choose',
                'highlight' => "Mentors' Study Abroad",
                'image' => 'https://images.unsplash.com/photo-1552664730-d307ca884978?auto=format&fit=crop&w=1100&q=80',
                'items' => [
                    ['title' => 'No confusion, clear plan', 'text' => 'Country, intake, and budget mapping before application so students avoid wrong decisions.'],
                    ['title' => 'A to Z support', 'text' => 'From profile review and SOP support to admission and visa document preparation.'],
                    ['title' => 'Hassle free processing', 'text' => 'A guided workflow with practical follow-up so applications do not get stuck halfway.'],
                ],
                'stats' => [
                    ['number' => '200+', 'label' => 'University pathways'],
                    ['number' => '19+', 'label' => 'Years of guidance style'],
                    ['number' => '10,000+', 'label' => 'Story driven trust cues'],
                ],
            ],
            'accreditation' => [
                'title' => 'Our Accreditations and Memberships',
                'text' => 'This row is ready for your official badges and certifications later.',
                'seal_1' => "Global\nMember",
                'seal_2' => "Visa\nPartner",
            ],
            'destinations' => [
                'title' => 'Choose your dream',
                'highlight' => 'destination',
                'text' => 'Destination card layout designed to match your shared homepage reference style.',
                'fallback_images' => [
                    'https://images.unsplash.com/photo-1523482580672-f109ba8cb9be?auto=format&fit=crop&w=1000&q=80',
                    'https://images.unsplash.com/photo-1507699622108-4be3abd695ad?auto=format&fit=crop&w=1000&q=80',
                    'https://images.unsplash.com/photo-1485738422979-f5c462d49f74?auto=format&fit=crop&w=1000&q=80',
                    'https://images.unsplash.com/photo-1517935706615-2717063c2225?auto=format&fit=crop&w=1000&q=80',
                    'https://images.unsplash.com/photo-1513635269975-59663e0ac1ad?auto=format&fit=crop&w=1000&q=80',
                    'https://images.unsplash.com/photo-1596422846543-75c6fc197f07?auto=format&fit=crop&w=1000&q=80',
                ],
            ],
            'events' => [
                'title' => 'Our',
                'highlight' => 'events',
                'text' => 'Event cards improve engagement and give visitors one more conversion reason.',
                'items' => [
                    [
                        'date' => '12 April 2026',
                        'title' => 'Malaysia Education Fair',
                        'text' => 'Meet university representatives, explore tuition options, and review your profile in one session.',
                    ],
                    [
                        'date' => '19 April 2026',
                        'title' => 'Scholarship and SOP Workshop',
                        'text' => 'Focused guidance on profile strategy, SOP writing direction, and scholarship opportunities.',
                    ],
                ],
            ],
            'institutions' => [
                'title' => 'Our Partner',
                'highlight' => 'Institutions',
                'text' => 'These shared partner institutions are managed from one central library and reused across multiple pages.',
                'items' => [
                    'Deakin University', 'La Trobe University', 'Charles Darwin University', 'University of Canberra', 'Victoria University',
                    'Central Queensland University', 'Swinburne University', 'University of Tasmania', 'Macquarie University', 'Torrens University',
                    'Western Sydney University', 'Northumbria University', 'Middlesex University', 'University of East London', 'Kaplan Business School',
                ],
            ],
            'stories' => [
                'title' => 'Visa',
                'highlight' => 'Success Stories',
                'text' => 'Testimonial blocks increase trust for first-time visitors coming from ads.',
                'items' => [
                    ['name' => 'Maliha Chowdhury', 'text' => 'The team turned my confusion into a practical plan. I knew exactly which country fit my budget, what documents to prepare, and how to approach the visa process.'],
                    ['name' => 'Rafid Hossain', 'text' => 'Communication was fast and clear. Every issue was explained simply, and I always knew the next step in my application journey.'],
                ],
            ],
            'promo' => [
                'title' => 'One step away from your study abroad dream',
                'text' => 'A conversion-focused red strip to break the scroll and push consultation action.',
                'button' => 'Book Free Consultation',
            ],
            'videos' => [
                'title' => 'Hear From Our',
                'highlight' => 'Students',
                'text' => 'Styled as video testimonial cards to mirror the feel of your target design.',
                'items' => [
                    ['title' => 'Visa interview recap', 'image' => 'https://images.unsplash.com/photo-1494790108377-be9c29b29330?auto=format&fit=crop&w=800&q=80'],
                    ['title' => 'Country selection journey', 'image' => 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?auto=format&fit=crop&w=800&q=80'],
                    ['title' => 'Scholarship planning story', 'image' => 'https://images.unsplash.com/photo-1544005313-94ddf0286df2?auto=format&fit=crop&w=800&q=80'],
                    ['title' => 'Departure day update', 'image' => 'https://images.unsplash.com/photo-1506794778202-cad84cf45f1d?auto=format&fit=crop&w=800&q=80'],
                ],
            ],
            'partners' => [
                'title' => 'Our',
                'highlight' => 'Partners',
                'text' => 'A slim trust row for travel and support partners.',
                'items' => ['Air Asia', 'B2B Visa', 'Pathway Hub', 'FastSign', 'Global Transfer'],
            ],
            'steps' => [
                'title' => 'Take your first step',
                'highlight' => 'with us',
                'text' => 'Checklist columns provide practical information before a user opens the apply modal.',
                'items' => [
                    ['title' => 'Prepare your profile', 'lines' => ['Academic review', 'Budget planning', 'Country shortlist', 'Intake timeline']],
                    ['title' => 'Build your application', 'lines' => ['University selection', 'SOP guidance', 'Document checklist', 'Offer tracking']],
                    ['title' => 'Move to visa stage', 'lines' => ['Funds planning', 'Visa document support', 'Interview prep', 'Pre departure support']],
                ],
            ],
            'faq' => [
                'title' => 'Frequently Asked',
                'highlight' => 'Questions',
                'text' => 'Accordion section completes the page flow and addresses hesitation points.',
                'items' => [
                    ['q' => 'How much does counseling cost?', 'a' => 'You can keep this as a free consultation promise now and replace with your exact pricing policy later.'],
                    ['q' => 'Can I apply with a study gap?', 'a' => 'Yes, in many cases. Strategy depends on profile, supporting documents, and destination requirement.'],
                    ['q' => 'Do you support scholarships?', 'a' => 'Yes. The page layout is prepared for scholarship-driven messaging and future updates.'],
                    ['q' => 'How long does visa processing take?', 'a' => 'Processing time depends on country, intake period, and embassy conditions.'],
                ],
            ],
            'final' => [
                'title' => 'Still wondering what to do?',
                'text' => 'Use this final conversion zone for consultation booking, WhatsApp handoff, or your campaign-level offer copy.',
                'button' => 'Book Free Consultation',
                'image' => 'https://images.unsplash.com/photo-1573496359142-b8d87734a5a2?auto=format&fit=crop&w=700&q=80',
            ],
            'sticky_button' => 'Apply Now',
        ];
    }

    public static function getContent(): array
    {
        $row = static::query()->first();
        $stored = $row?->content ?? [];

        return array_replace_recursive(static::defaults(), $stored);
    }

    public static function saveContent(array $content): void
    {
        static::query()->updateOrCreate(
            ['id' => 1],
            ['content' => $content]
        );
    }
}
