#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#---------------------------------------------------------------
package Common::FormObject::List::AlphaPaged;
use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::Assert;
use base 'Common::FormObject::List';

use constant kOtherPage => '0';

sub _getCollection {
    my ( $self, %args ) = @_;

    # !!! JPK - It's important to remember that this method
    # needs to be pagination aware...
    #
    assert( 0, 'override' );
}

sub _init {
    my ( $self, %args ) = @_;

    # All we really need to know is the current page.
    # The rest is essentially canned.
    #
    my $currentPage = $args{currentPage};

    # Remember, '0' is a valid page number (means 'Other')
    #
    $currentPage = 'A' unless defined $currentPage;

    $currentPage = uc($currentPage);

    my $next = $self->_getNext($currentPage);
    my $prev = $self->_getPrev($currentPage);

    $self->{Pagination}{Current}  = $currentPage;
    $self->{Pagination}{Next}     = $next;
    $self->{Pagination}{Previous} = $prev;

    return $self->SUPER::_init(%args);
}

sub _getNext {
    my ( $self, $page ) = @_;

    return undef if 'ALL' eq uc($page);
    return undef if kOtherPage eq $page;
    return kOtherPage if 'Z' eq $page;
    return chr( ord($page) + 1 );
}

sub _getPrev {
    my ( $self, $page ) = @_;

    return undef if 'ALL' eq uc($page);
    return undef if 'A' eq $page;
    return 'Z'   if kOtherPage eq $page;
    return chr( ord($page) - 1 );
}

1;
