/*
Theme Name:   Blocksy Child
Theme URI:    https://creativethemes.com/blocksy/
Description:  A custom child theme for the Blocksy WordPress theme.
Author:       Your Name
Author URI:   https://binadar.com/
Template:     blocksy
Version:      1.0.0
License:      GNU General Public License v2 or later
License URI:  http://www.gnu.org/licenses/gpl-2.0.html
*/

/* يمكنك إضافة تنسيقات الـ CSS المخصصة الخاصة بك هنا */

/*
Plugin Name: تنسيق حقول الدفع - ضبط المسافات
Description: مباعدة احترافية بين المدينة ورقم الجوال لتتطابق مع الحقول العلوية.
Version: 5.0
Author: Gemini
*/

add_filter( 'woocommerce_checkout_fields' , 'custom_perfect_spacing_fields' );

function custom_perfect_spacing_fields( $fields ) {

    // 1. إخفاء الحقول غير المطلوبة
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_company']);

    // 2. توزيع الأدوار (يمين ويسار) والترتيب
    $fields['billing']['billing_first_name']['class'] = array('form-row-first');
    $fields['billing']['billing_email']['class']      = array('form-row-last');
    $fields['billing']['billing_city']['class']       = array('form-row-first');
    $fields['billing']['billing_phone']['class']      = array('form-row-last');

    // تحديد الأولويات لضمان التتابع الصحيح
    $fields['billing']['billing_country']['priority']    = 10;
    $fields['billing']['billing_first_name']['priority'] = 20;
    $fields['billing']['billing_email']['priority']      = 30;
    $fields['billing']['billing_city']['priority']       = 40;
    $fields['billing']['billing_phone']['priority']      = 50;

    return $fields;
}

// 3. كود CSS لإجبار المباعدة (Margin)
add_action( 'wp_head', 'custom_css_spacing_logic' );
function custom_css_spacing_logic() {
    if ( is_checkout() ) {
        echo '<style>
            /* ضبط عام لكافة الحقول المزدوجة في السطر الواحد */
            #billing_first_name_field, #billing_email_field, 
            #billing_city_field, #billing_phone_field {
                width: 48% !important; /* عرض الحقل */
                display: inline-block !important;
                clear: none !important;
                vertical-align: top !important;
            }

            /* الحقل الأيمن (المدينة والاسم) يحصل على مسافة دفع من اليسار */
            #billing_first_name_field, #billing_city_field {
                float: right !important;
                margin-left: 4% !important; /* هذه هي المباعدة المطلوبة */
                margin-right: 0 !important;
            }

            /* الحقل الأيسر (البريد والجوال) يتم تثبيته لليسار تماماً */
            #billing_email_field, #billing_phone_field {
                float: left !important;
                margin-left: 0 !important;
                margin-right: 0 !important;
            }

            /* تنسيق الحواف والخلفية لتكون مريحة للعين */
            .woocommerce-checkout input.input-text {
                background-color: #f9f9f9 !important;
                border: 1px solid #e0e0e0 !important;
                border-radius: 8px !important;
                padding: 12px !important;
            }

            /* تأكد من أن الحقول تعود لعرضها الكامل في الشاشات الصغيرة */
            @media (max-width: 768px) {
                #billing_first_name_field, #billing_email_field, 
                #billing_city_field, #billing_phone_field {
                    width: 100% !important;
                    margin-left: 0 !important;
                    float: none !important;
                }
            }
        </style>';
    }
}




    //الى هنا استيراد الحد الادنى


// إنشاء كود مختصر لجلب بيانات البنك: [bank_details]
add_shortcode('bank_details', 'display_bacs_accounts_anywhere');

function display_bacs_accounts_anywhere() {
    $bacs_accounts = get_option('woocommerce_bacs_accounts');
    
    if (empty($bacs_accounts)) {
        return '<p>لا توجد حسابات بنكية مضافة في الإعدادات.</p>';
    }

    $output = '<div class="custom-bank-info-container">';
    foreach ($bacs_accounts as $account) {
        $output .= '<div class="bank-accounts__list-item" style="margin-bottom:20px; padding:15px; border:1px solid #eee;">';
        $output .= '<div class="bank-accounts__list-item-inner">'; // الكلاس الذي طلبته
        
        if (!empty($account['account_name']))   $output .= '<div><strong>اسم الحساب:</strong> ' . esc_html($account['account_name']) . '</div>';
        if (!empty($account['bank_name']))      $output .= '<div><strong>اسم البنك:</strong> ' . esc_html($account['bank_name']) . '</div>';
        if (!empty($account['account_number'])) $output .= '<div><strong>رقم الحساب:</strong> ' . esc_html($account['account_number']) . '</div>';
        if (!empty($account['iban']))           $output .= '<div><strong>IBAN:</strong> ' . esc_html($account['iban']) . '</div>';
        
        $output .= '</div>';
        $output .= '</div>';
    }
    $output .= '</div>';

    return $output;
}