jQuery(document).ready(function ($) {

    elementor.hooks.addFilter('elementor_pro/forms/content_template/item', function (field, item, form) {
        let telCountryCode = field['ccfef-country-code-field'];
        let inputFields = ['text', 'email', 'textarea', 'password', 'url', 'number', 'date', 'time', 'tel','select','country','state'];

        let field_icon_switcher = field.field_icon_switcher;
        let field_icon = field.field_icon.value;
        // Tel Icon switcher 
        let field_tel_icon_switcher = field.field_icon_tel_switcher;
        let field_tel_icon = field.field_tel_icon.value;
        const style = form.label_styles;
        const iconposition = form.lsfef_icon_position;

        let input_icon = "";
        let iconpositionclass = "";
        if (field_icon_switcher === "yes" || field_tel_icon_switcher == "yes") {
            input_icon = "icon_clss";
            iconpositionclass = `icon_${iconposition}_side`;
        }


        if (inputFields.includes(field.field_type) && form.show_labels === "true" && 'none' !== style) {

            field.css_classes += ` lsfef_custom_class lsfef_custom_style_class_${style} lsfef-form-style `;
        }


        if (inputFields.includes(field.field_type )) {
            if(field.field_type  == 'tel' && telCountryCode == 'yes'){
            } else if (field_icon_switcher === "yes" && field_icon !== '' || field_tel_icon_switcher === "yes" && field_tel_icon !== '' ) {
       
                field.css_classes += ` lsfef_custom_class lsfef_custom_style_class_${style} lsfef-form-style  ${input_icon} lsfe_icon_style_${iconpositionclass} `;
                if (field_icon_switcher === "yes") {
                    if( typeof field_icon == "string"){
                        const iconStyle = field_icon.replace(' ', '_');
                        field.css_classes += ` lsfef_icon_cls_${iconStyle} `;
                    }else{
                        const svgUrl = field_icon.url;
                        field.css_classes += ` lsfef_icon_cls_svg_${svgUrl} `; 
                    }
                }
                if (field_tel_icon_switcher === "yes") {
                    if(typeof field_tel_icon == "string"){
                        const iconStyle = field_tel_icon.replace(' ', '_');
                        field.css_classes += ` lsfef_icon_cls_${iconStyle} `;
                    }else{
                        const svgUrl = field_icon.url;
                        field.css_classes += ` lsfef_icon_cls_svg_${svgUrl} `; 
                    }
                }
            }       
        }
        return field;
    }, 10, 4);
});

