package AppUser::Login::SelectForm;

use strict;
use warnings;
use lib '/app/tools/common/lib';
use Common::Consts;

use lib '/app/tools/appuser/lib';
use AppUser::User::User;

use lib '/app/tools/rps/lib';
use Common::FormObject;
use base 'Common::FormObject';

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

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

    # user is here because they have access to multiple clients,
    # so display a drop down list for them to select from.
    #
    my $email      = $args{email};
    my $userObj    = AppUser::User::User->new( email => $email );
    my $clientList = $userObj->GetClientList();

    foreach my $clientObj ( sort { lc( $a->client_name ) cmp lc( $b->client_name ) } @$clientList ) {

        # a makeshift XMLObject for this client list
        #
        my $vhost = $clientObj->web_alias;
        $vhost = $clientObj->client_name_clean unless $vhost;

        my $href = {
            ClientName => $clientObj->client_name,
            ClientID   => $clientObj->client_id,
            URL        => $vhost,
        };
        push @{ $self->{ClientList}{Client} }, $href;
    }

    $self->{Email} = Common::FormObject::Scalar::EmailAddress->new( value => $args{email} );
    $self->{Password} = Common::FormObject::Scalar::String->new( value => $args{password} );

    return $self;
}

1;

