{% include 'header.twig' %}

{# FontAwesome 6 Fix #}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">

<style>
  /* QR Code Responsive Fix */
  .panel-body img {
      max-width: 300px !important;
      width: 100% !important;
      height: auto !important;
      display: block !important;
      margin: 10px auto !important;
      border-radius: 8px;
  }
  /* Custom Professional Styling */
  .card_v2 {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    background: rgba(20, 24, 33, 0.85);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  }
  .tab_btn_wrap .nav-link.active {
    background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%) !important;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
  }
  .table thead th {
    background-color: rgba(255, 255, 255, 0.03);
    color: #ff4747 !important;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0.5px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.05);
  }
  .table tbody tr td {
    color: #e0e6ed;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    vertical-align: middle;
  }
  .badge-payment-id {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
    font-family: monospace;
  }
  .loading-overlay { position: relative; opacity: 0.6; pointer-events: none; }
</style>

<div class="content">
  <div id="page_info"></div>
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-12">
        <div class="card card_v2 mb-4">
          <div class="card-body py-4">
            <h6 class="text-center text-bold mb-3" style="letter-spacing: 0.5px;">
              How to Deposit Through BKASH, Rocket, Nagad on {{ site["site_name"] }}
            </h6>
            <div class="text-center">
              <a href="https://www.youtube.com/" target="_blank" class="btn btn-primary px-5 py-2" style="font-size:15px; border-radius: 8px; font-weight: 600;">
                <i class="fab fa-youtube mr-2"></i> WATCH VIDEO
              </a>
            </div>
          </div>
        </div> 
        
        {% if PageText %} 
          <div id="block_107" class="mb-4">
            <div class="text-block-with-card">
              <div class="container">
                <div class="component_card_1">
                  <div class="card card_v2">
                    <div class="card-body text-block__description">
                      {{ contentText }}
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        {% endif %} 

        <div class="card card_v2 mb-4">
          <div class="card-body">
            <div id="newOrderTabsWrap">
              <ul class="nav nav-pills tab_btn_wrap mb-3" id="pills-tab" role="tablist">
                <li class="nav-item" role="presentation">
                  <button class="nav-link active" id="pills-order-tab" data-bs-toggle="pill" data-bs-target="#pills-order" type="button" role="tab" aria-controls="pills-order" aria-selected="true">
                    <i class="far fa-credit-card mr-2"></i> Add Fund
                  </button>
                </li>
              </ul>
              
              <div id="fallback-alerts">
                {% if error %}
                  <div class="alert alert-dismissible alert-danger">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                    {{ errorText }}
                  </div>
                {% endif %}
                {% if success %}
                  <div class="alert alert-dismissible alert-success">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                    {{ successText }}
                  </div>
                {% endif %}
              </div>
            </div>

            <div class="pt-2 pb-2">
              <form method="post" id="addfundsForm" action="/addfunds">    
                <div class="form-group mb-3">
                  <label Kharfor="method" class="control-label mb-2" style="font-weight: 500; color: #a0aec0;">{{ lang['addfunds.method'] }}</label>
                  <select class="form-control" id="payment_method" name="payment_type" style="background: #1a202c; color: #fff; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px;">
                    {% for method in site["paymentMethods"] %}
                      <option value="{{ method['id'] }}">{{ method['name'] }}</option>
                    {% endfor %}
                  </select>
                </div>
                <div id="addfunds_fields"></div>
              </form>
              
              <div id="formSubmitResponseMessage" style="display: none;"></div>
              <div id="formSubmitResponseContent" class="mt-3"></div>
            </div>
          </div>
        </div>

        <div class="card card_v2 mb-4">
          <div class="card-body">
            <h5 class="card-title mb-3" style="color: #fff; font-size: 16px;"><i class="fas fa-history mr-2"></i> Recent Payment History</h5>
            <div class="table-bg component_table">
              <div class="table-wr table-responsive">
                <table class="table mb-0">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>Method</th>
                      <th>Amount</th>
                      <th>Date</th>
                    </tr>
                  </thead>
                  <tbody>
                    {% if payments is empty %}
                      <tr>
                        <td colspan="4" class="text-center py-4" style="color: #718096;">No deposit history found.</td>
                      </tr>
                    {% else %}
                      {% for payment in payments %}
                        <tr>
                          <td><span class="badge-payment-id">#{{ payment['id'] }}</span></td>
                          <td><span style="font-weight: 500;">{{ payment['name'] }}</span></td>
                          <td><span class="text-success" style="font-weight: 600;">{{ payment['amount'] }}</span></td>
                          <td style="color: #a0aec0; font-size: 13px;">{{ payment['date'] }}</td>
                        </tr>
                      {% endfor %}
                    {% endif %}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>

        {% if contentText2 %}
          <div class="card card_v2 mt-4 mb-4">  
            <div class="card-body">
              {{ contentText2 }}
            </div>
          </div>
        {% endif %}

      </div>
    </div>
  </div>
</div>

{% include 'footer.twig' %}

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
  var paymentMethods = {{ site["paymentMethodsJSON"] }};
  const addfundsRoute = "/addfunds";

  function addfundsInit() {
    var fields = $("#addfunds_fields");
    var selectedMethod = $("#payment_method").val();
    if(!paymentMethods[selectedMethod]) return;
    
    var instructions = paymentMethods[selectedMethod][0].instructions;
    $.ajax({
      url: addfundsRoute,
      data: "action=getForm&selectedMethod=" + selectedMethod,
      type: "POST",
      success: function (json) {
        if (json.success == true) {
          var methodInstruction = instructions ? '<div class="form-group mb-3"><label class="control-label mb-2" style="color: #a0aec0;">Instructions</label><div class="panel-body p-3 border-solid" style="background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.05); border-radius: 8px; color: #cbd5e0;">' + instructions + '</div></div>' : "";
          fields.html(methodInstruction + json.content);
        }
      }
    });
  }

  $(document).ready(function () {
    addfundsInit();
    $("#payment_method").change(addfundsInit);

    // Toggle Script
    $('.navbar-toggler').on('click', function() {
        $('#navbarSupportedContent').collapse('toggle');
    });

    $("#addfundsForm").submit(function (e) {
      e.preventDefault();
      Swal.fire({ title: 'Verifying Transaction...', allowOutsideClick: false, didOpen: () => Swal.showLoading() });
      $.post(addfundsRoute, $(this).serialize(), function(json) {
         if (json.success) {
            Swal.fire('Success', json.message, 'success').then(() => location.reload());
         } else {
            Swal.fire('Error', json.message, 'error');
         }
      });
    });
  });
</script>