<?xml version='1.0' standalone='yes'?>
<container
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:var="http://www.skyrix.com/od/binding"
    xmlns:const="http://www.skyrix.com/od/constant"
    xmlns:label="OGo:label">
  <md-dialog flex="60" flex-sm="80" flex-xs="100">
    <form name="eventForm" ng-submit="editor.save(eventForm)">
      <md-toolbar>
        <div class="md-toolbar-tools">
          <md-icon class="material-icons sg-icon-toolbar-bg">assignment_turned_in</md-icon>
          <!-- summary -->
          <md-icon ng-if="editor.component.classification == 'confidential'">visibility_off</md-icon>
          <md-icon ng-if="editor.component.classification == 'private'">vpn_key</md-icon>
          <md-input-container class="md-block md-flex">
            <label><var:string label:value="Title"/></label>
            <input type="text"
                   class="md-title"
                   md-autofocus="true"
                   ng-model="editor.component.summary"
                   required="required"/>
          </md-input-container>
        </div>
      </md-toolbar>
      <md-dialog-content class="sg-has-form-sections">
        <div class="sg-form-section">
          <div layout="row" layout-xs="column">
            <!-- location -->
            <md-input-container flex="50" flex-xs="100">
              <label><var:string label:value="Location"/></label>
              <input type="text" ng-model="editor.component.location"/>
            </md-input-container>
            <!-- calendar -->
            <md-input-container flex="50" flex-xs="100">
              <label><var:string label:value="Calendar"/></label>
              <md-select ng-model="editor.component.destinationCalendar">
                <md-option ng-repeat="calendar in editor.destinationCalendars()"
                           ng-value="calendar.id">
                  <div layout="row" layout-align="start center">
                    <div class="sg-color-chip"
                         ng-class="calendar.getClassName('bg')"><!-- color --></div>
                    {{calendar.name}}
                  </div>
                </md-option>
              </md-select>
            </md-input-container>
          </div>
          <!-- comment -->
          <md-input-container class="md-block md-flex">
            <label><var:string label:value="Description"/></label>
            <textarea ng-model="editor.component.comment"><!-- comment --></textarea>
          </md-input-container>
          <!-- categories -->
          <md-chips ng-model="editor.component.categories">
            <md-chip-template>
              <span class="sg-chip-color">
                <span ng-style="{ 'background-color': editor.component.constructor.$categories[$chip] }"><!-- color --></span>
              </span>
              <span>{{$chip}}</span>
            </md-chip-template>
           <md-autocomplete
                md-selected-item="editor.categories.selected"
                md-search-text="editor.categories.searchText"
                md-items="category in editor.component.constructor.filterCategories(editor.categories.searchText) | orderBy"
                md-min-length="0"
                label:placeholder="Add a category">
              <div layout="row" layout-align="start center">
                <div class="sg-color-chip"
                     ng-style="{ 'background-color': editor.component.constructor.$categories[category] }"><!-- color --></div>
                <div md-highlight-text="editor.categories.searchText" md-highlight-flags="^i">{{category}}</div>
              </div>
            </md-autocomplete>
          </md-chips>
          <div layout="row" layout-align="space-between center" layout-wrap="layout-wrap">
            <!-- classification -->
            <md-radio-group class="sg-padded--top"
                            layout="row"
                            ng-model="editor.component.classification">
              <md-radio-button class="sg-padded--right" value="public">
                <var:string label:value="label_Public"/>
              </md-radio-button>
              <md-radio-button class="sg-padded--right" value="confidential">
                <var:string label:value="label_Confidential"/>
              </md-radio-button>
              <md-radio-button class="sg-padded--right" value="private">
                <var:string label:value="label_Private"/>
              </md-radio-button>
            </md-radio-group>
            <!-- priority -->
            <div class="pseudo-input-container" flex="50" flex-xs="100">
              <label class="pseudo-input-label"><var:string label:value="Priority"/></label>
              <md-slider-container>
                <md-slider class="md-flex"
                         md-discrete="true"
                         ng-model="editor.component.priority"
                         step="1"
                         min="0"
                         max="9"
                         label:aria-label="Priority"><!-- slider --></md-slider>
                <span>{{editor.priorityLevel()}}</span>
              </md-slider-container>
            </div>
          </div>
          <!-- attach urls -->
          <div ng-repeat="attach in editor.component.attachUrls">
            <div layout="row" layout-align="start center">
              <md-button class="md-icon-button" type="button" ng-click="editor.component.deleteAttachUrl($index)">
                <md-icon>remove_circle</md-icon>
              </md-button>
              <md-input-container class="md-block md-flex">
                <label>
                  <var:string label:value="URL"/>
                </label>
                <input type="text" ng-model="attach.value"
                       sg-focus-on="attachUrl_{{$index}}"/>
              </md-input-container>
            </div>
          </div>
          <div layout="row" layout-align="start center">
            <md-button class="md-icon-button" type="button" ng-click="editor.addAttachUrl($event)">
              <md-icon>add_circle</md-icon>
            </md-button>
            <label class="button-label">
              <var:string label:value="Attach"/>
            </label>
          </div>
        </div>

        <div class="sg-form-section">
          <!-- start -->
          <div ng-if="editor.component.start">
            <div class="pseudo-input-container">
              <label class="pseudo-input-label"><var:string label:value="From"/></label>
            </div>
            <div layout="row" layout-align="start center" layout-wrap="layout-wrap">
              <md-button class="md-icon-button" type="button" ng-click="editor.removeStartDate(eventForm)">
                <md-icon>remove_circle</md-icon>
              </md-button>
              <md-datepicker ng-model="editor.component.start"
                             ng-change="editor.adjustStartTime()"
                             label:md-placeholder="From"> <!-- date picker--></md-datepicker>
              <sg-timepicker ng-model="editor.startTime"
                             ng-required="editor.component.start"
                             ng-change="editor.adjustStartTime()"><!-- time picker --></sg-timepicker>
            </div>
          </div>
          <div class="md-layout-margin" layout="row" layout-align="start center" ng-hide="editor.component.start">
            <md-button class="md-icon-button" type="button" ng-click="editor.addStartDate(eventForm)">
              <md-icon>add_circle</md-icon>
            </md-button>
            <label class="button-label"><var:string label:value="Add From"/></label>
          </div>
          <!-- due -->
          <div ng-if="editor.component.due">
            <div class="pseudo-input-container">
              <label class="pseudo-input-label"><var:string label:value="Due"/></label>
            </div>
            <div layout="row" layout-align="start center" layout-wrap="layout-wrap">
              <md-button class="md-icon-button" type="button" ng-click="editor.removeDueDate(eventForm)">
                <md-icon>remove_circle</md-icon>
              </md-button>
              <md-datepicker ng-model="editor.component.due"
                             ng-change="editor.adjustDueTime()"
                             label:md-placeholder="Due"><!-- date picker--></md-datepicker>
              <sg-timepicker ng-model="editor.dueTime"
                             ng-required="editor.component.due"
                             ng-change="editor.adjustDueTime()"><!-- time picker --></sg-timepicker>
            </div>
          </div>
          <div class="md-layout-margin" layout="row" layout-align="start center" ng-hide="editor.component.due">
            <md-button class="md-icon-button" type="button" ng-click="editor.addDueDate(eventForm)">
              <md-icon>add_circle</md-icon>
            </md-button>
            <label class="button-label"><var:string label:value="Add Due"/></label>
          </div>
          <!-- status -->
          <div layout="row" layout-align="start center">
            <md-input-container flex="50">
              <label><var:string label:value="Status"/></label>
              <md-select ng-model="editor.component.status">
                <var:foreach list="statusList" item="item">
                  <md-option var:value="item"><var:string value="itemStatusText"/></md-option>
                </var:foreach>
              </md-select>
            </md-input-container>
              <md-datepicker ng-show="editor.component.status == 'completed'"
                             ng-model="editor.component.completed"
                             label:md-placeholder="status_COMPLETED"><!-- date picker--></md-datepicker>
          </div>
          <div layout="row" layout-align="center center"
               ng-show="editor.component.enablePercentComplete()">
            <md-slider class="md-flex"
                       md-discrete="true"
                       ng-model="editor.component.percentComplete"
                       step="5"
                       min="0"
                       max="100"
                       label:aria-label="% complete"><!-- slider --></md-slider>
            <div flex="50" class="sg-padded--left">{{editor.component.percentComplete}} <var:string label:value="% complete"/></div>
          </div>
        </div>
        <!-- repeat -->
        <div class="sg-form-section"
             ng-show="editor.component.start">
          <div layout="row" layout-align="start center">
            <md-input-container class="md-block md-flex">
              <label><var:string label:value="Repeat"/></label>
              <md-select ng-model="editor.component.repeat.frequency" ng-disabled="editor.component.occurrenceId">
                <md-option ng-value="frequency[0]" ng-repeat="frequency in ::editor.frequencies()" ng-bind-html="frequency[1]"><!-- frequency --></md-option>
              </md-select>
            </md-input-container>
            <md-button type="button" class="sg-icon-button"
                       label:aria-label="repeat_CUSTOM"
                       ng-disabled="editor.component.occurrenceId"
                       ng-show="editor.component.repeat.frequency != 'never'"
                       ng-click="editor.toggleRecurrenceEditor()">
              <md-icon ng-class="{'md-rotate-45': editor.showRecurrenceEditor}">add</md-icon>
            </md-button>
          </div>
          <div ng-show="editor.showRecurrenceEditor" flex-offset="5">
            <var:component className="UIxRecurrenceEditor" />
          </div>
          <!-- end repeat -->
          <div layout="row">
            <md-input-container class="md-block" flex="50" flex-xs="100"
                                ng-show="editor.component.repeat.frequency != 'never'">
              <label><var:string label:value="End Repeat"/></label>
              <md-select ng-model="editor.component.repeat.end"
                         ng-disabled="editor.component.occurrenceId">
                <md-option value="never"><var:string label:value="Never"/></md-option>
                <md-option value="count"><var:string label:value="After"/></md-option>
                <md-option value="until"><var:string label:value="On Date"/></md-option>
              </md-select>
            </md-input-container>
            <md-input-container class="md-block md-input-number"
                                ng-show="editor.component.repeat.end == 'count'">
              <label><var:string label:value="times"/></label>
              <input type="number" min="1" label:aria-label="times" ng-model="editor.component.repeat.count"/>
            </md-input-container>
            <md-input-container ng-show="editor.component.repeat.end == 'until'">
              <md-datepicker name="repeat_until"
                             ng-model="editor.component.repeat.until"
                             md-min-date="editor.component.end"
                             label:md-placeholder="On Date"><!-- date picker --></md-datepicker>
              <div ng-messages="eventForm.repeat_until.$error">
                <div ng-message="mindate"><var:string label:value="validate_untilbeforeend"/></div>
              </div>
            </md-input-container>
          </div>
        </div>
        <div class="sg-form-section"
             ng-show="editor.component.start || editor.component.due">
          <!-- reminder -->
          <md-checkbox ng-model="editor.component.$hasAlarm"
                       label:aria-label="Reminder"
                       ng-change="editor.onAlarmChange(eventForm)">
            <var:string label:value="Reminder"/>
          </md-checkbox>
          <div flex-offset="5"
               ng-show="editor.component.$hasAlarm">
            <var:component className="UIxReminderEditor" />
          </div>
        </div>
      </md-dialog-content>
      <!-- cancel/reset/save -->
      <md-dialog-actions>
        <md-button type="button" ng-click="editor.cancel(eventForm)">
          <var:string label:value="Cancel"/>
        </md-button>
        <md-button type="button"
                   ng-disabled="eventForm.$pristine"
                   ng-click="editor.reset(eventForm)">
          <var:string label:value="Reset"/>
        </md-button>
        <md-button class="md-primary md-hue-3" type="submit"
                   ng-disabled="eventForm.$pristine || eventForm.$invalid || eventForm.$submitted">
          <var:string label:value="Save"/>
        </md-button>
      </md-dialog-actions>
    </form>
  </md-dialog>
</container>
