<?php
defined('_WPBOOKINGPRO_EXEC') or die;
if(!class_exists("WpBookingPro_ConfigView")) {
    /**
     * Class WpBookingPro_ConfigView
     */
    class WpBookingPro_ConfigView extends WooBookingView
    {
        /**
         * @var
         */
        public $item;

        /**
         * @param null $tpl
         * @return false|string
         * @throws Exception
         */
        public function display($tpl = null)
        {
            if ($tpl == "list") {
                $tpl = "form";
            }
            switch ($tpl) {
                case "form":
                    $modelConfig = $this->getModel('config');
                    $input = Factory::getInput();
                    $id = $input->getInt('id');
                    $this->item = $modelConfig->getItem(1);
                    $this->form = $modelConfig->getForm();
                    return parent::display($tpl);
                    break;
                case "install":
                    $tmpl_short_path = "/views/config/tmpl/install.php";
                    $tmpl_path = WPBOOKINGPRO_PATH_COMPONENT . $tmpl_short_path;
                    $debug = "";
                    $open_source = Factory::getOpenSource();
                    if (file_exists($tmpl_path)) {
                        ob_start();
                        include $tmpl_path;
                        $content = ob_get_clean();
                        if (!trim($content)) {
                            $content = "<div class='wrapper-woo-booking'><p>layout <b>$tmpl_short_path</b> empty please add content to it</p></div>";
                        }
                        $content = "<div class=\"wrapper-woo-booking\">$content</div>";
                        $doc = Factory::getDocument();
                        $open_source->wp_add_inline_script();
                        return $content;
                    } else {
                        throw new Exception("Error:tpl <b>$tpl</b> not exits, please create it in view <b>" . $this->view . "</b>");
                    }
                    break;
            }

        }
    }
}