<?php
// session_start();
require("../includes/db_connect.php");
require_once("includes/session_token.php");

$accountId = $_SESSION['usr_accountId'];

$page_content = "";
$ssn_field = "";

$sql = "SELECT * FROM users WHERE accountId = :accountId LIMIT 1";
$sth = $conn->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$sth->execute([':accountId' => $accountId]);
$users = $sth->fetchAll();

foreach ($users as $key => $value) {
    $country = $value['country'];

    if ($country == "United States of America") {
        $ssn_field = ' <div class="col-md-6 " style="margin-top: 20px">
  <label for="ssn">SSN</label>
  <input type="text" class="form-control" id="ssn" autocomplete="off" placeholder="">
  <div class="invalid-feedback ssn_feedback"></div>
  </div>

   <div class="col-md-6 " style="margin-top: 20px">
  </div>';
    }
}

$kyc_usr_sql = "SELECT * FROM kyc_documents WHERE accountId =? LIMIT 1";
$kyc_usr_sth = $conn->prepare($kyc_usr_sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$kyc_usr_sth->execute([$accountId]);
$kyc_users = $kyc_usr_sth->fetchAll();

if (count($kyc_users) > 0) {
    foreach ($kyc_users as $key => $value) {
        $full_legal_name = $value['full_legal_name'];

        if ($full_legal_name != "default") {
            $page_content = '<div class="col-md-12">
      <h6 class="card-title">Identity Verification</h6>
      <p class="primary-color"><i class="link-icon" data-feather="user-check"></i></p>
      <p style="margin-top: 30px">Identity verification documents <br/> have been submitted.</p>
      </div>';
        } else {
            displayForm();
        }
    }
} else {
    displayForm();
}



function displayForm()
{
    global $page_content, $ssn_field;

    $page_content = '<div class="col-md-12">
  <h6 class="card-title">Identity Verification</h6>

  <div style="display: none;" id="errorPrompt" class="alert alert-danger" role="alert">
  <p></p>
  </div>

  <div class="row">

  <div class="col-md-6 " style="margin-top: 20px">
  <label for="legal_name">Full legal name</label>
  <input type="text" class="form-control" id="legal_name" autocomplete="off" placeholder="">
  <div class="invalid-feedback legal_name_feedback"></div>
  </div>

  <div class="col-md-6 " style="margin-top: 20px">
  <label for="nationality">Nationality</label>
  <input type="text" class="form-control" id="nationality" autocomplete="off" placeholder="">
  <div class="invalid-feedback nationality_feedback"></div>
  </div>

  '.$ssn_field.'

  <div class="col-md-6 " style="margin-top: 20px">
  <label for="date_of_birth">Date of Birth</label>
  <input type="text" id="date_of_birth" class="form-control" placeholder="DD/MM/YYYY" value="">
  <div class="invalid-feedback date_of_birth_feedback"></div>
  </div>

  <div class="col-md-6 " style="margin-top: 20px">
  <label for="address">Address</label>
  <input type="text" class="form-control" id="address" autocomplete="off" placeholder="">
  <div class="invalid-feedback address_feedback"></div>
  </div>

  <div class="col-md-6 " style="margin-top: 20px">
  <label for="mobile_number">Mobile Number</label>
  <input type="text" class="form-control" id="mobile_number" autocomplete="off" placeholder="e.g. (+1.....)">
  <div class="invalid-feedback mobile_number_feedback"></div>
  </div>

  <div class="col-md-6 " style="margin-top: 20px">
  <label for="email">Email Address</label>
  <input type="text" class="form-control" id="email" autocomplete="off" placeholder="">
  <div class="invalid-feedback email_feedback"></div>
  </div>

  <p  class="col-md-12" style="margin-top: 20px">Upload Identity Document (For example: ID card, Drivers License, Passport).</p>

  <div class="col-md-6 " style="margin-top: 20px">
  <label for="identity_file">Photo of identity document</label>
  <input type="file" id="identity_file" class="border" data-allowed-file-extensions="jpg png jpeg PNG JPEG JPG" data-max-file-size="1M"/>
  <div class="invalid-feedback identity_file_feedback"></div>
  </div>

  <div class="col-md-6 " style="margin-top: 20px">
  <label for="backside_file">Backside of identity document (if using passport, upload passport again).</label>
  <input type="file" id="backside_file" class="border" data-allowed-file-extensions="jpg png jpeg PNG JPEG JPG" data-max-file-size="1M"/>
  <div class="invalid-feedback backside_file_feedback"></div>
  </div>

  </div>


  <button type="button" style="margin-top: 20px" class="btn btn-primary  confirm_and_submit">Confirm and Submit
  <span style="display: none;" class="button_spinner spinner-border spinner-border-sm" role="status" aria-hidden="false"></span>
  </button>
  </div>';
}

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Identity Verification</title>
    <link rel="stylesheet" href="../assets/vendors/dropify/dist/dropify.min.css">

    <?php require_once("includes/header.php"); ?>

    <div class="content ht-100v pd-0">
        <div class="content-header center">
            <img src="../img/logo-white.png" class="aside-logo" style="width: 160px;" />
        </div><!-- content-header -->

        <div class="content-body">
            <div class="container pd-x-0">
                <div class="d-sm-flex align-items-center justify-content-between mg-b-20 mg-lg-b-25 mg-xl-b-30">
                    <div>
                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb breadcrumb-style1 mg-b-10">
                                <li class="breadcrumb-item"><a href="account">Dashboard</a></li>
                            </ol>
                        </nav>
                        <h4 class="mg-b-0 tx-spacing--1">Identity Verification</h4>
                    </div>

                </div>

                <div class="row row-xs">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body" id="page_content" style="padding-top: 50px; padding-bottom: 100px">

                                <?php echo ($page_content); ?>


                            </div>
                        </div>
                    </div>
                </div><!-- row -->

            </div><!-- container -->
        </div>
    </div>

    <?php require_once("includes/footer.php"); ?>
    <script src="../assets/vendors/dropify/dist/dropify.min.js"></script>
    <script src="../assets/js/dropify.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        var classes = $("#mn-identity-verification").prop('class');
        $("#mn-identity-verification").prop('class', classes + ' active pcoded-trigger');

    });
    </script>
    <script src="../js/identity-verification.js?<?php echo(rand()); ?>"></script>

    </body>

</html>