<?php

namespace App\Livewire\Store;

use App\Models\Partner;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Component;
use Livewire\WithPagination;

#[Layout('layouts.store')]
#[Title('Profil Mitra')]
class PartnerShow extends Component
{
    use WithPagination;

    public Partner $partner;

    public function mount(int $id): void
    {
        $this->partner = Partner::where('is_active', true)->findOrFail($id);
    }

    public function render()
    {
        $products = $this->partner->activeProducts()
            ->with('category')
            ->orderByRaw('CASE WHEN sort_order = 0 THEN 1 ELSE 0 END')
            ->orderBy('sort_order')
            ->orderByDesc('created_at')
            ->paginate(12);

        return view('livewire.store.partner-show', compact('products'));
    }
}
