<?php
/**
 * Planeación de formado — vista semanal por máquina.
 *
 * @package Logistica
 */

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

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

$week_start = Logistica_Forming_Planning::week_start();
$machines   = Logistica_Forming_Planning::get_machines();
$days       = Logistica_Forming_Planning::week_days( $week_start );
$statuses   = Logistica_Forming_Planning::get_statuses();
$complexities = Logistica_Forming_Planning::get_complexity_labels();
$labor_types  = Logistica_Forming_Planning::get_labor_types();
$papel_materials = Logistica_Forming_Planning::get_papel_materials();
$field_options   = Logistica_Forming_Planning::get_field_options();
$day_hours    = Logistica_Forming_Planning::default_day_hours();
$day_types    = Logistica_Forming_Planning::day_types();
$panel_year            = (int) wp_date( 'Y' );
$show_planeacion_board = ! is_admin();
$frontend_panel_url    = logistica_tab_url( 'logistica-planeacion-formado', 'frontend' );

logistica_admin_header( __( 'Planeación formado', 'logistica' ) );
?>
<section class="logistica-panel logistica-planeacion<?php echo $show_planeacion_board ? '' : ' logistica-planeacion--admin-settings'; ?>" data-planeacion-board<?php echo $show_planeacion_board ? '' : ' data-planeacion-admin-settings-only="1"'; ?>>
	<?php if ( ! logistica_is_tabbed_shell() ) : ?>
		<?php logistica_tab_loading_overlay( logistica_tab_loading_message( 'logistica-planeacion-formado' ) ); ?>
	<?php endif; ?>
	<div class="logistica-page-toolbar logistica-planeacion__toolbar">
		<?php
		if ( $show_planeacion_board ) {
			logistica_page_toolbar_intro(
				__( 'Planeación de formado', 'logistica' ),
				__( 'Organiza trabajos por máquina y día. Configura la jornada en cada columna; la duración de formado se calcula según referencia, cantidad y rendimiento (und/h).', 'logistica' ),
				'dashicons-calendar-alt'
			);
		} else {
			logistica_page_toolbar_intro(
				__( 'Configuración planeación formado', 'logistica' ),
				__( 'Opciones de administración para listas desplegables. La planeación operativa (Gantt, actividades e importación) está en el panel público.', 'logistica' ),
				'dashicons-admin-settings'
			);
		}
		?>
		<div class="logistica-planeacion__toolbar-actions">
			<span class="logistica-planeacion__save-status" data-planeacion-save-status aria-live="polite"></span>
		</div>
	</div>

	<?php if ( ! $show_planeacion_board ) : ?>
	<div class="logistica-planeacion__admin-settings">
		<?php if ( $frontend_panel_url ) : ?>
			<p class="logistica-planeacion__admin-settings-link">
				<a class="button button-secondary" href="<?php echo esc_url( $frontend_panel_url ); ?>"><?php esc_html_e( 'Abrir planeación en el panel público', 'logistica' ); ?></a>
			</p>
		<?php endif; ?>
		<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary" data-action="planeacion-edit-field-options">
			<span class="dashicons dashicons-list-view" aria-hidden="true"></span>
			<?php esc_html_e( 'Listas desplegables', 'logistica' ); ?>
		</button>
		<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary" data-action="planeacion-edit-forming-yield">
			<span class="dashicons dashicons-performance" aria-hidden="true"></span>
			<?php esc_html_e( 'Rendimiento por referencia', 'logistica' ); ?>
		</button>
	</div>
	<?php endif; ?>

	<?php if ( $show_planeacion_board ) : ?>
	<nav class="logistica-planeacion__machines logistica-planeacion__machines--select" aria-label="<?php esc_attr_e( 'Máquinas', 'logistica' ); ?>" data-planeacion-machines></nav>

	<?php require LOGISTICA_PLUGIN_DIR . 'admin/views/partials/planeacion-config-toolbar.php'; ?>

	<?php
	$planeacion_metrics_compare_title   = __( 'Gráficos de resultados por período', 'logistica' );
	$planeacion_metrics_use_period_form = true;
	require LOGISTICA_PLUGIN_DIR . 'admin/views/partials/planeacion-metrics.php';
	unset( $planeacion_metrics_compare_title, $planeacion_metrics_use_period_form );
	?>

	<ul class="logistica-planeacion__legend" aria-label="<?php esc_attr_e( 'Estados', 'logistica' ); ?>">
		<?php foreach ( $statuses as $key => $label ) : ?>
			<li>
				<span class="logistica-planeacion__status-swatch logistica-planeacion__status-swatch--<?php echo esc_attr( $key ); ?>"></span>
				<?php echo esc_html( $label ); ?>
			</li>
		<?php endforeach; ?>
	</ul>

	<div class="logistica-planeacion__board-section" data-excel-zoom-root="planeacion-formado">
		<div class="logistica-planeacion__board-toolbar">
			<div class="logistica-planeacion__week-nav" aria-label="<?php esc_attr_e( 'Navegación semanal', 'logistica' ); ?>">
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--icon" data-action="planeacion-prev-week" aria-label="<?php esc_attr_e( 'Semana anterior', 'logistica' ); ?>">
					<span class="dashicons dashicons-arrow-left-alt2" aria-hidden="true"></span>
				</button>
				<span class="logistica-planeacion__week-label" data-planeacion-week-label></span>
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--icon" data-action="planeacion-next-week" aria-label="<?php esc_attr_e( 'Semana siguiente', 'logistica' ); ?>">
					<span class="dashicons dashicons-arrow-right-alt2" aria-hidden="true"></span>
				</button>
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary logistica-planeacion__btn--compact" data-action="planeacion-today-week"><?php esc_html_e( 'Esta semana', 'logistica' ); ?></button>
			</div>
			<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary logistica-planeacion__btn--compact logistica-planeacion-pedidos-open" data-action="planeacion-pedidos-open" data-planeacion-pedidos-module="formado">
				<span class="dashicons dashicons-cart" aria-hidden="true"></span>
				<?php esc_html_e( 'Desde pedidos', 'logistica' ); ?>
			</button>
			<?php logistica_excel_table_zoom_controls(); ?>
		</div>
		<div class="logistica-planeacion__board-scroll" data-planeacion-scroll>
	<div class="logistica-planeacion__board" data-planeacion-grid>
		<?php foreach ( $days as $day ) : ?>
			<div class="logistica-planeacion__day" data-planeacion-day="<?php echo esc_attr( (string) $day['index'] ); ?>">
				<header class="logistica-planeacion__day-header">
					<div class="logistica-planeacion__day-title">
						<strong><?php echo esc_html( $day['label'] ); ?></strong>
						<span><?php echo esc_html( $day['short'] ); ?></span>
					</div>
					<label class="logistica-planeacion__day-type">
						<span class="screen-reader-text"><?php esc_html_e( 'Tipo de día', 'logistica' ); ?></span>
						<select
							data-planeacion-day-type="<?php echo esc_attr( (string) $day['index'] ); ?>"
							aria-label="<?php echo esc_attr( sprintf( __( 'Tipo de día %s', 'logistica' ), $day['label'] ) ); ?>"
						>
							<?php foreach ( $day_types as $type_key => $type_label ) : ?>
								<option value="<?php echo esc_attr( $type_key ); ?>"><?php echo esc_html( $type_label ); ?></option>
							<?php endforeach; ?>
						</select>
					</label>
					<div class="logistica-planeacion__day-hours">
						<label class="logistica-planeacion__time-field">
							<span class="screen-reader-text"><?php esc_html_e( 'Inicio jornada', 'logistica' ); ?></span>
							<input
								type="time"
								class="logistica-planeacion__time-input"
								value="<?php echo esc_attr( Logistica_Forming_Planning::minutes_to_time_input( $day_hours[ (string) $day['index'] ]['start'] ?? 420 ) ); ?>"
								data-planeacion-day-start="<?php echo esc_attr( (string) $day['index'] ); ?>"
								aria-label="<?php echo esc_attr( sprintf( __( 'Inicio jornada %s', 'logistica' ), $day['label'] ) ); ?>"
							>
						</label>
						<span class="logistica-planeacion__day-hours-sep" aria-hidden="true">–</span>
						<label class="logistica-planeacion__time-field">
							<span class="screen-reader-text"><?php esc_html_e( 'Fin jornada', 'logistica' ); ?></span>
							<input
								type="time"
								class="logistica-planeacion__time-input"
								value="<?php echo esc_attr( Logistica_Forming_Planning::minutes_to_time_input( $day_hours[ (string) $day['index'] ]['end'] ?? 1020 ) ); ?>"
								data-planeacion-day-end="<?php echo esc_attr( (string) $day['index'] ); ?>"
								aria-label="<?php echo esc_attr( sprintf( __( 'Fin jornada %s', 'logistica' ), $day['label'] ) ); ?>"
							>
						</label>
					</div>
					<button type="button" class="logistica-planeacion__day-add" data-action="planeacion-add-task-day" data-day="<?php echo esc_attr( (string) $day['index'] ); ?>" title="<?php esc_attr_e( 'Agregar actividad', 'logistica' ); ?>">+</button>
				</header>
				<div class="logistica-planeacion__day-body" data-planeacion-dropzone="<?php echo esc_attr( (string) $day['index'] ); ?>">
					<div class="logistica-planeacion__day-off" data-planeacion-day-off hidden>
						<span class="logistica-planeacion__day-off-icon dashicons dashicons-star-filled" aria-hidden="true"></span>
						<div class="logistica-planeacion__day-off-body">
							<strong data-planeacion-day-off-label><?php esc_html_e( 'Festivo', 'logistica' ); ?></strong>
							<p data-planeacion-day-off-desc><?php esc_html_e( 'Día no laborable. Sin actividades programadas.', 'logistica' ); ?></p>
						</div>
					</div>
					<div class="logistica-planeacion__timeline-scroll" data-planeacion-timeline-scroll hidden>
						<div class="logistica-planeacion__timeline" data-planeacion-timeline>
							<div class="logistica-planeacion__timeline-ruler" data-planeacion-timeline-ruler aria-hidden="true"></div>
							<div class="logistica-planeacion__timeline-track" data-planeacion-timeline-track></div>
						</div>
					</div>
					<p class="logistica-planeacion__empty" data-planeacion-empty hidden><?php esc_html_e( 'Sin actividades. Arrastra aquí o usa +.', 'logistica' ); ?></p>
				</div>
			</div>
		<?php endforeach; ?>
		<div class="logistica-planeacion__overflow-weeks" data-planeacion-overflow-weeks hidden></div>
	</div>
		</div>
	</div>
	<?php
	$planeacion_pedidos_module = 'formado';
	$planeacion_pedidos_days   = $days;
	require LOGISTICA_PLUGIN_DIR . 'admin/views/partials/planeacion-pedidos-picker.php';
	unset( $planeacion_pedidos_module, $planeacion_pedidos_days );
	?>
	<?php endif; ?>
