<?php
/**
 * Provide a admin area view for the plugin
 *
 * This file is used to markup the admin-facing aspects of the plugin.
 *
 * @link       https://codingfix.com
 * @since      1.0.0
 *
 * @package    Instalist
 * @subpackage Instalist/admin/partials
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
?>
<?php

WP_Filesystem();
global $wp_filesystem;

require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
?>
<section id="pluginer-options" class="wrap">
	<div id="saving-overlay" class="plgnr-page-overlay">
		<div id="loader-container">
			<div class="plgsspinner"></div>
		</div>
	</div>
	<div id="plgnr-content-wrapper">
		<div class="plgnrsection">
			<div id="working-overlay" class="plgnr-page-overlay"></div>
			<div class="import-section">
				<h2>Import list</h2>
				<?php
					$is_premium = apply_filters( 'pluginer_is_premium', false );

					$disabled = '';
					$args     = array(
						'post_type'      => 'plgnr_plugin_list',
						'posts_per_page' => -1,
					);
					$query    = new WP_Query( $args );
					if ( $query->found_posts < 1 || $is_premium ) {
						$disabled = apply_filters( 'pluginer_disabled_attr', $disabled );
					}
					?>
				<p>You can import a list from a file you have previously exported or even a file you have written down manually. The allowed file format is csv (each line corresponds to a plugin and the separator between plugin name and plugin slug must be a semicolon).<br />Just choose a file and click Import button.</p>
				<?php
				if ( ! $is_premium && $query->found_posts > 0 ) {
					echo '<div class="error notice"><p>Multi-lists management is a Premium feature. Upgrade to manage as many lists as you need!</p></div>';
				}

				// Mostra eventuali messaggi di errore.
				settings_errors( 'pluginer_import_error' );
				?>

				<div class="import-form-wrapper">
					<form id="import_plugin_list_form" method="post" action="admin-post.php" enctype="multipart/form-data"  multiple="false">
						<input type="hidden" name="action" value="plgnr_import_plugin_list" />
						<?php wp_nonce_field( 'plgnrimportpluginlist' ); ?>
						<?php
						if ( 'disabled' === $disabled ) {
							?>
							<button class="button-primary" disabled="disabled" title="You cannot import more than one list with the free version. Please upgrade to the premium version.">Choose a list (.csv)</button>
							<?php
						} else {
							?>
						<label for="import_list" class="btn">Choose a list (.csv)</label>
						<input type="file" name="import_list" id="import_list" style="display:none;" />
							<?php
						}
						?>
						<input type="submit" data-is-premium="<?php echo esc_attr( $is_premium ? 'true' : 'false' ); ?>" id="import_plugin_list_button" value="Import list" class="button-primary" <?php echo esc_html( $disabled ); ?> />
					</form>
				</div>
			</div>
		</div>

		<div class="plgnrsection">
		</div>

		<div class="plgnrsection">
		</div>

		<div class="plgnrsection">
			<!-- <input type="submit" value="Install and activate" class="button-primary save-changes" /> -->
		</div>
	</div>

</section>
