<?php
/**
 * Fundraiser Settings Tab
 *
 * Extends Ambassador Core settings with fundraiser-specific options.
 *
 * @package AmbassadorHub\Admin\Settings
 */

namespace AmbassadorHub\Fundraisers\Admin\Settings\Tabs;

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

use AmbassadorHub\Admin\Settings\AbstractTab;

/**
 * Fundraiser settings tab.
 *
 * Adds fundraiser-specific settings to Ambassador Core settings page.
 */
final class FundraiserTab extends AbstractTab {
	/**
	 * Constructor.
	 */
	public function __construct() {
		$this->id       = 'fundraisers';
		$this->label    = __( 'Fundraisers', 'ambassadorhub' );
		$this->priority = 10;
	}

	/**
	 * Render the Fundraiser tab content.
	 *
	 * Shows custom fundraiser fields and donation fields in a single combined view.
	 * General settings have moved to the plugin's General tab.
	 *
	 * @return void
	 */
	public function render(): void {
		?>
		<form method="post" action="options.php"> 

		<?php
			settings_fields( 'ambh_fundraisers' );
			do_settings_sections( 'ambh_fundraisers' );
		?>

		<?php
		/**
		 * Fires inside the Donation Fields section.
		 *
		 * Used to render the custom donation fields management table.
		 *
		 * @since 0.1.0
		 */
		do_action( 'ambh_fundraisers_settings_fields' );
		?>

		<?php
		/**
		 * Fires after all content — modals and JS assets live here.
		 *
		 * @since 0.1.0
		 */
		do_action( 'ambh_fundraisers_settings_after_form' );
		?>

		<?php submit_button(); ?>
		</form>
		<?php
	}

	/**
	 * Get a setting for this tab.
	 *
	 * @param string $key           Setting key.
	 * @param mixed  $default_value Default value.
	 *
	 * @return mixed Setting value.
	 */
	protected function get_setting( string $key, $default_value = '' ) {
		$option_key = $this->get_option_key( $key );
		return get_option( $option_key, $default_value );
	}

	/**
	 * Get the full option key for a setting.
	 *
	 * @param string $key Setting key.
	 *
	 * @return string Full option key.
	 */
	protected function get_option_key( string $key ): string {
		return 'ambh_fundraisers_' . $key;
	}
}
