// jamsh 
var ui = UI.UI({
    pages   : 1,
    styles  : {},
    terminal: '',
    title   : 'Test APP'
});

function exit2() {
  process.exit();
}

print(ui)
ui.init();


ui.pages[1]={
  quit    : ui.button({left:1,top:1,content:'QUIT', action:exit2}),
  label1  : ui.label({right:1,top:2, content:'Chat Demo'}),
  chat1   : ui.chat({left:1, top:6, width:40, height:14,  prompt:'> ', label:'My Chat',
                     bot:{color:'red'}, user:{align:'right',color:'blue'}, fg:{color:'black'}}),
  log1    : ui.log({right:1, top:6, width:34, height:14,  multiline:true, wrap:true, scrollable:true, label:'Log'}),
}
Log = function () {
  var line = Array.prototype.slice.call(arguments).map(function (arg) { 
    return inspect(arg) }).join(' ');
  ui.pages[1].log1.add(line);
  ui.pages[1].log1.scrollBottom();
}
ui.pages[1].chat1.on('eval',function (user) {
  Log(user);
  // ui.pages[1].chat1.print(user,{align:'right',color:'red'});
});
ui.pages[1].chat1.on('clicked',function (ev) {
   // Log(ev);
});
ui.pages[1].chat1.on('keypress',function (ch,key) {
  // Log(key);
});
ui.pages[1].chat1.message('Hello! I am sam.');
ui.pages[1].chat1.message('You can ask a lot of stuff.');
ui.pages[1].chat1.message('But firstly I have a question.');
ui.pages[1].chat1.message('You can answer it directly here.');
ui.pages[1].chat1.message('After a question form was andwered or cancles, you can ask questions, too!');

later(1000,function () {
  if (1) ui.pages[1].chat1.ask('Are you morbid?',{
    choices:['yes','no','maybe','sometimes','like my neighbour'],
    timeout:5000,
    layout:'vertical',
    // mutable:true
  },function (result) {
    Log(result);
    if (result && result.length) return 'Thank you!';
  });
  if (0) ui.pages[1].chat1.ask('How old are you?',{
    range:[1,100],
    timeout:500000,
    // mutable:true
  },function (result) {
    Log(result);
    if (result) return 'Thank you again!';
  });
  if (0) ui.pages[1].chat1.ask('Tell me your nightmare!',{
    text:[1,100],
    timeout:5000,
    // mutable:true
  },function (result) {
    Log(result);
    if (result && result.length) return 'Thank you!';
  });
});
ui.screen.key(['escape', 'q', 'C-c'], exit2);

ui.start();