{% load i18n %}{% load intelligence_extras %}
{% comment %} Header, niche identity + total gap count. {% endcomment %}
{{ result.niche.name }}
{{ result.niche.slug }}
{% if result.gaps %} {{ result.gaps|length }} {% translate "gap" %}{{ result.gaps|length|pluralize }} {% endif %}
{% if not result.gaps %}

{% translate "No gaps found for this niche." %}

{% else %} {% comment %} One card per gap. Stacked vertically; the outer result panel scrolls if the page gets long. {% endcomment %}
{% for gap in result.gaps %}
{% comment %} Header row, gap_type pill + opportunity score badge {% endcomment %}
{% if gap.gap_type %} {% if gap.gap_type == 'underserved' %} {% elif gap.gap_type == 'stale' %} {% else %} {% endif %} {{ gap.gap_type }} {% endif %}
{% translate "Opportunity" %} {{ gap.opportunity_score }}
{% comment %} Canonical title, what's currently dominating the niche {% endcomment %}
{% translate "Current top title" %}
{{ gap.canonical_title }}
{% comment %} Why the model thinks this is a gap {% endcomment %} {% if gap.explanation %}
{% translate "Why it's a gap" %}

{{ gap.explanation }}

{% endif %} {% comment %} Suggested angles, the actionable output {% endcomment %} {% if gap.suggested_angles %}
{% translate "Try these angles" %}
    {% for angle in gap.suggested_angles %}
  • → {{ angle }}
  • {% endfor %}
{% endif %} {% comment %} Component breakdown. Demand / supply / recency are 0–1 floats. Render as three small bars with raw percentages. Tooltips explain each because the direction isn't obvious (high demand = good, but low supply / low recency = also good, they signal undersupplied or stale niches). {% endcomment %} {% if gap.components %}
{% translate "Signals" %}
{% translate "Demand" %}{% translate ": search volume + trends interest. Higher is better." %}
{% translate "Supply" %}{% translate ": how saturated the niche is with existing content." %} {% translate "Lower" %} {% translate "is better (less competition)." %}
{% translate "Recency" %}{% translate ": how fresh the top-ranking videos are." %} {% translate "Lower" %} {% translate "is better (existing content is older, ripe for refresh)." %}
{% with c=gap.components %}
{% translate "Demand" %}
{{ c.demand|pretty_percent:0 }}
{% translate "Supply" %}
{{ c.supply|pretty_percent:0 }}
{% translate "Recency" %}
{{ c.recency|pretty_percent:0 }}
{% endwith %}
{% endif %} {% comment %} Evidence chips. Small at-a-glance stats: newest competitor age, trends appearances, residual outliers. Skip nulls. {% endcomment %} {% if gap.evidence %} {% with ev=gap.evidence %}
{% if ev.newest_quality_video_age_days is not None %} {% translate "Newest top video:" %} {{ ev.newest_quality_video_age_days }}{% translate "d old" %} {% endif %} {% if ev.trends_appearance_count %} {{ ev.trends_appearance_count }} {% translate "trend signal" %}{{ ev.trends_appearance_count|pluralize }} {% endif %} {% if ev.residual_outlier_count %} {{ ev.residual_outlier_count }} {% translate "overperformer" %}{{ ev.residual_outlier_count|pluralize }} {% endif %} {% if ev.autocomplete_rank %} {% translate "Autocomplete rank #" %}{{ ev.autocomplete_rank }} {% endif %}
{% comment %} Top competitors, collapsible via native
. No JS, CSP-safe, keyboard-accessible. Default closed so the card stays compact unless the user opts in. {% endcomment %} {% if ev.top_competitors %}
{% translate "Top" %} {{ ev.top_competitors|length }} {% translate "competitor" %}{{ ev.top_competitors|length|pluralize }} {% translate "ranking now" %}
    {% for c in ev.top_competitors %}
  • {{ c.title }}
    {{ c.channel_title }} {% if c.subscriber_count %}· {{ c.subscriber_count|humanize_count }} {% translate "subs" %}{% endif %} {% if c.view_count is not None %}· {{ c.view_count|humanize_count }} {% translate "views" %}{% endif %} {% if c.age_days is not None %}· {{ c.age_days }}{% translate "d old" %}{% endif %}
  • {% endfor %}
{% endif %} {% if ev.related_queries %}
{% translate "Related searches" %}
{% for q in ev.related_queries %} {{ q }} {% endfor %}
{% endif %} {% endwith %} {% endif %}
{% endfor %}
{% endif %}