@Master['master.html']
@Model['SendConfigViewModel']
@Section['Content']
<form class="mt-3" method="post">
    <div class="row mt-2">
        <div class="control-group mb-3">
            <div class="controls">
                <button type="submit" class="btn btn-primary">Speichern</button>
            </div>
        </div>
    </div>

    @If.SendConfigValidationInfo.Invalid
    <div class="alert alert-danger" role="alert">Ihre Eingaben sind ungültig, bitte korrigieren!</div>
    @EndIf

    @If.SuccessfulSaved
    <div class="alert alert-success" role="alert">Konfiguration wurde gespeichert.</div>
    @EndIf

    <div class="row mt-2">
        <h3>
            Sendeeinstellungen
            <small class="text-muted"></small>
        </h3>
    </div>

    <div class="row">
        <div class="col">
            <div class="form-group">
                <small id="NameHelp" class="form-text text-muted">Name</small>
                <input type="text" class="form-control @If.SendConfigValidationInfo.NameIsInvalid is-invalid @EndIf" id="Name" name="Name" value="@!Model.Name" aria-describedby="NameHelp" placeholder="Bitte eingeben.">
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col">
            <div class="form-group">
                <small id="SendModeHelp" class="form-text text-muted">Sendemethode auswählen</small>
                <select name="SendMode" class="form-control" id="SendMode" placeholder="Sendemethode auswählen" onchange="sendmodechanged(this)">
                    @Each.SendModeOptions
                    <option value="@Current.Value" @If.IsSelected selected @EndIf>@Current.Name</option>
                    @EndEach
                </select>
            </div>
        </div>
    </div>
    <p><span class="badge badge-secondary">SMTP - Postfach - Konfiguration</span></p>

    <div class="row">
        <div class="col">
            <div class="form-check">
                <input class="form-check-input" type="checkbox" value="True" @If.UseForSystemMessages checked="checked" @EndIf" name="UseForSystemMessages" id="UseForSystemMessages" ">
                <label class="form-check-label" for="UseForSystemMessages">Für Systemnachrichten (Fehler, Warnungen und Infomails) benutzen</label>
            </div>
        </div>
        <div class="col">
            <div class="form-group">
                <input type="text" class="form-control @If.SendConfigValidationInfo.SmtpEmailAddressIsInvalid is-invalid @EndIf @If.SendConfigValidationInfo.SmtpEmailAddressIsMissing is-invalid @EndIf" id="SmtpEmailAddress" name="SmtpEmailAddress" value="@!Model.SmtpEmailAddress" aria-describedby="SmtpEmailAddressHelp" placeholder="">
                <small id="SmtpEmailAddressHelp" class="form-text text-muted">E-Mail-Adresse</small>
            </div>
        </div>
    </div>

    <div class="row" id="spanHostName">
        <div class="col">
            <div class="form-group">
                <input type="text" class="form-control @If.SendConfigValidationInfo.SmtpHostIsInvalid is-invalid @EndIf" id="SmtpHost" name="SmtpHost" value="@!Model.SmtpHost" aria-describedby="SmtpHostHelp" placeholder="Bitte eingeben.">
                <small id="SmtpHostHelp" class="form-text text-muted">Hostname des SMTP-Servers</small>
            </div>
        </div>
    </div>
    <span id="spanSmtp">
        <div class="row">
            <div class="col">
                <div class="form-group">
                    <input type="number" class="form-control @If.SendConfigValidationInfo.SmtpPortIsInvalid is-invalid @EndIf" id="SmtpPort" name="SmtpPort" value="@!Model.SmtpPort" aria-describedby="SmtpPortHelp" placeholder="Bitte eingeben.">
                    <small id="SmtpPortHelp" class="form-text text-muted">Port des SMTP-Servers</small>
                </div>
            </div>
            <div class="col">
                <div class="form-group">
                    <div class="input-group-prepend">
                        <div class="input-group-text">
                            <input type="checkbox" value="True" @If.UseSslForSmtp checked="checked" @EndIf" name="UseSslForSmtp" id="UseSslForSmtp" />
                        </div>
                        &nbsp;Benutze SSL zum Verbinden für SMTP
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col">
                <div class="form-group">
                    <div class="input-group-prepend">
                        <div class="input-group-text">
                            <input type="checkbox" value="True" @If.WithoutUsernamePassword checked="checked" @EndIf" name="WithoutUsernamePassword" id="WithoutUsernamePassword">
                        </div>
                        &nbsp;Ohne Benutzername/Password (Anonymous)
                    </div>
                </div>
            </div>
        </div>
    </span>
    <div class="row" id="spanUsernamePassword">
        <div class="col">
            <div class="form-group">
                <input type="text" class="form-control @If.SendConfigValidationInfo.SmtpUsernameIsInvalid is-invalid @EndIf" id="SmtpUsername" name="SmtpUsername" value="@!Model.SmtpUsername" aria-describedby="SmtpUsernameHelp" placeholder="Bitte eingeben.">
                <small id="SmtpUsernameHelp" class="form-text text-muted">Benutzername des zu verwendenten SMTP-Accounts</small>
            </div>
        </div>
        <div class="col">
            <div class="form-group">
                <input type="password" class="form-control @If.SendConfigValidationInfo.SmtpPasswordIsInvalid is-invalid @EndIf" id="SmtpPassword" name="SmtpPassword" value="@!Model.SmtpPassword" aria-describedby="SmtpPasswordHelp" placeholder="Bitte eingeben.">
                <small id="SmtpPasswordHelp" class="form-text text-muted">Passwort des zu verwendenten SMTP-Accounts</small>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col">
            <div class="form-group">
                <div class="col">
                    <small id="SendingPauseAfterXMessagesHelp" class="form-text text-muted">Nach dem Versenden von X Nachrichten pausieren (0=keine Pause)</small>
                    <input type="number" class="form-control @If.SendConfigValidationInfo.SendingPauseAfterXMessagesIsInvalid is-invalid @EndIf" id="SubjectOcl" name="SendingPauseAfterXMessages" value="@!Model.SendingPauseAfterXMessages" aria-describedby="SendingPauseAfterXMessagesHelp" placeholder="Bitte eingeben.">
                </div>
                <div class="col">
                    <small id="SendingPauseXSecondsHelp" class="form-text text-muted">Länge der Pause in Sekunden (0=keine Pause)</small>
                    <input type="text" class="form-control @If.SendConfigValidationInfo.SendingPauseXSecondsIsInvalid is-invalid @EndIf" id="SendingPauseXSeconds" name="SendingPauseXSeconds" value="@!Model.SendingPauseXSeconds" aria-describedby="SendingPauseXSecondsHelp" placeholder="Bitte eingeben.">
                </div>
            </div>
        </div>
    </div>

    <span id="spanImap">
        <p><span class="badge badge-secondary">IMAP - Postfach - Konfiguration (zur Bounce-Erkennung)</span></p>
        <div class="row">
            <div class="col">
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" value="True" @If.ActivateImapForBounce checked="checked" @EndIf" name="ActivateImapForBounce" id="ActivateImapForBounce" ">
                    <label class="form-check-label" for="UseTemplateFromDataSourceFolder">IMAP für die Bounce-Erkennung aktivieren</label>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col">
                <div class="form-group">
                    <input type="text" class="form-control @If.SendConfigValidationInfo.ImapHostNameIsInvalid is-invalid @EndIf" id="ImapHostname" name="ImapHostname" value="@!Model.ImapHostname" aria-describedby="ImapHostnameHelp" placeholder="">
                    <small id="ImapHostnameHelp" class="form-text text-muted">Hostname des IMAP-Servers</small>
                </div>
            </div>
            <div class="col">
                <div class="form-group">
                    <input type="number" class="form-control @If.SendConfigValidationInfo.ImapPortIsInvalid is-invalid @EndIf" id="ImapPort" name="ImapPort" value="@!Model.ImapPort" aria-describedby="ImapPortHelp" placeholder="">
                    <small id="ImapPortHelp" class="form-text text-muted">Port des SMTP-Servers</small>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col">
                <div class="form-group">
                    <input type="text" class="form-control @If.SendConfigValidationInfo.ImapEmailAddressIsInvalid is-invalid @EndIf" id="ImapEmailAddress" name="ImapEmailAddress" value="@!Model.ImapEmailAddress" aria-describedby="ImapEmailAddressHelp" placeholder="">
                    <small id="ImapEmailAddressHelp" class="form-text text-muted">Emailadresse des IMAP-Kontos</small>
                </div>
            </div>
            <div class="col">
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" value="True" @If.ImapUseSsl checked="checked" @EndIf" name="ImapUseSsl" id="ImapUseSsl" ">
                    <label class="form-check-label" for="UseTemplateFromDataSourceFolder">Benutze SSL zum Verbinden für IMAP</label>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col">
                <div class="form-group">
                    <input type="text" class="form-control @If.SendConfigValidationInfo.ImapUsernameIsInvalid is-invalid @EndIf" id="ImapUsername" name="ImapUsername" value="@!Model.ImapUsername" aria-describedby="ImapUsernameHelp" placeholder="">
                    <small id="ImapUsernameHelp" class="form-text text-muted">Benutzername für den IMAP-Account</small>
                </div>
            </div>
            <div class="col">
                <div class="form-group">
                    <input type="password" class="form-control @If.SendConfigValidationInfo.ImapPasswordIsInvalid is-invalid @EndIf" id="ImapPassword" name="ImapPassword" value="@!Model.ImapPassword" aria-describedby="ImapPasswordHelp" placeholder="">
                    <small id="ImapPasswordHelp" class="form-text text-muted">Passwort für den IMAP-Account</small>
                </div>
            </div>
        </div>
    </span>

    <span id="spanSendgrid">
        <p><span class="badge badge-secondary">Sendgrid - Konfiguration</span></p>
        <div class="row">
            <div class="col">
                <div class="form-group">
                    <input type="text" class="form-control @If.SendConfigValidationInfo.SendGridKeyIsInvalid is-invalid @EndIf" id="SendGridKey" name="SendGridKey" value="@!Model.SendGridKey" aria-describedby="SendGridKeyHelp" placeholder="Bitte eingeben.">
                    <small id="SendGridKeyHelp" class="form-text text-muted">Ihr Sendgrid-Key</small>
                </div>
            </div>
        </div>
    </span>
