<?php

namespace GriffinForms\Admin\Html\Pages;

class Format extends \GriffinForms\Admin\Html\Format
{
    protected $config;
    protected $sql;
    protected $post;
    protected $referer;
    protected $secure;
    protected $choices;
    protected $modal_ids = array();
    protected $buttons;
    protected $item_id = 0;
    protected $js_data = [];
    protected $js_object = null;
    
    protected function setReferer()
    {
        $this->referer = wp_get_referer();
    }
    
    protected function setSql()
    {
        $this->setHelper('sql');
    }
    
    protected function setSecure()
    {
        $this->setHelper('secure');
    }    
    
    protected function setChoices()
    {
        $this->setHelper('choices');
    }
    
    protected function setJsData()
    {
        $this->js_data = array('item_id' => $this->item_id);
    }    
    
    protected function setJsObject()
    {
        $js_class = '\GriffinForms\Admin\Js\Local\\' . $this->meta;
        if (!class_exists($js_class)) {
            return;
        }

        $this->js_object = new $js_class($this->js_data);
    }
    
    public function getJs()
    {
        $this->js_object->js();
    }

    public function getInlineJs()
    {
        if (!is_object($this->js_object) || !method_exists($this->js_object, 'js')) {
            return;
        }

        wp_add_inline_script('griffinforms-global-js', $this->js_object->js());
    }
    
    protected function getNonceAction($action) {
        return 'action=' . $action . '&object=' . $this->meta;
    }
    
    protected function setSnackBar()
    {
        $snackbar = new \GriffinForms\Admin\Html\Elements\SnackBar();
        $snackbar->html();
    }
    
    protected function toastAlert()
    {
        $toast = new \GriffinForms\Admin\Html\Elements\Toast();
        $toast->html();
    }

    protected function setButtons()
    {
        $this->buttons = \GriffinForms\Admin\Html\Elements\Buttons::getInstance();
    }
    
    public function spinnerOverlay()
    {
       $spinner_overlay = new \GriffinForms\Admin\Html\Elements\SpinnerOverlay(); 
       $spinner_overlay->html(); 
    }
    
    public function pageHeading($text = '', $subtext = '')
    {
        if($text === '') {
            $text = $this->lang->getText('heading' . $this->meta, $subtext);
        }

        $heading = new \GriffinForms\Admin\Html\Elements\PageHeading($text, $subtext);
        $heading->html();
        
    }

    public function __construct()
    {
        $this->setAll();
    }
}
