<?php

namespace App\Livewire\LicenseTokens;

use App\Models\Products\LicenseToken;
use Livewire\Component;
use Livewire\WithPagination;

class Index extends Component
{
    use WithPagination;

    public string $search = '';

    protected $queryString = ['search'];

    public function updatingSearch()
    {
        $this->resetPage();
    }

    public function updatedSearch()
    {
        $this->dispatch('search-updated', search: $this->search);
    }

    public function delete($id)
    {
        $this->authorize('admin.license-tokens.destroy');
        
        $token = LicenseToken::findOrFail($id);
        $token->delete();

        session()->flash('success', 'Token eliminado correctamente.');
    }

    public function render()
    {
        return view('livewire.license-tokens.index')->layout('layouts.app');
    }
}

