<div class="header">
  <div class="title">
    <div class="submenu">
      <a ui-sref="motions.motion.list" class="btn btn-sm btn-default">
        <i class="fa fa-angle-double-left fa-lg"></i>
        <translate>Back to overview</translate>
      </a>
    </div>
    <h1 translate>Import motions</h1>
  </div>
</div>

<div class="details">

  <h3 translate>Select a CSV file</h3>
  <csv-import change="onCsvChange(csv)" config="csvConfig"></csv-import>

  <h4 translate>Please note:</h4>
  <ul class="indentation">
      <li><translate>Required comma or semicolon separated values with these column header names in the first row</translate>:<br>
        <code>
          <translate>Identifier</translate>,
          <translate>Title</translate>,
          <translate>Text</translate>,
          <translate>Reason</translate>,
          <translate>Submitter</translate>,
          <translate>Category</translate>,
          <translate>Origin</translate>
        </code>
      <li translate>Identifier, reason, submitter, category and origin are optional and may be empty.
      <li translate>Only double quotes are accepted as text delimiter (no single quotes).
      <li><a id="downloadLink" href="" ng-click="downloadCSVExample()" translate>Download CSV example file</a>
  </ul>

  <div ng-if="motions.length">
    <h3 translate>Preview</h3>
    <div class="scroll-x-container">
      <table class="table table-striped table-bordered table-condensed">
        <thead>
          <tr>
            <th>
            <th>#
            <th translate>Identifier
            <th translate>Title
            <th translate>Text
            <th translate>Reason
            <th translate>Submitter
            <th translate>Category
            <th translate>Origin</th>
        <tbody ng-repeat="motion in motions">
          <tr>
            <td class="minimum"
                ng-class="{ 'text-danger': motion.importerror, 'text-success': motion.imported }">
              <span ng-if="motion.importerror">
                <i class="fa fa-exclamation-triangle fa-lg"></i>
              </span>
              <span ng-if="!motion.importerror && !motion.imported" class="pointer">
                <i class="fa fa-check-circle-o fa-lg" ng-if="motion.selected" ng-click="motion.selected=false; calcStats();"></i>
                <i class="fa fa-circle-o fa-lg" ng-if="!motion.selected" ng-click="motion.selected=true; calcStats();"></i>
              </span>
              <span ng-if="motion.imported">
                <i class="fa fa-check-circle fa-lg"></i>
              </span>
            <td>
              {{ $index + 1 }}
            <td ng-class="{ 'text-danger': motion.identifier_error }">
              <span ng-if="motion.identifier_error" title="{{ motion.identifier_error | translate }}">
                <i class="fa fa-exclamation-triangle pointer"></i>
              </span>
              {{ motion.identifier }}
            <td ng-class="{ 'text-danger': motion.title_error }">
              <span ng-if="motion.title_error" title="{{ motion.title_error | translate }}">
                <i class="fa fa-exclamation-triangle"></i>
              </span>
              {{ motion.title }}
            <td ng-class="{ 'text-danger': motion.text_error }">
              <span ng-if="motion.text_error" title="{{ motion.text_error | translate }}">
                <i class="fa fa-exclamation-triangle"></i>
              </span>
              <span class="import-preview" ng-bind-html="motion.text | limitTo:90 | trusted"></span>
              {{ motion.text.length > 90 ? '...' : '' }}
            <td>
              <span class="import-preview" ng-bind-html="motion.reason | limitTo:90 | trusted"></span>
              {{ motion.reason.length > 90 ? '...' : '' }}
            <td ng-class="{ 'text-warning': motion.submitter_create }">
              <span ng-if="motion.submitter_create" title="{{ motion.submitter_create | translate }}">
                <i class="fa fa-plus-circle"></i>
              </span>
              {{ motion.submitter }}
            <td ng-class="{ 'text-warning': motion.category_create }">
              <span ng-if="motion.category_create" title="{{ motion.category_create | translate }}">
                <i class="fa fa-plus-circle"></i>
              </span>
              {{ motion.category }}
            <td>{{ motion.origin | limitTo:30 }}{{ motion.origin.length > 30 ? '...' : '' }}
      </table>
    </div>

    <div class="text-danger">
      <i class="fa fa-exclamation-triangle"></i>
      {{ motionsWillNotBeImported }}
      <translate>motions will be not imported.</translate>
    </div>
    <div>
      <i class="fa fa-check-circle-o fa-lg"></i>
      {{ motionsWillBeImported }}
      <translate>motions will be imported.</translate>
    </div>
    <div ng-repeat="motion in motionsImported = (motions | filter:{imported:true})"></div>
    <div ng-if="motionsImported.length > 0" class="text-success">
      <hr class="smallhr">
      <i class="fa fa-check-circle fa-lg"></i>
      {{ motionsImported.length }}
      <translate>motions were successfully imported.</translate>
      (<translate>Users created</translate>: {{ usersCreated }},
      <translate>Categories created</translate>: {{ categoriesCreated }})
    </div>

    <div class="spacer">
      <button ng-click="clear()" class="btn btn-default btn-sm" translate>
        Clear preview
      </button>
      <button ng-if="!csvImporting && motionsWillBeImported > 0" ng-click="import()" class="btn btn-primary btn-sm" translate>
        Import {{ motionsWillBeImported }} motions
      </button>
    </div>
    <div class="spacer">
      <a ng-if="csvimported" ui-sref="motions.motion.list" class="btn btn-default btn-sm">
        <i class="fa fa-angle-double-left fa-lg"></i>
        <translate>Back to motions overview</translate>
      </a>
    </div>
  </div>
</div>
