<?php
/**
 * Theme updater admin page and functions.
 */

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

class admin_updates {
	
    protected $remote_api_url = null; // URL API untuk request lisensi/update
    protected $theme_slug     = null; // Slug tema (nama folder)
    protected $version        = null; // Versi tema saat ini
    protected $author         = null; // Nama author tema
    protected $download_id    = null; // ID download di server EDD
    protected $renew_url      = null; // Link perpanjangan lisensi
    protected $strings        = null; // Array string tampilan (i18n)
    protected $beta           = false;
	
	
    // ----------------------------------------------------
    // 2a. Constructor
    // ----------------------------------------------------
    function __construct( $config = array(), $strings = array() ) {
        // Merge config user dengan default
        $config = wp_parse_args( $config, array(
            'remote_api_url' => EXTHEMES_API_URL,
            'download_id'    => '',
            'theme_slug'     => get_template(),
            'item_name'      => '',
            'license'        => '',
            'version'        => '',
            'author'         => '',
            'renew_url'      => '',
            'beta'           => false,
        ) );
		
		 
		
        // Set properti class
        $this->remote_api_url = $config['remote_api_url'];
        $this->item_name      = $config['item_name'];
        $this->theme_slug     = sanitize_key( $config['theme_slug'] );
        $this->version        = $config['version'];
        $this->author         = $config['author'];
        $this->download_id    = $config['download_id'];
        $this->renew_url      = $config['renew_url'];
        $this->beta           = $config['beta'];
        $this->strings        = $strings;
		
		
        // Jika versi tema kosong, ambil dari tema saat ini
        if( '' == $config['version'] ){
            $theme = wp_get_theme( $this->theme_slug );
            $this->version = $theme->get( 'Version' );
        }

        // ----------------------------------------------------
        // Hook WordPress
        // ----------------------------------------------------
        add_action( 'init', array( $this, 'updater_edd_themes' ) ); // Update tema
        add_action( 'admin_init', array( $this, 'register_option' ) ); // Daftar option license key
        add_action( 'admin_init', array( $this, 'license_action' ), 20 ); // Proses activate/deactivate/change
        add_action( 'admin_menu', array( $this, 'license_menu' ) ); // Menu lisensi di WP Admin
        add_action( 'add_option_'.$this->theme_slug.'_license_key', array( $this, 'activate_license' ), 20, 2 ); // Saat tambah license baru
        add_action( 'update_option_'.$this->theme_slug.'_license_key', array( $this, 'activate_license' ), 20, 2 ); // Saat update license
        add_filter( 'http_request_args', array( $this, 'disable_wporg_request' ), 5, 2 ); // Disable update WP.org
        add_action( 'admin_init', array( $this, 'weekly_license_check' ) );
		
    }	
	
    public function weekly_license_check() {
        $last_check = get_option( $this->theme_slug.'_last_license_check', false );
        $current_time = time();

        if( !$last_check || ($current_time - $last_check) > 604800 ) { // 600 or 604800 
            $license = trim( get_option( $this->theme_slug . '_license_key' ) );
            if( $license ) {
                $api_params = array(
                    'edd_action' => 'check_license',
                    'license'    => $license,
                    'item_name'  => urlencode( $this->item_name ),
                    'url'        => home_url('/')
                );
                $response = $this->get_api_response( $api_params );
                $license_data = json_decode( wp_remote_retrieve_body( $response ) );

                if( isset($license_data->license) && $license_data->license === 'valid' ) {
                    update_option( $this->theme_slug.'_license_key_status', 'valid' );
                    update_option( $this->theme_slug.'_last_license_check', $current_time );
                }
                
                else {
                    $this->force_deactivate_license();
                }
            }
        }
    }
	
    public function force_deactivate_license() {
        delete_option( $this->theme_slug . '_license_key' );
        delete_option( $this->theme_slug . '_license_key_status' );
        delete_transient( $this->theme_slug . '_license_message' );

        update_option( $this->theme_slug . '_features_disabled', 1 );

        // Redirect ke halaman lisensi dengan pesan
        $base_url = admin_url( 'admin.php?page=' . $this->theme_slug );
        $message = urlencode( $this->strings['license-invalid-deactivated'] ?? 'License invalid! All features are disabled.' );
        $redirect = add_query_arg( array( 'sl_theme_activation' => 'false', 'message' => $message ), $base_url );
        wp_redirect( $redirect );
        exit();
    }

    public function is_feature_active() {
        $disabled = get_option( $this->theme_slug . '_features_disabled', 0 );
        if( $disabled ) {
            return false; 
        }
        return true; 
    }


	// ----------------------------------------------------
    // 2b. Update tema via EDD
    // ----------------------------------------------------
    function updater_edd_themes() {
        // Hanya admin yang bisa update
        if ( ! current_user_can( 'manage_options' ) ) {
            return;
        }
		
        if( ! $this->is_feature_active() ) return;
		
        if ( get_option( $this->theme_slug.'_license_key_status', false) != 'valid' ) {
            return;
        }

        // Include class tema_updates jika belum ada
        if ( !class_exists( 'tema_updates' ) ) {  
            include( get_template_directory().'/libs/addons/inc/class_2.php' );
        }

        // Inisialisasi update
        new tema_updates(
            array(
                'remote_api_url' => $this->remote_api_url,
                'version'        => $this->version,
                'license'        => trim( get_option( $this->theme_slug . '_license_key' ) ),
                'item_name'      => $this->item_name,
                'author'         => $this->author,
                'beta'           => $this->beta
            ),
            $this->strings
        );
    }
    
