@extends('layouts.main')

@section('content')
<div class="card mb-4">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="mb-0">{{ $product->name }}</h5>
        <div>
            @if(Auth::user()->hasPermission('products.edit'))
            <a href="{{ route('products.edit', $product->id) }}" class="btn btn-primary btn-sm">
                <i class="bi bi-pencil"></i> Edit
            </a>
            @endif
            <a href="{{ route('products.index') }}" class="btn btn-secondary btn-sm">
                <i class="bi bi-arrow-left"></i> Back
            </a>
        </div>
    </div>
    <div class="card-body">
        <div class="row">
            <div class="col-md-4 text-center">
                @if($product->image)
                    <img src="{{ asset('storage/products/'.$product->image) }}" alt="{{ $product->name }}" class="img-fluid rounded" style="max-height: 300px;">
                @else
                    <div class="bg-light d-flex align-items-center justify-content-center rounded" style="height: 300px;">
                        <i class="bi bi-image text-muted" style="font-size: 4rem;"></i>
                    </div>
                @endif
            </div>
            <div class="col-md-8">
                <table class="table table-borderless">
                    <tr>
                        <td><strong>SKU:</strong></td>
                        <td>{{ $product->sku }}</td>
                    </tr>
                    @if($product->barcode)
                    <tr>
                        <td><strong>Barcode:</strong></td>
                        <td>{{ $product->barcode }}</td>
                    </tr>
                    @endif
                    <tr>
                        <td><strong>Category:</strong></td>
                        <td>{{ $product->category->name }}</td>
                    </tr>
                    <tr>
                        <td><strong>Unit of Measure:</strong></td>
                        <td>{{ $product->unitOfMeasure->name ?? 'N/A' }} ({{ $product->unitOfMeasure->abbreviation ?? '' }})</td>
                    </tr>
                    <tr>
                        <td><strong>Cost Price:</strong></td>
                        <td>{{ number_format($product->cost_price, 2) }}</td>
                    </tr>
                    <tr>
                        <td><strong>Selling Price:</strong></td>
                        <td>{{ number_format($product->selling_price, 2) }}</td>
                    </tr>
                    <tr>
                        <td><strong>Stock Quantity:</strong></td>
                        <td>
                            <span class="badge {{ $product->stock_quantity <= $product->low_stock_threshold ? 'bg-danger' : 'bg-success' }}">
                                {{ $product->stock_quantity }} {{ $product->unitOfMeasure->abbreviation ?? '' }}
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td><strong>Low Stock Threshold:</strong></td>
                        <td>{{ $product->low_stock_threshold }}</td>
                    </tr>
                    <tr>
                        <td><strong>Status:</strong></td>
                        <td>
                            <span class="badge {{ $product->is_active ? 'bg-success' : 'bg-secondary' }}">
                                {{ $product->is_active ? 'Active' : 'Inactive' }}
                            </span>
                        </td>
                    </tr>
                    @if($product->description)
                    <tr>
                        <td><strong>Description:</strong></td>
                        <td>{{ $product->description }}</td>
                    </tr>
                    @endif
                </table>
            </div>
        </div>
    </div>
</div>
@endsection
