<?php

namespace Waypoint\Agent\Acf;

use Waypoint\Agent\Base\Thing;

class Loader extends Thing {

	private string $acf_path;
	private string $acf_url;

	public function attach_hooks(): void {
		// ACF is already active as a standalone plugin — nothing to do.
		if ( defined( 'ACF' ) || function_exists( 'acf' ) ) {
			return;
		}

		$acf_file = dirname( WAYPOINT_AGENT_FILE ) . '/vendor/wpengine/advanced-custom-fields-pro/acf.php';

		if ( ! file_exists( $acf_file ) ) {
			return;
		}

		$this->acf_path = dirname( $acf_file ) . '/';
		$this->acf_url  = plugin_dir_url( WAYPOINT_AGENT_FILE ) . 'vendor/wpengine/advanced-custom-fields-pro/';

		add_filter( 'acf/settings/path', [ $this, 'get_acf_path' ] );
		add_filter( 'acf/settings/dir', [ $this, 'get_acf_url' ] );

		require_once $acf_file;
	}

	public function get_acf_path(): string {
		return $this->acf_path;
	}

	public function get_acf_url(): string {
		return $this->acf_url;
	}
}
