<?php
session_start();

require('../../includes/database.php');
include("../../log.php");

if (isset($_SESSION['accUsername']) && $_SESSION['accPassword'] != "") {
} else {
  header("Location:../../login/");
}
$accUsername = $_SESSION['accUsername'];

$accUsername = $_SESSION['accUsername'];
$accPassword = $_SESSION['accPassword'];

$query = "SELECT * FROM accounts	
			WHERE username = '$accUsername'
			&&   password = '$accPassword'";

$result = mysqli_query($con, $query) or die(mysqli_connect_error());
$rows = mysqli_num_rows($result);
if ($rows == 1) {
  while ($data = mysqli_fetch_assoc($result)) {

    extract($data);


    include('../components/head.php');
?>

    <body x-data class="is-header-blur is-sidebar-open" x-bind="$store.global.documentBody">
      <!-- App preloader-->
      <?php
      include("../components/preloader.php");
      include("../components/sidebar.php");
      include("../components/sidebar-body.php");
      include("../components/nav.php");
      include("../components/mobile-search.php");
      include("../components/right-sidebar.php");
      ?>

      <!-- Main Content Wrapper -->
      <main class="main-content w-full px-[var(--margin-x)] pb-8">
        <div class="mt-4 grid grid-cols-12 gap-4 sm:mt-5 sm:gap-5 lg:mt-6 lg:gap-6">

          <?php
          include("../components/user-pan.php");
          include("../components/transactions-pane.php");
          ?>

          <div class="card col-span-12 px-4 pb-5 sm:px-5 lg:col-span-6">
            <div class="flex items-center justify-between py-3">
              <h2 class="font-medium tracking-wide text-slate-700 dark:text-navy-100">
                Send Money
              </h2>
              <div x-data="usePopper({placement:'bottom-end',offset:4})" @click.outside="isShowPopper && (isShowPopper = false)" class="inline-flex">
                <button x-ref="popperRef" @click="isShowPopper = !isShowPopper" class="btn -mr-1 h-8 w-8 rounded-full p-0 hover:bg-slate-300/20 focus:bg-slate-300/20 active:bg-slate-300/25 dark:hover:bg-navy-300/20 dark:focus:bg-navy-300/20 dark:active:bg-navy-300/25">
                  <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z" />
                  </svg>
                </button>

                <div x-ref="popperRoot" class="popper-root" :class="isShowPopper && 'show'">
                  <div class="popper-box rounded-md border border-slate-150 bg-white py-1.5 font-inter dark:border-navy-500 dark:bg-navy-700">
                    <ul>
                      <li>
                        <a href="../send-money/" class="flex h-8 items-center px-3 pr-8 font-medium tracking-wide outline-none transition-all hover:bg-slate-100 hover:text-slate-800 focus:bg-slate-100 focus:text-slate-800 dark:hover:bg-navy-600 dark:hover:text-navy-100 dark:focus:bg-navy-600 dark:focus:text-navy-100"><?php echo $siteNameShort ?> Account</a>
                      </li>
                      <li>
                        <a href="../send-money/" class="flex h-8 items-center px-3 pr-8 font-medium tracking-wide outline-none transition-all hover:bg-slate-100 hover:text-slate-800 focus:bg-slate-100 focus:text-slate-800 dark:hover:bg-navy-600 dark:hover:text-navy-100 dark:focus:bg-navy-600 dark:focus:text-navy-100">Other Local Banks</a>
                      </li>
                      <li>
                        <a href="../send-money/" class="flex h-8 items-center px-3 pr-8 font-medium tracking-wide outline-none transition-all hover:bg-slate-100 hover:text-slate-800 focus:bg-slate-100 focus:text-slate-800 dark:hover:bg-navy-600 dark:hover:text-navy-100 dark:focus:bg-navy-600 dark:focus:text-navy-100">International Wire TF</a>
                      </li>
                    </ul>
                  </div>
                </div>
              </div>
            </div>
            <div class="flex space-x-2">
              <a href="../send-money/" class="btn space-x-6 bg-info font-medium text-white hover:bg-info-focus hover:shadow-lg hover:shadow-info/50 focus:bg-info-focus focus:shadow-lg focus:shadow-info/50 active:bg-info-focus/90">
                <span>Other Local Banks</span>
              </a>
              <a href="../send-money/" class="btn space-x-6 border border-warning/30 bg-warning/10 font-medium text-warning hover:bg-warning/20 focus:bg-warning/20 active:bg-warning/25">
                <span>International Wire TF</span>
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6" />
                </svg>
              </a>
            </div>
            <div class="mt-2 flex items-center justify-between">
              <p class="text-xs+">View All Beneficiary
                <a href="../beneficiaries/" class="btn -mr-1 h-8 w-8 rounded-full p-0 hover:bg-slate-300/20 focus:bg-slate-300/20 active:bg-slate-300/25 dark:hover:bg-navy-300/20 dark:focus:bg-navy-300/20 dark:active:bg-navy-300/25">
                  <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M14 5l7 7m0 0l-7 7m7-7H3" />
                  </svg>
                </a>
              </p>
            </div>
            <form action="../../bank-manager.php?action=send-money" onsubmit="return valid()" method="POST">
              <div class="mt-2 space-y-4">
                <label class="block">
                  <span class="text-xs+">Pay to</span>
                  <input x-input-mask="{creditCard: true}" class="form-input mt-1.5 h-9 w-full rounded-lg border border-slate-300 bg-transparent px-3 py-2 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent" placeholder="**** **** **** ****" type="text" name="receiver" onblur="userAvailabilityMb()" id="account_numberMb" />
                </label>
                <span class="text-center" id="account_name" style="font-size:12px;"></span>
                <div class="grid w-full grid-cols-2 gap-2">
                  <div x-data="{config:{numeral: true,numeralThousandsGroupStyle: 'thousand'}}">
                    <span class="text-xs+">Amount</span>
                    <div class="mt-1.5 flex h-9 -space-x-px">
                      <select class="form-select rounded-l-lg border border-slate-300 bg-white px-3 py-2 pr-9 hover:z-10 hover:border-slate-400 focus:z-10 focus:border-primary dark:border-navy-450 dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent">
                        <option class="hover:bg-primary/20" x-tooltip.placement.right="'<?php echo $currency ?>'"><?php echo $currency ?></option>
                      </select>
                      <input id="send-amount-mb" x-input-mask="config" class="form-input w-full rounded-r-lg border border-slate-300 bg-transparent px-3 py-2 placeholder:text-slate-400/70 hover:z-10 hover:border-slate-400 focus:z-10 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent" placeholder="Amount" type="text" name="amount" inputmode="numeric" onblur="amountInputMb()" />
                    </div>
                  </div>
                  <label class="block">
                    <span>4-Digit Pin</span>
                    <input required class="form-input mt-1.5 w-full rounded-lg border border-slate-300 bg-transparent px-3 py-2 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent" placeholder="XXXX" type="password" pattern="[0-9]{4}" inputmode="numeric" maxlength="4" name="pin" />
                  </label>
                </div>
              </div>
              <input type="hidden" name="transfer_type" value="MYBANK">
              <input type="hidden" name="commission" value="12">
              <?php include("../components/userSendInfo.php") ?>
              <div class="mt-5 flex justify-between text-slate-400 dark:text-navy-300">
                <p class="text-xs+">Commission:</p>
                <p><?php echo $currency ?> 12.00</p>
              </div>
              <div class="mt-2 flex justify-between">
                <p>Total:</p>
                <span style="display:flex" class="font-medium text-slate-700 dark:text-navy-100">
                  <span class="pr-1"><?php echo $currency ?> </span><span id="amountToPayMb"></span>
                </span>
              </div>
              <button id="account_namebutton" type="submit" class="btn mt-5 h-10 w-full bg-primary font-medium text-white hover:bg-primary-focus focus:bg-primary-focus active:bg-primary-focus/90 dark:bg-accent dark:hover:bg-accent-focus dark:focus:bg-accent-focus dark:active:bg-accent/90">
                Send Money
              </button>
            </form>
          </div>
        </div>
      </main>
      </div>

      <script>
        jQuery(document).ready(function() {
          Main.init();
          Login.init();
        });
      </script>

      <script>
        function amountInputMb() {
          document.getElementById("amountToPayMb").style.display = "none";
          var payamountmb = $("#send-amount-mb").val();
          payamountmb = Number(payamountmb.replaceAll(",", "")) + 12;
          if (1 == 1) {
            document.getElementById("amountToPayMb").style.display = "block";
            $("#amountToPayMb").html(`${new Intl.NumberFormat().format(payamountmb)}`);
          }
        }
      </script>

      <script>
        function userAvailabilityMb() {
          jQuery.ajax({
            url: "amount-checker.php",
            data: 'receiver=' + $("#account_numberMb").val(),
            type: "POST",
            success: function(data) {
              $("#account_name").html(data);
              $("#account_namebutton").html("Send to " + " " + "<i class='fa fa-send'></i>" + data);
            },
            error: function() {
              $("#account_namebutton").html("Send Money");
            }
          });
        }
      </script>

      <div id="trans-invoice"></div>
      <div id="x-teleport-target"></div>
      <script>
        window.addEventListener("DOMContentLoaded", () => Alpine.start());
      </script>
    </body>

    </html>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<?php
  }
}
?>