<?php

namespace App\Http\Controllers;

use App\Models\About;
use App\Models\ClientUpload;
use App\Models\Branch;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class AboutController extends Controller
{
    public function index()
    {
        $cacheTime = 60 * 24;

        $abouts = Cache::remember('about_page_content', $cacheTime, function () {
            return About::where('is_active', true)->get();
        });

        $clients = Cache::remember('about_page_clients', $cacheTime, function () {
            return ClientUpload::latest()->get();
        });
        
        $branches = Cache::remember('about_page_branches', $cacheTime, function () {
            return Branch::orderBy('name', 'asc')->get();
        });

        $chunkedBranches = array_chunk($branches->toArray(), 8);

        return view('about.index', compact('abouts', 'clients', 'chunkedBranches'));
    }
}