@php
    $hasDiscount = !is_null($product->discount_price) && $product->discount_price > 0;
    $basePrice   = $product->price ?: 0;
    $finalPrice  = $hasDiscount ? $product->discount_price : $basePrice;

    $imageUrl = $product->thumbnail_url
        ?? (!empty($product->thumbnail) ? asset('storage/'.$product->thumbnail) : asset('assets/img/default-product.jpg'));

    $brandName = 'SEF Card';
    $itemGroup = $product->product_code ?? $product->id;
    $description = Str::limit(strip_tags($product->short_description ?? $product->description ?? ''), 160);
@endphp

{{-- Open Graph Product Meta --}}
<meta property="og:type" content="product">
<meta property="og:title" content="{{ $product->name }} | SEF NFC Digital Card">
<meta property="og:description" content="{{ $description }}">
<meta property="og:url" content="{{ url()->current() }}">
<meta property="og:image" content="{{ $imageUrl }}">

<meta property="product:brand" content="{{ $brandName }}">
<meta property="product:availability" content="{{ $product->stock > 0 ? 'in stock' : 'out of stock' }}">
<meta property="product:condition" content="new">
<meta property="product:price:amount" content="{{ number_format($finalPrice, 2, '.', '') }}">
<meta property="product:price:currency" content="BDT">
<meta property="product:retailer_item_id" content="{{ $product->id }}">
<meta property="product:item_group_id" content="{{ $itemGroup }}">

{{-- JSON-LD Product Schema --}}
@php
    $productJsonLd = [
        '@context'   => 'https://schema.org',
        '@type'      => 'Product',
        'productID'  => (string) $product->id,
        'name'       => $product->name,
        'description'=> $description,
        'url'        => url()->current(),
        'image'      => $imageUrl,
        'brand'      => $brandName,
        'offers'     => [[
            '@type'         => 'Offer',
            'price'         => number_format($finalPrice, 2, '.', ''),
            'priceCurrency' => 'BDT',
            'itemCondition' => 'https://schema.org/NewCondition',
            'availability'  => $product->stock > 0
                ? 'https://schema.org/InStock'
                : 'https://schema.org/OutOfStock',
        ]],
        'additionalProperty' => [[
            '@type'      => 'PropertyValue',
            'propertyID' => 'item_group_id',
            'value'      => $itemGroup,
        ]],
    ];
@endphp

<script type="application/ld+json">
{!! json_encode($productJsonLd, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) !!}
</script>
