<?php

namespace GriffinForms\Frontend\Views;

final class GriffinFormsForm extends \GriffinForms\Frontend\Views\Format
{
    public function html()
    {
        $sql = \GriffinForms\Frontend\Sql\Form::getInstance();

        if ($sql->itemExists('form', $this->atts['id'])) {
            $form = new \GriffinForms\Frontend\Html\Forms\Form($this->atts['id']);
            return $form->html();
        } else {
            return $this->formDoesNotExists();
        }
    }

    private function formDoesNotExists()
    {
        $html = '<div class="alert alert-danger border-0 small" role="alert">';
        $html .= esc_html(__('Sorry, this form no longer exists.', 'griffinforms-form-builder'));
        $html .= '</div>';
        return $html;
    }
}