@extends('layouts.winemaker')

@section('title', $wine->wine_name . ' - Wine Details')

@section('content')
<style>
    .page-header {
        margin-bottom: 2rem;
    }

    .page-title {
        font-size: 2rem;
        font-weight: 700;
        color: #2d3748;
        margin-bottom: 0.5rem;
    }

    .breadcrumb {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        color: #718096;
        font-size: 0.875rem;
    }

    .breadcrumb a {
        color: #4a5568;
        text-decoration: none;
        transition: color 0.2s;
    }

    .breadcrumb a:hover {
        color: #2d3748;
    }

    .content-layout {
        display: grid;
        grid-template-columns: 1fr 350px;
        gap: 2rem;
    }

    .content-card {
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        padding: 2rem;
    }

    .card-title {
        font-size: 1.25rem;
        font-weight: 600;
        color: #2d3748;
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
        border-bottom: 2px solid #e2e8f0;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .detail-grid {
        display: grid;
        gap: 1.25rem;
    }

    .detail-row {
        display: grid;
        grid-template-columns: 140px 1fr;
        gap: 1rem;
        padding: 0.75rem 0;
        border-bottom: 1px solid #f7fafc;
    }

    .detail-label {
        font-weight: 500;
        color: #718096;
        font-size: 0.875rem;
    }

    .detail-value {
        color: #2d3748;
        font-weight: 500;
    }

    .status-badge {
        display: inline-flex;
        align-items: center;
        gap: 0.375rem;
        padding: 0.375rem 0.75rem;
        border-radius: 6px;
        font-size: 0.875rem;
        font-weight: 500;
    }

    .status-in_production {
        background: linear-gradient(135deg, #fef9c3 0%, #fde68a 100%);
        color: #78350f;
    }

    .status-aging {
        background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
        color: #1e40af;
    }

    .status-ready {
        background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
        color: #065f46;
    }

    .status-sold_out {
        background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
        color: #374151;
    }

    .wine-type-badge {
        display: inline-flex;
        align-items: center;
        gap: 0.375rem;
        padding: 0.375rem 0.75rem;
        border-radius: 6px;
        font-size: 0.875rem;
        font-weight: 500;
    }

    .wine-type-red {
        background: linear-gradient(135deg, #fecaca 0%, #fca5a5 100%);
        color: #7f1d1d;
    }

    .wine-type-white {
        background: linear-gradient(135deg, #fef9c3 0%, #fde68a 100%);
        color: #78350f;
    }

    .wine-type-rose {
        background: linear-gradient(135deg, #fbcfe8 0%, #f9a8d4 100%);
        color: #831843;
    }

    .description-box {
        background: #f7fafc;
        padding: 1rem;
        border-radius: 8px;
        color: #4a5568;
        line-height: 1.6;
        margin-top: 0.5rem;
    }

    .production-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .production-item {
        padding: 1rem;
        background: #f7fafc;
        border-radius: 8px;
        margin-bottom: 0.75rem;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .production-header {
        font-weight: 600;
        color: #2d3748;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .production-details {
        display: flex;
        gap: 1.5rem;
        font-size: 0.875rem;
        color: #718096;
    }

    .production-detail {
        display: flex;
        align-items: center;
        gap: 0.375rem;
    }

    .percentage-bar {
        height: 8px;
        background: #e2e8f0;
        border-radius: 4px;
        overflow: hidden;
        margin-top: 0.5rem;
    }

    .percentage-fill {
        height: 100%;
        background: linear-gradient(135deg, #89b4d9 0%, #a8cce5 100%);
        transition: width 0.3s;
    }

    .sidebar-card {
        position: sticky;
        top: 2rem;
    }

    .quick-stats {
        display: grid;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .stat-item {
        background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
        padding: 1rem;
        border-radius: 8px;
        text-align: center;
    }

    .stat-value {
        font-size: 1.5rem;
        font-weight: 700;
        color: #2d3748;
        margin-bottom: 0.25rem;
    }

    .stat-label {
        font-size: 0.75rem;
        color: #718096;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
        border-radius: 8px;
        font-weight: 600;
        font-size: 0.875rem;
        cursor: pointer;
        transition: all 0.2s;
        text-decoration: none;
        border: none;
    }

    .btn-primary {
        background: linear-gradient(135deg, #89b4d9 0%, #a8cce5 100%);
        color: #1a365d;
    }

    .btn-primary:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(137, 180, 217, 0.4);
    }

    .btn-secondary {
        background: white;
        color: #4a5568;
        border: 2px solid #e2e8f0;
    }

    .btn-secondary:hover {
        background: #f7fafc;
        border-color: #cbd5e0;
    }

    .icon {
        width: 20px;
        height: 20px;
    }

    .icon-sm {
        width: 16px;
        height: 16px;
    }

    @media (max-width: 1024px) {
        .content-layout {
            grid-template-columns: 1fr;
        }

        .sidebar-card {
            position: static;
        }
    }
</style>

<div class="page-header">
    <h1 class="page-title">{{ $wine->wine_name }}</h1>
    <div class="breadcrumb">
        <a href="{{ route('winemaker.cellar.index') }}">Cellar</a>
        <span>/</span>
        <span>{{ $wine->wine_name }}</span>
    </div>
</div>

<div class="content-layout">
    <div>
        <div class="content-card">
            <h2 class="card-title">
                <svg class="icon" fill="currentColor" viewBox="0 0 24 24">
                    <path d="M6,2V10C6,11.11 6.9,12 8,12H10V22H14V12H16C17.11,12 18,11.11 18,10V2H6M8,4H10V6H8V4M12,4H14V6H12V4M16,4H18V6H16V4M8,8H10V10H8V8M12,8H14V10H12V8M16,8H18V10H16V8Z"/>
                </svg>
                Wine Details
            </h2>

            @if($wine->image_url)
                <div style="margin-bottom: 2rem; text-align: center;">
                    <img src="{{ asset('storage/' . $wine->image_url) }}" alt="{{ $wine->wine_name }}"
                        style="max-width: 100%; max-height: 400px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);">
                </div>
            @endif

            <div class="detail-grid">
                <div class="detail-row">
                    <span class="detail-label">Vintage</span>
                    <span class="detail-value">{{ $wine->vintage }}</span>
                </div>

                <div class="detail-row">
                    <span class="detail-label">Grape Variety</span>
                    <span class="detail-value">{{ $wine->grapeVariety->variety_name ?? 'N/A' }}</span>
                </div>

                <div class="detail-row">
                    <span class="detail-label">Wine Type</span>
                    <span class="detail-value">
                        <span class="wine-type-badge wine-type-{{ $wine->wine_type }}">
                            {{ ucfirst($wine->wine_type ?? 'N/A') }}
                        </span>
                    </span>
                </div>

                <div class="detail-row">
                    <span class="detail-label">Sweetness</span>
                    <span class="detail-value">{{ str_replace('_', '-', ucfirst($wine->sweetness ?? 'N/A')) }}</span>
                </div>

                <div class="detail-row">
                    <span class="detail-label">Status</span>
                    <span class="detail-value">
                        <span class="status-badge status-{{ $wine->status }}">
                            {{ str_replace('_', ' ', ucfirst($wine->status)) }}
                        </span>
                    </span>
                </div>

                <div class="detail-row">
                    <span class="detail-label">Alcohol</span>
                    <span class="detail-value">{{ $wine->alcohol_percentage ?? 'N/A' }}%</span>
                </div>

                <div class="detail-row">
                    <span class="detail-label">Bottle Volume</span>
                    <span class="detail-value">{{ $wine->bottle_volume ?? 'N/A' }} L</span>
                </div>

                <div class="detail-row">
                    <span class="detail-label">Price per Bottle</span>
                    <span class="detail-value">
                        {{ $wine->price_per_bottle ? '$' . number_format($wine->price_per_bottle, 2) : 'Not set' }}
                    </span>
                </div>

                @if($wine->production_date)
                <div class="detail-row">
                    <span class="detail-label">Production Date</span>
                    <span class="detail-value">{{ $wine->production_date->format('d M Y') }}</span>
                </div>
                @endif

                @if($wine->bottling_date)
                <div class="detail-row">
                    <span class="detail-label">Bottling Date</span>
                    <span class="detail-value">{{ $wine->bottling_date->format('d M Y') }}</span>
                </div>
                @endif

                @if($wine->description)
                <div class="detail-row" style="grid-template-columns: 1fr;">
                    <span class="detail-label">Description</span>
                    <div class="description-box">{{ $wine->description }}</div>
                </div>
                @endif
            </div>
        </div>

        <div class="content-card" style="margin-top: 2rem;">
            <h2 class="card-title">
                <svg class="icon" fill="currentColor" viewBox="0 0 20 20">
                    <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"/>
                    <path fill-rule="evenodd" d="M4 5a2 2 0 012-2 3 3 0 003 3h2a3 3 0 003-3 2 2 0 012 2v11a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 4a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z" clip-rule="evenodd"/>
                </svg>
                Production Details
            </h2>

            @if($wine->harvests && $wine->harvests->count() > 0)
                <ul class="production-list">
                    @foreach($wine->harvests as $harvest)
                        <li class="production-item">
                            <div class="production-header">
                                <svg class="icon-sm" fill="currentColor" viewBox="0 0 24 24">
                                    <path d="M12,2C11.5,2 11,2.19 10.59,2.59L2.59,10.59C1.8,11.37 1.8,12.63 2.59,13.41L10.59,21.41C11.37,22.2 12.63,22.2 13.41,21.41L21.41,13.41C22.2,12.63 22.2,11.37 21.41,10.59L13.41,2.59C13,2.19 12.5,2 12,2M12,4L20,12L12,20L4,12L12,4M12,7C9.79,7 8,8.79 8,11C8,12.5 9,13.77 10.5,14.37L12,16L13.5,14.37C15,13.77 16,12.5 16,11C16,8.79 14.21,7 12,7M12,9A2,2 0 0,1 14,11A2,2 0 0,1 12,13A2,2 0 0,1 10,11A2,2 0 0,1 12,9Z"/>
                                </svg>
                                Harvest #{{ $harvest->id }} - {{ $harvest->varietyVariation->grapeVariety->variety_name ?? 'Unknown' }}
                            </div>
                            <div class="production-details">
                                <div class="production-detail">
                                    <svg class="icon-sm" fill="currentColor" viewBox="0 0 20 20">
                                        <path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd"/>
                                    </svg>
                                    @if($harvest->plannedTask && $harvest->plannedTask->execution_date)
                                        {{ $harvest->plannedTask->execution_date->format('d M Y') }}
                                    @else
                                        {{ $harvest->date->format('d M Y') }}
                                    @endif
                                </div>
                                <div class="production-detail">
                                    <svg class="icon-sm" fill="currentColor" viewBox="0 0 20 20">
                                        <path fill-rule="evenodd" d="M10 2a4 4 0 00-4 4v1H5a1 1 0 00-.994.89l-1 9A1 1 0 004 18h12a1 1 0 00.994-1.11l-1-9A1 1 0 0015 7h-1V6a4 4 0 00-4-4zm2 5V6a2 2 0 10-4 0v1h4zm-6 3a1 1 0 112 0 1 1 0 01-2 0zm7-1a1 1 0 100 2 1 1 0 000-2z" clip-rule="evenodd"/>
                                    </svg>
                                    {{ number_format($harvest->pivot->consumed_weight, 2) }} kg
                                </div>
                                <div class="production-detail">
                                    <strong>{{ number_format($harvest->pivot->blend_percentage, 1) }}%</strong>
                                </div>
                            </div>
                            <div class="percentage-bar">
                                <div class="percentage-fill" style="width: {{ $harvest->pivot->blend_percentage }}%"></div>
                            </div>
                        </li>
                    @endforeach
                </ul>
            @else
                <p style="color: #718096; text-align: center; padding: 2rem;">No production details available.</p>
            @endif
        </div>
    </div>

    <div class="sidebar-card">
        <div class="content-card">
            <h3 class="card-title">
                <svg class="icon" fill="currentColor" viewBox="0 0 20 20">
                    <path d="M2 11a1 1 0 011-1h2a1 1 0 011 1v5a1 1 0 01-1 1H3a1 1 0 01-1-1v-5zM8 7a1 1 0 011-1h2a1 1 0 011 1v9a1 1 0 01-1 1H9a1 1 0 01-1-1V7zM14 4a1 1 0 011-1h2a1 1 0 011 1v12a1 1 0 01-1 1h-2a1 1 0 01-1-1V4z"/>
                </svg>
                Quick Stats
            </h3>

            <div class="quick-stats">
                <div class="stat-item">
                    <div class="stat-value">{{ $wine->bottles_produced }}</div>
                    <div class="stat-label">Bottles Produced</div>
                </div>

                <div class="stat-item">
                    <div class="stat-value">{{ $wine->bottles_in_stock }}</div>
                    <div class="stat-label">In Stock</div>
                </div>

                @if($wine->bottles_produced > 0)
                <div class="stat-item">
                    <div class="stat-value">{{ number_format(($wine->bottles_in_stock / $wine->bottles_produced) * 100, 0) }}%</div>
                    <div class="stat-label">Remaining</div>
                </div>
                @endif
            </div>

            <div class="action-buttons">
                <a href="{{ route('wines.edit', $wine) }}" class="btn btn-primary">
                    <svg class="icon-sm" fill="currentColor" viewBox="0 0 20 20">
                        <path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"/>
                    </svg>
                    Edit Wine
                </a>

                <a href="{{ route('winemaker.cellar.index') }}" class="btn btn-secondary">
                    <svg class="icon-sm" fill="currentColor" viewBox="0 0 20 20">
                        <path fill-rule="evenodd" d="M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z" clip-rule="evenodd"/>
                    </svg>
                    Back to Cellar
                </a>
            </div>
        </div>
    </div>
</div>
@endsection
