(% extends "user_settings_partial_base.html" %)

(% block selected_setting_group %)
Profile Difference
(% endblock %)

(% block settings_vertical_point %)lg(% endblock %)

(% block settings_window %)

<form>
    (% if person.name != new_attrs.account_name %)
    <input type="hidden" name="account_name" value="(( new_attrs.account_name ))"/>
    (% endif %)
    (% if person.displayname != new_attrs.display_name %)
    <input type="hidden" name="display_name" value="(( new_attrs.display_name ))"/>
    (% endif %)

    (% for email in new_attrs.emails %)
    (% if !email.primary %)
    <input type="hidden" name="emails[]" value="(( email.value ))"/>
    (% endif %)
    (% endfor %)
    (% if let Some(new_primary_mail) = new_primary_mail %)
    <input type="hidden" name="new_primary_mail" value="(( new_primary_mail ))"/>
    (% endif %)

    <table class="table table-bordered overflow-x-scroll">
        <thead>
        <tr>
            <th scope="col">Attribute</th>
            <th scope="col">Old value</th>
            <th scope="col">New value</th>
        </tr>
        </thead>
        (% if person.name != new_attrs.account_name %)
        <tr>
            <th scope="row">Username</th>
            <td class="text-break">(( person.name ))</td>
            <td class="text-break">(( new_attrs.account_name ))</td>
        </tr>
        (% endif %)

        (% if person.displayname != new_attrs.display_name %)
        <tr>
            <th scope="row">Display name</th>
            <td class="text-break">(( person.displayname ))</td>
            <td class="text-break">(( new_attrs.display_name ))</td>
        </tr>
        (% endif %)
        (% if !emails_are_same %)
        <tr>
            <th scope="row">Primary Email</th>
            <td class="text-break">
                <ul class="ps-3 list-unstyled">
                    <li class="text-nowrap">(( primary_mail.clone().unwrap_or("none".to_string()) ))</li>
                </ul>
            </td>
            <td class="text-break">
                <ul class="ps-3 list-unstyled">
                    <li class="text-nowrap">(( new_primary_mail.clone().unwrap_or("none".to_string()) ))</li>
                </ul>
            </td>
        </tr>
        <tr>
            <th scope="row">Secondary Emails</th>
            <td class="text-break">
                <ul class="ps-3 list-unstyled">
                    (% for email in person.mails %)
                    (% if !email.primary %)
                    <li class="text-nowrap">(( email.value ))</li>
                    (% endif %)
                    (% endfor %)
                </ul>
            </td>
            <td class="text-break">
                <ul class="ps-3 list-unstyled">
                    (% for email in new_attrs.emails %)
                    (% if !email.primary %)
                    <li class="text-nowrap">(( email.value ))</li>
                    (% endif %)
                    (% endfor %)
                </ul>
            </td>
        </tr>
        (% endif %)
    </table>

    <div class="pt-4" hx-target="#user_settings_container" hx-swap="outerHTML">
        (% if can_rw %)
        <button class="btn btn-danger" type="button" hx-get="/ui/profile" hx-target="body" hx-swap="outerHTML">Discard
            Changes
        </button>
        <button class="btn btn-primary" type="button" hx-post="/ui/api/user_settings/confirm_profile" hx-target="body"
                hx-swap="outerHTML">Confirm Changes
        </button>
        (% else %)
        <a href="/ui/unlock">
            <!-- TODO: at the moment, session expiring here means progress is lost. Do we just show an error screen ? We can't pass the update state through the reauth session, and we don't have profile update sessions like cred update. -->
            <button class="btn btn-primary" type="button">Unlock Confirm 🔓</button>
        </a>
        (% endif %)
    </div>

</form>

(% endblock %)

