@extends('admin.layouts.app')

@section('title', 'مدیریت نسخه‌های اپلیکیشن')

@section('content')
<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="mb-0">نسخه‌های اپلیکیشن</h5>
        <a href="{{ route('admin.app-versions.create') }}" class="btn btn-primary">
            <i class="fas fa-plus me-2"></i>
            افزودن نسخه جدید
        </a>
    </div>

    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover align-middle">
                <thead>
                    <tr>
                        <th>کد</th>
                        <th>پلتفرم</th>
                        <th>نسخه</th>
                        <th>بیلد</th>
                        <th>حداقل نسخه</th>
                        <th>وضعیت</th>
                        <th>آپدیت اجباری</th>
                        <th>عملیات</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($versions as $version)
                        <tr>
                            <td>#{{ $version->id }}</td>
                            <td>
                                @if($version->app_type === 'android')
                                    <span class="badge bg-success"><i class="fab fa-android me-1"></i>اندروید</span>
                                @else
                                    <span class="badge bg-primary"><i class="fas fa-globe me-1"></i>PWA</span>
                                @endif
                            </td>
                            <td class="font-monospace">{{ $version->version }}</td>
                            <td class="font-monospace">{{ $version->build_number }}</td>
                            <td class="font-monospace">{{ $version->min_version }}</td>
                            <td>
                                @if($version->is_active)
                                    <span class="badge bg-success">فعال</span>
                                @else
                                    <span class="badge bg-secondary">غیرفعال</span>
                                @endif
                            </td>
                            <td>
                                @if($version->force_update)
                                    <span class="badge bg-danger">بله</span>
                                @else
                                    <span class="badge bg-info">خیر</span>
                                @endif
                            </td>
                            <td>
                                <div class="btn-group btn-group-sm">
                                    <a href="{{ route('admin.app-versions.edit', $version->id) }}" class="btn btn-outline-primary" title="ویرایش">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <form action="{{ route('admin.app-versions.set-active', $version->id) }}" method="POST" class="d-inline">
                                        @csrf
                                        <button type="submit" class="btn btn-outline-success" title="فعال‌سازی">
                                            <i class="fas fa-check"></i>
                                        </button>
                                    </form>
                                    <form action="{{ route('admin.app-versions.destroy', $version->id) }}" method="POST" class="d-inline" onsubmit="return confirm('حذف شود؟')">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-outline-danger" title="حذف">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="8" class="text-center text-muted py-4">نسخه‌ای ثبت نشده است</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <div class="d-flex justify-content-center mt-3">
            {{ $versions->links() }}
        </div>
    </div>
</div>

<div class="row mt-4">
    <div class="col-md-4">
        <div class="card bg-success text-white">
            <div class="card-body text-center">
                <h3 class="mb-0">{{ $stats['android_active'] ?? 0 }}</h3>
                <small>نسخه فعال اندروید</small>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card bg-primary text-white">
            <div class="card-body text-center">
                <h3 class="mb-0">{{ $stats['pwa_active'] ?? 0 }}</h3>
                <small>نسخه فعال PWA</small>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card bg-warning text-white">
            <div class="card-body text-center">
                <h3 class="mb-0">{{ $stats['force_updates'] ?? 0 }}</h3>
                <small>آپدیت اجباری</small>
            </div>
        </div>
    </div>
</div>
@endsection
