<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use App\Models\ConsultationSlot;
use App\Models\Service;
use App\Models\ServiceCategory;
use App\Models\SiteSetting;
use App\Models\Testimonial;

class HomeController extends Controller
{
    public function index()
    {
        $services = Service::with(['category', 'packages'])
            ->where('is_active', true)
            ->orderBy('sort_order')
            ->get();

        $pakServices  = $services->filter(fn($s) => $s->category?->slug === 'pakistan');
        $intlServices = $services->filter(fn($s) => $s->category?->slug === 'international');

        $testimonials = Testimonial::where('is_active', true)
            ->orderBy('sort_order')
            ->take(4)
            ->get();

        $consultationSlots = ConsultationSlot::where('is_active', true)
            ->orderBy('sort_order')
            ->get();

        $template = SiteSetting::getValue('homepage_template', 'default');
        $view = ($template === 'premium') ? 'frontend.home-premium' : 'frontend.home';

        return view($view, compact('services', 'pakServices', 'intlServices', 'testimonials', 'consultationSlots'));
    }

    public function about()
    {
        return view('frontend.about');
    }

    public function contact()
    {
        return view('frontend.contact');
    }

    public function sendContact()
    {
        // TODO: send email
        return back()->with('success', 'Thank you! We\'ll get back to you within 24 hours.');
    }
}
