<?php

namespace App\Http\Controllers;

use App\Models\Event;
use App\Models\Impact;
use App\Models\Post;
use App\Models\Slider;
use App\Models\PageContent;
use Illuminate\Http\Request;

class PageController extends Controller
{
    public function home()
    {
        $latestPosts = Post::latest()->limit(3)->get();
        $upcomingEvents = Event::where('event_date', '>=', now()->toDateString())
            ->orderBy('event_date', 'asc')
            ->limit(3)
            ->get();
        $impacts = Impact::orderBy('order')->get();
        $sliders = Slider::where('is_active', true)->orderBy('order')->get();
            
        return view('pages.home', compact('latestPosts', 'upcomingEvents', 'impacts', 'sliders'));
    }

    public function about()
    {
        $contents = PageContent::where('page_slug', 'about')->get()->keyBy('section_name');
        return view('pages.about', compact('contents'));
    }

    public function join()
    {
        $contents = PageContent::where('page_slug', 'join')->get()->keyBy('section_name');
        return view('pages.join', compact('contents'));
    }

    public function sponsors()
    {
        $contents = PageContent::where('page_slug', 'sponsors')->get()->keyBy('section_name');
        return view('pages.sponsors', compact('contents'));
    }

    public function blog()
    {
        return view('pages.blog');
    }

    public function events()
    {
        return view('pages.events');
    }
}
