<div class="panel panel-default lt-module-page__content-panel">
    <div class="panel-heading">{{'Site repository settings' | translate}}</div>
    <div class="panel-body">
        <form name="repositoryForm">
            <div class="radio">
                <label>
                    <input type="radio" ng-model="settings.repositoryType" value="2" /> {{'No repositories - Sites are created as subsites' | translate}}
                </label>
            </div>
            <div class="radio">
                <label ng-click="validatePrefix()">
                    <input type="radio" ng-model="settings.repositoryType" value="1" /> {{'Sitecollection repositories - Sites are created across sitecollections' | translate}}<br />
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" ng-model="settings.repositoryType" value="3" /> {{'Sitecollection - Sites are created as sitecollections' | translate}}<br />
                </label>
            </div>
            <div class="alert alert-warning" role="alert" ng-show="settings.repositoryType === '3'">
                {{"Warning: Using this capability will make site provisioning much slower as site collection is created on demand. Also note that having many site collections with Wizdom installed will increase upgrade time." | translate}}
            </div>

            <div class="form-group text-warning" ng-if="wizdomEnvironmentIsOnPrem">
                <i class="glyphicon glyphicon-warning-sign"></i>
                {{"Farm level configuration is required to enable sitecollection creation in an on-premises environment" | translate}}.
                {{"Please read documentation 'On-Premises: Sitecollection Creation'" | translate}}.
            </div>
            <div class="form-group" ng-class='{"has-error":(repositoryForm.prefix.$invalid || repositoryForm.managedPath.$invalid)}'>
                <label>{{'Url' | translate}}</label>
                <div ng-if="settings.repositoryType == 1 || settings.repositoryType == 3">
                    <div>{{'Managed Path' | translate}}</div>
                    <select class="form-control" ng-model="managedPathSelect" ng-change="settings.managedPath = managedPathSelect">
                        <option value="sites">sites</option>
                        <option value="teams">teams</option>
                        <option ng-if="wizdomEnvironmentIsOnPrem" value="custom">custom</option>
                    </select>
                    <div ng-show="managedPathSelect == 'custom'">
                        <div>{{'Write a custom path' | translate}}</div>
                        <input type="text" class="form-control" name="managedPath" ng-model="settings.managedPath" ng-pattern="/^[a-zA-Z0-9]*$/" required="" />
                    </div>
                </div>
                <div>
                    <div>{{'Url prefix' | translate}}</div>
                    <input type="text" class="form-control" name="prefix" placeholder='{{settings.repositoryType == 1 ? defaultPrefix : ""}}' ng-model="settings.prefix" ng-model-options="{ debounce: 500 }" ng-change="validatePrefix()" />
                    <p ng-if="settings.repositoryType == 1" class="help-block">{{'Result ex.' | translate}} https://tenant.sharepoint.com/<b>{{settings.managedPath}}</b>/<b>{{settings.prefix || defaultPrefix}}</b>1 </p>
                    <p ng-if="settings.repositoryType == 2" class="help-block">{{'Result ex.' | translate}} {{instance.url}}/<span ng-if="settings.prefix"><b>{{settings.prefix}}</b></span>[workspace title]</p>
                    <p ng-if="settings.repositoryType == 3" class="help-block">{{'Result ex.' | translate}} https://tenant.sharepoint.com/<b>{{settings.managedPath}}</b>/<span ng-if="settings.prefix"><b>{{settings.prefix}}</b></span>[workspace title] </p>
                    <div ng-hide="settings.repositoryType != 1 || repositorySettingPrefixIsValid" class="alert alert-danger" role="alert">
                        {{"Prefix is not unique across all Workspace instances and types" | translate}}
                    </div>
                </div>
            </div>            
            <div class="form-group" ng-if="settings.repositoryType == 1" ng-class='{"has-error":repositoryForm.maxSitesPerCollection.$invalid}'>
                <label>{{'Max number of sites per sitecollection' | translate}}</label>
                <input type="number" class="form-control" name="maxSitesPerCollection" ng-model="settings.maxSitesPerCollection" required="" />
            </div>
            <div class="form-group" ng-if="settings.repositoryType == 1" ng-class='{"has-error":repositoryForm.emptySlotsThreshold.$invalid}'>
                <label>{{'Number of empty slots (potential sites) to keep ready for creation' | translate}}</label>
                <input type="number" class="form-control" name="emptySlotsThreshold" ng-model="settings.emptySlotsThreshold" required="" />
            </div>
            <div class="form-group" ng-if="settings.repositoryType != 2" ng-class='{"has-error":repositoryForm.maxSizeInMB.$invalid}'>
                <label>{{'Max sitecollection size (Mb)' | translate}}</label>
                <input type="number" class="form-control" name="maxSizeInMB" ng-model="settings.maxSizeInMB" required="" />
            </div>
            <div class="form-group" ng-if="settings.repositoryType != 2" ng-class='{"has-error":repositoryForm.owner.$invalid}'>
                <label>{{'Sitecollection owner' | translate}}</label>
                <input type="text" class="form-control" style="display:none;" name="owner" ng-model="settings.owner" />
                <div wizdom365-principalpicker principals="settings.ownerPrincipals" add-fn="addOwner(principal)" remove-fn="removeOwner(principal)" mode="users" allowmultiple="false" class="principal-picker"></div>
            </div>
            <div ng-if="settings.repositoryType == 3">
                <label>{{'Features' | translate}}</label>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" ng-model="settings.enablePublishing"> {{'Publishing enabled' | translate}}
                    </label>
                </div>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" ng-model="settings.sendNotificationEmails"> {{'Send notification emails' | translate}}
                    </label>
                </div>
                <br />
            </div>
            <div class="form-group" ng-if="settings.repositoryType != 2">
                <label>{{'Timezone' | translate}}</label>
                <select class="form-control" ng-model="settings.timezoneId">
                    <option value="39">(UTC-12:00) International Date Line West</option>
                    <option value="95">(UTC-11:00) Coordinated Universal Time-11</option>
                    <option value="15">(UTC-10:00) Hawaii</option>
                    <option value="14">(UTC-09:00) Alaska</option>
                    <option value="78">(UTC-08:00) Baja California</option>
                    <option value="13">(UTC-08:00) Pacific Time (US and Canada)</option>
                    <option value="38">(UTC-07:00) Arizona</option>
                    <option value="77">(UTC-07:00) Chihuahua, La Paz, Mazatlan</option>
                    <option value="12">(UTC-07:00) Mountain Time (US and Canada)</option>
                    <option value="55">(UTC-06:00) Central America</option>
                    <option value="11">(UTC-06:00) Central Time (US and Canada)</option>
                    <option value="37">(UTC-06:00) Guadalajara, Mexico City, Monterrey</option>
                    <option value="36">(UTC-06:00) Saskatchewan</option>
                    <option value="35">(UTC-05:00) Bogota, Lima, Quito</option>
                    <option value="10">(UTC-05:00) Eastern Time (US and Canada)</option>
                    <option value="34">(UTC-05:00) Indiana (East)</option>
                    <option value="88">(UTC-04:30) Caracas</option>
                    <option value="91">(UTC-04:00) Asuncion</option>
                    <option value="9">(UTC-04:00) Atlantic Time (Canada)</option>
                    <option value="81">(UTC-04:00) Cuiaba</option>
                    <option value="33">(UTC-04:00) Georgetown, La Paz, Manaus, San Juan</option>
                    <option value="65">(UTC-04:00) Santiago</option>
                    <option value="28">(UTC-03:30) Newfoundland</option>
                    <option value="8">(UTC-03:00) Brasilia</option>
                    <option value="85">(UTC-03:00) Buenos Aires</option>
                    <option value="32">(UTC-03:00) Cayenne, Fortaleza</option>
                    <option value="60">(UTC-03:00) Greenland</option>
                    <option value="90">(UTC-03:00) Montevideo</option>
                    <option value="103">(UTC-03:00) Salvador</option>
                    <option value="96">(UTC-02:00) Coordinated Universal Time-02</option>
                    <option value="30">(UTC-02:00) Mid-Atlantic</option>
                    <option value="29">(UTC-01:00) Azores</option>
                    <option value="53">(UTC-01:00) Cape Verde Is.</option>
                    <option value="86">(UTC) Casablanca</option>
                    <option value="93">(UTC) Coordinated Universal Time</option>
                    <option value="2">(UTC) Dublin, Edinburgh, Lisbon, London</option>
                    <option value="31">(UTC) Monrovia, Reykjavik</option>
                    <option value="4">(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna</option>
                    <option value="6">(UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague</option>
                    <option value="3">(UTC+01:00) Brussels, Copenhagen, Madrid, Paris</option>
                    <option value="57">(UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb</option>
                    <option value="69">(UTC+01:00) West Central Africa</option>
                    <option value="83">(UTC+01:00) Windhoek</option>
                    <option value="79">(UTC+02:00) Amman</option>
                    <option value="5">(UTC+02:00) Athens, Bucharest, Istanbul</option>
                    <option value="80">(UTC+02:00) Beirut</option>
                    <option value="49">(UTC+02:00) Cairo</option>
                    <option value="98">(UTC+02:00) Damascus</option>
                    <option value="50">(UTC+02:00) Harare, Pretoria</option>
                    <option value="59">(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius</option>
                    <option value="101">(UTC+02:00) Istanbul</option>
                    <option value="27">(UTC+02:00) Jerusalem</option>
                    <option value="7">(UTC+02:00) Minsk (old)</option>
                    <option value="104">(UTC+02:00) E. Europe</option>
                    <option value="26">(UTC+03:00) Baghdad</option>
                    <option value="100">(UTC+03:00) Kaliningrad, Minsk</option>
                    <option value="74">(UTC+03:00) Kuwait, Riyadh</option>
                    <option value="56">(UTC+03:00) Nairobi</option>
                    <option value="25">(UTC+03:30) Tehran</option>
                    <option value="24">(UTC+04:00) Abu Dhabi, Muscat</option>
                    <option value="54">(UTC+04:00) Baku</option>
                    <option value="51">(UTC+04:00) Moscow, St. Petersburg, Volgograd</option>
                    <option value="89">(UTC+04:00) Port Louis</option>
                    <option value="82">(UTC+04:00) Tbilisi</option>
                    <option value="84">(UTC+04:00) Yerevan</option>
                    <option value="48">(UTC+04:30) Kabul</option>
                    <option value="87">(UTC+05:00) Islamabad, Karachi</option>
                    <option value="47">(UTC+05:00) Tashkent</option>
                    <option value="23">(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi</option>
                    <option value="66">(UTC+05:30) Sri Jayawardenepura</option>
                    <option value="62">(UTC+05:45) Kathmandu</option>
                    <option value="71">(UTC+06:00) Astana</option>
                    <option value="102">(UTC+06:00) Dhaka</option>
                    <option value="58">(UTC+06:00) Ekaterinburg</option>
                    <option value="61">(UTC+06:30) Yangon (Rangoon)</option>
                    <option value="22">(UTC+07:00) Bangkok, Hanoi, Jakarta</option>
                    <option value="46">(UTC+07:00) Novosibirsk</option>
                    <option value="45">(UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi</option>
                    <option value="64">(UTC+08:00) Krasnoyarsk</option>
                    <option value="21">(UTC+08:00) Kuala Lumpur, Singapore</option>
                    <option value="73">(UTC+08:00) Perth</option>
                    <option value="75">(UTC+08:00) Taipei</option>
                    <option value="94">(UTC+08:00) Ulaanbaatar</option>
                    <option value="63">(UTC+09:00) Irkutsk</option>
                    <option value="20">(UTC+09:00) Osaka, Sapporo, Tokyo</option>
                    <option value="72">(UTC+09:00) Seoul</option>
                    <option value="19">(UTC+09:30) Adelaide</option>
                    <option value="44">(UTC+09:30) Darwin</option>
                    <option value="18">(UTC+10:00) Brisbane</option>
                    <option value="76">(UTC+10:00) Canberra, Melbourne, Sydney</option>
                    <option value="43">(UTC+10:00) Guam, Port Moresby</option>
                    <option value="42">(UTC+10:00) Hobart</option>
                    <option value="70">(UTC+10:00) Yakutsk</option>
                    <option value="41">(UTC+11:00) Solomon Is., New Caledonia</option>
                    <option value="68">(UTC+11:00) Vladivostok</option>
                    <option value="17">(UTC+12:00) Auckland, Wellington</option>
                    <option value="97">(UTC+12:00) Coordinated Universal Time+12</option>
                    <option value="40">(UTC+12:00) Fiji</option>
                    <option value="99">(UTC+12:00) Magadan</option>
                    <option value="92">(UTC+12:00) Petropavlovsk-Kamchatsky - Old</option>
                    <option value="67">(UTC+13:00) Nuku'alofa</option>
                    <option value="16">(UTC+13:00) Samoa</option>
                </select>
            </div>

            <div class="form-group" ng-if="settings.repositoryType != 2">
                <label>{{'Language' | translate}}</label>
                <select class="form-control" ng-model="settings.lcid">
                    <option ng-repeat="language in languages | filter: activeOrSelected(language, settings.lcid)" ng-selected="language.lcid == settings.lcid" value="{{language.lcid}}">{{language.displayName}}</option>
                </select>
            </div>

            <div class="form-group" ng-if="settings.repositoryType != 2 && !wizdomEnvironmentIsOnPrem">
                <label>{{'External sharing' | translate}}</label>
                <select class="form-control" ng-model="settings.externalSharing">
                    <option value="1">{{"Don't allow sharing outside your organization" | translate}}</option>
                    <option value="2">{{'Allow external users who accept sharing invitations and sign in as authenticated users' | translate}}</option>
                    <option value="3">{{'Allow both external users who accept sharing invitations and anonymous guest links' | translate}}</option>
                </select>
                *{{'Be aware that you can not specify sharing functions that are less restriktiv than those specified for the tenant' | translate}}
            </div>

            <!--<button type="button" ng-click="update();" ng-hide="saving" ng-disabled="repositoryForm.$invalid" class="btn btn-success">{{'Save' | translate}}</button>
    <button type="button" ng-show="saving" class="btn btn-success">{{'Saving' | translate}}</button>-->
        </form>
    </div>
</div>