<?php

namespace App\Http\Controllers\Public;

use App\Http\Controllers\Controller;
use App\Models\Company;
use App\Support\Tenant;
use Illuminate\View\View;

class CompanyPageController extends Controller
{
    public function show(string $slug): View
    {
        $company = Company::where('slug', $slug)
            ->where('status', '!=', 'cancelled')
            ->firstOrFail();

        Tenant::set($company);

        $services  = $company->services()->public()->with('category')->orderBy('sort_order')->get();
        $employees = $company->employees()->bookable()->orderBy('sort_order')->get();
        $gallery   = $company->galleryItems()
            ->where('is_public', true)
            ->orderBy('sort_order')
            ->latest()
            ->limit(8)
            ->get();
        $featuredPromotions = $company->promotions()
            ->active()
            ->where('is_featured', true)
            ->latest()
            ->limit(3)
            ->get();

        return view('public.company', compact('company', 'services', 'employees', 'gallery', 'featuredPromotions'));
    }
}
