<?php

namespace Simple_Giveaways;

/**
 * TinyMCE Custom Control
 *
 * Copied from:
 *
 * @author Aurooba Ahmed <https://aurooba.com>
 * @license http://www.gnu.org/licenses/gpl-2.0.html
 */
class SG_Customizer_TinyMCE_Control extends \WP_Customize_Control {
	/**
	 * The type of control being rendered
	 */
	public $type = 'tinymce_editor';

	/**
	 * Pass our TinyMCE toolbar config to JavaScript
	 */
	public function to_json() {
		parent::to_json();

		$this->json['sg_tinymce_toolbar1'] = isset( $this->input_attrs['toolbar1'] ) ? esc_attr( $this->input_attrs['toolbar1'] ) : 'bold italic bullist numlist alignleft aligncenter alignright link';

		$this->json['sg_tinymce_toolbar2'] = isset( $this->input_attrs['toolbar2'] ) ? esc_attr( $this->input_attrs['toolbar2'] ) : '';

		$this->json['sg_tinymce_mediabuttons'] = isset( $this->input_attrs['mediaButtons'] ) && ( $this->input_attrs['mediaButtons'] === true ) ? true : false;

		$this->json['sg_tinymce_height'] = isset( $this->input_attrs['height'] ) ? esc_attr( $this->input_attrs['height'] ) : 200;
	}
	/**
	 * Render the control in the customizer
	 */
	public function render_content() {
		?>
		<div class="tinymce-control">
			<span class="customize-control-title">
				<?php echo esc_html( $this->label ); ?>
			</span>

			<?php if ( ! empty( $this->description ) ) { ?>
				<span class="customize-control-description">
					<?php echo esc_html( $this->description ); ?>
				</span>
			<?php } ?>

			<textarea id="<?php echo esc_attr( $this->id ); ?>" class="customize-control-tinymce-editor" <?php $this->link(); ?>><?php echo esc_attr( $this->value() ); ?></textarea>
		</div>
		<?php
	}
}
