<?php

namespace App\Http\Controllers;

use App\Models\Resource;
use App\Models\StandardsReference;
use App\Models\SiteSetting;

class ResourcePageController extends Controller
{
    private function settings(): array
    {
        return SiteSetting::pluck('value', 'key')->toArray();
    }

    public function index()
    {
        $brochures  = Resource::with('category')
            ->where('is_active', 1)
            ->where('resource_type', 'pdf')
            ->orderBy('sort_order')
            ->get();

        $videos     = Resource::with('category')
            ->where('is_active', 1)
            ->where('resource_type', 'video')
            ->orderBy('sort_order')
            ->get();

        $articles   = Resource::with('category')
            ->where('is_active', 1)
            ->where('resource_type', 'article')
            ->orderBy('sort_order')
            ->get();

        $standards  = Resource::with('category')
            ->where('is_active', 1)
            ->where('resource_type', 'link')
            ->orderBy('sort_order')
            ->get();

        $settings   = $this->settings();

        return view('pages.resources', compact(
            'brochures', 'videos', 'articles', 'standards', 'settings'
        ));
    }
}
