{% extends "base.html" %}
{% load i18n %}

{% block title %}{% trans "Price Monitor — Settings" %}{% endblock %}

{% block content %}
<div class="max-w-xl mx-auto px-4 py-6">

  <div class="flex items-center gap-3 mb-6">
    <a href="{% url 'pricemon-dashboard' %}"
       class="text-gray-400 hover:text-gray-600 transition">
      <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
      </svg>
    </a>
    <h1 class="text-xl font-bold text-gray-900">{% trans "Price Monitor Settings" %}</h1>
  </div>

  {% if messages %}
    {% for msg in messages %}
    <div class="mb-4 px-4 py-3 rounded-lg text-sm
      {% if msg.tags == 'error' %}bg-red-50 text-red-700 border border-red-100
      {% else %}bg-green-50 text-green-700 border border-green-100{% endif %}">
      {{ msg }}
    </div>
    {% endfor %}
  {% endif %}

  <div class="bg-white rounded-lg shadow-sm border border-gray-100 p-6">
    <h2 class="text-sm font-semibold text-gray-700 mb-4">{% trans "Telegram Notifications" %}</h2>

    <form method="post" class="space-y-5">
      {% csrf_token %}

      {% for field in form %}
      <div>
        <label class="block text-sm font-medium text-gray-700 mb-1">{{ field.label }}</label>
        {{ field }}
        {% if field.help_text %}
          <p class="text-xs text-gray-400 mt-1">{{ field.help_text }}</p>
        {% endif %}
        {% for error in field.errors %}
          <p class="text-xs text-red-600 mt-1">{{ error }}</p>
        {% endfor %}
      </div>
      {% endfor %}

      <div class="flex items-center gap-3 pt-2">
        <button type="submit"
                class="px-5 py-2 bg-indigo-600 text-white text-sm font-medium rounded-lg hover:bg-indigo-700 transition">
          {% trans "Save" %}
        </button>
        <a href="?test_telegram=1"
           class="px-4 py-2 bg-blue-50 text-blue-700 text-sm font-medium rounded-lg hover:bg-blue-100 transition">
          {% trans "Send Test Message" %}
        </a>
      </div>
    </form>
  </div>

  <p class="mt-4 text-xs text-gray-400">
    {% trans "These credentials apply to all price drop alerts. Create a bot via" %}
    <a href="https://t.me/BotFather" target="_blank" class="text-indigo-400 hover:underline">@BotFather</a>
    {% trans "and get your chat ID from" %}
    <a href="https://t.me/userinfobot" target="_blank" class="text-indigo-400 hover:underline">@userinfobot</a>.
  </p>

</div>
{% endblock %}
