{% extends 'edit.twig' %}

{% block inner_content %}
{% if result %}
<div id="dedit" class="tab-pane fade show active" role="tabpanel" aria-labelledby="domain-edit">
  <form data-id="editdomain_template" class="form-horizontal" role="form" method="post">

    <input type="hidden" value="0" name="active">
    <input type="hidden" value="0" name="backupmx">
    <input type="hidden" value="0" name="gal">
    <input type="hidden" value="0" name="relay_all_recipients">
    <input type="hidden" value="0" name="relay_unknown_only">

    {% if mailcow_cc_role == 'admin' %}
    <div class="row mb-4">
      <label class="control-label col-sm-2" for="max_num_aliases_for_domain">{{ lang.mailbox.template }}</label>
      <div class="col-sm-10">

        <div class="input-group mb-3">
          <input type="text" name="template" class="form-control" aria-label="Text input with dropdown button" value="{{ template.template }}" />
        </div>
      </div>

    </div>
    <div class="row mb-4">
      <label class="control-label col-sm-2">{{ lang.add.tags }}</label>
      <div class="col-sm-10">
        <div class="form-control tag-box">
          <input id="tags" type="text" class="tag-input">
          <span class="btn tag-add"><i class="bi bi-plus-lg"></i></span>
          <input type="hidden" value='{{ template.attributes.tags|json_encode }}' name="tags" class="tag-values" />
        </div>
      </div>
    </div>
    <div class="row mb-2">
      <label class="control-label col-sm-2" for="max_num_aliases_for_domain">{{ lang.edit.max_aliases }}</label>
      <div class="col-sm-10">
        <input type="number" class="form-control" name="max_num_aliases_for_domain" value="{{ template.attributes.max_num_aliases_for_domain }}">
      </div>
    </div>
    <div class="row mb-2">
      <label class="control-label col-sm-2" for="max_num_mboxes_for_domain">{{ lang.edit.max_mailboxes }}</label>
      <div class="col-sm-10">
        <input type="number" class="form-control" name="max_num_mboxes_for_domain" value="{{ template.attributes.max_num_mboxes_for_domain }}">
      </div>
    </div>
    <div class="row mb-2">
      <label class="control-label col-sm-2" for="def_quota_for_mbox">{{ lang.edit.mailbox_quota_def }}</label>
      <div class="col-sm-10">
        <input type="number" class="form-control" name="def_quota_for_mbox" value="{{ (template.attributes.def_quota_for_mbox / 1048576) }}">
      </div>
    </div>
    <div class="row mb-2">
      <label class="control-label col-sm-2" for="max_quota_for_mbox">{{ lang.edit.max_quota }}</label>
      <div class="col-sm-10">
        <input type="number" class="form-control" name="max_quota_for_mbox" value="{{ (template.attributes.max_quota_for_mbox / 1048576) }}">
      </div>
    </div>
    <div class="row mb-4">
      <label class="control-label col-sm-2" for="max_quota_for_domain">{{ lang.edit.domain_quota }}</label>
      <div class="col-sm-10">
        <input type="number" class="form-control" name="max_quota_for_domain" value="{{ (template.attributes.max_quota_for_domain / 1048576) }}">
      </div>
    </div>
    <div class="row">
      <div class="offset-sm-2 col-sm-10">
        <div class="checkbox">
          <label><input type="checkbox" value="1" name="gal"{% if template.attributes.gal == '1' %} checked{% endif %}> {{ lang.edit.gal }}</label>
          <small class="text-muted">{{ lang.edit.gal_info|raw }}</small>
        </div>
      </div>
    </div>
    <div class="row mb-2">
      <div class="offset-sm-2 col-sm-10">
        <div class="checkbox">
          <label><input type="checkbox" value="1" name="active"{% if template.attributes.active == '1' %} checked{% endif %}{% if mailcow_cc_role != 'admin' %} disabled{% endif %}> {{ lang.edit.active }}</label>
        </div>
      </div>
    </div>
    <hr>
    <div class="row">
      <label class="control-label col-sm-2">{{ lang.edit.ratelimit }}</label>
      <div class="col-sm-10">
        <input name="rl_value" type="number" value="{{ template.attributes.rl_value }}" autocomplete="off" class="form-control mb-4" placeholder="{{ lang.ratelimit.disabled }}">
        <select name="rl_frame" class="form-control">
          <option value="s"{% if template.attributes.rl_frame == 's' %} selected{% endif %}>{{ lang.ratelimit.second }}</option>
          <option value="m"{% if template.attributes.rl_frame == 'm' %} selected{% endif %}>{{ lang.ratelimit.minute }}</option>
          <option value="h"{% if template.attributes.rl_frame == 'h' %} selected{% endif %}>{{ lang.ratelimit.hour }}</option>
          <option value="d"{% if template.attributes.rl_frame == 'd' %} selected{% endif %}>{{ lang.ratelimit.day }}</option>
        </select>
      </div>
    </div>
    {% endif %}
    <hr>
    <div class="row mb-2">
      <label class="control-label col-sm-2" for="dkim_selector">{{ lang.admin.dkim_domains_selector }}</label>
      <div class="col-sm-10">
        <input class="form-control" id="dkim_selector" name="dkim_selector" value="{{ template.attributes.dkim_selector }}">
      </div>
    </div>
    <div class="row mb-4">
      <label class="control-label col-sm-2" for="key_size">{{ lang.admin.dkim_key_length }}</label>
      <div class="col-sm-10">
        <select data-style="btn btn-secondary btn-sm" class="form-control" id="key_size" name="key_size">
          <option value="1024" data-subtext="bits" {% if template.attributes.key_size == 1024 %} selected{% endif %}>1024</option>
          <option value="2048" data-subtext="bits" {% if template.attributes.key_size == 2048 %} selected{% endif %}>2048</option>
        </select>
      </div>
    </div>
    <hr>
    <div class="row mb-2">
      <label class="control-label col-sm-2">{{ lang.edit.backup_mx_options }}</label>
      <div class="col-sm-10">
        <div class="checkbox">
          <label><input type="checkbox" value="1" name="backupmx"{% if template.attributes.backupmx == '1' %} checked{% endif %}> {{ lang.edit.relay_domain }}</label>
          <br>
          <label><input type="checkbox" value="1" name="relay_all_recipients"{% if template.attributes.relay_all_recipients == '1' %} checked{% endif %}> {{ lang.edit.relay_all }}</label>
          <p>{{ lang.edit.relay_all_info|raw }}</p>
          <label><input type="checkbox" value="1" name="relay_unknown_only"{% if template.attributes.relay_unknown_only == '1' %} checked{% endif %}> {{ lang.edit.relay_unknown_only }}</label>
          <br>
          <p>{{ lang.edit.relay_transport_info|raw }}</p>
        </div>
      </div>
    </div>
    <hr>
    <div class="row">
      <div class="offset-sm-2 col-sm-10">
        <button class="btn btn-xs-lg d-block d-sm-inline btn-success" data-action="edit_selected" data-id="editdomain_template" data-item="{{ template.id }}" data-api-url='edit/domain/template' data-api-attr='{}' href="#">{{ lang.admin.save }}</button>
      </div>
    </div>
  </form>
</div>
{% else %}
  {{ parent() }}
{% endif %}
{% endblock %}
