<?php

/**
 * Extra Product Options for WooCommerce Actions
 *
 * Handles all action and filter hooks for the plugin.
 *
 * @package Extra_Product_Options_For_WooCommerce
 * @since   2.5
 */
// If this file is called directly, abort.
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
/**
 * Function will add class for label.
 *
 * @since 2.5
 *
 * @param string $field_label_class Label of the class.
 *
 * @return string $field_label_class Label of the class.
 */
function epofw_get_field_label_class_callback(  $field_label_class  ) {
    $field_label_class = $field_label_class . ' epofw_td_label';
    return $field_label_class;
}

add_filter( 'epofw_get_field_label_class', 'epofw_get_field_label_class_callback' );
/**
 * Function will display field label html.
 *
 * @since 2.5
 *
 * @param array $field_input_property Array of field input.
 * @param array $fields_data          Array of fields data.
 *
 * @return array $field_input_property Array of field input.
 */
function epofw_get_field_input_property_callback(  $field_input_property, $fields_data  ) {
    $check_field_lbl_title = epofw_get_field_label_title( $fields_data );
    $field_input_property['data-label-name'] = $check_field_lbl_title;
    // Get field type and restriction to set appropriate HTML5 input type.
    $field_type = ( isset( $fields_data['field']['type'] ) ? $fields_data['field']['type'] : '' );
    // Field restriction can be in multiple locations depending on context.
    $field_restriction = '';
    if ( isset( $field_input_property['field_restriction'] ) && !empty( $field_input_property['field_restriction'] ) ) {
        // Check in input property first (passed as attribute).
        $field_restriction = $field_input_property['field_restriction'];
    } elseif ( isset( $fields_data['field']['field_restriction'] ) && !empty( $fields_data['field']['field_restriction'] ) ) {
        // Check in field array.
        $field_restriction = $fields_data['field']['field_restriction'];
    } elseif ( isset( $fields_data['epofw_field_settings']['field_restriction'] ) && !empty( $fields_data['epofw_field_settings']['field_restriction'] ) ) {
        // Check in field settings array.
        $field_restriction = $fields_data['epofw_field_settings']['field_restriction'];
    }
    // Only modify type for text fields with specific restrictions.
    if ( 'text' === $field_type && !empty( $field_restriction ) ) {
        switch ( $field_restriction ) {
            case 'email':
                // Set HTML5 email input type for better UX (mobile keyboard, browser validation).
                $field_input_property['type'] = 'email';
                $field_input_property['autocomplete'] = 'email';
                // Add inputmode for better mobile support.
                $field_input_property['inputmode'] = 'email';
                // Add a stricter pattern to require proper domain with TLD (e.g., .com, .org).
                $field_input_property['pattern'] = '[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}';
                $field_input_property['title'] = __( 'Please enter a valid email address (e.g., name@example.com)', 'extra-product-options-for-woocommerce' );
                break;
            case 'url':
                // Set HTML5 url input type for better UX (mobile keyboard, browser validation).
                $field_input_property['type'] = 'url';
                $field_input_property['autocomplete'] = 'url';
                $field_input_property['inputmode'] = 'url';
                // Add a pattern to require a proper URL format with protocol.
                $field_input_property['pattern'] = 'https?://.+\\..+';
                $field_input_property['title'] = __( 'Please enter a valid URL (e.g., https://example.com)', 'extra-product-options-for-woocommerce' );
                break;
            case 'tel':
                // Set HTML5 tel input type for better UX (mobile phone keyboard).
                $field_input_property['type'] = 'tel';
                $field_input_property['autocomplete'] = 'tel';
                $field_input_property['inputmode'] = 'tel';
                // Pattern allows international formats: +1-234-567-8900, (123) 456-7890, 123.456.7890, etc.
                $field_input_property['pattern'] = '[0-9+\\-\\s().]{7,20}';
                $field_input_property['title'] = __( 'Please enter a valid phone number (e.g., +1-234-567-8900)', 'extra-product-options-for-woocommerce' );
                break;
            case 'only_number':
            case 'all_number':
                // Set numeric input mode for better mobile keyboard.
                $field_input_property['inputmode'] = 'numeric';
                break;
        }
    }
    return $field_input_property;
}

