<?php
/**
 * Shared utility helpers for WP Mail Doctor email functionality.
 *
 * @package MailDoctor
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Attempt to resolve a sample order ID for previews.
 *
 * @return int
 */
function mail_doctor_find_sample_order_id(): int {
	if ( ! function_exists( 'wc_get_orders' ) ) {
		return 0;
	}

	$orders = wc_get_orders(
		array(
			'limit'   => 1,
			'orderby' => 'date',
			'order'   => 'DESC',
			'return'  => 'ids',
		)
	);

	if ( empty( $orders ) ) {
		return 0;
	}

	return (int) $orders[0];
}
