<?php
/**
 * Cálculo de bolsas (segun hoja Excel).
 *
 * @package Logistica
 */

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

if ( ! function_exists( 'logistica_tapas_status_options' ) ) {
	/**
	 * @return array<string, string>
	 */
	function logistica_tapas_status_options() {
		if ( class_exists( 'Logistica_Select_Catalog', false ) ) {
			$options = Logistica_Select_Catalog::get_options( 'tapas_status' );
			if ( is_array( $options ) && ! empty( $options ) ) {
				return $options;
			}
		}

		return array(
			'pendiente'   => __( 'Pendiente', 'logistica' ),
			'fabricacion' => __( 'Fabricación', 'logistica' ),
			'formado'     => __( 'Formado', 'logistica' ),
			'finalizado'  => __( 'Finalizado', 'logistica' ),
			'cancelado'   => __( 'Cancelado', 'logistica' ),
			'otro'        => __( 'Otro...', 'logistica' ),
		);
	}
}

/**
 * @param string|array<int, string> $lines Lineas del titulo.
 * @param string                    $class Clase de columna.
 */
function logistica_bolsas_excel_th( $lines, $class = '' ) {
	if ( is_string( $lines ) ) {
		$lines = array( $lines );
	}

	$class_attr = $class ? ' class="' . esc_attr( $class ) . '"' : '';
	?>
	<th scope="col"<?php echo $class_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
		<span class="logistica-tapas-excel-th__label">
			<?php
			foreach ( $lines as $index => $line ) {
				if ( $index > 0 ) {
					echo '<br />';
				}
				echo esc_html( $line );
			}
			?>
		</span>
	</th>
	<?php
}

/**
 * @param string $label   Titulo del grupo.
 * @param int    $colspan Columnas.
 * @param string $class   Clases.
 */
function logistica_bolsas_excel_th_group( $label, $colspan, $class = '' ) {
	$class_attr = $class ? ' class="' . esc_attr( $class ) . '"' : '';
	?>
	<th scope="colgroup" colspan="<?php echo (int) $colspan; ?>"<?php echo $class_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
		<?php echo esc_html( $label ); ?>
	</th>
	<?php
}

/**
 * @param string               $label Etiqueta.
 * @param string               $field Campo.
 * @param string|int|float     $value Valor.
 * @param array<string, mixed> $args  Atributos.
 */
function logistica_bolsas_field_input( $label, $field, $value, $args = array() ) {
	$type       = isset( $args['type'] ) ? (string) $args['type'] : 'text';
	$extra      = isset( $args['attrs'] ) ? (string) $args['attrs'] : '';
	$classes    = isset( $args['class'] ) ? (string) $args['class'] : '';
	$class_attr = $classes ? ' class="' . esc_attr( $classes ) . '"' : '';
	?>
	<label class="logistica-tapas-field is-editable">
		<span class="logistica-tapas-field__label"><?php echo esc_html( $label ); ?></span>
		<input
			type="<?php echo esc_attr( $type ); ?>"
			data-field="<?php echo esc_attr( $field ); ?>"
			value="<?php echo esc_attr( (string) $value ); ?>"
			<?php echo $extra; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
			<?php echo $class_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
		/>
	</label>
	<?php
}

/**
 * @param string               $label Etiqueta.
 * @param string               $field Campo calculado.
 * @param int|false            $decimals Decimales.
 * @param array<string, mixed> $args Clases.
 */
function logistica_bolsas_field_output( $label, $field, $decimals = 2, $args = array() ) {
	$classes    = isset( $args['class'] ) ? (string) $args['class'] : '';
	$class_attr = $classes ? ' ' . esc_attr( $classes ) : '';
	?>
	<div class="logistica-tapas-field is-auto<?php echo $class_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" data-output-wrap="<?php echo esc_attr( $field ); ?>">
		<span class="logistica-tapas-field__label"><?php echo esc_html( $label ); ?></span>
		<strong class="logistica-tapas-field__value" data-output="<?php echo esc_attr( $field ); ?>" data-decimals="<?php echo esc_attr( (string) $decimals ); ?>"></strong>
	</div>
	<?php
}

/**
 * @param array<string, mixed> $row Datos de fila.
 */
