<?php

namespace GriffinForms\Admin\Html\Modals;

class Format extends \GriffinForms\Admin\Html\Format
{
    protected $config;
    protected $meta;
    protected $lang;
    protected $name;
    protected $item_type;
    protected $id;
    protected $action_btn_id;
    protected $css_class;
    protected $data;
    protected $buttons;
    
    protected function setId()
    {
        $this->id = 'griffinforms-' . strtolower($this->meta) . '-modal';
    }
    
    protected function setActionBtnId()
    {
        $this->action_btn_id = 'griffinforms-modalaction-' . strtolower($this->meta);;
    }
    
    public function getId()
    {
        return $this->id;
    }
    
    public function setCssClass($css_class = '')
    {
        $this->css_class = $css_class;
    }

    public function setButtons()
    {
        $this->buttons = \GriffinForms\Admin\Html\Elements\Buttons::getInstance();
    }
    
    public function html()
    {
        echo '<div class="modal fade" id="' . esc_attr($this->id) . '">';
        echo '<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable ' . esc_attr($this->css_class) . '">';
        echo '<div class="modal-content rounded-2 border-0">';
        $this->modalHeader();
        $this->modalBody();
        $this->modalFooter();
        echo '</div></div></div>';
        
    }
    
    protected function modalHeader()
    {
        echo '<div class="modal-header border-bottom-0">';
        echo '<h6 class="modal-title">' . esc_html($this->headerText()) . '</h6>';
        echo '<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>';
        echo '</div>';
        
    }
    
    protected function modalBody()
    {
        echo '<div class="modal-body container-fluid bg-white">';
        $this->modalContent();
        echo '</div>';
        
    }
    
    protected function headerText()
    {
        return '';
    }
    
    protected function modalContent()
    {
        return '';
    }    
    
    protected function modalFooter()
    {
        echo '<div class="modal-footer border-top-0 gap-2">';
        $this->cancelBtn();
        $this->ActionBtn();
        echo '</div>';
    }

    protected function cancelBtn()
    {
        echo '<button type="button" class="button" data-bs-dismiss="modal">' . esc_html($this->lang->getText('cancel_btn')) . '</button>';
    }

    protected function actionBtn($text = 'save', $btn_class = 'primary')
    {
        $wp_class = $btn_class === 'primary' ? 'button button-primary' : 'button';
        echo '<button type="button" id="' . esc_attr($this->action_btn_id). '" class="' . esc_attr($wp_class) . '" data-bs-dismiss="modal" data-item-type="" data-item-id="" data-parent-id="" data-parent-type="">' . esc_html($this->lang->getText($text, 'action_btn')) . '</button>';
    }

    // Deprecated
    protected function modalFormRow($label, $field)
    {
        echo '<div class="griffinforms-modal-row row my-3">';
        echo '<div class="griffinforms-modal-label col-md-3">';
        echo '<label>' . esc_html($label) . '</label></div>';
        echo '<div class="griffinforms-modal-field col-md-9">';
        echo wp_kses_post($field);
        echo '</div></div>';
        
    }
    
    public function __construct($lang, $data = '')
    {
        $this->lang = $lang;
        $this->data = $data;
        $this->setAll();
        if (method_exists($this, 'modalJs')) {
            $this->modalJs();
        };
    }
}