<?php
/**
 * Ready-made Coming Soon & Maintenance page presets.
 *
 * @package ComingSoonMaintenance
 */

namespace ComingSoonMaintenance;

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

final class PagePresets {

	private static function imageUrl( string $photo_id, int $width = 1920 ): string {
		return 'https://images.unsplash.com/' . $photo_id . '?auto=format&fit=crop&w=' . $width . '&q=80';
	}

	/** @return list<array{id: string, group: string, name: string, description: string}> */
	public static function getCatalog(): array {
		return [
			[
				'id'          => 'default',
				'group'       => 'default',
				'name'        => __( 'PowerSuite Default', 'wppowersuite-lite' ),
				'description' => __( 'Soft teal canvas with friendly launch copy and email signup.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'cs-teal-gradient',
				'group'       => 'coming_soon',
				'name'        => __( 'Teal Horizon', 'wppowersuite-lite' ),
				'description' => __( 'Fresh teal-to-silver gradient with countdown and subscribe form.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'cs-warm-sunrise',
				'group'       => 'coming_soon',
				'name'        => __( 'Warm Sunrise', 'wppowersuite-lite' ),
				'description' => __( 'Peach and coral gradient warmth for lifestyle and creative brands.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'cs-midnight',
				'group'       => 'coming_soon',
				'name'        => __( 'Midnight Launch', 'wppowersuite-lite' ),
				'description' => __( 'Deep navy gradient with bold headline and electric accent feel.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'cs-ocean-photo',
				'group'       => 'coming_soon',
				'name'        => __( 'Ocean View', 'wppowersuite-lite' ),
				'description' => __( 'Coastal photography with a soft teal overlay and social links.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'cs-minimal-pattern',
				'group'       => 'coming_soon',
				'name'        => __( 'Minimal Lines', 'wppowersuite-lite' ),
				'description' => __( 'Light pattern backdrop with understated copy and signup.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'cs-violet-launch',
				'group'       => 'coming_soon',
				'name'        => __( 'Violet Countdown', 'wppowersuite-lite' ),
				'description' => __( 'Bold violet-to-blue gradient for product launches and SaaS.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'maint-industrial',
				'group'       => 'maintenance',
				'name'        => __( 'Construction Zone', 'wppowersuite-lite' ),
				'description' => __( 'Warm construction palette with a structured notice card and bold hierarchy.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'maint-dark-service',
				'group'       => 'maintenance',
				'name'        => __( 'Night Service', 'wppowersuite-lite' ),
				'description' => __( 'Premium dark glass panel with calm, confident downtime messaging.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'maint-clean-gray',
				'group'       => 'maintenance',
				'name'        => __( 'Enterprise Status', 'wppowersuite-lite' ),
				'description' => __( 'Minimal SaaS-style status page with crisp typography and whitespace.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'maint-warning-stripe',
				'group'       => 'maintenance',
				'name'        => __( 'High Visibility', 'wppowersuite-lite' ),
				'description' => __( 'Attention-grabbing caution styling for short planned outages.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'maint-blueprint',
				'group'       => 'maintenance',
				'name'        => __( 'Engineering Mode', 'wppowersuite-lite' ),
				'description' => __( 'Blueprint grid aesthetic for technical and developer-facing brands.', 'wppowersuite-lite' ),
			],
			[
				'id'          => 'maint-workshop-photo',
				'group'       => 'maintenance',
				'name'        => __( 'Workshop Live', 'wppowersuite-lite' ),
				'description' => __( 'Cinematic workshop photography with warm industrial accents.', 'wppowersuite-lite' ),
			],
		];
	}

	/**
	 * Thumbnail spec for admin preset cards.
	 *
	 * @return array<string, mixed>
	 */
	public static function getPreviewSpec( string $preset_id ): array {
		$settings = self::getPresetSettings( $preset_id );
		if ( $settings === null ) {
			return [];
		}

		$bg_type = (string) ( $settings['bg_type'] ?? 'color' );
		$page    = self::resolvePageBackground( $settings, $bg_type );
		$group   = self::getPresetGroup( $preset_id );

		return array_merge(
			$page,
			[
				'layout'          => 'centered',
				'text_light'      => ! empty( $page['text_light'] ),
				'show_countdown'  => $group !== 'maintenance',
				'show_subscribe'  => ! empty( $settings['show_subscribe'] ),
				'show_social'     => ! empty( $settings['social_links'] ),
				'has_photo'       => ! empty( $page['page_image'] ),
			]
		);
	}

	private static function getPresetGroup( string $preset_id ): string {
		foreach ( self::getCatalog() as $item ) {
			if ( (string) $item['id'] === $preset_id ) {
				return (string) $item['group'];
			}
		}

		return 'default';
	}

	/**
	 * @param array<string, mixed> $settings
	 * @return array<string, mixed>
	 */
	private static function resolvePageBackground( array $settings, string $bg_type ): array {
		if ( $bg_type === 'gradient' ) {
			$fill = self::gradientToCss( $settings );

			return [
				'page_fill'   => $fill !== '' ? $fill : '#8dd3d3',
				'page_image'  => '',
				'page_overlay'=> '',
				'text_light'  => self::isDarkFill( $settings['bg_gradient_color1'] ?? '', $settings['bg_gradient_color2'] ?? '' ),
			];
		}

		if ( $bg_type === 'image' ) {
			$url = isset( $settings['bg_image_url'] ) ? trim( (string) $settings['bg_image_url'] ) : '';
			if ( $url === '' && ! empty( $settings['bg_image_id'] ) ) {
				$url = (string) wp_get_attachment_image_url( (int) $settings['bg_image_id'], 'medium' );
			}
			$overlay_color   = self::resolveColor( $settings['bg_image_overlay_color'] ?? '#000000', '#000000' );
			$overlay_opacity = isset( $settings['bg_image_overlay_opacity'] ) ? max( 0, min( 100, (int) $settings['bg_image_overlay_opacity'] ) ) : 60;

			return [
				'page_fill'    => $overlay_color,
				'page_image'   => $url,
				'page_overlay' => $overlay_opacity > 0 ? self::hexToRgba( $overlay_color, $overlay_opacity / 100 ) : '',
				'text_light'   => true,
			];
		}

		if ( $bg_type === 'patterns' ) {
			$overlay_color   = self::resolveColor( $settings['bg_pattern_overlay_color'] ?? '#000000', '#000000' );
			$overlay_opacity = isset( $settings['bg_pattern_overlay_opacity'] ) ? max( 0, min( 100, (int) $settings['bg_pattern_overlay_opacity'] ) ) : 40;
			$pattern         = in_array( $settings['bg_pattern'] ?? '', [ 'lines', 'stripes', 'curves' ], true ) ? (string) $settings['bg_pattern'] : 'lines';

			return [
				'page_fill'    => $overlay_color,
				'page_image'   => '',
				'page_overlay' => $overlay_opacity > 0 ? self::hexToRgba( $overlay_color, $overlay_opacity / 100 ) : '',
				'pattern'      => $pattern,
				'text_light'   => $overlay_opacity >= 35,
			];
		}

		$color = self::resolveColor( $settings['bg_color'] ?? '#8dd3d3', '#8dd3d3' );

		return [
			'page_fill'   => $color,
			'page_image'  => '',
			'page_overlay'=> '',
			'text_light'  => self::isDarkFill( $color ),
		];
	}

	/** @param array<string, mixed> $settings */
	private static function gradientToCss( array $settings ): string {
		$type   = ( $settings['bg_gradient_type'] ?? 'linear' ) === 'radial' ? 'radial' : 'linear';
		$angle  = isset( $settings['bg_gradient_angle'] ) ? max( 0, min( 360, (int) $settings['bg_gradient_angle'] ) ) : 135;
		$color1 = self::resolveColor( $settings['bg_gradient_color1'] ?? '#8dd3d3', '#8dd3d3' );
		$color2 = self::resolveColor( $settings['bg_gradient_color2'] ?? '#e8e8e8', '#e8e8e8' );
		$pos1   = isset( $settings['bg_gradient_pos1'] ) ? max( 0, min( 100, (int) $settings['bg_gradient_pos1'] ) ) : 0;
		$pos2   = isset( $settings['bg_gradient_pos2'] ) ? max( 0, min( 100, (int) $settings['bg_gradient_pos2'] ) ) : 100;

		if ( $type === 'radial' ) {
			return 'radial-gradient(circle at center,' . $color1 . ' ' . $pos1 . '%,' . $color2 . ' ' . $pos2 . '%)';
		}

		return 'linear-gradient(' . $angle . 'deg,' . $color1 . ' ' . $pos1 . '%,' . $color2 . ' ' . $pos2 . '%)';
	}

	private static function resolveColor( $value, string $fallback ): string {
		$color = is_string( $value ) ? trim( $value ) : '';
		if ( $color !== '' && preg_match( '/^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/', $color ) ) {
			return $color;
		}

		return $fallback;
	}

	private static function isDarkFill( string ...$colors ): bool {
		foreach ( $colors as $color ) {
			$hex = ltrim( self::resolveColor( $color, '#ffffff' ), '#' );
			if ( strlen( $hex ) === 3 ) {
				$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
			}
			if ( strlen( $hex ) >= 6 ) {
				$r = hexdec( substr( $hex, 0, 2 ) );
				$g = hexdec( substr( $hex, 2, 2 ) );
				$b = hexdec( substr( $hex, 4, 2 ) );
				$l = ( 0.299 * $r + 0.587 * $g + 0.114 * $b ) / 255;
				if ( $l < 0.45 ) {
					return true;
				}
			}
		}

		return false;
	}

	private static function hexToRgba( string $hex, float $alpha ): string {
		$hex = ltrim( $hex, '#' );
		if ( strlen( $hex ) === 3 ) {
			$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
		}

		$r = hexdec( substr( $hex, 0, 2 ) );
		$g = hexdec( substr( $hex, 2, 2 ) );
		$b = hexdec( substr( $hex, 4, 2 ) );

		return 'rgba(' . $r . ',' . $g . ',' . $b . ',' . max( 0, min( 1, $alpha ) ) . ')';
	}

	private static function sampleLaunchDate( int $days = 30 ): string {
		try {
			$dt = new \DateTime( '+' . max( 1, $days ) . ' days', wp_timezone() );

			return $dt->format( 'Y-m-d\TH:i' );
		} catch ( \Exception $e ) {
			return '';
		}
	}

	private static function richText( string $text ): string {
		return '<p>' . esc_html( $text ) . '</p>';
	}

	/**
	 * Map short design keys to module settings for preset palettes.
	 *
	 * @param array<string, mixed> $opts
	 * @return array<string, mixed>
	 */
	private static function palette( array $opts ): array {
		$map = [
			'text'                 => 'text_color',
			'heading'              => 'heading_color',
			'description'          => 'description_color',
			'countdown_bg'         => 'countdown_bg_color',
			'countdown_text'       => 'countdown_text_color',
			'countdown_radius'     => 'countdown_border_radius',
			'btn_bg'               => 'subscribe_btn_bg',
			'btn_text'             => 'subscribe_btn_text',
			'input_bg'             => 'subscribe_input_bg',
			'input_text'           => 'subscribe_input_text',
			'input_border'         => 'subscribe_input_border',
			'social_bg'            => 'social_icon_bg',
			'social_color'         => 'social_icon_color',
			'container_width'      => 'container_max_width',
			'content_align'        => 'content_align',
		];
		$out = [];
		foreach ( $map as $short => $long ) {
			if ( array_key_exists( $short, $opts ) && $opts[ $short ] !== '' && $opts[ $short ] !== null ) {
				$out[ $long ] = $opts[ $short ];
			}
		}

		return $out;
	}

	/** Dark-on-light palette for soft gradients and pattern templates. @return array<string, mixed> */
	private static function darkOnLight( string $accent = '#0f766e' ): array {
		return self::palette(
			[
				'text'             => '#134e4a',
				'heading'          => '#115e59',
				'description'      => '#0f766e',
				'countdown_bg'     => 'rgba(255,255,255,0.72)',
				'countdown_text'   => '#134e4a',
				'countdown_radius' => 16,
				'btn_bg'           => $accent,
				'btn_text'         => '#ffffff',
				'input_bg'         => 'rgba(255,255,255,0.9)',
				'input_text'       => '#134e4a',
				'input_border'     => 'rgba(20,184,166,0.35)',
				'social_bg'        => 'rgba(255,255,255,0.55)',
				'social_color'     => '#115e59',
			]
		);
	}

	/** Light-on-dark palette for photo and dark maintenance templates. @return array<string, mixed> */
	private static function lightOnDark(): array {
		return self::palette(
			[
				'text'            => '#e2e8f0',
				'heading'         => '#f8fafc',
				'description'     => '#cbd5e1',
				'container_width' => 680,
				'content_align'   => 'center',
			]
		);
	}

	/** @return array<string, mixed> */
	private static function presetShell( bool $coming_soon = true ): array {
		$shell = [
			'show_logo'      => 1,
			'auto_disable'   => 0,
			'social_links'   => [],
		];
		if ( $coming_soon ) {
			$shell['show_subscribe'] = 1;
		} else {
			$shell['show_subscribe'] = 0;
			$shell['launch_date']    = '';
		}

		return $shell;
	}

	/** @return array<string, array<string, mixed>> */
	private static function getOverrides(): array {
		$ocean_img    = self::imageUrl( 'photo-1505142468610-359e7d316be0' );
		$workshop_img = self::imageUrl( 'photo-1581091226825-a6a2a5aee158' );

		return [
			'default' => array_merge(
				[
					'page_preset'   => 'default',
					'mode'          => 'coming_soon',
					'bg_type'       => 'gradient',
					'bg_gradient_type'   => 'linear',
					'bg_gradient_angle'  => 145,
					'bg_gradient_color1' => '#99f6e4',
					'bg_gradient_color2' => '#ccfbf1',
					'bg_gradient_pos1'   => 0,
					'bg_gradient_pos2'   => 100,
					'heading'       => self::richText( __( 'Something Amazing is Coming', 'wppowersuite-lite' ) ),
					'description'   => self::richText( __( 'We are working hard to bring you something special. Join the list and be first to know when we launch.', 'wppowersuite-lite' ) ),
					'show_logo'     => 1,
					'show_subscribe'=> 1,
					'launch_date'   => self::sampleLaunchDate( 28 ),
					'auto_disable'  => 0,
					'social_links'  => [],
					'custom_css'    => ".wpps-csm-heading { font-family: Georgia, 'Times New Roman', serif; font-weight: 700; letter-spacing: -0.02em; }\n.wpps-csm-countdown-item { backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.45); }\n.wpps-csm-subscribe button { border-radius: 999px; font-weight: 700; }",
				],
				self::darkOnLight( '#0d9488' ),
				self::palette( [ 'container_width' => 720 ] )
			),
			'cs-teal-gradient' => array_merge(
				[
					'page_preset'              => 'cs-teal-gradient',
					'mode'                     => 'coming_soon',
					'bg_type'                  => 'gradient',
					'bg_gradient_type'         => 'linear',
					'bg_gradient_angle'        => 128,
					'bg_gradient_color1'       => '#5eead4',
					'bg_gradient_color2'       => '#f0fdfa',
					'bg_gradient_pos1'         => 0,
					'bg_gradient_pos2'         => 100,
					'heading'                  => self::richText( __( 'Fresh Start, Coming Soon', 'wppowersuite-lite' ) ),
					'description'              => self::richText( __( 'We are polishing the details before launch. Join the waitlist and be first in line.', 'wppowersuite-lite' ) ),
					'show_logo'                => 1,
					'show_subscribe'           => 1,
					'launch_date'              => self::sampleLaunchDate( 21 ),
					'auto_disable'             => 0,
					'bg_image_id'              => 0,
					'bg_image_url'             => '',
					'bg_video'                 => '',
					'social_links'             => [],
					'custom_css'               => ".wpps-csm-heading { font-family: Georgia, 'Times New Roman', serif; font-weight: 700; letter-spacing: -0.03em; font-size: clamp(2.1rem, 5vw, 3.6rem); }\n.wpps-csm-description { max-width: 34rem; margin-left: auto; margin-right: auto; }\n.wpps-csm-countdown-item { backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.55); box-shadow: 0 8px 24px rgba(15,118,110,0.08); }\n.wpps-csm-subscribe button { border-radius: 999px; font-weight: 700; box-shadow: 0 8px 20px rgba(15,118,110,0.22); }",
				],
				self::darkOnLight( '#0f766e' ),
				self::palette( [ 'container_width' => 760 ] )
			),
			'cs-warm-sunrise' => array_merge(
				[
					'page_preset'              => 'cs-warm-sunrise',
					'mode'                     => 'coming_soon',
					'bg_type'                  => 'gradient',
					'bg_gradient_type'         => 'radial',
					'bg_gradient_angle'        => 145,
					'bg_gradient_color1'       => '#fff7ed',
					'bg_gradient_color2'       => '#fdba74',
					'bg_gradient_pos1'         => 0,
					'bg_gradient_pos2'         => 100,
					'heading'                  => self::richText( __( 'A Brighter Launch Is Near', 'wppowersuite-lite' ) ),
					'description'              => self::richText( __( 'Warm colors, big plans. Leave your email and we will notify you the moment we go live.', 'wppowersuite-lite' ) ),
					'show_logo'                => 1,
					'show_subscribe'           => 1,
					'launch_date'              => self::sampleLaunchDate( 14 ),
					'auto_disable'             => 0,
					'bg_image_id'              => 0,
					'bg_image_url'             => '',
					'bg_video'                 => '',
					'social_links'             => [
						[ 'icon' => 'instagram', 'url' => 'https://instagram.com/' ],
						[ 'icon' => 'facebook', 'url' => 'https://facebook.com/' ],
					],
					'custom_css'               => ".wpps-csm-heading { font-family: Georgia, 'Times New Roman', serif; font-weight: 700; letter-spacing: -0.02em; }\n.wpps-csm-countdown-item { border: 1px solid rgba(234,88,12,0.2); box-shadow: 0 6px 18px rgba(234,88,12,0.1); }\n.wpps-csm-subscribe button { border-radius: 999px; font-weight: 700; }",
				],
				self::palette(
					[
						'text'             => '#431407',
						'heading'          => '#9a3412',
						'description'      => '#7c2d12',
						'countdown_bg'     => 'rgba(255,255,255,0.78)',
						'countdown_text'   => '#431407',
						'countdown_radius' => 18,
						'btn_bg'           => '#ea580c',
						'btn_text'         => '#ffffff',
						'input_bg'         => 'rgba(255,255,255,0.92)',
						'input_text'       => '#431407',
						'input_border'     => '#fdba74',
						'social_bg'        => 'rgba(255,255,255,0.65)',
						'social_color'     => '#c2410c',
						'container_width'  => 740,
					]
				)
			),
			'cs-midnight' => array_merge(
				[
					'page_preset'              => 'cs-midnight',
					'mode'                     => 'coming_soon',
					'bg_type'                  => 'gradient',
					'bg_gradient_type'         => 'linear',
					'bg_gradient_angle'        => 165,
					'bg_gradient_color1'       => '#020617',
					'bg_gradient_color2'       => '#1d4ed8',
					'bg_gradient_pos1'         => 0,
					'bg_gradient_pos2'         => 100,
					'heading'                  => self::richText( __( 'Launching Under the Stars', 'wppowersuite-lite' ) ),
					'description'              => self::richText( __( 'Something bold is almost here. Follow along or subscribe for launch-day access.', 'wppowersuite-lite' ) ),
					'show_logo'                => 1,
					'show_subscribe'           => 1,
					'launch_date'              => self::sampleLaunchDate( 45 ),
					'auto_disable'             => 0,
					'bg_image_id'              => 0,
					'bg_image_url'             => '',
					'bg_video'                 => '',
					'social_links'             => [
						[ 'icon' => 'twitter', 'url' => 'https://x.com/' ],
						[ 'icon' => 'linkedin', 'url' => 'https://linkedin.com/' ],
					],
					'custom_css'               => ".wpps-csm-heading { font-weight: 900; letter-spacing: -0.04em; font-size: clamp(2.2rem, 5vw, 3.8rem); }\n.wpps-csm-countdown-item { backdrop-filter: blur(14px); border: 1px solid rgba(125,211,252,0.35); }\n.wpps-csm-subscribe button { border-radius: 999px; font-weight: 800; box-shadow: 0 10px 28px rgba(14,165,233,0.35); }",
				],
				self::palette(
					[
						'text'             => '#e2e8f0',
						'heading'          => '#ffffff',
						'description'      => 'rgba(226,232,240,0.9)',
						'countdown_bg'     => 'rgba(14,165,233,0.16)',
						'countdown_text'   => '#ffffff',
						'countdown_radius' => 14,
						'btn_bg'           => '#38bdf8',
						'btn_text'         => '#0f172a',
						'input_bg'         => 'rgba(15,23,42,0.55)',
						'input_text'       => '#f8fafc',
						'input_border'     => 'rgba(125,211,252,0.45)',
						'social_bg'        => 'rgba(255,255,255,0.12)',
						'social_color'     => '#ffffff',
						'container_width'  => 780,
					]
				)
			),
			'cs-ocean-photo' => array_merge(
				[
					'page_preset'              => 'cs-ocean-photo',
					'mode'                     => 'coming_soon',
					'bg_type'                  => 'image',
					'bg_image_id'              => 0,
					'bg_image_url'             => $ocean_img,
					'bg_image_overlay_color'   => '#042f2e',
					'bg_image_overlay_opacity' => 52,
					'heading'                  => self::richText( __( 'Making Waves', 'wppowersuite-lite' ) ),
					'description'              => self::richText( __( 'Calm seas today, big launch tomorrow. Get notified when we open the doors.', 'wppowersuite-lite' ) ),
					'show_logo'                => 1,
					'show_subscribe'           => 1,
					'launch_date'              => self::sampleLaunchDate( 30 ),
					'auto_disable'             => 0,
					'bg_video'                 => '',
					'social_links'             => [
						[ 'icon' => 'instagram', 'url' => 'https://instagram.com/' ],
						[ 'icon' => 'tiktok', 'url' => 'https://tiktok.com/' ],
					],
					'custom_css'               => ".wpps-csm-heading { font-size: clamp(2.3rem, 5vw, 4rem); font-weight: 800; letter-spacing: -0.03em; }\n.wpps-csm-countdown-item { backdrop-filter: blur(18px); border: 1px solid rgba(255,255,255,0.22); }\n.wpps-csm-subscribe button { border-radius: 999px; font-weight: 700; }",
				],
				self::palette(
					[
						'text'             => '#ecfdf5',
						'heading'          => '#ffffff',
						'description'      => 'rgba(236,253,245,0.92)',
						'countdown_bg'     => 'rgba(255,255,255,0.16)',
						'countdown_text'   => '#ffffff',
						'countdown_radius' => 16,
						'btn_bg'           => '#2dd4bf',
						'btn_text'         => '#042f2e',
						'input_bg'         => 'rgba(15,23,42,0.45)',
						'input_text'       => '#ffffff',
						'input_border'     => 'rgba(45,212,191,0.45)',
						'social_bg'        => 'rgba(255,255,255,0.14)',
						'social_color'     => '#ffffff',
						'container_width'  => 760,
					]
				)
			),
			'cs-minimal-pattern' => array_merge(
				[
					'page_preset'                => 'cs-minimal-pattern',
					'mode'                       => 'coming_soon',
					'bg_type'                    => 'patterns',
					'bg_pattern'                 => 'lines',
					'bg_pattern_overlay_color'   => '#99f6e4',
					'bg_pattern_overlay_opacity' => 18,
					'heading'                    => self::richText( __( 'Quietly Building', 'wppowersuite-lite' ) ),
					'description'                => self::richText( __( 'Minimal and focused. We will be back with a cleaner, simpler experience.', 'wppowersuite-lite' ) ),
					'show_logo'                  => 1,
					'show_subscribe'             => 1,
					'launch_date'                => self::sampleLaunchDate( 18 ),
					'auto_disable'               => 0,
					'bg_image_id'                => 0,
					'bg_image_url'               => '',
					'bg_video'                   => '',
					'social_links'               => [],
					'custom_css'                 => ".wpps-csm-heading { font-weight: 700; letter-spacing: -0.025em; }\n.wpps-csm-description { max-width: 32rem; margin-left: auto; margin-right: auto; }\n.wpps-csm-countdown-item { box-shadow: 0 4px 16px rgba(15,118,110,0.08); border: 1px solid rgba(20,184,166,0.2); }\n.wpps-csm-subscribe button { border-radius: 8px; font-weight: 700; }",
				],
				self::darkOnLight( '#0d9488' ),
				self::palette( [ 'container_width' => 680 ] )
			),
			'cs-violet-launch' => array_merge(
				[
					'page_preset'              => 'cs-violet-launch',
					'mode'                     => 'coming_soon',
					'bg_type'                  => 'gradient',
					'bg_gradient_type'         => 'linear',
					'bg_gradient_angle'        => 135,
					'bg_gradient_color1'       => '#6d28d9',
					'bg_gradient_color2'       => '#2563eb',
					'bg_gradient_pos1'         => 0,
					'bg_gradient_pos2'         => 100,
					'heading'                  => self::richText( __( 'The Countdown Has Begun', 'wppowersuite-lite' ) ),
					'description'              => self::richText( __( 'Our next chapter starts soon. Subscribe for early access, updates, and launch-day perks.', 'wppowersuite-lite' ) ),
					'show_logo'                => 1,
					'show_subscribe'           => 1,
					'launch_date'              => self::sampleLaunchDate( 10 ),
					'auto_disable'             => 0,
					'bg_image_id'              => 0,
					'bg_image_url'             => '',
					'bg_video'                 => '',
					'social_links'             => [
						[ 'icon' => 'github', 'url' => 'https://github.com/' ],
						[ 'icon' => 'link', 'url' => 'https://' ],
					],
					'custom_css'               => ".wpps-csm-heading { text-transform: uppercase; letter-spacing: 0.08em; font-size: clamp(1.85rem, 4vw, 3rem); font-weight: 800; }\n.wpps-csm-countdown-item { min-width: 88px; backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.25); }\n.wpps-csm-subscribe button { border-radius: 999px; font-weight: 800; background: linear-gradient(90deg,#a855f7,#3b82f6) !important; border: none; }",
				],
				self::palette(
					[
						'text'             => '#ede9fe',
						'heading'          => '#ffffff',
						'description'      => 'rgba(237,233,254,0.92)',
						'countdown_bg'     => 'rgba(255,255,255,0.14)',
						'countdown_text'   => '#ffffff',
						'countdown_radius' => 999,
						'input_bg'         => 'rgba(15,23,42,0.4)',
						'input_text'       => '#ffffff',
						'input_border'     => 'rgba(167,139,250,0.5)',
						'social_bg'        => 'rgba(255,255,255,0.14)',
						'social_color'     => '#ffffff',
						'container_width'  => 800,
					]
				)
			),
			'maint-industrial' => array_merge(
				[
					'page_preset'                => 'maint-industrial',
					'mode'                       => 'maintenance',
					'bg_type'                    => 'gradient',
					'bg_gradient_type'           => 'linear',
					'bg_gradient_angle'          => 160,
					'bg_gradient_color1'         => '#fef3c7',
					'bg_gradient_color2'         => '#fde68a',
					'bg_gradient_pos1'           => 0,
					'bg_gradient_pos2'           => 100,
					'heading'                    => self::richText( __( 'We\'re Upgrading the Site', 'wppowersuite-lite' ) ),
					'description'                => self::richText( __( 'Scheduled maintenance is in progress. Everything should be back online shortly — thanks for your patience.', 'wppowersuite-lite' ) ),
					'launch_date'                => '',
					'custom_css'                 => ".wpps-csm-container{position:relative;padding:2.75rem 2.25rem 2.5rem;background:#fffdf8;border-radius:20px;border:1px solid #fcd34d;box-shadow:0 24px 60px rgba(120,53,15,0.14),inset 0 1px 0 rgba(255,255,255,0.9);}\n.wpps-csm-container::before{content:'';position:absolute;top:0;left:1.75rem;right:1.75rem;height:5px;border-radius:0 0 6px 6px;background:repeating-linear-gradient(90deg,#78350f 0,#78350f 10px,#fbbf24 10px,#fbbf24 20px);}\n.wpps-csm-heading{font-weight:900;text-transform:uppercase;letter-spacing:0.06em;font-size:clamp(1.65rem,3.8vw,2.55rem);line-height:1.15;margin-bottom:0.65rem;}\n.wpps-csm-description{max-width:30rem;margin:1.35rem auto 0;padding:1.2rem 1.35rem;background:#fffbeb;border-radius:12px;border:1px solid #fde68a;border-left:5px solid #d97706;font-weight:600;line-height:1.7;}",
				],
				self::presetShell( false ),
				self::palette(
					[
						'text'            => '#422006',
						'heading'         => '#78350f',
						'description'     => '#92400e',
						'container_width' => 640,
						'content_align'   => 'center',
					]
				)
			),
			'maint-dark-service' => array_merge(
				[
					'page_preset'        => 'maint-dark-service',
					'mode'               => 'maintenance',
					'bg_type'            => 'gradient',
					'bg_gradient_type'   => 'radial',
					'bg_gradient_angle'  => 0,
					'bg_gradient_color1' => '#0f172a',
					'bg_gradient_color2' => '#020617',
					'bg_gradient_pos1'   => 0,
					'bg_gradient_pos2'   => 100,
					'heading'            => self::richText( __( 'Back in a Moment', 'wppowersuite-lite' ) ),
					'description'        => self::richText( __( 'We\'re performing routine maintenance to keep things fast and secure. Please check back soon.', 'wppowersuite-lite' ) ),
					'launch_date'        => '',
					'custom_css'         => ".wpps-csm-container{position:relative;padding:3rem 2.25rem 2.75rem;border-radius:24px;background:linear-gradient(165deg,rgba(255,255,255,0.11),rgba(255,255,255,0.04));border:1px solid rgba(148,163,184,0.28);box-shadow:0 28px 70px rgba(2,6,23,0.55);backdrop-filter:blur(18px);}\n.wpps-csm-container::after{content:'';position:absolute;top:1.35rem;left:50%;transform:translateX(-50%);width:10px;height:10px;border-radius:50%;background:#38bdf8;box-shadow:0 0 0 0 rgba(56,189,248,0.55);animation:wpps-maint-pulse 2.4s ease-out infinite;}\n@keyframes wpps-maint-pulse{0%{box-shadow:0 0 0 0 rgba(56,189,248,0.55);}70%{box-shadow:0 0 0 14px rgba(56,189,248,0);}100%{box-shadow:0 0 0 0 rgba(56,189,248,0);}}\n.wpps-csm-heading{font-weight:800;letter-spacing:-0.035em;font-size:clamp(2rem,4.5vw,3.15rem);line-height:1.12;margin-top:1.5rem;margin-bottom:0.75rem;}\n.wpps-csm-description{max-width:32rem;margin:1.25rem auto 0;padding:1.15rem 1.35rem;border-radius:14px;background:rgba(15,23,42,0.55);border:1px solid rgba(148,163,184,0.22);line-height:1.75;font-size:clamp(1rem,2vw,1.125rem);}",
				],
				self::presetShell( false ),
				self::lightOnDark(),
				self::palette( [ 'container_width' => 700 ] )
			),
			'maint-clean-gray' => array_merge(
				[
					'page_preset'        => 'maint-clean-gray',
					'mode'               => 'maintenance',
					'bg_type'            => 'gradient',
					'bg_gradient_type'   => 'linear',
					'bg_gradient_angle'  => 180,
					'bg_gradient_color1' => '#ffffff',
					'bg_gradient_color2' => '#f1f5f9',
					'bg_gradient_pos1'   => 0,
					'bg_gradient_pos2'   => 100,
					'heading'            => self::richText( __( 'Maintenance in Progress', 'wppowersuite-lite' ) ),
					'description'        => self::richText( __( 'Our team is making improvements behind the scenes. Service will resume automatically when work is complete.', 'wppowersuite-lite' ) ),
					'launch_date'        => '',
					'custom_css'         => ".wpps-csm-container{padding:3rem 2.5rem 2.75rem;background:#ffffff;border-radius:22px;border:1px solid #e2e8f0;box-shadow:0 1px 2px rgba(15,23,42,0.04),0 20px 48px rgba(15,23,42,0.07);}\n.wpps-csm-heading{font-weight:700;letter-spacing:-0.04em;font-size:clamp(2rem,4.2vw,2.85rem);line-height:1.15;margin-bottom:0.5rem;}\n.wpps-csm-heading::before{content:'';display:block;width:44px;height:44px;margin:0 auto 1.25rem;border-radius:12px;background:#eff6ff url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M12 6v6l3 3'/%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3C/svg%3E\") center/22px no-repeat;}\n.wpps-csm-description{max-width:28rem;margin:1.5rem auto 0;font-size:clamp(1rem,2vw,1.125rem);line-height:1.75;}",
				],
				self::presetShell( false ),
				self::palette(
					[
						'text'            => '#64748b',
						'heading'         => '#0f172a',
						'description'     => '#64748b',
						'container_width' => 640,
						'content_align'   => 'center',
					]
				)
			),
			'maint-warning-stripe' => array_merge(
				[
					'page_preset'                => 'maint-warning-stripe',
					'mode'                       => 'maintenance',
					'bg_type'                    => 'color',
					'bg_color'                   => '#1c1917',
					'heading'                    => self::richText( __( 'Planned Downtime', 'wppowersuite-lite' ) ),
					'description'                => self::richText( __( 'The site is temporarily unavailable while we deploy updates. Expected duration: a few minutes.', 'wppowersuite-lite' ) ),
					'launch_date'                => '',
					'custom_css'                 => "body::before{content:'';position:fixed;inset:0;pointer-events:none;background:repeating-linear-gradient(-45deg,#facc15 0,#facc15 14px,#1c1917 14px,#1c1917 28px);opacity:0.92;z-index:0;}\n.wpps-csm-container{position:relative;padding:2.25rem 2rem 2rem;background:#fef08a;border-radius:14px;border:3px solid #1c1917;box-shadow:10px 10px 0 #1c1917;}\n.wpps-csm-container::before{content:'';display:block;height:8px;margin:-2.25rem -2rem 1.5rem;width:calc(100% + 4rem);border-radius:11px 11px 0 0;background:repeating-linear-gradient(90deg,#1c1917 0,#1c1917 16px,#fef08a 16px,#fef08a 32px);}\n.wpps-csm-heading{font-weight:900;text-transform:uppercase;letter-spacing:0.08em;font-size:clamp(1.55rem,3.6vw,2.45rem);line-height:1.1;margin-bottom:0.85rem;}\n.wpps-csm-description{margin:1.15rem auto 0;padding:1rem 1.15rem;background:#1c1917;border-radius:8px;font-weight:700;line-height:1.6;letter-spacing:0.01em;font-size:clamp(0.95rem,2vw,1.05rem);}",
				],
				self::presetShell( false ),
				self::palette(
					[
						'text'            => '#1c1917',
						'heading'         => '#1c1917',
						'description'     => '#fef08a',
						'container_width' => 620,
						'content_align'   => 'center',
					]
				)
			),
			'maint-blueprint' => array_merge(
				[
					'page_preset'                => 'maint-blueprint',
					'mode'                       => 'maintenance',
					'bg_type'                    => 'patterns',
					'bg_pattern'                 => 'lines',
					'bg_pattern_overlay_color'   => '#1e3a8a',
					'bg_pattern_overlay_opacity' => 72,
					'heading'                    => self::richText( __( 'System Maintenance', 'wppowersuite-lite' ) ),
					'description'                => self::richText( __( 'Engineering work is underway. Retry in a few minutes — no action is required on your end.', 'wppowersuite-lite' ) ),
					'launch_date'                => '',
					'custom_css'                 => ".wpps-csm-container{position:relative;padding:2.25rem 2rem 2rem;border-radius:6px;background:rgba(15,23,42,0.78);background-image:linear-gradient(rgba(147,197,253,0.12) 1px,transparent 1px),linear-gradient(90deg,rgba(147,197,253,0.12) 1px,transparent 1px);background-size:32px 32px;border:1px solid rgba(147,197,253,0.35);box-shadow:inset 0 0 0 1px rgba(30,64,175,0.4),0 24px 50px rgba(2,6,23,0.45);font-family:'Courier New',Courier,monospace;}\n.wpps-csm-container::before{content:'STATUS: OFFLINE';position:absolute;top:-0.65rem;left:1.25rem;padding:0.2rem 0.65rem;font-size:0.65rem;font-weight:700;letter-spacing:0.14em;color:#0f172a;background:#22d3ee;border-radius:2px;}\n.wpps-csm-heading{font-family:inherit;letter-spacing:0.1em;text-transform:uppercase;font-weight:700;font-size:clamp(1.45rem,3.2vw,2rem);margin-top:0.35rem;margin-bottom:0.65rem;}\n.wpps-csm-heading::before{content:'> ';color:#22d3ee;font-weight:700;}\n.wpps-csm-description{font-family:inherit;font-size:0.95rem;margin:1.1rem auto 0;padding:0.95rem 1.05rem;background:rgba(2,6,23,0.72);border-radius:4px;border:1px dashed rgba(147,197,253,0.45);display:inline-block;line-height:1.65;max-width:100%;text-align:left;}",
				],
				self::presetShell( false ),
				self::palette(
					[
						'text'            => '#dbeafe',
						'heading'         => '#93c5fd',
						'description'     => '#bfdbfe',
						'container_width' => 660,
						'content_align'   => 'center',
					]
				)
			),
			'maint-workshop-photo' => array_merge(
				[
					'page_preset'              => 'maint-workshop-photo',
					'mode'                     => 'maintenance',
					'bg_type'                  => 'image',
					'bg_image_url'             => $workshop_img,
					'bg_image_overlay_color'   => '#0c0a09',
					'bg_image_overlay_opacity' => 72,
					'heading'                  => self::richText( __( 'Work in Progress', 'wppowersuite-lite' ) ),
					'description'              => self::richText( __( 'Our crew is on site making improvements. We\'ll have everything ready for you shortly.', 'wppowersuite-lite' ) ),
					'launch_date'              => '',
					'custom_css'               => "body::before{content:'';position:fixed;inset:0;pointer-events:none;background:radial-gradient(ellipse 70% 55% at 50% 100%,rgba(251,146,60,0.22),transparent 60%),linear-gradient(180deg,rgba(12,10,9,0.15),rgba(12,10,9,0.55));z-index:0;}\n.wpps-csm-container{position:relative;padding:3rem 2.25rem 2.75rem;border-radius:20px;background:rgba(12,10,9,0.58);border:1px solid rgba(251,146,60,0.32);box-shadow:0 28px 64px rgba(0,0,0,0.42);backdrop-filter:blur(12px);}\n.wpps-csm-container::before{content:'';display:block;width:64px;height:3px;border-radius:999px;background:linear-gradient(90deg,#fb923c,#f97316);margin:0 auto 1.35rem;box-shadow:0 0 24px rgba(251,146,60,0.55);}\n.wpps-csm-heading{font-weight:900;letter-spacing:-0.04em;font-size:clamp(2.15rem,5vw,3.5rem);line-height:1.08;margin-bottom:0.65rem;}\n.wpps-csm-description{margin:1.35rem auto 0;padding:1.2rem 1.4rem;border-radius:14px;background:rgba(12,10,9,0.65);border:1px solid rgba(251,146,60,0.22);border-top:3px solid #fb923c;line-height:1.7;font-size:clamp(1rem,2vw,1.125rem);max-width:34rem;}",
				],
				self::presetShell( false ),
				self::lightOnDark(),
				self::palette( [ 'container_width' => 760 ] )
			),
		];
	}

	/**
	 * Settings that must never be overwritten when applying a template in the admin UI.
	 *
	 * @return string[]
	 */
	public static function getPresetProtectedKeys(): array {
		return [
			'enabled',
			'use_existing_page',
			'existing_page_url',
			'page_title',
			'logo_id',
			'logo_url',
			'logo_source',
			'logo_max_width',
			'logo_width_desktop',
			'logo_width_tablet',
			'logo_width_mobile',
			'subscribe_consent_text',
			'exclude_urls',
			'exclude_woocommerce',
			'allowed_roles',
			'allowed_user_ids',
			'bypass_token',
			'fetch_secret',
		];
	}

	/**
	 * Defaults merged into preset payloads for the admin form (design + content only).
	 *
	 * @return array<string, mixed>
	 */
	public static function getPresetBaseSettings(): array {
		$all = Module::getDefaultSettings();
		$keys = [
			'page_preset',
			'mode',
			'show_logo',
			'show_subscribe',
			'launch_date',
			'auto_disable',
			'heading',
			'description',
			'bg_type',
			'bg_color',
			'bg_image_url',
			'bg_image_overlay_color',
			'bg_image_overlay_opacity',
			'bg_image_position',
			'bg_image_size',
			'bg_image_repeat',
			'bg_pattern',
			'bg_pattern_overlay_color',
			'bg_pattern_overlay_opacity',
			'bg_gradient_type',
			'bg_gradient_angle',
			'bg_gradient_color1',
			'bg_gradient_color2',
			'bg_gradient_pos1',
			'bg_gradient_pos2',
			'bg_video',
			'bg_video_overlay_color',
			'bg_video_overlay_opacity',
			'social_links',
			'custom_css',
			'text_color',
			'heading_color',
			'description_color',
			'content_align',
			'container_max_width',
			'logo_align',
			'logo_bg_enabled',
			'logo_bg_color',
			'logo_bg_padding',
			'logo_border_radius',
			'countdown_bg_color',
			'countdown_text_color',
			'countdown_border_radius',
			'subscribe_btn_bg',
			'subscribe_btn_text',
			'subscribe_input_bg',
			'subscribe_input_text',
			'subscribe_input_border',
			'social_icon_bg',
			'social_icon_color',
		];

		return array_intersect_key( $all, array_flip( $keys ) );
	}

	/**
	 * @return array<string, mixed>|null
	 */
	public static function getPresetSettings( string $preset_id ): ?array {
		$overrides = self::getOverrides();
		if ( ! isset( $overrides[ $preset_id ] ) ) {
			return null;
		}

		$settings = array_merge( self::getPresetBaseSettings(), $overrides[ $preset_id ] );
		if ( $preset_id === 'default' ) {
			$settings['page_preset'] = 'default';
		}

		foreach ( self::getPresetProtectedKeys() as $key ) {
			unset( $settings[ $key ] );
		}
		unset( $settings['bg_image_id'] );

		return $settings;
	}

	/**
	 * @return array<string, array<string, mixed>>
	 */
	public static function getPresetsForJs(): array {
		$out = [];
		foreach ( array_keys( self::getOverrides() ) as $preset_id ) {
			$settings = self::getPresetSettings( $preset_id );
			if ( $settings !== null ) {
				$out[ $preset_id ] = $settings;
			}
		}

		return $out;
	}
}
