{% extends "base.html" %}
{% import "partials/icons.html" as icons %}
{% import "partials/image_section.html" as img %}
{% import "partials/detail_cards.html" as detail_cards %}
{% block title %}Brewlog · Edit Roaster{% endblock %}

{% block content %}
  <header class="flex flex-col gap-2">
    <h1 class="text-3xl font-semibold">Edit Roaster</h1>
    <p class="max-w-2xl text-sm text-text-secondary">Update roaster details.</p>
  </header>

  <section class="rounded-lg border bg-surface p-5">
    <form
      class="flex flex-col gap-4 pb-16 md:pb-0"
      data-signals:_submitting="false"
      data-signals:_submit-error="''"
      data-signals:_name="'{{ name }}'"
      data-signals:_country="'{{ country }}'"
      data-signals:_city="'{{ city }}'"
      data-signals:_homepage="'{{ homepage }}'"
      data-on:submit="$_submitting = true; $_submitError = ''; @put('/api/v1/roasters/{{ id }}', {contentType: 'form'})"
      data-on:datastar-fetch="if (!$_submitting) return;
        if (evt.detail.type === 'finished') { $_submitting = false; sessionStorage.setItem('toast', 'Roaster updated') }
        else if (evt.detail.type === 'error') { $_submitting = false; $_submitError = 'Failed to save changes.' }"
    >
      <div class="grid gap-4 sm:grid-cols-2">
        <label class="flex flex-col gap-1 text-sm">
          <span
            class="text-xs font-semibold text-text-muted uppercase tracking-wide"
            >Name*</span
          >
          <input
            type="text"
            name="name"
            required
            aria-required="true"
            class="input-field"
            placeholder="Example Coffee Roasters"
            data-bind:_name
          />
        </label>
        <label class="flex flex-col gap-1 text-sm">
          <span
            class="text-xs font-semibold text-text-muted uppercase tracking-wide"
            >Country*</span
          >
          <input
            type="text"
            name="country"
            required
            aria-required="true"
            class="input-field"
            placeholder="United States"
            data-bind:_country
          />
        </label>
        <label class="flex flex-col gap-1 text-sm">
          <span
            class="text-xs font-semibold text-text-muted uppercase tracking-wide"
            >City</span
          >
          <input
            type="text"
            name="city"
            class="input-field"
            placeholder="Portland"
            data-bind:_city
          />
        </label>
        <label class="flex flex-col gap-1 text-sm">
          <span
            class="text-xs font-semibold text-text-muted uppercase tracking-wide"
            >Homepage</span
          >
          <input
            type="url"
            name="homepage"
            class="input-field"
            placeholder="https://example.coffee"
            data-bind:_homepage
          />
        </label>
      </div>
      {{ img::deferred_upload_with_preview("edit-roaster-image", "Roaster Image", "roaster", id, image_url) }}
      {{ detail_cards::edit_form_actions() }}
    </form>
  </section>
{% endblock %}
