@extends('layouts.app')

@section('title', $product->name)

@section('content')
    <x-breadcrumbs :items="[
        ['label' => 'Dashboard', 'url' => route('dashboard')],
        ['label' => 'Products & Services', 'url' => route('products.index')],
        ['label' => $product->name],
    ]" />

    <x-page-header :title="$product->name" :subtitle="$product->code">
        @can('update', $product)
            <a href="{{ route('products.edit', $product) }}" class="btn btn-outline-primary btn-sm">Edit</a>
        @endcan
    </x-page-header>

    <div class="row g-3">
        <div class="col-lg-8">
            <x-card title="Overview">
                <dl class="row mb-0">
                    <dt class="col-sm-4 text-muted">Category</dt>
                    <dd class="col-sm-8">{{ $product->category->name ?? '—' }}</dd>
                    <dt class="col-sm-4 text-muted">Default Price</dt>
                    <dd class="col-sm-8"><x-money :amount="$product->default_price" /></dd>
                    <dt class="col-sm-4 text-muted">Charge Basis</dt>
                    <dd class="col-sm-8">{{ $product->default_charge_basis->label() }}</dd>
                    <dt class="col-sm-4 text-muted">Tax Rate</dt>
                    <dd class="col-sm-8">{{ $product->default_tax_rate ?? 0 }}%</dd>
                    <dt class="col-sm-4 text-muted">Status</dt>
                    <dd class="col-sm-8"><x-badge :status="$product->is_active ? 'active' : 'inactive'" :label="$product->is_active ? 'Active' : 'Inactive'" /></dd>
                    @if ($product->description)
                        <dt class="col-sm-4 text-muted">Description</dt>
                        <dd class="col-sm-8">{{ $product->description }}</dd>
                    @endif
                </dl>
            </x-card>

            @if ($product->packageItems->isNotEmpty())
                <x-card title="Used in Packages" class="mt-3">
                    <ul class="mb-0">
                        @foreach ($product->packageItems as $packageItem)
                            <li>
                                <a href="{{ route('packages.show', $packageItem->package) }}">{{ $packageItem->package->name ?? 'Package' }}</a>
                            </li>
                        @endforeach
                    </ul>
                </x-card>
            @endif
        </div>
    </div>
@endsection
