import { Ajax } from "./../ajax";
class Order {
    constructor() {
        this.syncButton();
        this._ajax = new Ajax;
    }

    syncButton() {
        const btn = document.querySelector("#koin-sync-button");

        if (!btn) return;

        btn.addEventListener("click", () => {
            const order = btn.getAttribute("data-order");
            const orderData = JSON.parse(order);

            const url = koinAjax.ajaxurl;
            const data = {
                action: 'koin_sync_order',
                nonce: koinAjax.nonce,
                ...orderData
            };

            this._ajax.do_ajax(
                url,
                data,
                `${window.location.pathname + window.location.search}`
            );
        });
    }
}

document.addEventListener("DOMContentLoaded", () => {
    new Order;
});
