<h3 class="modalTitle">
  <span ng-show="newattribute"
    >{{ ( 'hpo.data.prepare.correctiontools.correctallvalues.addRule' |
    translate ) + attr.alias }}</span
  >
  <span ng-show="!newattribute"
    >{{ ( 'hpo.data.prepare.correctiontools.correctallvalues.updateRule' |
    translate ) + attr.alias }}</span
  >
</h3>

<div class="modalBody">
  <div class="maintitlehpo row nomargin">
    <div class="col-md-12 nopaddingLeft">
      <div class="col-md-10 nopadding">
        <h4 translate>hpo.common.getvalues</h4>
      </div>
      <div class="col-md-2 nopadding">
        <button
          type="button"
          class="btn btn-info btn-sm pull-right"
          ng-click="getUniqueValues()"
        >
          <span translate>hpo.common.values</span>
        </button>
      </div>
    </div>
  </div>

  <div class="row nomargin">
    <div
      class="col-md-12 marginTop nopaddingLeft"
      ng-if="results && results[0] && results[0].result && results[0].result.length > 0"
    >
      <div css-manipulate='{"mh" : "300px" , "ovy":"auto"}'>
        <table
          class="table table-striped table-bordered text-center"
          ng-if="results[0] && results[0].result && results[0].result.length > 0"
        >
          <thead>
            <tr>
              <th>
                <label translate>common.value</label>
              </th>
              <th>
                <label translate>chart.count</label>
              </th>
              <th><label translate>chart.percentage</label> (%)</th>
            </tr>
          </thead>
          <tbody>
            <tr ng-repeat=" val in results[0].result | orderBy ">
              <td>
                {{ renderValue(val.value , results[0].attribute) }}
              </td>
              <td>
                {{ val.count }}
              </td>
              <td>
                {{ val.percentage }}
              </td>
            </tr>
          </tbody>
        </table>
        <div
          class="alert alert-hpo-info"
          ng-if="val && val.result && val.result.length === 0"
        >
          <translate>hpo.data.prepare.nodata</translate>
        </div>
      </div>
    </div>
    <div
      class="col-md-12 marginTop"
      ng-if="!results || !results[0] || !results[0].result || results[0].result.length === 0 "
    >
      <div class="alert alert-hpo-info">
        <translate ng-if="!results || !results[0]"
          >hpo.common.noaskeddata</translate
        >
        <translate
          ng-if="results && results[0] && results[0].result && results[0].result.length === 0 "
          >hpo.common.nodata</translate
        >
      </div>
    </div>
  </div>

  <form
    id="rulesChoiceCfgModal"
    class="form"
    role="form"
    ng-submit="addOrUpdateRule(currentEditedRule);"
  >
    <div class="maintitlehpo row nomargin">
      <div class="col-md-12 nopadding">
        <h4 translate>hpo.common.rules</h4>
      </div>
    </div>
    <div class="row nomargin">
      <div class="col-md-12 nopadding">
        <div class="col-md-2 nopaddingLeft">
          <abn-tree
            id="rulesChoiceCfgTree"
            tree-data="ruleNameTree"
            tree-control="treeControl"
            initial-selection="undefined"
            on-select="rules_tree_handler(branch)"
          ></abn-tree>
        </div>

        <div class="col-md-10 nopaddingLeft">
          <div
            ng-switch
            on="currentEditedRule.type"
            style="font-size: small;"
            ng-show="currentEditedRule.type"
          >
            <!--INITIALISATIONS-->
            <div ng-switch-when="value">
              <set-rule-hpo-value
                attr="attr"
                fti="fti"
                res="currentEditedRule.result"
                conditions="newcondition.conditions"
                usespecialfilters="usespecialfilters"
              ></set-rule-hpo-value>
            </div>

            <!--INITIALISATIONS-->
            <div ng-switch-when="discretisation">
              <set-rule-hpo-discretisation
                attr="attr"
                fti="fti"
                res="currentEditedRule.result"
                conditions="newcondition.conditions"
                usespecialfilters="usespecialfilters"
              ></set-rule-hpo-discretisation>
            </div>

            <!--INITIALISATIONS-->
            <div ng-switch-when="regroupement">
              <set-rule-hpo-regroupement
                attr="attr"
                fti="fti"
                conditions="newcondition.conditions"
                res="currentEditedRule.result"
                usespecialfilters="usespecialfilters"
              ></set-rule-hpo-regroupement>
            </div>

            <!--INITIALISATIONS-->
            <div ng-switch-when="calculator">
              <set-rule-hpo-calculator
                attr="attr"
                fti="fti"
                res="currentEditedRule.result"
                conditions="newcondition.conditions"
                attributes="attributes"
                usespecialfilters="usespecialfilters"
              ></set-rule-hpo-calculator>
            </div>
          </div>

          <div ng-show="!currentEditedRule.type">
            <div class="col-md-12 nopadding">
              <div class="alert alert-hpo-info marginBottom">
                <translate>hpo.common.nochosenrule</translate>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <hr />

    <div class="row nomargin">
      <div class="col-md-12 text-right nopadding-col marginBottom pull-right">
        <button class="btn btn-primary" type="submit">
          <translate>common.save</translate>
        </button>
      </div>
    </div>
  </form>
</div>
