<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Berikan Review - Ryll Store</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 40px 20px;
            position: relative;
            overflow-x: hidden;
        }
        
        body::before, body::after {
            content: '';
            position: absolute;
            border-radius: 50%;
            background: rgba(255,255,255,0.1);
            animation: float 20s infinite ease-in-out;
        }
        
        body::before {
            width: 500px;
            height: 500px;
            top: -200px;
            left: -200px;
        }
        
        body::after {
            width: 400px;
            height: 400px;
            bottom: -150px;
            right: -150px;
            animation-delay: -10s;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(180deg); }
        }
        
        .container {
            max-width: 650px;
            margin: 0 auto;
            background: white;
            padding: 40px;
            border-radius: 24px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            position: relative;
            z-index: 1;
            animation: slideUp 0.6s ease;
        }
        
        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .header {
            text-align: center;
            margin-bottom: 35px;
            padding-bottom: 25px;
            border-bottom: 2px solid #f0f0f0;
        }
        
        .header h1 {
            font-size: 28px;
            color: #1a1a1a;
            margin-bottom: 8px;
            font-weight: 700;
            letter-spacing: -0.5px;
        }
        
        .header p {
            color: #666;
            font-size: 15px;
        }
        
        .product-card {
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
            padding: 20px;
            border-radius: 16px;
            margin-bottom: 30px;
            border: 2px solid #dee2e6;
            display: flex;
            align-items: center;
            gap: 16px;
        }
        
        .product-card .icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 28px;
            flex-shrink: 0;
        }
        
        .product-card .info {
            flex: 1;
        }
        
        .product-card .product-name {
            font-size: 16px;
            font-weight: 600;
            color: #333;
            margin-bottom: 4px;
        }
        
        .product-card .order-id {
            font-size: 13px;
            color: #666;
        }
        
        .badge {
            display: inline-block;
            padding: 3px 10px;
            background: #d4edda;
            color: #155724;
            border-radius: 12px;
            font-size: 11px;
            font-weight: 600;
            margin-left: 8px;
        }
        
        @if(session('error'))
        .alert {
            background: #fff3cd;
            border-left: 4px solid #ffc107;
            padding: 16px;
            border-radius: 12px;
            margin-bottom: 24px;
            color: #856404;
            font-size: 14px;
        }
        @endif
        
        .form-group {
            margin-bottom: 28px;
        }
        
        label {
            display: block;
            font-weight: 600;
            color: #333;
            margin-bottom: 10px;
            font-size: 14px;
        }
        
        .required {
            color: #ef4444;
            margin-left: 2px;
        }
        
        .star-rating {
            display: flex;
            gap: 8px;
            flex-direction: row-reverse;
            justify-content: flex-end;
            font-size: 48px;
            margin: 10px 0;
        }
        
        .star-rating input {
            display: none;
        }
        
        .star-rating label {
            cursor: pointer;
            color: #e0e0e0;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            margin: 0;
        }
        
        .star-rating label:hover,
        .star-rating label:hover ~ label,
        .star-rating input:checked ~ label {
            color: #ffc107;
            transform: scale(1.1);
        }
        
        input[type="text"],
        textarea {
            width: 100%;
            padding: 14px 16px;
            border: 2px solid #e0e0e0;
            border-radius: 12px;
            font-size: 15px;
            font-family: inherit;
            transition: all 0.3s;
            background: #fafafa;
        }
        
        input[type="text"]:focus,
        textarea:focus {
            outline: none;
            border-color: #667eea;
            background: white;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }
        
        textarea {
            min-height: 120px;
            resize: vertical;
        }
        
        .char-count {
            text-align: right;
            font-size: 12px;
            color: #999;
            margin-top: 6px;
        }
        
        .file-input-wrapper {
            position: relative;
            display: inline-block;
            width: 100%;
        }
        
        input[type="file"] {
            width: 100%;
            padding: 40px 20px;
            border: 2px dashed #e0e0e0;
            border-radius: 12px;
            cursor: pointer;
            background: #fafafa;
            transition: all 0.3s;
        }
        
        input[type="file"]:hover {
            border-color: #667eea;
            background: #f5f7ff;
        }
        
        .file-hint {
            display: block;
            font-size: 13px;
            color: #999;
            margin-top: 8px;
        }
        
        .error-message {
            color: #ef4444;
            font-size: 13px;
            margin-top: 6px;
        }
        
        .submit-btn {
            width: 100%;
            padding: 18px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 12px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .submit-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
        }
        
        .submit-btn:active {
            transform: translateY(0);
        }
        
        .footer-note {
            text-align: center;
            margin-top: 24px;
            padding-top: 20px;
            border-top: 1px solid #f0f0f0;
            font-size: 12px;
            color: #999;
        }
        
        @media (max-width: 600px) {
            .container {
                padding: 30px 20px;
            }
            
            .header h1 {
                font-size: 24px;
            }
            
            .star-rating {
                font-size: 40px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>⭐ Berikan Review</h1>
            <p>Bagaimana pengalaman Anda dengan produk ini?</p>
        </div>

        <div class="product-card">
            <div class="icon">🎮</div>
            <div class="info">
                <div class="product-name">{{ $transaction->product_name ?? 'Product' }}</div>
                <div class="order-id">
                    Invoice #{{ $transaction->invoice_number }}
                    <span class="badge">✓ Selesai</span>
                </div>
            </div>
        </div>

        @if(session('error'))
            <div class="alert">
                ⚠️ {{ session('error') }}
            </div>
        @endif

        <form method="POST" action="{{ route('reviews.store.token', $transaction->review_token) }}" enctype="multipart/form-data" id="reviewForm">
            @csrf

            <div class="form-group">
                <label>Rating <span class="required">*</span></label>
                <div class="star-rating">
                    @for ($i = 5; $i >= 1; $i--)
                        <input type="radio" id="star{{ $i }}" name="rating" value="{{ $i }}" {{ old('rating') == $i ? 'checked' : '' }} required>
                        <label for="star{{ $i }}">★</label>
                    @endfor
                </div>
                @error('rating')
                    <div class="error-message">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="reviewer_name">Nama Anda <span class="required">*</span></label>
                <input 
                    type="text" 
                    id="reviewer_name" 
                    name="reviewer_name" 
                    value="{{ old('reviewer_name', $transaction->customer_name) }}" 
                    placeholder="Nama yang akan ditampilkan" 
                    required
                    maxlength="100"
                >
                @error('reviewer_name')
                    <div class="error-message">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="comment">Ulasan (Opsional)</label>
                <textarea 
                    id="comment" 
                    name="comment" 
                    placeholder="Ceritakan pengalaman Anda dengan produk ini..."
                    maxlength="1000"
                    oninput="updateCharCount()"
                >{{ old('comment') }}</textarea>
                <div class="char-count">
                    <span id="charCount">0</span>/1000 karakter
                </div>
                @error('comment')
                    <div class="error-message">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="images">Upload Foto (Opsional)</label>
                <input 
                    type="file" 
                    id="images" 
                    name="images[]" 
                    accept="image/jpeg,image/png,image/jpg,image/gif" 
                    multiple
                >
                <span class="file-hint">📷 Maksimal 3 foto, masing-masing max 2MB (JPG, PNG, GIF)</span>
                @error('images')
                    <div class="error-message">{{ $message }}</div>
                @enderror
            </div>

            <button type="submit" class="submit-btn">
                <span>📤</span>
                <span>Kirim Review</span>
            </button>
        </form>

        <div class="footer-note">
            🔒 Link ini hanya dapat digunakan satu kali untuk keamanan
        </div>
    </div>

    <script>
        // Character counter
        function updateCharCount() {
            const textarea = document.getElementById('comment');
            const charCount = document.getElementById('charCount');
            charCount.textContent = textarea.value.length;
        }
        
        // Initialize char count
        window.addEventListener('load', updateCharCount);
        
        // File validation
        document.getElementById('images').addEventListener('change', function(e) {
            const files = e.target.files;
            
            if (files.length > 3) {
                alert('Maksimal 3 foto!');
                e.target.value = '';
                return;
            }
            
            for (let file of files) {
                if (file.size > 2 * 1024 * 1024) {
                    alert(`File ${file.name} terlalu besar! Maksimal 2MB per foto.`);
                    e.target.value = '';
                    return;
                }
            }
        });
    </script>
</body>
</html>