<div>
    <div class="w-full flex items-center justify-between">
        <a href="{{ route('license_tokens.show', $licenseToken) }}"
            class="flex rounded-lg bg-white border border-gray-200 px-4 py-2 text-gray-700 hover:bg-gray-100 font-bold">
            <img src="{{ asset('vendor/blade-untitledui-icons/arrow-narrow-left.svg') }}" alt="Volver" class="w-6 h-6">
            <span class="ml-2">Volver</span>
        </a>
    </div>

    <div class="w-full flex flex-wrap items-center justify-between mt-8 rounded-lg bg-white border border-gray-200 px-8 py-4">
        <div class="w-full flex items-center justify-center flex-col">
            <h1 class="text-4xl font-bold">Gestionar entornos</h1>
            <p class="text-gray-500 text-sm">
                Selecciona los entornos que deseas vincular a este token de licencia.
            </p>
        </div>

        <div class="w-full flex items-end justify-between mt-8">
            <div class="font-bold text-lg">
                Listado de entornos
            </div>
            <div class="w-1/3">
                <input type="text" wire:model.live.debounce.300ms="search" class="w-full rounded-lg border border-gray-200 px-4 py-2" placeholder="Buscar entorno">
            </div>
        </div>

        <div class="w-full mt-4">
            @forelse($environments as $environment)
                <div class="w-full flex items-center justify-between py-3 px-2 rounded-lg transition-colors hover:bg-gray-50 border-b border-gray-100">
                    <div class="flex items-center justify-start flex-1">
                        <input type="checkbox"
                            wire:model="selectedEnvironments"
                            value="{{ $environment->id }}"
                            class="w-4 h-4 text-orange-600 border-gray-300 rounded focus:ring-orange-500 mr-3 cursor-pointer">
                        <div class="flex items-center justify-start mr-2 border border-gray-200 rounded-lg p-1">
                            <img src="{{ $environment->type->image_url ?? asset('images/placeholder.png') }}"
                                alt="{{ $environment->type->name ?? 'Environment' }}" class="w-10 h-10 rounded-full">
                        </div>
                        <div class="flex flex-col">
                            <div class="font-bold">{{ $environment->name }}</div>
                            <div class="text-sm text-gray-500">{{ $environment->domain }}</div>
                            @if($environment->client)
                                <div class="text-xs text-gray-400">{{ $environment->client->name }}</div>
                            @endif
                        </div>
                    </div>
                    <div class="flex items-center justify-end">
                        @if($environment->licenseToken && $environment->licenseToken->id !== $licenseToken->id)
                            <span class="text-xs text-gray-500 bg-gray-200 px-2 py-1 rounded">Vinculado a otro token</span>
                        @endif
                    </div>
                </div>
            @empty
                <div class="w-full text-center py-8 text-gray-500">
                    No se encontraron entornos.
                </div>
            @endforelse
        </div>

        <div class="w-full flex items-center justify-end mt-8">
            <a href="{{ route('license_tokens.show', $licenseToken) }}" class="bg-white hover:bg-gray-100 px-4 py-2">Cancelar</a>
            <button wire:click="save" class="bg-3ip hover:bg-3ip-light text-white px-4 py-2 rounded-lg ml-4">Guardar cambios</button>
        </div>
    </div>
</div>