</section>

<?php if ( $show_planeacion_board ) : ?>
<dialog class="logistica-planeacion__modal" data-planeacion-modal>
	<form method="dialog" class="logistica-planeacion__modal-form" data-planeacion-form>
		<header class="logistica-planeacion__modal-header">
			<h3 data-planeacion-modal-title><?php esc_html_e( 'Actividad', 'logistica' ); ?></h3>
			<button type="button" class="logistica-planeacion__modal-close" data-action="planeacion-close-modal" aria-label="<?php esc_attr_e( 'Cerrar', 'logistica' ); ?>">&times;</button>
		</header>
		<div class="logistica-planeacion__modal-body">
			<input type="hidden" data-planeacion-field="id">
			<div class="logistica-planeacion__form-grid">
				<label>
					<span><?php esc_html_e( 'OP', 'logistica' ); ?></span>
					<input type="text" data-planeacion-field="op" placeholder="<?php esc_attr_e( 'Ej. 8510 o SIN OP', 'logistica' ); ?>">
				</label>
				<label>
					<span><?php esc_html_e( 'Día', 'logistica' ); ?></span>
					<select data-planeacion-field="day">
						<?php foreach ( $days as $day ) : ?>
							<option value="<?php echo esc_attr( (string) $day['index'] ); ?>"><?php echo esc_html( $day['label'] ); ?></option>
						<?php endforeach; ?>
					</select>
				</label>
				<label>
					<span><?php esc_html_e( 'Estado', 'logistica' ); ?></span>
					<select data-planeacion-field="pedido_estado">
						<?php foreach ( $statuses as $key => $label ) : ?>
							<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $label ); ?></option>
						<?php endforeach; ?>
					</select>
				</label>
				<label class="logistica-planeacion__form-span-2">
					<span><?php esc_html_e( 'Tipo de labor', 'logistica' ); ?></span>
					<select data-planeacion-field="labor_type" data-planeacion-labor-type>
						<?php foreach ( $labor_types as $key => $label ) : ?>
							<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $label ); ?></option>
						<?php endforeach; ?>
					</select>
					<small class="logistica-planeacion__field-hint logistica-planeacion__labor-hint" data-planeacion-labor-hint hidden></small>
				</label>
				<label class="logistica-planeacion__form-span-2">
					<span><?php esc_html_e( 'Descripción', 'logistica' ); ?></span>
					<input type="text" data-planeacion-field="labor" placeholder="<?php esc_attr_e( 'Ej. Formado de tapas', 'logistica' ); ?>">
				</label>
				<div class="logistica-planeacion__form-span-2 logistica-planeacion__labor-section" data-planeacion-labor-section="tiraje">
				<label data-planeacion-labor-field="formado_referencia">
					<span><?php esc_html_e( 'Referencia', 'logistica' ); ?></span>
					<select data-planeacion-field="formado_referencia" data-planeacion-formado-referencia>
						<option value=""><?php esc_html_e( '— Seleccionar —', 'logistica' ); ?></option>
						<?php foreach ( Logistica_Forming_Yield::get_entries() as $yield_entry ) : ?>
							<option value="<?php echo esc_attr( $yield_entry['key'] ); ?>">
								<?php echo esc_html( $yield_entry['label'] ); ?>
							</option>
						<?php endforeach; ?>
					</select>
				</label>
				<label>
					<span><?php esc_html_e( 'Cantidad', 'logistica' ); ?></span>
					<input type="text" data-planeacion-field="tamanos" placeholder="<?php esc_attr_e( 'Ej. 2000 unidades', 'logistica' ); ?>">
					<small class="logistica-planeacion__field-hint" data-planeacion-formado-qty-hint><?php esc_html_e( 'Indique referencia y cantidad para calcular la duración.', 'logistica' ); ?></small>
				</label>
				<label>
					<span><?php esc_html_e( 'Complejidad', 'logistica' ); ?></span>
					<select data-planeacion-field="complexity">
						<?php foreach ( $complexities as $key => $label ) : ?>
							<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $label ); ?></option>
						<?php endforeach; ?>
					</select>
				</label>
				</div>
				<label>
					<span><?php esc_html_e( 'Duración (min)', 'logistica' ); ?></span>
					<input type="number" min="15" step="15" data-planeacion-field="duration_minutes" data-planeacion-duration-input>
					<small class="logistica-planeacion__field-hint" data-planeacion-duration-hint hidden></small>
				</label>
				<?php
				$check_fields = array(
					'montaje' => __( 'Montaje', 'logistica' ),
					'troquel' => __( 'Troquel', 'logistica' ),
					'pegado'  => __( 'Pegado', 'logistica' ),
					'meta'    => __( 'Cumplimiento de metas', 'logistica' ),
				);
				foreach ( $check_fields as $field_key => $field_label ) :
					?>
					<label data-planeacion-labor-field="<?php echo esc_attr( $field_key ); ?>">
						<span><?php echo esc_html( $field_label ); ?></span>
						<select data-planeacion-field="<?php echo esc_attr( $field_key ); ?>" data-planeacion-options-list="<?php echo esc_attr( $field_key ); ?>">
							<option value=""><?php esc_html_e( '—', 'logistica' ); ?></option>
						</select>
					</label>
				<?php endforeach; ?>
				<label>
					<span><?php esc_html_e( 'Inicio real', 'logistica' ); ?></span>
					<input type="time" class="logistica-planeacion__time-input" data-planeacion-field="actual_start">
				</label>
				<label>
					<span><?php esc_html_e( 'Fin real', 'logistica' ); ?></span>
					<input type="time" class="logistica-planeacion__time-input" data-planeacion-field="actual_end">
				</label>
				<label>
					<span><?php esc_html_e( 'Persona asignada', 'logistica' ); ?></span>
					<input type="text" data-planeacion-field="assigned_person" placeholder="<?php esc_attr_e( 'Operario responsable', 'logistica' ); ?>">
				</label>
				<label>
					<span><?php esc_html_e( 'Prioridad tablero', 'logistica' ); ?></span>
					<select data-planeacion-field="board_priority">
						<?php foreach ( Logistica_Production_Board::get_priorities() as $prio_key => $prio_label ) : ?>
							<option value="<?php echo esc_attr( $prio_key ); ?>"><?php echo esc_html( $prio_label ); ?></option>
						<?php endforeach; ?>
					</select>
				</label>
				<label class="logistica-planeacion__form-span-2">
					<span><?php esc_html_e( 'Novedad / alerta', 'logistica' ); ?></span>
					<select data-planeacion-field="board_alert">
						<?php foreach ( Logistica_Production_Board::get_alerts() as $alert_key => $alert_label ) : ?>
							<option value="<?php echo esc_attr( $alert_key ); ?>"><?php echo esc_html( $alert_label ); ?></option>
						<?php endforeach; ?>
					</select>
				</label>
				<label class="logistica-planeacion__form-span-2">
					<span><?php esc_html_e( 'Notas', 'logistica' ); ?></span>
					<textarea rows="2" data-planeacion-field="notes"></textarea>
				</label>
			</div>
		</div>
		<footer class="logistica-planeacion__modal-footer logistica-planeacion__modal-footer--task">
			<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--danger logistica-planeacion__btn--modal" data-action="planeacion-delete-task"><?php esc_html_e( 'Eliminar', 'logistica' ); ?></button>
			<div class="logistica-planeacion__modal-actions">
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary logistica-planeacion__btn--modal" data-action="planeacion-close-modal"><?php esc_html_e( 'Cancelar', 'logistica' ); ?></button>
				<button type="submit" class="logistica-planeacion__btn logistica-planeacion__btn--primary logistica-planeacion__btn--modal"><?php esc_html_e( 'Guardar actividad', 'logistica' ); ?></button>
			</div>
		</footer>
	</form>
