<div class="magazinestyle--getting-started--wrapper">
        <div id="magazinestyle-admin-about-page">
                <div class="magazinestyle-about-container  magazinestyle-admin-card magazinestyle-admin-card-header admin-grid-2">
                        <div class="magazinestyle-header-left admin-col">
                                <h2>
                                        <?php echo esc_html( $theme->get('Name') ); ?>
                                </h2>
                                <p>
                                        <?php esc_html_e( 'Multipurpose Premium WordPress Theme', 'magazine-style' ); ?>
                                </p>

               			 </div>
						<div class="magazinestyle-header-left admin-col">
							<div class="magazinestyle-card-header-button-group">							
								
								
								<a href="<?php echo esc_url( __( 'https://www.insertcart.com/product/magazine-style-wp-theme/', 'magazine-style' ) ); ?>" class="magazinestyle-admin-button" rel="noreferrer" target="_blank"><span class="dashicons dashicons-cart"></span><?php esc_html_e( 'Get Pro', 'magazine-style' ); ?> </a>
								
								<a  href="<?php echo esc_url( __( 'https://www.insertcart.com/magazine-style-wp-theme-documentation-and-setup-guide/', 'magazine-style' ) ); ?>" class="magazinestyle-admin-button premium-button"
                                                target="_blank" rel="noreferrer"><span class="dashicons dashicons-book-alt"></span> <?php esc_html_e( 'Documentations', 'magazine-style' ); ?></a></div>
                        		</div>
							</div>
                <div class="magazinestyle-about-container subscribe-panel">
                        <div class="admin-col">
                                <div class="gutentor-get-started-content">
                                        <h3><?php esc_html_e( 'Magazine Style Theme', 'magazine-style' ); ?></h3>
                                        <p><?php esc_html_e( 'Magazine Style is a sleek and modern WordPress theme designed for Full Site Editing (FSE). It is optimized for speed and performance, ensuring your website loads quickly and efficiently. With its pre-built block patterns, you can easily create stunning layouts and customize your site design without writing a single line of code. magazinestyle is also mobile-friendly, SEO-optimized, and translation-ready, making it a versatile choice for businesses of all sizes.', 'magazine-style' ); ?></p>
                                      
                                </div>
                        </div>
                       
                      
                </div>
                <div class="magazinestyle-about-container magazinestyle-compare-table">
                        <div class="admin-grid-1">
                                <h3>
                                        <?php esc_html_e( 'Compare Free Vs Pro', 'magazine-style' ); ?>
									</h3>
									<p class="magazinestyle-compare-table-subtitle"><a href="<?php echo esc_url( __( 'https://www.insertcart.com/product/magazine-style-wp-theme/', 'magazine-style' ) ); ?>" target="__blank"><?php esc_html_e( 'Checkout all features', 'magazine-style' ); ?> <i class="dashicons dashicons-arrow-right-alt"></i></a></p>
                                <table>
                                        <thead>
                                                <tr>
                                                        <th>
                                                                <?php esc_html_e( 'Features', 'magazine-style' ); ?>
                                                        </th>
                                                        <th>
                                                                <?php esc_html_e( 'Magazine Style Free', 'magazine-style' ); ?>
                                                        </th>
                                                        <th>
                                                                <?php esc_html_e( 'Magazine Style Pro', 'magazine-style' ); ?>
                                                        </th>
                                                </tr>
                                        </thead>
                                        <tbody>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Responsive Design', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Painless Setup', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Color Options', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Premium site demos', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Multiple Block Layout', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Premium Patterns', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Multiple Fonts', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Slider Block ', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Post Listing Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'WooCommerce Filter Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Gallery Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Star Rating Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Icon Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Post Carousel Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Google Map Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Testimonials Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                <?php esc_html_e( 'Team Block', 'magazine-style' ); ?>
                                                                </th>
                                                        <td><span class="dashicons dashicons-no"></span></th>
                                                        <td><span class="dashicons dashicons-yes"></span></th>
                                                </tr>
                                        </tbody>
                                </table>
                        </div>
                </div>

                <div class="feature-list">
                        <div class="magazinestyle-about-container magazinestyle-about-content">
                                <div class="magazinestyle-admin-card features">
                                        <h4 class="magazinestyle-admin-card-title is-medium is-sub"><?php esc_html_e( 'Magazine Style Core Features', 'magazine-style' ); ?>
                                        </h4>
                                        <ul class="magazinestyle-options-features">
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Global page settings(typography,
                                                        color, ...)', 'magazine-style' ); ?> </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Site Demo', 'magazine-style' ); ?>   </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Predefined sections', 'magazine-style' ); ?>   </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Fully Responsive', 'magazine-style' ); ?>   </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Highly customizable row columns', 'magazine-style' ); ?>
                                                </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Color Options', 'magazine-style' ); ?>   </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Device specific responsive controls', 'magazine-style' ); ?>
                                                </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Google fonts', 'magazine-style' ); ?> </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Classic &amp; gradient color and
                                                        background', 'magazine-style' ); ?></li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Box-shadow', 'magazine-style' ); ?></li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Border', 'magazine-style' ); ?> </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Advanced Typography', 'magazine-style' ); ?> </li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( 'Pre build pattrens', 'magazine-style' ); ?></li>
                                                <li><span class="dashicons dashicons-yes"></span>
												<?php esc_html_e( '&amp; More...', 'magazine-style' ); ?> </li>
                                        </ul>
                                </div>
                        </div>
                        <div class="magazinestyle-about-side">
                                <div class="magazinestyle-admin-card member"><span><i class="fa fa-star"
                                                        aria-hidden="true"></i> <i class="fa fa-star"
                                                        aria-hidden="true"></i> <i class="fa fa-star"
                                                        aria-hidden="true"></i> <i class="fa fa-star"
                                                        aria-hidden="true"></i> <i class="fa fa-star"
                                                        aria-hidden="true"></i></span>
                                        <h3 class="magazinestyle-admin-card-title is-small"><?php esc_html_e( 'Love our product?', 'magazine-style' ); ?>
                                        </h3>
                                        <h4 class="magazinestyle-admin-card-title is-small"><?php esc_html_e( 'Motivate us by
                                                giving 5 star on
                                                our profile.', 'magazine-style' ); ?></h4><a
                                                href="https://wordpress.org/support/theme/magazine-style/reviews/?filter=5"
                                                class="magazinestyle-admin-button large magazinestyle-block is-default"
                                                target="__blank"><?php esc_html_e( 'Rate Us', 'magazine-style' ); ?></a>
                                </div>
                                <div class="magazinestyle-admin-card cart-two">
                                        <h3 class="magazinestyle-admin-card-title is-small"><?php esc_html_e( 'Still have question?
                                                Ask Us, now!', 'magazine-style' ); ?>
                                        </h3>
                                        <p><?php esc_html_e( 'We are always ready with all fix issues you stuck to ensure smoothly works with magazinestyle', 'magazine-style' ); ?></p><a href="<?php echo esc_url( __( 'https://www.insertcart.com/contact-us/', 'magazine-style' ) ); ?>"
                                                class="magazinestyle-admin-button primary large magazinestyle-block"><?php esc_html_e( 'Get Support', 'magazine-style' ); ?></a>
								<a  href="<?php echo esc_url( __( 'https://www.insertcart.com/magazine-style-wp-theme-documentation-and-setup-guide/', 'magazine-style' ) ); ?>" class="magazinestyle-admin-button premium-button"
                                                target="_blank" rel="noreferrer"><i class="fa fa-book"></i>
                                                <?php esc_html_e( 'Documentations', 'magazine-style' ); ?></a>
							
                                </div>
                        </div>
                </div>
					<?php echo magazinestyle_display_core(); ?>
        </div>
</div>
<?php
function magazinestyle_core_style() {

	// Set template directory uri
	$directory_uri = get_template_directory_uri();

	wp_enqueue_style( 'bootstrap', $directory_uri . '/inc/core/bootstrap/css/bootstrap.css' );
	wp_enqueue_style( 'bootstrap-responsive', $directory_uri . '/inc/core/bootstrap/css/bootstrap-responsive.css', 'bootstrap' );
	wp_enqueue_style( 'magazinestyle-responsive', $directory_uri . '/inc/core/bootstrap/css/responsive.css', array( 'bootstrap', 'bootstrap-responsive' ) );
	wp_enqueue_style( 'core_style', get_template_directory_uri() . '/inc/core/css/core.css' );
}
function magazinestyle_get_themes( $request ) {
    $key = 'magazinestyle_' . md5( wp_json_encode( $request ) );

    // Check transient cache first
    if ( false === ( $themes = get_transient( $key ) ) ) {
        // Build the query URL for the GET request
        $url = add_query_arg( $request, 'https://api.wordpress.org/themes/info/1.2/' );

        // Use GET instead of POST
        $response = wp_remote_get( $url );

        // Handle errors in response
        if ( is_wp_error( $response ) ) {
            return $response;
        }

        // Decode JSON response
        $themes = json_decode( wp_remote_retrieve_body( $response ) );

        // Validate the response
        if ( ! is_object( $themes ) || ! isset( $themes->themes ) ) {
            return new WP_Error( 'theme_api_error', 'Unexpected response format from the API' );
        }

        // Cache the result for 24 hours
        set_transient( $key, $themes, 60 * 60 * 24 );
    }

    return $themes;
}



function magazinestyle_enqueue_dashboard_scripts() {
    wp_enqueue_script( 'themeload', get_template_directory_uri() . '/js/themeload.js', array( 'jquery' ), null, true );

    // Fetch themes in PHP
    $request = array(
        'action'  => 'query_themes',
        'browse'  => 'popular', // Adjusted for API v1.2
    );
    $themes = magazinestyle_get_themes( $request );

    // Prepare themes data for frontend
    $themes_data = is_wp_error( $themes ) || ! isset( $themes->themes ) ? [] : $themes->themes;

    wp_localize_script( 'themeload', 'magazinestyleThemes', $themes_data );
}
add_action( 'wp_enqueue_scripts', 'magazinestyle_enqueue_dashboard_scripts' );
function magazinestyle_display_core() {
    ?>
    <div class="magazinestyle-about-container subscribe-panel">
        <div class="admin-col">
            <div class="gutentor-get-started-content">
                <h4 class="magazinestyle-admin-card-title is-medium is-sub"><?php esc_html_e( 'Amazing WP Themes', 'magazine-style' ); ?></h4>
                <div class="container-fluid">
                    <div id="core_container">
                        <div id="themes-container">
                            <!-- Themes will be dynamically loaded here -->
                        </div>
                        <div id="core_themes" class="row-fluid">
                            <?php
                            $request = array(
                                'action' => 'query_themes',
                                'author' => 'sandy786', // Filter by your author slug
                                'per_page' => 100,     // Fetch more themes (adjust if needed)
                            );

                            $themes = magazinestyle_get_themes( $request );							
							

                            // Handle errors or empty responses
                            if ( is_wp_error( $themes ) ) {
                                echo '<p>' . esc_html__( 'Failed to fetch themes. Please try again later.', 'magazine-style' ) . '</p>';
                                return;
                            }

                            if ( ! isset( $themes->themes ) || empty( $themes->themes ) ) {
                                echo '<p>' . esc_html__( 'No themes found.', 'magazine-style' ) . '</p>';
                                return;
                            }

                            $active_theme = wp_get_theme()->get( 'Name' );
							$counter = 1;

                            // For currently active theme.
					foreach ( $themes->themes as $theme ) {
						if( $active_theme == $theme->name ) {?>

							<div id="<?php echo $theme->slug; ?>" class="theme-container span3">
								<div class="image-container">
									<img class="theme-screenshot" src="<?php echo $theme->screenshot_url ?>"/>

									<div class="theme-description">
										<p><?php echo $theme->description; ?></p>
									</div>
								</div>
								<div class="theme-details active">
									<span class="theme-name"><?php echo $theme->name; ?><?php echo ': Current'; ?></span>
									<a class="button button-secondary customize right" target="_blank" href="<?php echo esc_url(home_url()). '/wp-admin/customize.php' ?>"><?php echo 'Customize'; ?></a>
								</div>
							</div>

						<?php
						$counter++;
						break;
						}
					}

					// For all other themes.
					foreach ( $themes->themes as $theme ) {
						if( $active_theme != $theme->name ) {

							// Set the argument array with author name.
							/* $args = array(
								'slug' => $theme->slug,
							); */

							// Set the $request array.
							/* $request = array(
								'body' => array(
									'action'  => 'theme_information',
									'request' => serialize( (object)$args )
								)
							); */
							//$theme_details = magazinestyle_get_themes( $request );
							?>

							<div id="<?php echo $theme->slug; ?>" class="theme-container span3 <?php echo $counter % 4 == 1 ? 'no-left-megin' : ""; ?>">
								<div class="image-container">
									<img class="theme-screenshot" src="<?php echo $theme->screenshot_url ?>"/>

									<div class="theme-description">
										<p><?php echo $theme->description; ?></p>
									</div>
								</div>
								<div class="theme-details">
									<span class="theme-name"><?php echo $theme->name; ?></span>

									<!-- Check if the theme is installed -->
									<?php if( wp_get_theme( $theme->slug )->exists() ) { ?>

										<!-- Show the tick image notifying the theme is already installed. -->									
										<span class="dashicons dashicons-yes" data-toggle="tooltip"    data-placement="bottom"  title="Already installed"  data-alt="Tick icon representing already installed theme" ></span>


										<!-- Activate Button -->
										<a  class="button button-primary activate right"
											href="<?php echo wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . urlencode( $theme->slug ) ), 'switch-theme_' . $theme->slug );?>" ><?php echo 'Activate'; ?></a>
									<?php }
									else {

										// Set the install url for the theme.
										$install_url = add_query_arg( array(
												'action' => 'install-theme',
												'theme'  => $theme->slug,
											), self_admin_url( 'update.php' ) );
									?>
									
									<?php 
										$downloaded_count = isset($theme_details->downloaded) ? (float) $theme_details->downloaded : 0;
										?>
										<a data-toggle="tooltip" data-placement="bottom" 
										   title="<?php echo 'Downloaded ' . number_format($downloaded_count) . ' times'; ?>" 
										   class="button button-primary install right" 
										   href="<?php echo esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ); ?>">
										   <?php echo 'Install Now'; ?>
										</a>
																						
									<?php } ?>
									<!-- Preview button -->
									<a class="button button-secondary preview right" target="_blank" href="<?php echo $theme->preview_url; ?>"><?php echo 'Live Preview'; ?></a>
								</div>
							</div>
							<?php
							$counter++;
						}
					}?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php
}
