<?php
defined( 'ABSPATH' ) || exit;
/**
 * Booking policy snippet.
 *
 * Expected variables:
 * - Optional: $bookaro_policy_lines (array)
 * - Optional: $bookaro_policy_cancel
 * - Optional: $bookaro_policy_reschedule
 * - Optional: $bookaro_policy_payment
 * - Optional: $bookaro_policy_deposit
 * - Optional: $bookaro_policy_cancel_fee
 * - Optional: $bookaro_policy_no_show_fee
 * - Optional: $bookaro_policies (combined fallback)
 */
$bookaro_policy_cancel = isset( $bookaro_policy_cancel ) ? trim( (string) $bookaro_policy_cancel ) : '';
$bookaro_policy_reschedule = isset( $bookaro_policy_reschedule ) ? trim( (string) $bookaro_policy_reschedule ) : '';
$bookaro_policy_payment = isset( $bookaro_policy_payment ) ? trim( (string) $bookaro_policy_payment ) : '';
$bookaro_policy_deposit = isset( $bookaro_policy_deposit ) ? trim( (string) $bookaro_policy_deposit ) : '';
$bookaro_policy_cancel_fee = isset( $bookaro_policy_cancel_fee ) ? trim( (string) $bookaro_policy_cancel_fee ) : '';
$bookaro_policy_no_show_fee = isset( $bookaro_policy_no_show_fee ) ? trim( (string) $bookaro_policy_no_show_fee ) : '';
$bookaro_policies = isset( $bookaro_policies ) ? trim( (string) $bookaro_policies ) : '';

$bookaro_policy_lines = isset( $bookaro_policy_lines ) && is_array( $bookaro_policy_lines )
    ? array_values(
        array_filter(
            array_map(
                static function ( $line ): string {
                    return trim( (string) $line );
                },
                $bookaro_policy_lines
            )
        )
    )
    : [];

if ( empty( $bookaro_policy_lines ) ) {
    $bookaro_policy_lines = array_values(
        array_filter(
            [
                $bookaro_policy_cancel,
                $bookaro_policy_reschedule,
                $bookaro_policy_payment,
                $bookaro_policy_deposit,
                $bookaro_policy_cancel_fee,
                $bookaro_policy_no_show_fee,
            ]
        )
    );
}

if ( empty( $bookaro_policy_lines ) && $bookaro_policies !== '' ) {
    $bookaro_policy_lines[] = $bookaro_policies;
}

if ( empty( $bookaro_policy_lines ) ) {
    return;
}
?>
<div class="bookaro-policy-snippet">
    <h3 class="bookaro-email-subheading"><?php esc_html_e( 'Booking policy', 'mybookaro' ); ?></h3>
    <ul class="bookaro-policy-list">
        <?php foreach ( $bookaro_policy_lines as $bookaro_policy_line ) : ?>
            <li><?php echo esc_html( $bookaro_policy_line ); ?></li>
        <?php endforeach; ?>
    </ul>
</div>
