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

<?php

$checked = polylai_fs()->can_use_premium_code__premium_only() ? "checked" : "";
$allowed = implode(",", polylai_Utils::allowed_langs());

?>

<div data-nonce="<?php echo wp_create_nonce('polylai_polylai_run_cron'); ?>" data-allowed="<?php echo $allowed; ?>">
	<div class='polylaitr-panel polylaitr-panel-wide'>
		<span data-close class="polylaitr-close dashicons dashicons-no"></span>
		<h2><?php _e('PolylAI Translator', 'ai-translator-for-polylang'); ?></h2>

		<div id='polylaitr-content'>
<?php if (!(is_plugin_active('polylang/polylang.php') || is_plugin_active('polylang-pro/polylang.php'))): ?>

	<div class="">
		<h4 class="tw-text-[24px] tw-text-amber-500">
			<?php _e('Polylang not installed or not activated', 'ai-translator-for-polylang'); ?>
		</h4>
		<p><?php _e('PolylAI Translator <strong>requires Polylang</strong> plugin.', 'ai-translator-for-polylang'); ?>
		</p>
		<p><?php _e('How to fix it: go to the plugins page and install "Polylang", activate it, add the languages you need on your site and then come back here for automating your translations.', 'ai-translator-for-polylang'); ?>
		</p>
	</div>

<?php else: ?>

			<p><?php _e('Translate from <strong></strong>', 'ai-translator-for-polylang'); ?></p>
			<p data-wait><i><?php _e('Loading languages...', 'ai-translator-for-polylang'); ?></i></p>
			<div class="tw-max-h-[100px] tw-scroll-auto tw-overflow-auto">
				<ul id="polylaitr-langs" class="tw-grid tw-grid-cols-3">
				</ul>
			</div>

			<div class="tw-flex tw-gap-2 tw-items-center tw-mb-2">
				<p><?php _e('Status of the translated posts:', 'ai-translator-for-polylang'); ?></p>
				<select name="post_status" data-polylai-status>
					<option value="publish"><?php _e('Published', 'ai-translator-for-polylang'); ?></option>
					<option value="pending"><?php _e('Pending Review', 'ai-translator-for-polylang'); ?></option>
					<option value="draft" selected><?php _e('Draft', 'ai-translator-for-polylang'); ?></option>
					<option value="private"><?php _e('Private', 'ai-translator-for-polylang'); ?></option>
				</select>
			</div>
	
			<p class="tw-text-center tw-font-bold tw-text-[14px]"><?php _e('Choose the translation provider:', 'ai-translator-for-polylang'); ?></p>
			<div class='tw-grid tw-grid-cols-2 tw-gap-1'>
				<div data-polylai-svc='cloud' class='polylai-svc polylai-svc-selected'>
					<input type="radio" data-poly-service checked class="tw-absolute tw-right-2 tw-top-3" />
					<div>
						<h3 class='tw-font-bold tw-text-[20px] tw-text-center tw-w-full tw-mb-0'><?php _e('PolylAI Cloud', 'ai-translator-for-polylang'); ?></h3>
						<h4 class="tw-text-[12px] tw-text-center tw-w-full tw-mt-0"><?php _e('Our powerful service', 'ai-translator-for-polylang'); ?></h4>
					</div>

					<div class="tw-text-center">
						<p><?php _e('Unlimited languages', 'ai-translator-for-polylang'); ?></p>
						<p class="tw-font-bold"><span data-credits></span> <?php _e('credits', 'ai-translator-for-polylang'); ?></p>
					</div>
				</div>
				<div data-polylai-svc='local' class='polylai-svc'>
					<input type="radio" data-poly-service class="tw-absolute tw-right-2 tw-top-3" />
					<div>
						<h3 class='tw-font-bold tw-text-[20px] tw-text-center tw-w-full tw-mb-0'><?php _e('Local plugin', 'ai-translator-for-polylang'); ?></h3>
						<h4 class="tw-text-[12px] tw-text-center tw-w-full tw-mt-0"><?php _e('Your server', 'ai-translator-for-polylang'); ?></h4>
					</div>

					<p>
						<?php if ($is_premium): ?>
							<?php _e('Premium', 'ai-translator-for-polylang'); ?>
						<?php else: ?>
							<?php _e('Free version, limited languages', 'ai-translator-for-polylang'); ?>
						<?php endif ?>
					</p>
					<p class="polylaitr-ui-key-msg polylai-warn polylai-hidden">
							<?php _e('OpenAI API key is required to translate.', 'ai-translator-for-polylang'); ?><br />
							<?php _e('Enter your API key in the <a href="wp-admin/admin.php?page=polylai-translator-options" target="_blank">Settings</a> page.', 'ai-translator-for-polylang'); ?>
						</p>
				</div>
			</div>	
			<?php endif ?>
		</div>
		<p>
			<a href="admin.php?page=polylai"><?php _e('Buy translation tokens', 'ai-translator-for-polylang'); ?></a>
		</p>
		<div class='polylaitr-buttons tw-mt-4' id="translate-buttons">
				<span data-close class='button'><?php _e('Cancel', 'ai-translator-for-polylang'); ?></span>
				<span class='button disabled' data-submit><?php _e('Translate', 'ai-translator-for-polylang'); ?></span>
			</div>
			<div class='tw-mt-4 polylai-hidden' id='close-button'>
				<span data-close class='button'><?php _e('Close', 'ai-translator-for-polylang'); ?></span>
			</div>
	</div>
</div>