<?php

/**
 * This template displaying select field addon item.
 * This template can be overridden by copying it to yourtheme/eopfw-templates/epofw-select.php
 * NOTE, on occasion Extra Product Options for WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @package Extra_Product_Options_For_WooCommerce/Templates
 * @version 2.5
 */
defined( 'ABSPATH' ) || exit;
$epofw_args = array();
$epofw_field_type = ( isset( $args['epofwtwp_args']['attr_data']['type'] ) ? $args['epofwtwp_args']['attr_data']['type'] : 'select' );
$epofw_sanitize_attr_data = array(
    $epofw_field_type => array(
        'data-default' => true,
    ),
);
if ( !empty( $args['epofwtwp_args']['attr_data'] ) ) {
    foreach ( $args['epofwtwp_args']['attr_data'] as $epofw_attr_name => $epofw_attr_value ) {
        $epofw_sanitize_attr_data[$epofw_field_type][$epofw_attr_name] = true;
        if ( 'name' === $epofw_attr_name ) {
            if ( strpos( $epofw_attr_value, 'epofw_field_' ) === false ) {
                $epofw_attr_value = 'epofw_field_' . $epofw_attr_value;
            }
            /**
             * Apply filters for select name field property.
             *
             * @since 2.5
             */
            $epofw_args['name'] = apply_filters( 'epofw_field_property_' . $epofw_field_type . '_' . $epofw_attr_name, $epofw_attr_value . '[value]', $args );
        } elseif ( 'type' === $epofw_attr_name ) {
            unset($args['epofwtwp_args']['attr_data'][$epofw_attr_name]);
        } elseif ( !empty( $epofw_attr_value ) ) {
            /**
             * Apply filters for select field property.
             *
             * @since 2.5
             */
            $epofw_args[$epofw_attr_name] = apply_filters( 'epofw_field_property_' . $epofw_field_type . '_' . $epofw_attr_name, $epofw_attr_value, $args );
        }
    }
}
$epofw_addon_options = ( isset( $args['epofwtwp_args']['fields_data']['epofw_field_settings']['options'] ) ? $args['epofwtwp_args']['fields_data']['epofw_field_settings']['options'] : '' );
$epofw_check_hop = ( isset( $args['epofwtwp_args']['fields_data']['common']['hop'] ) ? $args['epofwtwp_args']['fields_data']['common']['hop'] : '' );
$epofw_unique_field_slug = 'epofw_' . $epofw_field_type . '_field';
/**
 * Before addon field.
 *
 * @since 2.5
 */
do_action( 'epofw_before_addon_field_' . $epofw_field_type );
if ( !empty( $epofw_args ) && !empty( $epofw_addon_options ) ) {
    ?>
	<select
		<?php 
    foreach ( $epofw_args as $epofw_attr_name => $epofw_attr_value ) {
        if ( !isset( $epofw_sanitize_attr_data[$epofw_field_type][$epofw_attr_name] ) ) {
            continue;
        }
        echo sanitize_key( $epofw_attr_name ) . esc_attr( EPOFW_EQUAL ) . '"' . esc_attr( sanitize_text_field( $epofw_attr_value ) ) . '"';
    }
    ?>
	>
		<option value=""><?php 
    esc_html_e( 'None', 'extra-product-options-for-woocommerce' );
    ?></option>
		<?php 
    foreach ( $epofw_addon_options as $epofw_opt_value ) {
        if ( !empty( $epofw_opt_value ) ) {
            $epofw_opt_grp_data = epofw_explore_label_from_opt_group( $epofw_opt_value );
            $epofw_opt_id = ( isset( $epofw_opt_grp_data['opt_id'] ) ? sanitize_text_field( $epofw_opt_grp_data['opt_id'] ) : '' );
            $epofw_opt_label = sanitize_text_field( $epofw_opt_grp_data['opt_label'] );
            $epofw_opt_price_type = sanitize_key( $epofw_opt_grp_data['opt_price_type'] );
            $epofw_opt_price = $epofw_opt_grp_data['opt_price'];
        }
        $epofwtwp_args['opt_label'] = $epofw_opt_label;
        $epofwtwp_args['opt_price_type'] = $epofw_opt_price_type;
        $epofwtwp_args['opt_price'] = $epofw_opt_price;
        $epofwtwp_args['check_hop'] = $epofw_check_hop;
        $epofwtwp_args['product_data'] = ( isset( $args['epofwtwp_args']['product_data'] ) ? $args['epofwtwp_args']['product_data'] : '' );
        $epofwtwp_args['qty'] = ( isset( $args['epofwtwp_args']['qty'] ) ? absint( $args['epofwtwp_args']['qty'] ) : '' );
        $epofw_front_label = epofw_title_with_price( $epofwtwp_args, $args['epofwtwp_args']['fields_data'] );
        $epofw_stock_status = array();
        $epofw_stock_label = '';
        $epofw_opt_disabled = '';
        ?>
			<option value="<?php 
        echo esc_attr( $epofw_opt_label );
        ?>" data-opt-id="<?php 
        echo esc_attr( $epofw_opt_id );
        ?>"<?php 
        echo wp_kses_post( $epofw_opt_disabled );
        ?>>
				<?php 
        echo wp_kses_post( $epofw_front_label . $epofw_stock_label );
        ?>
			</option>
			<?php 
    }
    ?>
	</select>

	<?php 
}
/**
 * After addon field.
 *
 * @since 2.5
 */
do_action( 'epofw_after_addon_field_' . $epofw_field_type );