</dialog>

<dialog class="logistica-planeacion__modal logistica-planeacion__machine-modal" data-planeacion-machine-modal>
	<form class="logistica-planeacion__modal-form" data-planeacion-machine-form>
		<header class="logistica-planeacion__modal-header">
			<h3 data-planeacion-machine-modal-title><?php esc_html_e( 'Nueva máquina', 'logistica' ); ?></h3>
			<button type="button" class="logistica-planeacion__modal-close" data-action="planeacion-close-machine-modal" aria-label="<?php esc_attr_e( 'Cerrar', 'logistica' ); ?>">&times;</button>
		</header>
		<div class="logistica-planeacion__modal-body">
			<input type="hidden" data-planeacion-machine-slug value="">
			<p class="logistica-planeacion__field-hint" data-planeacion-machine-modal-hint><?php esc_html_e( 'Cada máquina tiene programación semanal independiente (tareas, horarios y jornadas propias).', 'logistica' ); ?></p>
			<label class="logistica-planeacion__form-span-2">
				<span><?php esc_html_e( 'Nombre de la máquina', 'logistica' ); ?></span>
				<input type="text" data-planeacion-machine-name placeholder="<?php esc_attr_e( 'Ej. Heidelberg XL', 'logistica' ); ?>" required>
			</label>
		</div>
		<footer class="logistica-planeacion__modal-footer logistica-planeacion__modal-footer--task">
			<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--danger logistica-planeacion__btn--modal" data-action="planeacion-delete-machine" hidden><?php esc_html_e( 'Eliminar máquina', 'logistica' ); ?></button>
			<div class="logistica-planeacion__modal-actions">
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary logistica-planeacion__btn--modal" data-action="planeacion-close-machine-modal"><?php esc_html_e( 'Cancelar', 'logistica' ); ?></button>
				<button type="submit" class="logistica-planeacion__btn logistica-planeacion__btn--primary logistica-planeacion__btn--modal" data-planeacion-machine-submit><?php esc_html_e( 'Crear máquina', 'logistica' ); ?></button>
			</div>
		</footer>
	</form>
