<?php

class Diller_Refer_Friend_Form_Shortcode {

	public $short_code_name = '';
	public $form = null;

	public function __construct() {
		$this->short_code_name = Diller_Loyalty_Configs::LOYALTY_FRIEND_REFERRAL_FORM_SHORTCODE;
		$this->form = new Diller_Refer_Friend_Form("dillerReferFriendForm");
	}

	public function render($atts) {
		$params = shortcode_atts( array(
			'title' => __('Refer a friend', 'diller-loyalty'),
		), $atts );

		$this->form->set_title($params["title"]);
		$this->form->build_fields();

		if ($this->form->was_submitted() && $this->form->request_validated() && $this->form->save()):
			return DillerLoyalty()->display_notices($this->form->get_id(), false);
		endif;

		// Use ob_start() to Control Output Timing and preventing from printing the content too early
		ob_start();
		$this->form->render();
		return ob_get_clean();
	}

	public function enqueue_scripts() {
		$this->form->enqueue_scripts();
	}

	public function enqueue_styles() {
		$this->form->enqueue_styles();
	}
}
