<?php 
$rowcount = $this->input->post('payment_row_count') +1;
$base_currency = get_base_currency();
$currency_symbol = !empty($base_currency->symbol) ? $base_currency->symbol : '$';
// Check if walk-in customer (customer_id = 1)
$customer_id = isset($_POST['customer_id']) ? $_POST['customer_id'] : (isset($_GET['customer_id']) ? $_GET['customer_id'] : '');
$is_walk_in = ($customer_id == 1 || $customer_id == '1');
?>
<div class="payment-card payments_div" id="payment_row_<?= $rowcount; ?>">
  <span class="remove-payment" onclick="remove_payment_row(<?= $rowcount; ?>)" title="Remove"><i class="fa fa-times-circle"></i></span>
  <!-- Row 1: Amount and Currency -->
  <div class="row" style="margin-bottom: 8px;">
    <div class="col-sm-6 col-xs-12">
      <div class="form-group">
        <label><?= $this->lang->line('amount') ?: 'Amount'; ?> (<?= $currency_symbol ?>) <span class="text-danger">*</span></label>
        <input type="text" class="form-control text-right payment amount-input only_currency" id="amount_<?= $rowcount;?>" name="amount_<?= $rowcount;?>" onkeyup="calculate_payments()" onchange="calculate_payments()" placeholder="0.00">
        <span id="amount_<?= $rowcount;?>_msg" style="display:none" class="text-danger small"></span>
      </div>
    </div>
    <div class="col-sm-6 col-xs-12">
      <div class="form-group">
        <label><?= $this->lang->line('currency') ?: 'Currency'; ?></label>
        <select class="form-control" id='payment_currency_<?= $rowcount;?>' name="payment_currency_<?= $rowcount;?>" onchange="update_payment_currency(<?= $rowcount;?>)">
          <?php
            echo "<option value='".$base_currency->id."' selected>".$base_currency->currency_code."</option>";
          ?>
        </select>
      </div>
    </div>
  </div>
  <!-- Row 2: Payment Type and Account -->
  <div class="row" style="margin-bottom: 8px;">
    <div class="col-sm-6 col-xs-12">
      <div class="form-group">
        <label><?= $this->lang->line('payment_type') ?: 'Payment Type'; ?></label>
        <select class="form-control" id='payment_type_<?= $rowcount;?>' name="payment_type_<?= $rowcount;?>">
          <?php
            $q1 = $this->db->query("select * from db_paymenttypes where status=1 and store_id=".get_current_store_id());
            if($q1->num_rows() > 0){
              foreach($q1->result() as $res1){
                // Hide Credit Sale/Credit for walk-in customers
                if($is_walk_in && (strtolower($res1->payment_type) == 'credit' || strtolower($res1->payment_type) == 'credit sale')){
                  continue;
                }
                $sel = ($is_walk_in && strtolower($res1->payment_type) === 'cash') ? ' selected' : '';
                echo "<option value='".$res1->payment_type."'".$sel.">".$res1->payment_type ."</option>";
              }
            }
          ?>
        </select>
      </div>
    </div>
    <div class="col-sm-6 col-xs-12">
      <div class="form-group">
        <label><?= $this->lang->line('account') ?: 'Account'; ?></label>
        <select class="form-control" id='account_id_<?= $rowcount;?>' name="account_id_<?= $rowcount;?>">
          <option value="">-- Select --</option>
          <?= get_accounts_select_list(); ?>
        </select>
      </div>
    </div>
  </div>
  <!-- Row 3: Payment Note (Full Width) -->
  <div class="row" style="margin-bottom: 0;">
    <div class="col-sm-12 col-xs-12">
      <div class="form-group">
        <label><?= $this->lang->line('payment_note') ?: 'Payment Note'; ?></label>
        <textarea class="form-control" id="payment_note_<?= $rowcount;?>" name="payment_note_<?= $rowcount;?>" rows="2" placeholder="Optional note..."></textarea>
      </div>
    </div>
  </div>
</div>