</dialog>
<?php endif; ?>

<?php if ( ! $show_planeacion_board ) : ?>
<dialog class="logistica-planeacion__modal logistica-planeacion__options-modal" data-planeacion-options-modal>
	<form class="logistica-planeacion__modal-form" data-planeacion-options-form>
		<header class="logistica-planeacion__modal-header">
			<h3><?php esc_html_e( 'Listas desplegables', 'logistica' ); ?></h3>
			<button type="button" class="logistica-planeacion__modal-close" data-action="planeacion-close-options-modal" aria-label="<?php esc_attr_e( 'Cerrar', 'logistica' ); ?>">&times;</button>
		</header>
		<div class="logistica-planeacion__modal-body">
			<p class="logistica-planeacion__field-hint"><?php esc_html_e( 'Escribe una opción por línea. Estas listas alimentan los campos Montaje, Troquel, Pegado y Cumplimiento de metas.', 'logistica' ); ?></p>
			<div class="logistica-planeacion__options-grid">
				<label>
					<span><?php esc_html_e( 'Montaje', 'logistica' ); ?></span>
					<textarea rows="5" data-planeacion-options-field="montaje" placeholder="<?php esc_attr_e( "OK\nBUSCAR", 'logistica' ); ?>"></textarea>
				</label>
				<label>
					<span><?php esc_html_e( 'Troquel', 'logistica' ); ?></span>
					<textarea rows="5" data-planeacion-options-field="troquel" placeholder="<?php esc_attr_e( "OK\nTROQUEL PEDIDO", 'logistica' ); ?>"></textarea>
				</label>
				<label>
					<span><?php esc_html_e( 'Pegado', 'logistica' ); ?></span>
					<textarea rows="5" data-planeacion-options-field="pegado"></textarea>
				</label>
				<label>
					<span><?php esc_html_e( 'Cumplimiento de metas', 'logistica' ); ?></span>
					<textarea rows="5" data-planeacion-options-field="meta"></textarea>
				</label>
			</div>
		</div>
		<footer class="logistica-planeacion__modal-footer">
			<div class="logistica-planeacion__modal-actions logistica-planeacion__modal-actions--end">
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary logistica-planeacion__btn--modal" data-action="planeacion-close-options-modal"><?php esc_html_e( 'Cancelar', 'logistica' ); ?></button>
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--primary logistica-planeacion__btn--modal" data-action="planeacion-save-field-options"><?php esc_html_e( 'Guardar listas', 'logistica' ); ?></button>
			</div>
		</footer>
	</form>
