<?php

namespace Waypoint\Agent\Integrations;

use Waypoint\Agent\Base\Thing;

class Rank_Math_Disable_Content_Ai extends Thing {

	public function attach_hooks(): void {
		add_filter( 'rank_math/modules', [ $this, 'disable_module' ] );
	}

	/**
	 * Mark the Content AI module as disabled rather than removing it from the array.
	 * Rank Math hard-inserts content-ai at position 0 in setup_modules() regardless
	 * of the filter result -- removing the key produces a null entry that causes a
	 * fatal TypeError in Admin_Menu::register_pages() when array_merge() receives
	 * null from Module::get_args().
	 */
	public function disable_module( array $modules ): array {
		if ( isset( $modules['content-ai'] ) ) {
			$modules['content-ai']['disabled'] = true;
		}
		return $modules;
	}
}
