import {_nonce} from "./library.js";
import { __ } from './library.js';

export function do_signoff(setShowModalSignoff,showToast, participant_id, date_unregister) {
    const response = fetch("/wp-json/solea/participant/update-registration/signoff", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            participant_id: participant_id,
            date_unregister: date_unregister,
            solea_nonce: _nonce(),
        }),
    })
        .then((res) => res.json())
        .then((data) => {

                var container = document.getElementById('participant_row_' + participant_id);

                container.style.display = 'none';
                setShowModalSignoff()
                showToast(
                    __( 'The participant was deregistered.', 'solea') +
                    __('The participant was informed by email.', 'solea' ), "success", 10000);
            }
        );
}

export function do_resignon(setShowModalSignoff,showToast, participant_id) {
    const response = fetch("/wp-json/solea/participant/update-registration/resignon", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            participant_id: participant_id,
            solea_nonce: _nonce(),
        }),
    })
        .then((res) => res.json())
        .then((data) => {

                var container = document.getElementById('participant_row_' + participant_id);

                container.style.display = 'none';
                setShowModalSignoff()

                showToast (
                    __( 'The participant was re-registered.', 'solea' ) +
                    __( 'The participant was informed by email.', 'solea' ));
            }
        );
}