<?php
/**
 * Order selector for a signed in customer.
 *
 * @package SkyServers\Retragere
 *
 * @var array<string,mixed> $args
 */

declare(strict_types=1);

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

$ssrcOrders   = isset($args['orders']) && is_array($args['orders']) ? $args['orders'] : [];
$ssrcSelected = isset($args['selected']) ? (int) $args['selected'] : 0;

if ([] === $ssrcOrders) {
    return;
}
?>
<p>
    <label for="ssrc-order"><?php esc_html_e('The order you are withdrawing from', 'skyservers-retragere-contract'); ?></label><br>
    <select id="ssrc-order" name="ssrc_order">
        <option value="0"><?php esc_html_e('— My order is not in the list —', 'skyservers-retragere-contract'); ?></option>
        <?php foreach ($ssrcOrders as $ssrcOrder) : ?>
            <option value="<?php echo esc_attr((string) $ssrcOrder->get_id()); ?>"
                data-order-number="<?php echo esc_attr((string) $ssrcOrder->get_order_number()); ?>"
                <?php selected($ssrcSelected, (int) $ssrcOrder->get_id()); ?>>
                <?php
                printf(
                    '#%1$s — %2$s — %3$s',
                    esc_html((string) $ssrcOrder->get_order_number()),
                    esc_html(wc_format_datetime($ssrcOrder->get_date_created())),
                    wp_kses_post($ssrcOrder->get_formatted_order_total())
                );
                ?>
            </option>
        <?php endforeach; ?>
    </select>
</p>
<p class="description">
    <?php esc_html_e('If you cannot find your order in the list, choose the first option and write its number below. The request is recorded either way.', 'skyservers-retragere-contract'); ?>
</p>
