<div ng-controller="Admin.SecurityCalendarConfigurationController">
    <ng-form name="calendarConfigurationForm">
        <fieldset ng-disabled="isLoading">
            <div class="pull-right well">
                <div class="btn-group">
                    <button class="btn btn-xs btn-link" ng-click="saveChanges()" ng-disabled="calendarConfigurationForm.$invalid">
                        <i class="fa fa-save"></i>
                        <span translate>
			            	admin.security.calendarConfiguration.calendarConfigForm.save.button
			            </span>
                    </button>
                </div>
            </div>
            <panel-view header="{{'admin.security.calendarConfiguration.title' | translate}}" collapsible="false">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="row" ng-repeat="configurableObjectType in configurableObjectTypes">
                            <div class="col-lg-12">
                                <label translate>
                                    {{configurableObjectType.label}}
                                </label>
                            </div>
                            <div class="well-sm">
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox"
                                                        ng-model="calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled">
                                                <span translate>
							                        	admin.security.calendarConfiguration.calendarConfigForm.enableCalendarIntegration.checkbox
							                    	</span>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-4 form-group">
                                            <label for="email" translate>
                                                admin.security.calendarConfiguration.calendarConfigForm.email.label
                                            </label>
											<span ng-show="calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled" class="required-asterisk">*</span>
                                            <input type="email" required id="email{{configurableObjectType.id}}"
                                                    placeholder="{{'admin.security.calendarConfiguration.calendarConfigForm.email.placeholder' | translate}}"
                                                    ng-model="calendarConfigDataModel.configurationsByType[configurableObjectType.id].systemEmail"
                                                    class="form-control"
                                                    ng-disabled="!calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled"
                                                    ng-required="calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled"
                                                    ng-change="systemEmailInputChanged(configurableObjectType)">
                                            <span class="text-danger"
                                                    ng-if="validEmailsByObjectType[configurableObjectType.id] === 'NOT_VALID'">
													<i class="fa fa-times"></i>
													<span translate>
														admin.security.calendarConfiguration.calendarConfigForm.emailNotValid
													</span>
												</span>
                                            <span class="text-success"
                                                    ng-if="validEmailsByObjectType[configurableObjectType.id] === 'VALID'">
													<i class="fa fa-check"></i>
													<span translate>
														admin.security.calendarConfiguration.calendarConfigForm.emailValid
													</span>
												</span>
                                        </div>
                                        <div class="col-lg-4 form-group">
                                            <label for="password" translate>
                                                admin.security.calendarConfiguration.calendarConfigForm.password.label
                                            </label>
                                            <span ng-show="calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled" class="required-asterisk">*</span>
                                            <div ng-show="calendarConfigDataModel.configurationsByType[configurableObjectType.id].isPasswordSet === true">
                                                <button class="btn btn-sm btn-primary"
                                                        ng-click="calendarConfigDataModel.configurationsByType[configurableObjectType.id].isPasswordSet = false; passwordRequirementByObjectType[configurableObjectType.id]=true">
                                                    <span translate>admin.security.calendarConfiguration.calendarConfigForm.password.changeButton</span>
                                                </button>
                                            </div>
                                            <input name="password" type="password"
                                                    ng-show="calendarConfigDataModel.configurationsByType[configurableObjectType.id].isPasswordSet !== true"
                                                    placeholder="{{'admin.security.calendarConfiguration.calendarConfigForm.password.placeholder' | translate}}"
                                                    ng-model="calendarConfigDataModel.configurationsByType[configurableObjectType.id].password"
                                                    class="form-control"
                                                    ng-click="calendarConfigDataModel.configurationsByType[configurableObjectType.id].isPasswordSet = false"
                                                    ng-disabled="!calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled"
                                                    ng-required="calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled && passwordRequirementByObjectType[configurableObjectType.id]" />

                                        </div>
                                        <div class="col-lg-12">
                                            <button class="btn btn-sm btn-primary"
                                                    ng-show="calendarConfigDataModel.configurationsByType[configurableObjectType.id].isPasswordSet !== true"
                                                    ng-click="validateEmail(calendarConfigDataModel.configurationsByType[configurableObjectType.id].systemEmail, calendarConfigDataModel.configurationsByType[configurableObjectType.id].password, configurableObjectType)"
                                                    ng-disabled="!calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled || !calendarConfigDataModel.configurationsByType[configurableObjectType.id].systemEmail">
													<span translate>
									            		admin.security.calendarConfiguration.calendarConfigForm.validate.button
									            	</span>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-4 form-group">
                                        <label for="purge" translate>
                                            admin.security.calendarConfiguration.calendarConfigForm.purge.label
                                        </label>
                                        <select name="purge" class="form-control"
                                                ng-model="calendarConfigDataModel.configurationsByType[configurableObjectType.id].purgeOptions"
                                                ng-disabled="!calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled"
                                                ng-required="calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled">
                                            <option value="" disabled selected hidden translate>
                                                admin.security.calendarConfiguration.calendarConfigForm.purge.placeholder
                                            </option>
                                            <option ng-repeat="option in purgeSelectOptions" value="{{option.value}}" translate>
                                                {{option.label}}
                                            </option>
                                        </select>
                                    </div>
                                    <div class="col-lg-2 form-group"
                                            ng-if="calendarConfigDataModel.configurationsByType[configurableObjectType.id].purgeOptions === 'CLOSED_X_DAYS'">
                                        <label for="purgeDays" translate>
                                            admin.security.calendarConfiguration.calendarConfigForm.purgeDays.label
                                        </label>
                                        <input name="purgeDays" type="number" min="0"
                                                placeholder="{{'admin.security.calendarConfiguration.calendarConfigForm.purgeDays.placeholder' | translate}}"
                                                class="form-control"
                                                ng-model="calendarConfigDataModel.configurationsByType[configurableObjectType.id].daysClosed"
                                                ng-required="calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled"
                                                ng-disabled="!calendarConfigDataModel.configurationsByType[configurableObjectType.id].integrationEnabled">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </panel-view>
        </fieldset>
    </ng-form>
</div>