@page "/parametres_mail"
@inject HttpClient Http

@code {
    private ParametresCompteMail_VM VM;

    protected override async Task OnInitializedAsync()
    {
        VM = new(Http);
        await VM.LoadDataAsync();
    }

    private async Task SauvegarderAsync()
    {
        await VM.SaveDataAsync();
    }
}

<h3>Paramètres du Compte Mail</h3>

@if (VM?.SelectedItem is null)
{
    <p>Chargement...</p>
}
else
{
    <div class="form-container">
        <div class="form-group">
            <label>Serveur IMAP :</label>
            <input @bind="VM.SelectedItem.ServeurImap" />
        </div>
        <div class="form-group">
            <label>Port IMAP :</label>
            <input type="number" @bind="VM.SelectedItem.ServeurImapPort" />
        </div>
        <div class="form-group">
            <label>Serveur SMTP :</label>
            <input @bind="VM.SelectedItem.ServeurSmtp" />
        </div>
        <div class="form-group">
            <label>Port SMTP :</label>
            <input type="number" @bind="VM.SelectedItem.ServeurSmtpPort" />
        </div>
        <div class="form-group">
            <label>Adresse mail :</label>
            <input @bind="VM.SelectedItem.UserAdresse" />
        </div>
        <div class="form-group">
            <label>Mot de passe :</label>
            <input type="password" @bind="VM.SelectedItem.UserMotPasse" />
        </div>
        <div class="form-group">
            <label>Nom et prénom :</label>
            <input @bind="VM.SelectedItem.UserNomPrenom" />
        </div>
        <div class="form-group">
            <label>Rôle :</label>
            <input @bind="VM.SelectedItem.UserRole" />
        </div>
        <div class="form-group">
            <label>Entreprise :</label>
            <input @bind="VM.SelectedItem.UserEntreprise" />
        </div>
        <div class="form-group">
            <label>Rafraîchissement réception (min) :</label>
            <input type="number" @bind="VM.SelectedItem.DelayRefresh" />
        </div>
        <div class="form-group">
            <label>Rafraîchissement envoi (min) :</label>
            <input type="number" @bind="VM.SelectedItem.DelaySentRefresh" />
        </div>
        <div class="form-group">
            <label>Récupération envois (jours) :</label>
            <input type="number" @bind="VM.SelectedItem.DelaySentRecup" />
        </div>
        <div class="form-group">
            <label>OverdueDays Sent (jours) :</label>
            <input type="number" @bind="VM.SelectedItem.OverdueDaysSent" />
        </div>

        <p style="color:darkgreen">@VM.Message</p>

        <div class="form-actions">
            <button class="btn btn-primary" @onclick="SauvegarderAsync">Sauvegarder</button>
        </div>
    </div>
}

<style>
    .form-container {
        max-width: 500px;
        margin: auto;
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }

    .form-group {
        margin-bottom: 10px;
    }

        .form-group label {
            display: block;
            font-weight: bold;
            margin-bottom: 3px;
        }

        .form-group input {
            width: 100%;
            padding: 5px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

    .form-actions {
        text-align: right;
        margin-top: 10px;
    }
</style>
