@extends('layouts.admin')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="page-title-box">
                <div class="page-title-right">
                    <a href="{{ route('admin.inventory-alerts.index') }}" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> Back
                    </a>
                    @if(!$inventoryAlert->is_resolved)
                        <form action="{{ route('admin.inventory-alerts.resolve', $inventoryAlert) }}"
                              method="POST" class="d-inline">
                            @csrf
                            @method('PATCH')
                            <button type="submit" class="btn btn-success">
                                <i class="fas fa-check"></i> Resolve Alert
                            </button>
                        </form>
                    @endif
                </div>
                <h4 class="page-title">Inventory Alert Detail</h4>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <table class="table table-bordered">
                        <tr>
                            <th style="width: 200px;">Product</th>
                            <td>
                                @if($inventoryAlert->product)
                                    <a href="{{ route('admin.products.edit', $inventoryAlert->product) }}">{{ $inventoryAlert->product->name }}</a>
                                @else
                                    N/A
                                @endif
                            </td>
                        </tr>
                        <tr>
                            <th>Type</th>
                            <td>
                                <span class="badge bg-{{ $inventoryAlert->type == 'low_stock' ? 'warning' : ($inventoryAlert->type == 'out_of_stock' ? 'danger' : 'info') }}">
                                    {{ str_replace('_', ' ', ucfirst($inventoryAlert->type)) }}
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <th>Message</th>
                            <td>{{ $inventoryAlert->message }}</td>
                        </tr>
                        <tr>
                            <th>Resolved</th>
                            <td>
                                <span class="badge bg-{{ $inventoryAlert->is_resolved ? 'success' : 'secondary' }}">
                                    {{ $inventoryAlert->is_resolved ? 'Yes' : 'No' }}
                                </span>
                            </td>
                        </tr>
                        @if($inventoryAlert->resolved_at)
                        <tr>
                            <th>Resolved At</th>
                            <td>{{ $inventoryAlert->resolved_at->format('M d, Y H:i:s') }}</td>
                        </tr>
                        @endif
                        <tr>
                            <th>Created At</th>
                            <td>{{ $inventoryAlert->created_at->format('M d, Y H:i:s') }}</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
