<?php
/**
 * Default example buttons on first install.
 *
 * @package Rsmspark_Content_Widgets
 */

defined( 'ABSPATH' ) || exit;

/**
 * Rsmspark_Buttons_Seed
 */
class Rsmspark_Buttons_Seed {

	const OPTION_KEY = 'rsmspark_buttons_seeded';

	/**
	 * @return void
	 */
	public static function maybe_create_defaults() {
		if ( get_option( self::OPTION_KEY, false ) ) {
			return;
		}

		$existing = get_posts(
			array(
				'post_type'      => Rsmspark_Buttons_Config::CPT,
				'post_status'    => 'any',
				'posts_per_page' => 1,
				'fields'         => 'ids',
			)
		);

		if ( ! empty( $existing ) ) {
			update_option( self::OPTION_KEY, 1, false );
			return;
		}

		$presets = array(
			array(
				'title'  => __( 'Primary CTA', 'rsm-content-widgets' ),
				'config' => array(
					'text_line_1'    => __( 'Get Started', 'rsm-content-widgets' ),
					'text_line_2'    => __( 'Free trial — no card required', 'rsm-content-widgets' ),
					'shape'          => 'rounded',
					'bg_color'       => '#2563eb',
					'bg_hover_color' => '#1d4ed8',
					'text_color'     => '#ffffff',
					'shadow'         => 'soft',
					'hover_effect'   => 'lift',
					'link_url'       => '#',
				),
			),
			array(
				'title'  => __( 'Secondary Outline', 'rsm-content-widgets' ),
				'config' => array(
					'text_line_1'    => __( 'Learn More', 'rsm-content-widgets' ),
					'shape'          => 'rounded',
					'bg_color'       => '#ffffff',
					'bg_hover_color' => '#f8fafc',
					'text_color'     => '#1e293b',
					'border_color'   => '#cbd5e1',
					'border_width'   => 2,
					'hover_effect'   => 'none',
					'shadow'         => 'none',
					'link_url'       => '#',
				),
			),
			array(
				'title'  => __( 'Pill Action', 'rsm-content-widgets' ),
				'config' => array(
					'text_line_1'    => __( 'Shop Now', 'rsm-content-widgets' ),
					'icon'           => 'cart',
					'icon_type'      => 'sprite',
					'shape'          => 'pill',
					'bg_color'       => '#0f172a',
					'bg_hover_color' => '#334155',
					'text_color'     => '#ffffff',
					'hover_effect'   => 'scale',
					'link_url'       => '#',
				),
			),
			array(
				'title'  => __( 'Danger / Warning', 'rsm-content-widgets' ),
				'config' => array(
					'text_line_1'    => __( 'Delete Account', 'rsm-content-widgets' ),
					'shape'          => 'rectangle',
					'border_radius'  => 4,
					'bg_color'       => '#dc2626',
					'bg_hover_color' => '#b91c1c',
					'text_color'     => '#ffffff',
					'hover_effect'   => 'glow',
					'link_url'       => '#',
				),
			),
			array(
				'title'  => __( 'Ghost Link', 'rsm-content-widgets' ),
				'config' => array(
					'text_line_1'    => __( 'View Details', 'rsm-content-widgets' ),
					'shape'          => 'rounded',
					'bg_color'       => 'transparent',
					'bg_hover_color' => '#f1f5f9',
					'text_color'     => '#334155',
					'shadow'         => 'none',
					'hover_effect'   => 'scale',
					'link_url'       => '#',
				),
			),
		);

		foreach ( $presets as $preset ) {
			$post_id = wp_insert_post(
				array(
					'post_type'   => Rsmspark_Buttons_Config::CPT,
					'post_status' => 'publish',
					'post_title'  => (string) $preset['title'],
				),
				true
			);

			if ( ! is_wp_error( $post_id ) && $post_id ) {
				Rsmspark_Buttons_Config::save( (int) $post_id, wp_parse_args( $preset['config'], Rsmspark_Buttons_Config::defaults() ) );
			}
		}

		update_option( self::OPTION_KEY, 1, false );
	}
}
