use strict;
use warnings;

package BarnOwl::Style::BTang;
use base qw(BarnOwl::Style::Default);

sub description {"Custom style for btang.";}

#class / instance / sender / date / auth / darkmatter or whatnot / (zsig)

# Hack for working with older BarnOwl.
sub humanize {
    if ( *BarnOwl::Style::Default::humanize{CODE} ) {
        return BarnOwl::Style::Default::humanize(@_);
    } else {
        shift;
        return shift;
    }
}

sub chat_header {
    my $self = shift;
    my $m = shift;
    my $header;
    if ( $m->is_personal ) {
        my $personal_context = $m->personal_context;
        $personal_context = ' [' . $self->humanize($personal_context, 1) . ']' if $personal_context;

        if ( $m->direction eq "out" ) {
            $header = ucfirst $m->type . $personal_context . " sent to " . $m->pretty_recipient;
        } else {
            $header = ucfirst $m->type . $personal_context . " from " . $m->pretty_sender;
        }
    } else {
        $header = $self->humanize($m->context, 1);
        if(defined $m->subcontext) {
            $header .= ' / ' . $self->humanize($m->subcontext, 1);
        }
        $header .= ' / @b{' . $m->pretty_sender . '}';
    }

    if($m->opcode) {
        $header .= " [" . $self->humanize($m->opcode, 1) . "]";
    }
    $header .= " / " . $self->format_time($m);
    if($m->auth) {
        $header .= " / " . (($m->auth =~ /YES/) ? '+' : '-');
    }
    if($m->hostname) {
        $header .= " / " . $m->hostname;
    }
    $header .= " / " . $self->format_sender($m);
    return $header;
}

BarnOwl::create_style("BTang", "BarnOwl::Style::BTang");

1;