</dialog>

<dialog class="logistica-planeacion__modal logistica-planeacion__forming-yield-modal" data-planeacion-forming-yield-modal>
	<form class="logistica-planeacion__modal-form" data-planeacion-forming-yield-form>
		<header class="logistica-planeacion__modal-header">
			<h3><?php esc_html_e( 'Rendimiento por referencia (formado)', 'logistica' ); ?></h3>
			<button type="button" class="logistica-planeacion__modal-close" data-action="planeacion-close-forming-yield-modal" aria-label="<?php esc_attr_e( 'Cerrar', 'logistica' ); ?>">&times;</button>
		</header>
		<div class="logistica-planeacion__modal-body">
			<p class="logistica-planeacion__field-hint"><?php esc_html_e( 'Rendimiento en unidades por hora (und/h). Se usa para calcular la duración al programar actividades de formado.', 'logistica' ); ?></p>
			<p class="logistica-planeacion__forming-yield-status" data-planeacion-forming-yield-status role="status" aria-live="polite"></p>
			<div class="logistica-planeacion__forming-yield-table-wrap">
				<table class="logistica-planeacion__forming-yield-table">
					<thead>
						<tr>
							<th><?php esc_html_e( 'Referencia', 'logistica' ); ?></th>
							<th><?php esc_html_e( 'Rendimiento (und/h)', 'logistica' ); ?></th>
							<th><span class="screen-reader-text"><?php esc_html_e( 'Acciones', 'logistica' ); ?></span></th>
						</tr>
					</thead>
					<tbody data-planeacion-forming-yield-rows></tbody>
				</table>
			</div>
			<div class="logistica-planeacion__forming-yield-add">
				<h4><?php esc_html_e( 'Agregar referencia', 'logistica' ); ?></h4>
				<div class="logistica-planeacion__forming-yield-add-grid">
					<label>
						<span><?php esc_html_e( 'Referencia', 'logistica' ); ?></span>
						<input type="text" data-planeacion-forming-yield-add-label placeholder="<?php esc_attr_e( 'Ej. Vaso 20 oz', 'logistica' ); ?>">
					</label>
					<label>
						<span><?php esc_html_e( 'Rendimiento (und/h)', 'logistica' ); ?></span>
						<input type="number" min="1" step="1" data-planeacion-forming-yield-add-units placeholder="<?php esc_attr_e( 'Ej. 2000', 'logistica' ); ?>">
					</label>
					<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary" data-action="planeacion-forming-yield-add-row"><?php esc_html_e( 'Agregar', 'logistica' ); ?></button>
				</div>
			</div>
		</div>
		<footer class="logistica-planeacion__modal-footer">
			<div class="logistica-planeacion__modal-actions logistica-planeacion__modal-actions--end">
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--secondary logistica-planeacion__btn--modal" data-action="planeacion-close-forming-yield-modal"><?php esc_html_e( 'Cancelar', 'logistica' ); ?></button>
				<button type="button" class="logistica-planeacion__btn logistica-planeacion__btn--primary logistica-planeacion__btn--modal" data-action="planeacion-save-forming-yield"><?php esc_html_e( 'Guardar rendimiento', 'logistica' ); ?></button>
			</div>
		</footer>
	</form>