add_filter(
    'epofw_get_field_input_property',
    'epofw_get_field_input_property_callback',
    10,
    2
);
/**
 * Function will display field label html.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args {
 *     The array of data.
 *
 *     @type object    $product_data   Data of the current product.
 *     @type int|float $product_price  Product price.
 *     @type string    $opt_price_type Price type - Fixed, Percentage of product price or etc.
 *     @type string    $epofw_action   Page action - shop|product page.
 *     @type array     $fields_data    Array of addon data.
 * }
 */
function epofw_html_table_field_label_td_callback(  $args  ) {
    _deprecated_function(
        'epofw_html_table_field_label_td_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_html_table_field_label_td is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    wc_get_template(
        'epofw-field-label-html.php',
        array(
            'epofwtwp_args' => $args,
        ),
        epofw_get_template_path(),
        epofw_get_default_path()
    );
}

add_action(
    'epofw_html_table_field_label_td',
    'epofw_html_table_field_label_td_callback',
    10,
    1
);
/**
 * Function will display field input html.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args {
 *                                 The array of data.
 *
 * @type object    $product_data   Data of the current product.
 * @type int|float $product_price  Product price.
 * @type string    $opt_price_type Price type - Fixed, Percentage of product price or etc.
 * @type string    $epofw_action   Page action - shop|product page.
 * @type array     $fields_data    Array of addon data.
 * }
 */
function epofw_html_table_field_input_td_callback(  $args  ) {
    _deprecated_function(
        'epofw_html_table_field_input_td_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_html_table_field_input_td is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    wc_get_template(
        'epofw-field-input-html.php',
        array(
            'epofwtwp_args' => $args,
        ),
        epofw_get_template_path(),
        epofw_get_default_path()
    );
}

add_action(
    'epofw_html_table_field_input_td',
    'epofw_html_table_field_input_td_callback',
    10,
    1
);
/**
 * Function will display field title.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args {
 *                                 The array of data.
 *
 * @type object    $product_data   Data of the current product.
 * @type int|float $product_price  Product price.
 * @type string    $opt_price_type Price type - Fixed, Percentage of product price or etc.
 * @type string    $epofw_action   Page action - shop|product page.
 * @type array     $fields_data    Array of addon data.
 * }
 */
