<?php

namespace GriffinForms\Admin\App\Html\Containers;

final class TitleBar extends \GriffinForms\Admin\App\Html\Containers\Format
{

    protected function setWidgets()
    {
        $this->widgets = array(
            'wp_svg_icon',
            'structure_panel_btn',
            'options_menu',
            'form_themes_btn',
            'preview_btn',
            'command_palette',
        );
    }

    public function getHtml()
    {
        echo '<div id="' . esc_attr($this->getHtmlId()) . '" class="d-flex justify-content-between align-items-center bg-white border-bottom">';
        $this->getLeftHtml();
        $this->getCenterHtml();
        $this->getRightHtml();
        echo '</div>';
    }

    private function getLeftHtml() {
        echo '<div id="griffinforms-titlebar-left" class="d-flex align-items-center">';
        $this->widgets['wp_svg_icon']->getHtml();
        echo '<div id="griffinforms-titlebar-left-actions" class="d-flex align-items-center" data-gf-context="form-layout">';
        $this->widgets['structure_panel_btn']->getHtml();
        echo '</div>';
        echo '</div>';
    }

    private function getCenterHtml() {
        echo '<div id="griffinforms-titlebar-center" class="d-flex align-items-center justify-content-center flex-grow-1 text-center">';
        $this->widgets['command_palette']->getHtml();
        echo '</div>';
    }

    private function getRightHtml() {
        echo '<div id="griffinforms-titlebar-right" class="d-flex align-items-center justify-content-end gap-2 me-2">';
        $this->widgets['form_themes_btn']->getHtml();
        $this->widgets['preview_btn']->getHtml();
        $this->widgets['options_menu']->getHtml();
        echo '</div>';
    }

    public function titlebarJs()
    {
    }

    public function getJs()
    {
        $this->titlebarJs();
        $this->widgets['structure_panel_btn']->getJs();
        $this->widgets['preview_btn']->getJs();
        $this->widgets['form_themes_btn']->getJs();
        $this->widgets['options_menu']->getJs();
        $this->widgets['command_palette']->getJs();
    }
}
