<?php
/**
 * DefaultSellerRole class.
 *
 * @package DokanKits\Features\Vendor
 * @since   3.0.0
 */

namespace DokanKits\Features\Vendor;

use DokanKits\Features\Feature;

/**
 * Default Seller Role Feature
 *
 * Enables the "I am a Vendor" option by default on the My Account page.
 * When this feature is active, the seller role checkbox will be pre-selected
 * on the registration form, encouraging users to register as vendors.
 *
 * @since   3.0.0
 * @package DokanKits\Features\Vendor
 */
class DefaultSellerRole extends Feature {

	/**
	 * Feature option key for enabling/disabling this feature
	 *
	 * @since 3.0.0
	 * @var string
	 */
	protected string $option_key = 'set_default_seller_role_checkbox';

	/**
	 * Feature settings group for admin UI organization
	 *
	 * @since 3.0.0
	 * @var string
	 */
	protected string $settings_group = 'vendor';

	/**
	 * Feature settings section within the group
	 *
	 * @since 3.0.0
	 * @var string
	 */
	protected string $settings_section = 'registration';

	/**
	 * Number of sub-features contained in this feature
	 *
	 * @since 3.0.0
	 * @var int
	 */
	protected int $total_features = 1;

	/**
	 * Register hooks with WordPress
	 *
	 * Sets up the filter to pre-select the seller role checkbox
	 * on the registration form when enabled.
	 *
	 * @since 3.0.0
	 * @return void
	 */
	public function register_hooks(): void {
		add_filter( 'dokan_seller_registration_default_role', array( $this, 'maybe_set_default_role' ) );
	}

	/**
	 * Maybe set default role if feature is enabled
	 *
	 * Changes the default role to 'seller' when this feature is enabled,
	 * making the vendor checkbox pre-selected on registration.
	 *
	 * @since 3.0.0
	 * @param string $role The current default role.
	 * @return string Modified default role.
	 */
	public function maybe_set_default_role( string $role ): string {
		if ( $this->is_enabled() ) {
			return 'seller';
		}

		return $role;
	}
}
