<?php
/**
 * Partial — Production detail, PENDING fallback (production exists but hasn't started yet).
 *
 * @package Contentosapp_Studio
 * @since   3.2.0
 */

defined( 'ABSPATH' ) || exit;
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- Included detail-state template; local presentation variables are scoped to this partial.

$queue_position = isset( $queue_position ) ? (int) $queue_position : 0;
$queue_total    = isset( $queue_total ) ? (int) $queue_total : 0;
$pending_agent  = max( 1, (int) ( $production->current_agent ?? 1 ) );
$pending_agent_name = isset( $agent_defs[ $pending_agent ]['name'] )
	? $agent_defs[ $pending_agent ]['name']
	/* translators: %02d: agent number (zero-padded, e.g. 01) */
	: sprintf(
		/* translators: %02d: two-digit agent number. */
		__( 'Agent %02d', 'contentosapp-studio' ),
		$pending_agent
	);
?>
<div class="fos-pipeline-body fos-pending-body">
	<div class="fos-pipeline-body__header fos-pending-body__header">
		<div>
			<div class="fos-pending-body__eyebrow"><?php esc_html_e( 'Production queued', 'contentosapp-studio' ); ?></div>
			<div class="fos-pending-body__title"><?php esc_html_e( 'Aguardando slot local para iniciar', 'contentosapp-studio' ); ?></div>
		</div>
		<span class="cts-badge cts-badge--neutral"><?php echo (int) $agent_qty; ?> <?php esc_html_e( 'stages', 'contentosapp-studio' ); ?></span>
	</div>

	<div class="fos-pending-body__content">
		<div class="fos-detalhe-progress">
			<div class="fos-detalhe-progress__top">
				<div>
					<div class="fos-detalhe-progress__status">
						<?php esc_html_e( 'Na fila de produção', 'contentosapp-studio' ); ?>
					</div>
					<div class="fos-detalhe-progress__agent fos-pending-queue-subtitle">
						<?php
						if ( $queue_position > 0 ) {
							printf(
								/* translators: 1: queue position, 2: total queued productions */
								esc_html__( 'Waiting for the local slot. Position %1$d of %2$d in the queue.', 'contentosapp-studio' ),
								(int) $queue_position,
								(int) max( $queue_position, $queue_total )
							);
						} else {
							esc_html_e( 'The production will start shortly.', 'contentosapp-studio' );
						}
						?>
					</div>
				</div>
				<div class="fos-detalhe-progress__right">
					<div class="fos-detalhe-progress__pct"><?php echo esc_html( $queue_position > 0 ? '#' . $queue_position : __( 'Fila', 'contentosapp-studio' ) ); ?></div>
					<div class="fos-detalhe-progress__pct-label">
						<?php esc_html_e( 'posição atual', 'contentosapp-studio' ); ?>
					</div>
				</div>
			</div>
			<div class="fos-detalhe-bar-wrap">
				<div class="fos-detalhe-bar-fill" style="width: 100%"></div>
			</div>
			<div class="fos-detalhe-dots" aria-hidden="true">
				<?php for ( $i = 1; $i <= $agent_qty; $i++ ) : ?>
					<div class="fos-detalhe-dot fos-detalhe-dot--pending"></div>
				<?php endfor; ?>
			</div>
		</div>

		<div class="fos-pending-queue-note">
			<div class="fos-pending-queue-note__icon">⏳</div>
			<div>
				<div class="fos-pending-queue-note__title"><?php esc_html_e( 'Local queue protection is active.', 'contentosapp-studio' ); ?></div>
				<div class="fos-pending-queue-note__text">
					<?php esc_html_e( 'Contentosapp Studio will start this production automatically as soon as the current local runner finishes or frees the slot.', 'contentosapp-studio' ); ?>
				</div>
			</div>
		</div>

		<div class="fos-pipeline-grid-mini fos-pending-queue-grid">
			<div class="fos-pipeline-mini-stat">
				<div class="fos-pipeline-mini-stat__label"><?php esc_html_e( 'QUEUE POSITION', 'contentosapp-studio' ); ?></div>
				<div class="fos-pipeline-mini-stat__value fos-pending-queue-position">
					<?php echo esc_html( $queue_position > 0 ? '#' . $queue_position : __( 'Waiting', 'contentosapp-studio' ) ); ?>
				</div>
			</div>
			<div class="fos-pipeline-mini-stat">
				<div class="fos-pipeline-mini-stat__label"><?php esc_html_e( 'WAITING', 'contentosapp-studio' ); ?></div>
				<div class="fos-pipeline-mini-stat__value fos-pending-queue-total">
					<?php echo esc_html( (string) $queue_total ); ?>
				</div>
			</div>
			<div class="fos-pipeline-mini-stat">
				<div class="fos-pipeline-mini-stat__label"><?php esc_html_e( 'FIRST STEP', 'contentosapp-studio' ); ?></div>
				<div class="fos-pipeline-mini-stat__value"><?php echo esc_html( $pending_agent_name ); ?></div>
			</div>
			<div class="fos-pipeline-mini-stat">
				<div class="fos-pipeline-mini-stat__label"><?php esc_html_e( 'START MODE', 'contentosapp-studio' ); ?></div>
				<div class="fos-pipeline-mini-stat__value"><?php esc_html_e( 'Automatic', 'contentosapp-studio' ); ?></div>
			</div>
		</div>
	</div>
</div>
