<template>
    <form class="content-l" v-if="popup.payload" @submit.prevent="deleteUser(popup.payload)">
        <UiWarning><p>Are you sure you want to delete user <span>{{ popup.payload.email }}</span>?</p></UiWarning>
        <div class="center">
            <UiButton type="submit">Delete</UiButton>
        </div>
    </form>
</template>

<script setup lang="ts">
import {usePopup} from "~/components/ui/popup/Popup";
import type {User} from "~/user/User";
import {useDelete} from "~/utils/HttpUtils";
import UiWarning from "~/components/ui/UiWarning.vue";

const popup = usePopup().require<User>();

function deleteUser(user: User)
{
    useDelete("/api/realms/" + useRoute().params.realm_key + "/users/" + user.id, () => {
        if (popup.config?.callback)
        {
            popup.config.callback();
        }
        usePopup().close();
    })
}
</script>

<style scoped>
span {
    font-weight: bold;
}
</style>