<?php

namespace App\Livewire\Admin;

use App\Models\ImportBatch;
use Livewire\Component;
use Livewire\WithPagination;

class PreClaim extends Component
{
    use WithPagination;

    public string $searchBatches = '';

    public function updatedSearchBatches(): void
    {
        $this->resetPage('batchesPage');
    }

    public function render()
    {
        $batchesQuery = ImportBatch::query()->latest('id');

        if (trim($this->searchBatches) !== '') {
            $s = '%' . trim($this->searchBatches) . '%';
            $batchesQuery->where(function ($q) use ($s) {
                $q->where('file_type', 'like', $s)
                    ->orWhere('file_path', 'like', $s);
            });
        }

        $batches = $batchesQuery->paginate(15, ['*'], 'batchesPage');
        $batches->withPath(route('admin.preclaim'));

        return view('livewire.admin.pre-claim', compact('batches'));
    }
}
