<li class="flexrow item">
  <label class="generic-label item-field-label-long">Automatisation ? </label>
  <input type="checkbox" name="system.isautomated" {{checked system.isautomated}} {{#unless isEditMode}}disabled{{/unless}} />
</li>

{{#if system.isautomated}}
<li class="flexrow item">
  <ul>
    {{#each system.automations as |automation key|}}
      <li class="automation-item item flexrow">
        <hr>
      </li>
      <li class="automation-item item flexrow" data-automation-field="eventtype" data-automation-index="{{key}}">
        <label class="generic-label item-field-label-medium">Evènement</label>
        <select class="item-field-label-long automation-edit-field" type="text"
          name="system.automations.{{key}}.eventtype"
          data-automation-index="{{key}}" data-automation-field="eventtype"
          value="{{automation.eventtype}}" data-dtype="String" {{#unless ../isEditMode}}disabled{{/unless}}>
          {{selectOptions @root.config.optionsAutomationEvent selected=automation.eventtype valueAttr="key" labelAttr="label"}}
        </select>

        <label class="generic-label item-field-label-medium">&nbsp;</label>

        {{#if ../isEditMode}}
        <button type="button" data-action="deleteAutomation" data-automation-index="{{key}}"
          class="item-control item-field-label-medium" title="Supprimer">
          <i class="fas fa-trash"></i>
        </button>
        {{/if}}

      </li>

      {{#if (eq automation.eventtype "on-drop")}}
      <li class="automation-item item flexrow">
        <label class="generic-label item-field-label-long">Compétence/Attribut</label>
        <input type="text" class="item-field-label-medium automation-edit-field"
          name="system.automations.{{key}}.competence"
          data-automation-index="{{key}}" data-automation-field="competence"
          value="{{automation.competence}}" data-dtype="String" {{#unless ../isEditMode}}disabled{{/unless}} />
      </li>
      <li class="automation-item item flexrow">
        <label class="generic-label item-field-label-long">Valeur minimum</label>
        <input type="text" class="item-field-label-medium automation-edit-field"
          name="system.automations.{{key}}.minLevel"
          data-automation-index="{{key}}" data-automation-field="minLevel"
          value="{{automation.minLevel}}" data-dtype="Number" {{#unless ../isEditMode}}disabled{{/unless}} />
      </li>
      {{/if}}

      {{#if (eq automation.eventtype "bonus-permanent")}}
      <li class="automation-item item flexrow">
        <label class="generic-label item-field-label-long">Désignation</label>
        <select class="item-field-label-long automation-edit-field" type="text"
          name="system.automations.{{key}}.bonusname"
          data-automation-index="{{key}}" data-automation-field="bonusname"
          value="{{automation.bonusname}}" data-dtype="String" {{#unless ../isEditMode}}disabled{{/unless}}>
          {{selectOptions @root.config.optionsBonusPermanent selected=automation.bonusname valueAttr="key" labelAttr="label"}}
        </select>
      </li>
      <li class="automation-item item flexrow">
        <label class="generic-label item-field-label-long">Bonus</label>
        <input type="text" class="item-field-label-medium automation-edit-field"
          name="system.automations.{{key}}.bonus"
          data-automation-index="{{key}}" data-automation-field="bonus"
          value="{{automation.bonus}}" data-dtype="Number" {{#unless ../isEditMode}}disabled{{/unless}} />
      </li>
      {{/if}}

      {{#if (eq automation.eventtype "prepare-roll")}}
      <li class="automation-item item flexrow">
        <label class="generic-label item-field-label-long">Compétence/Attribut</label>
        <input type="text" class="item-field-label-medium automation-edit-field"
          name="system.automations.{{key}}.competence"
          data-automation-index="{{key}}" data-automation-field="competence"
          value="{{automation.competence}}" data-dtype="String" {{#unless ../isEditMode}}disabled{{/unless}} />
      </li>
      <li class="automation-item item flexrow">
        <label class="generic-label item-field-label-long">Bonus</label>
        <input type="text" class="item-field-label-medium automation-edit-field"
          name="system.automations.{{key}}.bonus"
          data-automation-index="{{key}}" data-automation-field="bonus"
          value="{{automation.bonus}}" data-dtype="Number" {{#unless ../isEditMode}}disabled{{/unless}} />
      </li>
      <li class="automation-item item flexrow">
        <label class="generic-label item-field-label-long">Coût en BA</label>
        <input type="text" class="item-field-label-medium automation-edit-field"
          name="system.automations.{{key}}.baCost"
          data-automation-index="{{key}}" data-automation-field="baCost"
          value="{{automation.baCost}}" data-dtype="Number" {{#unless ../isEditMode}}disabled{{/unless}} />
      </li>
      {{/if}}

    {{/each}}

  </ul>
</li>

{{#if isEditMode}}
<li class="flexrow item">
  <button type="button" data-action="addAutomation" class="chat-card-button">Ajouter une automatisation</button>
</li>
{{/if}}

{{/if}}