</form>
<script>
    function changeViewForSendMode(sendMode) {
        var labelHostname = "Hostname des SMTP-Servers";
        var labelUsername = "Benutzername des zu verwendenten SMTP-Accounts";
        var labelPassword = "Passwort des zu verwendenten SMTP-Accounts";
        var isSpanSendGridVisible = false;
        var isSpanSmtpVisible = true;
        var isSpanImapVisible = true;
        var isSpanUsernameVisible = true;
        var isSpanHostnameVisible = true;

        // Sendgrid
        if (sendMode == "1") {
            isSpanSendGridVisible = true;
            isSpanImapVisible = false;
            isSpanSmtpVisible = false;
            isSpanUsernameVisible = false;
            isSpanHostnameVisible = false;
        }

        // Graph-SendModes Email
        if (sendMode == "2") {
            labelHostname = "TenantId";
            labelUsername = "ClientId";
            labelPassword = "ClientSecret";
            isSpanImapVisible = false;
            isSpanSmtpVisible = false;
            isSpanUsernameVisible = true;
            isSpanHostnameVisible = true;
        }

        // Graph-Send to Teams-Channel
        if (sendMode == "3") {
            isSpanImapVisible = false;
            isSpanSmtpVisible = false;
            isSpanUsernameVisible = false;
            isSpanHostnameVisible = false;
        }

        var labelHostnameElem = document.getElementById("SmtpHostHelp");
        var labelUsernameElem = document.getElementById("SmtpUsernameHelp");
        var labelPasswordElem = document.getElementById("SmtpPasswordHelp");
        var spanImapElem = document.getElementById("spanImap");
        var spanSmtpElem = document.getElementById("spanSmtp");
        var spanSendgridElem = document.getElementById("spanSendgrid");
        var spanUsernameElem = document.getElementById("spanUsernamePassword");
        var spanHostnameElem = document.getElementById("spanHostName");
        labelHostnameElem.innerHTML = labelHostname;
        labelUsernameElem.innerHTML = labelUsername;
        labelPasswordElem.innerHTML = labelPassword;
        if (isSpanImapVisible) {
            spanImapElem.style.display = "block";
        } else {
            spanImapElem.style.display = "none";
        }
        if (isSpanHostnameVisible) {
            spanHostnameElem.style.display = "block";
        } else {
            spanHostnameElem.style.display = "none";
        }
        if (isSpanUsernameVisible) {
            spanUsernameElem.style.display = "block";
        } else {
            spanUsernameElem.style.display = "none";
        }
        if (isSpanSmtpVisible) {
            spanSmtpElem.style.display = "block";
        } else {
            spanSmtpElem.style.display = "none";
        }
        if (isSpanSendGridVisible) {
            spanSendgridElem.style.display = "block";
        } else {
            spanSendgridElem.style.display = "none";
        }
    }

    function sendmodechanged(sendmodecombo) {
        var value = sendmodecombo.value;
        changeViewForSendMode(value);
    }

    function initView() {
        var sendModeElem = document.getElementById("SendMode");
        var sendMode = sendModeElem.value;
        changeViewForSendMode(sendMode);
    }

    initView();
</script>
@EndSection
