<?php
/**
 * AI Alt Text admin view helpers.
 *
 * @package AIAltTextGenerator
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Render accordion help tooltip.
 */
function wpps_ai_alt_tip( string $text ): void {
	echo '<span class="wpps-ai-alt-accordion-tooltip" aria-label="' . esc_attr__( 'Help', 'wppowersuite-lite' ) . '">';
	echo '<span class="wpps-ai-alt-accordion-tooltip-trigger">?</span>';
	echo '<span class="wpps-ai-alt-accordion-tooltip-panel">' . esc_html( $text ) . '</span>';
	echo '</span>';
}

/**
 * Render accordion section opener.
 *
 * @param array{id: string, title: string, tip?: string, open?: bool} $args
 */
function wpps_ai_alt_accordion_open( array $args ): void {
	$id    = sanitize_key( (string) ( $args['id'] ?? '' ) );
	$title = (string) ( $args['title'] ?? '' );
	$open  = ! empty( $args['open'] );
	$tip   = (string) ( $args['tip'] ?? '' );

	if ( $id === '' || $title === '' ) {
		return;
	}
	?>
	<div class="wpps-ai-alt-accordion<?php echo $open ? ' is-open' : ''; ?>" data-accordion-id="<?php echo esc_attr( $id ); ?>">
		<button type="button" class="wpps-ai-alt-accordion-header" aria-expanded="<?php echo $open ? 'true' : 'false'; ?>" aria-controls="wpps-ai-alt-accordion-<?php echo esc_attr( $id ); ?>">
			<span class="wpps-ai-alt-accordion-title">
				<?php echo esc_html( $title ); ?>
				<?php if ( $tip !== '' ) : ?>
					<?php wpps_ai_alt_tip( $tip ); ?>
				<?php endif; ?>
			</span>
			<span class="dashicons dashicons-arrow-down-alt2 wpps-ai-alt-accordion-chevron"></span>
		</button>
		<div id="wpps-ai-alt-accordion-<?php echo esc_attr( $id ); ?>" class="wpps-ai-alt-accordion-body">
	<?php
}

function wpps_ai_alt_accordion_close(): void {
	echo '</div></div>';
}
