<!DOCTYPE html>
<html>
<head>
    <title>LocalLendables Items</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body { 
            font-family: Arial, sans-serif; 
            margin: 20px; 
            background: #f5f5f5;
        }
        .header { 
            background: #28a745; 
            color: white; 
            padding: 20px; 
            border-radius: 8px; 
            margin-bottom: 20px;
        }
        .items { 
            display: grid; 
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); 
            gap: 20px; 
        }
        .item { 
            background: white; 
            border-radius: 8px; 
            padding: 15px; 
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            cursor: pointer;
            transition: transform 0.2s;
        }
        .item:hover { 
            transform: translateY(-2px); 
        }
        .item img { 
            width: 100%; 
            height: 200px; 
            object-fit: cover; 
            border-radius: 4px; 
        }
        .price { 
            color: #28a745; 
            font-weight: bold; 
            margin: 10px 0; 
        }
        .owner { 
            display: flex; 
            align-items: center; 
            margin-top: 10px; 
        }
        .owner img { 
            width: 30px; 
            height: 30px; 
            border-radius: 50%; 
            margin-right: 8px; 
        }
        .back-btn { 
            background: #6c757d; 
            color: white; 
            padding: 10px 20px; 
            text-decoration: none; 
            border-radius: 4px; 
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>LocalLendables Items</h1>
        <p>Authentic community lending data loaded: {{ items|length }} items</p>
        <a href="/dashboard/{{ currentUser.id }}" class="back-btn">← Back to Dashboard</a>
    </div>

    <div class="items">
        {% for item in items %}
        <div class="item" onclick="showDetails('{{ item.title }}', '{{ item.description }}', '{{ item.primaryLogo ?: item.imageUrl }}', '{{ item.extraImages }}')">
            <img src="/lendable_items/{{ item.thumbnailLogo ?: item.imageUrl }}" alt="{{ item.title }}" style="object-fit: contain;" onerror="this.src='/lendable_items/placeholder.png'">
            {% if item.isRequest %}
                <div style="display: flex; align-items: center; margin-bottom: 8px;">
                    <span style="color: #666; font-size: 14px;">Asking For:</span>
                </div>
            {% endif %}
            <h3>{{ item.title }}{% if item.isRequest %}?{% endif %}</h3>
            <p>{{ item.description|slice(0, 100) }}{% if item.description|length > 100 %}...{% endif %}</p>
            <div class="price">
                {% if item.isRequest %}
                    Request Item
                {% elseif item.dailyRate == "0.00" %}
                    Lendable
                {% else %}
                    ${{ item.dailyRate }}/day
                {% endif %}
            </div>
            <div class="owner">
                <img src="/ll_images/{{ item.ownerAvatar }}" alt="{{ item.ownerShowName }}" onerror="this.style.display='none'">
                <span>{{ item.ownerShowName }} ({{ item.ownerRating }}⭐)</span>
            </div>
            {% if item.extraImages %}
                <small style="color: #666;">📸 Multi-image gallery available</small>
            {% endif %}
        </div>
        {% endfor %}
    </div>

    <script>
    function showDetails(title, description, primaryImage, extraImages) {
        let imageList = primaryImage;
        if (extraImages && extraImages !== 'null' && extraImages.trim()) {
            const additional = extraImages.split(',').map(img => img.trim()).filter(img => img);
            if (additional.length > 0) {
                imageList += '\n\nAdditional images:\n' + additional.join('\n');
            }
        }
        
        alert(`${title}\n\n${description}\n\nImages:\n${imageList}`);
    }
    </script>
</body>
</html>