
<% if !_.isEmpty(@accounts_fixed): %>
<h2><%- @T('Fixed Email Accounts') %></h2>
<div class="action">
  <div class="action-flow">
    <div class="action-block">
      <ul>
        <% for email_address in @accounts_fixed: %>
          <li><%= email_address.realname %> &lt;<%= email_address.email %>&gt;
        <% end %>
      </ul>
    </div>
  </div>
</div>
<% end %>

<h2><%- @T('Email Accounts') %></h2>

<% if !_.isEmpty(@not_used_email_addresses): %>
<div class="action">
  <div class="action-flow">
    <div class="action-block">
      <%- @T('Notice') %>: <%- @T('Unassigned email addresses, assign them to a channel or delete them.') %></h3>
      <ul class="list">
      <% for email_address in @not_used_email_addresses: %>
        <li class="list-item" data-id="<%= email_address.id %>">
          <div class="list-item-name">
            <a href="#" class="js-emailAddressEdit"><%= email_address.realname %> &lt;<%= email_address.email %>&gt;</a>
          </div>
          <div class="list-item-delete js-emailAddressDelete">
            <%- @Icon('diagonal-cross') %>
          </div>
      <% end %>
      </ul>
    </div>
  </div>
</div>
<% end %>

<% if _.isEmpty(@account_channels): %>
  <p><%- @T('You have no configured account right now.') %></p>
<% else: %>
  <% for channel in @account_channels: %>
  <div class="action <% if channel.active isnt true: %>is-inactive<% end %>" data-id="<%- channel.id %>">
    <div class="action-flow" style="width: 100%;">
      <div class="action-block action-block--flex">
        <div class="horizontal">
          <h3><%- @Icon('status', channel.status_in + " inline") %> <%- @T('Inbound') %></h3>
          <% if channel.preferences.editable isnt false: %>
            <div class="js-editInbound btn btn--text space-left"><%- @T('Edit') %></div>
          <% end %>
        </div>
        <table class="key-value">
          <tr>
            <td><%- @T('User') %>
            <td><%= channel.options.inbound.options.user %>
            <% if channel.options.inbound.options.folder: %>
              (<%- @T('Folder') %>: <%= channel.options.inbound.options.folder %>)
            <% end %>
          <tr>
            <td><%- @T('Host') %>
            <td><%= channel.options.inbound.options.host %>
          <tr>
            <td><%- @T('Protocol') %>
            <td><%= channel.options.inbound.adapter %>
        </table>

        <% if !_.isEmpty(channel.last_log_in): %>
        <div class="alert alert--danger">
          <%= channel.last_log_in %>
        </div>
        <% end %>

        <hr>

        <h3><%- @T('Destination Group') %></h3>
        <a href="#" class="js-channelGroupChange <% if channel.group.active is false: %>alert alert--danger<% end %>">
          <% groupName = '' %>
          <% if channel.group.displayName: %>
            <% groupName = channel.group.displayName() %>
          <% else: %>
            <% groupName = channel.group %>
          <% end %>
          <% if channel.group.active is false: %>
            <%- @T('%s is inactive, please select a active one.', groupName) %>
          <% else: %>
            <%= groupName %>
          <% end %>
        </a>
      </div>
      <div class="action-block action-block--flex">
        <div class="horizontal">
          <h3><%- @Icon('status', channel.status_out + " inline") %> <%- @T('Outbound') %></h3>
          <% if channel.preferences.editable isnt false: %>
            <div class="js-editOutbound btn btn--text space-left"><%- @T('Edit') %></div>
          <% end %>
        </div>
        <table class="key-value">
        <% if channel.options.outbound && channel.options.outbound.options: %>
          <tr>
            <td><%- @T('User') %>
            <td><%= channel.options.outbound.options.user %>
          <tr>
            <td><%- @T('Host') %>
            <td><%= channel.options.outbound.options.host %>
        <% end %>
          <tr>
            <td><%- @T('Protocol') %>
            <td><%= channel.options.outbound.adapter %>
        </table>

        <% if !_.isEmpty(channel.last_log_out): %>
        <div class="alert alert--danger">
          <%= channel.last_log_out %>
        </div>
        <% end %>

        <hr>

        <h3><%- @T('Email Address') %></h3>
        <ul class="list">
        <% if !_.isEmpty(channel.email_addresses): %>
          <% for email_address in channel.email_addresses: %>
            <li class="list-item" data-id="<%= email_address.id %>">
              <div class="list-item-name"><%= email_address.email %></div>
              <div class="btn btn--text js-emailAddressEdit space-left space-right"><%- @T('Edit') %></div>
              <% if channel.email_addresses.length > 1: %>
              <div class="list-item-delete js-emailAddressDelete">
                <%- @Icon('diagonal-cross') %>
              </div>
              <% end %>
          <% end %>
        <% else: %>
          <li class="list-item"><%- @T('none') %>
        <% end %>
        </ul>
        <a class="text-muted js-emailAddressNew" href="#">+ <%- @T('Add') %></a>

      </div>
    </div>
    <div class="action-controls">
      <% if channel.active is true: %>
        <div class="btn btn--secondary js-channelDisable"><%- @T('Disable') %></div>
      <% else: %>
        <div class="btn btn--secondary js-channelEnable"><%- @T('Enable') %></div>
      <% end %>
      <div class="btn btn--danger btn--secondary js-channelDelete"><%- @T('Delete') %></div>
    </div>
  </div>
  <% end %>
<% end %>

<a class="btn btn--success js-channelNew"><%- @T('New') %></a>

<% if !_.isEmpty(@notification_channels) && !App.Config.get('system_online_service'): %>
  <h2><%- @T('Email Notification') %></h2>
  <% for channel in @notification_channels: %>
    <div class="action" data-id="<%- channel.id %>">
      <div class="action-flow action-flow--row">
        <div class="action-block action-block--flex">
          <div class="horizontal">
            <h3><%- @Icon('status', channel.status_out + " inline") %> <%- @T('Outbound') %></h3>
            <div class="btn btn--text js-editNotificationOutbound space-left"><%- @T('Edit') %></div>
          </div>

          <table class="key-value">
          <% if channel.options.outbound && channel.options.outbound.options: %>
            <tr>
              <td><%- @T('User') %>
              <td><%= channel.options.outbound.options.user %>
            <tr>
              <td><%- @T('Host') %>
              <td><%= channel.options.outbound.options.host %>
          <% end %>
            <tr>
              <td><%- @T('Protocol') %>
              <td><%= channel.options.outbound.adapter %>
          </table>

          <% if channel.status_in is 'error': %>
            <div class="alert alert--danger"><%= channel.last_log_in %></div>
          <% end %>
          <% if channel.status_out is 'error': %>
            <div class="alert alert--danger"><%= channel.last_log_out %></div>
          <% end %>
        </div>
        <div class="action-block action-block--flex">
          <h3><%- @T('Email Address') %></h3>
          <ul class="list">
            <li class="list-item"><%= @config.notification_sender %>
          </ul>
        </div>
      </div>
    </div>
  <% end %>
<% end %>
