<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<md-dialog aria-label="Validation Results" ng-cloak>
    <ng-form name="policyForm">
        <div  class="md-toolbar-tools">
            <h4 class="md-title"><span>{{title}} for field {{field.name}}</span></h4>
            <span flex></span>
        </div>
        <md-dialog-content layout="column" style="min-width:500px;padding-top:0px;" layout-padding>

            <div ng-if="policyRules != null && policyRules.length >0 ">
                <md-list>
                    <md-list-item ng-repeat="rule in policyRules track by $index">
                        <span class="md-list-item-text">{{rule.name}}</span>
                        <span class="md-secondary">
                            <md-button class="md-icon-button" ng-click="editPolicy($event,$index,rule)">
                                <ng-md-icon icon="edit" ></ng-md-icon>
                            </md-button>
                              <md-button class="md-icon-button" ng-click="deletePolicyByIndex(index)">
                                  <ng-md-icon icon="delete" ></ng-md-icon>
                              </md-button>
                        </span>
                        <md-divider></md-divider>
                    </md-list-item>
                </md-list>
            </div>

            <div class="edit-form" style="padding-top:0px;">
                 <md-progress-linear md-mode="indeterminate" ng-if="loadingPolicies"></md-progress-linear>

                <md-input-container class="md-block layout-padding-top-bottom" style="margin-top:0px;">
                    <label class="md-container-ignore label-small layout-padding-top">Select Rule Type</label>
                    <md-select ng-model="ruleType" ng-model-options="{trackBy: '$value.name'}" ng-change="onRuleTypeChange()" aria-label="Rule Type">
                        <md-option ng-value="opt" ng-repeat="opt in options">{{ opt.name }}</md-option>
                    </md-select>
                    <span class="hint">{{editRule.description}}</span>
                </md-input-container>
                <thinkbig-policy-input-form the-form="policyForm" rule="editRule" mode="ruleMode" feed="feed"></thinkbig-policy-input-form>

                <div layout="row" layout-align="start stretch" flex>
                    <md-button ng-if="editRule != null" ng-click="cancelEdit($event)">{{cancelText}}</md-button>
                    <span flex></span>
                    <md-button class="md-primary" ng-if="editRule != null" ng-click="addPolicy($event)" ng-disabled="policyForm.$invalid">{{addText}}</md-button>
                </div>
            </div>

        </md-dialog-content>
        <md-dialog-actions layout="row" layout-align="start stretch" flex>
            <span flex></span>
            <md-button ng-click="cancel($event)">
                Cancel
            </md-button>
            <md-button class="md-raised md-primary" ng-click="done($event)" ng-disabled="!pendingEdits || editRule != null || policyForm.$invalid">
                Done
            </md-button>
        </md-dialog-actions>
    </ng-form>
</md-dialog>

