<?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"
    xmlns:rsrc="OGo:url">

  
    <md-card style="overflow: hidden">
      <md-toolbar>
        <div class="md-toolbar-tools">
            <md-button ng-click="toggleCenter()"
                       class="sg-icon-button md-primary md-hue-1 hide show-gt-xs"
                       aria-hidden="true">
              <md-tooltip ng-if="centerIsClose" md-direction="bottom">{{ ::'Reduce' | loc }}</md-tooltip>
              <md-tooltip ng-else="centerIsClose" md-direction="bottom">{{ ::'Expand' | loc }}</md-tooltip>
              <md-icon>{{ centerIsClose ? 'fullscreen_exit' : 'fullscreen' }}</md-icon>
            </md-button>
          <md-icon class="material-icons sg-icon-toolbar-bg">contacts</md-icon>
          <div class="sg-md-title md-flex" ng-bind-html="editor.card.$fullname({html: true})"><!-- computed fullname --></div>
          <md-button class="sg-icon-button"
                     label:aria-label="Cancel"
                     ng-click="editor.cancel()">
            <md-icon>close</md-icon>
          </md-button>
          <md-button class="sg-icon-button"
                     label:aria-label="Reset"
                     ng-click="editor.reset(contactForm)">
            <md-icon>undo</md-icon>
          </md-button>
          <md-button class="sg-icon-button"
                     label:aria-label="Save"
                     type="submit"
                     ng-disabled="contactForm.$pristine || contactForm.$invalid || contactForm.$submitted || editor.duplicatedCard"
                     ng-click="editor.save(contactForm)">
            <md-icon>save</md-icon>
          </md-button>
        </div>
      </md-toolbar>
      <md-card-actions flex-none="flex-none" layout="row" layout-align="end center">
        <div class="md-flex"><!-- spacer --></div>
      </md-card-actions>
      <md-card-content>
        <form class="md-inline-form" name="contactForm"
              ng-submit="editor.save(contactForm)">

          <!-- contact editor -->
          <div ng-if="editor.card.$isCard()">
            <md-input-container class="md-block md-flex">
              <label>
                <var:string label:value="Display"/>
              </label>
              <input type="text" ng-maxlength="255" ng-model="editor.card.c_cn"/>
            </md-input-container>

            <div id="contact-identification" class="sg-fieldset" layout="row" layout-xs="column">
              <md-input-container flex="40" flex-xs="100">
                <label>
                  <var:string label:value="Firstname"/>
                </label>
                <input type="text" ng-maxlength="255" ng-model="editor.card.c_givenname"/>
              </md-input-container>
              <md-input-container flex="40" flex-xs="100">
                <label>
                  <var:string label:value="Lastname"/>
                </label>
                <input type="text" ng-maxlength="255" ng-model="editor.card.c_sn"/>
              </md-input-container>
              <md-input-container flex="20" flex-xs="100">
                <label>
                  <var:string label:value="Nickname"/>
                </label>
                <input type="text" ng-model="editor.card.nickname"/>
              </md-input-container>
            </div>

            <div id="contact-identification" class="sg-fieldset" layout="row" layout-xs="column">
              <md-input-container flex="40" flex-xs="100">
                <label>
                  <var:string label:value="Organization"/>
                </label>
                <input type="text" ng-model="editor.card.org"/>
              </md-input-container>
              <md-input-container flex="40" flex-xs="100">
                <label>
                  <var:string label:value="Title"/>
                </label>
                <input type="text" ng-model="editor.card.title"/>
              </md-input-container>
              <md-input-container flex="20" flex-xs="100">
                <label>
                  <var:string label:value="Role"/>
                </label>
                <input type="text" ng-model="editor.card.role"/>
              </md-input-container>
            </div>

            <!-- other orgs -->
            <div class="attr" ng-repeat="org in editor.card.orgs">
              <div layout="row" layout-align="start center">
                <md-button class="md-icon-button" type="button" ng-click="editor.removeAttribute(contactForm, 'orgs', $index)">
                  <md-icon>remove_circle</md-icon>
                </md-button>
                <md-input-container class="md-flex">
                  <label>
                    <var:string label:value="Organization Unit"/>
                  </label>
                  <input type="text" ng-model="org.value"
                         sg-focus-on="org_{{$index}}"/>
                </md-input-container>
              </div>
            </div>
            <div class="md-layout-margin" layout="row" layout-align="start center">
              <md-button class="md-icon-button" type="button" ng-click="editor.addOrg($event)">
                <md-icon>add_circle</md-icon>
              </md-button>
              <label class="button-label">
                <var:string label:value="Add Organizational Unit"/>
              </label>
            </div>

            <!-- categories -->
            <md-chips ng-model="editor.card.categories"
                      md-transform-chip="editor.transformCategory($chip)">
              <md-chip-template>{{$chip.value}}</md-chip-template>
              <md-autocomplete
                  md-selected-item="editor.categories.selected"
                  md-search-text="editor.categories.searchText"
                  md-items="category in editor.card.constructor.filterCategories(editor.categories.searchText)"
                  md-min-length="0"
                  label:placeholder="Add a category">
                <span md-highlight-text="editor.categories.searchText">{{category.value}}</span>
              </md-autocomplete>
            </md-chips>

            <!-- S/MIME certificate -->
            <div class="section" ng-if="editor.card.hasCertificate">
              <div class="pseudo-input-container">
                <label class="pseudo-input-label"><var:string label:value="Security"/></label>
                <sg-block-toggle class="hide-print" layout="column">
                  <md-list-item class="sg-button-toggle">
                    <p class="md-flex">
                      <md-icon rsrc:md-svg-src="img/certificate.svg"><!-- certificate --></md-icon>
                      {{::'S/MIME Certificate' | loc}}
                    </p>
                    <md-button class="md-warn"
                               ng-click="editor.removeCertificate(contactForm)">
                      <var:string label:value="Uninstall"/>
                    </md-button>
                    <md-icon class="sg-icon-toggle">expand_more</md-icon>
                  </md-list-item>
                  <div class="sg-block-toggle">
                    <div class="md-margin" md-whiteframe="3">
                      <div class="md-padding" layout="row" layout-wrap="layout-wrap">
                        <div flex="50" flex-xs="100">
                          <div class="sg-padded--bottom" ng-if="editor.certificate.emails.length">
                            <div class="md-subhead md-default-theme md-fg md-primary"
                                 ng-bind="::'Email Addresses' | loc"><!-- Email Addresses --></div>
                            <div class="pseudo-input-field md-body-1"
                                 ng-repeat="email in ::editor.certificate.emails"
                                 ng-bind="email"><!-- email address --></div>
                          </div>
                          <div class="md-subhead md-default-theme md-fg md-primary"
                               ng-bind="::'Subject Name' | loc"><!-- Subject Name --></div>
                          <div ng-repeat="field in editor.certificate.subject">
                            <div class="pseudo-input-label" ng-bind="field[0] | loc"><!-- label --></div>
                            <div class="pseudo-input-field md-body-1" ng-bind="field[1]"><!-- value --></div>
                          </div>
                        </div>
                        <div flex="50" flex-xs="100">
                          <div class="md-subhead md-default-theme md-fg md-primary"
                               ng-bind="::'Issuer' | loc"><!-- Issuer --></div>
                          <div ng-repeat="field in editor.certificate.issuer">
                            <div class="pseudo-input-label" ng-bind="field[0] | loc"><!-- label --></div>
                            <div class="pseudo-input-field md-body-1" ng-bind="field[1]"><!-- value --></div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </sg-block-toggle>
              </div>
            </div>

            <!-- emails -->
            <div class="section">
              <div class="attr" ng-repeat="email in editor.card.emails">
                <div layout="row" layout-align="start center">
                  <md-button class="md-icon-button" type="button" ng-click="editor.removeAttribute(contactForm, 'emails', $index)">
                    <md-icon>remove_circle</md-icon>
                  </md-button>
                  <md-input-container flex="20">
                    <md-select ng-model="email.type" label:placeholder="Type">
                      <md-option ng-repeat="type in ::editor.allEmailTypes" ng-value="type">{{ type.capitalize() | loc }}</md-option>
                    </md-select>
                  </md-input-container>
                  <md-input-container class="md-flex">
                    <label>
                      <var:string label:value="Email Address"/>
                    </label>
                    <input type="text" ng-model="email.value"
                           ng-pattern="editor.emailRE"
                           sg-focus-on="email_{{$index}}"/>
                  </md-input-container>
                </div>
              </div>
              <div class="md-layout-margin" layout="row" layout-align="start center">
                <md-button class="md-icon-button" type="button" ng-click="editor.addEmail()">
                  <md-icon>add_circle</md-icon>
                </md-button>
                <label class="button-label">
                  <var:string label:value="New Email Address"/>
                </label>
              </div>
            </div>

            <!-- screenname -->
            <div class="section">
              <div layout="row" layout-align="start center" ng-show="editor.card.c_screenname != null">
                <md-button class="md-icon-button" type="button" ng-click="editor.removeAttribute(contactForm, 'c_screenname', -1)">
                  <md-icon>remove_circle</md-icon>
                </md-button>
                <md-input-container class="md-flex">
                  <label>
                    <var:string label:value="Screen Name"/>
                  </label>
                  <input type="text" ng-model="editor.card.c_screenname"/>
                </md-input-container>
              </div>
              <div class="md-layout-margin" layout="row" layout-align="start center" ng-show="editor.card.c_screenname == null">
                <md-button class="md-icon-button" type="button" ng-click="editor.addScreenName($event)">
                  <md-icon>add_circle</md-icon>
                </md-button>
                <label class="button-label">
                  <var:string label:value="Add Screen Name"/>
                </label>
              </div>
            </div>

            <!-- birthday -->
            <div class="section">
              <div layout="row" layout-align="start end" ng-show="editor.card.birthday">
                <md-button class="md-icon-button" type="button" ng-click="editor.removeAttribute(contactForm, 'birthday', -1)">
                  <md-icon>remove_circle</md-icon>
                </md-button>
                <div class="pseudo-input-container">
                  <label class="pseudo-input-label">
                    <var:string label:value="Birthday"/>
                  </label>
                  <md-datepicker class="pseudo-input-field"
                                 ng-model="editor.card.birthday"><!-- birthday --></md-datepicker>
                </div>
              </div>
              <div class="md-layout-margin" layout="row" layout-align="start center" ng-hide="editor.card.birthday">
                <md-button class="md-icon-button" type="button" ng-click="editor.addBirthday()">
                  <md-icon>add_circle</md-icon>
                </md-button>
                <label class="button-label">
                  <var:string label:value="Add Birthday"/>
                </label>
              </div>
            </div>

            <!-- phones -->
            <div class="section">
              <div class="attr" ng-repeat="phone in editor.card.phones">
                <div layout="row" layout-align="start center">
                  <md-button class="md-icon-button" type="button" ng-click="editor.removeAttribute(contactForm, 'phones', $index)">
                    <md-icon>remove_circle</md-icon>
                  </md-button>
                  <md-input-container flex="20">
                    <md-select ng-model="phone.type" label:placeholder="Type">
                      <md-option ng-repeat="type in ::editor.allTelTypes" ng-value="type">{{ type.capitalize() | loc }}</md-option>
                    </md-select>
                  </md-input-container>
                  <md-input-container class="md-flex">
                    <label>
                      <var:string label:value="Phone Number"/>
                    </label>
                    <input type="text" ng-model="phone.value"
                           sg-focus-on="phone_{{$index}}"/>
                  </md-input-container>
                </div>
              </div>
              <div layout="row" layout-align="start center">
                <md-button class="md-icon-button" type="button" ng-click="editor.addPhone()">
                  <md-icon>add_circle</md-icon>
                </md-button>
                <label class="button-label">
                  <var:string label:value="New Phone Number"/>
                </label>
              </div>
            </div>

            <!-- urls -->
            <div class="section">
              <div class="attr" ng-repeat="url in editor.card.urls">
                <div layout="row" layout-align="start center">
                  <md-button class="md-icon-button" type="button" ng-click="editor.removeAttribute(contactForm, 'urls', $index)">
                    <md-icon>remove_circle</md-icon>
                  </md-button>
                  <md-input-container flex="20">
                    <md-select ng-model="url.type" label:placeholder="Type">
                      <md-option ng-repeat="type in ::editor.allUrlTypes" ng-value="type">{{ type.capitalize() | loc }}</md-option>
                    </md-select>
                  </md-input-container>
                  <md-input-container class="md-flex">
                    <label>
                      <var:string label:value="URL"/>
                    </label>
                    <input type="url" ng-model="url.value" sg-focus-on="url_{{$index}}"/>
                  </md-input-container>
                </div>
              </div>
              <div class="md-layout-margin" layout="row" layout-align="start center">
                <md-button class="md-icon-button" type="button" ng-click="editor.addUrl()">
                  <md-icon>add_circle</md-icon>
                </md-button>
                <label class="button-label">
                  <var:string label:value="New URL"/>
                </label>
              </div>
            </div>

            <!-- addresses -->
            <div class="section">
              <div class="attr" ng-repeat="address in editor.card.addresses">
                <div layout="row" layout-align="start center">
                  <md-button class="md-icon-button" type="button" ng-click="editor.removeAttribute(contactForm, 'addresses', $index)">
                    <md-icon>remove_circle</md-icon>
                  </md-button>
                  <div class="md-flex" layout="column">
                    <div layout="row">
                      <md-input-container flex="20">
                        <md-select ng-model="address.type" label:placeholder="Type">
                          <md-option ng-repeat="type in ::editor.allAddressTypes" ng-value="type">{{ type.capitalize() | loc }}</md-option>
                        </md-select>
                      </md-input-container>
                      <md-input-container class="md-flex">
                        <label>
                          <var:string label:value="street"/>
                        </label>
                        <input type="text" ng-model="address.street"
                               sg-focus-on="address_{{$index}}"/>
                      </md-input-container>
                    </div>
                    <div layout="row">
                      <md-input-container flex="20">
                        <label>
                          <var:string label:value="Postoffice"/>
                        </label>
                        <input type="text" ng-model="address.postoffice"/>
                      </md-input-container>
                      <md-input-container class="md-flex">
                        <label>
                          <var:string label:value="street (continued)"/>
                        </label>
                        <input type="text" ng-model="address.street2"/>
                      </md-input-container>
                    </div>
                    <div layout="row">
                      <md-input-container flex="50" flex-xs="100">
                        <label>
                          <var:string label:value="City"/>
                        </label>
                        <input type="text" ng-model="address.locality"/>
                      </md-input-container>
                      <md-input-container flex="50" flex-xs="100">
                        <label>
                          <var:string label:value="Region"/>
                        </label>
                        <input type="text" ng-model="address.region"/>
                      </md-input-container>
                    </div>
                    <div layout="row" layout-align="start center">
                      <md-input-container flex="50" flex-xs="100">
                        <label>
                          <var:string label:value="Country"/>
                        </label>
                        <input type="text" ng-model="address.country"/>
                      </md-input-container>
                      <md-input-container class="md-flex">
                        <label>
                          <var:string label:value="Postal Code"/>
                        </label>
                        <input type="text" ng-model="address.postalcode"/>
                      </md-input-container>
                    </div>
                  </div>
                </div>
              </div>
              <div class="md-layout-margin" layout="row" layout-align="start center">
                <md-button class="md-icon-button" type="button" ng-click="editor.addAddress()">
                  <md-icon>add_circle</md-icon>
                </md-button>
                <label class="button-label">
                  <var:string label:value="New Address"/>
                </label>
              </div>
            </div>

	    <!-- custom fields -->
            <div class="section">
              <div class="attr" ng-repeat="(key, value) in editor.card.customFields">
                <div layout="row" layout-align="start center">
                  <md-button class="md-icon-button" type="button" ng-click="editor.deleteCustomField(key)">
                    <md-icon>remove_circle</md-icon>
                  </md-button>
                  <md-input-container flex="20">
                     <label>
                       <var:string label:value="Type"/>
                     </label>
                     <input type="text" readonly="readonly" ng-value="key"/>
                  </md-input-container>
                  <md-input-container class="md-flex">
                    <label>
                      <var:string label:value="Custom Value"/>
                    </label>
                    <input type="text" ng-model="editor.card.customFields[key]"/>
                  </md-input-container>
                </div>
              </div>
              <div class="md-layout-margin" layout="row"
                   layout-align="start center" ng-show="editor.canAddCustomField()">
                <md-button class="md-icon-button" type="button" ng-click="editor.addCustomField()">
                  <md-icon>add_circle</md-icon>
                </md-button>
                <label class="button-label">
                  <var:string label:value="New Custom Value"/>
                </label>
              </div>
            </div>

            <!-- note -->
            <md-input-container class="md-block md-flex"
                                ng-repeat="note in editor.card.notes">
              <label><var:string label:value="Note"/></label>
              <textarea ng-model="note.value"><!-- note --></textarea>
            </md-input-container>
          </div>

          <!-- list editor -->
          <div ng-if="editor.card.$isList()">
            <md-input-container>
              <label>
                <var:string label:value="Display"/>
              </label>
              <input type="text" ng-maxlength="255" ng-model="editor.card.c_cn"/>
            </md-input-container>

            <md-input-container>
              <label>
                <var:string label:value="Nickname"/>
              </label>
              <input type="text" ng-model="editor.card.nickname"/>
            </md-input-container>

            <md-input-container>
              <label>
                <var:string label:value="Description"/>
              </label>
              <textarea ng-model="editor.card.description"><!-- note --></textarea>
            </md-input-container>

            <!-- list members -->
            <div class="pseudo-input-container">
              <label class="pseudo-input-label">
                <var:string label:value="Members"/>
              </label>
              <md-contact-chips
                  class="sg-chips-autocomplete"
                  ng-model="editor.card.refs"
                  ng-change="contactForm.$setDirty()"
                  md-contacts="editor.userFilter($query, editor.card.refs)"
                  md-contact-name="$$fullname"
                  md-contact-image="$$image"
                  md-contact-email="$$email"
                  md-require-match="true"
                  filter-selected="false"
                  label:placeholder="Add Member"><!-- members --></md-contact-chips>
            </div>
          </div>
        </form>
      </md-card-content>
      <md-card-actions class="md-default-theme md-bg md-warn md-padding sg-dialog-message ng-hide"
                         ng-show="editor.duplicatedCard">
        <div class="sg-padded--bottom" ng-bind-html="::'A similar card already exists. Would you like to save it anyway?' | loc | txt2html"><!-- warning --></div>
        <div class="md-flex">
          <md-icon>person</md-icon> {{ editor.duplicatedCard.$shortFormat() }}
        </div>
      </md-card-actions>
      <md-card-actions class="ng-hide" layout="row" layout-align="end center" ng-show="editor.duplicatedCard">
        <md-button type="button"
                   ng-click="editor.edit(contactForm)">
          <var:string label:value="Edit"/>
        </md-button>
        <md-button class="md-warn" type="button"
                   label:aria-label="Save"
                   ng-disabled="contactForm.$invalid || contactForm.$submitted"
                   ng-click="editor.save(contactForm, { ignoreDuplicate: true })">
          <var:string label:value="Save"/>
        </md-button>
      </md-card-actions>
    </md-card>
</container>
