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

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

                var container = document.getElementById('payment_participant_' + participant_id);
                if (!data.payment_complete) {
                    container.classList.add('red');
                    container.classList.add('red-background');
                } else {
                    container.classList.remove('red');
                    container.classList.remove('red-background');
                }
                container.innerHTML = data.response_text;
                setShowModalPayment(false);
                showToast(__('The payment was booked', 'solea'), "success", 10000);
            }
        );
}