/**
 * Customizer Reset Script
 */
(function ($, api) {
    api.bind('ready', function () {
        var $header = $('#customize-header-actions');
        var $resetBtn = $('<button type="button" class="button-secondary alignright" id="golpo-reset-settings" style="margin-top: 9px; margin-right: 10px;">Reset</button>');

        $header.append($resetBtn);

        $resetBtn.on('click', function (e) {
            e.preventDefault();
            if (confirm(golpo_reset_obj.confirm)) {
                $.ajax({
                    type: 'POST',
                    url: golpo_reset_obj.ajaxurl,
                    data: {
                        action: 'golpo_reset_customizer',
                        nonce: golpo_reset_obj.nonce
                    },
                    success: function (response) {
                        if (response.success) {
                            location.reload();
                        } else {
                            alert('Failed to reset.');
                        }
                    }
                });
            }
        });
    });
})(jQuery, wp.customize);
