<?php

namespace GriffinForms\Admin\Html\FormControls\Form;

class ProgressBar extends \GriffinForms\Admin\Html\FormControls\Form\Format
{
    public function html()
    {
        $toggle = isset($this->value['toggle']) ? (bool) $this->value['toggle'] : false;
        $style = isset($this->value['style']) ? (string) $this->value['style'] : 'stepper';
        $show_page_headings = !isset($this->value['show_page_headings']) || (bool) $this->value['show_page_headings'];

        echo '<div class="row">';
        echo '<div class="col-md-12 mb-3" id="griffinforms-progressbar-toggle-wrap">';
        $this->toggleProgressBar($toggle);
        echo '</div>';
        echo '<div class="griffinforms-hidden-option col-md-12 mb-3" id="griffinforms-progressbarstyle-wrap">';
        $this->progressBarStyle($style);
        echo '</div>';
        echo '<div class="griffinforms-hidden-option col-md-12 mb-3" id="griffinforms-progressbarshowpageheadings-wrap">';
        $this->showPageHeadings($show_page_headings);
        echo '</div>';
        echo '</div>';
    }

    protected function toggleProgressBar(bool $value)
    {
        $data = $this->getControlData(array('label' => __('Enable progress bar', 'griffinforms-form-builder')));
        $field = new \GriffinForms\Admin\Html\FormControls\ToggleCheckbox('progress_bar_toggle', $value, $data);
        $field->html();
    }

    protected function progressBarStyle(string $value)
    {
        $field = new \GriffinForms\Admin\Html\FormControls\SelectField('progress_bar_style', $value, $this->getControlData());
        $field->selectOptions(array('stepper' => 'Stepper', 'tabs' => 'Tabs'));
        echo '<div class="mb-2">' . esc_html__('Style', 'griffinforms-form-builder') . '</div>';
        $field->html();
    }

    protected function showPageHeadings(bool $value)
    {
        $data = $this->getControlData(array('label' => __('Use page headings as step labels', 'griffinforms-form-builder')));
        $field = new \GriffinForms\Admin\Html\FormControls\ToggleCheckbox('progress_bar_show_page_headings', $value, $data);
        $field->html();
        echo '<p class="mt-1 text-secondary small">' . esc_html__('When disabled, steps without a custom Step Name will show "Step 1", "Step 2", etc.', 'griffinforms-form-builder') . '</p>';
    }
}
