use Tk;
# use strict;

use CardPlay::Card;
use CardPlay::CardPile;
use CardPlay::CardBoard;

my $w = MainWindow->new();

$w->title('Card Demonstration');
$w->iconname('Card');
# my @ARG = $w;

my $w_msg = $w->Label(-font => '-Adobe-Times-Medium-R-Normal-*-180-*-*-*-*-*-*', -wraplength => '4i',
             -justify => 'left', -text => 'CardPile Demonstratoin');
my $c = $w->Canvas(-relief => 'raised');
my $w_frame = $w->Frame;
my $w_ok = $w_frame->Button(-text => 'Quit', -width => 8, -command => ['destroy', $w]);
my $w_undo = $w_frame->Button(-text => 'Undo', -width => 8, -command => sub { $main::board->undo() ;});
my $w_redo = $w_frame->Button(-text => 'Redo', -width => 8, -command => sub { $main::board->redo() ;});
$w_msg->pack(-side => 'top', -fill => 'x');
$c->pack(-side => 'top', -fill => 'both',-expand=>'t');
$w_frame->pack(-side => 'bottom', -pady => '5');
$w_ok->pack(-side => 'left', -padx => '5');
$w_undo->pack(-side => 'left', -padx => '5');
$w_redo->pack(-side => 'left', -padx => '5');

$w->update();
# Card->init(-main=>$w,-large=>1);
CardPlay::Card->init(-main=>$w);
print STDOUT "card initialzation done\n";

$board = CardPlay::CardBoard->new();

$x = 20;
$y = 20;
for($i=0;$i<4;$i++) {
    $cp = CardPlay::CardPile->new(-canvas=>$c,-base=>1,-board=>$board);
    $cp->display('-x'=>$x,'-y'=>$y,-mergeable=>1);
    $x += $CardPlay::Card::cx+5; 
}

$x = 20;
$y = 120;
foreach $suit ( 's','h','c','d') {
    $card = [];
    for($i=1;$i<14;$i++) {
    $card->[$i-1]=CardPlay::Card->new(
        -canvas=>$c,-board=>$board,-suit=>$suit,-number=>$i);
    }
    $cp = CardPlay::CardPile->new(
    -canvas=>$c,-contents=>$card,-auto_open=>1,-board=>$board);
    $cp->display('-x'=>$x,'-y'=>$y, -splitable=>1,-base=>1);
    $x += $CardPlay::Card::cx+5; 
}
print STDOUT "cardpile initialzation done\n";
$board->log_commit(-1);
$w->update();

$w->MainLoop();

1;

# end