<?php

namespace App\Http\Livewire\Pages\SendPatch;

use App\Models\ConfServerLicense;
use App\Models\ConfServerPendding;
use App\Models\ConfSmartupdate;
use Livewire\Component;
use Livewire\WithPagination;

class DeleteMultiPatch extends Component
{

    public $serverkey = '', $companyName, $showSearch, $searchInProgress, $results, $selectedPatches = [];

    public function selectResult($key)
    {
        $this->serverkey = $key;
        $this->results = [];
        $this->showSearch = false;

        $serverLicense =  ConfServerLicense::where('SNKEY', $this->serverkey)->first();
        if (isset($serverLicense)) {
            $this->companyName = $serverLicense->COMPANY;
        }
        $this->emit('updateServerkey', $key);
    }
    public function updatedServerkey()
    {
        $this->showSearch = true;
        if ($this->searchInProgress) {
            $this->reset('results');
        }

        $this->searchInProgress = true;
        $this->results = ConfServerLicense::where('SNKEY', 'LIKE', '%' . $this->serverkey . '%')->take(50)->get();

        $this->searchInProgress = false;
    }
    public function render()
    {
        return view('livewire.pages.send-patch.delete-multi-patch', [
            'selectedPatches' => ConfSmartUpdate::whereIn('PID', $this->selectedPatches)->get()
        ]);
    }
}
