<?php
/**
 * Single Product tabs
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product/tabs/tabs.php.
 *
 * HOWEVER, on occasion 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.
 *
 * @see 	    http://docs.woothemes.com/document/template-structure/
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.4.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Filter tabs and allow third parties to add their own.
 *
 * Each tab is an array containing title, callback and priority.
 * @see woocommerce_default_product_tabs()
 */
$tabs = apply_filters( 'woocommerce_product_tabs', array() );
/**
 * TABELA OU OUTRAS INFORMAÇÕES
 */
$to_show = get_field("show_tabela_medidas");
if($to_show == "img" || $to_show == "page"){
	$label = get_field("tabela_img_label");
	$sublabel = get_field("tabela_img_sublabel");
	$other_info_label = get_field("other_info");
	$other_info_url = get_field("other_info_url");
	$button_label = get_field("button_label");
	if(get_field("page_tabela_text")){
		$page_nt = get_field("page_tabela_text")[0];
		$label = get_field("tabela_img_label",$page_nt);
		$sublabel = get_field("tabela_img_sublabel",$page_nt);
		$other_info_label = get_field("other_info",$page_nt);
		$other_info_url = get_field("other_info_url",$page_nt);
		$button_label = get_field("button_label",$page_nt);
	}
	if($to_show == "img"){
		$table_img_url = get_field("imagem_tabela");
		$button_url = '<a href="'. $table_img_url .'" data-rel="lightbox"><div class="button white-border anim-fast">' . $button_label . '</div></a>';
	}elseif($to_show == "page"){
		$table_page_url = get_field("page_tabela");
		$button_url = '<a href="'. $table_page_url .'" target="_blank"><div class="button white-border anim-fast">' . $button_label . '</div></a>';
	}
	$oi_output = '<div class="useful-info">';
	$oi_output .= '<div class="aligner"></div>';
	$oi_output .= '<div class="label-wrapper">';
	$oi_output .= '<div class="label">' . $label . '</div>';
	$oi_output .= '<div class="sublabel">' . $sublabel . '</div>';
	$oi_output .= '</div>';
	$oi_output .= $button_url; 
	if($other_info_url){
		$oi_output .='<div class="other-info text"><a href="' . $other_info_url . '"><span class="info-icon">i</span>' . $other_info_label . '</a></div>';
	} 
	$oi_output .= '</div>';
}
/**
 *FIM  TABELA OU OUTRAS INFORMAÇÕES
 */
if ( ! empty( $tabs ) ){
	?>

	<div class="woocommerce-tabs wc-tabs-wrapper">
		<ul class="tabs wc-tabs">
			<?php foreach ( $tabs as $key => $tab ) : ?>
				<li class="<?php echo esc_attr( $key ); ?>_tab">
					<a href="#tab-<?php echo esc_attr( $key ); ?>"><?php echo apply_filters( 'woocommerce_product_' . $key . '_tab_title', esc_html( $tab['title'] ), $key ); ?></a>
				</li>
				<?php if(esc_attr( $key ) == "additional_information"){
					$att = true;
				} ?>
			<?php endforeach; ?>
		</ul>
		<?php 
		foreach ( $tabs as $key => $tab ) : ?>
			<div class="panel entry-content wc-tab" id="tab-<?php echo esc_attr( $key ); ?>">
				<?php call_user_func( $tab['callback'], $key, $tab ); ?>
				<?php  
				if ($att) {
					if(esc_attr( $key ) == 'additional_information'){
						echo $oi_output;
					}
				}else{
					if(esc_attr( $key ) == 'description'){
						echo $oi_output;
					}
				}
				?>
			</div>
		<?php endforeach; ?>
		<?php do_action('woocommerce_aba_after_tabs'); ?>
	</div>

<?php 
}
	?>