function logistica_render_bolsas_record( $row = array() ) {
	$defaults = array(
		'status'           => 'fabricacion',
		'status_other'     => '',
		'descripcion'      => '',
		'kilos'            => 0,
		'peso_paquete_10'  => 0,
		'precio_kg'        => 0,
		'precio_total'     => 0,
		'codigo_graficos'  => '',
		'ancho'            => 0,
		'largo'            => 0,
		'calibre'          => 0,
	);
	$row            = wp_parse_args( $row, $defaults );
	$status_options = logistica_tapas_status_options();
	$status         = (string) $row['status'];
	$status_other   = (string) $row['status_other'];
	$is_known       = array_key_exists( $status, $status_options );
	$select_status  = $is_known ? $status : 'otro';

	if ( ! $is_known && '' !== $status ) {
		$status_other = $status;
	}

	$close_label  = esc_attr__( 'Cerrar', 'logistica' );
	$remove_label = esc_attr__( 'Eliminar', 'logistica' );
	$dup_label    = esc_attr__( 'Duplicar referencia', 'logistica' );
	?>
	<article class="logistica-tapas-card logistica-bolsas-card is-status-<?php echo esc_attr( $select_status ); ?>" data-bolsas-record>
		<header class="logistica-tapas-card__head">
			<div class="logistica-tapas-card__status-wrap">
				<label class="logistica-tapas-field is-editable logistica-tapas-field--status">
					<span class="logistica-tapas-field__label"><?php esc_html_e( 'Estado', 'logistica' ); ?></span>
					<select data-field="status" class="logistica-tapas-status-select">
						<?php foreach ( $status_options as $value => $label ) : ?>
							<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $select_status, $value ); ?>><?php echo esc_html( $label ); ?></option>
						<?php endforeach; ?>
					</select>
				</label>
				<label class="logistica-tapas-field is-editable logistica-tapas-field--status-other<?php echo 'otro' === $select_status ? '' : ' is-hidden'; ?>">
					<span class="logistica-tapas-field__label"><?php esc_html_e( 'Estado personalizado', 'logistica' ); ?></span>
					<input
						type="text"
						data-field="status_other"
						value="<?php echo esc_attr( $status_other ); ?>"
						placeholder="<?php esc_attr_e( 'Escribe el estado', 'logistica' ); ?>"
					/>
				</label>
			</div>
			<div class="logistica-tapas-card__identity">
				<?php
				logistica_bolsas_field_input( __( 'Descripción', 'logistica' ), 'descripcion', $row['descripcion'] );
				logistica_bolsas_field_input(
					__( 'Código GRAFICOSTOS', 'logistica' ),
					'codigo_graficos',
					$row['codigo_graficos'],
					array(
						'type'  => 'text',
						'class' => 'logistica-copy-field',
						'attrs' => 'inputmode="text" autocapitalize="off" autocomplete="off"',
					)
				);
				?>
			</div>
			<div class="logistica-tapas-card__actions">
				<button type="button" class="logistica-table-icon-btn logistica-tapas-icon-btn" data-action="duplicate-bolsas-row" aria-label="<?php echo esc_attr( $dup_label ); ?>" title="<?php echo esc_attr( $dup_label ); ?>">
					<span class="logistica-tapas-icon logistica-tapas-icon--duplicate" aria-hidden="true"></span>
				</button>
				<button type="button" class="logistica-table-icon-btn logistica-tapas-icon-btn" data-action="close-bolsas-row" aria-label="<?php echo esc_attr( $close_label ); ?>" title="<?php echo esc_attr( $close_label ); ?>">
					<span class="logistica-tapas-icon logistica-tapas-icon--close" aria-hidden="true"></span>
				</button>
				<button type="button" class="logistica-table-icon-btn logistica-tapas-icon-btn logistica-tapas-icon-btn--danger" data-action="remove-bolsas-row" aria-label="<?php echo esc_attr( $remove_label ); ?>" title="<?php echo esc_attr( $remove_label ); ?>">
					<span class="logistica-tapas-icon logistica-tapas-icon--delete" aria-hidden="true"></span>
				</button>
			</div>
		</header>
		<div class="logistica-tapas-card__body">
			<section class="logistica-tapas-section">
				<h4 class="logistica-tapas-section__title"><?php esc_html_e( 'Peso y cantidad', 'logistica' ); ?></h4>
				<div class="logistica-tapas-grid logistica-tapas-grid--4">
					<?php
					logistica_bolsas_field_input( __( 'Kilos (kg)', 'logistica' ), 'kilos', $row['kilos'], array( 'type' => 'number', 'attrs' => 'step="0.01" min="0"' ) );
					logistica_bolsas_field_output( __( 'Gramos (gr)', 'logistica' ), 'gramos', 0, array( 'class' => 'is-bolsas-gramos' ) );
					logistica_bolsas_field_input( __( 'Peso paquete x10 (gr)', 'logistica' ), 'peso_paquete_10', $row['peso_paquete_10'], array( 'type' => 'number', 'attrs' => 'step="0.01" min="0"' ) );
					logistica_bolsas_field_output( __( 'Peso bolsa (und)', 'logistica' ), 'peso_bolsa', 2 );
					logistica_bolsas_field_output( __( 'Cantidad bolsas (und)', 'logistica' ), 'cantidad_bolsas', 0, array( 'class' => 'is-total is-bolsas-cantidad' ) );
					?>
				</div>
			</section>
			<section class="logistica-tapas-section logistica-tapas-section--results">
				<h4 class="logistica-tapas-section__title"><?php esc_html_e( 'Precios', 'logistica' ); ?></h4>
				<div class="logistica-tapas-grid logistica-tapas-grid--3">
					<?php
					logistica_bolsas_field_input( __( 'Precio (kg)', 'logistica' ), 'precio_kg', $row['precio_kg'], array( 'type' => 'text', 'class' => 'logistica-money-field', 'attrs' => 'inputmode="decimal" autocomplete="off"' ) );
					logistica_bolsas_field_input( __( 'Precio total (COP)', 'logistica' ), 'precio_total', $row['precio_total'], array( 'type' => 'text', 'class' => 'logistica-money-field', 'attrs' => 'inputmode="decimal" autocomplete="off"' ) );
					logistica_bolsas_field_output( __( 'Precio (und)', 'logistica' ), 'precio_und', 2, array( 'class' => 'is-total' ) );
					?>
				</div>
			</section>
			<section class="logistica-tapas-section">
				<h4 class="logistica-tapas-section__title"><?php esc_html_e( 'Medida', 'logistica' ); ?></h4>
				<div class="logistica-tapas-grid logistica-tapas-grid--3">
					<?php
					logistica_bolsas_field_input( __( 'Ancho', 'logistica' ), 'ancho', $row['ancho'], array( 'type' => 'number', 'attrs' => 'step="0.01" min="0"' ) );
					logistica_bolsas_field_input( __( 'Largo', 'logistica' ), 'largo', $row['largo'], array( 'type' => 'number', 'attrs' => 'step="0.01" min="0"' ) );
					logistica_bolsas_field_input( __( 'Calibre', 'logistica' ), 'calibre', $row['calibre'], array( 'type' => 'number', 'attrs' => 'step="0.01" min="0"' ) );
					?>
				</div>
			</section>
		</div>
	</article>
	<?php
}

