<?php
/**
 * Checkout billing information form
 *
 * Template aligned with WooCommerce 3.6.0
 * @see https://woocommerce.com/document/template-structure/
 * @package Pawfect
 * @version 10.9.1
 */

defined( 'ABSPATH' ) || exit;
?>
<div class="woocommerce-billing-fields">
    <?php if ( wc_ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>

        <h3 class="pawfect-font-serif pawfect-text-3xl pawfect-mb-6">
            <?php esc_html_e( 'Billing &amp; Shipping', 'pawfect' ); ?>
        </h3>

    <?php else : ?>

        <h3 class="pawfect-font-serif pawfect-text-3xl pawfect-mb-6">
            <?php esc_html_e( 'Billing details', 'pawfect' ); ?>
        </h3>

    <?php endif; ?>

    <?php do_action( 'woocommerce_before_checkout_billing_form', $checkout ); ?>

    <div class="woocommerce-billing-fields__field-wrapper pawfect-grid pawfect-grid-cols-1 md:pawfect-grid-cols-2 pawfect-gap-6">
        <?php
        $fields = $checkout->get_checkout_fields( 'billing' );

        foreach ( $fields as $key => $field ) {
            // Determine column span
            $col_span_class = '';
            if (in_array($key, ['billing_country', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_email'])) {
                $col_span_class = 'md:pawfect-col-span-2';
            } else {
                $col_span_class = 'md:pawfect-col-span-1';
            }
            
            echo '<div class="' . esc_attr($col_span_class) . '">';
            woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
            echo '</div>';
        }
        ?>
    </div>

    <?php do_action( 'woocommerce_after_checkout_billing_form', $checkout ); ?>
</div>

<?php if ( ! is_user_logged_in() && $checkout->is_registration_enabled() ) : ?>
    <div class="woocommerce-account-fields pawfect-mt-8">
        <?php if ( ! $checkout->is_registration_required() ) : ?>

            <p class="form-row form-row-wide create-account">
                <label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
                    <input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true ); ?> type="checkbox" name="createaccount" value="1" /> <span><?php esc_html_e( 'Create an account?', 'pawfect' ); ?></span>
                </label>
            </p>

        <?php endif; ?>

        <?php do_action( 'woocommerce_before_checkout_registration_form', $checkout ); ?>

        <?php if ( $checkout->get_checkout_fields( 'account' ) ) : ?>

            <div class="create-account">
                <?php foreach ( $checkout->get_checkout_fields( 'account' ) as $key => $field ) : ?>
                    <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
                <?php endforeach; ?>
                <div class="clear"></div>
            </div>

        <?php endif; ?>

        <?php do_action( 'woocommerce_after_checkout_registration_form', $checkout ); ?>
    </div>
<?php endif; ?>

