/**
 * Review request dismissal handler.
 *
 * @since 1.0.3
 */
(function ($) {
    'use strict';

    $(document).ready(function () {
        $('.stwlite-dismiss-review-request').on('click', function (e) {
            e.preventDefault();
            $(this).closest('.stwlite-review-request-notice').slideUp();

            // AJAX to save dismissal
            dismissReviewRequest();
        });

        $('.stwlite-dismiss-review-later').on('click', function (e) {
            e.preventDefault();
            $(this).closest('.stwlite-review-request-notice').slideUp();

            // AJAX to save dismissal
            dismissReviewRequest(true);
        });

        // Handle default dismissal (x button)
        $('.stwlite-review-request-notice').on('click', '.notice-dismiss', function () {
            dismissReviewRequest();
        });
    });

    /**
     * Dismiss review request.
     * 
     * @param {bool} later Whether to dismiss for later.
     *
     * @since 1.0.3
     */
    function dismissReviewRequest(later) {
        later = later || false;

        $.post(ajaxurl, {
            action: 'stwlite_dismiss_review_request',
            nonce: stwliteReviewPrompt.nonce,
            later: later ? 'yes' : 'no'
        });
    }
})(jQuery);
