@extends('admin.layouts.app')
@section('title', 'Video Plugins')
@section('content')
<div class="action-bar">
    <span>{{ $plugins->count() }} video plugin(s)</span>
</div>

@if(session('success'))
    <div class="alert alert-success">{{ session('success') }}</div>
@endif
@if(session('error'))
    <div class="alert alert-error">{{ session('error') }}</div>
@endif

<div class="card">
    <table>
        <tr>
            <th>Plugin</th>
            <th>Version</th>
            <th>Status</th>
            <th>Configured</th>
            <th>Actions</th>
        </tr>
        @forelse($plugins as $plugin)
        @php $resolved = $plugin->resolvePlugin(); @endphp
        <tr>
            <td>
                <strong>{{ $plugin->name }}</strong>
                @if($plugin->author)<br><small class="text-muted">by {{ $plugin->author }}</small>@endif
                @if($plugin->description)<br><small class="text-muted">{{ $plugin->description }}</small>@endif
            </td>
            <td>v{{ $plugin->version }}</td>
            <td>
                @if($plugin->is_installed && $plugin->is_active)
                    <span style="color:#6fcf97">Active</span>
                @elseif($plugin->is_installed)
                    <span style="color:#f0c040">Inactive</span>
                @else
                    <span style="color:#e74c3c">Not Installed</span>
                @endif
            </td>
            <td>
                @if($resolved && $resolved->isConfigured($plugin))
                    <span style="color:#6fcf97">&#10003;</span>
                @else
                    <span style="color:#e74c3c">&#10007;</span>
                @endif
            </td>
            <td class="inline-flex">
                @if($plugin->is_installed)
                    <a href="{{ route('admin.video-plugins.edit', $plugin) }}" class="btn btn-primary btn-sm">Configure</a>
                    <a href="{{ route('admin.video-plugins.toggle', $plugin) }}" class="btn btn-sm {{ $plugin->is_active ? 'btn-dark' : 'btn-primary' }}"
                       onclick="return confirm('{{ $plugin->is_active ? 'Deactivate' : 'Activate' }} this plugin?')">
                        {{ $plugin->is_active ? 'Deactivate' : 'Activate' }}
                    </a>
                    <a href="{{ route('admin.video-plugins.uninstall', $plugin->code) }}" class="btn btn-danger btn-sm"
                       onclick="return confirm('Uninstall this plugin?')">Uninstall</a>
                @else
                    <a href="{{ route('admin.video-plugins.install', $plugin->code) }}" class="btn btn-primary btn-sm">Install</a>
                @endif
            </td>
        </tr>
        @empty
        <tr>
            <td colspan="5">
                <div class="empty-state">
                    <p>No video plugins installed.</p>
                    <p style="font-size:0.85rem;color:var(--text-muted);margin-top:8px;">
                        Available plugins: YouTube Video, Vimeo Video, HTML5 Video Player
                    </p>
                    <div style="margin-top:15px;display:flex;gap:10px;justify-content:center;flex-wrap:wrap">
                        <a href="{{ route('admin.video-plugins.install', 'youtube') }}" class="btn btn-primary btn-sm">Install YouTube</a>
                        <a href="{{ route('admin.video-plugins.install', 'vimeo') }}" class="btn btn-primary btn-sm">Install Vimeo</a>
                        <a href="{{ route('admin.video-plugins.install', 'video_player') }}" class="btn btn-primary btn-sm">Install Video Player</a>
                    </div>
                </div>
            </td>
        </tr>
        @endforelse
    </table>
</div>
@endsection
