<?php

namespace App\Http\Livewire\Pages\SendPatch;

use Livewire\Component;

class DeleteMultiPatchBox extends Component
{

    protected $listeners = ['updateSelectedPatches'];

    public $selectedPatches = [];
    public $selectedPatchName = [];
    public $serverkey = '', $showSearch = false, $searchInProgress, $reponseMessages = [];
    public $showProgressModal = false;
    public $results = [];
    
    public function mount($selectedPatches)
    {
        $this->selectedPatches = $selectedPatches;
    }
    public function updateSelectedPatches($patchId, $allSelectPatchName)
    {
        if (is_array($patchId)) {
            $this->selectedPatches = $patchId;
            $this->selectedPatchName = $allSelectPatchName;
        } else {
            if (in_array($patchId, $this->selectedPatches)) {
                $key = array_search($patchId, $this->selectedPatches);
                if ($key !== false) {
                    unset($this->selectedPatches[$key]);
                    unset($this->allSelectPatchName[$key]);
                }
            } else {
                $this->selectedPatches[] = $patchId;
                $this->selectedPatchName[] = $allSelectPatchName;
            }
        }
    }
    public function render()
    {
        return view('livewire.pages.send-patch.delete-multi-patch-box');
    }
}
