<?php
/**
 * Spreadsheet-style conversion tables.
 *
 * @package Logistica
 */

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

$logistica_calculators = array(
	'bobina-pliego'      => __( 'Conversión hojas y kilos', 'logistica' ),
	'gramaje-papel'      => __( 'Gramaje papel', 'logistica' ),
	'calibre-material'   => __( 'Conversión de calibre', 'logistica' ),
	'montaje-compartido' => __( 'Montaje compartido impresión', 'logistica' ),
	'pliego-conversion'  => __( 'Hojas a hojas', 'logistica' ),
);

/**
 * Celda de accion (duplicar + eliminar) para tablas de conversion.
 *
 * @param string $duplicate_action Acción data-action duplicar.
 * @param string $delete_action    Acción data-action eliminar.
 * @param string $delete_label     Etiqueta accesible eliminar.
 * @return void
 */
function logistica_conversion_action_cell( $duplicate_action, $delete_action, $delete_label = '' ) {
	if ( '' === $delete_label ) {
		$delete_label = __( 'Eliminar', 'logistica' );
	}
	?>
	<td class="logistica-calc-excel-actions-cell">
		<div class="logistica-calc-excel-actions">
			<button type="button" class="button button-small logistica-table-icon-btn logistica-calc-excel-btn-duplicate" data-action="<?php echo esc_attr( $duplicate_action ); ?>" aria-label="<?php esc_attr_e( 'Duplicar', 'logistica' ); ?>" title="<?php esc_attr_e( 'Duplicar', 'logistica' ); ?>">
				<span class="dashicons dashicons-admin-page" aria-hidden="true"></span>
			</button>
			<button type="button" class="button button-small logistica-table-icon-btn logistica-calc-excel-btn-delete" data-action="<?php echo esc_attr( $delete_action ); ?>" aria-label="<?php echo esc_attr( $delete_label ); ?>" title="<?php echo esc_attr( $delete_label ); ?>">
				<span class="dashicons dashicons-trash" aria-hidden="true"></span>
			</button>
		</div>
	</td>
	<?php
}
?>
<section class="logistica-conversion-board is-nav-collapsed" data-conversion-board>
	<?php if ( ! logistica_is_tabbed_shell() ) : ?>
		<?php logistica_tab_loading_overlay( logistica_tab_loading_message( 'logistica-conversiones' ) ); ?>
	<?php endif; ?>
	<div class="logistica-close-toolbar logistica-conversion-intro">
		<?php
		logistica_page_toolbar_intro(
			__( 'Calculadoras', 'logistica' ),
			__( 'Convierte bobinas, hojas, gramajes y calibres, y calcula montajes compartidos con resultados inmediatos para planeación.', 'logistica' ),
			'dashicons-calculator'
		);
		?>
	</div>

	<div class="logistica-conversion-layout">
		<aside class="logistica-conversion-nav" data-conversion-nav aria-label="<?php esc_attr_e( 'Navegación de calculadoras', 'logistica' ); ?>">
			<div class="logistica-conversion-nav__head">
				<span class="logistica-conversion-nav__title"><?php esc_html_e( 'Navegación', 'logistica' ); ?></span>
				<button
					type="button"
					class="logistica-conversion-nav__toggle"
					data-action="toggle-conversion-nav"
					aria-expanded="false"
					aria-controls="logistica-conversion-nav-list"
					title="<?php esc_attr_e( 'Ocultar menú', 'logistica' ); ?>"
				>
					<span aria-hidden="true">&lsaquo;</span>
					<span class="screen-reader-text"><?php esc_html_e( 'Ocultar menú de calculadoras', 'logistica' ); ?></span>
				</button>
			</div>
			<nav id="logistica-conversion-nav-list">
				<ul class="logistica-conversion-nav__list">
					<?php foreach ( $logistica_calculators as $calc_slug => $calc_label ) : ?>
						<li>
							<a
								href="#logistica-calc-<?php echo esc_attr( $calc_slug ); ?>"
								class="logistica-conversion-nav__link"
								data-calc-nav="<?php echo esc_attr( $calc_slug ); ?>"
							><?php echo esc_html( $calc_label ); ?></a>
						</li>
					<?php endforeach; ?>
				</ul>
			</nav>
		</aside>

		<div class="logistica-conversion-main">
			<button
				type="button"
				class="logistica-conversion-nav-reopen"
				data-action="toggle-conversion-nav"
				aria-expanded="false"
				hidden
			>
				<span aria-hidden="true">&#9776;</span>
				<?php esc_html_e( 'Mostrar menú', 'logistica' ); ?>
			</button>

	<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>
		<span class="is-formula"><?php esc_html_e( 'Validación OK', 'logistica' ); ?></span>
		<span class="is-missing"><?php esc_html_e( 'Advertencia', 'logistica' ); ?></span>
		<span class="is-error"><?php esc_html_e( 'Error / faltante', 'logistica' ); ?></span>
	</div>

	<div class="logistica-sheet" id="logistica-calc-bobina-pliego" data-sheet="bobina-pliego">
		<h2><?php esc_html_e( 'Conversión hojas y kilos', 'logistica' ); ?></h2>
		<?php logistica_excel_table_zoom_toolbar(); ?>
		<div class="logistica-sheet-presets" data-sheet-presets>
			<label>
				<?php esc_html_e( 'Conversión guardada', 'logistica' ); ?>
				<select data-template-select>
					<option value=""><?php esc_html_e( 'Selecciona una conversión', 'logistica' ); ?></option>
				</select>
			</label>
			<div class="logistica-sheet-presets__actions">
				<button type="button" class="button" data-action="save-sheet-template"><?php esc_html_e( 'Guardar', 'logistica' ); ?></button>
				<button type="button" class="button" data-action="load-sheet-template"><?php esc_html_e( 'Cargar', 'logistica' ); ?></button>
				<button type="button" class="button" data-action="edit-sheet-template"><?php esc_html_e( 'Editar', 'logistica' ); ?></button>
				<button type="button" class="button button-link-delete" data-action="delete-sheet-template"><?php esc_html_e( 'Eliminar', 'logistica' ); ?></button>
			</div>
		</div>
		<div class="logistica-conversion-scroll-host">
		<div class="logistica-sheet-scroll logistica-tapas-excel-scroll" data-conversion-excel-scroll tabindex="0">
			<table>
				<thead>
					<tr>
						<th></th>
						<th><?php esc_html_e( 'Tamaño hoja vertical (cm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño hoja horizontal (cm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Gramaje (gr/m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño vertical (m)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño horizontal (m)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Área hoja (m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Gramaje (kg/m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Peso hoja (gr)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Cantidad utilizada (kg)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Cantidad pliegos (und)', 'logistica' ); ?></th>
					</tr>
				</thead>
				<tbody>
					<?php
					$bobina_rows = array(
						array( 'Medida pliegos', 'pliegos', 0, 0, 0, 0 ),
						array( 'Medida kilos', 'kilos', 0, 0, 0, 0 ),
					);
					$index = 0;
					foreach ( $bobina_rows as $row ) :
						?>
						<tr data-mode="<?php echo esc_attr( $row[1] ); ?>">
							<th><?php echo esc_html( $row[0] ); ?></th>
							<td class="is-editable"><input type="number" step="0.01" data-field="width_cm" value="<?php echo esc_attr( $row[2] ); ?>"></td>
							<td class="is-editable"><input type="number" step="0.01" data-field="height_cm" value="<?php echo esc_attr( $row[3] ); ?>"></td>
							<td class="is-editable"><input type="number" step="0.01" data-field="gsm" value="<?php echo esc_attr( $row[4] ); ?>"></td>
							<td data-output="width_m"></td>
							<td data-output="height_m"></td>
							<td data-output="area_m2"></td>
							<td data-output="gsm_kg"></td>
							<td data-output="sheet_weight"></td>
							<td class="<?php echo 'kilos' === $row[1] ? 'is-editable' : 'is-result'; ?>">
								<?php if ( 'kilos' === $row[1] ) : ?>
									<input type="number" step="0.01" data-field="kg" value="<?php echo esc_attr( $row[5] ); ?>">
								<?php else : ?>
									<span data-output="kg"></span>
								<?php endif; ?>
							</td>
							<td class="<?php echo 'pliegos' === $row[1] ? 'is-editable' : 'is-result'; ?>">
								<?php if ( 'pliegos' === $row[1] ) : ?>
									<input type="number" step="1" data-field="quantity" value="<?php echo esc_attr( $row[5] ); ?>">
								<?php else : ?>
									<span data-output="quantity"></span>
								<?php endif; ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		</div>
		<p class="logistica-tapas-scroll-hint" data-conversion-scroll-hint><?php esc_html_e( 'Desliza horizontalmente para ver todas las columnas.', 'logistica' ); ?></p>
		</div>
	</div>

	<div class="logistica-sheet" id="logistica-calc-gramaje-papel" data-sheet="gramaje-papel">
		<h2><?php esc_html_e( 'Gramaje papel', 'logistica' ); ?></h2>
		<?php logistica_excel_table_zoom_toolbar(); ?>
		<div class="logistica-conversion-scroll-host">
		<div class="logistica-sheet-scroll logistica-tapas-excel-scroll" data-conversion-excel-scroll tabindex="0">
			<table>
				<thead>
					<tr>
						<th></th>
						<th><?php esc_html_e( 'Tamaño hoja ancho (cm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño hoja alto (cm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Peso (gr)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Área hoja (cm2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Área 1 m2 (cm2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Gramaje (gr/m2)', 'logistica' ); ?></th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<th><?php esc_html_e( 'Medida pliegos', 'logistica' ); ?></th>
						<td class="is-editable"><input type="number" step="0.01" data-field="width_cm" value="0"></td>
						<td class="is-editable"><input type="number" step="0.01" data-field="height_cm" value="0"></td>
						<td class="is-editable"><input type="number" step="0.01" data-field="weight_gr" value="0"></td>
						<td data-output="area_cm2"></td>
						<td data-output="one_m2"></td>
						<td class="is-result" data-output="gsm"></td>
					</tr>
				</tbody>
			</table>
		</div>
		<p class="logistica-tapas-scroll-hint" data-conversion-scroll-hint><?php esc_html_e( 'Desliza horizontalmente para ver todas las columnas.', 'logistica' ); ?></p>
		</div>
	</div>

	<div class="logistica-sheet" id="logistica-calc-calibre-material" data-sheet="calibre-material">
		<h2><?php esc_html_e( 'Conversión de calibre', 'logistica' ); ?></h2>
		<?php logistica_excel_table_zoom_toolbar(); ?>
		<p class="logistica-sheet-hint"><?php esc_html_e( 'Convierte entre milímetros, pulgadas decimales y calibre comercial en milésimas (ej. 20"). Fórmula: mm / 25.4 = pulgadas; milésimas = redondeo(pulgadas x 1000).', 'logistica' ); ?></p>
		<div class="logistica-conversion-scroll-host">
		<div class="logistica-sheet-scroll logistica-tapas-excel-scroll" data-conversion-excel-scroll tabindex="0">
			<table>
				<thead>
					<tr>
						<th></th>
						<th><?php esc_html_e( 'Valor de entrada', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Calibre (mm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Pulgadas', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Calibre comercial', 'logistica' ); ?></th>
					</tr>
				</thead>
				<tbody>
					<tr data-mode="mm">
						<th><?php esc_html_e( 'Tengo calibre en mm', 'logistica' ); ?></th>
						<td class="is-editable"><input type="number" step="0.001" min="0" data-field="calibre_mm" value="0" aria-label="<?php esc_attr_e( 'Calibre en milímetros', 'logistica' ); ?>"></td>
						<td class="is-result" data-output="calibre_mm"></td>
						<td class="is-result" data-output="calibre_inches"></td>
						<td class="is-result" data-output="calibre_commercial"></td>
					</tr>
					<tr data-mode="pulgadas">
						<th><?php esc_html_e( 'Tengo calibre en pulgadas', 'logistica' ); ?></th>
						<td class="is-editable"><input type="number" step="0.0001" min="0" data-field="calibre_inches" value="0" aria-label="<?php esc_attr_e( 'Calibre en pulgadas', 'logistica' ); ?>"></td>
						<td class="is-result" data-output="calibre_mm"></td>
						<td class="is-result" data-output="calibre_inches"></td>
						<td class="is-result" data-output="calibre_commercial"></td>
					</tr>
					<tr data-mode="comercial">
						<th><?php esc_html_e( 'Me indican calibre comercial', 'logistica' ); ?></th>
						<td class="is-editable"><input type="number" step="1" min="0" data-field="calibre_commercial" value="0" aria-label="<?php esc_attr_e( 'Calibre comercial en milésimas, por ejemplo 20', 'logistica' ); ?>"></td>
						<td class="is-result" data-output="calibre_mm"></td>
						<td class="is-result" data-output="calibre_inches"></td>
						<td class="is-result" data-output="calibre_commercial"></td>
					</tr>
				</tbody>
			</table>
		</div>
		<p class="logistica-tapas-scroll-hint" data-conversion-scroll-hint><?php esc_html_e( 'Desliza horizontalmente para ver todas las columnas.', 'logistica' ); ?></p>
		</div>
	</div>

	<div class="logistica-sheet is-wide" id="logistica-calc-montaje-compartido" data-sheet="montaje-compartido">
		<h2><?php esc_html_e( 'Montaje compartido impresión', 'logistica' ); ?></h2>
		<?php logistica_excel_table_zoom_toolbar(); ?>
		<div class="logistica-sheet-presets" data-sheet-presets>
			<label>
				<?php esc_html_e( 'Conversión guardada', 'logistica' ); ?>
				<select data-template-select>
					<option value=""><?php esc_html_e( 'Selecciona una conversión', 'logistica' ); ?></option>
				</select>
			</label>
			<div class="logistica-sheet-presets__actions">
				<button type="button" class="button" data-action="save-sheet-template"><?php esc_html_e( 'Guardar', 'logistica' ); ?></button>
				<button type="button" class="button" data-action="load-sheet-template"><?php esc_html_e( 'Cargar', 'logistica' ); ?></button>
				<button type="button" class="button" data-action="edit-sheet-template"><?php esc_html_e( 'Editar', 'logistica' ); ?></button>
				<button type="button" class="button button-link-delete" data-action="delete-sheet-template"><?php esc_html_e( 'Eliminar', 'logistica' ); ?></button>
			</div>
		</div>
		<div class="logistica-conversion-scroll-host">
		<div class="logistica-sheet-scroll logistica-tapas-excel-scroll" data-conversion-excel-scroll tabindex="0">
			<table class="logistica-mount-base">
				<thead>
					<tr>
						<th><?php esc_html_e( 'Tamaño hoja vertical (cm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño hoja horizontal (cm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Gramaje (gr/m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Peso hoja (gr)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Total cabidas', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Estado cabidas', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Estado distribución', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Pliegos montaje', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Cantidad utilizada (kg)', 'logistica' ); ?></th>
					</tr>
				</thead>
				<tbody>
					<tr data-mount-base>
						<td class="is-editable"><input type="number" step="0.01" data-field="height_cm" value="0"></td>
						<td class="is-editable"><input type="number" step="0.01" data-field="width_cm" value="0"></td>
						<td class="is-editable"><input type="number" step="0.01" data-field="gsm" value="0"></td>
						<td data-output="sheet_weight"></td>
						<td class="is-editable"><input type="number" step="1" data-field="target_cavities" value="0"></td>
						<td data-output="cavities_status"></td>
						<td data-output="distribution_status"></td>
						<td class="is-result" data-output="required_sheets"></td>
						<td class="is-result" data-output="kg_used"></td>
					</tr>
				</tbody>
			</table>
			<table class="logistica-mount-refs">
				<thead>
					<tr>
						<th><?php esc_html_e( 'Referencia', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Cabidas', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Unidades requeridas', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Pliegos por referencia', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño distribuido', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Unidades posibles', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Estado', 'logistica' ); ?></th>
						<th class="is-actions-head"><?php esc_html_e( 'Acción', 'logistica' ); ?></th>
					</tr>
				</thead>
				<tbody data-shared-refs>
					<tr>
						<td class="is-editable"><input type="text" data-field="reference" value="Ref 1"></td>
						<td class="is-editable"><input type="number" step="1" data-field="cavities" value="0"></td>
						<td class="is-editable"><input type="number" step="1" data-field="units" value="0"></td>
						<td data-output="sheets_ref"></td>
						<td class="is-result" data-output="distributed_size"></td>
						<td class="is-result" data-output="possible_units"></td>
						<td data-output="ref_status"></td>
						<?php logistica_conversion_action_cell( 'duplicate-shared-ref', 'remove-shared-ref', __( 'Quitar referencia', 'logistica' ) ); ?>
					</tr>
					<tr>
						<td class="is-editable"><input type="text" data-field="reference" value="Ref 2"></td>
						<td class="is-editable"><input type="number" step="1" data-field="cavities" value="0"></td>
						<td class="is-editable"><input type="number" step="1" data-field="units" value="0"></td>
						<td data-output="sheets_ref"></td>
						<td class="is-result" data-output="distributed_size"></td>
						<td class="is-result" data-output="possible_units"></td>
						<td data-output="ref_status"></td>
						<?php logistica_conversion_action_cell( 'duplicate-shared-ref', 'remove-shared-ref', __( 'Quitar referencia', 'logistica' ) ); ?>
					</tr>
					<tr>
						<td class="is-editable"><input type="text" data-field="reference" value="Ref 3"></td>
						<td class="is-editable"><input type="number" step="1" data-field="cavities" value="0"></td>
						<td class="is-editable"><input type="number" step="1" data-field="units" value="0"></td>
						<td data-output="sheets_ref"></td>
						<td class="is-result" data-output="distributed_size"></td>
						<td class="is-result" data-output="possible_units"></td>
						<td data-output="ref_status"></td>
						<?php logistica_conversion_action_cell( 'duplicate-shared-ref', 'remove-shared-ref', __( 'Quitar referencia', 'logistica' ) ); ?>
					</tr>
					<tr data-blank-ref>
						<td><?php esc_html_e( 'Blanco / sobrante', 'logistica' ); ?></td>
						<td data-output="blank_cavities"></td>
						<td>0</td>
						<td>0</td>
						<td class="is-result" data-output="blank_distributed_size"></td>
						<td class="is-result" data-output="blank_possible_units"></td>
						<td data-output="blank_status"></td>
						<td class="logistica-calc-excel-actions-cell"></td>
					</tr>
				</tbody>
			</table>
		</div>
		<p class="logistica-tapas-scroll-hint" data-conversion-scroll-hint><?php esc_html_e( 'Desliza horizontalmente para ver todas las columnas.', 'logistica' ); ?></p>
		</div>
		<div class="logistica-sheet-actions">
			<button type="button" class="button" data-action="add-shared-ref"><?php esc_html_e( 'Agregar referencia', 'logistica' ); ?></button>
		</div>
	</div>

	<div class="logistica-sheet" id="logistica-calc-pliego-conversion" data-sheet="pliego-conversion">
		<h2><?php esc_html_e( 'Conversión de hojas a hojas', 'logistica' ); ?></h2>
		<?php logistica_excel_table_zoom_toolbar(); ?>
		<div class="logistica-sheet-presets" data-sheet-presets>
			<label>
				<?php esc_html_e( 'Conversión guardada', 'logistica' ); ?>
				<select data-template-select>
					<option value=""><?php esc_html_e( 'Selecciona una conversión', 'logistica' ); ?></option>
				</select>
			</label>
			<div class="logistica-sheet-presets__actions">
				<button type="button" class="button" data-action="save-sheet-template"><?php esc_html_e( 'Guardar', 'logistica' ); ?></button>
				<button type="button" class="button" data-action="load-sheet-template"><?php esc_html_e( 'Cargar', 'logistica' ); ?></button>
				<button type="button" class="button" data-action="edit-sheet-template"><?php esc_html_e( 'Editar', 'logistica' ); ?></button>
				<button type="button" class="button button-link-delete" data-action="delete-sheet-template"><?php esc_html_e( 'Eliminar', 'logistica' ); ?></button>
			</div>
		</div>
		<div class="logistica-conversion-scroll-host">
		<div class="logistica-sheet-scroll logistica-tapas-excel-scroll" data-conversion-excel-scroll tabindex="0">
			<table class="logistica-conversion-excel-table">
				<thead>
					<tr>
						<th></th>
						<th><?php esc_html_e( 'Cantidad corte', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño hoja vertical (cm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño hoja horizontal (cm)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Gramaje (gr/m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Vertical (m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Horizontal (m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Tamaño hoja (m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Gramaje (kg/m2)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Peso hoja (gr)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Factor de conversión', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Cantidad pliegos (und)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Cantidad utilizada (kg)', 'logistica' ); ?></th>
						<th><?php esc_html_e( 'Validación corte', 'logistica' ); ?></th>
						<th class="is-actions-head"><?php esc_html_e( 'Acción', 'logistica' ); ?></th>
					</tr>
				</thead>
				<tbody data-pliego-cuts>
					<?php
					$pliego_rows = array(
						array( 'Tamaño inicial', 0, 0, 0, 0, 0 ),
						array( 'Corte 1', 1, 0, 0, 0, '' ),
						array( 'Corte 2', 2, 0, 0, 0, '' ),
						array( 'Corte 3', 3, 0, 0, 0, '' ),
					);
					foreach ( $pliego_rows as $index => $row ) :
						?>
						<tr>
							<th class="<?php echo 0 === $index ? 'is-locked-label' : 'is-editable'; ?>">
								<?php if ( 0 === $index ) : ?>
									<?php echo esc_html( $row[0] ); ?>
								<?php else : ?>
									<input type="text" data-field="cut_label" value="<?php echo esc_attr( $row[0] ); ?>">
								<?php endif; ?>
							</th>
							<td data-output="cuts_label"><?php echo esc_html( $row[1] ); ?></td>
							<td class="is-editable"><input type="number" step="0.01" data-field="height_cm" value="<?php echo esc_attr( $row[2] ); ?>"></td>
							<td class="is-editable"><input type="number" step="0.01" data-field="width_cm" value="<?php echo esc_attr( $row[3] ); ?>"></td>
							<td class="<?php echo 0 === $index ? 'is-editable' : ''; ?>">
								<?php if ( 0 === $index ) : ?>
									<input type="number" step="0.01" data-field="gsm" value="<?php echo esc_attr( $row[4] ); ?>">
								<?php else : ?>
									<span data-output="base_gsm"></span>
								<?php endif; ?>
							</td>
							<td data-output="height_m"></td>
							<td data-output="width_m"></td>
							<td data-output="area_m2"></td>
							<td data-output="gsm_kg"></td>
							<td data-output="sheet_weight"></td>
							<td data-output="factor"></td>
							<td class="<?php echo 0 === $index ? 'is-editable' : 'is-result'; ?>">
								<?php if ( 0 === $index ) : ?>
									<input type="number" step="1" data-field="quantity" value="<?php echo esc_attr( $row[5] ); ?>">
								<?php else : ?>
									<span data-output="quantity"></span>
								<?php endif; ?>
							</td>
							<td class="is-result" data-output="kg_used"></td>
							<td data-output="cut_status"></td>
							<?php if ( 0 !== $index ) : ?>
								<?php logistica_conversion_action_cell( 'duplicate-pliego-cut', 'remove-pliego-cut', __( 'Quitar corte', 'logistica' ) ); ?>
							<?php else : ?>
								<td class="logistica-calc-excel-actions-cell"></td>
							<?php endif; ?>
						</tr>
					<?php endforeach; ?>
				</tbody>
				<tfoot>
					<tr class="logistica-cut-summary">
						<td colspan="7"><?php esc_html_e( 'Resumen cortes del tamaño inicial', 'logistica' ); ?></td>
						<td data-output="used_area"></td>
						<td colspan="2" data-output="remaining_area"></td>
						<td colspan="5" data-output="cut_summary"></td>
					</tr>
				</tfoot>
			</table>
		</div>
		<p class="logistica-tapas-scroll-hint" data-conversion-scroll-hint><?php esc_html_e( 'Desliza horizontalmente para ver todas las columnas.', 'logistica' ); ?></p>
		</div>
		<div class="logistica-sheet-actions">
			<button type="button" class="button" data-action="add-pliego-cut"><?php esc_html_e( 'Agregar corte', 'logistica' ); ?></button>
		</div>
	</div>

		</div>
	</div>

</section>
