<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
use Elementor\Controls_Manager;

/**
 * WooCommerce Guard Trait - Handle WooCommerce checks and notices
 */
trait Sifency_Addons_WooCommerce_Guard {

	protected function is_woocommerce_active() {
		return class_exists( 'WooCommerce' ) || class_exists( 'woocommerce' );
	}

	protected function add_woocommerce_inactive_notice() {
		$this->start_controls_section( 'woo_notice', array( 'label' => esc_html__( 'Notice', 'sifency-addons' ) ) );
		$this->add_control(
			'woo_notice_control',
			array(
				'type' => Controls_Manager::RAW_HTML,
				'raw'  => '<div class="elementor-panel-alert elementor-panel-alert-warning">' . esc_html__( 'WooCommerce is not installed or active.', 'sifency-addons' ) . '</div>',
			)
		);
		$this->end_controls_section();
	}

	protected function render_woocommerce_placeholder( $msg = 'WooCommerce not active' ) {
		echo '<div class="sifency-placeholder">' . esc_html( $msg ) . '</div>';
	}

	protected function check_and_guard_woocommerce() {
		if ( ! $this->is_woocommerce_active() ) {
			$this->add_woocommerce_inactive_notice();
			return false;
		}
		return true;
	}
}
