<?php
/**
 * Checkout Form
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.
 */

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

do_action( 'woocommerce_before_checkout_form', $checkout );

// If checkout registration is disabled and not logged in, the user cannot checkout.
if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
	echo '<div class="container-main mt-8"><div class="bg-red-50 border border-red-200 rounded-xl p-6 text-center"><p class="text-red-700 font-semibold">' . esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) ) ) . '</p></div></div>';
	return;
}

?>

<div class="mt-6 md:mt-8 lg:mt-10">
    
    <!-- هدر صفحه -->
    <div class="mb-6">
        <h1 class="text-2xl md:text-3xl font-bold text-gray-800">تسویه حساب</h1>
        <p class="text-gray-600 text-sm mt-2">لطفاً اطلاعات خود را تکمیل کنید</p>
    </div>

    <form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data" aria-label="<?php echo esc_attr__( 'Checkout', 'woocommerce' ); ?>">

        <div class="flex flex-col lg:flex-row gap-6 lg:gap-8">
            
            <!-- بخش اطلاعات مشتری -->
            <div class="lg:w-2/3">
                
                <?php if ( $checkout->get_checkout_fields() ) : ?>

                    <?php do_action( 'woocommerce_checkout_before_customer_details' ); ?>

                    <div class="space-y-6" id="customer_details">
                        
                        <!-- اطلاعات صورتحساب -->
                        <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-6">
                            <h2 class="text-xl font-bold text-gray-800 mb-6 pb-4 border-b border-gray-200">
                                <i class="ri-user-line ml-2 text-emerald-600"></i>
                                اطلاعات صورتحساب
                            </h2>
                            <?php do_action( 'woocommerce_checkout_billing' ); ?>
                        </div>

                        <!-- اطلاعات ارسال -->
                        <?php if ( function_exists('WC') && WC()->cart->needs_shipping() && ! wc_ship_to_billing_address_only() ) : ?>
                        <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-6">
                            <h2 class="text-xl font-bold text-gray-800 mb-6 pb-4 border-b border-gray-200">
                                <i class="ri-truck-line ml-2 text-emerald-600"></i>
                                اطلاعات ارسال
                            </h2>
                            <?php do_action( 'woocommerce_checkout_shipping' ); ?>
                        </div>
                        <?php endif; ?>

                    </div>

                    <?php do_action( 'woocommerce_checkout_after_customer_details' ); ?>

                <?php endif; ?>
                
            </div>
            
            <!-- بخش خلاصه سفارش -->
            <div class="lg:w-1/3">
                <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-6 sticky top-6">
                    <?php do_action( 'woocommerce_checkout_before_order_review_heading' ); ?>
                    
                    <h2 class="text-xl font-bold text-gray-800 mb-6 pb-4 border-b border-gray-200" id="order_review_heading">
                        <i class="ri-shopping-bag-3-line ml-2 text-emerald-600"></i>
                        خلاصه سفارش
                    </h2>
                    
                    <?php do_action( 'woocommerce_checkout_before_order_review' ); ?>

                    <div id="order_review" class="woocommerce-checkout-review-order">
                        <?php do_action( 'woocommerce_checkout_order_review' ); ?>
                    </div>

                    <?php do_action( 'woocommerce_checkout_after_order_review' ); ?>
                </div>
            </div>
            
        </div>

    </form>
    
</div>

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

