@extends('admin.layouts.app')

@section('title', 'View Statistic')

@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">Statistic: {{ $statistic->title }}</h1>
                <div class="btn-group">
                    <a href="{{ route('admin.statistics.edit', $statistic) }}" class="btn btn-primary">
                        <i class="bi bi-pencil"></i> Edit
                    </a>
                    <a href="{{ route('admin.statistics.index') }}" class="btn btn-secondary">
                        <i class="bi bi-arrow-left"></i> Back to List
                    </a>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-8">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">Statistic Details</h5>
                    <div>
                        @if($statistic->is_active)
                            <span class="badge bg-success">Active</span>
                        @else
                            <span class="badge bg-secondary">Inactive</span>
                        @endif
                    </div>
                </div>
                <div class="card-body">
                    <dl class="row">
                        <dt class="col-sm-3">Title:</dt>
                        <dd class="col-sm-9">{{ $statistic->title }}</dd>

                        <dt class="col-sm-3">Value:</dt>
                        <dd class="col-sm-9">
                            <span class="badge bg-primary fs-6">{{ number_format($statistic->value) }}</span>
                        </dd>

                        <dt class="col-sm-3">Suffix:</dt>
                        <dd class="col-sm-9">
                            @if($statistic->suffix)
                                <code>{{ $statistic->suffix }}</code>
                            @else
                                <em class="text-muted">No suffix</em>
                            @endif
                        </dd>

                        <dt class="col-sm-3">Icon:</dt>
                        <dd class="col-sm-9">
                            @if($statistic->icon)
                                <i class="{{ $statistic->icon }} fs-4 text-primary me-2"></i>
                                <code>{{ $statistic->icon }}</code>
                            @else
                                <em class="text-muted">No icon specified</em>
                            @endif
                        </dd>

                        <dt class="col-sm-3">Sort Order:</dt>
                        <dd class="col-sm-9">
                            <span class="badge bg-light text-dark">{{ $statistic->sort_order }}</span>
                        </dd>

                        <dt class="col-sm-3">Formatted Display:</dt>
                        <dd class="col-sm-9">
                            <strong>{{ $statistic->formatted_value }}</strong>
                            <small class="text-muted">(This is how it appears with formatting)</small>
                        </dd>

                        <dt class="col-sm-3">Created:</dt>
                        <dd class="col-sm-9">{{ $statistic->created_at->format('F d, Y \a\t H:i') }}</dd>

                        <dt class="col-sm-3">Last Updated:</dt>
                        <dd class="col-sm-9">{{ $statistic->updated_at->format('F d, Y \a\t H:i') }}</dd>
                    </dl>
                </div>
            </div>

            <div class="card mt-4">
                <div class="card-header">
                    <h5 class="mb-0">Website Preview</h5>
                </div>
                <div class="card-body">
                    <div class="text-center border rounded p-5" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
                        @if($statistic->icon)
                            <i class="{{ $statistic->icon }} mb-3" style="font-size: 3rem;"></i>
                        @endif
                        <h2 class="mb-2">{{ number_format($statistic->value) }}{{ $statistic->suffix }}</h2>
                        <p class="mb-0 opacity-75">{{ $statistic->title }}</p>
                    </div>
                    <small class="text-muted mt-2 d-block">
                        <i class="bi bi-info-circle"></i> This is how the statistic will appear on your website
                    </small>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Quick Actions</h5>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-2">
                        <a href="{{ route('admin.statistics.edit', $statistic) }}" class="btn btn-primary">
                            <i class="bi bi-pencil"></i> Edit Statistic
                        </a>
                        
                        @if($statistic->is_active)
                            <form action="{{ route('admin.statistics.update', $statistic) }}" method="POST">
                                @csrf
                                @method('PUT')
                                <input type="hidden" name="title" value="{{ $statistic->title }}">
                                <input type="hidden" name="value" value="{{ $statistic->value }}">
                                <input type="hidden" name="suffix" value="{{ $statistic->suffix }}">
                                <input type="hidden" name="icon" value="{{ $statistic->icon }}">
                                <input type="hidden" name="sort_order" value="{{ $statistic->sort_order }}">
                                <input type="hidden" name="is_active" value="0">
                                <button type="submit" class="btn btn-warning w-100">
                                    <i class="bi bi-pause-circle"></i> Deactivate
                                </button>
                            </form>
                        @else
                            <form action="{{ route('admin.statistics.update', $statistic) }}" method="POST">
                                @csrf
                                @method('PUT')
                                <input type="hidden" name="title" value="{{ $statistic->title }}">
                                <input type="hidden" name="value" value="{{ $statistic->value }}">
                                <input type="hidden" name="suffix" value="{{ $statistic->suffix }}">
                                <input type="hidden" name="icon" value="{{ $statistic->icon }}">
                                <input type="hidden" name="sort_order" value="{{ $statistic->sort_order }}">
                                <input type="hidden" name="is_active" value="1">
                                <button type="submit" class="btn btn-success w-100">
                                    <i class="bi bi-play-circle"></i> Activate
                                </button>
                            </form>
                        @endif

                        <form action="{{ route('admin.statistics.destroy', $statistic) }}" 
                              method="POST" 
                              onsubmit="return confirm('Are you sure you want to delete this statistic? This action cannot be undone.')">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-danger w-100">
                                <i class="bi bi-trash"></i> Delete Statistic
                            </button>
                        </form>
                    </div>
                </div>
            </div>

            <div class="card mt-3">
                <div class="card-header">
                    <h5 class="mb-0">Alternative Previews</h5>
                </div>
                <div class="card-body">
                    <!-- Simple Card Style -->
                    <div class="mb-3">
                        <h6 class="small text-muted mb-2">Card Style:</h6>
                        <div class="card text-center">
                            <div class="card-body py-3">
                                @if($statistic->icon)
                                    <i class="{{ $statistic->icon }} fs-2 text-primary mb-2"></i>
                                @endif
                                <h4 class="text-primary mb-1">{{ number_format($statistic->value) }}{{ $statistic->suffix }}</h4>
                                <p class="text-muted mb-0 small">{{ $statistic->title }}</p>
                            </div>
                        </div>
                    </div>

                    <!-- Minimal Style -->
                    <div class="mb-3">
                        <h6 class="small text-muted mb-2">Minimal Style:</h6>
                        <div class="text-center p-3 border rounded">
                            <h3 class="text-dark mb-1">{{ number_format($statistic->value) }}{{ $statistic->suffix }}</h3>
                            <small class="text-muted">{{ $statistic->title }}</small>
                        </div>
                    </div>

                    <!-- Badge Style -->
                    <div>
                        <h6 class="small text-muted mb-2">Badge Style:</h6>
                        <div class="text-center">
                            @if($statistic->icon)
                                <i class="{{ $statistic->icon }} text-primary me-1"></i>
                            @endif
                            <span class="badge bg-primary fs-6">{{ number_format($statistic->value) }}{{ $statistic->suffix }}</span>
                            <br><small class="text-muted">{{ $statistic->title }}</small>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card mt-3">
                <div class="card-header">
                    <h5 class="mb-0">Usage Information</h5>
                </div>
                <div class="card-body">
                    <h6>Template Usage:</h6>
                    <p class="small text-muted">
                        To use this statistic in your Blade templates:
                    </p>
                    <pre class="bg-light p-2 rounded small"><code>$statistic = Statistic::find({{ $statistic->id }});
echo $statistic->formatted_value;</code></pre>
                    
                    <h6 class="mt-3">Display Value:</h6>
                    <pre class="bg-light p-2 rounded small"><code>{{ '{' }}{{ '{' }} $statistic->formatted_value {{ '}' }}{{ '}' }}</code></pre>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection