<?php
namespace WTC_CHECKOUT\Modules\Dashboard\Admin;
use WTC_CHECKOUT\Modules\Dashboard\Services\DashboardStyleManager;
defined( 'ABSPATH' ) || exit;
class DashboardSettings {
	private $active_tab = 'settings';
	public function __construct() {
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$this->active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'settings';
		add_action( 'admin_init', array( $this, 'register_settings' ) );
		add_action( 'admin_post_wtc_save_dashboard_styles', array( $this, 'handle_save_styles' ) );
		add_action( 'admin_post_wtc_reset_dashboard_styles', array( $this, 'handle_reset_styles' ) );
	}
	public function register_settings() {
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_enabled', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_theme_mode', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_custom_styles_enabled', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_width_mode', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_width_custom', array( 'sanitize_callback' => 'absint' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_show_coupon_card', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_show_points_card', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_show_total_spent_card', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_show_order_count_card', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_chart_enabled', array( 'sanitize_callback' => 'sanitize_text_field' ) );
		register_setting( 'wtc_dashboard_options', 'wtc_dashboard_chart_period', array( 'sanitize_callback' => 'sanitize_text_field' ) );
	}
	public function render_settings_page() {
		?>
		<div class="wrap wtc-admin-page">
			<h1><?php esc_html_e( 'Kullanıcı Paneli', 'wtc-checkout' ); ?></h1>
			<?php settings_errors( 'wtc_dashboard_styles' ); ?>
			<h2 class="wtc-nav-tab-wrapper nav-tab-wrapper">
				<a href="?page=wtc-dashboard&tab=settings" class="wtc-nav-tab nav-tab <?php echo 'settings' === $this->active_tab ? 'nav-tab-active wtc-nav-tab-active' : ''; ?>">
					<?php esc_html_e( 'Ayarlar', 'wtc-checkout' ); ?>
				</a>
				<a href="?page=wtc-dashboard&tab=appearance" class="wtc-nav-tab nav-tab <?php echo 'appearance' === $this->active_tab ? 'nav-tab-active wtc-nav-tab-active' : ''; ?>">
					<?php esc_html_e( 'Görünüm', 'wtc-checkout' ); ?>
				</a>
				<a href="?page=wtc-dashboard&tab=how_to_use" class="wtc-nav-tab nav-tab <?php echo 'how_to_use' === $this->active_tab ? 'nav-tab-active wtc-nav-tab-active' : ''; ?>">
					<?php esc_html_e( 'Nasıl Kullanılır?', 'wtc-checkout' ); ?>
				</a>
<?php
echo '<style>
        .wtc-nav-tab-wrapper {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        gap: 10px;
        position: relative;
    }
    .wtc-right-tabs {
        margin-left: auto;
        display: flex;
        gap: 10px;
    }
    .wtc-right-tabs a {
        display: inline-flex;
        align-items: center;
        font-weight: bold;
        border-radius: 4px;
        text-decoration: none;
        padding: 10px 20px;
        transition: background-color 0.3s ease;
        font-size: 16px;
    }
    .wtc-premium-link {
        background-color: #0AA000;
        color: #fff !important;
    }
    .wtc-premium-link:hover {
        background-color:rgb(8, 97, 2);
    }
    .wtc-support-link {
        background-color: #FFDD00;
        color: #000 !important;
    }
    .wtc-support-link:hover {
        background-color: #f2cc00;
    }
    </style>';
echo '<span class="wtc-right-tabs">';
echo '<a href="https://coff.ee/woosoft" target="_blank" class="wtc-support-link">☕&nbsp;&nbsp;Buy me a coffee</a>';
echo '</span>';
?>
			</h2>
			<div class="wtc-card">
				<?php
				if ( 'settings' === $this->active_tab ) {
					$this->render_general_settings();
				} elseif ( 'appearance' === $this->active_tab ) {
					$this->render_appearance_settings();
				} elseif ( 'how_to_use' === $this->active_tab ) {
					$this->render_how_to_use();
				}
				?>
			</div>
		</div>
		<?php
	}
	private function render_general_settings() {
		$enabled    = get_option( 'wtc_dashboard_enabled', 'no' );
		$theme_mode = get_option( 'wtc_dashboard_theme_mode', 'auto' );
		?>
		<form method="post" action="options.php" class="wtc-settings-form">
			<?php
			settings_fields( 'wtc_dashboard_options' );
			do_settings_sections( 'wtc_dashboard_options' );
			?>
			<div class="wtc-settings-section">
				<table class="form-table wtc-form-table">
					<tr>
						<th scope="row"><?php esc_html_e( 'Kullanıcı Paneli', 'wtc-checkout' ); ?></th>
						<td>
							<div class="wtc-toggle-wrapper">
								<input type="hidden" name="wtc_dashboard_enabled" value="no">
								<input type="checkbox" id="wtc_dashboard_enabled" name="wtc_dashboard_enabled" value="yes" <?php checked( $enabled, 'yes' ); ?> class="wtc-toggle-input">
								<label for="wtc_dashboard_enabled" class="wtc-toggle-label"></label>
								<span class="toggle-label"><?php esc_html_e( 'Modern Kullanıcı Paneli görünümünü aktif et', 'wtc-checkout' ); ?></span>
							</div>
							<p class="description"><?php esc_html_e( 'Aktif edildiğinde, kısa kodu eklediğiniz "Hesabım" sayfası modern bir görünüm alır.', 'wtc-checkout' ); ?></p>
						</td>
					</tr>
				</table>
			</div>
			<div class="wtc-settings-section">
				<h3><?php esc_html_e( 'Genel Ayarlar', 'wtc-checkout' ); ?></h3>
				<table class="form-table wtc-form-table">
					<tr>
						<th scope="row"><?php esc_html_e( 'Görünüm Modu', 'wtc-checkout' ); ?></th>
						<td>
							<select name="wtc_dashboard_theme_mode" class="wtc-select">
								<option value="auto" <?php selected( $theme_mode, 'auto' ); ?>><?php esc_html_e( 'Otomatik (Tarayıcı Tercihi ve Saat)', 'wtc-checkout' ); ?></option>
								<option value="light" <?php selected( $theme_mode, 'light' ); ?>><?php esc_html_e( 'Aydınlık Mod (Varsayılan)', 'wtc-checkout' ); ?></option>
								<option value="dark" <?php selected( $theme_mode, 'dark' ); ?>><?php esc_html_e( 'Karanlık Mod', 'wtc-checkout' ); ?></option>
							</select>
							<p class="description"><?php esc_html_e( 'Kullanıcıların göreceği renk şemasını belirleyin.', 'wtc-checkout' ); ?></p>
						</td>
					</tr>
					<?php self::render_chart_settings_fields(); ?>
				</table>
			</div>
			<p class="submit">
				<button type="submit" class="button button-primary"><?php esc_html_e( 'Ayarları Kaydet', 'wtc-checkout' ); ?></button>
			</p>
		</form>
		<?php
	}
	private function render_chart_settings_fields() {
		?>
		<tr>
			<th scope="row"><?php esc_html_e( 'Toplam Sipariş Kartı', 'wtc-checkout' ); ?></th>
			<td>
				<div class="wtc-toggle-wrapper">
					<input type="hidden" name="wtc_dashboard_show_total_spent_card" value="no">
					<input type="checkbox" id="wtc_dashboard_show_total_spent_card" name="wtc_dashboard_show_total_spent_card" value="yes" <?php checked( get_option( 'wtc_dashboard_show_total_spent_card', 'yes' ), 'yes' ); ?> class="wtc-toggle-input">
					<label for="wtc_dashboard_show_total_spent_card" class="wtc-toggle-label"></label>
					<span class="toggle-label"><?php esc_html_e( 'Toplam harcama tutarını panelde göster', 'wtc-checkout' ); ?></span>
				</div>
				<p class="description"><?php esc_html_e( 'Kullanıcının bugüne kadar yaptığı toplam harcamayı gösteren istatistik kartı.', 'wtc-checkout' ); ?></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php esc_html_e( 'Siparişler Kartı', 'wtc-checkout' ); ?></th>
			<td>
				<div class="wtc-toggle-wrapper">
					<input type="hidden" name="wtc_dashboard_show_order_count_card" value="no">
					<input type="checkbox" id="wtc_dashboard_show_order_count_card" name="wtc_dashboard_show_order_count_card" value="yes" <?php checked( get_option( 'wtc_dashboard_show_order_count_card', 'yes' ), 'yes' ); ?> class="wtc-toggle-input">
					<label for="wtc_dashboard_show_order_count_card" class="wtc-toggle-label"></label>
					<span class="toggle-label"><?php esc_html_e( 'Toplam sipariş sayısını panelde göster', 'wtc-checkout' ); ?></span>
				</div>
				<p class="description"><?php esc_html_e( 'Kullanıcının toplam sipariş sayısını gösteren istatistik kartı.', 'wtc-checkout' ); ?></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php esc_html_e( 'Puan Kartı', 'wtc-checkout' ); ?></th>
			<td>
				<div class="wtc-toggle-wrapper">
					<input type="hidden" name="wtc_dashboard_show_points_card" value="no">
					<input type="checkbox" id="wtc_dashboard_show_points_card" name="wtc_dashboard_show_points_card" value="yes" <?php checked( get_option( 'wtc_dashboard_show_points_card', 'yes' ), 'yes' ); ?> class="wtc-toggle-input">
					<label for="wtc_dashboard_show_points_card" class="wtc-toggle-label"></label>
					<span class="toggle-label"><?php esc_html_e( 'Puan bakiyesini panelde göster', 'wtc-checkout' ); ?></span>
				</div>
				<p class="description"><?php esc_html_e( 'Puan modülü aktifse, kullanıcının puan bakiyesini gösteren istatistik kartı.', 'wtc-checkout' ); ?></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php esc_html_e( 'Kuponlar Kartı', 'wtc-checkout' ); ?></th>
			<td>
				<div class="wtc-toggle-wrapper">
					<input type="hidden" name="wtc_dashboard_show_coupon_card" value="no">
					<input type="checkbox" id="wtc_dashboard_show_coupon_card" name="wtc_dashboard_show_coupon_card" value="yes" <?php checked( get_option( 'wtc_dashboard_show_coupon_card', 'yes' ), 'yes' ); ?> class="wtc-toggle-input">
					<label for="wtc_dashboard_show_coupon_card" class="wtc-toggle-label"></label>
					<span class="toggle-label"><?php esc_html_e( 'Kupon sayısını panelde göster', 'wtc-checkout' ); ?></span>
				</div>
				<p class="description"><?php esc_html_e( 'Kullanıcının kaç adet kuponu olduğunu gösteren istatistik kartı.', 'wtc-checkout' ); ?></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php esc_html_e( 'Harcama Grafiği', 'wtc-checkout' ); ?></th>
			<td>
				<div class="wtc-toggle-wrapper">
					<input type="hidden" name="wtc_dashboard_chart_enabled" value="no">
					<input type="checkbox" id="wtc_dashboard_chart_enabled" name="wtc_dashboard_chart_enabled" value="yes" <?php checked( get_option( 'wtc_dashboard_chart_enabled', 'yes' ), 'yes' ); ?> class="wtc-toggle-input">
					<label for="wtc_dashboard_chart_enabled" class="wtc-toggle-label"></label>
					<span class="toggle-label"><?php esc_html_e( 'Harcama trendi grafiğini göster', 'wtc-checkout' ); ?></span>
				</div>
				<p class="description"><?php esc_html_e( 'Harcama grafiğini kullanıcı panel sayfasında gösterir.', 'wtc-checkout' ); ?></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php esc_html_e( 'Grafik Periyodu', 'wtc-checkout' ); ?></th>
			<td>
				<select name="wtc_dashboard_chart_period" class="wtc-select">
					<option value="1_month" <?php selected( get_option( 'wtc_dashboard_chart_period', '1_year' ), '1_month' ); ?>><?php esc_html_e( 'Son 1 Ay (Günlük)', 'wtc-checkout' ); ?></option>
					<option value="6_months" <?php selected( get_option( 'wtc_dashboard_chart_period', '1_year' ), '6_months' ); ?>><?php esc_html_e( 'Son 6 Ay (Aylık)', 'wtc-checkout' ); ?></option>
					<option value="1_year" <?php selected( get_option( 'wtc_dashboard_chart_period', '1_year' ), '1_year' ); ?>><?php esc_html_e( 'Son 1 Yıl (Aylık)', 'wtc-checkout' ); ?></option>
				</select>
				<p class="description"><?php esc_html_e( 'Harcama grafiği için gösterilecek veri periyodu ayarlar.', 'wtc-checkout' ); ?></p>
			</td>
		</tr>
		<?php
	}
	private function render_appearance_settings() {
		$settings        = DashboardStyleManager::get_all_settings();
		$defaults        = DashboardStyleManager::get_defaults();
		$settings_groups = DashboardStyleManager::get_settings_groups();
		$custom_styles_enabled = get_option( 'wtc_dashboard_custom_styles_enabled', 'no' );
		?>
		<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" id="wtc-appearance-form">
			<input type="hidden" name="action" value="wtc_save_dashboard_styles">
			<?php wp_nonce_field( 'wtc_dashboard_styles_nonce', 'wtc_styles_nonce' ); ?>
			<div class="wtc-settings-section">
				<table class="form-table wtc-form-table">
					<tr>
						<th scope="row"><?php esc_html_e( 'Stil Ayarları', 'wtc-checkout' ); ?></th>
						<td>
							<div class="wtc-toggle-wrapper">
								<input type="hidden" name="wtc_dashboard_custom_styles_enabled" value="no">
								<input type="checkbox" id="wtc_dashboard_custom_styles_enabled" name="wtc_dashboard_custom_styles_enabled" value="yes" <?php checked( $custom_styles_enabled, 'yes' ); ?> class="wtc-toggle-input">
								<label for="wtc_dashboard_custom_styles_enabled" class="wtc-toggle-label"></label>
								<span class="toggle-label"><?php esc_html_e( 'Özel Stilleri Aktif Et', 'wtc-checkout' ); ?></span>
							</div>
							<p class="description"><?php esc_html_e( 'Bu seçenek kapalı olduğunda, aşağıdaki ayarlar ne olursa olsun sistem varsayılan (tema moduna duyarlı) stil ayarlarını kullanır.', 'wtc-checkout' ); ?></p>
						</td>
					</tr>
				</table>
			</div>
			<div class="wtc-style-settings-wrapper" id="wtc-style-settings-grid" style="<?php echo 'yes' === $custom_styles_enabled ? '' : 'opacity: 0.5; pointer-events: none;'; ?>">
			<div class="wtc-style-row wtc-style-row-1">
				<?php 
				foreach ( $settings_groups as $group_key => $group ) : 
					if ( ( $group['row'] ?? 1 ) !== 1 ) continue;
				?>
					<div class="wtc-style-col wtc-style-col-half">
						<div class="wtc-style-panel">
							<h3><?php echo esc_html( $group['label'] ); ?></h3>
							<div class="wtc-style-fields">
								<?php foreach ( $group['fields'] as $field_key => $field ) : 
									$default = $defaults[ $field_key ] ?? '';
									$db_val = get_option( 'wtc_dashboard_' . $field_key, false );
									if ( 'toggle' === $field['type'] ) {
										$value = ( $db_val !== false ) ? $db_val : $default;
									} else {
										$value = ( $db_val !== false ) ? $db_val : '';
									}
									$conditional_style = '';
									$conditional_data  = '';
									if ( ! empty( $field['conditional'] ) ) {
										$cond_field      = $field['conditional']['field'];
										$cond_value      = $field['conditional']['value'];
										$cond_field_val  = get_option( 'wtc_dashboard_' . $cond_field, $defaults[ $cond_field ] ?? '' );
										$conditional_style = ( $cond_field_val !== $cond_value ) ? 'display:none;' : '';
										$conditional_data  = 'data-conditional-field="' . esc_attr( $cond_field ) . '" data-conditional-value="' . esc_attr( $cond_value ) . '"';
									}
								?>
									<div class="wtc-style-field" style="<?php echo esc_attr( $conditional_style ); ?>" <?php echo $conditional_data; // phpcs:ignore ?>>
										<label><?php echo esc_html( $field['label'] ); ?></label>
										<div class="wtc-style-input">
											<?php if ( 'color' === $field['type'] ) : ?>
												<input type="text" name="<?php echo esc_attr( $field_key ); ?>" value="<?php echo esc_attr( $value ); ?>" class="wtc-color-picker" data-default-color="<?php echo esc_attr( $default ); ?>">
											<?php elseif ( 'number' === $field['type'] ) : ?>
												<input type="number" name="<?php echo esc_attr( $field_key ); ?>" value="<?php echo esc_attr( $value ); ?>" class="small-text"<?php echo ! empty( $field['min'] ) ? ' min="' . esc_attr( $field['min'] ) . '"' : ''; ?><?php echo ! empty( $field['step'] ) ? ' step="' . esc_attr( $field['step'] ) . '"' : ''; ?>>
												<?php if ( ! empty( $field['suffix'] ) ) : ?><span class="suffix"><?php echo esc_html( $field['suffix'] ); ?></span><?php endif; ?>
											<?php elseif ( 'text' === $field['type'] ) : ?>
												<input type="text" name="<?php echo esc_attr( $field_key ); ?>" value="<?php echo esc_attr( $value ); ?>" class="regular-text" style="width: 100px;">
												<?php if ( ! empty( $field['suffix'] ) ) : ?><span class="suffix"><?php echo esc_html( $field['suffix'] ); ?></span><?php endif; ?>
											<?php elseif ( 'toggle' === $field['type'] ) : ?>
												<label class="wtc-toggle-wrapper-settings">
													<input type="hidden" name="<?php echo esc_attr( $field_key ); ?>" value="no">
													<input type="checkbox" name="<?php echo esc_attr( $field_key ); ?>" value="yes" <?php checked( $value, 'yes' ); ?> class="wtc-toggle-input">
													<span class="wtc-toggle-label"></span>
												</label>
											<?php elseif ( 'select' === $field['type'] ) : ?>
												<select name="<?php echo esc_attr( $field_key ); ?>" id="wtc_dashboard_<?php echo esc_attr( $field_key ); ?>">
													<?php foreach ( $field['options'] as $opt_value => $opt_label ) : ?>
														<option value="<?php echo esc_attr( $opt_value ); ?>" <?php selected( $value ?: $default, $opt_value ); ?>><?php echo esc_html( $opt_label ); ?></option>
													<?php endforeach; ?>
												</select>
											<?php endif; ?>
										</div>
										<?php if ( ! empty( $field['description'] ) ) : ?><p class="description"><?php echo esc_html( $field['description'] ); ?></p><?php endif; ?>
									</div>
								<?php endforeach; ?>
							</div>
						</div>
					</div>
				<?php endforeach; ?>
			</div>
			<div class="wtc-style-row wtc-style-row-2">
				<h3 class="wtc-style-row-title"><?php esc_html_e( 'İstatistik Kart Renkleri', 'wtc-checkout' ); ?></h3>
				<div class="wtc-style-cards-grid">
					<?php 
					foreach ( $settings_groups as $group_key => $group ) : 
						if ( ( $group['row'] ?? 1 ) !== 2 ) continue;
					?>
						<div class="wtc-style-card-panel">
							<h4>
								<?php if ( ! empty( $group['icon'] ) ) : ?>
									<span class="wtc-card-icon"><?php \WTC_CHECKOUT\Core\Helpers\SvgIconHelper::render( $group['icon'] ); ?></span>
								<?php endif; ?>
								<?php echo esc_html( $group['label'] ); ?>
							</h4>
							<div class="wtc-style-fields">
								<?php foreach ( $group['fields'] as $field_key => $field ) : 
									$default = $defaults[ $field_key ] ?? '';
									$db_val = get_option( 'wtc_dashboard_' . $field_key, false );
									$value = ( $db_val !== false ) ? $db_val : '';
								?>
									<div class="wtc-style-field">
										<label><?php echo esc_html( $field['label'] ); ?></label>
										<div class="wtc-style-input">
											<input type="text" name="<?php echo esc_attr( $field_key ); ?>" value="<?php echo esc_attr( $value ); ?>" class="wtc-color-picker" data-default-color="<?php echo esc_attr( $default ); ?>">
										</div>
									</div>
								<?php endforeach; ?>
							</div>
						</div>
					<?php endforeach; ?>
				</div>
			</div>
		</div>
		<p class="submit">
			<button type="submit" class="button button-primary button-large" id="wtc-save-styles">
				<?php esc_html_e( 'Değişiklikleri Kaydet', 'wtc-checkout' ); ?>
			</button>
			<a href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=wtc_reset_dashboard_styles' ), 'wtc_dashboard_reset_nonce', 'wtc_reset_nonce' ) ); ?>" class="button button-secondary button-large" id="wtc-reset-styles" style="margin-left: 10px;">
				<?php esc_html_e( 'Varsayılana Sıfırla', 'wtc-checkout' ); ?>
			</a>
		</p>				
		</form>
		<?php
	}
	public function handle_save_styles() {
		if ( ! isset( $_POST['wtc_styles_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['wtc_styles_nonce'] ) ), 'wtc_dashboard_styles_nonce' ) ) {
			wp_die( esc_html__( 'Güvenlik doğrulaması başarısız.', 'wtc-checkout' ) );
		}
		if ( ! current_user_can( 'manage_options' ) ) {
			wp_die( esc_html__( 'Yetkiniz yok.', 'wtc-checkout' ) );
		}
		$settings = array();
		foreach ( $_POST as $key => $value ) {
			if ( strpos( $key, 'wtc_dashboard_' ) === 0 ) {
				$clean_key = str_replace( 'wtc_dashboard_', '', $key );
				$settings[ $clean_key ] = $value;
			} else {
				$settings[ $key ] = $value;
			}
		}
		try {
			DashboardStyleManager::save_settings( $settings );
			add_settings_error( 'wtc_dashboard_styles', 'wtc_styles_saved', __( 'Ayarlar kaydedildi ve CSS oluşturuldu.', 'wtc-checkout' ), 'success' );
		} catch (\Exception $e) {
			add_settings_error( 'wtc_dashboard_styles', 'wtc_styles_error', __( 'Hata: ', 'wtc-checkout' ) . $e->getMessage(), 'error' );
		}
		wp_safe_redirect( admin_url( 'admin.php?page=wtc-dashboard&tab=appearance' ) );
		exit;
	}
	public function handle_reset_styles() {
		if ( ! isset( $_GET['wtc_reset_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['wtc_reset_nonce'] ) ), 'wtc_dashboard_reset_nonce' ) ) {
			wp_die( esc_html__( 'Güvenlik doğrulaması başarısız.', 'wtc-checkout' ) );
		}
		if ( ! current_user_can( 'manage_options' ) ) {
			wp_die( esc_html__( 'Yetkiniz yok.', 'wtc-checkout' ) );
		}
		try {
			DashboardStyleManager::reset_to_defaults();
			add_settings_error( 'wtc_dashboard_styles', 'wtc_styles_reset', __( 'Tüm ayarlar varsayılana sıfırlandı.', 'wtc-checkout' ), 'success' );
		} catch (\Exception $e) {
			add_settings_error( 'wtc_dashboard_styles', 'wtc_reset_error', $e->getMessage(), 'error' );
		}
		wp_safe_redirect( admin_url( 'admin.php?page=wtc-dashboard&tab=appearance' ) );
		exit;
	}
	private function render_how_to_use() {
		?>
		<div class="notice notice-info inline" style="border: 1px solid #b5d2ea; border-left-width: 4px; background: #fff; padding: 15px; margin-bottom: 25px;">
			<h3 style="margin: 0 0 10px;"><?php esc_html_e( 'Nasıl Kullanılır?', 'wtc-checkout' ); ?></h3>
			<p><?php esc_html_e( 'Modern Dashboard tasarımını sitenizde aktif etmek için aşağıdaki adımları izleyin:', 'wtc-checkout' ); ?></p>
			<ol>
				<li>WordPress <b><a href="/wp-admin/post-new.php?post_type=page">Sayfalar > Sayfa Ekle</a></b> yolunu izleyerek boş bir sayfa oluşturun (Örn: "Hesabım Yeni").</li>
				<li>Sayfanın içeriğine şu kısa kodu (shortcode) ekleyin: <code>[wtc_dashboard]</code></li>
				<li>Sayfa özelliklerinden şablonu <b>"Tam Genişlik (Full Width)"</b> olarak seçin (Temanızın kenar çubuya olmayan şablonu).</li>
				<li><b><a href="/wp-admin/admin.php?page=wc-settings&tab=advanced">WooCommerce > Ayarlar > Gelişmiş</a></b> sekmesine gidin.</li>
				<li><b>"Hesabım Sayfası"</b> ayarını yeni oluşturduğunuz sayfa ile değiştirip kaydedin.</li>
			</ol>
			<p><?php esc_html_e( 'Not: Dilerseniz yukarıda verilen kısa kodu (shortcode), mevcut hesabım sayfasındaki kısa kod (shortcode) ile değiştirebilirsiniz.', 'wtc-checkout' ); ?></p>
		</div>
		<?php
	}
}