<?php

namespace NeurogenesisTheme\Core\Admin\Actions;

use NeurogenesisTheme\Helpers\ThemeOptions;

defined( 'ABSPATH' ) || exit;

/**
 * Persists theme install metadata when the theme is activated.
 */
final class OnThemeActivation {

	public function __construct() {
		add_action( 'after_switch_theme', array( $this, 'set_install_date' ) );
	}

	public function set_install_date(): void {
		if ( ThemeOptions::get( ThemeOptions::INSTALLED_ON ) ) {
			return;
		}

		$values = array(
			ThemeOptions::INSTALLED_ON => current_time( 'Y-m-d' ),
		);

		// Timestamp used by Quick Setup steps to detect "new since activation" content.
		if ( ! ThemeOptions::get( ThemeOptions::QUICK_SETUP_STARTED_AT ) ) {
			$values[ ThemeOptions::QUICK_SETUP_STARTED_AT ] = current_time( 'mysql', true );
		}

		ThemeOptions::set_many( $values );
	}
}
