<?php
require "connect.php";
if (isset($_POST['withdraw'])) {
    $amount = $_POST['amount'];
    $method = $_POST['method'];
    $coin = $_POST['coin'];
    $wallet_add = $_POST['wallet_add'];
    $bank_name = $_POST['bankName'];
    $acct_name = $_POST['accountName'];
    $acct_no = $_POST['accountNumber'];
    $acct_swift = $_POST['sort_code'];

    if ($method == "Bank") {
      $withdrawal_des = "Bank Name:$bank_name, Acct No:$acct_no, Account Name:$acct_name, Swift Code:$acct_swift";
      $t_mode = "$method";
    }else {
      $withdrawal_des = $wallet_add;
      $t_mode = "$method ($coin)";
    }


    if (empty($amount)) {
        $error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
          <i class='fa fa-warning'></i> &nbsp; enter withdrawable amount to complete withdrawal
        </div>";
    }else if ($method == "Bank" AND empty($bank_name) || empty($acct_name) || empty($acct_no)) {
      $error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
        Please enter Bank Details to complete withdrawal!
      </div>";

    }else if ($method == "Crypto" AND empty($wallet_add)) {
      $error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
        Please enter $coin wallet address to complete withdrawal
      </div>";

    }else if ($amount > $balance) {
      $error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
        insufficient balance, make a deposit!
      </div>";
    }else {
      $error = "<div class='alert alert-danger d-flex align-items-center' role='alert'>
        Wihdrawal cannot be placed at the moment due to ongoing trade session, kindly message support
      </div>";
    }

}
?>