    // ----------------------------------------------------
    // 2c. Menu lisensi di admin
    // ----------------------------------------------------
    function license_menu(){
        $strings = $this->strings;
        add_menu_page(
            $strings['theme-license'],       // Judul halaman
            $strings['theme-license'],       // Judul menu
            'manage_options',                // Capability admin
            $this->theme_slug,               // Slug menu
            array( $this, 'license_page' ),  // Callback halaman
            'dashicons-admin-network'        // Icon menu
        );
    }
	 
	
	// ------------------------------------------
    // Function baru: Render License Page + Tabs + Changelog
    // ----------------------------------------------------
    public function render_license_page($license, $status, $customer_name, $customer_email, $site_count, $license_limit, $expires, $message, $author_names, $gravatar_link, $strings) {
		
    ob_start();
    
	?>	
		
	<!-- Font Awesome & TailwindCSS -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" />
	<script src="https://cdn.tailwindcss.com"></script>

	<style>
	.iframe-wrap{position:relative;width:100%;height:0;padding-bottom:129%}
	.iframe-wrap iframe{position:absolute;top:0;left:0;width:100%;height:100%}
	.alt-tabs{max-width:1100px;font-family:'Segoe UI',system-ui,sans-serif}
	.alt-tabs-wrap{display:flex;background:#ffffff;border-radius:1.5rem;box-shadow:0 25px 50px rgba(0,0,0,.08);overflow:hidden}
	.alt-tabs-nav{width:280px;background:#f9fafb;border-right:1px solid #e5e7eb;display:flex;flex-direction:column}
	.alt-tab{padding:1.4rem 1.6rem;border:none;background:transparent;text-align:left;font-size:1.05rem;font-weight:600;color:#6b7280;cursor:pointer;display:flex;gap:.9rem;align-items:center;transition:.3s;position:relative}
	.alt-tab i{font-size:1.2rem;width:24px}
	.alt-tab:hover{background:rgba(37,99,235,.06);color:#2563eb}
	.alt-tab.active{background:#ffffff;color:#2563eb}
	.alt-tab.active::before{content:"";position:absolute;left:0;top:0;width:4px;height:100%;background:linear-gradient(to bottom,#2563eb,#4f46e5)}
	.alt-tabs-content{flex:1;padding:3rem;position:relative;overflow:hidden}
	.alt-panel{display:none;animation:slideIn .45s ease}
	.alt-panel.active{display:block}
	.alt-panel h3{font-size:2.2rem;margin-bottom:1rem;color:#111827}
	.alt-panel p{font-size:1.1rem;color:#4b5563;line-height:1.7}
	.alt-stats{margin-top:2rem;display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:1.5rem}
	.alt-stat{background:#f9fafb;border-radius:1rem;padding:1.8rem}
	.alt-stat span{display:block;font-size:.95rem;color:#6b7280}
	.alt-stat strong{font-size:2rem;color:#2563eb}
	@keyframes slideIn{from{opacity:0;transform:translateX(30px)}
	to{opacity:1;transform:translateX(0)}
	}
	@media (max-width:768px){.alt-tabs-wrap{flex-direction:column}
	.alt-tabs-nav{width:100%;flex-direction:row;overflow-x:auto}
	.alt-tab{flex:1;justify-content:center;white-space:nowrap}
	.alt-tab.active::before{top:auto;bottom:0;width:100%;height:3px}
	}
	.aps-tab-content.active{display:block}
	@keyframes fadeInUp{from{opacity:0;transform:translateY(20px)}
	to{opacity:1;transform:translateY(0)}
	}
	.animate-fadeInUp{animation:fadeInUp 0.7s ease-out forwards}
	.card-hover:hover{transform:translateY(-5px);box-shadow:0 20px 25px -5px rgba(0,0,0,0.1),0 10px 10px -5px rgba(0,0,0,0.04)}
	.text-maroon-700{color:#800000}
	.aps-tab-content.active{display:block}
	.youtube-responsive{position:relative;width:100%;padding-bottom:56.25%;height:0;overflow:hidden;border-radius:12px}
	.youtube-responsive iframe{position:absolute;top:0;left:0;width:100%;height:100%}.aps-tab-content.active{display:block}

	</style>

        <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12">

        <!-- Header -->
       <header class="text-center mb-12 animate-fadeInUp">
			<h1 class="text-4xl md:text-5xl font-extrabold text-gray-900 tracking-tight">
				<?php
				// Gunakan _e() untuk echo langsung
				printf(
					/* translators: %s = Product name and version */
					esc_html__('License Key for %s', TEXT_DOMAIN),
					esc_html(PRODUCT_NAME . ' v' . PRODUCT_VERSIONS)
				);
				?>
			</h1>
			<p class="mt-3 text-lg text-gray-600">
				<?php _e('Manage & activate your licenses easily', TEXT_DOMAIN); ?>
			</p>
		</header>


        <!-- License Status -->
        <?php if ($license) : ?>
            <?php if (in_array($status, ['valid'])) : ?>
                <!-- Active License Card -->
                <div class="bg-white rounded-2xl shadow-xl overflow-hidden mb-10 animate-fadeInUp card-hover transition-transform duration-300">
                    <div class="p-8 md:p-10">
                        <!-- Badge & Expire -->
                        <div class="flex justify-between items-start mb-4">
                            <span class="inline-block px-3 py-1 text-sm font-medium rounded-full bg-green-100 text-green-800"><?php _e('Active', TEXT_DOMAIN); ?></span>
                            <span class="text-gray-400 text-sm"><?php echo sprintf($strings['expires%s'], $expires); ?></span>
                        </div>
                        <!-- Profile -->
                        <div class="flex flex-col md:flex-row items-center gap-8">
                            <div class="flex-shrink-0">
                                <img src="<?php echo $gravatar_link; ?>" alt="Customer" class="w-24 h-24 md:w-32 md:h-32 rounded-full ring-4 ring-blue-100 object-cover">
                            </div>
                            <div class="text-center md:text-left flex-1">
                                <h2 class="text-3xl font-bold text-red-600 uppercase tracking-wide"><?php echo $customer_name; ?></h2>
                                <div class="mt-4 space-y-2 text-gray-700">
                                    <p class="text-lg">
                                        <span class="font-semibold text-gray-900"><?php _e('License Key :', TEXT_DOMAIN); ?></span>
                                        <span class="font-mono text-xl text-maroon-700 bg-gray-100 px-3 py-1 rounded"><?php echo $this->get_hidden_license($license); ?></span>
                                    </p>
                                    <p class="text-base">
                                        <span class="font-semibold"> <?php _e('Active in :', TEXT_DOMAIN); ?></span> <?php echo sprintf($strings['%1$s/%2$-sites'], $site_count, $license_limit); ?>
                                    </p>
                                    <p class="text-base">
                                        <span class="font-semibold"><?php _e('Email :', TEXT_DOMAIN); ?></span> <?php echo $this->get_hidden_email($customer_email); ?>
                                    </p>
                                </div>
                            </div>
                        </div>

                        <!-- Social Links -->
                        <div class="mt-10 flex justify-center md:justify-end gap-6 text-2xl">
                            <a href="<?php echo EXTHEMES_ITEMS_URL; ?>" target="_blank" class="text-gray-500 hover:text-blue-600 transition">
                                <i class="fab fa-globe"></i>
                            </a>
                            <a href="<?php echo EXTHEMES_YOUTUBE_URL; ?>" target="_blank" class="text-gray-500 hover:text-red-600 transition">
                                <i class="fab fa-youtube"></i>
                            </a>
                            <a href="<?php echo EXTHEMES_FACEBOOK_URL; ?>" target="_blank" class="text-gray-500 hover:text-blue-700 transition">
                                <i class="fab fa-facebook"></i>
                            </a>
                        </div>
                    </div>

                    <!-- Deactivate Button -->
                    <div class="bg-gray-50 px-8 py-6 border-t border-gray-100 text-right">
                        <form method="post" action="options.php">
                            <?php settings_fields($this->theme_slug . ''); ?>
                            <?php wp_nonce_field($this->theme_slug . '_nonce', $this->theme_slug . '_nonce'); ?>
                            <input type="hidden" name="<?php echo $this->theme_slug; ?>_license_key_hidden" value="<?php echo esc_attr($license); ?>">
                            <button type="submit" name="<?php echo $this->theme_slug; ?>_license_deactivate" class="inline-flex items-center px-6 py-3 bg-red-600 text-white font-medium rounded-lg shadow-md hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 transition">
                                <i class="fas fa-power-off mr-2"></i>
                                <?php echo esc_attr($strings['deactivate-license']); ?>
                            </button>
                        </form>
                    </div>
                </div>
                <!-- End Active License Card -->

            <?php else: ?>
                <!-- Invalid / Inactive License -->
                <div class="bg-white rounded-2xl shadow-xl p-8 md:p-10 mb-10 animate-fadeInUp text-center">
                    <i class="fas fa-lock text-6xl text-red-500 mb-6"></i>
                    <h2 class="text-3xl font-bold text-gray-800 mb-4"> <?php _e('License Not Active', TEXT_DOMAIN); ?></h2>
                    <p class="text-lg text-gray-600 mb-6"><?php echo $message; ?></p>
                    <form method="post" action="options.php" class="max-w-md mx-auto">
                        <?php settings_fields($this->theme_slug . ''); ?>
                        <?php wp_nonce_field($this->theme_slug . '_nonce', $this->theme_slug . '_nonce'); ?>
                        <div class="flex flex-col sm:flex-row gap-4">
                            <input type="text" name="<?php echo $this->theme_slug; ?>_license_key" placeholder="<?php echo $strings['enter-key']; ?>" class="flex-1 px-5 py-4 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition text-lg" required>
                            <button type="submit" name="submit" class="px-8 py-4 bg-gradient-to-r from-blue-600 to-indigo-600 text-white font-semibold rounded-lg shadow-lg hover:from-blue-700 hover:to-indigo-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition transform hover:scale-105">
                                <?php echo esc_attr($strings['activate-license']); ?>
                            </button>
                        </div>
                        <?php if ($license): ?>
                            <p class="mt-4 text-sm text-gray-500 text-center">
									<?php 
									// _e() untuk langsung echo, esc_html() untuk keamanan
									printf(
										/* translators: %s = hidden license key */
										esc_html__('Your License Key: %s', TEXT_DOMAIN),
										'<strong class="font-mono">' . esc_html($this->get_hidden_license($license)) . '</strong>'
									); 
									?>
								</p>

                        <?php endif; ?>
                    </form>
                </div>
            <?php endif; ?>

        <?php else: ?>
            <!-- No License Yet -->
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-10 mb-10 animate-fadeInUp text-center">
                <i class="fas fa-key text-7xl text-blue-500 mb-8 opacity-80"></i>
					<h2 class="text-4xl font-bold text-gray-800 mb-4">
						<?php
						// _e() atau __() untuk terjemahan
						// translators: %s = author name
						printf(
							esc_html__('Welcome, %s!', TEXT_DOMAIN),
							esc_html($author_names)
						);
						?>
					</h2>
					
					<p class="text-xl text-gray-600 mb-8">
						<?php
						// translators: %s = product name and version
						printf(
							esc_html__('Input Your License Key for %s', TEXT_DOMAIN ),
							'<span class="font-semibold text-blue-600">' . esc_html(PRODUCT_NAME . ' v' . PRODUCT_VERSIONS) . '</span>'
						);
						?>
					</p>

                <form method="post" action="options.php" class="max-w-lg mx-auto">
                    <?php settings_fields($this->theme_slug . ''); ?>
                    <?php wp_nonce_field($this->theme_slug . '_nonce', $this->theme_slug . '_nonce'); ?>
                    <div class="flex flex-col sm:flex-row gap-4">
                        <input type="text" name="<?php echo $this->theme_slug; ?>_license_key" placeholder="<?php echo $strings['enter-key']; ?>" class="flex-1 px-6 py-4 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition text-lg" required>
                        <button type="submit" name="submit" class="px-10 py-4 bg-gradient-to-r from-blue-600 to-indigo-600 text-white font-semibold rounded-lg shadow-lg hover:from-blue-700 hover:to-indigo-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition transform hover:scale-105">
                            <?php echo esc_attr($strings['activate-license']); ?>
                        </button>
                    </div>
                    <?php if (!empty($message)): ?>
                        <p class="mt-6 text-red-600 font-medium"><?php echo $message; ?></p>
                    <?php endif; ?>
                </form>
            </div>
			<?php endif; ?>

			<!-- Tabs Section (Changelog / Demo / System Info) -->
			<?php
			$this->render_tabs_section(); // Panggil function render_tabs_section yang sudah kita buat sebelumnya
			?>

        </div>
	
	<?php
	
    return ob_get_clean();
    }

    // Function render_tabs_section() seperti yang sudah dibuat sebelumnya
    public function render_tabs_section() {
	// Semua HTML tabs + panels sama persis seperti yang ada di kode asli
	?>
	<!-- Copy seluruh struktur HTML alt-tabs di sini -->
		
	<div class="alt-tabs">
	<div class="alt-tabs-wrap">

	<!-- NAV -->
	<div class="alt-tabs-nav">
		<button class="alt-tab active" data-panel="p1">
			<?php _e('Changelog', TEXT_DOMAIN); ?>
		</button>
		<button class="alt-tab" data-panel="p2">
			<?php _e('How to Import Demo', TEXT_DOMAIN); ?>
		</button>
		<button class="alt-tab" data-panel="p3">
			<?php _e('System Info', TEXT_DOMAIN); ?>
		</button>
		<button class="alt-tab" data-panel="p4">
			<?php _e('How to Get a License Key', TEXT_DOMAIN); ?>
		</button>
		<button class="alt-tab" data-panel="p5">
			<?php _e('Support', TEXT_DOMAIN); ?>
		</button>
	</div>


	<!-- CONTENT -->
	<div class="alt-tabs-content">

	<div class="alt-panel active" id="p1">
      
	<div class="changelog-wrapper terminal-cli">

		<div class="changelog-header">
			<h2>
				📋 <?php _e('Changelog', TEXT_DOMAIN); ?>
			</h2>
			<p>
				<?php _e('Latest updates & improvements', TEXT_DOMAIN); ?>
			</p>
		</div>

		<div class="changelog">
			<?php
			$html = file_get_contents(WEB_CHANGELOG);
			echo $html;
			?>
		</div>
		
	</div>
	
	</div>

	<div class="alt-panel" id="p2">    
		
		<div class="terminal-cli">
		
		<div class="changelog-header">
			<h2>
				🎬 <?php _e('How to Import Demo', TEXT_DOMAIN); ?>
			</h2> 
		</div>

		<div class="youtube-terminal">
			<!--<div class="prompt">$</div>-->
			<div class="youtube-responsive">
				<iframe 
					src="https://www.youtube.com/embed/<?php echo IDIFRAMEYUTUBE; ?>" 
					title="YouTube video player" 
					frameborder="0"
					allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" 
					allowfullscreen>
				</iframe>
			</div>
		</div>
	</div>

 
	</div>
	
	<div class="alt-panel" id="p3">

		<div class="terminal-cli">
		
			<div class="changelog-header">
				<h2>💻 <?php _e('System Info', TEXT_DOMAIN); ?></h2>
				<p><?php _e('Memory & PHP Infos & Server Environment', TEXT_DOMAIN); ?></p>
			</div>

			<div class="system-info">
				<?php
				echo sprintf(
					esc_html__('Memory Limit: %s', TEXT_DOMAIN),
					'<b class="text-info">' . esc_html(ini_get('memory_limit')) . '</b>'
				) . '<br>';

				echo sprintf(
					esc_html__('Post Max Size: %s', TEXT_DOMAIN),
					'<b class="text-info">' . esc_html(ini_get('post_max_size')) . '</b>'
				) . '<br>';

				echo sprintf(
					esc_html__('PHP Version: %s (Required PHP 7.4+)', TEXT_DOMAIN),
					'<b class="text-info">' . esc_html(phpversion()) . '</b>'
				) . '<br>';

				echo sprintf(
					esc_html__('OS: %s and %s', TEXT_DOMAIN),
					'<b class="text-info">' . esc_html(php_uname()) . '</b>',
					'<b class="text-info">' . esc_html(PHP_OS) . '</b>'
				) . '<br>';

				if ( ini_get('allow_url_fopen') ) {
					echo esc_html__('allow_url_fopen is ENABLED', TEXT_DOMAIN) . ' <b class="text-info">ENABLED</b><br>';
				} else {    
					echo esc_html__('allow_url_fopen is DISABLED. Please turn it ON (Required allow_url_fopen)', TEXT_DOMAIN) . ' <u class="cool-link">ON</u><br>';
				}
				?>
			</div>

		</div>


	</div>
	
	<div class="alt-panel" id="p4">
	
	<div class="terminal-cli">
	
		<div class="changelog-header">          
			<p>
				<?php
				// translators: %1$s = product name, %2$s = product version
				printf(
					esc_html__('How to Get a License Key %1$s v.%2$s?', TEXT_DOMAIN),
					esc_html(PRODUCT_NAME),
					esc_html(PRODUCT_VERSIONS)
				);
				?>
			</p> 
		</div>

		<ol class="terminal-list">
			<li>
				<span class="cli-prompt">$</span>
				<?php _e('If you already bought', TEXT_DOMAIN); ?> 
				<i class="fa fa-hand-o-right cli-icon"></i> 
				<b><a href="<?php echo esc_url(EXTHEMES_MEMBER_URL); ?>" target="_blank"><?php _e('Login to the member area', TEXT_DOMAIN); ?></a></b>
			</li>
			<li>
				<span class="cli-prompt">$</span>
				<?php _e('If you forget your License Key', TEXT_DOMAIN); ?> 
				<i class="fa fa-hand-o-right cli-icon"></i> 
				<b><a href="<?php echo esc_url(EXTHEMES_HOW_TO); ?>" target="_blank"><?php _e('See My License Key', TEXT_DOMAIN); ?></a></b>
			</li>
			<li>
				<span class="cli-prompt">$</span>
				<?php _e("If you haven't bought yet", TEXT_DOMAIN); ?> 
				<i class="fa fa-hand-o-right cli-icon"></i> 
				<b><a href="<?php echo esc_url(EXTHEMES_ITEMS_URL); ?>" target="_blank">
					<?php printf(__('Buy %s', TEXT_DOMAIN), esc_html(EXTHEMES_NAME)); ?>
				</a></b>
			</li>
		</ol>


	</div>
 
	
	</div>

	<div class="alt-panel" id="p5">
		<div class="terminal-cli">
		
		<div class="changelog-header">
			<h2>💰 <?php _e('Donate & Support', TEXT_DOMAIN); ?></h2>
			<p><?php _e('If this theme helps you save time and grow your website, please consider supporting development through a donation.', TEXT_DOMAIN); ?></p>
		</div>

		<ul class="terminal-listx">
			<li><span class="cli-prompt">$</span> <?php _e('☕ Help maintain updates', TEXT_DOMAIN); ?></li>
			<li><span class="cli-prompt">$</span> <?php _e('🚀 Fund new features', TEXT_DOMAIN); ?></li>
			<li><span class="cli-prompt">$</span> <?php _e('🛠 Faster bug fixes', TEXT_DOMAIN); ?></li>
		</ul>

			<hr>
			<!-- WhatsApp Support -->
			<div class="ai-donate-btn" style="margin:10px 0;">
				<strong>💬 <?php _e('Support via WhatsApp', TEXT_DOMAIN); ?></strong>
				<br>
				<button onclick="window.open('https://wa.me/62816200234?text=Hello%20Support', '_blank')" 
						style="background:#25D366; color:#fff; padding:8px 16px; border:none; border-radius:6px; cursor:pointer; font-weight:600; margin-top:6px; display:inline-flex; align-items:center; gap:6px;">
					<img src="https://upload.wikimedia.org/wikipedia/commons/6/6b/WhatsApp.svg" 
						 style="height:20px;" alt="WhatsApp">
					<?php _e('Contact us', TEXT_DOMAIN); ?>
				</button>
			</div>

			

			<!-- PayPal -->
			<div class="ai-donate-btn">
				<a href="https://paypal.me/exthemesdevs" target="_blank">
					<img alt="PayPal" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4nICAnaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkJz48c3ZnIGhlaWdodD0iNTEycHgiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDUxMiA1MTI7IiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCA1MTIgNTEyIiB3aWR0aD0iNTEycHgiIHhtbDpzcGFjZT0icHJlc2VydmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxnIGlkPSJfeDMyXzUwLXBheXBhbCI+PGc+PHBhdGggZD0iTTI1MC41ODUsMjcxLjg3NGM2OC41NjYtMC44MTEsMTIwLjI5OS0yOC4wOTcsMTQyLjEwNi05MS41OTMgICAgYzIxLjkxMS02MS42NzEsMTYuMzMyLTExOC42NzYtNDQuNjMtMTQyLjMxMWMtMzkuNDU3LTE1LjMxNi01Mi40NDEtMTEuNTYzLTIwNi45MjMtMTEuNTYzYy0xMC4wNDIsMC0xOC43NjUsNy40MDUtMjAuMjg4LDE3LjE0MiAgICBMNjEuNDEyLDQyMC43NzhjLTEuMDE0LDcuNDA0LDQuNTY0LDE0LjA5OSwxMi4yNzIsMTQuMDk5aDc1LjY2OWMyLjAyOSwwLDIuNzM4LTAuNzA4LDMuMDQzLTIuNTM0ICAgIGM0LjE1OC0yNS42NjQsMTguMjU5LTExNi40NDcsMjEuODA4LTEzNS45MjJDMTgwLjA4OSwyNjQuNzc0LDIwNi41NjMsMjcyLjU4NiwyNTAuNTg1LDI3MS44NzR6IiBzdHlsZT0iZmlsbDojMDAyRDhBOyIvPjxwYXRoIGQ9Ik00MjMuNDI3LDE1MC40NmMtMS44MjYtMS4zMTktMi41MzYtMS44MjctMy4wNDMsMS4zMTdjLTIuMDI5LDExLjU2NS01LjE3MywyMi44MjMtOC45MjcsMzQuMDgzICAgIEMzNzAuOTg1LDMwMS4yOSwyNTguOCwyOTEuMjQ5LDIwNC4wMjYsMjkxLjI0OWMtNi4xODgsMC0xMC4yNDUsMy4zNDgtMTEuMDU3LDkuNTM0ICAgIGMtMjIuOTIzLDE0Mi40MTEtMjcuNDg4LDE3Mi4xMzEtMjcuNDg4LDE3Mi4xMzFjLTEuMDE1LDcuMjAyLDMuNTUsMTMuMDg1LDEwLjc1MiwxMy4wODVoNjQuNDFjOC43MjMsMCwxNS45MjUtNi4zOTEsMTcuNjUtMTUuMTEyICAgIGMwLjcwOS01LjQ3OS0xLjExNSw2LjE4NywxNC42MDYtOTIuNjA5YzQuNjY1LTIyLjMxNCwxNC41MDQtMTkuOTgsMjkuNzE5LTE5Ljk4YzcyLjAxOSwwLDEyOC4yMTEtMjkuMjE0LDE0NC45NDgtMTEzLjkxICAgIEM0NTQuMTYxLDIwOS4wODgsNDUyLjIzNCwxNzEuOTYzLDQyMy40MjcsMTUwLjQ2eiIgc3R5bGU9ImZpbGw6IzAxOUJFMTsiLz48L2c+PC9nPjxnIGlkPSJMYXllcl8xIi8+PC9zdmc+" style="vertical-align:middle; height:30px;">
					<?php _e('Donate via PayPal', TEXT_DOMAIN); ?>
				</a>
			</div>

			<!-- Bitcoin -->
			<div class="ai-crypto-box">
				<strong>₿ <?php _e('Donate via Bitcoin', TEXT_DOMAIN); ?></strong>
				<textarea class="aps-textarea" readonly onclick="this.select()">AK4yetqZNDYyQdLKZVHqRh9HpdxdAEhyy</textarea>
			</div>

			<!-- Tether USDT -->
			<div class="ai-crypto-box">
				<strong>🪙 <?php _e('Donate via Tether (USDT – TRC20)', TEXT_DOMAIN); ?></strong>
				<textarea class="aps-textarea" readonly onclick="this.select()">TSP7i8XuRvbQQ5VfhDC2EwL8XMucvU4Qr1</textarea>
			</div>

			<!-- Ethereum -->
			<div class="ai-crypto-box">
				<strong>🪙 <?php _e('Donate via Ethereum (ERC-20 / ETH)', TEXT_DOMAIN); ?></strong>
				<textarea class="aps-textarea" readonly onclick="this.select()">0x94fcbd06a3f700898ba750fc942d726b86da1f5f</textarea>
			</div>
			
		</div>
	</div>
 
	</div>
	</div>
	</div>
	
	<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
	<style>
	.terminal-cli{font-family:'JetBrains Mono','Courier New',monospace;max-width:900px;background:#ffffff;border-radius:12px;box-shadow:0 10px 30px rgba(0,0,0,.08);font-family:"Courier New",Courier,monospace;color:#000000}
	.terminal-cli .changelog-header h2{margin-bottom:0;font-size:1.6rem}
	.terminal-cli .changelog-header p{margin-top:4px;color:#555;font-size:0.9rem}
	.changelog h3{font-weight:bolder;margin:1rem 0 0.5rem 0;cursor:pointer;padding:0.2rem 0;position:relative;font-size:1rem!important}
	.changelog h3::before{content:"@<?php echo THEMES_NAMES;?>:~$ ";color:#000;font-weight:bolder}
	.changelog h3{position:relative;margin:20px 0 10px;padding-left:20px;cursor:pointer;font-weight:bold;font-size:unset}
	.changelog h3::after{content:"↓";position:absolute;right:0;top:0;color:#2563eb;font-weight:bold}
	.changelog h3.collapsed::after{content:"→"}
	.changelog ul{list-style:none;padding-left:20px;margin:0 0 10px 0}
	.changelog ul li{padding:2px 0;font-size:0.95rem;border-left:2px solid #e5e7eb;padding-left:10px;opacity:0;transform:translateX(-10px);transition:all 0.3s ease-out}
	.changelog ul li.show{opacity:1;transform:translateX(0)}
	.label-gradient{font-weight:600;background:linear-gradient(90deg,#f97316,#3b82f6,#16a34a,#f43f5e);-webkit-background-clip:text;-webkit-text-fill-color:transparent}
	.changelog ul.collapsed{display:none}
	.changelog{max-height:70vh;overflow-y:auto;scroll-behavior:smooth}
	@media (max-width:640px){.changelog{padding:10px 0}
	}
	.prefix-add{color:#16a34a;font-weight:600}
	.prefix-fix{color:#f97316;font-weight:600}
	.prefix-improve{color:#3b82f6;font-weight:600}
	.prefix-remove{color:#ef4444;font-weight:600}
	.changelog ul li span.text-white{color:#000000}
	.terminal-cli .changelog-header p{margin-top:4px;color:#555;font-size:0.9rem}
	.system-info b.text-info{color:#e83e8c;font-weight:bold;font-size:0.9rem}
	.cool-link{color:#2563eb;font-weight:bold;text-decoration:underline}
	.youtube-terminal{position:relative;border:1px solid #e5e7eb;border-radius:10px;padding:10px}
	.youtube-terminal .prompt{font-weight:bold;color:#2563eb;margin-bottom:6px}
	.youtube-responsive{position:relative;width:100%;padding-bottom:56.25%;height:0}
	.youtube-responsive iframe{position:absolute;top:0;left:0;width:100%;height:100%;border-radius:6px}
	.aps-tab-content.active{display:block}
	.terminal-cli .terminal-list{list-style:none;padding-left:0;margin-top:20px}
	.terminal-cli .terminal-list li{margin-bottom:12px;line-height:1.5;font-size:0.95rem}
	.terminal-cli .cli-prompt{color:#2563eb;font-weight:bold;margin-right:6px}
	.terminal-cli .cli-icon{color:#3c763d;margin:0 6px}
	.terminal-cli a{color:#3c763d;text-decoration:none}
	.terminal-cli a:hover{color:#2563eb}
	.terminal-cli .terminal-list li::marker{content:none}
	.aps-tab-content.active{display:block}
	.cli-prompt{color:#2563eb;font-weight:bold;margin-right:6px}
	.ai-crypto-box{margin-top:12px}
	.ai-crypto-box strong{display:block;margin-bottom:4px}
	.aps-textarea{width:100%;min-height:28px;font-family:"Courier New",monospace;font-size:0.9rem;padding:6px 10px;border-radius:6px;border:1px solid #d1d5db;resize:none;background:#f9fafb;color:#000;cursor:pointer}
	.aps-textarea:focus{outline:none;border-color:#2563eb;background:#f3f4f6}
	.ai-donate-btn a{display:inline-flex;align-items:center;gap:8px;text-decoration:none;font-weight:bold;color:#2563eb;margin-top:10px}
	.ai-donate-btn img{height:30px}
	.aps-tab-content.active{display:block}
	</style>

	<script>
	document.addEventListener("DOMContentLoaded",()=>{const titles=document.querySelectorAll(".changelog h3");titles.forEach((h3,index)=>{const ul=h3.nextElementSibling;if(!ul || ul.tagName !=="UL")return;if(index===0){h3.classList.add("latest");}else{ul.classList.add("collapsed");h3.classList.add("collapsed");}h3.addEventListener("click",()=>{titles.forEach(otherH3=>{const otherUl=otherH3.nextElementSibling;if(!otherUl || otherUl.tagName !=="UL")return;otherUl.classList.add("collapsed");otherH3.classList.add("collapsed");});ul.classList.remove("collapsed");h3.classList.remove("collapsed");ul.querySelectorAll("li").forEach((li,i)=>{li.classList.remove("show");setTimeout(()=>li.classList.add("show"),i * 100);});});});document.querySelectorAll(".changelog li").forEach((li,index)=>{const text=li.textContent.trim();const lower=text.toLowerCase();let prefix="";let className="";if(lower.startsWith("add")){prefix="[ADD]";className="prefix-add";}else if(lower.startsWith("fix")){prefix="[FIX]";className="prefix-fix";}else if(lower.startsWith("improve")){prefix="[IMPROVE]";className="prefix-improve";}else if(lower.startsWith("remove")){prefix="[REMOVE]";className="prefix-remove";}if(prefix){li.innerHTML=`<span class="${className}">${prefix}</span>– ${text}`;setTimeout(()=>li.classList.add("show"),index * 100);}});const tabs=document.querySelectorAll('.alt-tab');const panels=document.querySelectorAll('.alt-panel');let activeTabId=localStorage.getItem('activeAltTab');if(activeTabId){tabs.forEach(tab=>tab.classList.remove('active'));panels.forEach(panel=>panel.classList.remove('active'));const lastTab=document.querySelector(`.alt-tab[data-panel="${activeTabId}"]`);const lastPanel=document.getElementById(activeTabId);if(lastTab && lastPanel){lastTab.classList.add('active');lastPanel.classList.add('active');}}else{if(tabs[0] && panels[0]){tabs[0].classList.add('active');panels[0].classList.add('active');}}tabs.forEach(tab=>{tab.addEventListener('click',()=>{tabs.forEach(t=>t.classList.remove('active'));panels.forEach(p=>p.classList.remove('active'));tab.classList.add('active');const panel=document.getElementById(tab.dataset.panel);if(panel)panel.classList.add('active');localStorage.setItem('activeAltTab',tab.dataset.panel);});});});
	</script>
		
	<?php
    }
	
    // ----------------------------------------------------
    // 2d. Halaman lisensi
    // ----------------------------------------------------
	function license_page(){
		
        $strings = $this->strings;
        $license = trim( get_option( $this->theme_slug . '_license_key' ) );

        if( ! $license ){
            $message = $strings['enter-key']; // License kosong
        } else {
            delete_transient( $this->theme_slug.'_license_message' ); // Hapus cache lama
            if( ! get_transient( $this->theme_slug.'_license_message', false ) ){
                set_transient( $this->theme_slug.'_license_message', $this->check_license(), ( 60 * 60 * 24 ) );
            }
            $message = get_transient( $this->theme_slug.'_license_message' );
        }

        $status = get_option( $this->theme_slug.'_license_key_status', false );

        // Request API lisensi ke server eksternal edd
        $api_params = array(
            'edd_action' => 'check_license',
            'license'    => $license,
            'item_name'  => urlencode( $this->item_name ),
            'url'        => home_url('/')
        );
        $response = $this->get_api_response( $api_params );
        $license_data = json_decode( wp_remote_retrieve_body( $response ) );
		
		
		//print_r($api_params);

        $site_count    = isset( $license_data->site_count ) ? $license_data->site_count : '';
        $customer_name = isset( $license_data->customer_name ) ? $license_data->customer_name : '';
        $customer_email= isset( $license_data->customer_email ) ? $license_data->customer_email : '';
        $license_limit = isset( $license_data->license_limit) ? $license_data->license_limit : '';  

        $expires = false;
        if( isset( $license_data->expires ) && 'lifetime' != $license_data->expires ){
            $expires = date_i18n( get_option( 'date_format' ), strtotime( $license_data->expires, current_time( 'timestamp' ) ) );
            $renew_link = '<a href="' . esc_url( $this->get_renewal_link() ) . '" target="_blank">' . $strings['renew'] . '</a>';
        } elseif( isset( $license_data->expires ) && 'lifetime' == $license_data->expires ){
            $expires = 'lifetime';
        }

        if( 0 == $license_limit ){
            $license_limit = $strings['unlimited'];
        }

        $gravatar_link = '//gravatar.com/avatar/'.md5($customer_email);

        $user_info    = get_userdata(1); // User ID 1 (admin)
        $author_names = $user_info->user_login;
		
		$license_page_html_code   = $this->render_license_page($license, $status, $customer_name, $customer_email, $site_count, $license_limit, $expires, $message, $author_names, $gravatar_link, $strings);
		
		echo $license_page_html_code;
		  
		?>
	 
		<?php
	}  
	
	// ----------------------------------------------------
	// Fungsi untuk menyembunyikan sebagian license / email
	// ----------------------------------------------------        
	function get_hidden_license( $license ){
		if( !$license )
		return $license;
		$start = substr( $license, 0, 7 );
		$finish = substr( $license, -7 );
		$license = $start.'**********'.$finish;		
		//$license = 'License*****Hiden';
		return $license;
	}
	
	function get_hidden_email( $customer_email ){
		if( !$customer_email ) return $customer_email;
		$customer_email = substr($customer_email,0,7).'*****'.substr($customer_email,-8);
		return $customer_email;
	}
		
	function get_hidden_email2( $customer_email ){
		if( !$customer_email )
		return $customer_email;
		$start = substr( $customer_email, 0, 7 );
		$finish = substr( $customer_email, -8 );
		$customer_email = $start.'*****'.$finish;
		return $customer_email;
	}
	
	// ----------------------------------------------------
    // 2e. Register option license key
    // ----------------------------------------------------    
	function register_option(){
		register_setting(
			$this->theme_slug . '',
			$this->theme_slug . '_license_key',
			array( $this, 'sanitize_license' )
		);
	}	

    // ----------------------------------------------------
    // Sanitasi input license key
    // ----------------------------------------------------    
	function sanitize_license( $new ){
		$old = get_option( $this->theme_slug . '_license_key' );
		if( $old && $old != $new ){
			delete_option( $this->theme_slug . '_license_key_status' );
			delete_transient( $this->theme_slug . '_license_message' );
		}
		return $new;
	}
	
    // ----------------------------------------------------
    // Fungsi kirim request API
    // ----------------------------------------------------    
	function get_api_response( $api_params ){
		$response = wp_remote_post( $this->remote_api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
		return $response;
	}

    // ----------------------------------------------------
    // 2f. Activate license
    // ----------------------------------------------------    
	function activate_license(){
		$license = trim( get_option( $this->theme_slug . '_license_key' ) );
		$api_params = array(
			'edd_action' => 'activate_license',
			'license'    => $license,
			'item_name'  => urlencode( $this->item_name ),
			'url'        => home_url('/')
		);
		$response = $this->get_api_response( $api_params );
		if( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ){
			if( is_wp_error( $response ) ){
				$message = $response->get_error_message();
			} else{
				$message = __( 'An error occurred, please try again.', TEXT_DOMAIN );
			}
		} else{
			$license_data = json_decode( wp_remote_retrieve_body( $response ) );
			if( false === $license_data->success ){
				
                // Pesan error berdasarkan tipe error
                switch( $license_data->error ){
                    case 'expired' : $message = sprintf(__('Your license code has expired on%s.', TEXT_DOMAIN), date_i18n(get_option('date_format'), strtotime($license_data->expires))); break;
                    case 'revoked' : $message = __('Your license code has been disabled and can no longer be used.', TEXT_DOMAIN); break;
                    case 'missing' : $message = __('Invalid license.', TEXT_DOMAIN); break;
                    case 'invalid' :
                    case 'site_inactive' : $message = __('Your license is currently inactive on this website.', TEXT_DOMAIN); break;
                    case 'item_name_mismatch' : $message = sprintf(__('This license code does not appear to be valid for %s.', TEXT_DOMAIN), $this->item_name); break;
                    case 'no_activations_left': $message = __('Your license code has reached the limit of license activation.', TEXT_DOMAIN); break;
                    default : $message = __('An error occurred, please try again.', TEXT_DOMAIN); break;
                }
				
				// Redirect jika error
				if( ! empty( $message ) ){
					/*
					/wp-admin/admin.php?page=license
					*/
					$base_url = admin_url( 'admin.php?page=' . $this->theme_slug . '' );
					$redirect = add_query_arg( array( 'sl_theme_activation' => 'false', 'message' => urlencode( $message ) ), $base_url );
					wp_redirect( $redirect );
					exit();
				}
			}
		}
		
        // Update status license jika sukses
		if( $license_data && isset( $license_data->license ) ){
			update_option( $this->theme_slug . '_license_key_status', $license_data->license );
			delete_transient( $this->theme_slug . '_license_message' );
		}
		wp_redirect( admin_url( 'admin.php?page=' . $this->theme_slug . '' ) );
		exit();
	}
	
    // ----------------------------------------------------
    // 2g. Deactivate license
    // ----------------------------------------------------
	function deactivate_license(){
		$license = trim( get_option( $this->theme_slug . '_license_key' ) );
		$api_params = array(
			'edd_action' => 'deactivate_license',
			'license'    => $license,
			'item_name'  => urlencode( $this->item_name ),
			'url'        => home_url('/')
		);
		$response = $this->get_api_response( $api_params );
		if( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ){
			if( is_wp_error( $response ) ){
				$message = $response->get_error_message();
			} 
			else{
				$message = __( 'An error occurred, please try again.', TEXT_DOMAIN );
			}
		} 
		else{
			$license_data = json_decode( wp_remote_retrieve_body( $response ) );
			if( $license_data && ( $license_data->license == 'deactivated' ) ){
				delete_option( $this->theme_slug . '_license_key' );
				delete_option( $this->theme_slug . '_license_key_status' );
				delete_transient( $this->theme_slug . '_license_message' );
			}
		}

        // Redirect setelah deactivation
		if( ! empty( $message ) ){
			$base_url = admin_url( 'admin.php?page=' . $this->theme_slug . '' );
			$redirect = add_query_arg( array( 'sl_theme_activation' => 'false', 'message' => urlencode( $message ) ), $base_url );
			wp_redirect( $redirect );
			exit();
		}
		wp_redirect( admin_url( 'admin.php?page=' . $this->theme_slug . '' ) );
		exit();
	}

    // ----------------------------------------------------
    // 2h. Change license
    // ----------------------------------------------------
	function change_license(){
		delete_option( $this->theme_slug . '_license_key' );
		delete_option( $this->theme_slug . '_license_key_status' );
		delete_transient( $this->theme_slug . '_license_message' );
		wp_redirect( admin_url( 'admin.php?page=' . $this->theme_slug . '' ) );
		exit();
	}

    // ----------------------------------------------------
    // 2i. Dapatkan link perpanjangan
    // ----------------------------------------------------
	function get_renewal_link(){
		if( '' != $this->renew_url ){
			return $this->renew_url;
		}
		$license_key = trim( get_option( $this->theme_slug . '_license_key', false ) );
		if( '' != $this->download_id && $license_key ){
			$url = esc_url( $this->remote_api_url );
			$url .= '/checkout/?edd_license_key=' . $license_key . '&download_id=' . $this->download_id;
			return $url;
		}
		return $this->remote_api_url;
	}

    // ----------------------------------------------------
    // 2j. Proses activate / deactivate / change
    // ----------------------------------------------------
	function license_action(){
		if( isset( $_POST[ $this->theme_slug . '_license_activate' ] ) ){
			if( check_admin_referer( $this->theme_slug . '_nonce', $this->theme_slug . '_nonce' ) ){
				$this->activate_license();
			}
		}
		if( isset( $_POST[$this->theme_slug . '_license_deactivate'] ) ){
			if( check_admin_referer( $this->theme_slug . '_nonce', $this->theme_slug . '_nonce' ) ){
				$this->deactivate_license();
			}
		}
		if( isset( $_POST[$this->theme_slug . '_license_change'] ) ){
			if( check_admin_referer( $this->theme_slug . '_nonce', $this->theme_slug . '_nonce' ) ){
				$this->change_license();
			}
		}
	}

    // ----------------------------------------------------
    // 2k. Check license status
    // ----------------------------------------------------
	function check_license(){
		$license = trim( get_option( $this->theme_slug . '_license_key' ) );
		$strings = $this->strings;
		$api_params = array(
			'edd_action' => 'check_license',
			'license'    => $license,
			'item_name'  => urlencode( $this->item_name ),
			'url'        => home_url('/')
		);
		$response = $this->get_api_response( $api_params );
		if( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ){
			if( is_wp_error( $response ) ){
				$message = $response->get_error_message();
				if( strpos( $message, 'Could not resolve host' ) !== false ){
					$message = esc_html__( 'Could not connect to license server', TEXT_DOMAIN );
				}
			} 
			else{
				$message = $strings['license-status-unknown'];
			}
		} else{
			$license_data = json_decode( wp_remote_retrieve_body( $response ) );
			if( !isset( $license_data->license ) ){
				$message = $strings['license-status-unknown'];
				return $message;
			}
			if( $license_data && isset( $license_data->license ) ){
				update_option( $this->theme_slug . '_license_key_status', $license_data->license );
			}
			$expires = false;
			if( isset( $license_data->expires ) && 'lifetime' != $license_data->expires ){
				$expires = date_i18n( get_option( 'date_format' ), strtotime( $license_data->expires, current_time( 'timestamp' ) ) );
				$renew_link = '<a href="' . esc_url( $this->get_renewal_link() ) . '" target="_blank">' . $strings['renew'] . '</a>';
			} 
			elseif( isset( $license_data->expires ) && 'lifetime' == $license_data->expires ){
				$expires = 'lifetime';
			}
			$site_count			= isset( $license_data->site_count ) ? $license_data->site_count : '';
			$customer_name		= isset( $license_data->customer_name ) ? $license_data->customer_name : '';
			$customer_email		= isset( $license_data->customer_email ) ? $license_data->customer_email : '';
			$license_limit		= isset( $license_data->license_limit) ? $license_data->license_limit : '';
			if( 0 == $license_limit ){
				$license_limit	= $strings['unlimited'];
			}
			
			if( $license_data->license == 'valid' ){
				$message 		= $strings['license-key-is-active'] . ' ';
				if( isset( $expires ) && 'lifetime' != $expires ){
					$message .= ' <br>'.sprintf( $strings['expires%s'], $expires ) . ' ';
				}
				if( isset( $expires ) && 'lifetime' == $expires ){
					$message .= ' <br>'.$strings['expires-never'];
				}
				if( $site_count && $license_limit ){
					$message .= ' <br> '.sprintf( $strings['%1$s/%2$-sites'], $site_count, $license_limit );
				}
				if( $customer_name && $license_limit ){
					$message .=  ' <br> '.sprintf( $strings['customer-name-%1$s'], $customer_name, $license_limit );
				}
				if( $customer_email && $license_limit ){
					$message .=  ' <br> '.sprintf( $strings['customer-email-%1$s'], $customer_email, $license_limit );
				}
			} else if( $license_data->license == 'expired' ){
				if( $expires ){
					$message = ' <br>'.sprintf( $strings['license-key-expired-%s'], $expires );
				} else{
					$message = $strings['license-key-expired'];
				}
				if( $renew_link ){
					$message .= ' ' . $renew_link;
				}
			} else if( $license_data->license == 'invalid' ){
				$message = $strings['license-keys-do-not-match'];
			} else if( $license_data->license == 'inactive' ){
				$message = $strings['license-is-inactive'];
			} else if( $license_data->license == 'disabled' ){
				$message = $strings['license-key-is-disabled'];
			} else if( $license_data->license == 'site_inactive' ){
				$message = $strings['site-is-inactive'];
			} else{
				$message = $strings['license-status-unknown'];
			}
		}
		return $message;
	}

    // ----------------------------------------------------
    // 2l. Disable WP.org update
    // ----------------------------------------------------
	function disable_wporg_request( $r, $url ){
		if( 0 !== strpos( $url, 'https://api.wordpress.org/themes/update-check/1.1/' ) ){
			return $r;
		}
		$themes			= json_decode( $r['body']['themes'] );
		$parent			= get_option( 'template' );
		$child			= get_option( 'stylesheet' );
		unset( $themes->themes->$parent );
		unset( $themes->themes->$child );
		$r['body']['themes'] = json_encode( $themes );
		return $r;
	}
}

	// ----------------------------------------------------
	// 3️⃣ Admin notice untuk error lisensi
	// ----------------------------------------------------
	function exthemes_theme_license_admin_notices(){
		if( isset( $_GET['sl_theme_activation'] ) && ! empty( $_GET['message'] ) ){
			switch( $_GET['sl_theme_activation'] ){
				case 'false':
				$message = urldecode( $_GET['message'] );
				?>
				<div class="error">
					<p><?php echo $message; ?></p>
				</div>
				<?php
				break;
				case 'true':
				default:
				break;
			}
		}
	}
	add_action( 'admin_notices', 'exthemes_theme_license_admin_notices', 2 );

	// ----------------------------------------------------
	// 4️⃣ Disable auto update WP
	// ----------------------------------------------------
	//add_filter( 'auto_update_theme', 'edd_sample_disable_theme_autoupdates', 10, 2 );
	function edd_sample_disable_theme_autoupdates( $update, $theme ) {
		if ( PRODUCT_THEME_SLUG === $theme->theme ) {
			return false;
		}

		return $update;
	}