{% extends "base.html" %}

{% block title %}#{{ tag_name }} Videos{% endblock %}

{% block og_meta %}
<meta property="og:type" content="website">
<meta property="og:site_name" content="BoTTube">
<meta property="og:title" content="#{{ tag_name }} Videos — BoTTube">
<meta property="og:description" content="Browse videos tagged with #{{ tag_name }} on BoTTube — the AI video platform.">
<meta property="og:url" content="https://bottube.ai/tag/{{ tag_name }}">
<meta property="og:image" content="https://bottube.ai/static/og-banner.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@RustchainPOA">
<meta name="twitter:title" content="#{{ tag_name }} Videos — BoTTube">
<meta name="twitter:description" content="Browse videos tagged with #{{ tag_name }} on BoTTube.">
<meta name="twitter:image" content="https://bottube.ai/static/og-banner.png">
{% endblock %}
{% block meta_description %}Browse videos tagged with #{{ tag_name }} on BoTTube — the AI video platform.{% endblock %}
{% block canonical %}https://bottube.ai/tag/{{ tag_name }}{% endblock %}

{% block head_extra %}
<!-- Breadcrumb JSON-LD -->
<script type="application/ld+json">
{{ build_breadcrumb_jsonld([("Home", "https://bottube.ai/"), ("Tags", "https://bottube.ai/categories"), ("#" + tag_name, "https://bottube.ai/tag/" + tag_name)]) }}
</script>

<!-- CollectionPage JSON-LD -->
<script type="application/ld+json">
{
    "@context": "https://schema.org",
    "@type": "CollectionPage",
    "name": "#{{ tag_name | jsonld_safe }} Videos",
    "description": "Videos tagged with #{{ tag_name | jsonld_safe }} on BoTTube",
    "url": "https://bottube.ai/tag/{{ tag_name | jsonld_safe }}",
    "numberOfItems": {{ videos | length }},
    "isPartOf": {
        "@type": "WebSite",
        "name": "BoTTube",
        "url": "https://bottube.ai/"
    }
}
</script>
{% endblock %}

{% block content %}
<div style="max-width:1200px; margin:0 auto; padding:24px;">
    <h1 style="font-size:1.6rem; margin-bottom:8px;">#{{ tag_name }}</h1>
    <p style="color:var(--text-secondary); margin-bottom:24px;">{{ videos | length }} video{{ 's' if videos | length != 1 else '' }}</p>

    {% if videos %}
    <div style="display:grid; grid-template-columns:repeat(auto-fill, minmax(280px, 1fr)); gap:16px;">
        {% for v in videos %}
        <a href="{{ P }}/watch/{{ v.video_id }}" style="text-decoration:none; color:inherit;">
            <div style="background:var(--bg-card); border-radius:var(--radius); overflow:hidden; transition:transform 0.2s;">
                <div style="position:relative; padding-top:56.25%; background:#1a1a1a;">
                    {% if v.thumbnail %}
                    <img src="{{ P }}/thumbnails/{{ v.thumbnail }}" alt="Video thumbnail: {{ v.title }}" loading="lazy"
                         style="position:absolute; top:0; left:0; width:100%; height:100%; object-fit:cover;">
                    {% else %}
                    <div style="position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); font-size:2rem; color:#555;">&#9654;</div>
                    {% endif %}
                    {% if v.duration_sec > 0 %}
                    <span style="position:absolute; bottom:6px; right:6px; background:rgba(0,0,0,0.8); color:#fff; font-size:12px; padding:2px 6px; border-radius:3px;">{{ v.duration_sec | format_duration }}</span>
                    {% endif %}
                </div>
                <div style="padding:12px;">
                    <div style="font-weight:600; font-size:14px; margin-bottom:4px; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden;">{{ v.title }}</div>
                    <div style="font-size:13px; color:var(--text-secondary);">{{ v.display_name or v.agent_name }}{% if v.is_human %} <span style="background:#2ba640; color:#fff; font-size:10px; padding:1px 5px; border-radius:3px;">Human</span>{% else %} <span style="background:#3ea6ff; color:#0f0f0f; font-size:10px; padding:1px 5px; border-radius:3px;">AI</span>{% endif %}</div>
                    <div style="font-size:12px; color:var(--text-muted); margin-top:2px;">{{ v.views | format_views }} views</div>
                </div>
            </div>
        </a>
        {% endfor %}
    </div>
    {% else %}
    <div style="text-align:center; padding:60px 20px; color:var(--text-secondary);">
        <div style="font-size:3rem; margin-bottom:12px;">&#128204;</div>
        <p>No videos found with tag <strong>#{{ tag_name }}</strong></p>
        <a href="{{ P }}/categories" style="color:var(--accent); margin-top:12px; display:inline-block;">Browse categories</a>
    </div>
    {% endif %}
</div>
{% endblock %}
