<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use AIAltTextGenerator\Capabilities;
use AIAltTextGenerator\QualityScorer;
use AIAltTextGenerator\Settings;
?>
<div class="wpps-ai-alt-panel">
	<?php if ( ! $supported ) : ?>
		<p class="description"><?php esc_html_e( 'AI alt text is available for JPEG, PNG, GIF, WebP, AVIF, BMP, TIFF, and SVG images (max 20MB).', 'wp-powersuite' ); ?></p>
		<?php return; ?>
	<?php endif; ?>

	<?php if ( ! empty( $status ) ) : ?>
		<p class="description">
			<?php
			printf(
				/* translators: %s: status label */
				esc_html__( 'Status: %s', 'wp-powersuite' ),
				esc_html( QualityScorer::label( (string) $status ) )
			);
			?>
		</p>
	<?php endif; ?>

	<p>
		<label for="wpps-ai-alt-field" class="screen-reader-text"><?php esc_html_e( 'Alt text', 'wp-powersuite' ); ?></label>
		<textarea id="wpps-ai-alt-field" class="widefat" rows="3" placeholder="<?php esc_attr_e( 'Describe the image for accessibility...', 'wp-powersuite' ); ?>"><?php echo esc_textarea( $suggestion !== '' ? $suggestion : $current_alt ); ?></textarea>
	</p>
	<p class="description"><?php esc_html_e( 'Generate a suggestion, review it, then save. AI suggestions are not saved automatically unless auto-approve is enabled in settings.', 'wp-powersuite' ); ?></p>
	<?php if ( Capabilities::canGenerate() && Settings::hasApiKey() ) : ?>
	<p>
		<button type="button" class="button" id="wpps-ai-alt-generate" data-attachment-id="<?php echo esc_attr( (string) $post->ID ); ?>" data-regenerate="<?php echo $has_generated ? '1' : '0'; ?>">
			<?php
			echo $has_generated
				? esc_html__( 'Regenerate with AI', 'wp-powersuite' )
				: esc_html__( 'Generate with AI', 'wp-powersuite' );
			?>
		</button>
		<button type="button" class="button button-primary" id="wpps-ai-alt-save" data-attachment-id="<?php echo esc_attr( (string) $post->ID ); ?>">
			<?php esc_html_e( 'Save Alt Text', 'wp-powersuite' ); ?>
		</button>
	</p>
	<p class="wpps-ai-alt-decorative-actions">
		<button type="button" class="button-link" id="wpps-ai-alt-decorative" data-attachment-id="<?php echo esc_attr( (string) $post->ID ); ?>"<?php echo $is_decorative ? ' hidden' : ''; ?>>
			<?php esc_html_e( 'Mark as decorative', 'wp-powersuite' ); ?>
		</button>
		<button type="button" class="button-link" id="wpps-ai-alt-undecorative" data-attachment-id="<?php echo esc_attr( (string) $post->ID ); ?>"<?php echo $is_decorative ? '' : ' hidden'; ?>>
			<?php esc_html_e( 'Unmark as decorative', 'wp-powersuite' ); ?>
		</button>
	</p>
	<p class="description wpps-ai-alt-decorative-note"<?php echo $is_decorative ? '' : ' hidden'; ?>><?php esc_html_e( 'This image is decorative and skips AI alt text generation. Unmark it if the image conveys meaningful content.', 'wp-powersuite' ); ?></p>
	<?php elseif ( Capabilities::canGenerate() ) : ?>
		<p class="description"><?php esc_html_e( 'Configure an API key in AI Alt Text settings to generate suggestions with AI.', 'wp-powersuite' ); ?></p>
	<?php else : ?>
		<p class="description"><?php esc_html_e( 'You do not have permission to generate alt text for this image.', 'wp-powersuite' ); ?></p>
	<?php endif; ?>
	<div id="wpps-ai-alt-result" class="wpps-ai-alt-result" style="display:none;"></div>
</div>
