<?php
/**
 * Setup.
 *
 * @package MadeByAura\Prime\Plugins\ACFPro\Hooks
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime\Plugins\ACFPro\Hooks;

use MadeByAura\Prime\Base;
use MadeByAura\Prime\Helpers\SingletonTrait;

defined( 'ABSPATH' ) || die();

/**
 * Setup.
 */
class Setup {
	use SingletonTrait;

	/**
	 * Constructor.
	 */
	protected function __construct() {
		// JSON load/save paths.
		add_filter( 'acf/settings/load_json', [ __CLASS__, 'add_load_json_path' ] );

		// Theme options.
		add_filter( 'acf/settings/save_json/key=ui_options_page_64d8d5ddda340', [ __CLASS__, 'set_save_json_path' ] );

		// Field group: Theme options.
		add_filter( 'acf/settings/save_json/key=group_67f661a3d4b86', [ __CLASS__, 'set_save_json_path' ] );

		// Field group: Post meta.
		add_filter( 'acf/settings/save_json/key=group_62d925e5dee75', [ __CLASS__, 'set_save_json_path' ] );

		// Field group: Page meta.
		add_filter( 'acf/settings/save_json/key=group_61e571896e538', [ __CLASS__, 'set_save_json_path' ] );
	}

	/**
	 * Set json load path.
	 *
	 * @link https://www.advancedcustomfields.com/resources/local-json/
	 *
	 * @param array $paths  Paths.
	 * @return array $paths
	 */
	public static function add_load_json_path( $paths ) {
		$paths[] = Base::get_info( 'path' ) . 'plugins/ACFPro/json';

		return $paths;
	}

	/**
	 * Set json save path.
	 *
	 * Create directory if it does not exist.
	 *
	 * @link https://www.advancedcustomfields.com/resources/local-json/
	 *
	 * @return string $path  Path.
	 */
	public static function set_save_json_path() {
		$path = Base::get_info( 'path' ) . 'plugins/ACFPro/json';

		wp_mkdir_p( $path );

		return $path;
	}
}
