<?php

namespace App\Http\Controllers\Public;

use App\Http\Controllers\Controller;
use App\Models\Contact;
use App\Models\Gallery;
use App\Models\Post;
use App\Models\Potential;
use App\Models\Statistic;
use App\Models\VillageProfile;

class HomeController extends Controller
{
    public function index()
    {
        $profile   = VillageProfile::current();
        if (!$profile->foto_utama || str_contains($profile->foto_utama, 'unsplash')) {
            $profile->update(['foto_utama' => 'images/kantor desa.jpeg']);
        }
        $statistic = Statistic::current();
        $contact   = Contact::current();
        $potentials = Potential::latest()->limit(4)->get();
        $latestPosts = Post::berita()->latest()->limit(3)->get();
        $galleries  = Gallery::latest()->limit(8)->get();

        return view('public.home', compact(
            'profile', 'statistic', 'contact', 'potentials', 'latestPosts', 'galleries'
        ));
    }
}