</dialog>
<?php endif; ?>

<script type="application/json" id="logistica-planeacion-formado-bootstrap">
<?php
echo wp_json_encode(
	array(
		'semana_inicio' => $week_start,
		'today_ymd'     => wp_date( 'Y-m-d', null, new DateTimeZone( Logistica_User_Panel::PANEL_TIMEZONE ) ),
		'timezone'      => Logistica_User_Panel::PANEL_TIMEZONE,
		'machines'             => $machines,
		'default_machine'      => Logistica_Forming_Planning::default_machine_slug(),
		'custom_machine_slugs' => array_keys( Logistica_Forming_Planning::get_custom_machines() ),
		'days'          => $days,
		'statuses'      => $statuses,
		'tamanos_base'  => Logistica_Forming_Planning::TAMANOS_BASE,
		'minutes_base'  => Logistica_Forming_Planning::MINUTES_BASE,
		'complexities'   => $complexities,
		'labor_types'    => $labor_types,
		'labor_defaults' => Logistica_Forming_Planning::LABOR_DEFAULT_MINUTES,
		'labor_field_rules' => Logistica_Forming_Planning::labor_field_rules(),
		'papel_materials' => $papel_materials,
		'field_options'   => $field_options,
		'forming_yield'   => Logistica_Forming_Yield::get_entries(),
		'day_hours'      => $day_hours,
		'day_types'      => $day_types,
		'holiday_settings' => Logistica_Settings::get_panel_holidays_client_config(),
		'festivo_dates'  => Logistica_Settings::get_festivo_dates_map( $panel_year - 1, $panel_year + 2 ),
	),
	JSON_UNESCAPED_UNICODE
);
?>
</script>
<?php logistica_admin_footer(); ?>
