#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package Support::DTMV::Command::ClientCIStatus;
use strict;
use warnings;

use lib '/app/tools/support/lib';
use base 'Support::Command::Submit';

use lib '/app/tools/bookpub/lib';
use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;
use Support::DTMV::ClientCIStatusList;
use BookPub::Catalog::Import::Process::Fetcher::Factory;
use Common::Client;
use Common::RSApp;

sub cmd  { return 'ci_c'; }
sub area { return 'dtmv'; }

use constant kTemplate => "/app/tools/support/templates/dtmv/client_import_status.xsl";

sub execute {
    my ($self) = @_;

    my $response = $self->SUPER::execute();
    return $response if $response;

    my $clientID = $self->getParam('client');
    my $page     = $self->getParam('page');
    $page = 1 unless $page;

    # Present a list of valid clients for the selection menu.
    #
    my @validIDs = BookPub::Catalog::Import::Process::Fetcher::Factory::ValidClientIDs();
    foreach my $id (@validIDs) {
        my $client = Common::Client->new( clientID => $id );
        push @{ $self->{xml}{ValidClientList}{Client} }, $client;
    }

    if ($clientID) {
        my $tempContext = Common::RSApp->new_temporary( clientID => $clientID );
        $self->{xml}{SelectedClient} = Common::Client::Current();
        $self->{xml}{StatusList} = Support::DTMV::ClientCIStatusList->new( currentPage => $page );
    }

    $response = RSApache::Response::XSLT->new( $self->{xml}, kTemplate );

    return $response;
}

1;
