@extends('layouts.winemaker')

@section('title', 'Cellar - Winemaker')

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

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

    .page-subtitle {
        color: #718096;
        font-size: 1rem;
    }

    .stats-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1.5rem;
        margin-bottom: 2rem;
    }

    .stat-card {
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        padding: 1.5rem;
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .stat-icon {
        width: 48px;
        height: 48px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .stat-content {
        flex: 1;
    }

    .stat-label {
        font-size: 0.875rem;
        color: #718096;
        margin-bottom: 0.25rem;
    }

    .stat-value {
        font-size: 1.75rem;
        font-weight: 700;
        color: #2d3748;
    }

    .wines-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 2rem;
    }

    .wine-card {
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        overflow: hidden;
        transition: all 0.3s;
        cursor: pointer;
    }

    .wine-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    }

    .wine-image {
        width: 100%;
        height: 200px;
        background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }

    .wine-image svg {
        width: 64px;
        height: 64px;
        opacity: 0.5;
    }

    .wine-status-overlay {
        position: absolute;
        top: 1rem;
        right: 1rem;
    }

    .wine-content {
        padding: 1.5rem;
    }

    .wine-header {
        margin-bottom: 1rem;
    }

    .wine-name {
        font-size: 1.25rem;
        font-weight: 600;
        color: #2d3748;
        margin-bottom: 0.5rem;
    }

    .wine-badges {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

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

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

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

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

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

    .badge-status {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
    }

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

    .status-aging {
        background: linear-gradient(135deg, #fed7aa 0%, #fdba74 100%);
        color: #92400e;
    }

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

    .status-sold_out {
        background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
        color: #991b1b;
    }

    .wine-details {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .wine-detail {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

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

    .detail-value {
        font-size: 0.875rem;
        font-weight: 600;
        color: #2d3748;
    }

    .wine-actions {
        display: flex;
        gap: 0.75rem;
        padding-top: 1rem;
        border-top: 1px solid #e2e8f0;
    }

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

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

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

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

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

    .empty-state {
        text-align: center;
        padding: 4rem 2rem;
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }

    .empty-icon {
        width: 80px;
        height: 80px;
        margin: 0 auto 1.5rem;
        opacity: 0.5;
    }

    .empty-title {
        font-size: 1.5rem;
        font-weight: 600;
        color: #2d3748;
        margin-bottom: 0.5rem;
    }

    .empty-description {
        color: #718096;
        margin-bottom: 2rem;
    }

    .btn-primary {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 1.5rem;
        background: linear-gradient(135deg, #89b4d9 0%, #a8cce5 100%);
        color: #1a365d;
        border: none;
        border-radius: 8px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        text-decoration: none;
    }

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

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

    @media (max-width: 768px) {
        .wines-grid {
            grid-template-columns: 1fr;
        }

        .stats-grid {
            grid-template-columns: 1fr;
        }
    }

</style>

<div class="page-header">
    <h1 class="page-title">Wine Cellar</h1>
    <p class="page-subtitle">Manage your wine inventory and production</p>
</div>

<div class="stats-grid">
    <div class="stat-card">
        <div class="stat-icon" style="background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);">
            <svg style="width: 24px; height: 24px; color: #1e40af;" fill="currentColor" viewBox="0 0 24 24">
                <path d="M19,19H5V8H19M16,1V3H8V1H6V3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3H18V1M17,12H12V17H17V12Z"/>
            </svg>
        </div>
        <div class="stat-content">
            <div class="stat-label">In Production</div>
            <div class="stat-value">{{ $wines->where('status', 'in_production')->count() }}</div>
        </div>
    </div>

    <div class="stat-card">
        <div class="stat-icon" style="background: linear-gradient(135deg, #fed7aa 0%, #fdba74 100%);">
            <svg style="width: 24px; height: 24px; color: #92400e;" fill="currentColor" viewBox="0 0 20 20">
                <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z" clip-rule="evenodd"/>
            </svg>
        </div>
        <div class="stat-content">
            <div class="stat-label">Aging</div>
            <div class="stat-value">{{ $wines->where('status', 'aging')->count() }}</div>
        </div>
    </div>

    <div class="stat-card">
        <div class="stat-icon" style="background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);">
            <svg style="width: 24px; height: 24px; color: #065f46;" fill="currentColor" viewBox="0 0 20 20">
                <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
            </svg>
        </div>
        <div class="stat-content">
            <div class="stat-label">Ready</div>
            <div class="stat-value">{{ $wines->where('status', 'ready')->count() }}</div>
        </div>
    </div>

    <div class="stat-card">
        <div class="stat-icon" style="background: linear-gradient(135deg, #89b4d9 0%, #a8cce5 100%);">
            <svg style="width: 24px; height: 24px; color: #1a365d;" 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>
        </div>
        <div class="stat-content">
            <div class="stat-label">Total Bottles</div>
            <div class="stat-value">{{ $wines->sum('bottles_in_stock') }}</div>
        </div>
    </div>
</div>

@if($wines->count() > 0)
<div class="wines-grid">
    @foreach($wines as $wine)
    <div class="wine-card">
        <div class="wine-image">
            @if($wine->image_url)
                <img src="{{ asset('storage/' . $wine->image_url) }}" alt="{{ $wine->wine_name }}" style="width: 100%; height: 100%; object-fit: cover;">
            @else
                <svg 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>
            @endif
            <div class="wine-status-overlay">
                <span class="badge badge-status status-{{ $wine->status }}">
                    @if($wine->status == 'in_production')
                        In Production
                    @elseif($wine->status == 'aging')
                        Aging
                    @elseif($wine->status == 'ready')
                        Ready
                    @elseif($wine->status == 'sold_out')
                        Sold Out
                    @else
                        {{ ucfirst($wine->status) }}
                    @endif
                </span>
            </div>
        </div>

        <div class="wine-content">
            <div class="wine-header">
                <h3 class="wine-name">{{ $wine->wine_name }}</h3>
                <div class="wine-badges">
                    <span class="badge badge-vintage">{{ $wine->vintage }}</span>
                    <span class="badge badge-{{ $wine->wine_type }}">
                        {{ ucfirst($wine->wine_type) }}
                    </span>
                </div>
            </div>

            <div class="wine-details">
                <div class="wine-detail">
                    <span class="detail-label">Variety</span>
                    <span class="detail-value">{{ $wine->grapeVariety->variety_name ?? 'N/A' }}</span>
                </div>
                <div class="wine-detail">
                    <span class="detail-label">Alcohol</span>
                    <span class="detail-value">{{ number_format($wine->alcohol_percentage, 1) }}%</span>
                </div>
                <div class="wine-detail">
                    <span class="detail-label">Bottles</span>
                    <span class="detail-value">{{ $wine->bottles_in_stock }} / {{ $wine->bottles_produced }}</span>
                </div>
                <div class="wine-detail">
                    <span class="detail-label">Bottling Date</span>
                    <span class="detail-value">{{ $wine->bottling_date ? \Carbon\Carbon::parse($wine->bottling_date)->format('M Y') : 'N/A' }}</span>
                </div>
            </div>

            <div class="wine-actions">
                <a href="{{ route('wines.edit', $wine->id) }}" class="btn-action btn-update">
                    <svg class="icon" style="width: 16px; height: 16px;" 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
                </a>
                <a href="{{ route('wines.show', $wine->id) }}" class="btn-action btn-view">
                    <svg class="icon" style="width: 16px; height: 16px;" fill="currentColor" viewBox="0 0 20 20">
                        <path d="M10 12a2 2 0 100-4 2 2 0 000 4z"/>
                        <path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd"/>
                    </svg>
                    View
                </a>
            </div>
        </div>
    </div>
    @endforeach
</div>
@else
<div class="empty-state">
    <svg class="empty-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/>
    </svg>
    <h2 class="empty-title">No Wines in Cellar</h2>
    <p class="empty-description">Start by bottling wines from your harvests.</p>
    <a href="{{ route('winemaker.harvests.index') }}" class="btn-primary">
        <svg class="icon" 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>
        View Harvests
    </a>
</div>
@endif
@endsection
