<?php
/**
 * Homepage composition module (not a Layout Engine).
 *
 * @package Kutby
 * @since   2.9.1
 */

declare(strict_types=1);

namespace Kutby\Modules;

use Kutby\Contracts\ModuleInterface;
use Kutby\Homepage\DemoContent;

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

/**
 * Class HomepageModule
 */
final class HomepageModule implements ModuleInterface {

	/**
	 * {@inheritdoc}
	 */
	public function register(): void {
		add_action( 'after_switch_theme', array( DemoContent::class, 'seed' ) );
		add_action( 'admin_init', array( $this, 'maybe_seed_admin' ), 5 );

		/**
		 * Homepage module ready.
		 *
		 * @since 2.9.1
		 */
		do_action( 'kutby_homepage_module_ready' );
	}

	/**
	 * {@inheritdoc}
	 */
	public function boot(): void {}

	/**
	 * Seed demo content once for admins (existing installs).
	 *
	 * @return void
	 */
	public function maybe_seed_admin(): void {
		if ( ! current_user_can( 'manage_options' ) ) {
			return;
		}
		if ( get_option( DemoContent::OPTION_KEY ) ) {
			return;
		}
		DemoContent::seed();
	}
}
