<?php
namespace Sifency\Classes;

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

use Sifency\Classes\Sifency_Addons_Widget_Base;

abstract class Sifency_Themebuilder_Widget_Base extends Sifency_Addons_Widget_Base {

	abstract protected function get_allowed_template_types();

	public function show_in_panel() {

		$is_core_active = class_exists( 'Sifency_Essential' );

		$selective_environment = class_exists( 'Sifency_Addons_Theme_Builder_Master' ) &&
			\Sifency_Addons_Theme_Builder_Master::sifency_addons_selective_environment();

		if ( $is_core_active || $selective_environment ) {
			return true;
		}

		$current_type = \Sifency_Addons_Theme_Builder_Master::get_current_theme_builder_type();

		if ( ! $current_type ) {
			return false;
		}

		$allowed_types = $this->get_allowed_template_types();

		if ( is_string( $allowed_types ) ) {
			$allowed_types = array( $allowed_types );
		}

		return in_array( $current_type, $allowed_types, true );
	}
}
