<?php

namespace Modules\VetSite\Support;

/**
 * The catalogue of section "blocks" a page can be built from. Each block has:
 *   - label / icon  : shown in the page-builder palette
 *   - fields[]      : editor schema {key,label,type} where type ∈
 *                     text|textarea|richtext|image|url|color|repeater|list
 *   - defaults{}    : starter content when a block is added
 * Blocks are rendered by Resources/views/blocks/{type}.blade.php and are
 * theme-agnostic (the active theme's CSS restyles them).
 */
class BlockRegistry
{
    public static function all(): array
    {
        return [
            'hero' => [
                'label' => 'Hero', 'icon' => 'fas fa-star',
                'fields' => [
                    ['key' => 'eyebrow', 'label' => 'Eyebrow', 'type' => 'text'],
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'subheading', 'label' => 'Subheading', 'type' => 'textarea'],
                    ['key' => 'image', 'label' => 'Background / side image', 'type' => 'image'],
                    ['key' => 'primary_label', 'label' => 'Primary button text', 'type' => 'text'],
                    ['key' => 'primary_url', 'label' => 'Primary button link', 'type' => 'url'],
                    ['key' => 'secondary_label', 'label' => 'Secondary button text', 'type' => 'text'],
                    ['key' => 'secondary_url', 'label' => 'Secondary button link', 'type' => 'url'],
                ],
                'defaults' => [
                    'eyebrow' => 'Trusted veterinary care',
                    'heading' => 'Compassionate care for the pets you love',
                    'subheading' => 'Modern medicine, a gentle touch, and a team that treats your companion like family.',
                    'image' => 'https://images.unsplash.com/photo-1576201836106-db1758fd1c97?auto=format&fit=crop&w=1400&q=80',
                    'primary_label' => 'Book an appointment', 'primary_url' => '#contact',
                    'secondary_label' => 'Our services', 'secondary_url' => '#services',
                ],
            ],
            'about' => [
                'label' => 'About', 'icon' => 'fas fa-paw',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'body', 'label' => 'Body', 'type' => 'richtext'],
                    ['key' => 'image', 'label' => 'Image', 'type' => 'image'],
                ],
                'defaults' => [
                    'heading' => 'Where your pet is family',
                    'body' => '<p>Our experienced veterinarians combine advanced diagnostics with genuine compassion to keep your companions healthy and happy at every stage of life.</p><p>From wagging-tail wellness visits to complex surgery, we treat every animal as if they were our own.</p>',
                    'image' => 'https://images.unsplash.com/photo-1601758228041-f3b2795255f1?auto=format&fit=crop&w=1000&q=80',
                ],
            ],
            'services' => [
                'label' => 'Services', 'icon' => 'fas fa-briefcase-medical',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'subheading', 'label' => 'Subheading', 'type' => 'textarea'],
                    ['key' => 'items', 'label' => 'Services', 'type' => 'repeater',
                     'item' => [['key' => 'icon', 'label' => 'Icon (FontAwesome)', 'type' => 'text'],
                                ['key' => 'title', 'label' => 'Title', 'type' => 'text'],
                                ['key' => 'text', 'label' => 'Description', 'type' => 'textarea']]],
                ],
                'defaults' => [
                    'heading' => 'Complete care, under one roof',
                    'items' => [
                        ['icon' => 'fas fa-stethoscope', 'title' => 'Wellness Exams', 'text' => 'Routine check-ups and preventive care to keep tails wagging.'],
                        ['icon' => 'fas fa-syringe', 'title' => 'Vaccinations', 'text' => 'Tailored vaccination plans for lifelong protection.'],
                        ['icon' => 'fas fa-tooth', 'title' => 'Dental Care', 'text' => 'Cleanings and oral surgery for a healthy smile.'],
                        ['icon' => 'fas fa-x-ray', 'title' => 'Diagnostics', 'text' => 'On-site lab, digital X-ray and ultrasound.'],
                        ['icon' => 'fas fa-heartbeat', 'title' => 'Surgery', 'text' => 'Safe, modern surgical suites with full monitoring.'],
                        ['icon' => 'fas fa-ambulance', 'title' => 'Emergency', 'text' => 'Urgent care when your pet needs it most.'],
                    ],
                ],
            ],
            'stats' => [
                'label' => 'Stats', 'icon' => 'fas fa-chart-simple',
                'fields' => [
                    ['key' => 'items', 'label' => 'Stats', 'type' => 'repeater',
                     'item' => [['key' => 'value', 'label' => 'Value', 'type' => 'text'],
                                ['key' => 'label', 'label' => 'Label', 'type' => 'text']]],
                ],
                'defaults' => [
                    'items' => [
                        ['value' => '15k+', 'label' => 'Happy patients'],
                        ['value' => '20+', 'label' => 'Years of care'],
                        ['value' => '24/7', 'label' => 'Emergency support'],
                        ['value' => '4.9', 'label' => 'Average rating'],
                    ],
                ],
            ],
            'team' => [
                'label' => 'Team', 'icon' => 'fas fa-user-doctor',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'subheading', 'label' => 'Subheading', 'type' => 'textarea'],
                    ['key' => 'items', 'label' => 'Members', 'type' => 'repeater',
                     'item' => [['key' => 'image', 'label' => 'Photo', 'type' => 'image'],
                                ['key' => 'name', 'label' => 'Name', 'type' => 'text'],
                                ['key' => 'role', 'label' => 'Role', 'type' => 'text']]],
                ],
                'defaults' => [
                    'heading' => 'Meet our veterinary team',
                    'subheading' => 'Caring, certified professionals dedicated to your pet’s wellbeing.',
                    'items' => [
                        ['name' => 'Dr. Sarah Hill', 'role' => 'Chief Veterinarian', 'image' => 'https://images.unsplash.com/photo-1594824476967-48c8b964273f?auto=format&fit=crop&w=500&q=80'],
                        ['name' => 'Dr. James Park', 'role' => 'Surgeon', 'image' => 'https://images.unsplash.com/photo-1612349317150-e413f6a5b16d?auto=format&fit=crop&w=500&q=80'],
                        ['name' => 'Dr. Lena Ortiz', 'role' => 'Internal Medicine', 'image' => 'https://images.unsplash.com/photo-1559839734-2b71ea197ec2?auto=format&fit=crop&w=500&q=80'],
                        ['name' => 'Dr. Omar Aziz', 'role' => 'Dentistry & Surgery', 'image' => 'https://images.unsplash.com/photo-1622253692010-333f2da6031d?auto=format&fit=crop&w=500&q=80'],
                    ],
                ],
            ],
            'gallery' => [
                'label' => 'Gallery', 'icon' => 'fas fa-images',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'items', 'label' => 'Images', 'type' => 'repeater',
                     'item' => [['key' => 'image', 'label' => 'Image', 'type' => 'image'],
                                ['key' => 'caption', 'label' => 'Caption', 'type' => 'text']]],
                ],
                'defaults' => ['heading' => 'Inside our clinic', 'items' => [
                    ['image' => 'https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=700&q=80', 'caption' => 'Friendly faces'],
                    ['image' => 'https://images.unsplash.com/photo-1450778869180-41d0601e046e?auto=format&fit=crop&w=700&q=80', 'caption' => 'Gentle handling'],
                    ['image' => 'https://images.unsplash.com/photo-1583337130417-3346a1be7dee?auto=format&fit=crop&w=700&q=80', 'caption' => 'Modern facilities'],
                    ['image' => 'https://images.unsplash.com/photo-1444212477490-ca407925329e?auto=format&fit=crop&w=700&q=80', 'caption' => 'Happy patients'],
                    ['image' => 'https://images.unsplash.com/photo-1535930891776-0c2dfb7fda1a?auto=format&fit=crop&w=700&q=80', 'caption' => 'Expert care'],
                    ['image' => 'https://images.unsplash.com/photo-1425082661705-1834bfd09dca?auto=format&fit=crop&w=700&q=80', 'caption' => 'Feline friends'],
                    ['image' => 'https://images.unsplash.com/photo-1606425271394-c3ca9ac8d4fb?auto=format&fit=crop&w=700&q=80', 'caption' => 'Comfortable wards'],
                    ['image' => 'https://images.unsplash.com/photo-1597633425046-08f5110420b5?auto=format&fit=crop&w=700&q=80', 'caption' => 'Surgical suite'],
                ]],
            ],
            'testimonials' => [
                'label' => 'Testimonials', 'icon' => 'fas fa-quote-left',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'items', 'label' => 'Testimonials', 'type' => 'repeater',
                     'item' => [['key' => 'quote', 'label' => 'Quote', 'type' => 'textarea'],
                                ['key' => 'name', 'label' => 'Name', 'type' => 'text'],
                                ['key' => 'meta', 'label' => 'Detail (pet / role)', 'type' => 'text']]],
                ],
                'defaults' => [
                    'heading' => 'Loved by pet parents',
                    'items' => [
                        ['quote' => 'They treated my dog like their own. Caring, professional and always available.', 'name' => 'Emily R.', 'meta' => 'Max’s mum'],
                        ['quote' => 'Modern facilities and the friendliest staff. Highly recommend!', 'name' => 'David K.', 'meta' => 'Luna’s dad'],
                    ],
                ],
            ],
            'faq' => [
                'label' => 'FAQ', 'icon' => 'fas fa-circle-question',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'items', 'label' => 'Questions', 'type' => 'repeater',
                     'item' => [['key' => 'q', 'label' => 'Question', 'type' => 'text'],
                                ['key' => 'a', 'label' => 'Answer', 'type' => 'textarea']]],
                ],
                'defaults' => [
                    'heading' => 'Frequently asked questions',
                    'items' => [
                        ['q' => 'Do you accept walk-ins?', 'a' => 'Yes — though we recommend booking ahead so we can prepare for your visit.'],
                        ['q' => 'Do you offer emergency care?', 'a' => 'We provide urgent care during clinic hours and can refer for overnight emergencies.'],
                    ],
                ],
            ],
            'hours' => [
                'label' => 'Opening Hours', 'icon' => 'fas fa-clock',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'items', 'label' => 'Rows', 'type' => 'repeater',
                     'item' => [['key' => 'day', 'label' => 'Day(s)', 'type' => 'text'],
                                ['key' => 'time', 'label' => 'Hours', 'type' => 'text']]],
                ],
                'defaults' => [
                    'heading' => 'Opening hours',
                    'items' => [
                        ['day' => 'Mon – Fri', 'time' => '8:00 AM – 7:00 PM'],
                        ['day' => 'Saturday', 'time' => '9:00 AM – 5:00 PM'],
                        ['day' => 'Sunday', 'time' => '10:00 AM – 2:00 PM'],
                    ],
                ],
            ],
            'products' => [
                'label' => 'Products / Shop', 'icon' => 'fas fa-bag-shopping',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'subheading', 'label' => 'Subheading', 'type' => 'textarea'],
                    ['key' => 'items', 'label' => 'Products', 'type' => 'repeater',
                     'item' => [['key' => 'image', 'label' => 'Image', 'type' => 'image'],
                                ['key' => 'name', 'label' => 'Name', 'type' => 'text'],
                                ['key' => 'price', 'label' => 'Price', 'type' => 'text'],
                                ['key' => 'old_price', 'label' => 'Old price', 'type' => 'text'],
                                ['key' => 'badge', 'label' => 'Badge (e.g. Sale)', 'type' => 'text']]],
                ],
                'defaults' => [
                    'heading' => 'Best sellers',
                    'subheading' => 'Quality food, toys and accessories for your best friend.',
                    'items' => [
                        ['image' => 'https://images.unsplash.com/photo-1589924691995-400dc9ecc119?auto=format&fit=crop&w=500&q=80', 'name' => 'Premium Dog Food 5kg', 'price' => '$39', 'old_price' => '$49', 'badge' => 'Sale'],
                        ['image' => 'https://images.unsplash.com/photo-1583511655826-05700d52f4d9?auto=format&fit=crop&w=500&q=80', 'name' => 'Chew Toy Bundle', 'price' => '$18', 'old_price' => '', 'badge' => 'New'],
                        ['image' => 'https://images.unsplash.com/photo-1601758228041-f3b2795255f1?auto=format&fit=crop&w=500&q=80', 'name' => 'Cozy Pet Bed', 'price' => '$54', 'old_price' => '', 'badge' => ''],
                        ['image' => 'https://images.unsplash.com/photo-1576201836106-db1758fd1c97?auto=format&fit=crop&w=500&q=80', 'name' => 'Grooming Kit', 'price' => '$29', 'old_price' => '$35', 'badge' => 'Sale'],
                    ],
                ],
            ],
            'pricing' => [
                'label' => 'Pricing / Packages', 'icon' => 'fas fa-tags',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'subheading', 'label' => 'Subheading', 'type' => 'textarea'],
                    ['key' => 'items', 'label' => 'Packages', 'type' => 'repeater',
                     'item' => [['key' => 'name', 'label' => 'Name', 'type' => 'text'],
                                ['key' => 'price', 'label' => 'Price', 'type' => 'text'],
                                ['key' => 'period', 'label' => 'Period (e.g. / visit)', 'type' => 'text'],
                                ['key' => 'features', 'label' => 'Features (one per line)', 'type' => 'textarea'],
                                ['key' => 'featured', 'label' => 'Highlight? (1/0)', 'type' => 'text']]],
                ],
                'defaults' => [
                    'heading' => 'Our packages',
                    'subheading' => 'Transparent pricing with no surprises.',
                    'items' => [
                        ['name' => 'Basic Wash', 'price' => '$29', 'period' => '/ visit', 'features' => "Bath & blow dry\nNail trim\nEar cleaning", 'featured' => '0'],
                        ['name' => 'Full Groom', 'price' => '$59', 'period' => '/ visit', 'features' => "Everything in Basic\nHaircut & styling\nTeeth brushing\nPerfume finish", 'featured' => '1'],
                        ['name' => 'Spa Deluxe', 'price' => '$89', 'period' => '/ visit', 'features' => "Everything in Full Groom\nDe-shedding treatment\nPaw & nose balm\nMassage", 'featured' => '0'],
                    ],
                ],
            ],
            'pets' => [
                'label' => 'Adoptable Pets', 'icon' => 'fas fa-dog',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'subheading', 'label' => 'Subheading', 'type' => 'textarea'],
                    ['key' => 'items', 'label' => 'Pets', 'type' => 'repeater',
                     'item' => [['key' => 'image', 'label' => 'Photo', 'type' => 'image'],
                                ['key' => 'name', 'label' => 'Name', 'type' => 'text'],
                                ['key' => 'breed', 'label' => 'Breed', 'type' => 'text'],
                                ['key' => 'age', 'label' => 'Age', 'type' => 'text'],
                                ['key' => 'gender', 'label' => 'Gender', 'type' => 'text']]],
                ],
                'defaults' => [
                    'heading' => 'Meet our adoptable friends',
                    'subheading' => 'Every one of them is looking for a loving forever home.',
                    'items' => [
                        ['image' => 'https://images.unsplash.com/photo-1543466835-00a7907e9de1?auto=format&fit=crop&w=500&q=80', 'name' => 'Buddy', 'breed' => 'Golden Retriever', 'age' => '2 years', 'gender' => 'Male'],
                        ['image' => 'https://images.unsplash.com/photo-1574158622682-e40e69881006?auto=format&fit=crop&w=500&q=80', 'name' => 'Mia', 'breed' => 'Tabby Cat', 'age' => '1 year', 'gender' => 'Female'],
                        ['image' => 'https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=500&q=80', 'name' => 'Rocky', 'breed' => 'Labrador Mix', 'age' => '3 years', 'gender' => 'Male'],
                        ['image' => 'https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=500&q=80', 'name' => 'Luna', 'breed' => 'Siberian Husky', 'age' => '8 months', 'gender' => 'Female'],
                    ],
                ],
            ],
            'cta' => [
                'label' => 'Call to action', 'icon' => 'fas fa-bullhorn',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'text', 'label' => 'Text', 'type' => 'textarea'],
                    ['key' => 'button_label', 'label' => 'Button text', 'type' => 'text'],
                    ['key' => 'button_url', 'label' => 'Button link', 'type' => 'url'],
                ],
                'defaults' => [
                    'heading' => 'Ready to give your pet the best care?',
                    'text' => 'Book an appointment today — our team can’t wait to meet you.',
                    'button_label' => 'Book now', 'button_url' => '#contact',
                ],
            ],
            'contact' => [
                'label' => 'Contact', 'icon' => 'fas fa-envelope',
                'fields' => [
                    ['key' => 'heading', 'label' => 'Heading', 'type' => 'text'],
                    ['key' => 'subheading', 'label' => 'Subheading', 'type' => 'textarea'],
                    ['key' => 'map_embed', 'label' => 'Google Maps embed URL', 'type' => 'url'],
                    ['key' => 'show_form', 'label' => 'Show contact form (1/0)', 'type' => 'text'],
                ],
                'defaults' => [
                    'heading' => 'Get in touch',
                    'subheading' => 'Questions, bookings or emergencies — we’re here to help.',
                    'show_form' => '1',
                ],
            ],
            'html' => [
                'label' => 'Custom HTML', 'icon' => 'fas fa-code',
                'fields' => [
                    ['key' => 'html', 'label' => 'HTML', 'type' => 'richtext'],
                ],
                'defaults' => ['html' => '<p>Custom content…</p>'],
            ],
        ];
    }

    public static function exists(string $type): bool
    {
        return array_key_exists($type, static::all());
    }

    public static function get(string $type): ?array
    {
        return static::all()[$type] ?? null;
    }

    public static function defaults(string $type): array
    {
        return static::all()[$type]['defaults'] ?? [];
    }
}
