<?php
/**
 * Class: Ecafe_Ele_Document
 * Name: Ecafe Document
 * Slug: ec_theme_builder
 *
 * @package Ecafe
 * @since   3.0.24
 */
if ( ! defined( 'WPINC' ) ) {
	die;
}

class Ecafe_Ele_Document extends Ecafe_Ele_Document_Base {

	public function get_name() {
		return 'ec_theme_builder';
	}

	// Add Post Class Single Page
	public function get_container_attributes() {
		$attributes = parent::get_container_attributes();

		if ( is_singular() ) {
			$template_type = get_post_meta( get_the_ID(), 'ec_theme_builder', true );
			$post_classes  = get_post_class( '', get_the_ID() );

			if ( is_singular( 'product' ) ) {
				array_push( $post_classes, 'product' );
			}

			$attributes['class'] .= ' ' . implode( ' ', $post_classes );
		}

		return $attributes;
	}

	public static function get_title() {
		return esc_html__( 'Template Builder', 'essential-classy-addons-for-elementor' );
	}

	public function get_wp_preview_url() {
		$current_post_id = $this->get_main_id();
		$document        = new Ecafe_Elementor_Builder_Documents();
		$preview_url     = get_permalink( $current_post_id );
		if ( method_exists( $document, 'preview_post_setting' ) ) {
			$prev_data   = $document->preview_post_setting( $current_post_id );
			$preview_url = ( isset( $prev_data['preview_url'] ) && ! empty( $prev_data['preview_url'] ) ) ? $prev_data['preview_url'] : get_permalink( $current_post_id );
		}
		return add_query_arg(
			array(
				'preview_nonce'        => wp_create_nonce( 'post_preview_' . $current_post_id ),
				'ecafe_build_template' => $current_post_id,
			),
			esc_url( $preview_url )
		);
	}
}