$default_rows = array(
	array(
		'status'          => 'fabricacion',
		'descripcion'     => '7oz',
		'kilos'           => 93.1,
		'peso_paquete_10' => 39,
		'precio_kg'       => 15000,
		'precio_total'    => 1396500,
		'codigo_graficos' => '3642',
		'ancho'           => 5.5,
		'largo'           => 25,
		'calibre'         => 0.65,
	),
	array(
		'status'          => 'fabricacion',
		'descripcion'     => '9oz-12oz',
		'kilos'           => 101.5,
		'peso_paquete_10' => 31,
		'precio_kg'       => 13500,
		'precio_total'    => 529580,
		'codigo_graficos' => '16',
		'ancho'           => 6.5,
		'largo'           => 21,
		'calibre'         => 0.65,
	),
	array(
		'status'          => 'fabricacion',
		'descripcion'     => 'Tazon 5-6 oz',
		'kilos'           => 50.3,
		'peso_paquete_10' => 43,
		'precio_kg'       => 13500,
		'precio_total'    => 679050,
		'codigo_graficos' => '',
		'ancho'           => 6.5,
		'largo'           => 23,
		'calibre'         => 0.65,
	),
);
?>
<section class="logistica-conversion-board logistica-tapas-board logistica-bolsas-board">
	<?php if ( ! logistica_is_tabbed_shell() ) : ?>
		<?php logistica_tab_loading_overlay( logistica_tab_loading_message( 'logistica-calculos' ) ); ?>
	<?php endif; ?>
	<div class="logistica-close-toolbar logistica-conversion-intro">
		<?php
		logistica_page_toolbar_intro(
			__( 'Cálculo de bolsas', 'logistica' ),
			__( 'Calcula peso por bolsa, cantidad fabricada y precio unitario desde kilos, gramos, medidas y parámetros de producción.', 'logistica' ),
			'dashicons-portfolio'
		);
		?>
	</div>

	<div class="logistica-close-legend logistica-conversion-legend">
		<span class="is-editable"><?php esc_html_e( 'Editable', 'logistica' ); ?></span>
		<span class="is-auto"><?php esc_html_e( 'Calculado', 'logistica' ); ?></span>
	</div>

	<div class="logistica-sheet logistica-sheet--bolsas" data-sheet="bolsas-calculo">
		<div class="logistica-tapas-excel-wrap">
			<h5 class="logistica-tapas-section__title"><?php esc_html_e( 'Vista hoja de cálculo (Excel)', 'logistica' ); ?></h5>
			<?php logistica_excel_table_zoom_toolbar(); ?>
			<p class="logistica-tapas-excel__intro"><?php esc_html_e( 'Vista tipo Excel. Pulsa el icono de editar en cada fila para modificar solo esa referencia.', 'logistica' ); ?></p>
			<div class="logistica-tapas-filters" data-bolsas-filters>
				<div class="logistica-tapas-filters__head">
					<span class="logistica-tapas-filters__icon" aria-hidden="true">
						<svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
							<path d="M4 5h16l-6.2 7.35v5.9L10 20v-7.65L4 5z" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
						</svg>
					</span>
					<p class="logistica-tapas-filters__title"><?php esc_html_e( 'Filtrar tabla', 'logistica' ); ?></p>
					<span class="logistica-tapas-filters__badge" data-bolsas-filter-badge hidden><?php esc_html_e( 'Activo', 'logistica' ); ?></span>
				</div>
				<div class="logistica-tapas-filters__fields">
					<label class="logistica-tapas-filters__field">
						<span class="logistica-tapas-filters__label"><?php esc_html_e( 'Descripción', 'logistica' ); ?></span>
						<select data-bolsas-filter="descripcion">
							<option value=""><?php esc_html_e( 'Todos', 'logistica' ); ?></option>
						</select>
					</label>
					<label class="logistica-tapas-filters__field">
						<span class="logistica-tapas-filters__label"><?php esc_html_e( 'Estado', 'logistica' ); ?></span>
						<select data-bolsas-filter="status">
							<option value=""><?php esc_html_e( 'Todos', 'logistica' ); ?></option>
							<?php foreach ( logistica_tapas_status_options() as $status_key => $status_label ) : ?>
								<option value="<?php echo esc_attr( $status_key ); ?>"><?php echo esc_html( $status_label ); ?></option>
							<?php endforeach; ?>
						</select>
					</label>
					<div class="logistica-tapas-filters__actions">
						<button type="button" class="button logistica-tapas-filters__btn" data-action="clear-bolsas-filters">
							<span class="logistica-tapas-filters__btn-icon" aria-hidden="true">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M6 6l12 12M18 6L6 18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
								</svg>
							</span>
							<?php esc_html_e( 'Limpiar filtros', 'logistica' ); ?>
						</button>
					</div>
				</div>
				<p class="logistica-tapas-filters__meta" data-bolsas-filter-meta hidden></p>
			</div>
			<div class="logistica-tapas-excel-toolbar">
				<button type="button" class="button logistica-excel-btn logistica-excel-btn--export" data-action="export-bolsas-excel">
					<span class="dashicons dashicons-media-spreadsheet" aria-hidden="true"></span>
					<span class="logistica-excel-btn__label"><?php esc_html_e( 'Exportar Excel (.xlsx)', 'logistica' ); ?></span>
				</button>
				<button type="button" class="button logistica-excel-btn logistica-excel-btn--import" data-action="import-bolsas-excel">
					<span class="dashicons dashicons-upload" aria-hidden="true"></span>
					<span class="logistica-excel-btn__label"><?php esc_html_e( 'Importar Excel', 'logistica' ); ?></span>
				</button>
				<input
					type="file"
					data-bolsas-import-file
					accept=".xls,.xlsx,.csv,text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
					hidden
				/>
			</div>
			<ul class="logistica-tapas-status-legend" aria-hidden="true">
				<li><span class="logistica-tapas-status-legend__swatch is-row-status-pendiente"></span><?php esc_html_e( 'Pendiente', 'logistica' ); ?></li>
				<li><span class="logistica-tapas-status-legend__swatch is-row-status-fabricacion"></span><?php esc_html_e( 'Fabricación', 'logistica' ); ?></li>
				<li><span class="logistica-tapas-status-legend__swatch is-row-status-formado"></span><?php esc_html_e( 'Formado', 'logistica' ); ?></li>
				<li><span class="logistica-tapas-status-legend__swatch is-row-status-finalizado"></span><?php esc_html_e( 'Finalizado', 'logistica' ); ?></li>
				<li><span class="logistica-tapas-status-legend__swatch is-row-status-cancelado"></span><?php esc_html_e( 'Cancelado', 'logistica' ); ?></li>
				<li><span class="logistica-tapas-status-legend__swatch is-row-status-otro"></span><?php esc_html_e( 'Otro', 'logistica' ); ?></li>
				<li><span class="logistica-tapas-status-legend__swatch is-calc-missing"></span><?php esc_html_e( 'Faltan datos', 'logistica' ); ?></li>
			</ul>
			<?php logistica_table_sheet_actions( __( 'Añadir referencia', 'logistica' ), 'add-bolsas-row' ); ?>

			<div id="logistica-bolsas-cards-panel" class="logistica-tapas-cards-panel logistica-tapas-inline-form-slot" data-bolsas-cards-panel hidden>
				<div class="logistica-tapas-list" data-bolsas-rows>
					<?php foreach ( $default_rows as $row ) : ?>
						<?php logistica_render_bolsas_record( $row ); ?>
					<?php endforeach; ?>
				</div>
				<div class="logistica-tapas-form-actions" data-bolsas-form-actions hidden>
					<button type="button" class="button button-primary logistica-calc-form-btn logistica-calc-form-btn--confirm" data-action="confirm-bolsas-form">
						<span class="dashicons dashicons-saved" aria-hidden="true"></span>
						<?php esc_html_e( 'Agregar referencia', 'logistica' ); ?>
					</button>
					<button type="button" class="button logistica-calc-form-btn logistica-calc-form-btn--cancel" data-action="cancel-bolsas-form">
						<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>
						<?php esc_html_e( 'Cancelar', 'logistica' ); ?>
					</button>
				</div>
			</div>

			<div class="logistica-tapas-scroll-host">
				<div class="logistica-sheet-scroll logistica-tapas-excel-scroll" data-bolsas-excel-scroll tabindex="0">
					<table class="logistica-tapas-excel-table logistica-bolsas-excel-table">
						<colgroup>
							<col class="logistica-tapas-col logistica-tapas-col--validacion" />
							<col class="logistica-tapas-col logistica-tapas-col--estado" />
							<col class="logistica-tapas-col logistica-tapas-col--num-sm" />
							<col class="logistica-tapas-col logistica-tapas-col--producto" />
							<col class="logistica-tapas-col logistica-tapas-col--num" />
							<col class="logistica-tapas-col logistica-tapas-col--num" />
							<col class="logistica-tapas-col logistica-tapas-col--num" />
							<col class="logistica-tapas-col logistica-tapas-col--num" />
							<col class="logistica-tapas-col logistica-tapas-col--num" />
							<col class="logistica-tapas-col logistica-tapas-col--num" />
							<col class="logistica-tapas-col logistica-tapas-col--num" />
							<col class="logistica-tapas-col logistica-tapas-col--num" />
							<col class="logistica-tapas-col logistica-tapas-col--codigo" />
							<col class="logistica-tapas-col logistica-tapas-col--num-sm" />
							<col class="logistica-tapas-col logistica-tapas-col--num-sm" />
							<col class="logistica-tapas-col logistica-tapas-col--num-sm" />
							<col class="logistica-tapas-col logistica-tapas-col--actions" />
						</colgroup>
						<thead>
							<tr class="logistica-tapas-excel-groups">
								<?php logistica_bolsas_excel_th_group( __( 'Validación', 'logistica' ), 1 ); ?>
								<?php logistica_bolsas_excel_th_group( __( 'Referencia', 'logistica' ), 3 ); ?>
								<?php logistica_bolsas_excel_th_group( __( 'Peso', 'logistica' ), 4, 'is-col-bolsas-peso' ); ?>
								<?php logistica_bolsas_excel_th_group( __( 'Cantidad', 'logistica' ), 1, 'is-col-bolsas-cantidad' ); ?>
								<?php logistica_bolsas_excel_th_group( __( 'Precio', 'logistica' ), 3, 'is-col-bolsas-precio' ); ?>
								<?php logistica_bolsas_excel_th_group( __( 'Código', 'logistica' ), 1 ); ?>
								<?php logistica_bolsas_excel_th_group( __( 'Medida', 'logistica' ), 3 ); ?>
								<?php logistica_bolsas_excel_th_group( '', 1, 'is-actions-head' ); ?>
							</tr>
							<tr>
								<?php logistica_bolsas_excel_th( __( 'Validación', 'logistica' ), 'logistica-tapas-col--validacion' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Estado', 'logistica' ), 'logistica-tapas-col--estado' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Id', 'logistica' ) ); ?>
								<?php logistica_bolsas_excel_th( __( 'Descripción', 'logistica' ) ); ?>
								<?php logistica_bolsas_excel_th( __( 'Kilos (kg)', 'logistica' ), 'is-col-bolsas-peso' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Gramos (gr)', 'logistica' ), 'is-col-bolsas-peso' ); ?>
								<?php logistica_bolsas_excel_th( array( __( 'Peso paquete', 'logistica' ), __( 'x10 (gr)', 'logistica' ) ), 'is-col-bolsas-peso' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Peso bolsa (und)', 'logistica' ), 'is-col-bolsas-peso' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Cantidad bolsas (und)', 'logistica' ), 'is-col-bolsas-cantidad' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Precio (kg)', 'logistica' ), 'is-col-bolsas-precio' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Precio total', 'logistica' ), 'is-col-bolsas-precio' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Precio (und)', 'logistica' ), 'is-col-bolsas-precio' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Código GRAFICOSTOS', 'logistica' ), 'is-col-bolsas-codigo' ); ?>
								<?php logistica_bolsas_excel_th( __( 'Ancho', 'logistica' ) ); ?>
								<?php logistica_bolsas_excel_th( __( 'Largo', 'logistica' ) ); ?>
								<?php logistica_bolsas_excel_th( __( 'Calibre', 'logistica' ) ); ?>
								<?php logistica_bolsas_excel_th( __( 'Acción', 'logistica' ), 'is-actions-head' ); ?>
							</tr>
						</thead>
						<tbody data-bolsas-table-body></tbody>
						<tfoot>
							<tr class="logistica-tapas-excel-summary logistica-bolsas-excel-summary" data-bolsas-table-summary>
								<td></td>
								<td></td>
								<th colspan="2"><?php esc_html_e( 'Totales', 'logistica' ); ?></th>
								<td data-output="sum_kilos"></td>
								<td data-output="sum_gramos"></td>
								<td colspan="2"></td>
								<td data-output="sum_cantidad_bolsas"></td>
								<td colspan="2"></td>
								<td data-output="sum_precio_total"></td>
								<td></td>
								<td colspan="3"></td>
								<td></td>
							</tr>
						</tfoot>
					</table>
				</div>
				<?php logistica_table_pagination( 'bolsas' ); ?>
			</div>
			<p class="logistica-tapas-scroll-hint" data-bolsas-scroll-hint hidden><?php esc_html_e( 'Desliza horizontalmente para ver todas las columnas.', 'logistica' ); ?></p>
		</div>

		<aside class="logistica-tapas-totals logistica-bolsas-totals">
			<h2 class="logistica-tapas-totals__title"><?php esc_html_e( 'Totales', 'logistica' ); ?></h2>
			<div class="logistica-tapas-totals__groups">
				<div class="logistica-tapas-totals__group" data-bolsas-summary>
					<h4 class="logistica-tapas-section__title"><?php esc_html_e( 'Resumen bolsas', 'logistica' ); ?></h4>
					<div class="logistica-tapas-grid logistica-tapas-grid--3">
						<?php
						logistica_bolsas_field_output( __( 'Kilos (kg)', 'logistica' ), 'sum_kilos', 2 );
						logistica_bolsas_field_output( __( 'Gramos (gr)', 'logistica' ), 'sum_gramos', 0, array( 'class' => 'is-bolsas-gramos' ) );
						logistica_bolsas_field_output( __( 'Cantidad bolsas (und)', 'logistica' ), 'sum_cantidad_bolsas', 0, array( 'class' => 'is-total is-bolsas-cantidad' ) );
						logistica_bolsas_field_output( __( 'Precio total (COP)', 'logistica' ), 'sum_precio_total', 0, array( 'class' => 'is-total' ) );
						?>
					</div>
				</div>
			</div>
		</aside>

	</div>
</section>
