jQuery(document).ready(function ($) {
    // Register the filter
    elementor.hooks.addFilter('cool_formkit/forms/content_template/item', function (field, item, form) {
        // Check if the field type is 'date'
        if (field.field_type == "date") {
            // Initialize variables
            let minFieldId = field['link_min_fieldId'] ? field['link_min_fieldId'] : '';
            let maxFieldId = field['link_max_fieldId'] ? field['link_max_fieldId'] : '';
            let fieldId = field['_id'] ? field['_id'] : '';
            let customId = field['custom_id'] ? field['custom_id'] : '';


            if (!field.attributes) {
                field.attributes = {};
            }
            // Add attributes dynamically to the field
            if (minFieldId) {
                field.attributes['ccfef_link_min_fieldId'] = minFieldId;
            }
            if (maxFieldId) {
                field.attributes['ccfef_link_max_fieldId'] = maxFieldId;
            }
            if (fieldId) {
                field.attributes['ccfef_fieldId'] = fieldId;
            }
            if (customId) {
                field.attributes['ccfef_customId'] = customId;
            }

             // Add custom CSS classes if needed
            field.attributes += ` ccfef_link_min_fieldId_"${minFieldId}" ccfef_link_max_fieldId_"${maxFieldId}"`;
            field.css_classes += ` ccfef_link_min_fieldId_"${minFieldId}" ccfef_link_max_fieldId_"${maxFieldId}" ccfef_fieldId_"${fieldId}" ccfef_customId_"${customId}" `;
        }
        return field;
    }, 10, 4);
});

  