<?php
/**
 * Advanced button configuration.
 *
 * @package IMPACT_WIDGETS_ELEMENTOR
 */

namespace ImpactAddons\ImpactWidgetsForElementor\Config;

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

final class Advanced_Button_Config {
	/**
	 * Get design style options for the widget control.
	 *
	 * @return array<string, string>
	 */
	public static function get_style_options(): array {
		return array(
			'background'     => esc_html__( 'Background Style', 'impact-widgets-for-elementor' ),
			'bordered'       => esc_html__( 'Bordered Style', 'impact-widgets-for-elementor' ),
			'accent-overlay' => esc_html__( 'Accent Overlay (Merged)', 'impact-widgets-for-elementor' ),
			'offer-note'     => esc_html__( 'Badge Content', 'impact-widgets-for-elementor' ),
			'ribbon-tag'     => esc_html__( 'Ribbon Tag', 'impact-widgets-for-elementor' ),
			'downloadable'   => esc_html__( 'Downloadable', 'impact-widgets-for-elementor' ),
		);
	}

	/**
	 * Default style key.
	 */
	public static function get_default_style(): string {
		return 'background';
	}

	/**
	 * Sanitize and validate style key.
	 */
	public static function sanitize_style( string $style ): string {
		$options = self::get_style_options();

		if ( ! array_key_exists( $style, $options ) ) {
			if ( 'style-13' === $style ) {
				return 'ribbon-tag';
			}
			if ( in_array( $style, array( 'download-style-1', 'download-style-2', 'download-style-3', 'download-style-4', 'download-style-5' ), true ) ) {
				return 'downloadable';
			}

			$legacy_background_styles = array(
				'style-1',
				'style-2',
				'style-3',
				'style-4',
				'style-7',
				'style-8',
				'style-10',
				'style-12',
				'style-14',
			);
			$legacy_bordered_styles = array( 'style-5', 'style-6', 'style-9', 'style-11' );

			if ( in_array( $style, $legacy_background_styles, true ) ) {
				return 'background';
			}

			if ( in_array( $style, $legacy_bordered_styles, true ) ) {
				return 'bordered';
			}

			return self::get_default_style();
		}

		return $style;
	}
}
