<?php

use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;

class GeneratorController {

    //The folder to be created
    private $name_path = '';
    //The tables to be created
    private $tables = Array();

    function menu() {

        $default_behavior = function (CliMenu $clm) {
            
        };

        $module_name = function(CliMenu $clm) {

            $result = $clm->askText()
                    ->setPlaceholderText('Enter something here')
                    ->ask();

            $this->name_path = $result->fetch();
            $clm->getSelectedItem()->showItemExtra();
        };

        $show_info = function(CliMenu $clm) {
            $clm->flash('Module name and path \n' . $this->name_path)->display();
        };

        /* $menu = (new CliMenuBuilder)
          ->setTitle(Lang::get_string('main_title', 'generator'))
          ->addItem(Lang::get_string('name_definition', 'generator'), $module_name)
          ->addItem(Lang::get_string('show_info', 'generator'), $show_info)
          ->setItemExtra('[COMPLETE!]')
          ->addLineBreak('-')
          ->setBorder(1, 2, 'yellow')
          ->setPadding(2, 4)
          //->setMarginAuto()
          ->build();

          $menu->open(); */
        /* $menu = (new CliMenuBuilder)
          ->setTitle('CLI Menu')
          ->addItem('First Item', $default_behavior)
          ->addItem('Second Item', $default_behavior)
          ->addLineBreak('-')
          ->addSubMenu('Options', function (CliMenuBuilder $b) {
          $b->setTitle('CLI Menu > Options')
          ->addItem('First option', function (CliMenu $menu) {
          echo sprintf('Executing option: %s', $menu->getSelectedItem()->getText());
          })
          ->addLineBreak('-');
          })
          ->setWidth(70)
          ->setBackgroundColour('yellow')
          ->build();
          $menu->open(); */
        $callable = function (CliMenu $menu) {
            echo "I'm just a boring selectable item";
        };

        $menu = (new CliMenuBuilder)
                ->addItem('Normal Item', function(){})
                ->addSubMenu('Super Sub Menu', function (CliMenuBuilder $b) {
                    $b->setTitle('Behold the awesomeness')
                    ->addItem('asdasdasdas', function(){});
                })
                ->build();
        $menu->open();
    }

}
