<?php
/**
 * CPT Builder - Taxonomy Basic tab.
 *
 * @package CptBuilder
 *
 * @var array<string, mixed> $definition
 * @var bool                 $is_edit
 * @var string               $key
 */

namespace CptBuilder;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<h2><?php esc_html_e( 'Basic settings', 'wp-powersuite' ); ?></h2>
<p class="description"><?php esc_html_e( 'The key and labels are the foundation of your taxonomy. The key cannot be changed after creation.', 'wp-powersuite' ); ?></p>

<table class="form-table" role="presentation">
	<tbody>
		<tr>
			<th scope="row"><label for="cptb-key"><?php esc_html_e( 'Taxonomy key', 'wp-powersuite' ); ?> <span class="cptb-req">*</span></label></th>
			<td>
				<?php if ( $is_edit ) : ?>
					<code class="cptb-key-readonly"><?php echo esc_html( $key ); ?></code>
					<p class="description"><?php esc_html_e( 'The key is locked after creation to keep stored terms reachable.', 'wp-powersuite' ); ?></p>
				<?php else : ?>
					<input type="text" id="cptb-key" name="key" value="<?php echo esc_attr( $key ); ?>" class="regular-text" maxlength="<?php echo esc_attr( (string) Config::MAX_TAXONOMY_KEY_LENGTH ); ?>" pattern="[a-z][a-z0-9_]*" required>
					<p class="description">
						<?php
						printf(
							/* translators: %d: maximum characters. */
							esc_html__( 'Lowercase letters, numbers, and underscores only. Must start with a letter. Maximum %d characters.', 'wp-powersuite' ),
							(int) Config::MAX_TAXONOMY_KEY_LENGTH
						);
						?>
					</p>
				<?php endif; ?>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="cptb-singular"><?php esc_html_e( 'Singular label', 'wp-powersuite' ); ?> <span class="cptb-req">*</span></label></th>
			<td>
				<input type="text" id="cptb-singular" name="labels[singular_name]" value="<?php echo esc_attr( cptb_label( $definition, 'singular_name' ) ); ?>" class="regular-text" placeholder="<?php esc_attr_e( 'e.g. Genre', 'wp-powersuite' ); ?>" required>
				<p class="description"><?php esc_html_e( 'Name for one term.', 'wp-powersuite' ); ?></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="cptb-plural"><?php esc_html_e( 'Plural label', 'wp-powersuite' ); ?> <span class="cptb-req">*</span></label></th>
			<td>
				<input type="text" id="cptb-plural" name="labels[name]" value="<?php echo esc_attr( cptb_label( $definition, 'name' ) ); ?>" class="regular-text" placeholder="<?php esc_attr_e( 'e.g. Genres', 'wp-powersuite' ); ?>" required<?php echo $is_edit ? '' : ' data-cptb-autoslug="cptb-key"'; ?>>
				<p class="description"><?php esc_html_e( 'Name for multiple terms. Used to suggest the key and other labels.', 'wp-powersuite' ); ?></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php esc_html_e( 'Hierarchical', 'wp-powersuite' ); ?></th>
			<td>
				<label class="cptb-toggle" for="cptb-args-hierarchical">
					<input type="checkbox" id="cptb-args-hierarchical" name="args[hierarchical]" value="1" <?php checked( (bool) cptb_tax_arg( $definition, 'hierarchical' ) ); ?>>
					<span><?php esc_html_e( 'Behaves like categories (parent/child terms). Leave off for tag-like behavior.', 'wp-powersuite' ); ?></span>
				</label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="cptb-description"><?php esc_html_e( 'Description', 'wp-powersuite' ); ?></label></th>
			<td>
				<textarea id="cptb-description" name="args[description]" class="large-text" rows="2"><?php echo esc_textarea( (string) cptb_tax_arg( $definition, 'description' ) ); ?></textarea>
				<p class="description"><?php esc_html_e( 'A short description of the taxonomy. Shown in some themes and the REST API.', 'wp-powersuite' ); ?></p>
			</td>
		</tr>
		<?php if ( ! $is_edit && class_exists( '\CustomFields\CptBridge' ) && \CustomFields\CptBridge::isCustomFieldsEnabled() ) : ?>
		<tr>
			<th scope="row"><?php esc_html_e( 'Field group', 'wp-powersuite' ); ?></th>
			<td>
				<label>
					<input type="checkbox" name="create_default_field_group" value="1" checked>
					<?php esc_html_e( 'Create a default Custom Fields group for this taxonomy', 'wp-powersuite' ); ?>
				</label>
				<p class="description"><?php esc_html_e( 'Adds a starter term field group with a Description field on add/edit term screens.', 'wp-powersuite' ); ?></p>
			</td>
		</tr>
		<?php endif; ?>
	</tbody>
</table>
