{% import "base_widget.html" as b %}

{%- macro view(name, field, prefix) %}
  <h3>{{ name }}</h3>
  {% if field.value %}
  <p>{{ field.value.from }} - {{ field.value.to }} {{field.value.currency}}</p>
  {% else %}
  <p>{{ field.empty }}</p>
  {% endif %}

{%- endmacro %}

{%- macro table_view(name, field, prefix) %}
{% if field.value %}
  {{ field.value.from }} - {{ field.value.to }} {{field.value.currency}}
{% else %}
  {{ field.empty }}
{% endif %}
{%- endmacro %}


{%- macro edit(name, field, prefix) %}
{{kwargs.____}} {#XXX#}
<div class="control-group {% if field.errors %}error{% endif %}">
    <label for="form_{{ name }}_id">{{ field.title }}</label>
    <input name="{{ prefix }}{{ name }}__from" type="text" id="form_{{ name }}_id"
       value="{{ field.value.from or field.empty }}" {% if field.required %}required{% endif %}
       pattern="\d+(\.\d{2})?" placeholder="120.00" maxlength="6" /> - 
    <input name="{{ prefix }}{{ name }}__to" type="text" id="form_{{ name }}_id"
       value="{{ field.value.to or field.empty }}" {% if field.required %}required{% endif %}
       pattern="\d+(\.\d{2})?" placeholder="240.00" maxlength="6" />
    <select name="{{ prefix }}{{ name }}__currency" type="text" id="form_{{ name }}_id">
      <option value=""> - </option>
      {% for currency, name in [['UAH', 'грн.'],['USD', 'дол.'], ['EUR', 'евро']] %}
      <option {% if currency == field.value.currency %}selected{%endif%}
      value="{{currency}}">{{name}}</option>
      {% endfor %}
    </select>
    {% if field.errors %}<span class="help-inline">{{ field.errors|join(', ') }}</span>{% endif %}
    {% if field.description %}<span class="help-block">{{ field.description }}</span>{% endif %}
</div>
{%- endmacro %}
