<?php
/**
 * Catálogo e impresión de rótulos para marcar rollos.
 *
 * @package Logistica
 */

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

require_once LOGISTICA_PLUGIN_DIR . 'admin/views/partials.php';

$rows          = Logistica_Rotulo_Rollos_Catalog::get_all();
$tipo_options  = Logistica_Rotulo_Rollos_Catalog::tipo_options();
$tamano_options = Logistica_Rotulo_Rollos_Catalog::tamano_options();
$print_settings = Logistica_Rotulo_Rollos_Print::get_settings();
$save_action   = admin_url( 'admin-post.php' );
$redirect_base = logistica_tab_url( 'logistica-rotulos-rollos', is_admin() ? 'admin' : 'frontend' );
$export_url    = wp_nonce_url(
	add_query_arg( 'action', 'logistica_export_rotulo_rollos', admin_url( 'admin-post.php' ) ),
	'logistica_export_rotulo_rollos'
);
$status        = isset( $_GET['logistica_status'] ) ? sanitize_key( wp_unslash( $_GET['logistica_status'] ) ) : '';
$error_message = get_transient( 'logistica_rotulo_rollos_error_' . get_current_user_id() );
$import_result = in_array( $status, array( 'imported', 'import_error' ), true )
	? get_transient( 'logistica_rotulo_rollos_import_' . get_current_user_id() )
	: false;
$filter_tipos  = array();
$filter_tamanos = array();

foreach ( $rows as $row ) {
	if ( ! empty( $row['tipo'] ) ) {
		$filter_tipos[ $row['tipo'] ] = $tipo_options[ $row['tipo'] ] ?? $row['tipo'];
	}
	if ( ! empty( $row['tamano'] ) ) {
		$filter_tamanos[ $row['tamano'] ] = $row['tamano'];
	}
}

if ( $filter_tipos ) {
	asort( $filter_tipos, SORT_NATURAL | SORT_FLAG_CASE );
}
if ( $filter_tamanos ) {
	asort( $filter_tamanos, SORT_NATURAL | SORT_FLAG_CASE );
}

if ( $error_message ) {
	delete_transient( 'logistica_rotulo_rollos_error_' . get_current_user_id() );
}
if ( is_array( $import_result ) ) {
	delete_transient( 'logistica_rotulo_rollos_import_' . get_current_user_id() );
}
$rotulos_module_tabs = array(
	array(
		'id'    => 'rollos',
		'label' => __( 'Rótulos rollos', 'logistica' ),
	),
	array(
		'id'    => 'estibas',
		'label' => __( 'Estibas producto terminado', 'logistica' ),
	),
);
?>
<div class="logistica-rotulos-module" data-rotulos-module>
	<?php if ( ! logistica_is_tabbed_shell() ) : ?>
		<?php logistica_tab_loading_overlay( logistica_tab_loading_message( 'logistica-rotulos-rollos' ), false ); ?>
	<?php endif; ?>

	<div class="logistica-rotulos-module__tabs logistica-user-panel__tabs" role="tablist" aria-label="<?php esc_attr_e( 'Tipos de rotulado', 'logistica' ); ?>">
		<?php foreach ( $rotulos_module_tabs as $index => $module_tab ) : ?>
			<button
				type="button"
				class="logistica-user-panel__tab<?php echo 0 === $index ? ' is-active' : ''; ?>"
				role="tab"
				id="rotulos-module-tab-btn-<?php echo esc_attr( $module_tab['id'] ); ?>"
				data-rotulos-module-tab="<?php echo esc_attr( $module_tab['id'] ); ?>"
				aria-controls="rotulos-module-tab-<?php echo esc_attr( $module_tab['id'] ); ?>"
				aria-selected="<?php echo 0 === $index ? 'true' : 'false'; ?>"
			><?php echo esc_html( $module_tab['label'] ); ?></button>
		<?php endforeach; ?>
	</div>

	<div class="logistica-user-panel__tab-panels logistica-rotulos-module__panels">
		<div
			class="logistica-user-panel__tab-panel is-active"
			role="tabpanel"
			id="rotulos-module-tab-rollos"
			data-rotulos-module-tab-panel="rollos"
			aria-labelledby="rotulos-module-tab-btn-rollos"
		>
