<?php

namespace App\Providers;

use App\Models\Navigation;
use App\Models\Setting;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class ViewServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        //
    }

    public function boot(): void
    {
        View::composer('*', function ($view) {
            $view->with('siteSettings', $this->getSiteSettings());
        });

        View::composer('layouts.app', function ($view) {
            $view->with('headerNavigation', Navigation::getHeaderMenu());
            $view->with('footerNavigation', Navigation::getFooterMenu());
        });
    }

    protected function getSiteSettings(): object
    {
        $settings = Setting::all()->pluck('value', 'key')->toArray();
        
        return (object) [
            // General
            'site_name' => $settings['site_name'] ?? 'TEFLIN 2026',
            'site_tagline' => $settings['site_tagline'] ?? '',
            'site_description' => $settings['site_description'] ?? '',
            'logo' => $settings['logo'] ?? '',
            'favicon' => $settings['favicon'] ?? '',
            
            // Conference
            'conference_title' => $settings['conference_title'] ?? '72nd TEFLIN International Conference',
            'conference_theme' => $settings['conference_theme'] ?? 'Transforming Language Education: Innovation, Inclusion, and Connection for a Sustainable Future',
            'conference_date' => $settings['conference_date'] ?? '2026-10-07',
            'conference_end_date' => $settings['conference_end_date'] ?? '2026-10-09',
            'conference_location' => $settings['conference_location'] ?? 'Jakarta, Indonesia',
            'conference_venue' => $settings['conference_venue'] ?? 'UIN Syarif Hidayatullah Jakarta',
            'registration_open' => ($settings['registration_open'] ?? 'true') === 'true',
            'full_paper_submission_open' => ($settings['full_paper_submission_open'] ?? 'false') === 'true',
            'abstract_deadline' => $settings['abstract_deadline'] ?? '2026-05-31',
            
            // Hero
            'hero_badge_text' => $settings['hero_badge_text'] ?? 'Registration Now Open',
            'hero_badge_color' => $settings['hero_badge_color'] ?? 'green',
            'hero_title' => $settings['hero_title'] ?? '',
            'hero_subtitle' => $settings['hero_subtitle'] ?? '',
            'hero_cta_primary_text' => $settings['hero_cta_primary_text'] ?? 'Submit Abstract',
            'hero_cta_primary_url' => $settings['hero_cta_primary_url'] ?? '',
            'hero_cta_secondary_text' => $settings['hero_cta_secondary_text'] ?? 'Register Now',
            'hero_cta_secondary_url' => $settings['hero_cta_secondary_url'] ?? '',
            
            // Contact
            'contact_email' => $settings['contact_email'] ?? 'info@teflin.org',
            'contact_phone' => $settings['contact_phone'] ?? '',
            'contact_whatsapp' => $settings['contact_whatsapp'] ?? '',
            'contact_address' => $settings['contact_address'] ?? '',
            
            // Social
            'facebook_url' => $settings['facebook_url'] ?? '',
            'twitter_url' => $settings['twitter_url'] ?? '',
            'instagram_url' => $settings['instagram_url'] ?? '',
            'youtube_url' => $settings['youtube_url'] ?? '',
            'linkedin_url' => $settings['linkedin_url'] ?? '',
            
            // Footer
            'footer_about' => $settings['footer_about'] ?? '',
            'footer_copyright' => $settings['footer_copyright'] ?? '© ' . date('Y') . ' TEFLIN. All rights reserved.',
        ];
    }
}
