<?php

/**
 * Display a success toast notification
 *
 * @since 1.0.0
 * @param string $message The message to display
 * @param array $options Additional options
 */
function easy_invoice_toast_success($message, $options = array()) {
    if (wp_doing_ajax()) {
        wp_send_json_success(array(
            'toast' => array(
                'type' => 'success',
                'message' => $message,
                'options' => $options
            )
        ));
    } else {
        echo "<script>if (typeof EasyInvoiceToast !== 'undefined') { EasyInvoiceToast.success('" . esc_js($message) . "', " . json_encode($options) . "); }</script>";
    }
}

/**
 * Display an error toast notification
 *
 * @since 1.0.0
 * @param string $message The message to display
 * @param array $options Additional options
 */
function easy_invoice_toast_error($message, $options = array()) {
    if (wp_doing_ajax()) {
        wp_send_json_error(array(
            'toast' => array(
                'type' => 'error',
                'message' => $message,
                'options' => $options
            )
        ));
    } else {
        echo "<script>if (typeof EasyInvoiceToast !== 'undefined') { EasyInvoiceToast.error('" . esc_js($message) . "', " . json_encode($options) . "); }</script>";
    }
}

/**
 * Display a warning toast notification
 *
 * @since 1.0.0
 * @param string $message The message to display
 * @param array $options Additional options
 */
function easy_invoice_toast_warning($message, $options = array()) {
    if (wp_doing_ajax()) {
        wp_send_json_error(array(
            'toast' => array(
                'type' => 'warning',
                'message' => $message,
                'options' => $options
            )
        ));
    } else {
        echo "<script>if (typeof EasyInvoiceToast !== 'undefined') { EasyInvoiceToast.warning('" . esc_js($message) . "', " . json_encode($options) . "); }</script>";
    }
}

/**
 * Display an info toast notification
 *
 * @since 1.0.0
 * @param string $message The message to display
 * @param array $options Additional options
 */
function easy_invoice_toast_info($message, $options = array()) {
    if (wp_doing_ajax()) {
        wp_send_json_success(array(
            'toast' => array(
                'type' => 'info',
                'message' => $message,
                'options' => $options
            )
        ));
    } else {
        echo "<script>if (typeof EasyInvoiceToast !== 'undefined') { EasyInvoiceToast.info('" . esc_js($message) . "', " . json_encode($options) . "); }</script>";
    }
}