{% extends "base.html" %}
{% import "partials/detail_cards.html" as detail %}
{% import "partials/icons.html" as icons %}
{% import "partials/image_section.html" as img %}
{% block title %}Brewlog · {{ cup.roast_name }} at {{ cup.cafe_name }}{% endblock %}
{% block description %}
  {{ cup.roast_name }}
  by {{ cup.roaster_name }} at {{ cup.cafe_name }}, {{ cup.cafe_city }}.
{% endblock %}
{% block og_title %}{{ cup.roast_name }} at {{ cup.cafe_name }} — Brewlog{% endblock %}
{% block og_description %}
  {{ cup.roast_name }}
  by {{ cup.roaster_name }} at {{ cup.cafe_name }}, {{ cup.cafe_city }}.
{% endblock %}
{% block head %}
  <meta property="og:image" content="{{ base_url }}/static/og-image.png" />
{% endblock %}
{% block content %}
  <header class="flex items-start justify-between gap-4">
    <div class="flex items-center gap-4 min-w-0">
      {{ img::image_thumbnail("cup", cup.id, image_url, is_authenticated) }}
      <div class="flex flex-col gap-1 min-w-0">
        <h1 class="text-2xl font-semibold truncate">{{ cup.roast_name }}</h1>
        <p class="text-sm text-text-secondary">
          <a
            href="/data?type=cups"
            class="text-accent hover:text-accent-hover transition"
            >Cups</a
          >
          · {{ cup.created_date }}
        </p>
      </div>
    </div>
  </header>
  {% if image_url.is_some() %}
    {{ img::lightbox_script() }}
  {% endif %}

  {# ── Coffee + map ── #}
  <div class="grid gap-6 md:grid-cols-2">
    {{ detail::coffee_card(cup.roast_name, cup.roaster_name, cup.origin, cup.origin_flag, cup.region, cup.producer, cup.process, cup.tasting_notes, roaster_slug, roast_slug) }}
    {{ detail::map_with_legend(cup.map_countries, cup.map_max, cup.legend_entries) }}
  </div>

  {# ── Roaster & cafe ── #}
  <div class="grid gap-6 md:grid-cols-2">
    {{ detail::roaster_card(cup.roaster_name, cup.roaster_country, cup.roaster_country_flag, cup.roaster_city, cup.roaster_homepage, roaster_slug) }}

    <div class="rounded-lg border bg-surface p-5">
      <h2 class="text-lg font-semibold text-text mb-4">Cafe</h2>
      <dl class="grid grid-cols-2 gap-x-4 gap-y-3 text-sm">
        <div>
          <dt class="text-text-muted">Name</dt>
          <dd class="font-medium">
            <a
              href="/cafes/{{ cafe_slug }}"
              class="text-accent hover:text-accent-hover transition"
              >{{ cup.cafe_name }}</a
            >
          </dd>
        </div>
        <div>
          <dt class="text-text-muted">Country</dt>
          <dd class="font-medium text-text">
            {% if !cup.cafe_country_flag.is_empty() %}
              <span class="mr-1">{{ cup.cafe_country_flag }}</span>
            {% endif %}{{ cup.cafe_country }}
          </dd>
        </div>
        <div>
          <dt class="text-text-muted">City</dt>
          <dd class="font-medium text-text">{{ cup.cafe_city }}</dd>
        </div>
        <div>
          <dt class="text-text-muted">Location</dt>
          <dd class="font-medium">
            <a
              href="{{ cup.cafe_map_url }}"
              target="_blank"
              rel="noreferrer noopener"
              class="text-accent hover:text-accent-hover transition"
              >View on Map</a
            >
          </dd>
        </div>
        {% if let Some(url) = cup.cafe_website %}
          <div>
            <dt class="text-text-muted">Website</dt>
            <dd class="font-medium">
              <a
                href="{{ url }}"
                target="_blank"
                rel="noreferrer noopener"
                class="text-accent hover:text-accent-hover transition"
                >Visit Website</a
              >
            </dd>
          </div>
        {% endif %}
      </dl>
    </div>
  </div>

  {% if is_authenticated %}
    {{ detail::edit_delete_buttons(edit_url, "cup", "/api/v1/cups", cup.id) }}
  {% endif %}
{% endblock %}
