<?php

namespace GriffinForms\Frontend;

class ShortCodes extends \GriffinForms\Frontend\Format
{   
    public function registerShortcodes()
    {
        $shortcodes = $this->config->getShortcodes();
        foreach ($shortcodes as $shortcode) {
            add_shortcode($shortcode, array($this, 'shortcodeOutput'));
        }
    }
    
    public function shortcodeOutput($atts, $content, $shortcode_tag)
    {
        $view_class = '\GriffinForms\Frontend\Views\\' . str_replace('_', '', $shortcode_tag);
        $view = new $view_class($atts, $content, $shortcode_tag);
        
        $html = '<div class="griffinforms-shortcode-view-container container-fluid">';
        $html .= $view->html();
        $html .= '</div>';
        return $html;
    }
    
    public function __construct()
    {
        $this->setAll();
        add_action('init', array($this, 'registerShortcodes'));
    }
}