jQuery(function ($) {
    var $container = $('#customize-header-actions');
    var $button = $('<input type="submit" name="newshit-reset" id="newshit-reset" class="button-secondary button newshit-reset-button">')
        .attr('value', _NEWSHITCustomizerReset.reset)
        .css({
            'float': 'right',
            'margin': '9px 0',
            'background-color': '#2816F8',
            'color': '#ffffff',
            'border-color': '#2816F8',
        });
    $button.on('click', function (event) {
        event.preventDefault();

        var data = {
            wp_customize: 'on',
            action: 'customizer_reset',
            nonce: _NEWSHITCustomizerReset.nonce.reset
        };

        var response = confirm(_NEWSHITCustomizerReset.confirm);

        if (!response) return;

        $button.attr('disabled', 'disabled');

        $.post(ajaxurl, data, function () {
            wp.customize.state('saved').set(true);
            location.reload();
        });
    });
    $container.append($button);
});
