<?php

namespace App\Http\Controllers;

use App\Models\CaseStudy;
use App\Models\SiteSetting;

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

    public function index()
    {
        $caseStudies = CaseStudy::where('is_active', 1)->orderBy('sort_order')->get();
        $categories  = $caseStudies->pluck('category')->filter()->unique()->values();
        $settings    = $this->settings();

        return view('pages.case-studies', compact('caseStudies', 'categories', 'settings'));
    }

    public function show(string $slug)
    {
        $caseStudy = CaseStudy::where('slug', $slug)
            ->where('is_active', 1)
            ->firstOrFail();

        $settings = $this->settings();

        return view('pages.case-study-detail', compact('caseStudy', 'settings'));
    }
}