<section class="logistica-rotulo-rollos-board" data-rotulo-rollos-board data-rotulo-post-url="<?php echo esc_url( $save_action ); ?>" data-rotulo-redirect-base="<?php echo esc_url( $redirect_base ); ?>" data-rotulo-delete-nonce="<?php echo esc_attr( wp_create_nonce( 'logistica_delete_rotulo_rollos' ) ); ?>" data-rotulo-tipos="<?php echo esc_attr( wp_json_encode( $tipo_options, JSON_UNESCAPED_UNICODE ) ); ?>">
	<div class="logistica-close-toolbar logistica-rotulo-rollos-toolbar">
		<div class="logistica-rotulo-rollos-toolbar__intro">
			<div class="logistica-rotulo-rollos-toolbar__badge" aria-hidden="true">
				<span class="dashicons dashicons-media-default"></span>
			</div>
			<div>
				<h2><?php esc_html_e( 'Rótulos para rollos', 'logistica' ); ?></h2>
				<p><?php esc_html_e( 'Define tipos y tamaños de ancho. Cada tamaño recibe un color automático. Imprime rótulos con lote, peso y gramaje.', 'logistica' ); ?></p>
			</div>
		</div>
	</div>

	<?php if ( 'saved' === $status ) : ?>
		<div class="notice notice-success"><p><?php esc_html_e( 'Registro guardado.', 'logistica' ); ?></p></div>
	<?php elseif ( 'deleted' === $status ) : ?>
		<div class="notice notice-success"><p><?php esc_html_e( 'Registro eliminado.', 'logistica' ); ?></p></div>
	<?php elseif ( 'print_settings_saved' === $status ) : ?>
		<div class="notice notice-success"><p><?php esc_html_e( 'Tamaño de rótulo guardado.', 'logistica' ); ?></p></div>
	<?php elseif ( 'imported' === $status ) : ?>
		<div class="notice notice-success"><p><?php echo esc_html( is_array( $import_result ) && ! empty( $import_result['message'] ) ? $import_result['message'] : __( 'Datos importados desde Excel correctamente.', 'logistica' ) ); ?></p></div>
	<?php elseif ( 'import_error' === $status ) : ?>
		<div class="notice notice-error"><p><?php echo esc_html( is_array( $import_result ) && ! empty( $import_result['message'] ) ? $import_result['message'] : __( 'No se pudo importar el archivo Excel.', 'logistica' ) ); ?></p></div>
	<?php elseif ( 'error' === $status && $error_message ) : ?>
		<div class="notice notice-error"><p><?php echo esc_html( $error_message ); ?></p></div>
	<?php endif; ?>

	<p class="logistica-rotulo-rollos-status" data-rotulo-rollos-status role="status" aria-live="polite"></p>

	<?php require LOGISTICA_PLUGIN_DIR . 'admin/views/partials/rotulo-rollos-print-settings.php'; ?>

	<div class="logistica-rotulo-rollos-layout">
		<div class="logistica-rotulo-rollos-form-column">
			<form class="logistica-rotulo-rollos-form" method="post" action="<?php echo esc_url( $save_action ); ?>" data-rotulo-new-form>
				<input type="hidden" name="action" value="logistica_save_rotulo_rollos">
				<?php wp_nonce_field( 'logistica_save_rotulo_rollos' ); ?>
				<input type="hidden" name="redirect_to" value="<?php echo esc_url( $redirect_base ); ?>">
				<input type="hidden" name="id" value="0">

				<div class="logistica-rotulo-rollos-section-head logistica-rotulo-rollos-section-head--compact">
					<span class="logistica-rotulo-rollos-section-head__icon" aria-hidden="true">
						<span class="dashicons dashicons-plus-alt2"></span>
					</span>
					<p class="logistica-rotulo-rollos-section-head__title"><?php esc_html_e( 'Nuevo ancho', 'logistica' ); ?></p>
				</div>

				<label><?php esc_html_e( 'Tipo', 'logistica' ); ?>
					<select name="tipo" required data-rotulo-tipo-select>
						<option value=""><?php esc_html_e( 'Seleccionar…', 'logistica' ); ?></option>
						<?php foreach ( $tipo_options as $tipo_key => $tipo_label ) : ?>
							<option value="<?php echo esc_attr( $tipo_key ); ?>"><?php echo esc_html( $tipo_label ); ?></option>
						<?php endforeach; ?>
					</select>
				</label>

				<label><?php esc_html_e( 'Tamaño', 'logistica' ); ?>
					<select name="tamano" required data-rotulo-tamano-field>
						<option value=""><?php esc_html_e( 'Seleccionar…', 'logistica' ); ?></option>
						<?php foreach ( $tamano_options as $tamano_option ) : ?>
							<option value="<?php echo esc_attr( $tamano_option ); ?>"><?php echo esc_html( $tamano_option ); ?></option>
						<?php endforeach; ?>
					</select>
				</label>

				<p class="logistica-rotulo-rollos-color-preview" data-rotulo-color-preview hidden>
					<span class="logistica-rotulo-rollos-color-preview__swatch" data-rotulo-color-swatch aria-hidden="true"></span>
					<span data-rotulo-color-label></span>
				</p>

				<label><?php esc_html_e( 'Observaciones', 'logistica' ); ?>
					<textarea name="observaciones" rows="2" placeholder="<?php esc_attr_e( 'Opcional', 'logistica' ); ?>"></textarea>
				</label>

				<p class="logistica-rotulo-rollos-form__actions">
					<button type="submit" class="button button-primary"><?php esc_html_e( 'Guardar', 'logistica' ); ?></button>
				</p>
			</form>
		</div>

		<div class="logistica-rotulo-rollos-table-wrap logistica-tapas-excel-wrap" data-excel-zoom-root="rotulo-rollos">
			<form
				id="logistica-rotulo-rollos-excel-upload"
				class="logistica-excel-upload-form-source"
				method="post"
				action="<?php echo esc_url( $save_action ); ?>"
				enctype="multipart/form-data"
				hidden
			>
				<input type="hidden" name="action" value="logistica_import_rotulo_rollos">
				<input type="hidden" name="redirect_to" value="<?php echo esc_url( $redirect_base ); ?>">
				<?php wp_nonce_field( 'logistica_import_rotulo_rollos' ); ?>
			</form>

			<div class="logistica-rotulo-rollos-table-wrap__head">
				<div class="logistica-rotulo-rollos-section-head">
					<span class="logistica-rotulo-rollos-section-head__icon" aria-hidden="true">
						<span class="dashicons dashicons-list-view"></span>
					</span>
					<div class="logistica-rotulo-rollos-section-head__text">
						<p class="logistica-rotulo-rollos-section-head__title"><?php esc_html_e( 'Registros', 'logistica' ); ?></p>
						<span class="logistica-rotulo-rollos-section-head__count" data-rotulo-rollos-total><?php echo esc_html( (string) count( $rows ) ); ?></span>
					</div>
				</div>
				<?php
				logistica_table_excel_toolbar(
					array(
						'export_url'        => $export_url,
						'import_form_id'    => 'logistica-rotulo-rollos-excel-upload',
						'import_input_id'   => 'logistica-rotulo-rollos-excel-file',
						'import_input_name' => 'rotulo_rollos_file',
						'import_data_attr'  => 'rotulo-rollos-import-file',
						'import_action'     => 'import-rotulo-rollos-excel',
						'show_zoom'         => true,
					)
				);
				?>
				<p class="logistica-empty-hint logistica-rotulo-rollos-excel-hint"><?php esc_html_e( 'Exporta la plantilla con los registros actuales. Incluye la columna ID para actualizar filas existentes. La columna Ancho es solo referencia.', 'logistica' ); ?></p>
			</div>

			<p class="logistica-empty-hint" data-rotulo-rollos-empty-hint <?php echo empty( $rows ) ? '' : 'hidden'; ?>><?php esc_html_e( 'Aún no hay anchos registrados. Usa el formulario para agregar el primero.', 'logistica' ); ?></p>

			<div class="logistica-tapas-filters logistica-rotulo-rollos-filters" data-rotulo-rollos-filters>
				<div class="logistica-tapas-filters__head">
					<?php logistica_table_filters_icon(); ?>
					<p class="logistica-tapas-filters__title"><?php esc_html_e( 'Buscar y filtrar', 'logistica' ); ?></p>
					<span class="logistica-tapas-filters__badge" data-rotulo-rollos-filter-badge hidden><?php esc_html_e( 'Activo', 'logistica' ); ?></span>
				</div>
				<div class="logistica-tapas-filters__fields">
					<label class="logistica-tapas-filters__field logistica-tapas-filters__field--search">
						<span class="logistica-tapas-filters__label"><?php esc_html_e( 'Buscar', 'logistica' ); ?></span>
						<input
							type="search"
							data-rotulo-rollos-filter-search
							placeholder="<?php esc_attr_e( 'Tipo, tamaño, ancho, observaciones…', 'logistica' ); ?>"
							autocomplete="off"
							spellcheck="false"
						>
					</label>
					<label class="logistica-tapas-filters__field">
						<span class="logistica-tapas-filters__label"><?php esc_html_e( 'Tipo', 'logistica' ); ?></span>
						<select data-rotulo-rollos-filter-tipo>
							<option value=""><?php esc_html_e( 'Todos', 'logistica' ); ?></option>
							<?php foreach ( $filter_tipos as $filter_tipo_key => $filter_tipo_label ) : ?>
								<option value="<?php echo esc_attr( $filter_tipo_key ); ?>"><?php echo esc_html( $filter_tipo_label ); ?></option>
							<?php endforeach; ?>
						</select>
					</label>
					<label class="logistica-tapas-filters__field">
						<span class="logistica-tapas-filters__label"><?php esc_html_e( 'Tamaño', 'logistica' ); ?></span>
						<select data-rotulo-rollos-filter-tamano>
							<option value=""><?php esc_html_e( 'Todos', 'logistica' ); ?></option>
							<?php foreach ( $filter_tamanos as $filter_tamano_value ) : ?>
								<option value="<?php echo esc_attr( $filter_tamano_value ); ?>"><?php echo esc_html( $filter_tamano_value ); ?></option>
							<?php endforeach; ?>
						</select>
					</label>
					<div class="logistica-tapas-filters__actions">
						<button type="button" class="button logistica-tapas-filters__btn" data-action="clear-rotulo-rollos-filters" disabled>
							<?php logistica_table_filters_clear_icon(); ?>
							<?php esc_html_e( 'Limpiar filtros', 'logistica' ); ?>
						</button>
					</div>
				</div>
				<p class="logistica-tapas-filters__meta" data-rotulo-rollos-filter-meta hidden></p>
			</div>

			<p class="logistica-rotulo-rollos-filter-empty" data-rotulo-rollos-filter-empty hidden>
				<?php esc_html_e( 'Ningún registro coincide con la búsqueda o los filtros.', 'logistica' ); ?>
			</p>

			<div class="logistica-rotulo-rollos-table-card" <?php echo empty( $rows ) ? 'hidden' : ''; ?> data-rotulo-rollos-table-card>
				<div class="logistica-rotulo-rollos-scroll" tabindex="0">
					<table class="widefat striped logistica-rotulo-rollos-table">
						<thead>
							<tr>
								<th scope="col"><?php esc_html_e( 'Color', 'logistica' ); ?></th>
								<th scope="col"><?php esc_html_e( 'Tipo', 'logistica' ); ?></th>
								<th scope="col"><?php esc_html_e( 'Tamaño', 'logistica' ); ?></th>
								<th scope="col"><?php esc_html_e( 'Ancho', 'logistica' ); ?></th>
								<th scope="col"><?php esc_html_e( 'Observaciones', 'logistica' ); ?></th>
								<th class="is-actions-head" scope="col"><?php esc_html_e( 'Acción', 'logistica' ); ?></th>
							</tr>
						</thead>
						<tbody data-rotulo-rollos-rows>
						<?php foreach ( $rows as $row ) : ?>
							<?php
							$observaciones_text = trim( (string) ( $row['observaciones'] ?? '' ) );
							?>
							<tr
								data-rotulo-row
								data-rotulo-id="<?php echo esc_attr( (string) (int) $row['id'] ); ?>"
								data-tipo="<?php echo esc_attr( $row['tipo'] ); ?>"
								data-tipo-label="<?php echo esc_attr( $row['tipo_label'] ); ?>"
								data-tamano="<?php echo esc_attr( $row['tamano'] ); ?>"
								data-ancho-label="<?php echo esc_attr( $row['ancho_label'] ); ?>"
								data-accent-color="<?php echo esc_attr( $row['accent_color'] ); ?>"
								data-rotulo-search="<?php echo esc_attr( Logistica_Rotulo_Rollos_Catalog::build_row_search_text( $row ) ); ?>"
							>
								<td>
									<span class="logistica-rotulo-rollos-color-chip" style="background-color: <?php echo esc_attr( $row['accent_color'] ); ?>;" title="<?php echo esc_attr( $row['accent_color'] ); ?>"></span>
								</td>
								<td><?php echo esc_html( $row['tipo_label'] ); ?></td>
								<td><?php echo esc_html( $row['tamano'] ); ?></td>
								<td><strong><?php echo esc_html( $row['ancho_label'] ); ?></strong></td>
								<td class="logistica-rotulo-rollos-observaciones-cell"><?php echo esc_html( '' !== $observaciones_text ? $observaciones_text : '—' ); ?></td>
								<td class="logistica-rotulo-rollos-actions-cell">
									<div class="logistica-rotulo-rollos-actions">
										<button type="button" class="button button-small logistica-table-icon-btn logistica-rotulo-rollos-btn-print" data-action="print-rotulo-rollos" aria-label="<?php esc_attr_e( 'Imprimir rótulo', 'logistica' ); ?>" title="<?php esc_attr_e( 'Imprimir rótulo', 'logistica' ); ?>">
											<span class="dashicons dashicons-printer" aria-hidden="true"></span>
										</button>
										<button type="button" class="button button-small logistica-table-icon-btn logistica-rotulo-rollos-btn-edit" data-action="edit-rotulo-rollos" data-rotulo-id="<?php echo esc_attr( (string) (int) $row['id'] ); ?>" aria-label="<?php esc_attr_e( 'Editar', 'logistica' ); ?>" title="<?php esc_attr_e( 'Editar', 'logistica' ); ?>">
											<span class="dashicons dashicons-edit" aria-hidden="true"></span>
										</button>
										<form method="post" action="<?php echo esc_url( $save_action ); ?>" class="logistica-inline-delete-form" onsubmit="return confirm('<?php echo esc_js( __( '¿Eliminar este registro?', 'logistica' ) ); ?>');">
											<input type="hidden" name="action" value="logistica_delete_rotulo_rollos">
											<?php wp_nonce_field( 'logistica_delete_rotulo_rollos' ); ?>
											<input type="hidden" name="redirect_to" value="<?php echo esc_url( $redirect_base ); ?>">
											<input type="hidden" name="id" value="<?php echo esc_attr( (string) (int) $row['id'] ); ?>">
											<button type="submit" class="button button-small logistica-table-icon-btn logistica-rotulo-rollos-btn-delete" aria-label="<?php esc_attr_e( 'Eliminar', 'logistica' ); ?>" title="<?php esc_attr_e( 'Eliminar', 'logistica' ); ?>">
												<span class="dashicons dashicons-trash" aria-hidden="true"></span>
											</button>
										</form>
									</div>
								</td>
							</tr>
						<?php endforeach; ?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>

	<div class="logistica-label-print-modal logistica-rotulo-rollos-print-modal" data-rotulo-print-modal hidden aria-hidden="true">
		<div class="logistica-label-print-modal__backdrop" data-rotulo-print-close></div>
		<div class="logistica-label-print-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="rotulo-print-modal-title">
			<header class="logistica-label-print-modal__head">
				<div>
					<h3 id="rotulo-print-modal-title"><?php esc_html_e( 'Imprimir rótulo de rollo', 'logistica' ); ?></h3>
					<p class="logistica-label-print-modal__ref" data-rotulo-print-summary></p>
				</div>
				<button type="button" class="logistica-label-print-modal__close" data-rotulo-print-close aria-label="<?php esc_attr_e( 'Cerrar', 'logistica' ); ?>">&times;</button>
			</header>
			<form class="logistica-label-print-modal__body" data-rotulo-print-form>
				<div class="logistica-label-print-modal__scroll">
					<div class="logistica-prod-label-preview-wrap logistica-roll-label-preview-wrap" data-rotulo-visual-preview>
						<div data-rotulo-visual-preview-mount></div>
					</div>

					<input type="hidden" data-rotulo-field="rotulo_id">
					<input type="hidden" data-rotulo-field="ancho_label">
					<input type="hidden" data-rotulo-field="tamano">
					<input type="hidden" data-rotulo-field="accent_color">

					<fieldset class="logistica-label-print-modal__section">
						<legend><?php esc_html_e( 'Tamaño de impresión', 'logistica' ); ?></legend>
						<p class="logistica-label-print-modal__hint" data-rotulo-print-size-hint></p>
					</fieldset>

					<fieldset class="logistica-label-print-modal__section">
						<legend><?php esc_html_e( 'Datos del rollo', 'logistica' ); ?></legend>
						<div class="logistica-label-print-modal__grid">
							<label><?php esc_html_e( 'Ancho', 'logistica' ); ?><input type="text" data-rotulo-field="ancho_display" readonly class="logistica-readonly-field"></label>
							<label><?php esc_html_e( 'Lote', 'logistica' ); ?><input type="text" name="lote" data-rotulo-field="lote" required inputmode="numeric" placeholder="<?php esc_attr_e( 'Ej. 1001', 'logistica' ); ?>"></label>
							<label><?php esc_html_e( 'Consecutivo', 'logistica' ); ?><input type="number" name="num_consecutivo" min="1" step="1" data-rotulo-field="num_consecutivo" value="1" title="<?php esc_attr_e( 'Cantidad de rollos con lotes consecutivos a partir del lote inicial.', 'logistica' ); ?>"></label>
							<label data-rotulo-peso-single-wrap><?php esc_html_e( 'Peso', 'logistica' ); ?><input type="text" name="peso" data-rotulo-field="peso" inputmode="numeric" placeholder="<?php esc_attr_e( 'Opcional', 'logistica' ); ?>"></label>
							<label><?php esc_html_e( 'Gramaje', 'logistica' ); ?><input type="text" name="gramaje" data-rotulo-field="gramaje" required placeholder="<?php esc_attr_e( 'Ej. 298 GR', 'logistica' ); ?>"></label>
							<label><?php esc_html_e( 'Copias', 'logistica' ); ?><input type="number" name="num_copias" min="1" step="1" data-rotulo-field="num_copias" value="1" title="<?php esc_attr_e( 'Copias de cada rótulo generado.', 'logistica' ); ?>"></label>
						</div>
						<div class="logistica-rotulo-peso-por-lote" data-rotulo-peso-por-lote-wrap hidden>
							<p class="logistica-rotulo-peso-por-lote__title"><?php esc_html_e( 'Peso por lote', 'logistica' ); ?></p>
							<p class="logistica-label-print-modal__hint logistica-rotulo-peso-por-lote__hint"><?php esc_html_e( 'Indica el peso de cada rollo o déjalo en blanco si aún no lo conoces.', 'logistica' ); ?></p>
							<div class="logistica-rotulo-peso-por-lote__list" data-rotulo-peso-por-lote-list></div>
						</div>
						<p class="logistica-label-print-modal__hint logistica-rotulo-rollos-consecutivo-hint" data-rotulo-consecutivo-hint hidden></p>
						<div class="logistica-rotulo-print-history" data-rotulo-print-history hidden>
							<div class="logistica-rotulo-print-history__head">
								<p class="logistica-rotulo-print-history__title"><?php esc_html_e( 'Historial de rotulación', 'logistica' ); ?></p>
								<p class="logistica-rotulo-print-history__hint"><?php esc_html_e( 'Últimos 2 registros. Pulsa uno para cargar lote y gramaje.', 'logistica' ); ?></p>
							</div>
							<div class="logistica-rotulo-print-history__list" data-rotulo-print-history-list role="list"></div>
						</div>
					</fieldset>

					<p class="logistica-label-print-modal__status" data-rotulo-print-status role="status"></p>
				</div>
				<footer class="logistica-label-print-modal__foot">
					<button type="button" class="button" data-rotulo-print-preview><?php esc_html_e( 'Vista previa', 'logistica' ); ?></button>
					<button type="submit" class="button button-primary"><?php esc_html_e( 'Imprimir', 'logistica' ); ?></button>
				</footer>
			</form>
		</div>
	</div>

	<div class="logistica-label-print-modal logistica-rotulo-rollos-edit-modal" data-rotulo-edit-modal hidden aria-hidden="true">
		<div class="logistica-label-print-modal__backdrop" data-rotulo-edit-close></div>
		<div class="logistica-label-print-modal__dialog" role="dialog" aria-modal="true">
			<header class="logistica-label-print-modal__head">
				<h3><?php esc_html_e( 'Editar ancho', 'logistica' ); ?></h3>
				<button type="button" class="logistica-label-print-modal__close" data-rotulo-edit-close aria-label="<?php esc_attr_e( 'Cerrar', 'logistica' ); ?>">&times;</button>
			</header>
			<form class="logistica-label-print-modal__body" data-rotulo-edit-form method="post" action="<?php echo esc_url( $save_action ); ?>">
				<div class="logistica-label-print-modal__scroll">
					<input type="hidden" name="action" value="logistica_save_rotulo_rollos">
					<?php wp_nonce_field( 'logistica_save_rotulo_rollos' ); ?>
					<input type="hidden" name="redirect_to" value="<?php echo esc_url( $redirect_base ); ?>">
					<input type="hidden" name="id" value="0" data-rotulo-edit-id>

					<label><?php esc_html_e( 'Tipo', 'logistica' ); ?>
						<select name="tipo" required data-rotulo-edit-tipo>
							<?php foreach ( $tipo_options as $tipo_key => $tipo_label ) : ?>
								<option value="<?php echo esc_attr( $tipo_key ); ?>"><?php echo esc_html( $tipo_label ); ?></option>
							<?php endforeach; ?>
						</select>
					</label>

					<label><?php esc_html_e( 'Tamaño', 'logistica' ); ?>
						<select name="tamano" required data-rotulo-edit-tamano>
							<?php foreach ( $tamano_options as $tamano_option ) : ?>
								<option value="<?php echo esc_attr( $tamano_option ); ?>"><?php echo esc_html( $tamano_option ); ?></option>
							<?php endforeach; ?>
						</select>
					</label>

					<label><?php esc_html_e( 'Observaciones', 'logistica' ); ?>
						<textarea name="observaciones" rows="3" data-rotulo-edit-observaciones></textarea>
					</label>
				</div>
				<footer class="logistica-label-print-modal__foot">
					<button type="button" class="button" data-rotulo-edit-close><?php esc_html_e( 'Cancelar', 'logistica' ); ?></button>
					<button type="submit" class="button button-primary"><?php esc_html_e( 'Guardar', 'logistica' ); ?></button>
				</footer>
			</form>
		</div>
	</div>
</section>
		</div>

		<div
			class="logistica-user-panel__tab-panel"
			role="tabpanel"
			id="rotulos-module-tab-estibas"
			data-rotulos-module-tab-panel="estibas"
			aria-labelledby="rotulos-module-tab-btn-estibas"
			hidden
		>
			<?php require LOGISTICA_PLUGIN_DIR . 'admin/views/partials/rotulo-estibas-panel.php'; ?>
		</div>
	</div>
</div>
