#!/usr/bin/perl

use Curses;
use Curses::Widgets qw( :all );
use Curses::Forms;


my ($mwh, $dwh);
my ($text, $content);
my (@date_disp);
my (@buttons, $sel, %list);

$mwh = new Curses;
noecho();
halfdelay(5);
$mwh->keypad(1);

$mwh->erase();

$mwh->box(ACS_VLINE, ACS_HLINE);
$mwh->attrset(0);

$mwh->standout();
$mwh->addstr(0, 1, "RCMS Demo v0.0.1");
$mwh->standend();
select_colour($mwh, 'blue');



$form = Curses::Forms->new(
{
'Y' => 0,
'X' => 0,
'LINES' => $LINES,
'COLS' => $COLS
});

$form->set_defaults( 
	BORDER => 1,
	DEF_ACTV => 'green',
	DEF_INACTV => 'green',
	DEF_FUNC => \&clock,
	BORDER_COLOUR => 'green',
	TITLE=>'RCMS ROReport Demo v0.1'
	);

$listformat = " @<<<<  @>>>>>> @<<<<<<<<<<<<<<<<<<<<<<<<<  @>>>> @|| @<<<< £@<<<<<  £@>>>>>";

%list = ();

$str= formline $listformat,(1800,"00.001","Ben Jones",20,"W",12,0.60,-20.20);
$list{1}=$^A;
$^A="";

$str= formline $listformat,(1830,"00.003","John Keeney",20,"LM",12,0.80,20.0);
$list{2}=$^A;
$^A="";

%ROs=(
'1' => 'Mark Dennehy',
'2' => 'Jason Sibley',
'3' => 'David Gallagher (TRO)'
);

$Ammo="Discipline : Free Rifle

            W     LM
Brought   [200] [200]
Used      [ 20] [ 20]
Remaining [480] [480]";

$Money=
"Float at Start  : £10.00
Cashbox Total   : £11.40
Float Left      : £10.00
Net Income      :  £1.40";

$notes = "This is a demo. Nothing should work right.
And the data is not even in the database, 
let alone being recovered from it.";

$ActiveRO = "Mark Dennehy 00.002";

$form->add( 
	{ 
	'type' => 'txt_field',
	'name' => 'active_ro',
	'ypos' => 1,
	'xpos' => ($COLS /3)*2,
	'regex' => "\tqQ",
	'lines' => 1,
	'cols' => (($COLS - 2)/3)-2,
	'title' => 'Active Range Officer',
	'content' => $ActiveRO,
	'edit' => 0 
	},
	{ 
	'type' => 'list_box',
	'name' => 'ROs_On_Duty',
	'ypos' => 4,
	'xpos' => ($COLS /3)*2,
	'regex' => "\tqQ",
	'lines' => 6,
	'cols' => (($COLS - 2)/3)-2,
	'title' => 'Range Officers on Duty',
	'list' => \%ROs,
	'edit' => 0 
	},
	{ 
	'type' => 'txt_field',
	'name' => 'Ammo',
	'ypos' => 1,
	'xpos' => 1+($COLS - 2)/3,
	'regex' => "\tqQ",
	'lines' => 9,
	'cols' => (($COLS - 2)/3)-2,
	'title' => 'Ammo',
	'content' => $Ammo,
	'edit' => 0 
	},
	{ 
	'type' => 'txt_field',
	'name' => 'Money',
	'ypos' => 1,
	'xpos' => 1,
	'regex' => "\tqQ",
	'lines' => 9,
	'cols' => (($COLS - 2)/3)-2,
	'title' => 'Money',
	'content' => $Money,
	'edit' => 0 
	},
	{ 
	'type' => 'list_box',
	'name' => 'details',
	'ypos' => 12,
	'xpos' => 1,
	'lines' => $LINES - 22,
	'cols' => $COLS - 4,
	'list'	=> \%list,
	'title' => 'Details'
	},
	{ 
	'type' => 'txt_field',
	'name' => 'notes',
	'ypos' => $LINES - 8,
	'xpos' => 1,
	'regex' => "\tqQ",
	'lines' => 5,
	'cols' => $COLS - 4,
	'title' => 'Notes',
	'content' => $notes,
	'edit' => 1 
	}
	);

$form->bind(
["details","[qQ]","Quit_form"],
["notes","[qQ]","Quit_form"],
);

$form->tab_order(qw( details notes ));

clock;


$form->activate(1);

clock;

msg_box(
'title' => "RCMS Demo v0.0.1",
'message' => $notes,
'border' => 'red'
);

clock;
$form->activate;


#######################################################################

sub clock {
	# Update the clock in the upper right hand corner of the screen
	#
	# Usage:  clock()

	$mwh->standout();
	$mwh->addstr(0, ($COLS - 26), scalar (localtime));
	$mwh->standend();
	$mwh->refresh();
	#Curses::Forms->refresh_forms();
}
