{% 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 · {{ brew.roast_name }}{% endblock %}
{% block description %}
  {{ brew.roast_name }}
  by {{ brew.roaster_name }} — {{ brew.coffee_weight }} coffee,
  {{ brew.water_volume }} water.
{% endblock %}
{% block og_title %}{{ brew.roast_name }} — Brewlog{% endblock %}
{% block og_description %}
  {{ brew.roast_name }}
  by {{ brew.roaster_name }} — {{ brew.coffee_weight }} coffee,
  {{ brew.water_volume }} water.
{% 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("brew", brew.id, image_url, is_authenticated) }}
      <div class="flex flex-col gap-1 min-w-0">
        <h1 class="text-2xl font-semibold truncate">{{ brew.roast_name }}</h1>
        <p class="text-sm text-text-secondary">
          <a
            href="/data?type=brews"
            class="text-accent hover:text-accent-hover transition"
            >Brews</a
          >
          · {{ brew.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(brew.roast_name, brew.roaster_name, brew.origin, brew.origin_flag, brew.region, brew.producer, brew.process, brew.tasting_notes, roaster_slug, roast_slug) }}
    {{ detail::map_with_legend(brew.map_countries, brew.map_max, brew.legend_entries) }}
  </div>

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

    <div class="rounded-lg border bg-surface p-5">
      <h2 class="text-lg font-semibold text-text mb-4">Gear</h2>
      <dl class="grid grid-cols-2 gap-x-4 gap-y-3 text-sm">
        <div>
          <dt class="text-text-muted">Grinder</dt>
          <dd class="font-medium text-text">{{ brew.grinder_name }}</dd>
        </div>
        <div>
          <dt class="text-text-muted">Brewer</dt>
          <dd class="font-medium text-text">{{ brew.brewer_name }}</dd>
        </div>
        {% if let Some(fp) = brew.filter_paper_name %}
          <div>
            <dt class="text-text-muted">Filter Paper</dt>
            <dd class="font-medium text-text">{{ fp }}</dd>
          </div>
        {% endif %}
      </dl>
    </div>
  </div>

  {# ── Recipe ── #}
  <div class="grid gap-6 md:grid-cols-2">
    <div class="rounded-lg border bg-surface p-5">
      <h2 class="text-lg font-semibold text-text mb-4">Recipe</h2>
      <dl class="grid grid-cols-2 gap-x-4 gap-y-3 text-sm">
        <div>
          <dt class="text-text-muted">Coffee</dt>
          <dd class="font-medium text-text">{{ brew.coffee_weight }}</dd>
        </div>
        <div>
          <dt class="text-text-muted">Water</dt>
          <dd class="font-medium text-text">{{ brew.water_volume }}</dd>
        </div>
        <div>
          <dt class="text-text-muted">Temperature</dt>
          <dd class="font-medium text-text">{{ brew.water_temp }}</dd>
        </div>
        <div>
          <dt class="text-text-muted">Grind Setting</dt>
          <dd class="font-medium text-text">{{ brew.grind_setting }}</dd>
        </div>
        {% if let Some(time) = brew.brew_time %}
          <div>
            <dt class="text-text-muted">Brew Time</dt>
            <dd class="font-medium text-text">{{ time }}</dd>
          </div>
        {% endif %}
        {% if !brew.quick_notes_label.is_empty() %}
          <div>
            <dt class="text-text-muted">Notes</dt>
            <dd class="font-medium text-text">{{ brew.quick_notes_label }}</dd>
          </div>
        {% endif %}
      </dl>
    </div>
  </div>

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