<?php
/**
 * Class: Ecafe_Ele_Document_Base
 * Name: Document Base
 * Slug: ec-template-builder-document
 *
 * @package Ecafe
 * @since   3.0.24
 */
if ( ! defined( 'WPINC' ) ) {
	die;
}

class Ecafe_Ele_Document_Base extends Elementor\Core\Base\Document {

	public function get_name() {
		return 'ec-template-builder-document';
	}

	public static function get_type() {
		return 'ec-template-builder-document';
	}

	public static function get_properties() {
		$properties = parent::get_properties();

		$properties['cpt']           = array( 'ec_theme_builder' );
		$properties['register_type'] = true;
		$properties['support_kit']   = true;

		return $properties;
	}

	public static function get_preview_as_default() {
		return '';
	}

	public static function get_preview_as_options() {
		return array();
	}

	/**
	 * Get elements data with new query
	 *
	 * @param null    $data
	 * @param boolean $with_html_content
	 */
	public function get_elements_raw_data( $data = null, $with_html_content = false ) {

		ecafe_theme_builder_load()->documents->ec_preview_query_switch();

		$editor_data = parent::get_elements_raw_data( $data, $with_html_content );

		ecafe_theme_builder_load()->documents->ec_current_query_restore();

		return $editor_data;
	}

	/**
	 * Render current element
	 *
	 * @param $data
	 */
	public function render_element( $data ) {

		ecafe_theme_builder_load()->documents->ec_preview_query_switch();

		$render_html = parent::render_element( $data );

		ecafe_theme_builder_load()->documents->ec_current_query_restore();

		return $render_html;
	}

	/**
	 * Return elements data
	 *
	 * @param string $status
	 */
	public function get_elements_data( $status = 'publish' ) {

		if ( ! isset( $_GET[ ECAFE_POST ] ) || ! isset( $_GET['preview'] ) ) {
			return parent::get_elements_data( $status );
		}

		ecafe_theme_builder_load()->documents->ec_preview_query_switch();

		$elements = parent::get_elements_data( $status );

		ecafe_theme_builder_load()->documents->ec_current_query_restore();

		return $elements;
	}
}
