@extends('admin.layouts.app')

@section('title', 'Statistics')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h1 class="h3">Statistics</h1>
                <a href="{{ route('admin.statistics.create') }}" class="btn btn-primary">
                    <i class="bi bi-plus"></i> Add New Statistic
                </a>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    @if($statistics->count() > 0)
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Icon</th>
                                        <th>Title</th>
                                        <th>Value</th>
                                        <th>Suffix</th>
                                        <th>Status</th>
                                        <th>Sort Order</th>
                                        <th>Last Updated</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($statistics as $statistic)
                                        <tr>
                                            <td>
                                                @if($statistic->icon)
                                                    <i class="{{ $statistic->icon }} fs-4 text-primary"></i>
                                                @else
                                                    <i class="bi bi-graph-up fs-4 text-muted"></i>
                                                @endif
                                            </td>
                                            <td>
                                                <strong>{{ $statistic->title }}</strong>
                                            </td>
                                            <td>
                                                <span class="badge bg-primary fs-6">{{ number_format($statistic->value) }}</span>
                                            </td>
                                            <td>
                                                @if($statistic->suffix)
                                                    <small class="text-muted">{{ $statistic->suffix }}</small>
                                                @else
                                                    <small class="text-muted">-</small>
                                                @endif
                                            </td>
                                            <td>
                                                @if($statistic->is_active)
                                                    <span class="badge bg-success">Active</span>
                                                @else
                                                    <span class="badge bg-secondary">Inactive</span>
                                                @endif
                                            </td>
                                            <td>
                                                <span class="badge bg-light text-dark">{{ $statistic->sort_order }}</span>
                                            </td>
                                            <td>
                                                <small>{{ $statistic->updated_at->format('M d, Y') }}</small>
                                            </td>
                                            <td>
                                                <div class="btn-group btn-group-sm" role="group">
                                                    <a href="{{ route('admin.statistics.show', $statistic) }}" 
                                                       class="btn btn-outline-primary" title="View">
                                                        <i class="bi bi-eye"></i>
                                                    </a>
                                                    <a href="{{ route('admin.statistics.edit', $statistic) }}" 
                                                       class="btn btn-outline-secondary" title="Edit">
                                                        <i class="bi bi-pencil"></i>
                                                    </a>
                                                    <form action="{{ route('admin.statistics.destroy', $statistic) }}" 
                                                          method="POST" class="d-inline" 
                                                          onsubmit="return confirm('Are you sure you want to delete this statistic?')">
                                                        @csrf
                                                        @method('DELETE')
                                                        <button type="submit" class="btn btn-outline-danger" title="Delete">
                                                            <i class="bi bi-trash"></i>
                                                        </button>
                                                    </form>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>

                        <!-- Pagination -->
                        @if($statistics->hasPages())
                            <div class="d-flex justify-content-center mt-4">
                                {{ $statistics->links() }}
                            </div>
                        @endif
                    @else
                        <div class="text-center py-5">
                            <i class="bi bi-graph-up text-muted" style="font-size: 4rem;"></i>
                            <h4 class="text-muted mt-3">No Statistics Found</h4>
                            <p class="text-muted">Start by creating your first statistic to showcase your achievements.</p>
                            <a href="{{ route('admin.statistics.create') }}" class="btn btn-primary mt-3">
                                <i class="bi bi-plus"></i> Create First Statistic
                            </a>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>

    @if($statistics->where('is_active', true)->count() > 0)
        <div class="row mt-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">Preview - Active Statistics</h5>
                    </div>
                    <div class="card-body">
                        <div class="row text-center">
                            @foreach($statistics->where('is_active', true)->sortBy('sort_order') as $statistic)
                                <div class="col-md-3 mb-3">
                                    <div class="border rounded p-3">
                                        @if($statistic->icon)
                                            <i class="{{ $statistic->icon }} fs-1 text-primary mb-2"></i>
                                        @endif
                                        <h3 class="text-primary mb-1">{{ number_format($statistic->value) }}{{ $statistic->suffix }}</h3>
                                        <p class="text-muted mb-0">{{ $statistic->title }}</p>
                                    </div>
                                </div>
                            @endforeach
                        </div>
                        <small class="text-muted">
                            <i class="bi bi-info-circle"></i> This is how the statistics will appear on your website
                        </small>
                    </div>
                </div>
            </div>
        </div>
    @endif
</div>
@endsection