define([
    'jquery',
    'mage/utils/wrapper',
    'Magento_Checkout/js/model/quote'
], function ($, wrapper, quote) {
    'use strict';

    console.log('🔧 SHIPPING FIELDS: Set Shipping Information Mixin LOADED!');

    return function (targetModule) {
        return wrapper.wrap(targetModule, function (originalAction) {
            console.log('🚢 SHIPPING FIELDS: Mixin executing');
            
            try {
                var shippingDate = null;
                var shippingMessage = null;
                
                // Get field values from DOM
                $('input, textarea, select').each(function() {
                    var $this = $(this);
                    var name = ($this.attr('name') || '').toLowerCase();
                    var value = $this.val();
                    
                    if (value && name.includes('shipping_date')) {
                        shippingDate = value;
                        console.log('�� Found shipping_date:', shippingDate);
                    }
                    if (value && name.includes('shipping_message')) {
                        shippingMessage = value;
                        console.log('📝 Found shipping_message:', shippingMessage);
                    }
                });
                
                // Store in window object for plugin to access
                window.shippingFieldsData = {
                    shipping_date: shippingDate,
                    shipping_message: shippingMessage
                };
                console.log('✅ Stored shipping fields data:', window.shippingFieldsData);
                
            } catch (error) {
                console.error('❌ Error in shipping fields mixin:', error);
            }

            return originalAction();
        });
    };
});
