<?php
/**
 * Gravity Forms add-on registration and settings screen.
 *
 * This establishes the add-on, its settings tab, and the Google connection
 * screen. The booking logic (availability, event creation) lives in the custom
 * DrezSync Booking field, so this class stays lean.
 *
 * @package DrezSync
 */

defined( 'ABSPATH' ) || exit;

GFForms::include_addon_framework();

/**
 * DrezSync Gravity Forms add-on: registers the settings tab and its
 * Google connection screen. Booking logic lives in the custom field, so no
 * feed framework is needed here.
 */
class DrezSync_GF_Addon extends GFAddOn {

	/**
	 * Plugin version.
	 *
	 * @var string
	 */
	protected $_version = DREZSYNC_VERSION;

	/**
	 * Minimum Gravity Forms version.
	 *
	 * @var string
	 */
	protected $_min_gravityforms_version = DREZSYNC_MIN_GF_VERSION;

	/**
	 * Add-on slug.
	 *
	 * @var string
	 */
	protected $_slug = 'drezsync';

	/**
	 * Path to the main plugin file, relative to the plugins directory.
	 *
	 * @var string
	 */
	protected $_path = 'drezsync/drezsync.php';

	/**
	 * Full path to this file.
	 *
	 * @var string
	 */
	protected $_full_path = __FILE__;

	/**
	 * Add-on title.
	 *
	 * @var string
	 */
	protected $_title = 'DrezSync: Calendar Booking for Gravity Forms';

	/**
	 * Short title shown in menus.
	 *
	 * @var string
	 */
	protected $_short_title = 'DrezSync';

	/**
	 * Single instance.
	 *
	 * @var DrezSync_GF_Addon|null
	 */
	private static $_instance = null;

	/**
	 * Return the single instance.
	 *
	 * @return DrezSync_GF_Addon
	 */
	public static function get_instance() {
		if ( null === self::$_instance ) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}

	/**
	 * Render the DrezSync settings tab.
	 *
	 * We render the whole page ourselves (rather than returning fields) so our
	 * connection forms post to admin-post.php at the top level, instead of being
	 * nested inside Gravity Forms' own settings form.
	 */
	public function plugin_settings_page() {
		echo '<h3><span>' . esc_html__( 'Google Calendar', 'drezsync' ) . '</span></h3>';
		DrezSync::instance()->connect->render();
	}
}
