jQuery(function ($) {
    var $container = $('#customize-header-actions');
    var $button = $('<input type="submit" name="newscope-reset" id="newscope-reset" class="button-secondary button newscope-reset-button">')
        .attr('value', _newscopeCustomizerReset.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: _newscopeCustomizerReset.nonce.reset
        };

        var response = confirm(_newscopeCustomizerReset.confirm);

        if (!response) return;

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

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