<?php
/**
 * Activity Guard – Real Time Notifier to Slack Activator
 *
 * This class is used to builds all of the tables when the plugin is activated
 *
 * @package WPNTS\Inc
 */

namespace WPNTS\Inc;

use WPNTS\Inc\wpnts_nts_fs; // phpcs:ignore
use WPNTS\Inc\Notify; // phpcs:ignore
use WPNTS\Inc\WPUpdate; // phpcs:ignore
use WPNTS\Inc\PluginUpdate; // phpcs:ignore
use WPNTS\Inc\NotifierReview; // phpcs:ignore
use WPNTS\Inc\NotifierSupport; // phpcs:ignore

defined('ABSPATH') || die('Hey, what are you doing here? You silly human!');
/**
 * Activator Class.
 *
 * @since 1.0.0
 */
class Activate {

	/**
	 * Activate function, Seed initial settings.
	 *
	 * @since 1.0.0
	 */
	public static function wpnts_activate() {
		// Make it static so I can call it direct on a function.

		if ( ! wp_next_scheduled('wpnts_corn_hook') ) {
			wp_schedule_event(time(), 'added_schedules_interval', 'wpnts_corn_hook');
		}

		self::init_template_tracking();

		flush_rewrite_rules();
	}

	/**
	 * Initialize template tracking by storing current templates for all pages
	 *
	 * @since [your-next-version]
	 */
	public static function init_template_tracking() {
		// Get all pages
		$pages = get_posts([
			'post_type' => 'page',
			'posts_per_page' => -1,
			'post_status' => 'publish',
		]);

		// Store current template for each page
		foreach ( $pages as $page ) {
			$current_template = get_post_meta($page->ID, '_wp_page_template', true);
			if ( ! empty($current_template) ) {
				update_post_meta($page->ID, '_wpnts_last_template', $current_template);
			}
		}
	}
}
