<?php
/**
 * Plugin settings class
 *
 * @since  1.0.0
 *
 * @category  WordPress_Plugin
 * @package   QrCdr
 * @author    Nicola Franchini
 * @link      https://veno.es
 */

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

if ( ! class_exists( 'QRcdrSettings', false ) ) {

	/**
	 * QRcdrSettings class
	 */
	class QRcdrSettings {

		/**
		 * Settings name
		 *
		 * @var string
		 */
		public $settings = 'qrcdr-settings';

		/**
		 * Plugin options name for the license key.
		 *
		 * @var string
		 */
		private $options_name = 'qrcdr_options';

		/**
		 * Settings group name.
		 *
		 * @var string
		 */
		private $settings_group = 'qrcdr_settings_group';

		/**
		 * Settings slug
		 *
		 * @var string
		 */
		private $slug = 'qrcdr';

		/**
		 * Plugin's public display name.
		 *
		 * @var string
		 */
		private $plugin_name = 'QRcdr';

		/**
		 * The hook suffix for the settings page.
		 *
		 * @var string
		 */
		private $settings_page_hook = 'toplevel_page_qrcdr-settings';

		/**
		 * Holds an instance of the object
		 *
		 * @var instance
		 */
		protected static $instance = null;

		/**
		 * Returns the running object
		 *
		 * @return QRcdrSettings
		 */
		public static function get_instance() {
			if ( null === self::$instance ) {
				self::$instance = new self();
			}
			return self::$instance;
		}
		/**
		 * Start up
		 */
		public function __construct() {

			register_activation_hook( dirname( __DIR__ ) . '/' . qrcdr_plugin()->slug . '.php', array( $this, 'activate_plugin' ) );

			if ( is_admin() ) {
				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_settings_assets' ) );
				add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
				add_action( 'admin_init', array( $this, 'page_init' ) );
				$prefix = is_network_admin() ? 'network_admin_' : '';
				add_filter( $prefix . 'plugin_action_links_' . dirname( plugin_basename( __DIR__ ) ) . '/' . qrcdr_plugin()->slug . '.php', array( $this, 'action_links' ) );
				// Review notice.
				add_filter( 'admin_footer_text', array( $this, 'custom_admin_footer_text' ) );
			}
		}

		/**
		 * Add footer notice
		 *
		 * @param str $text Footer text.
		 *
		 * @return str notice text
		 */
		public function custom_admin_footer_text( $text ) {
			// Ottieni l'ID della schermata corrente.
			$screen = get_current_screen();

			if ( 'toplevel_page_qrcdr-settings' === $screen->id || strpos( $screen->id, 'qrcdr_page_' ) === 0 ) {
				$url = 'https://wordpress.org/support/plugin/qrcdr/reviews/?rate=5#new-post'; // Inserisci lo slug corretto del plugin.
				$text = sprintf(
					// Translators: plugin rating page.
					__( 'If you like <strong>QRcdr</strong> please leave us a <a href="%s" target="_blank">★★★★★</a> rating. A huge thanks in advance!', 'venobox' ),
					$url
				);
			}
			return $text;
		}

		/**
		 * Load admin script
		 *
		 * @param string $hook page hook.
		 */
		public function enqueue_settings_assets( $hook ) {

			$subpage_prefix = 'qrcdr_page_';

			// Skip non QRcdr pages.
			if ( $this->settings_page_hook !== $hook && strpos( $hook, $subpage_prefix ) !== 0 ) {
				return;
			}

			if ( ! did_action( 'wp_enqueue_media' ) ) {
				wp_enqueue_media();
			}

			$is_dev_mode = defined( 'WP_DEBUG' ) && WP_DEBUG;

			$script_dependencies = array( 'wp-element', 'wp-components', 'wp-i18n' );
			$style_dependencies  = array( 'wp-components' );

			// --- BUNDLE ADMIN ---
			$admin_script_path    = $is_dev_mode ? 'assets/js/admin.dev.js' : 'assets/js/admin.min.js';
			$admin_style_path     = $is_dev_mode ? 'assets/css/admin.css' : 'assets/css/admin.min.css';
			$script_version = $is_dev_mode ? filemtime( plugin_dir_path( __DIR__ ) . $admin_script_path ) : QRCDR_VERSION;
			$style_version  = $is_dev_mode ? filemtime( plugin_dir_path( __DIR__ ) . $admin_style_path ) : QRCDR_VERSION;

			// Registra gli asset per il pannello di amministrazione.
			wp_enqueue_script(
				'qrcdr-admin',
				plugin_dir_url( __DIR__ ) . $admin_script_path,
				$script_dependencies,
				$script_version,
				true
			);

			wp_enqueue_style(
				'qrcdr-admin',
				plugin_dir_url( __DIR__ ) . $admin_style_path,
				$style_dependencies,
				$style_version
			);

			wp_localize_script(
				'qrcdr-admin',
				'qrcdrAdminVars',
				array(
					'i18n' => array(
						'fgColor'    => esc_html__( 'Foreground color', 'qrcdr-pro' ),
						'bgColor'    => esc_html__( 'Background color', 'qrcdr-pro' ),
						'choosePlaceholder' => esc_html__( 'Choose Placeholder', 'qrcdr-pro' ),
						'chooseImage'       => esc_html__( 'Choose Image', 'qrcdr-pro' ),
						'chooseWatermarks'  => esc_html__( 'Choose Watermarks', 'qrcdr-pro' ),
					),
				)
			);
		}

		/**
		 * The links to show on the plugins overview page in an array.
		 *
		 * @param arr $links Links.
		 */
		public function action_links( $links ) {
			$store_link = '<a target="_blank" style="font-weight:bold" href="https://veno.es/shop/product/qrcdr-pro?utm_source=wp-plugin">' . __( 'Get PRO', 'qrcdr' ) . '</a>';
			$settings_link = '<a href="admin.php?page=' . $this->settings . '">' . __( 'Settings', 'qrcdr' ) . '</a>';
			array_unshift( $links, $store_link, $settings_link );
			return $links;
		}

		/**
		 * Add options page
		 */
		public function add_plugin_page() {
			add_menu_page(
				__( 'QRcdr Settings', 'qrcdr' ), // $page_title.
				__( 'QRcdr', 'qrcdr' ), // $menu_title.
				'manage_options', // $capability.
				$this->settings, // $menu_slug.
				array( $this, 'create_admin_page' ),
				'data:image/svg+xml;base64,' . base64_encode( '<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24"><polygon class="st0" points="15.3,15.3 15.3,13.1 13.1,13.1 13.1,19.6 15.3,19.6 15.3,21.8 13.1,21.8 13.1,24 15.3,24 15.3,21.8 17.5,21.8 17.5,15.3"/><rect x="21.8" y="21.8" class="st0" width="2.2" height="2.2"/><polygon class="st0" points="21.8,15.3 19.6,15.3 19.6,21.8 17.5,21.8 17.5,24 19.6,24 19.6,21.8 21.8,21.8 21.8,19.6 24,19.6 24,13.1 21.8,13.1"/><rect x="4.4" y="4.4" class="st0" width="2.2" height="2.2"/><path class="st0" d="M0,10.9h10.9V0H0V10.9z M2.2,2.2h6.5v6.5h0H2.2V2.2z"/><rect x="17.5" y="4.4" class="st0" width="2.2" height="2.2"/><path class="st0" d="M13.1,0v10.9H24V0H13.1z M21.8,8.7L21.8,8.7h-6.5V2.2h6.5V8.7z"/><rect x="4.4" y="17.4" class="st0" width="2.2" height="2.2"/><path class="st0" d="M0,24h10.9V13.1H0V24z M2.2,15.3h6.5v6.5h0H2.2V15.3z"/></svg>' )
			);
		}

		/**
		 * Controlla se un plugin specifico è installato e attivo.
		 * Presuppone che il codice venga eseguito nell'area di amministrazione.
		 *
		 * @param string $plugin_path Plugin path.
		 * @return bool True if active, False otherwise.
		 */
		public function is_plugin_installed( $plugin_path ) {

			$all_installed_plugins = get_plugins();

			if ( array_key_exists( $plugin_path, $all_installed_plugins ) ) {
				return is_plugin_active( $plugin_path );
			}
			return false;
		}

		/**
		 * Options page callback
		 */
		public function create_admin_page() {
			// Check user capabilities.
			if ( ! current_user_can( 'manage_options' ) ) {
				return;
			}
			settings_errors();
			// phpcs:ignore WordPress.Security.NonceVerification.Recommended
			$active_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'options';

			?>
			<div class="wrap qrcdr-tab-nav">
				<h1><?php echo esc_attr( get_admin_page_title() ); ?></h1>
				<div class="qrcdr-admin-ui">
					<div class="qrcdr-pro-main-block">
						<form method="post" action="options.php">
							<nav class="nav-tab-wrapper">
								<a href="#" data-tab-id="options" class="nav-tab <?php echo 'options' === $active_tab ? 'nav-tab-active' : ''; ?>">
									<?php esc_attr_e( 'QR Code Options', 'qrcdr' ); ?>
								</a>
								<a href="#" data-tab-id="style" class="nav-tab <?php echo 'style' === $active_tab ? 'nav-tab-active' : ''; ?>">
									<?php esc_attr_e( 'Generator Style', 'qrcdr' ); ?>
								</a>
								<a href="#" data-tab-id="logos" class="nav-tab <?php echo 'logos' === $active_tab ? 'nav-tab-active' : ''; ?>">
									<?php esc_attr_e( 'Logos', 'qrcdr' ); ?>
								</a>
							</nav>
						<?php
							// This prints out all hidden setting fields.
							settings_fields( $this->settings_group );
							do_settings_sections( $this->settings );
							submit_button();
						?>
						</form>
					</div>
					<?php
					$file_path = plugin_dir_path( __DIR__ ) . 'template-parts/admin/pro-features.php';
					if ( file_exists( $file_path ) ) {
						include $file_path;
					} else {
						echo '<div class="error"><p>' . esc_html__( 'Template file not found', 'qrcdr' ) . '</p></div>';
					}
					?>
			</div>
			<?php
		}

		/**
		 * Helper function to render Color Picker component.
		 *
		 * @param string $name          Option name.
		 * @param string $default_color Default.
		 * @param string $description   Description.
		 */
		private function render_color_picker_field( $name, $default_color, $description ) {
			$option_value = $this->get_option( $name, $default_color );
			$input_name   = esc_attr( $this->options_name . '[' . $name . ']' );

			// Il contenitore che il nostro JS troverà. Nota la classe comune.
			echo '<div class="qrcdr-color-picker-component" 
				data-initial-color="' . esc_attr( $option_value ) . '"
				data-input-name="' . esc_attr( $input_name ) . '"></div>
				<p class="description">' . esc_html( $description ) . '</p>';
		}

		/**
		 * Register and add settings
		 */
		public function page_init() {

			// phpcs:ignore WordPress.Security.NonceVerification.Recommended
			$active_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'options';

			register_setting(
				$this->settings_group, // Option group.
				$this->options_name, // Option name.
				array(
					'sanitize_callback' => array( $this, 'sanitize' ),
				)
			);

			add_settings_section(
				'options_panel',
				esc_html__( 'Default Options', 'qrcdr' ),
				array( $this, 'print_section_info' ),
				$this->settings,
				array(
					'before_section' => '<div class="tabs-content ' . ( 'options' === $active_tab ? 'active' : '' ) . '" id="qrcdr-tab-options">',
					'after_section' => '</div>',
				)
			);

			add_settings_field(
				'delete_old',
				esc_html__( 'Delete static QR codes', 'qrcdr' ),
				array( $this, 'delete_old_callback' ),
				$this->settings,
				'options_panel'
			);

			add_settings_field(
				'qr_colors',
				esc_html__( 'Default QR code colors', 'qrcdr' ),
				array( $this, 'qr_colors_callback' ), // Nuova funzione di callback.
				$this->settings,
				'options_panel'
			);

			add_settings_field(
				'precision',
				esc_html__( 'Precision', 'qrcdr' ),
				array( $this, 'precision_callback' ),
				$this->settings,
				'options_panel'
			);
			add_settings_field(
				'size',
				esc_html__( 'Size', 'qrcdr' ),
				array( $this, 'size_callback' ),
				$this->settings,
				'options_panel'
			);

			add_settings_field(
				'lat',
				esc_html__( 'Initial map latitude', 'qrcdr' ),
				array( $this, 'lat_callback' ),
				$this->settings,
				'options_panel'
			);
			add_settings_field(
				'lng',
				esc_html__( 'Initial map longitude', 'qrcdr' ),
				array( $this, 'lng_callback' ),
				$this->settings,
				'options_panel'
			);

			add_settings_section(
				'style_panel',
				esc_html__( 'Default Generator UI Style', 'qrcdr' ),
				array( $this, 'print_section_info' ),
				$this->settings,
				array(
					'before_section' => '<div class="tabs-content ' . ( 'style' === $active_tab ? 'active' : '' ) . '" id="qrcdr-tab-style">',
					'after_section' => '</div>',
				)
			);
			add_settings_field(
				'placeholder',
				esc_html__( 'Placeholder', 'qrcdr' ),
				array( $this, 'placeholder_callback' ),
				$this->settings,
				'style_panel'
			);

			add_settings_field(
				'border_radius', // ID del campo.
				esc_html__( 'Border radius', 'qrcdr' ), // Etichetta.
				array( $this, 'border_radius_callback' ), // Callback che renderà il campo.
				$this->settings, // Pagina delle impostazioni.
				'style_panel' // Sezione a cui appartiene il campo.
			);

			add_settings_field(
				'primary_color',
				esc_html__( 'Primary color', 'qrcdr' ),
				array( $this, 'primary_color_callback' ),
				$this->settings,
				'style_panel'
			);

			add_settings_section(
				'logos_panel',
				esc_html__( 'Available Logos', 'qrcdr' ),
				array( $this, 'print_section_info' ),
				$this->settings,
				array(
					'before_section' => '<div class="tabs-content ' . ( 'logos' === $active_tab ? 'active' : '' ) . '" id="qrcdr-tab-logos">',
					'after_section' => '</div>',
				)
			);

			add_settings_field(
				'watermarks',
				esc_html__( 'Watermarks', 'qrcdr' ),
				array( $this, 'watermarks_callback' ),
				$this->settings,
				'logos_panel'
			);
		}

		/**
		 * Output border radius component
		 */
		public function border_radius_callback() {
			$options = get_option( $this->options_name );

			// Gestisce la retrocompatibilità: il valore potrebbe essere un array (vecchio formato) o un numero.
			$border_radius_value = 0; // Valore di default.
			if ( isset( $options['border_radius'] ) ) {
				if ( is_array( $options['border_radius'] ) && isset( $options['border_radius']['value'] ) ) {
					$border_radius_value = $options['border_radius']['value'];
				} elseif ( is_numeric( $options['border_radius'] ) ) {
					$border_radius_value = $options['border_radius'];
				}
			}

			echo '<div class="qrcdr-range-slider-wrapper" style="border-radius: ' . esc_attr( $border_radius_value ) . 'px;">';
			// Input di tipo range.
			echo '<input 
					type="range" 
					class="qrcdr-range-slider-input" 
					name="' . esc_attr( $this->options_name ) . '[border_radius]" 
					value="' . esc_attr( $border_radius_value ) . '" 
					min="0" 
					max="30" 
					step="1" 
				  />';

			// Contenitore per mostrare il valore corrente in tempo reale.
			echo '<span class="qrcdr-range-value"><span class="qrcdr-range-slider-display">' . esc_html( $border_radius_value ) . '</span> px</span>';
			echo '</div>';

			echo '<p class="description">' . esc_html__( 'Set the border radius for buttons and inputs.', 'qrcdr' ) . '</p>';
		}

		/**
		 * Sanitize each setting field as needed
		 *
		 * @param array $input Contains all settings fields as array keys.
		 */
		public function sanitize( $input ) {

			$new_input = array();

			// 1. Sanitizzazione per border_radius (nuovo formato).
			if ( isset( $input['border_radius'] ) ) {
				$value = absint( $input['border_radius'] );
				// Assicura che il valore rientri nel range consentito (0-30).
				$new_input['border_radius'] = max( 0, min( 30, $value ) );
			} else {
				$new_input['border_radius'] = 0; // Imposta un valore predefinito sicuro.
			}

			// 3. Sanitizzazione per altri campi (metodo più specifico se non sai esattamente cosa contengono)
			if ( $input ) {
				foreach ( $input as $key => $value ) {
					if ( 'border_radius' === $key ) {
						continue; // Già gestiti sopra.
					}

					if ( is_array( $value ) ) {
						$sub_array = array();
						foreach ( $value as $sub_key => $sub_value ) {
							$sub_array[ $sub_key ] = sanitize_text_field( $sub_value );
						}
						$new_input[ $key ] = $sub_array;
					} else {
						// Per stringhe semplici che non sono HTML.
						$new_input[ $key ] = sanitize_text_field( $value );
					}
				}
			}

			return $new_input;
		}

		/**
		 * Print the Section text.
		 */
		public function print_section_info() {
		}

		/**
		 * Delete old qr callback
		 */
		public function delete_old_callback() {
			$option = $this->get_option( 'delete_old', '1 day ago' );

			$optionarray = array(
				'1 day ago' => __( '1 Day', 'qrcdr' ),
				'2 days ago' => __( '2 Days', 'qrcdr' ),
				'3 days ago' => __( '3 Days', 'qrcdr' ),
				'7 days ago' => __( '1 Week', 'qrcdr' ),
				'1 month ago' => __( '1 Month', 'qrcdr' ),
				'no' => __( 'Never', 'qrcdr' ),
			);

			echo '<select name="' . esc_attr( $this->options_name ) . '[delete_old]">';
			foreach ( $optionarray as $key => $value ) {
				printf( '<option value="' . esc_attr( $key ) . '" ' . selected( $option, $key, false ) . '>%s</option>', esc_html( $value ) ); // XSS ok.
			}
			echo '</select>';
			echo '<p>' . esc_html__( 'Set the expiration time for static QR codes created by guests', 'qrcdr' ) . '</p>';
		}

		/**
		 * Upload placeholder
		 */
		public function placeholder_callback() {
			$default = plugin_dir_url( __DIR__ ) . 'images/placeholder.svg';
			$optionplaceholder = $this->get_option( 'placeholder', $default );
			?>
			<div class="qrcdr-get-placeholder">
				<img src="<?php echo esc_url( $optionplaceholder ); ?>" alt="<?php esc_attr_e( 'Placeholder Image', 'qrcdr' ); ?>">
			</div>
			<input type="hidden" name="<?php echo esc_attr( $this->options_name ); ?>[placeholder]" class="qrcdr-placeholder" value="<?php echo esc_url( $optionplaceholder ); ?>" />
			<button class="button qrcdr-placeholder-upload"><?php esc_html_e( 'Select placeholder', 'qrcdr' ); ?></button>
			<button data-default="<?php echo esc_url( $default ); ?>" class="button qrcdr-placeholder-reset"><?php esc_html_e( 'Reset', 'qrcdr' ); ?></button>
			<?php
		}

		/**
		 * Upload watermarks
		 */
		public function watermarks_callback() {
			$get_watermarks = $this->get_option( 'watermarks', '' );
			?>
			<div class="qrcdr-get-watermarks">
			<?php
			if ( strlen( $get_watermarks ) ) {
				$watermarks_array = explode( ',', $get_watermarks );
				foreach ( $watermarks_array as $key => $value ) {
					$thumb = wp_get_attachment_image_url( $value );
					?>
					<div data-id="<?php echo esc_attr( $value ); ?>" class="qrcdr-wrap-watermark">
						<img src="<?php echo esc_url( $thumb ); ?>">
						<a href="#" class="qrcdr-remove-template">
							<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M16 8A8 8 0 110 8a8 8 0 0116 0zm-4.146-3.146a.5.5 0 00-.708-.708L8 7.293 4.854 4.146a.5.5 0 10-.708.708L7.293 8l-3.147 3.146a.5.5 0 00.708.708L8 8.707l3.146 3.147a.5.5 0 00.708-.708L8.707 8l3.147-3.146z" clip-rule="evenodd"/></svg>
						</a>
					</div>
					<?php
				}
			}
			?>
			</div>
			<input type="hidden" name="<?php echo esc_attr( $this->options_name ); ?>[watermarks]" class="qrcdr-watermarks" value="<?php echo esc_attr( $this->get_option( 'watermarks', '' ) ); ?>" />
			<button class="button qrcdr-watermarks-upload"><?php esc_html_e( 'Select watermarks', 'qrcdr' ); ?></button>
			<?php
		}

		/**
		 * Primary color
		 */
		public function primary_color_callback() {
			$this->render_color_picker_field(
				'primary_color',
				'#671AFF',
				__( 'Default primary color UI', 'qrcdr' )
			);
		}

		/**
		 * QR code colors
		 */
		public function qr_colors_callback() {
			$qr_color   = $this->get_option( 'qr_color', '#000000' );
			$qr_bgcolor = $this->get_option( 'qr_bgcolor', '#FFFFFF' );
			?>
			<div id="qrcdr-color-settings-root" 
				 data-qr-color="<?php echo esc_attr( $qr_color ); ?>"
				 data-qr-bgcolor="<?php echo esc_attr( $qr_bgcolor ); ?>"
				 data-name-qr-color="<?php echo esc_attr( $this->options_name . '[qr_color]' ); ?>"
				 data-name-qr-bgcolor="<?php echo esc_attr( $this->options_name . '[qr_bgcolor]' ); ?>"
			>
			</div>
			<?php
		}

		/**
		 * Precision L, M, Q, H
		 */
		public function precision_callback() {
			$optionprecision = $this->get_option( 'precision', 'Q' );

			$optionarray = array(
				'L' => 'L - ' . __( 'Smallest', 'qrcdr' ),
				'M' => 'M - ' . __( 'Medium', 'qrcdr' ),
				'Q' => 'Q - ' . __( 'High', 'qrcdr' ),
				'H' => 'H - ' . __( 'Best', 'qrcdr' ),
			);

			echo '<select name="' . esc_attr( $this->options_name ) . '[precision]">';
			foreach ( $optionarray as $key => $value ) {
				printf( '<option value="' . esc_attr( $key ) . '" ' . selected( $optionprecision, $key, false ) . '>%s</option>', esc_html( $value ) );
			}
			echo '</select>';
		}

		/**
		 * Size
		 */
		public function size_callback() {
			?>
			<select name="<?php echo esc_attr( $this->options_name ); ?>[size]">
			<?php
			$optionsize = $this->get_option( 'size', 24 );
			for ( $i = 8; $i <= 32; $i += 4 ) {
				$value = $i * 25;
				printf( '<option value="' . esc_attr( $i ) . '" ' . selected( $optionsize, $i, false ) . '>%s</option>', esc_attr( $value ) );
			};
			?>
			</select>
			<?php
		}

		/**
		 * Map lat
		 */
		public function lat_callback() {
			$option = $this->get_option( 'lat', '40.7127837' );
			printf( '<input type="text" name="' . esc_attr( $this->options_name ) . '[lat]" value="%s" />', esc_attr( $option ) );
		}
		/**
		 * Map lng
		 */
		public function lng_callback() {
			$option = $this->get_option( 'lng', '-74.00594130000002' );
			printf( '<input type="text" name="' . esc_attr( $this->options_name ) . '[lng]" value="%s" />', esc_attr( $option ) );
		}

		/**
		 * Wrapper function around get_option
		 *
		 * @param str   $key     Options array key.
		 * @param mixed $default Optional default value.
		 * @return mixed         Option value
		 */
		public function get_option( $key = '', $default = false ) {
			// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- This is a standard WPML hook for string registration.
			do_action( 'wpml_multilingual_options', $this->options_name );

			$opts = get_option( $this->options_name );

			if ( ! is_array( $opts ) ) {
				return $default;
			}
			if ( 'all' === $key ) {
				return $opts;
			}

			// Se la chiave specifica esiste nell'array delle opzioni, restituisci il suo valore.
			// Questo gestisce correttamente stringhe vuote, 0, e altri valori "falsy".
			if ( array_key_exists( $key, $opts ) ) {
				return $opts[ $key ];
			}

			// Altrimenti, restituisci il valore di default.
			return $default;
		}

		/**
		 * Rewrite permalinks on activation, after cpt registration
		 */
		public function activate_plugin() {
			// Set activation date for new installations.
			$option_name = $this->slug . '_activation_date';
			if ( false === get_option( $option_name ) ) {
				add_option( $option_name, time() );
			}
		}
	}
}
