### ----------------------------------------------------
### -- Vikna
### -- Licenses: Artistic-2.0
### -- Authors: Vadim Belman <vrurg@cpan.org>
### -- File: lib/Vikna/Widget.rakumod
### ----------------------------------------------------
### -- Chunk 2 of 2
(
            Promise.in(10),
            start $.app.panic($cause, :object( self ))
            );
    }
    else {
        nextsame;
    }
    exit 1 if $bail-out;
}

method print(|) { !!! }

proto method get-child( ::?CLASS:D: | ) {*}
multi method get-child( Str:D $name --> Vikna::Widget ) {
    %!child-by-name{$name}:exists ?? %!child-by-id{%!child-by-name{$name}}<child> !! Nil
}
multi method get-child( Int:D $id --> Vikna::Widget ) {
    %!child-by-id{$id}:exists ?? %!child-by-id{$id}<child> !! Nil
}

proto method AT-KEY( | ) {*}
multi method AT-KEY( ::?CLASS:D: Str:D $wname ) {
    %!child-by-name{$wname} ?? %!child-by-id{%!child-by-name{$wname}}<child> !! Nil
}
multi method AT-KEY( ::?CLASS:D: Int $id ) {
    %!child-by-id{$id}<child>
}
multi method AT-KEY( ::?CLASS:U: | ) {
    Nil
}

proto method EXISTS-KEY( | ) {*}
multi method EXISTS-KEY( ::?CLASS:D: Str:D $wname ) {
    %!child-by-name{$wname}:exists
}
multi method EXISTS-KEY( ::?CLASS:D: Int:D $id ) {
    %!child-by-id{$id}:exists
}
multi method EXISTS-KEY( ::?CLASS:U: | ) {
    False
}

proto method DELETE-KEY( | ) {*}
multi method DELETE-KEY( ::?CLASS:D: Str:D $wname ) {
    self.remove-child: $_ with $.get-child( $wname );
}
multi method DELETE-KEY( ::?CLASS:D: Int:D $id ) {
    self.remove-child: $_ with $.get-child( $id );
}

method Bool {
    self.defined && $!closed.status ~~ Planned
}

method Str {
    $.name
}

method gist {
    $.id ~ ":" ~ $.name
}


