<?php

namespace GriffinForms\Admin\Html;

class format extends \GriffinForms\Admin\Format
{   
    protected $config;
    protected $meta;
    protected $component_js;
    protected $component_css;
    protected $modal_ids = array();
    protected $inline_icons;
    
    protected function jsReady($string)
    {
        return str_replace('"', '\"', $string);
    }
    
    protected function setComponentJs()
    {
        $file = $this->config->getRootPath() . 'admin/js/griffinforms-' . strtolower($this->meta) . '.js';
        if(file_exists($file)) {
            $url = $this->config->getRootUrl() . 'admin/js/griffinforms-' . strtolower($this->meta) . '.js';
            wp_enqueue_script('griffinforms-' . strtolower($this->meta), $url, [], '1.0', false);
        }
    }    
    
    protected function setComponentCss()
    {
        $file = $this->config->getRootPath() . 'admin/css/griffinforms-' . strtolower($this->meta) . '.css';
        if(file_exists($file)) {
            $url = $this->config->getRootUrl() . 'admin/css/griffinforms-' . strtolower($this->meta) . '.css';
            wp_enqueue_style('griffinforms-' . strtolower($this->meta), $url, array(), '1.0', false);
        }
    }
    
    protected function mIcon($icon, $style = 'rounded', $format = 'print')
    {
        $icon_class = 'material-symbols-' . $style . ' griffinforms-icon align-text-bottom';
        
        if ($format == 'print') {
            echo '<i class=\'' . esc_attr($icon_class) . '\'>' . esc_attr($icon) . '</i>';
        } else {
            return '<i class=\'' . esc_attr($icon_class) . '\'>' . $icon . '</i>';
        }
    }

    protected function setInlineIcons()
    {
        $this->inline_icons = \GriffinForms\Admin\Html\Icons\InlineIcons::getInstance();
    }
    
    protected function newModal($for, $class = '', $data = '')
    {
        $modal_class = '\GriffinForms\Admin\Html\Modals\\' . $for;
        $modal = new $modal_class($this->lang, $data);
        $this->modal_ids[$for] = $modal->getId();
        $modal->setCssClass($class);
        $modal->html();
    }
    
    public function __construct()
    {
        $this->setAll();
    }
}