<?php
/**
 * Renders stock fields for each Hub Account in product edit page.
 *
 * @package flo-sync
 */

use NMFS\Sync\Items\Articles\Stock\Models\Stock_Data_Collection_Model;

defined( 'ABSPATH' ) || exit;

/**
 * View file parameters.
 *
 * @var array $params
 */

/**
 * Stock data for each Hub Account.
 *
 * @var Stock_Data_Collection_Model $product_stock_collection
 */
$product_stock_collection = $params['product_stock_collection'];
?>
<div class="options-group">
	<h3 style="padding-left: 10px;">
		<?php
		if ( $params['manages_stock'] ) {
			esc_html_e( 'Stock in Hub Accounts', 'flo-sync' );
		} else {
			esc_html_e( 'Article exists in Hub Account', 'flo-sync' );
		}
		?>
	</h3>
	<?php
	$count = 1;
	foreach ( $product_stock_collection->get_stock_data() as $stock_data ) {
		if ( ! isset( $stock_data->hub_account ) ) {
			continue;
		}
		$value = $params['manages_stock']
			? wc_stock_amount( $stock_data->quantity ) :
			( $stock_data->article_exists_in_hub ? __( 'Yes', 'flo-sync' ) : __( 'No', 'flo-sync' ) );
		woocommerce_wp_text_input(
			array(
				'id'                => '_nmf_bo_stock_' . ( $count++ ),
				'value'             => $value,
				'label'             => $stock_data->hub_account->get_display_name(),
				'custom_attributes' => array( 'readonly' => 'readonly' ),
			)
		);
	}
	?>
</div>
