<?php

namespace Yuvayana\Acadlix\Common\Controller;

defined('ABSPATH') || exit();

if (!class_exists("ThankyouController")) {
  class ThankyouController
  {
    protected static $_instance = null;

    public function __construct()
    {
      if (is_admin())
        return;
      add_filter("template_include", [$this, 'template_loader'], 10);
      add_action("wp_enqueue_scripts", [$this, 'enqueue_front_thankyou']);
    }

    protected function is_thankyou_page()
    {
      $thankyou_page_id = acadlix()->helper()->acadlix_get_option('acadlix_thankyou_page_id');
      return $thankyou_page_id && is_page($thankyou_page_id);
    }

    public function template_loader($template)
    {
      if ($this->is_thankyou_page()) {
        // !defined('DONOTCACHEPAGE') && define('DONOTCACHEPAGE', true); // phpcs:ignore

        // $thankyou_template = $this->processData();
        // if ($thankyou_template) {
        //     return $thankyou_template;
        // }
        return acadlix()->view()->thankyou()->render();
      }

      return $template;
    }


    public function enqueue_front_thankyou()
    {
      wp_enqueue_style('acadlix-front-thankyou-css');
    }

    public static function instance()
    {
      if (is_null(self::$_instance)) {
        self::$_instance = new self();
      }

      return self::$_instance;
    }
  }
}