<?php
/**
 * CPT Builder - Labels tab.
 *
 * @package CptBuilder
 *
 * @var array<string, mixed> $definition
 */

namespace CptBuilder;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<h2><?php esc_html_e( 'Labels', 'wppowersuite-lite' ); ?></h2>
<p class="description"><?php esc_html_e( 'All labels are generated automatically from your singular and plural labels — the generated text is shown as a placeholder. Type in a field only when you want to override it.', 'wppowersuite-lite' ); ?></p>

<table class="form-table" role="presentation">
	<tbody>
		<?php
		$cptb_singular  = cptb_label( $definition, 'singular_name' );
		$cptb_plural    = cptb_label( $definition, 'name' );
		$cptb_templates = Config::labelTemplates();

		foreach ( Config::labelFields() as $label_key => $meta ) :
			$template    = $cptb_templates[ $label_key ] ?? null;
			$placeholder = $template !== null ? Config::generateLabel( $template, $cptb_singular, $cptb_plural ) : '';
			$extra_attrs = '';
			if ( $template !== null ) {
				$extra_attrs = sprintf(
					'data-cptb-template="%s" data-cptb-source="%s" data-cptb-transform="%s"',
					esc_attr( $template['template'] ),
					esc_attr( $template['source'] ),
					esc_attr( $template['transform'] ?? '' )
				);
			}
			cptb_text_row( 'labels[' . $label_key . ']', $meta['label'], cptb_label( $definition, $label_key ), $meta['help'], $placeholder, $extra_attrs );
		endforeach;
		?>
	</tbody>
</table>
