<?php
namespace WCQT\classes\admin;

class ProductsTablePage
{
	function __construct()
	{
		/* add_action( 'woocommerce_product_quick_edit_start', array($this, 'add_custom_field_quick_edit') );
		add_action( 'manage_product_posts_custom_column', 	array($this,'show_custom_field_quick_edit_data'), 9999, 2 );
		add_action( 'woocommerce_product_quick_edit_save', 	array($this,'save_custom_field_quick_edit') ); */
	}
	function add_custom_field_quick_edit() 
	{
	   echo '<div class="inline-edit-group">';
		woocommerce_wp_checkbox( array(
			'id' => '_is_quotable',
			'class' => '',
			'label' => esc_html__( ' Is the variation quotable?', 'woocommerce-quote' )
		) );
		echo '</div>';
	}
	function show_custom_field_quick_edit_data( $column, $product_id )
	{
		if ( 'name' !== $column ) return;
		
		global $wcqt_option_model, $wcqt_wpml_model;
		$options 			= $wcqt_option_model->get_options();
		$product_id 			= $wcqt_wpml_model->get_original_id($product_id);
		$selected_products	= wcqt_get_value_if_set($options, array('exclusion', 'products'), array());
		$is_quotable 		= in_array($product_id, $selected_products);
		echo '<div style="display:none;">'.esc_html__( ' Is the variation quotable?', 'woocommerce-quote' ).': <span id="wcqt_' . $product_id . '" data-quotable="'.($is_quotable ? "yes" : "no").'">' . ($is_quotable ? esc_html__( 'Yes', 'woocommerce-quote' ) : esc_html__( 'no', 'woocommerce-quote' ) ) . '</span></div>';
		
		wc_enqueue_js( "
		  $(document).on('click', '.editinline', function() 
		  {
			 var is_quotable = $('#wcqt_".$product_id."').data('quotable') === 'yes';
			 console.log(".$product_id.");
			 console.log(is_quotable);
			 console.log($('#wcqt_".$product_id."').data('quotable'));
			 $('#_is_quotable').prop('checked', is_quotable);
			});
		" );
	}
	function save_custom_field_quick_edit( $product ) 
	{
		
	}
 
}
?>