<div ng-controller="Admin.SecurityEmailSenderConfigurationController">
    <ng-form name="securityEmailConfigurationForm">
        <div class="pull-right well">
            <div class="btn-group">
                <button class="btn btn-xs btn-link" ng-click="save()"
                        ng-disabled="emailSenderConfigDataModel['email.sender.allowDocuments'] && !(emailSenderConfigDataModel['email.sender.allowAttachments'] || emailSenderConfigDataModel['email.sender.allowHyperlinks']) || securityEmailConfigurationForm.$invalid">
                    <i class="fa fa-save"></i>
                    <span translate>
                        admin.security.emailConfiguration.emailConfigForm.save.button
                    </span>
                </button>
            </div>
        </div>
        <panel-view header="{{'admin.security.emailConfiguration.title' | translate}}" collapsible="false">
            <div class="row">
                <div class="col-lg-12">
                    <label translate>
                        admin.security.emailConfiguration.emailConfigForm.deliveryMethods.label
                    </label>
                </div>
                <div class="well-sm">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" ng-model="emailSenderConfigDataModel['email.sender.allowDocuments']">
                                    <span translate>
                                        admin.security.emailConfiguration.emailConfigForm.enableDocumentEmail.checkbox
                                    </span>
                                    <span class="text-danger"
                                            ng-if="emailSenderConfigDataModel['email.sender.allowDocuments'] && !(emailSenderConfigDataModel['email.sender.allowAttachments'] || emailSenderConfigDataModel['email.sender.allowHyperlinks'])">
                                        <i class="fa fa-times"></i>
                                        <span translate>admin.security.emailConfiguration.emailConfigForm.errorMsg</span>
                                    </span>
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="row" ng-if="emailSenderConfigDataModel['email.sender.allowDocuments']">
                        <div class="col-lg-12">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" ng-model="emailSenderConfigDataModel['email.sender.allowAttachments']">
                                    <span translate>
                                        admin.security.emailConfiguration.emailConfigForm.enableDocumentAttach.checkbox
                                    </span>
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="row" ng-if="emailSenderConfigDataModel['email.sender.allowDocuments']">
                        <div class="col-lg-12">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" ng-model="emailSenderConfigDataModel['email.sender.allowHyperlinks']">
                                    <span translate>
                                        admin.security.emailConfiguration.emailConfigForm.enableDocumentHyperlink.checkbox
                                    </span>
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="row" ng-if="emailSenderConfigDataModel['email.sender.allowDocuments']">
                        <div class="col-lg-12">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" ng-model="emailSenderConfigDataModel['email.sender.convertDocumentsToPdf']">
                                    <span translate>
                                        admin.security.emailConfiguration.emailConfigForm.documentsAsPdf.checkbox
                                    </span>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <!--                 <div class="col-lg-12">
                                    <label translate>
                                        admin.security.emailConfiguration.emailConfigForm.serverSettings.label
                                    </label>
                                </div> -->
                <div class="well-sm">
                    <div class="row">
                        <div class="col-lg-4 form-group">
                            <label for="serverType" translate>
                                admin.security.emailConfiguration.emailConfigForm.serverType.label
                            </label>
                            <select id="serverType" class="form-control" ng-model="emailSenderConfigDataModel['email.sender.type']">
                                <option value="" disabled selected hidden translate>
                                    admin.security.emailConfiguration.emailConfigForm.serverType.placeholder
                                </option>
                                <option ng-repeat="option in serverTypeSelectOptions" value="{{option.value}}" translate>
                                    {{option.label}}
                                </option>
                            </select>
                        </div>
                        <div class="col-lg-4 form-group">
                            <label>
                                &nbsp;
                            </label>
                            <label class="text-success" ng-if="emailSenderConfigDataModel['email.sender.type'] === 'outlook'">
                                <span translate>
                                   admin.security.emailConfiguration.emailConfigForm.serverType.configuredExchange.label
                                </span>
                            </label>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-4 form-group">
                            <label for="server" translate>
                                admin.security.emailConfiguration.emailConfigForm.server.label</label>
                            <span class="required-asterisk">*</span>
                            <input type="text" id="server"
                                    placeholder="{{'admin.security.emailConfiguration.emailConfigForm.server.placeholder' | translate}}"
                                    ng-model="emailSenderConfigDataModel['email.sender.host']" class="form-control"
                                    ng-disabled="emailSenderConfigDataModel['email.sender.type'] !== 'smtp'" required>
                        </div>
                        <div class="col-lg-2 form-group">
                            <label for="port" translate>
                                admin.security.emailConfiguration.emailConfigForm.port.label
                            </label>
                            <input type="text" id="port"
                                    placeholder="{{'admin.security.emailConfiguration.emailConfigForm.port.placeholder' | translate}}"
                                    ng-model="emailSenderConfigDataModel['email.sender.port']" class="form-control"
                                    ng-disabled="emailSenderConfigDataModel['email.sender.type'] !== 'smtp'">
                        </div>
                        <div class="col-lg-4 form-group">
                            <label for="encryption" translate>
                                admin.security.emailConfiguration.emailConfigForm.encryption.label
                            </label>
                            <select id="encryption" class="form-control" ng-model="emailSenderConfigDataModel['email.sender.encryption']"
                                    ng-change="changeEncryption(emailSenderConfigDataModel['email.sender.encryption'])"
                                    ng-disabled="emailSenderConfigDataModel['email.sender.type'] !== 'smtp'">
                                <option value="" disabled selected hidden translate>
                                    admin.security.emailConfiguration.emailConfigForm.encryption.placeholder
                                </option>
                                <option ng-repeat="option in encryptionSelectOptions" value="{{option.value}}" translate>
                                    {{option.label}}
                                </option>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 form-group">
                            <label for="username" translate>
                                admin.security.emailConfiguration.emailConfigForm.username.label
                            </label>
                            <input type="text" id="username"
                                    placeholder="{{'admin.security.emailConfiguration.emailConfigForm.username.placeholder' | translate}}"
                                    ng-model="emailSenderConfigDataModel['email.sender.username']" class="form-control"
                                    ng-disabled="emailSenderConfigDataModel['email.sender.type'] !== 'smtp'">
                        </div>
                        <div class="col-lg-3 form-group">
                            <label for="password" translate>
                                admin.security.emailConfiguration.emailConfigForm.password.label
                            </label>
                            <input type="password" name="password" id="password"
                                    placeholder="{{'admin.security.emailConfiguration.emailConfigForm.password.placeholder' | translate}}"
                                    ng-model="emailSenderConfigDataModel['email.sender.password']" class="form-control"
                                    ng-disabled="emailSenderConfigDataModel['email.sender.type'] !== 'smtp'" />
                        </div>
                        <div class="col-lg-4 form-group">
                            <label for="userFrom" translate>
                                admin.security.emailConfiguration.emailConfigForm.userFrom.label
                            </label>
                            <span class="required-asterisk">*</span>
                            <input id="userFrom" type="email" required pattern="[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,63}$"
                                    placeholder="{{'admin.security.emailConfiguration.emailConfigForm.userFrom.placeholder' | translate}}"
                                    ng-model="emailSenderConfigDataModel['email.sender.userFrom']" class="form-control"
                                    ng-disabled="emailSenderConfigDataModel['email.sender.type'] !== 'smtp'" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 form-group">
                            <button class="btn btn-sm btn-primary form-control" name="validate"
                                    ng-click="validateSmtpConfiguration(emailSenderConfigDataModel)"
                                    ng-disabled="emailSenderConfigDataModel['email.sender.type'] !== 'smtp'">
                                <span translate>
                                    admin.security.emailConfiguration.emailConfigForm.validate.button
                                </span>
                            </button>
                        </div>
                        <div class="col-lg-4 form-group">
                             <span class="text-danger"
                                     ng-if="emailSenderConfigDataModel['email.sender.type'] === 'smtp' && isSmtpValid !== null && !isSmtpValid">
                                <i class="fa fa-times"></i>
                                <span translate>
                                    admin.security.emailConfiguration.emailConfigForm.smtpNotValid
                                </span>
                            </span>
                            <span class="text-success"
                                    ng-if="emailSenderConfigDataModel['email.sender.type'] === 'smtp' && isSmtpValid !== null && isSmtpValid">
                                <i class="fa fa-check"></i>
                                <span translate>
                                    admin.security.emailConfiguration.emailConfigForm.smtpValid
                                </span>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </panel-view>
    </ng-form>
</div>