<?php
/**
 * RAQ table row.
 *
 * @var WC_Product $prod        The product
 * @var int        $id          Bundle item ID..
 * @var string     $link        The link.
 * @var string     $title       The title.
 * @var string     $image       The image.
 * @var string     $quantity    The quantity.
 * @var array      $raq_content RAQ data.
 * @var string     $key         The key.
 *
 * @author  YITH
 * @package YITH\ProductBundles\Templates
 */

$raq         = array();
$bundle_info = $raq_info['yith-bundle-add-to-cart-params'] ?? array();

$the_title = $title;
?>
<tr class="<?php echo esc_attr( apply_filters( 'yith_ywraq_item_class', 'cart_item yith-wcpb-child-of-bundle-table-item', $raq_content, $key ) ); ?>"
	<?php echo esc_attr( apply_filters( 'yith_ywraq_item_attributes', '', $raq_content, $key ) ); ?>>

	<td class="product-remove">
	</td>

	<td class="product-thumbnail" style="text-align:center;border: 1px solid #eee;">
		<?php echo $image; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
	</td>

	<td class="product-name">
		<?php
		if ( ! ! $prod->get_sku() && get_option( 'ywraq_show_sku' ) === 'yes' ) {
			$the_title .= apply_filters( 'ywraq_sku_label', __( ' SKU:', 'yith-woocommerce-request-a-quote' ) ) . $prod->get_sku();
		}
		?>
		<a href="<?php echo esc_url( $link ); ?>"><?php echo esc_html( $the_title ); ?></a>
		<?php
		$item_data = array();

		if ( ! empty( $variation_id ) && ! empty( $variations ) ) {
			foreach ( $variations as $name => $value ) {
				$label = $name;
				$name  = strtolower( $name );
				$value = $bundle_info[ 'yith_bundle_attribute_' . $name . '_' . $id ] ?? '';

				if ( '' === $value ) {
					continue;
				}
				$name         = 'attribute_' . $name;
				$the_taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $name ) ) );

				// If this is a term slug, get the term's nice name.
				if ( taxonomy_exists( $the_taxonomy ) ) {
					$the_term = get_term_by( 'slug', $value, $the_taxonomy );
					if ( ! is_wp_error( $the_term ) && $the_term && $the_term->name ) {
						$value = $the_term->name;
					}
					$label = wc_attribute_label( $the_taxonomy );

				} else {

					if ( strpos( $name, 'attribute_' ) !== false ) {
						$custom_att = str_replace( 'attribute_', '', $name );

						if ( ! ! $custom_att ) {
							$label = wc_attribute_label( $custom_att );
						}
					}
				}

				$item_data[] = array(
					'key'   => $label,
					'value' => $value,
				);
			}
		}
		$item_data = apply_filters( 'ywraq_request_quote_view_item_data', $item_data, $raq, $prod, false );

		if ( ! ! $item_data ) {
			foreach ( $item_data as $data ) {
				echo esc_html( $data['key'] ) . ': ' . wp_kses_post( $data['value'] ) . "\n";
			}
		}
		?>
	</td>


	<td class="product-quantity">
		<?php echo esc_html( $quantity ); ?>
	</td>
	<?php if ( get_option( 'ywraq_hide_total_column', 'yes' ) === 'no' ) : ?>
		<td class="product-subtotal">
		</td>
	<?php endif ?>
</tr>
