<?php
/**
 * Partial — Settings / Language tab.
 *
 * @package Contentosapp_Studio
 * @since   3.2.0
 */

defined( 'ABSPATH' ) || exit;
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- Included admin settings template; local presentation variables are scoped to this partial.

$_lang_val         = Costudio_Admin::get_default_language();
$_content_lang_val = Costudio_Admin::get_default_content_language();

$_lang_meta = array(
	'en_US' => array( 'name' => __( 'English (US)', 'contentosapp-studio' ),       'flag' => 'en_US.svg' ),
	'es_ES' => array( 'name' => __( 'Español (España)', 'contentosapp-studio' ),   'flag' => 'es_ES.svg' ),
	'pt_BR' => array( 'name' => __( 'Português (Brasil)', 'contentosapp-studio' ), 'flag' => 'pt_BR.svg' ),
);
if ( ! isset( $_lang_meta[ $_lang_val ] ) ) {
	$_lang_val = 'en_US';
}
if ( ! isset( $_lang_meta[ $_content_lang_val ] ) ) {
	$_content_lang_val = 'en_US';
}
$_flag_base = COSTUDIO_URL . 'assets/images/flags/';
?>
<div id="fos-tab-language" class="fos-tab-panel">
	<form id="fos-settings-lang-form" class="fos-settings-form">

		<p class="fos-int-zone-label"><?php esc_html_e( 'Regional Settings', 'contentosapp-studio' ); ?></p>

		<!-- UI Language -->
		<div class="fos-int-card">
			<div class="fos-int-card__header">
				<div class="fos-int-card__left">
					<span class="fos-int-card__icon">🖥️</span>
					<div>
						<p class="fos-int-card__title"><?php esc_html_e( 'Interface Language', 'contentosapp-studio' ); ?></p>
						<p class="fos-int-card__subtitle"><?php esc_html_e( 'Set the language for the Contentosapp Studio dashboard and menus.', 'contentosapp-studio' ); ?></p>
					</div>
				</div>
			</div>
			<div class="fos-int-card__body">
				<div class="fos-lang-row">
					<div class="fos-int-field">
						<label for="fos-default-language"><?php esc_html_e( 'UI Language', 'contentosapp-studio' ); ?></label>
						<select name="default_language" id="fos-default-language" class="cts-lang-select fos-int-select" data-preview="fos-lang-preview-ui">
							<?php foreach ( $_lang_meta as $code => $meta ) : ?>
								<option value="<?php echo esc_attr( $code ); ?>" <?php selected( $_lang_val, $code ); ?>><?php echo esc_html( $meta['name'] ); ?></option>
							<?php endforeach; ?>
						</select>
					</div>
					<div class="fos-lang-preview-col">
						<div class="cts-lang-preview" id="fos-lang-preview-ui">
							<img class="cts-lang-flag" src="<?php echo esc_url( $_flag_base . $_lang_meta[ $_lang_val ]['flag'] ); ?>" alt="" width="20" height="14">
							<span class="cts-lang-preview__name"><?php echo esc_html( $_lang_meta[ $_lang_val ]['name'] ); ?></span>
						</div>
					</div>
				</div>
			</div>
		</div>

		<p class="fos-int-zone-label"><?php esc_html_e( 'AI Content Settings', 'contentosapp-studio' ); ?></p>

		<!-- Content Language -->
		<div class="fos-int-card">
			<div class="fos-int-card__header">
				<div class="fos-int-card__left">
					<span class="fos-int-card__icon">🤖</span>
					<div>
						<p class="fos-int-card__title"><?php esc_html_e( 'Content Language (AI Output)', 'contentosapp-studio' ); ?></p>
						<p class="fos-int-card__subtitle"><?php esc_html_e( 'This defines the language in which articles are written and which default agent prompts are used.', 'contentosapp-studio' ); ?></p>
					</div>
				</div>
			</div>
			<div class="fos-int-card__body">
				<div class="fos-lang-row">
					<div class="fos-int-field">
						<label for="fos-default-content-language"><?php esc_html_e( 'Output Language', 'contentosapp-studio' ); ?></label>
						<select name="default_content_language" id="fos-default-content-language" class="cts-lang-select fos-int-select" data-preview="fos-lang-preview-content">
							<?php foreach ( $_lang_meta as $code => $meta ) : ?>
								<option value="<?php echo esc_attr( $code ); ?>" <?php selected( $_content_lang_val, $code ); ?>><?php echo esc_html( $meta['name'] ); ?></option>
							<?php endforeach; ?>
						</select>
					</div>
					<div class="fos-lang-preview-col">
						<div class="cts-lang-preview" id="fos-lang-preview-content">
							<img class="cts-lang-flag" src="<?php echo esc_url( $_flag_base . $_lang_meta[ $_content_lang_val ]['flag'] ); ?>" alt="" width="20" height="14">
							<span class="cts-lang-preview__name"><?php echo esc_html( $_lang_meta[ $_content_lang_val ]['name'] ); ?></span>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="fos-settings-save-bar">
			<span class="fos-settings-save-bar__hint">💾 <?php esc_html_e( 'Content language affects all AI generations.', 'contentosapp-studio' ); ?></span>
			<div class="fos-settings-save-bar__actions">
				<span class="fos-settings-save-bar__msg" id="fos-settings-lang-msg"></span>
				<button type="submit" class="cts-btn cts-btn--primary"><?php esc_html_e( 'Save Language Settings', 'contentosapp-studio' ); ?></button>
			</div>
		</div>

	</form>
</div><!-- #fos-tab-language -->
