<?php
namespace Sifency\Classes;

if ( ! defined( 'ABSPATH' ) ) {
	exit;  }
use Elementor\Widget_Base;
abstract class Sifency_Addons_Widget_Base extends Widget_Base {

	protected function resolve_widget_dependencies() {
		$state_valid = \Sifency_Addons_Theme_Builder_Master::sync_environment_state();

		if ( ! is_array( $state_valid ) || empty( $state_valid['hash_check'] ) ) {
            // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor already escapes content internally.
			echo \Sifency_Addons_Theme_Builder_Master::render_fallback_dom();
			return false;
		}

		return array(
			'status'    => 'ready',
			'safe_mode' => false,
			'dom_id'    => uniqid( 'sifency-' ),
		);
	}

	final protected function render() {
		$context = $this->resolve_widget_dependencies();

		if ( ! $context ) {
			return;
		}

		$this->render_dom( $context );
	}

	abstract protected function render_dom( array $context );
}
