<?php $this->load->view('header');?>
		
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            &nbsp;
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo base_url();?>"><?php echo $this->lang->line('hf_home');?></a></li>
              <li class="breadcrumb-item"><?php echo $this->lang->line('hf_package_manager');?></li>
			  <li class="breadcrumb-item active"><?php echo $this->lang->line('hf_buy_package');?></li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

	<!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="card card-default">
          <div class="card-header">
            <h3 class="card-title"><?php echo $this->lang->line('hf_buy_package');?></h3>

            <div class="card-tools">
              <b class="text-success"><?php echo $this->lang->line('buy_current_package');?>:</b> 
			  <span><?php echo $this->lang->line(get_package($package_type));?></span> &nbsp;|&nbsp; 
			  <b class="text-success"><?php echo $this->lang->line('wallet_1');?>:</b> 
			  <span><?php echo (isset($v_unit) ? $v_unit : '');?></span> &nbsp;|&nbsp; 
			  <b class="text-success"><?php echo $this->lang->line('wallet_4');?>:</b> 
			  <span><?php echo (isset($v_unit4) ? $v_unit4 : '');?></span>
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
			<?php
				$package_arr = array();
				$num = 0;
				$lowest_package = 0;
				$dropdown_list = '';
				if($package->num_rows() > 0) {
					foreach($package->result() as $row) {
						$package_arr[$row->package_id] = $row->package_price;
						
						if($row->package_id > $package_type) {
							if($num == 0) {
								$lowest_package = $row->package_price;
								$num++;
							}
						
							$dropdown_list .= '<option value="' . $row->package_id . '" data-value="' . $row->package_price . '">' . $row->package_name . '</option>';
						}
					}
				}
								
				$diff_amount = 0;
				if(isset($package_arr[$package_type])) {
					$diff_amount = ($lowest_package - $package_arr[$package_type]);
					if($diff_amount < 0) {
						$diff_amount = 0;
					}
				}
				else {
					$diff_amount = $lowest_package;
				}
				
				if($diff_amount > 0) {
			?>
			<form class="form-horizontal" id="buy-form">
				<div class="form-group row">
					<label for="package_type" class="col-sm-2 col-form-label"><?php echo $this->lang->line('buy_package');?></label>
					<div class="col-sm-3">
						<select class="form-control" id="package_type" name="package_type">
						    <?php
								if( ! empty($dropdown_list)) {
									echo $dropdown_list;
								}
								else {
									echo '<option value="0">' . $this->lang->line('buy_please_select') . '</option>';
								}
							?>
						</select>
					</div>
				</div>
				<div class="form-group row">
					<label for="diff_amount" class="col-sm-2 col-form-label"><?php echo $this->lang->line('buy_need_to_topup');?></label>
					<div class="col-sm-3">
						<label id="diff_amount" class="custom-label"><?php echo $diff_amount;?></label>
					</div>
				</div>
				<div class="form-group row">
					<label for="transaction_amount" class="col-sm-2 col-form-label"><?php echo $this->lang->line('wallet_1');?></label>
					<div class="col-sm-3">
					  <input type="text" class="form-control" id="transaction_amount" name="transaction_amount" placeholder="<?php echo $this->lang->line('buy_fill_in_amount_to_use_message_1');?>">
					</div>
				</div>
				<div class="form-group row">
					<label for="transaction_amount_4" class="col-sm-2 col-form-label"><?php echo $this->lang->line('wallet_4');?></label>
					<div class="col-sm-3">
					  <input type="text" class="form-control" id="transaction_amount_4" name="transaction_amount_4" placeholder="<?php echo $this->lang->line('buy_fill_in_amount_to_use_message_2');?>">
					</div>
				</div>
				<div class="form-group row">
					<label for="security_password" class="col-sm-2 col-form-label"><?php echo $this->lang->line('buy_security_password');?></label>
					<div class="col-sm-3">
					  <input type="password" class="form-control" id="security_password" name="security_password" placeholder="<?php echo $this->lang->line('buy_security_password_fill_in_message');?>">
					</div>
				</div>
				<div class="form-group row">
					<div class="offset-sm-2 col-sm-10">
					  <input type="hidden" id="current_package" name="current_package" value="<?php echo (isset($package_arr[$package_type]) ? $package_arr[$package_type] : 0);?>" />
					  <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>" />
					  <button onclick="buy_submit()" type="button" class="btn btn-primary"><?php echo $this->lang->line('buy_buy_now');?></button>
					</div>
				</div>
			</form>
			<?} else {?>
				<?php echo $this->lang->line('buy_highest_package_now');?>
			<?}?>
          </div>
          <!-- /.card-body -->
        </div>
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
		
<?php $this->load->view('footer');?>		