<?php
/**
 * Abstract Tab Base Class
 *
 * @package AmbassadorHub\Admin\Settings
 */

namespace AmbassadorHub\Admin\Settings;

/**
 * Base class for settings tabs with common functionality.
 */
abstract class AbstractTab implements Tab {
	/**
	 * Tab ID.
	 *
	 * @var string
	 */
	protected string $id;

	/**
	 * Tab label.
	 *
	 * @var string
	 */
	protected string $label;

	/**
	 * Tab priority.
	 *
	 * @var int
	 */
	protected int $priority = 10;

	/**
	 * Get tab ID.
	 *
	 * @return string
	 */
	public function get_id(): string {
		return $this->id;
	}

	/**
	 * Get tab label.
	 *
	 * @return string
	 */
	public function get_label(): string {
		return $this->label;
	}

	/**
	 * Get tab priority.
	 *
	 * @return int
	 */
	public function get_priority(): int {
		return $this->priority;
	}

	/**
	 * Render the tab content.
	 *
	 * Override in subclasses.
	 *
	 * @return void
	 */
	public function render(): void {
		echo '<p>' . esc_html__( 'No content configured for this tab.', 'ambassadorhub' ) . '</p>';
	}

	/**
	 * Save a setting for this tab.
	 *
	 * @param string $key Setting key.
	 * @param mixed  $value Setting value.
	 *
	 * @return bool True if saved, false otherwise.
	 */
	protected function save_setting( string $key, $value ): bool {
		$option_key = $this->get_option_key( $key );
		return update_option( $option_key, $value );
	}

	/**
	 * Get a setting for this tab.
	 *
	 * @param string $key Setting key.
	 * @param mixed  $default_value Default value if not found.
	 *
	 * @return mixed Setting value or default.
	 */
	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_{$this->id}_{$key}";
	}
}
