<?php
/**
 * WeCodeArt Framework.
 *
 * WARNING: This file is part of the core WeCodeArt Framework. DO NOT edit this file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * @package 	WeCodeArt Framework
 * @subpackage 	Support\WooCommerce
 * @copyright   Copyright (c) 2025, WeCodeArt Framework
 * @since 		1.9
 * @version		6.3.7
 */

namespace WeCodeArt\Support\Plugins;

defined( 'ABSPATH' ) || exit;

use WeCodeArt\Support\Plugins;
use WeCodeArt\Admin\Notifications;
use WeCodeArt\Admin\Notifications\Notification;
use WeCodeArt\Config\Traits\Singleton;
use WeCodeArt\Config\Interfaces\Integration;
use function WeCodeArt\Functions\get_prop;

/**
 * The Class: Handles all necesary functions and requirements 
 * to ensure proper support for WooCommerce
 */
class WooCommerce implements Integration {

	use Singleton;

	const NOTICE_ID = 'wecodeart/extension/woocommerce';
	
	/**
	 * Get Conditionals
	 *
	 * @return void
	 */
	public static function get_conditionals() {
		wecodeart( 'ifso' )->register( 'is_woocommerce_active', WooCommerce\Condition::class );

		return [ 'is_woocommerce_active' ];
	}

	/**
	 * Hooks
	 *
	 * @since   5.0.0
	 * @version	6.1.2
	 *
	 * @return  void
	 */
	public function register_hooks() {
		add_action( 'admin_notices', [ $this, 'manage_notice' ] );
	}

	/**
	 * Manage Notice
	 *
	 * @since 	6.1.2
	 * @version	6.1.7
	 */
	public function manage_notice() {
		if( class_exists( 'WCA\EXT\WOO' ) ) {
			return;
		}

		$notification = new Notification(
			sprintf( '<h3 style="margin: .5em 0;">%s</h3>', esc_html__( 'Amazing news!', 'wecodeart' ) ) .
			sprintf(
				esc_html__( 'We have an extension that integrates our theme with WooCommerce plugin! You can get it from %s.', 'wecodeart' ),
				sprintf(
					'<a href="%s" target="_blank">%s</a>',
					esc_url( admin_url( '/themes.php?page=wecodeart&tab=plugins' ) ),
					esc_html__( 'here', 'wecodeart' )
				)
			),
			[
				'id'			=> self::NOTICE_ID,
				'type'     		=> Notification::INFO,
				'priority' 		=> 1,
				'class'			=> 'notice is-dismissible',
				'capabilities' 	=> 'activate_plugins',
			]
		);
		
		if( get_user_option( self::NOTICE_ID ) === 'seen' ) {
			Notifications::get_instance()->remove_notification( $notification );
			set_transient( self::NOTICE_ID, true, WEEK_IN_SECONDS );
			return;
		}

		if( get_transient( self::NOTICE_ID ) === false ) {
			Notifications::get_instance()->add_notification( $notification );
		}
	}

	/**
	 * Installer
	 *
	 * @since	6.1.2
	 * @version	6.3.1
	 *
	 * @return 	array
	 */
	public function installer(): array {
		return [
			'slug'          => 'BicanMarianValeriu/wca-woocommerce',
			'title'         => esc_html__( 'WCA: WooCommerce', 'wecodeart' ),
			'description'   => Plugins::get_default_description( 'WooCommerce', 'external' ),
			'source'        => 'github',
			'more'          => 'https://www.wecodeart.com/integrations/woocommerce/',
			'required' 		=> [ 'woocommerce' ]
		];
	}
}