<?php

namespace App\Livewire\Store;

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

#[Layout('layouts.store')]
#[Title('Mitra Kami')]
class Partners extends Component
{
    public string $search = '';

    public function render()
    {
        $partners = Partner::where('is_active', true)
            ->when($this->search, fn ($q) =>
                $q->where('name', 'like', "%{$this->search}%"))
            ->withCount(['products' => fn ($q) => $q->where('is_active', true)])
            ->orderBy('name')
            ->get();

        return view('livewire.store.partners', compact('partners'));
    }
}
