<?php
/**
 * File Path: templates/admin/author-photo-field.php
 *
 * Admin Template — Author Photo Picker Field
 *
 * Renders the photo preview image, hidden attachment-ID input, and the
 * Add Photo / Change / Remove button pair for a single author card.
 *
 * JavaScript (admin-authors-photo.js) manages the visible state:
 * it toggles the `hidden` attribute on the preview and Remove button and
 * swaps the Change button's label between "Add Photo" and "Change".
 *
 * Expected variables (passed via mbs_get_template_part() $args):
 *   int    $term_id    Author term ID.
 *   int    $photo_id   Current attachment ID (0 if none).
 *   string $photo_url  Current photo URL (empty string if none).
 *   string $preview_id DOM id for the preview <img>.
 *   string $input_id   DOM id for the hidden attachment-ID <input>.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div class="mbs-settings-field-cell mbs-author-field-photo">
	<label><?php esc_html_e( 'Photo', 'my-book-showroom' ); ?></label>
	<div class="mbs-author-photo-wrap">
		<img id="<?php echo esc_attr( $preview_id ); ?>"
		     class="mbs-author-photo-img"
		     src="<?php echo esc_url( $photo_url ); ?>"
		     alt=""
		     <?php echo $photo_url ? '' : 'hidden'; ?>>
		<input type="hidden"
		       id="<?php echo esc_attr( $input_id ); ?>"
		       name="mbs_author_photo_id[<?php echo esc_attr( $term_id ); ?>]"
		       value="<?php echo esc_attr( $photo_id ); ?>">
		<div class="mbs-author-photo-controls">
			<button type="button"
			        class="button mbs-author-photo-select"
			        data-term-id="<?php echo esc_attr( $term_id ); ?>"
			        data-preview="<?php echo esc_attr( $preview_id ); ?>"
			        data-input="<?php echo esc_attr( $input_id ); ?>">
				<?php echo $photo_url
					? esc_html__( 'Change', 'my-book-showroom' )
					: esc_html__( 'Add Photo', 'my-book-showroom' ); ?>
			</button>
			<button type="button"
			        class="button mbs-author-photo-remove"
			        data-term-id="<?php echo esc_attr( $term_id ); ?>"
			        data-preview="<?php echo esc_attr( $preview_id ); ?>"
			        data-input="<?php echo esc_attr( $input_id ); ?>"
			        <?php echo $photo_url ? '' : 'hidden'; ?>>
				<?php esc_html_e( 'Remove', 'my-book-showroom' ); ?>
			</button>
		</div>
	</div>
</div>