function epofw_field_title_callback(  $args  ) {
    _deprecated_function(
        'epofw_field_title_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_field_title is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    $fields_data = ( isset( $args['epofwtwp_args']['fields_data'] ) ? $args['epofwtwp_args']['fields_data'] : array() );
    // Skip rendering if title position is "above" - label template already handles it.
    $check_field_title_position = epofw_get_field_label_title_position( $fields_data );
    if ( 'above' === $check_field_title_position ) {
        return;
    }
    $check_field_inp_type = epofw_get_field_type( $fields_data );
    $check_field_lbl_title_type = epofw_get_field_label_title_type( $fields_data );
    $check_field_lbl_title = epofw_get_field_label_title( $fields_data );
    $check_field_lbl_data_name = '';
    if ( $check_field_lbl_title ) {
        $check_field_lbl_data_name = 'data-label-name="' . $check_field_lbl_title . '"';
    }
    $check_field_lbl_class = epofw_get_field_label_class( $fields_data );
    $heading_type = $check_field_lbl_title_type;
    $title_or_content = $check_field_lbl_title;
    $title_styles = '';
    $color_attr = '';
    if ( $check_field_lbl_class ) {
        /**
         * Filter for title label class.
         *
         * @since 1.0.0
         */
        $check_field_lbl_class = apply_filters( 'epofw_field_title_lbl_class', $check_field_lbl_class, $args );
        $check_field_lbl_class = 'class="' . $check_field_lbl_class . '"';
    }
    $check_hop = '';
    if ( 'on' !== $check_hop && isset( $fields_data['epofw_field_settings']['enable_price_extra'] ) && 'on' === $fields_data['epofw_field_settings']['enable_price_extra'] ) {
        $price_label_for_text = epofw_title_with_price( $args['epofwtwp_args'], $fields_data );
        $title_or_content = $title_or_content . $price_label_for_text;
    }
    if ( 'heading' === $check_field_inp_type ) {
        $heading_type = epofw_get_field_heading_type( $fields_data );
        $title_or_content = epofw_get_field_label_title( $fields_data );
    }
    if ( 'paragraph' === $check_field_inp_type ) {
        $heading_type = epofw_get_field_content_type( $fields_data );
        $title_or_content = epofw_get_field_content( $fields_data );
    }
    $html = '<' . $heading_type . ' ' . $check_field_lbl_class . ' ' . $color_attr . ' ' . $check_field_lbl_data_name . ' ' . $title_styles . '>' . $title_or_content . '</' . $heading_type . '>';
    /**
     * Filter for title action.
     *
     * @since 1.0.0
     */
    echo wp_kses_post( apply_filters( 'epofw_field_title_action', $html, $args ) );
}

add_action(
    'epofw_field_title',
    'epofw_field_title_callback',
    10,
    2
);
/**
 * Function will display field subtitle.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args {
 * The array of data.
 *
 * @type object    $product_data   Data of the current product.
 * @type int|float $product_price  Product price.
 * @type string    $opt_price_type Price type - Fixed, Percentage of product price or etc.
 * @type string    $epofw_action   Page action - shop|product page.
 * @type array     $fields_data    Array of addon data.
 * }
 */
function epofw_field_subtitle_callback(  $args  ) {
    _deprecated_function(
        'epofw_field_subtitle_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_field_subtitle is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    $fields_data = ( isset( $args['epofwtwp_args']['fields_data'] ) ? $args['epofwtwp_args']['fields_data'] : array() );
    // Skip rendering if title position is "above" - label template already handles it.
    $check_field_title_position = epofw_get_field_label_title_position( $fields_data );
    if ( 'above' === $check_field_title_position ) {
        return;
    }
    $html = '';
    $check_field_lbl_subtitle = epofw_get_field_label_subtitle( $fields_data );
    $check_field_lbl_subtitle_type = epofw_get_field_label_subtitle_type( $fields_data );
    $check_field_lbl_subtitle_class = epofw_get_field_label_subtitle_class( $fields_data );
    /**
     * Filter for subtitle label class.
     *
     * @since 1.0.0
     */
    $check_field_lbl_subtitle_class = ( !empty( $check_field_lbl_subtitle_class ) ? 'class="' . apply_filters( 'epofw_field_subtitle_lbl_subtitle', $check_field_lbl_subtitle_class, $args ) . '"' : '' );
    $subtitle_styles = '';
    if ( $check_field_lbl_subtitle ) {
        $html = '<' . $check_field_lbl_subtitle_type . ' ' . $check_field_lbl_subtitle_class . ' ' . $subtitle_styles . '>' . $check_field_lbl_subtitle . '</' . $check_field_lbl_subtitle_type . '>';
    }
    /**
     * Filter for subtitle action.
     *
     * @since 1.0.0
     */
    echo wp_kses_post( apply_filters( 'epofw_field_subtitle_action', $html, $args ) );
}

add_action(
    'epofw_field_subtitle',
    'epofw_field_subtitle_callback',
    10,
    1
);
/**
 * Function will display start td html.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args {
 * The array of data.
 *
 * @type object    $product_data   Data of the current product.
 * @type int|float $product_price  Product price.
 * @type string    $opt_price_type Price type - Fixed, Percentage of product price or etc.
 * @type string    $epofw_action   Page action - shop|product page.
 * @type array     $fields_data    Array of addon data.
 * }
 */
function epofw_field_label_start_td_callback(  $args  ) {
    _deprecated_function(
        'epofw_field_label_start_td_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_field_label_start_td is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    $fields_data = ( isset( $args['epofwtwp_args']['fields_data'] ) ? $args['epofwtwp_args']['fields_data'] : array() );
    $check_field_inp_type = epofw_get_field_type( $fields_data );
    /**
     * Filter for start label tag.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $tag = apply_filters( 'epofw_field_label_start_tag_display', 'div', $args );
    /**
     * Filter for td label class.
     *
     * @since 1.0.0
     */
    $label_class = apply_filters( 'epofw_field_td_label_class', 'label epofw_td_label', $args );
    ?>
	<<?php 
    echo esc_html( $tag );
    ?> class="<?php 
    echo esc_attr( $label_class );
    ?>"
	<?php 
    if ( 'heading' === $check_field_inp_type || 'paragraph' === $check_field_inp_type ) {
        echo 'colspan="2"';
    }
    ?>
	>
	<?php 
}

add_action(
    'epofw_field_label_start_td',
    'epofw_field_label_start_td_callback',
    10,
    1
);
/**
 * Function will display start td html.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args {
 * The array of data.
 *
 * @type object    $product_data   Data of the current product.
 * @type int|float $product_price  Product price.
 * @type string    $opt_price_type Price type - Fixed, Percentage of product price or etc.
 * @type string    $epofw_action   Page action - shop|product page.
 * @type array     $fields_data    Array of addon data.
 * }
 */
function epofw_field_label_end_td_callback(  $args  ) {
    _deprecated_function(
        'epofw_field_label_end_td_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_field_label_end_td is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    /**
     * Filter for end label tag class.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $tag = apply_filters( 'epofw_field_label_end_tag_display', 'div', $args );
    ?>
	</<?php 
    echo esc_html( $tag );
    ?>>
	<?php 
}

add_action(
    'epofw_field_label_end_td',
    'epofw_field_label_end_td_callback',
    10,
    1
);
/**
 * Function will display start td html.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args {
 * The array of data.
 *
 * @type object    $product_data   Data of the current product.
 * @type int|float $product_price  Product price.
 * @type string    $opt_price_type Price type - Fixed, Percentage of product price or etc.
 * @type string    $epofw_action   Page action - shop|product page.
 * @type array     $fields_data    Array of addon data.
 * }
 */
function epofw_field_input_start_td_callback(  $args  ) {
    _deprecated_function(
        'epofw_field_input_start_td_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_field_input_start_td is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    $fields_data = ( isset( $args['epofwtwp_args']['fields_data'] ) ? $args['epofwtwp_args']['fields_data'] : array() );
    $check_field_title_position = epofw_get_field_label_title_position( $fields_data );
    /**
     * Filter for input start tag.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $tag = apply_filters( 'epofw_field_input_start_tag_display', 'div', $args );
    /**
     * Filter for td class.
     *
     * @since 1.0.0
     */
    $input_class = apply_filters( 'epofw_field_td_input_class', 'value epofw_td_value epofw_' . $check_field_title_position, $args );
    ?>
	<<?php 
    echo esc_html( $tag );
    ?> class="<?php 
    echo esc_attr( $input_class );
    ?>"
	<?php 
    if ( !empty( $args ) ) {
        echo 'data-epofw_sa="' . esc_attr( wc_esc_json( epofw_all_fields_attr( $args ) ) ) . '"';
    }
    ?>
	>
	<?php 
}

add_action(
    'epofw_field_input_start_td',
    'epofw_field_input_start_td_callback',
    10,
    1
);
/**
 * Function will display start td html.
 *
 * @since 2.5
 *
 * @param array $args {
 * The array of data.
 *
 * @type object    $product_data   Data of the current product.
 * @type int|float $product_price  Product price.
 * @type string    $opt_price_type Price type - Fixed, Percentage of product price or etc.
 * @type string    $epofw_action   Page action - shop|product page.
 * @type array     $fields_data    Array of addon data.
 * }
 */
function epofw_field_input_end_td_callback(  $args  ) {
    /**
     * Filter for end input tag.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $tag = apply_filters( 'epofw_field_input_end_tag_display', 'div', $args );
    ?>
	</<?php 
    echo esc_html( $tag );
    ?>>
	<?php 
}

add_action(
    'epofw_field_input_end_td',
    'epofw_field_input_end_td_callback',
    10,
    1
);
/**
 * Function will modify input id in shop page because should be unique in shop page.
 *
 * @since 2.5
 *
 * @param string $attr_value Old input id value.
 * @param array  $args       Array of args.
 *
 * @return string
 */
function epofw_modifiy_field_id_property_callback(  $attr_value, $args  ) {
    $epofw_action = ( isset( $args['epofwtwp_args']['epofw_action'] ) ? $args['epofwtwp_args']['epofw_action'] : '' );
    $product_data = ( isset( $args['epofwtwp_args']['product_data'] ) ? $args['epofwtwp_args']['product_data'] : '' );
    if ( 'epofw_shop' === $epofw_action ) {
        if ( !empty( $product_data ) ) {
            $attr_value = 'epofw_shop_' . $product_data->get_id() . '_' . $attr_value;
        }
    }
    return $attr_value;
}

add_action(
    'epofw_field_property_text_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_password_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_hidden_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_number_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_datepicker_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_colorpicker_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_checkbox_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_checkboxgroup_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_radiogroup_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_textarea_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_select_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_multiselect_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_timepicker_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_switch_id',
    'epofw_modifiy_field_id_property_callback',
    10,
    2
);
/**
 * Function will modify input name in shop page because should be unique in shop page.
 *
 * @since 2.5
 *
 * @param string $attr_value Old input name value.
 * @param array  $args       Array of args.
 *
 * @return string
 */
function epofw_modifiy_field_name_property_callback(  $attr_value, $args  ) {
    return $attr_value;
}

add_action(
    'epofw_field_property_text_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_password_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_hidden_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_number_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_datepicker_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_colorpicker_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_checkbox_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_checkboxgroup_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_radiogroup_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_textarea_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_select_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_multiselect_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_timepicker_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
add_action(
    'epofw_field_property_switch_name',
    'epofw_modifiy_field_name_property_callback',
    10,
    2
);
/**
 * Function will print start of tr.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args Array of args.
 */
function epofw_html_start_tr_display_callback(  $args  ) {
    _deprecated_function(
        'epofw_html_start_tr_display_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_html_start_tr_display is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    $fields_data = ( isset( $args['fields_data'] ) ? $args['fields_data'] : array() );
    $fields_key = ( isset( $args['fields_key'] ) ? $args['fields_key'] : '' );
    $check_field_title_position = epofw_get_field_label_title_position( $fields_data );
    $check_field_inp_type = epofw_get_field_type( $fields_data );
    /**
     * Filter the HTML tag for the start of a table row (tr) during display.
     * Applies a filter to customize the HTML tag for the start of a table row (tr) based on the provided structure.
     *
     * @since 2.5
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     *
     * @param string $tag  The HTML tag for the start of a table row.
     * @param array  $args Additional arguments for customization.
     *
     * @return string Modified HTML tag for the start of a table row.
     */
    $tag = apply_filters( 'epofw_html_start_tr_tag_display', 'div', $args );
    /**
     * Filter the CSS class for a table row (tr) during display.
     * Applies a filter to customize the CSS class for a table row (tr) based on specific conditions.
     *
     * @since 2.5
     *
     * @param string $tr_class The default CSS class for the table row.
     * @param array  $args     Additional arguments for customization.
     *
     * @return string Modified CSS class for the table row.
     */
    $tr_class = apply_filters( 'epofw_html_tr_class_display', 'epofw_tr_se epofw_label_' . $check_field_title_position, $args );
    ?>
	<<?php 
    echo esc_html( $tag );
    ?> class="<?php 
    echo esc_attr( $tr_class );
    ?>"  id="epofw_<?php 
    echo esc_attr( $check_field_inp_type );
    ?>_<?php 
    echo esc_attr( $fields_key );
    ?>"
	<?php 
    ?>
	>
	<?php 
}

add_action(
    'epofw_html_start_tr_display',
    'epofw_html_start_tr_display_callback',
    10,
    1
);
/**
 * Function will print end of tr.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array $args Array of args.
 */
function epofw_html_end_tr_display_callback(  $args  ) {
    _deprecated_function(
        'epofw_html_end_tr_display_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_html_end_tr_display is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    /**
     * Filter for end tr tag.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $tag = apply_filters( 'epofw_html_end_tr_tag_display', 'div', $args );
    ?>
	</<?php 
    echo esc_html( $tag );
    ?>>
	<?php 
}

add_action(
    'epofw_html_end_tr_display',
    'epofw_html_end_tr_display_callback',
    10,
    1
);
/**
 * Function will print start table and tbody.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 *
 * @param array  $fields_data_arr Fields data array.
 * @param object $product_data    Product data.
 */
function epofw_html_start_table_display_callback(  $fields_data_arr, $product_data  ) {
    _deprecated_function(
        'epofw_html_start_table_display_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_html_start_table_display is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    $additional_rule_datas = array();
    $additional_data = epofw_data_attr_json( $additional_rule_datas );
    $fields_data_arr = epofw_check_array_key_exists( 'general', $fields_data_arr );
    $data_attr = ( isset( $additional_data['data_attr'] ) ? $additional_data['data_attr'] : array() );
    $condition_type = ( isset( $additional_data['condition_type'] ) ? $additional_data['condition_type'] : '' );
    // Default class for displaying fields.
    $epofw_tbl_class = 'epofw_field_dl';
    /**
     * Filter for start main tag.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $main_tag = apply_filters( 'epofw_html_start_main_tag_display', 'div', $fields_data_arr );
    /**
     * Filter for start child tag.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $child_tag = apply_filters( 'epofw_html_start_child_tag_display', 'div', $fields_data_arr );
    /**
     * Filter for main tag class.
     *
     * @since 1.0.0
     */
    $main_tag_class = apply_filters( 'epofw_html_main_tag_class_display', 'epofw_fields_table ' . $epofw_tbl_class, $fields_data_arr );
    /**
     * Filter for child tag class.
     *
     * @since 1.0.0
     */
    $child_tag_class = apply_filters( 'epofw_html_child_tag_class_display', 'epofw_middle_tg', $fields_data_arr );
    ?>
	<<?php 
    echo esc_html( $main_tag );
    ?> class="<?php 
    echo esc_attr( $main_tag_class );
    ?>"
	data-prd-type="<?php 
    echo esc_attr( $condition_type );
    ?>"
	data-epofw_attr="<?php 
    echo esc_attr( wc_esc_json( $data_attr ) );
    ?>">
	<<?php 
    echo esc_html( $child_tag );
    ?> class="<?php 
    echo esc_attr( $child_tag_class );
    ?>">
	<?php 
}

add_action(
    'epofw_html_start_table_display',
    'epofw_html_start_table_display_callback',
    10,
    2
);
/**
 * Function will print end of table and tbody.
 *
 * @since 2.5
 * @deprecated 4.4.0 This action hook is deprecated. Use the template system directly instead.
 */
function epofw_html_end_table_display_callback() {
    _deprecated_function(
        'epofw_html_end_table_display_callback',
        '4.4.0',
        null,
        esc_html__( 'This callback function is deprecated. The action hook epofw_html_end_table_display is no longer used in the plugin.', 'extra-product-options-for-woocommerce' )
    );
    /**
     * Filter for end main tag.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $main_tag = apply_filters( 'epofw_html_end_main_tag_display', 'div' );
    /**
     * Filter for end child tag.
     *
     * @since 1.0.0
     * @since 4.4.0 Removed epofw_get_tag_based_on_structure() param, now uses 'div' directly.
     */
    $child_tag = apply_filters( 'epofw_html_end_child_tag_display', 'div' );
    ?>
	</<?php 
    echo esc_html( $child_tag );
    ?>>
	</<?php 
    echo esc_html( $main_tag );
    ?>>
	<?php 
}

add_action( 'epofw_html_end_table_display', 'epofw_html_end_table_display_callback' );
/**
 * Function will return allowed html tags for render fields type.
 *
 * @since 4.3.1
 *
 * @param array  $allowed_tags The allowed html tags.
 * @param string $context      The context of the allowed html tags.
 *
 * @return array
 */
function epofw_allow_tags_for_render_fields_type(  $allowed_tags, $context  ) {
    if ( 'epofw_custom' === $context ) {
        if ( !isset( $allowed_tags['input'] ) ) {
            $allowed_tags['input'] = array();
        }
        $allowed_tags['input'] = array_merge( $allowed_tags['input'], array(
            'type'                      => true,
            'value'                     => true,
            'placeholder'               => true,
            'name'                      => true,
            'id'                        => true,
            'class'                     => true,
            'maxlength'                 => true,
            'rd_text'                   => true,
            'rd_text_color'             => true,
            'rd_text_class'             => true,
            'readonly'                  => true,
            'data-label-name'           => true,
            'data-nextfe'               => true,
            'data-crntfe'               => true,
            'min'                       => true,
            'max'                       => true,
            'step'                      => true,
            'checked'                   => true,
            'epofw_fau'                 => true,
            'epofw_fmul'                => true,
            'min_size'                  => true,
            'max_size'                  => true,
            'extension'                 => true,
            'required'                  => true,
            'epofw_af_product_quantity' => true,
            'epofw_af_default_quantity' => true,
            'epofw_af_min_quantity'     => true,
            'epofw_af_max_quantity'     => true,
        ) );
        if ( !isset( $allowed_tags['textarea'] ) ) {
            $allowed_tags['textarea'] = array();
        }
        $allowed_tags['textarea'] = array_merge( $allowed_tags['textarea'], array(
            'required'        => true,
            'type'            => true,
            'value'           => true,
            'placeholder'     => true,
            'name'            => true,
            'id'              => true,
            'class'           => true,
            'cols'            => true,
            'rows'            => true,
            'data-label-name' => true,
            'data-nextfe'     => true,
            'data-crntfe'     => true,
        ) );
        if ( !isset( $allowed_tags['select'] ) ) {
            $allowed_tags['select'] = array();
        }
        $allowed_tags['select'] = array_merge( $allowed_tags['select'], array(
            'required'        => true,
            'name'            => true,
            'id'              => true,
            'class'           => true,
            'data-label-name' => true,
            'data-nextfe'     => true,
            'data-crntfe'     => true,
            'multiple'        => true,
            'data-select2-id' => true,
            'tabindex'        => true,
            'aria-hidden'     => true,
        ) );
        if ( !isset( $allowed_tags['option'] ) ) {
            $allowed_tags['option'] = array();
        }
        $allowed_tags['option'] = array_merge( $allowed_tags['option'], array(
            'value'    => true,
            'selected' => true,
        ) );
        if ( !isset( $allowed_tags['button'] ) ) {
            $allowed_tags['button'] = array();
        }
        $allowed_tags['button'] = array_merge( $allowed_tags['button'], array(
            'type'           => true,
            'name'           => true,
            'id'             => true,
            'class'          => true,
            'data-inc'       => true,
            'data-lgc-type'  => true,
            'data-lgc-class' => true,
            'aria-expanded'  => true,
            'style'          => true,
        ) );
    }
    return $allowed_tags;
}

add_filter(
    'wp_kses_allowed_html',
    'epofw_allow_tags_for_render_fields_type',
    10,
    2
);
/**
 * Render Section Layout Global Settings preview for free users.
 *
 * Shows the Section Layout global settings section as disabled fields with
 * PRO badges so free users can see what is available in the premium version.
 * This callback is removed by the premium Section Layout Settings module when active.
 *
 * @since 4.4.6
 */
function epofw_render_section_layout_global_free_preview() {
    $epofw_pro_badge = '<span class="epofw-pro-badge-inline">' . esc_html__( 'PRO', 'extra-product-options-for-woocommerce' ) . '</span>';
    $epofw_badge_html = epofw_get_badge_allowed_html();
    ?>
	<div class="epofw_main_left_section epofw-configuration-box epofw-global-section-layout-settings epofw-premium-field-disabled">
		<div class="epofw-box-header epofw-accordion-header">
			<div class="epofw-box-header-title">
				<h3><?php 
    esc_html_e( 'Section Layout Global Settings', 'extra-product-options-for-woocommerce' );
    echo wp_kses( $epofw_pro_badge, $epofw_badge_html );
    ?></h3>
				<p class="epofw-box-description"><?php 
    esc_html_e( 'Set default section layout behavior for all addons. Individual addons can override these settings.', 'extra-product-options-for-woocommerce' );
    ?></p>
			</div>
			<button type="button" class="button-link epofw-accordion-toggle" aria-expanded="false" aria-controls="epofw-global-section-layout-settings-content" data-epofw-default-open="false" data-epofw-expand-text="<?php 
    echo esc_attr__( 'Expand', 'extra-product-options-for-woocommerce' );
    ?>" data-epofw-collapse-text="<?php 
    echo esc_attr__( 'Collapse', 'extra-product-options-for-woocommerce' );
    ?>">
				<span class="dashicons dashicons-arrow-up-alt" aria-hidden="true"></span>
			</button>
		</div>
		<div class="epofw_section epofw_field_info epofw-box-content" id="epofw-global-section-layout-settings-content">

		<!-- Default Layout -->
		<div class="epofw-setting-field">
			<div class="epofw-setting-label">
				<label><?php 
    esc_html_e( 'Default Section Layout', 'extra-product-options-for-woocommerce' );
    ?></label>
				<p class="epofw-field-description"><?php 
    esc_html_e( 'Default layout style for addon sections when not specified per-addon.', 'extra-product-options-for-woocommerce' );
    ?></p>
			</div>
			<div class="epofw-setting-input">
				<select disabled>
					<option><?php 
    esc_html_e( 'Default (Stacked)', 'extra-product-options-for-woocommerce' );
    ?></option>
					<option><?php 
    esc_html_e( 'Accordion', 'extra-product-options-for-woocommerce' );
    ?></option>
					<option><?php 
    esc_html_e( 'Tabs', 'extra-product-options-for-woocommerce' );
    ?></option>
					<option><?php 
    esc_html_e( 'Step Wizard', 'extra-product-options-for-woocommerce' );
    ?></option>
				</select>
			</div>
		</div>
	</div>
	<?php 
}

add_action( 'epofw_global_settings_sections', 'epofw_render_section_layout_global_free_preview' );
/**
 * Render Section Layout preview for free users in the addon builder.
 *
 * Shows the Section Layout dropdown and sub-options as disabled fields with
 * PRO badges so free users can see what is available in the premium version.
 * This callback is removed by the premium Section Layout module when active.
 *
 * @since 4.4.6
 *
 * @param array  $epofw_addon_data Addon data array.
 * @param string $epofw_post_id   Post ID for the current addon.
 */
function epofw_render_section_layout_free_preview(  $epofw_addon_data, $epofw_post_id  ) {
    $epofw_pro_badge = '<span class="epofw-pro-badge-inline">' . esc_html__( 'PRO', 'extra-product-options-for-woocommerce' ) . '</span>';
    $epofw_badge_html = epofw_get_badge_allowed_html();
    ?>
	<div class="epofw-setting-field epofw-section-layout-field epofw-premium-field-disabled">
		<div class="epofw-setting-label">
			<label for="epofw_section_layout"><?php 
    esc_html_e( 'Section Layout', 'extra-product-options-for-woocommerce' );
    echo wp_kses( $epofw_pro_badge, $epofw_badge_html );
    ?></label>
			<p class="epofw-field-description"><?php 
    esc_html_e( 'Choose how multiple sections are displayed on the product page.', 'extra-product-options-for-woocommerce' );
    ?></p>
		</div>
		<div class="epofw-setting-input">
			<select id="epofw_section_layout" disabled>
				<option><?php 
    esc_html_e( '-- Use Global --', 'extra-product-options-for-woocommerce' );
    ?></option>
				<option><?php 
    esc_html_e( 'Default (Stacked)', 'extra-product-options-for-woocommerce' );
    ?></option>
				<option><?php 
    esc_html_e( 'Accordion', 'extra-product-options-for-woocommerce' );
    ?></option>
				<option><?php 
    esc_html_e( 'Tabs', 'extra-product-options-for-woocommerce' );
    ?></option>
				<option><?php 
    esc_html_e( 'Step Wizard', 'extra-product-options-for-woocommerce' );
    ?></option>
			</select>
		</div>
	</div>
	<?php 
}

add_action(
    'epofw_addon_configuration_fields',
    'epofw_render_section_layout_free_preview',
    10,
    2
);
add_filter( 'epofw_parsed_addon_data_before_save', 'epofw_normalize_slider_mode_for_free_before_save', 5 );
add_filter( 'epofw_before_save_addon_data', 'epofw_normalize_slider_mode_for_free_before_save', 5 );