<?php

declare(strict_types=1);

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

use Signocore\Multilanguage\Application\Constants;

/**
 * @var string $currentStrategy
 * @var bool $isPro
 * @var string $siteUrl
 */

$parsedUrl = wp_parse_url($siteUrl);
$host = $parsedUrl['host'] ?? 'example.com';
$scheme = $parsedUrl['scheme'] ?? 'https';
$hideDefault = (int) get_option(Constants::OPTION_PREFIX . 'hide_default_language_prefix', 1);
?>

<h2 class="sml-wizard-title"><?php esc_html_e('URL Structure', 'signocore-multilanguage'); ?></h2>
<p class="sml-wizard-subtitle"><?php esc_html_e('Choose how translated pages should be accessed. This determines how language-specific URLs are structured on your site.', 'signocore-multilanguage'); ?></p>

<div class="sml-strategy-cards">
	<?php // Directory prefix ?>
	<div class="sml-strategy-card <?php echo $currentStrategy === Constants::URL_STRATEGY_DIRECTORY ? 'selected' : ''; ?>" data-strategy="<?php echo esc_attr(Constants::URL_STRATEGY_DIRECTORY); ?>">
		<div class="sml-strategy-radio">
			<input
				type="radio"
				name="url_strategy"
				value="<?php echo esc_attr(Constants::URL_STRATEGY_DIRECTORY); ?>"
				<?php checked($currentStrategy, Constants::URL_STRATEGY_DIRECTORY); ?>
			>
		</div>
		<div class="sml-strategy-content">
			<div class="sml-strategy-title">
				<?php esc_html_e('Directory Prefix', 'signocore-multilanguage'); ?>
				<span class="sml-strategy-badge free"><?php esc_html_e('Free', 'signocore-multilanguage'); ?></span>
			</div>
			<p class="sml-strategy-description">
				<?php esc_html_e('Add a language code as a directory prefix to your URLs. This is the most common and SEO-friendly approach.', 'signocore-multilanguage'); ?>
			</p>
			<div class="sml-strategy-example">
				<?php echo esc_html($scheme . '://' . $host); ?>/<strong>da</strong>/about-us/
			</div>
		</div>
	</div>

	<?php // Subdomain ?>
	<div class="sml-strategy-card <?php echo $currentStrategy === Constants::URL_STRATEGY_SUBDOMAIN ? 'selected' : ''; ?> <?php echo !$isPro ? 'locked' : ''; ?>" data-strategy="<?php echo esc_attr(Constants::URL_STRATEGY_SUBDOMAIN); ?>">
		<div class="sml-strategy-radio">
			<input
				type="radio"
				name="url_strategy"
				value="<?php echo esc_attr(Constants::URL_STRATEGY_SUBDOMAIN); ?>"
				<?php checked($currentStrategy, Constants::URL_STRATEGY_SUBDOMAIN); ?>
				<?php disabled(!$isPro); ?>
			>
		</div>
		<div class="sml-strategy-content">
			<div class="sml-strategy-title">
				<?php esc_html_e('Subdomain', 'signocore-multilanguage'); ?>
				<span class="sml-strategy-badge pro"><?php esc_html_e('Pro', 'signocore-multilanguage'); ?></span>
				<?php if (!$isPro): ?>
					<span class="sml-strategy-lock"><span class="dashicons dashicons-lock"></span></span>
				<?php endif; ?>
			</div>
			<p class="sml-strategy-description">
				<?php esc_html_e('Use a language-specific subdomain for each translation. Requires DNS configuration.', 'signocore-multilanguage'); ?>
			</p>
			<div class="sml-strategy-example">
				<?php echo esc_html($scheme); ?>://<strong>da</strong>.<?php echo esc_html($host); ?>/about-us/
			</div>
		</div>
	</div>

	<?php // Custom domains ?>
	<div class="sml-strategy-card <?php echo $currentStrategy === Constants::URL_STRATEGY_DOMAIN ? 'selected' : ''; ?> <?php echo !$isPro ? 'locked' : ''; ?>" data-strategy="<?php echo esc_attr(Constants::URL_STRATEGY_DOMAIN); ?>">
		<div class="sml-strategy-radio">
			<input
				type="radio"
				name="url_strategy"
				value="<?php echo esc_attr(Constants::URL_STRATEGY_DOMAIN); ?>"
				<?php checked($currentStrategy, Constants::URL_STRATEGY_DOMAIN); ?>
				<?php disabled(!$isPro); ?>
			>
		</div>
		<div class="sml-strategy-content">
			<div class="sml-strategy-title">
				<?php esc_html_e('Custom Domains', 'signocore-multilanguage'); ?>
				<span class="sml-strategy-badge pro"><?php esc_html_e('Pro', 'signocore-multilanguage'); ?></span>
				<?php if (!$isPro): ?>
					<span class="sml-strategy-lock"><span class="dashicons dashicons-lock"></span></span>
				<?php endif; ?>
			</div>
			<p class="sml-strategy-description">
				<?php esc_html_e('Map each language to a completely different domain. Best for international brands with country-specific domains.', 'signocore-multilanguage'); ?>
			</p>
			<div class="sml-strategy-example">
				<?php echo esc_html($scheme); ?>://<strong><?php
					$parts = explode('.', $host);
					if (count($parts) >= 2) {
						$parts[count($parts) - 1] = 'dk';
						echo esc_html(implode('.', $parts));
					} else {
						echo esc_html($host);
					}
				?></strong>/about-us/
			</div>
		</div>
	</div>
</div>

<div class="sml-hide-default-wrap">
	<input
		type="checkbox"
		id="sml-hide-default-prefix"
		<?php checked($hideDefault, 1); ?>
	>
	<div>
		<label for="sml-hide-default-prefix">
			<?php esc_html_e('Hide language prefix for default language', 'signocore-multilanguage'); ?>
		</label>
		<p class="sml-hide-default-desc">
			<?php
			printf(
				/* translators: 1: URL with prefix, 2: URL without prefix */
				esc_html__('When enabled, the default language URL will be %1$s instead of %2$s', 'signocore-multilanguage'),
				'<code>' . esc_html($scheme . '://' . $host . '/about-us/') . '</code>',
				'<code>' . esc_html($scheme . '://' . $host . '/en/about-us/') . '</code>'
			);
			?>
		</p>
	</div>
</div>

<div class="sml-wizard-actions">
	<button type="button" class="sml-skip-link"><?php esc_html_e('Skip Setup', 'signocore-multilanguage'); ?></button>
	<div class="sml-wizard-actions-right">
		<button type="button" id="sml-back-btn" class="sml-btn sml-btn-secondary">
			<?php esc_html_e('Back', 'signocore-multilanguage'); ?>
		</button>
		<button type="button" id="sml-next-btn" class="sml-btn sml-btn-primary">
			<?php esc_html_e('Next', 'signocore-multilanguage'); ?>
			<span class="sml-spinner"></span>
		</button>
	</div>
</div>
