<?php
use App\Models\Setting;
use App\Models\Bank;

$setting = Setting::first();

$banks = Bank::all();

$bank_status = [];

//status active bank
foreach ($banks as $bank) {
  $bank_status[$bank->nama_bank] = $bank->status == 1;
}
?>
@extends('layouts.main')
@section('isMobile')
<form id="depositForm" class="needs-validation" action="" method="post" accept-charset="UTF-8" enctype="multipart/form-data" novalidate="novalidate">
  

  <div class="box-wrapper plr-15">
    <div class="row d-flex">
      <div class="col-md-3 col-xs-4  ">
        <div class="font-weight-bold">
          Metode Penyetoran<span class="text-danger">*</span>
        </div>
      </div>
      <div class="col-md-9 col-xs-8 d-flex flex-wrap">
        <div class="radio_2 ">
          <input class="" id="radioBank7" name="deposite_method" checked="" type="radio" value="7">
          <label class=" " for="radioBank7">
            <span class="radio-title">
              E-wallet                </span>
            <span class="marked">
              <i class="icon-checkmark"></i>
            </span>
          </label>
        </div>
        <span class="method-check-type" id="checkType">(Manual Cek)</span>
        <span class="deposit-info">
          <span id="selectedBank"></span>
          Jumlah Deposit IDR
          <span id="depositAmount"></span>
        </span>
      </div>
    </div>
    <div class="tab">
      <!--- First Tab ----->
      <!------------------------------------ Except Crypto Show Sender Banks Details ------------------------->
      <!------------------------------------ Except Crypto Show Sender Banks Details End ------------------------->
      

      <div class="deposit-form  row d-flex" id="deposit-form-7" style="">
        <div class="col-md-3 col-xs-4  ">
          <div class="font-weight-bold">
            *Bank<span class="text-danger">*</span>
          </div>
        </div>
        <div class="col-md-9 col-xs-8 d-flex flex-wrap">
          <select class="form-control bank_list m-15" data-type="7" data-plugin="bank_list" id="bank_name_7" name="bank_name">
            <option selected="" value="">-Silahkan pilih -</option>
    
            @foreach($bankMethods as $method)
            <option value="{{ $method->provider }}" data-p_id="{{ $method->p_id }}" data-status="1">{{ $method->nama_bank }}</option>
            @endforeach
         
          </select>
          <input type="hidden" name="bank_to_provider" id="bank_to_provider" value="63e49933da51bb04e726e69c">

        </div>
      </div>
      <div class="row  info-lst" id="bankInfo_de001" style="">
        <div class="col-md-3">
          <div class="qrcode"></div>
        </div>
        <div class="col-xs-12 col-md-9 ">
          <div class="bankInfo-box" id="bankList">
            <div class="box-title">
              <i class="icon-invoice i-invoice"></i>
              Rincian Deposit Akun
              <div class="pull-right acc_status">
                STATUS : <span class="text-success">ONLINE</span>
              </div>
              <input type="hidden" id="depo_acc_status" value="ONLINE">
            </div>

            <table class="table table-borderless   text-right info-box--001">
              <tbody>
                <tr class="text-center first">
                  <td colspan="2" style="padding-bottom:10px">
                    <img src="https://files.sitestatic.net/e-wallet/20240222082805000000b9383399732M3HYAA__231x233.png" alt="" style="display:block; margin:auto; height: 200px;">
                  </td>
                </tr>
                <tr class="text-left first">
                  <td class="col-xs-12 col-md-6 " colspan="2">
                    <small>
                      Nama akun                                    </small>
                  </td>
                </tr>
                <tr class="">
                  <td class="col-xs-12 col-md-6 " colspan="2">
                    <input id="NhdZqqtX" value="MHD RAMLI" class="copy-input">

                    <a href="javascript:void(0);" data-sel="NhdZqqtX" class="btn btn-link btn-copy lbl">
                      <span class=" ">
                        MHD RAMLI
                      </span>
                      <i class="icon-copy"></i>
                    </a>
                    <div class="btn btn-link btn-copy lbl" style="display: none;"></div>
                    <div class="btn btn-link btn-copy lbl" style="display: none;"></div>
                  </td>
                </tr>
                <tr class="text-left first">
                  <td class="col-xs-12 col-md-6 " colspan="2">
                    <small>
                      No. Wallet / ACCT
                    </small>
                  </td>
                </tr>

                <tr class=" ">
                  <td class="col-xs-12 col-md-6" colspan="2" style="padding-bottom: 10px;">


                    <input id="0QXD6TgjFi" value="08785202" class="copy-input">

                    <a href="javascript:void(0);" data-sel="0QXD6TgjFi" class="btn btn-link btn-copy lbl">
                      <span class=" " style="white-space: normal; word-break: break-word;">
                        08785202
                      </span>
                      <i class="icon-copy"></i>
                    </a>
                    <div class="btn btn-link btn-copy lbl" style="display: none;"></div>
                    <div class="btn btn-link btn-copy lbl" style="display: none;"></div>


                  </td>
                </tr>
                <tr class="text-left tr_type2  ">
                  <td class="col-xs-6 col-md-6"> <small>Bank</small> </td>
                  <td class="col-xs-6 col-md-6 text-right">
                    <span class="lbl">
                      0
                    </span>

                  </td>
                </tr>
                <tr class="text-left tr_type2  ">
                  <td class="col-xs-6 col-md-6"> <small>Min Deposit</small> </td>
                  <td class="col-xs-6 col-md-6 text-right">


                    <span class="lbl">
                      IDR10,000.00
                    </span>
                    <input type="hidden" id="bank_min_deposit" class="min_deposit" value="10000">
                  </td>
                </tr>

                <tr class="text-left tr_type2">
                  <td class="col-xs-6 col-md-6 "> <small i18n="">Max Deposit</small></td>
                  <td class="col-xs-6 col-md-6 text-right ">
                    <span class="lbl">
                      IDR10,000,000.00
                    </span>
                    <input type="hidden" id="bank_max_deposit" class="max_deposit" value="10000000">
                  </td>
                </tr>

                <tr class="text-left tr_type2  ">
                  <td class="col-xs-6  col-md-6 "> <small i18n="">Komisi Bank / Transaksi</small></td>
                  <td class="col-xs-6 col-md-6 text-right">

                    <span class="lbl">
                      IDR 0.00
                    </span>
                  </td>
                </tr>

                <input type="hidden" id="admin_fee" value="IDR 0.00">
                <input type="hidden" id="percent_check" value="0">
                <tr class="text-left tr_type2  ">
                  <td class="col-xs-6  col-md-6 "> <small i18n="">Subsidi Bank / Transaksi</small></td>
                  <td class="col-xs-6 col-md-6 text-right">

                    <span class="lbl">
                      IDR 0

                    </span>
                  </td>
                </tr>

                <input type="hidden" id="subsidi" value="IDR 0">
              </tbody>
            </table>

            <script>
              $(document).ready(function() {

                $('[data-toggle="tooltip"]').tooltip();
              });

            </script>
          </div>
        </div>
      </div>
      <div class="row d-flex">
        <div class="col-md-3 col-xs-4">
          <div class="font-weight-bold">
            Bonus
          </div>
        </div>
        <div class="col-md-9 col-xs-8   d-flex flex-wrap">

          <div class="m-15" style="width: 100%;">
            <div style="    width: 100%; ">
              <select class="form-control promoList " name="promo_event" data-plugin="promoList" id="promo_event">
                <option value="0">Pilih promo tersedia</option>
                <option value="SPORTSKY">BONUS NEW MEMBER SPORTSBOOK 20%    |  SPORTSKY</option>
              </select>
            </div>
            <div class="fs-sm" style="  ">
              <span style="">Ada kode promosi? </span> <button class="btn btn-link txt_accent fs-sm" id="btn_add_promo" type="button">Tambah disini</button>
            </div>
            <div class="" id="f_grp_promo_code" style="display:none; margin-top:5px;  ">
              <div class="input-group uline">
                <input type="text" disabled="" id="pcode_not_confirm" name="pcode_not_confirm" class="ignore form-control underline " placeholder="Masukkan kode promo" value="">
                <span class="input-group-btn">
                  <button class="btn btn-link  " id="btn_apply_pcode" type="button">Apply</button>
                  <button class="btn btn-link" id="btn_clear_pcode" style="display:none;" type="button">Clear</button>
                </span>
              </div>
              <!-- /input-group -->
            </div>
            <div class="" style="position: relative; width:100% ; margin-bottom:5px; ">
              <input type="hidden" disabled="" id="promo_code" name="promo_code" class="form-control " value="">
            </div>

          </div>
        </div>
      </div>
      <div class="row info-lst" id="promoInfo_de001" style="display: none;">
        <div class="col-md-3"></div>
        <div class="col-xs-12 col-md-9 ">
          <div class="bankInfo-box" id="promoList">
          </div>
        </div>
      </div>
      <div class="row d-flex">
        <div class="col-md-3 col-xs-4 ">
          <div class="font-weight-bold">
            Jumlah Deposit<span class="text-danger">*</span>
          </div>
        </div>
        <div class="col-md-9 col-xs-8">
          <div class=" d-flex flex-wrap">
            <input type="tel" class="form-control m-15" placeholder="0.00" id="deposite_amount" name="deposite_amount" autocomplete="off">
          </div>
          <p class="min-max-notes">
            Min Deposit <span class="min-deposit-amount" style="padding-right: 30px;"><b>10,000.00</b></span>
            Max Deposit <span class="max-deposit-amount"><b>10,000,000.00</b></span>
          </p>
        </div>
      </div>

      <div class="row d-flex">
        <div class="col-md-3 col-xs-4  ">
          <div class="font-weight-bold">
            Keterangan                                      <span class="text-danger">*</span>
          </div>
        </div>
        <div class="col-md-9 col-xs-8 d-flex flex-wrap">
          <input type="text" class="form-control m-15" id="ref_no" maxlength="35" minlength="5" name="ref_no" placeholder="No. Referensi / Nama Pengirim" required="">
        </div>
      </div>
      <div class="row d-flex">
        <div class="col-md-3 col-xs-4 ">
          <div class="font-weight-bold">
            Bukti Transfer
          </div>
        </div>
        <div class="col-md-9 col-xs-8 d-flex flex-wrap">
          <div class="file-drop-area file-drop-area-receipt m-15">
            <span class="btn btn-secondary " i18n="">Pilih File</span>
            <span class="file-msg">
              atau seret dan taruh file di sini                   </span>
            <input class="file-input" name="receipt" id="receipt" type="file">
          </div>
        </div>
      </div>

      <!--  only for curacao_lic (TODO: change $curacao_lic) -->
      <!--  only for curacao_lic-->

      <div class="row d-flex">
        <div class="col-md-12 d-flex flex-wrap">
          <label>
            <input type="checkbox" class="form-check-input" id="exampleCheck1" name="termcondition">
            Saya telah membaca dan menyetujui Syarat dan Ketentuan Promosi. Kami tidak menerima jenis setoran dalam bentuk cek. Semua jenis pembayaran dalam bentuk cek ke akun kami akan diabaikan. </label>
        </div>
      </div>
    </div>
    <!--- second Tab end----->
    <div class="row d-flex">
      <div class="col-md-3 col-xs-4  ">
      </div>
      <div class="col-md-9 col-xs-8 d-flex flex-wrap">
        <div class="m-15">
          <button type="button" class="btn btn-primary" id="backBtn" onclick="load_method_form()">Back</button>

          <button type="submit" class="btn btn-secondary" id="submitBtn">Deposit</button>
        </div>
      </div>
    </div>
  </div>
  <input type="hidden" id="stage_val">
</form>
<script>
  window.removeOptions= function ($select, $options) {
        window.setOriginalSelect($select);
        $options.remove();
    }

  window.restoreOptions= function ($select) {
        var ogHTML = $select.data("originalHTML");
        if (ogHTML != undefined) {
            $select.html(ogHTML);
        }
    }
window.setBankUserOptions= function (method){

    var $s = $('select#bank_user_id');
    window.restoreOptions($s); // Make sure you're working with a full deck
    var $optsToRemove  = $s.find('option').not('[data-method='+ method +']' ).not('[value=""]' );
    if(method == 5){
            $optsToRemove = $optsToRemove.not('[data-method='+ 7 +']' );
        }
    window.removeOptions($s, $optsToRemove); 

}

        var secret_key = 'aa';
        var bank_min_amount =_min_amount = "50000";
        var bank_max_amount =_max_amount  = "100000000";
        var min_string = "The minimum deposit amount is"  ;
        var max_string = "The maximum deposit amount is" ;
        var method = 5 ;
        var providerSettingID = "" ;
        var pID = "" ;
        var agent_code = '' ;

        $(document).ready(function () {
                    $('#user_identification-field').hide();
                    $('#source-fund-field').hide();
                    $('#source_fund').prop('disabled',true);
                    $('#user_identification').prop('disabled',true);
                    $('#source_fund').prop('disabled',true);

            window.setBankUserOptions(method);
            $('#bankInfo_de001').hide();
            $('#promoInfo_de001').hide();


            var onFirstLoad=true;
            function onChgDepositeMethod( ){
                $('.deposit-form').hide();
                $('#deposit-form-'+ $(this).val()).show();
                $('select.bank_list').prop('disabled',true);
                $('select.bank_list').val('');
                $('#bank_name_'+ $(this).val()).prop('disabled',false);
                $('#bank_user_id').prop('disabled',false);

                if(method ==6){
                    $('#ref_no').attr('placeholder','No Ref /No Serial /No Pengirim' );
                }
                else {
                    $('#ref_no').attr('placeholder','No. Referensi / Nama Pengirim' );
                }
                $('#bankList').html('');
                $('#bankInfo_de001').hide();

            }
            
              $('input[name=deposite_method]').change(onChgDepositeMethod );

            $('input[name=deposite_method][value="' + method+ '"]').each(onChgDepositeMethod );



            $('.bank_list').on('change', function () {

                var select_name = $(this).val();
                var position = $(this).find(":selected").index();
                $('#bankList').html('');
                $('#bankInfo_de001').hide();
                var type= $(this).data('type');
                var provider_Id=$(this).find(":selected").data('p_id');
                $('input[id=bank_to_provider]').val(provider_Id);

                bank_max_amount = _max_amount;
                bank_min_amount = _min_amount;
                 $('.min_deposit').val(_min_amount) ;
                 $('.max_deposit').val(_max_amount) ;
                 var _self= this;

                 function onSelBankIsNotEmpty(){
                    $('#bankInfo_de001').fadeIn();
                    var _bank_min= $('#bank_min_deposit').val();
                    var _bank_max= $('#bank_max_deposit').val();
                    bank_min_amount = parseInt(_bank_min);
                    bank_max_amount = parseInt(_bank_max);
                    $('.min-deposit-amount').html(  '<b>' +  window.commaSeparateNumber( bank_min_amount) + '</b>') ;
                    $('.max-deposit-amount').html(  '<b>' +  window.commaSeparateNumber( bank_max_amount) + '</b>') ;
                    var o = {msg : ''};
                    var cal_min_amount = getMinDepoWithPromo(bank_min_amount,o );
                    var msgMin = o.msg;

                    adddepositAmtRules(cal_min_amount , bank_max_amount , msgMin );
                }
                function onSelBankIsEmpty(){
                    var o = {msg : ''};
                    var cal_min_amount = getMinDepoWithPromo(bank_min_amount,o );
                    var msgMin = o.msg;
                    adddepositAmtRules(cal_min_amount , bank_max_amount , msgMin );
                }

                function getBankDetails(){
                    var token = $("input[name='_token']").val();
                    var _onFirstLoad = onFirstLoad;

                    var __self = _self;
                    $.ajax({
                        url: "/deposit-bank-details",
                        type: "POST",
                        data: { select_name: select_name, _token: token, type: type ,lang : window.lang,provider_id:provider_Id},
                        beforeSend: function () {
                            $("#bankList").html();
                            2000
                        },
                        success: function (data) {
                            if (data) {


                                $("#bankList").html(data);
                                
                                

                                if($('#depo_acc_status').val() == 'OFFLINE'){
                                    if(!_onFirstLoad){
                                        sweetAlert( transMsgs.offlineBank , 'warning' , 'Warning' , true ).then(
                                                    function(isConfirm) {
                                                        if(isConfirm){

                                                            onSelBankIsNotEmpty();
                                                        }
                                                        else {
                                                            $("#bankList").html('');
                                                            $(__self).val(null);
                                                            onSelBankIsEmpty();
                                                        }
                                                    }
                                        ) ;

                                        return ;
                                    }

                                }

                                onSelBankIsNotEmpty();
                                return ;


                            }
                            else {
                                $("#bankList").html('');
                                $(_self).val(null);
                                onSelBankIsEmpty();
                            }
                        }
                    });
                }

                if ( !!select_name  ) {
                    getBankDetails();
                }

                else {
                    onSelBankIsEmpty();

                }



                return false;

            });
            
            $('#btn_add_ubank__depo').click(function(e){

           // $(this).prop('disabled',  true);
            $('#regbank_popup__depo').html('');
            $('#regbank_popup__depo').load('/regaccform?type=' + method , function(){
            $('#regbank_popup__depo').nifty("show");
            if(method==5){
                 window.bindBankRegFormVal('#bank_register_popup');
            }
            else  {
                window.bindNewFundRegFormVal("#pulsa_register_form");
            }

            });
        });
        
         function getMinDepoWithPromo(bank_min ,msgMin ){
                msgMin.msg  =  min_string;
                bank_min = bank_min?     bank_min : _min_amount;
                var selPromoInd=  $('.promoList').find(":selected").index();
                var hasSelPromo= !!selPromoInd || !!$('#promo_code').val() ;
                if (!hasSelPromo) {
                    return bank_min ;
                }
                else {

                    promo_min_amount =  parseInt($('#promo_min_amount').val() ); //

                    if(!!promo_min_amount){

                        if(promo_min_amount  >  bank_min ) {
                            msgMin.msg =  "Persyaratan minimal deposit untuk promo adalah  " ;

                            return promo_min_amount;
                        }
                    }

                }

                return bank_min ;
            }
          
            $('select[data-plugin="bank_list"][data-type="'+ method + '"]').find('option').each(function(index,element){
                  let provider_id = $(element).data('p_id');
                  let provider_setting_id = element.value;
                  if(provider_id == pID && provider_setting_id == providerSettingID){
                    $(element).prop('selected','selected').trigger('change');
                  }

            });
            onFirstLoad=false;
            $('.promoList').on('change', function () {
                //var selected = $(this).find("option:selected").val();
                var promo_id = $(this).val();

                // var position = $(this).find(":selected").index();
                $('#promoList').html('');
                $('#promoInfo_de001').hide();

                if (promo_id == 0) {
                    $('input[name="promo_code"]').prop('disabled',false);
                    var msgMin = min_string;
                    adddepositAmtRules(bank_min_amount , bank_max_amount , msgMin );
                    $('input[name="pcode_not_confirm"]').prop('disabled',false);
                    $('#btn_apply_pcode').prop('disabled',false);
                } else {
                    $('input[name="promo_code"]').val('');
                    $('input[name="promo_code"]').prop('disabled',true);
                    function cbPromoList(r){
                        if(r.status){
                        $('input[name="pcode_not_confirm"]').val('').prop('disabled',true);
                        $('#btn_apply_pcode').prop('disabled',true);
                        }
                    }
                    getPromoNAddDepoRules(promo_id ,cbPromoList);
                    return false;

                }
                return false;
            });

            function adddepositAmtRules(intMin , intMax , msgMin ){
                $("#deposite_amount").rules("remove", "min max");
                $("#deposite_amount").rules("add",
                    {
                        min: intMin,
                        max: intMax,

                        messages: {
                            min: msgMin + window.currencyCode + window.commaSeparateNumber( intMin),
                            max: "Jumlah deposit maksimum adalah"  + window.currencyCode + window.commaSeparateNumber(intMax),
                        }
                    });
            }
            function getPromoNAddDepoRules(promo_id , cb, reqUrl = "https://skylink386.shop/promo_details", is_promo_code = false){
                $('#promoInfo_de001').hide();
                $("#promoList").html('');
                var result = { status : true, msg : '' } ;
                var token = $("input[name='_token']").val();

                //clear promo code first
                $('input[name="promo_code"]').prop('disabled',true).val('');
                $.ajax({
                        url: reqUrl,
                        type: "POST",
                        async:true,
                        data: { select_name: promo_id, _token: token,is_promo_code:is_promo_code,method:method},
                        //dataType: 'json',
                        beforeSend: function () {
                            $("#bankList").html();
                            2000
                        },
                        success: function (data) {
                            if (data) {

                                $("#promoList").html(data);
                                $('#promoInfo_de001').fadeIn();


                                depoValidator.showErrors({
                                     "promo_code": null
                                });
                            }
                        },
                        error: function(xhr, status, error){
                            result.status = false ;


                            if(xhr.responseJSON){
                                result.msg =  xhr.responseJSON.message ;

                            }
                            else {

                                result.msg = JSON.parse(xhr.responseText).message;
                            }
                            sweetAlert( result.msg, 'warning' , 'Warning' );
                            $('#promo_event').val(0);

                        },
                        complete: function(){


                            cb(result);

                            var o = {msg : ''};
                            var cal_min_amount = getMinDepoWithPromo(bank_min_amount,o );
                            var msgMin = o.msg;
                            adddepositAmtRules(cal_min_amount , bank_max_amount , msgMin );

                        },
                    });

                    return result;
            }

            $('#btn_add_promo').click(function(){
                  $('#f_grp_promo_code').fadeIn();
                  var v = $('#promo_event').val();
                  if(  !!v &&  v!=0 ){
                     $('#pcode_not_confirm').prop('disabled',true);
                  }
                  else {
                    $('#pcode_not_confirm').prop('disabled',false);
                  }
                  $(this).parent().hide();
                  return false;
              });
              var btn_click= false;
            $('#btn_apply_pcode').click(function(e){
                if(btn_click==true){
                    return;
                }
                btn_click=true;
                e.preventDefault();
                $(this).prop('disabled',true);

                function cbPromoCode(r){
                    if(r.status){

                        $('#promo_event').val(0).prop('disabled',true);
                        $('input[name="promo_code"]').prop('disabled',false).val($('input[name="pcode_not_confirm"]').val());
                        $('input[name="pcode_not_confirm"]').prop('disabled',true); //when pcode correct , user shud click clear btn
                        $('#btn_apply_pcode').hide();
                        $('#btn_clear_pcode').show();
                        depoValidator.showErrors({
                            "promo_code":  null
                            });
                    }
                    else {
                        depoValidator.showErrors({
                            "promo_code": r.msg
                            });
                    }

                    setTimeout(function(){
                        $('#btn_apply_pcode').prop('disabled',false).blur().focusout();
                        btn_click=false;
                    }  , 2000);
                }

                var v = $('#pcode_not_confirm').val();
                var r =  {'status' : true , 'msg' : ''};
                if(!v || (v && v.length <2)  ){
                    r.status = false;
                    r.msg = "Kode promo tidak boleh lebih dari 8 karakter";
                }
                else  if(!v || (v && v.length > 15 ) ){
                    r.status = false;
                    r.msg = "Kode promo tidak boleh lebih dari 15 karakter";
                }
                else {
                    r =  getPromoNAddDepoRules(v ,  cbPromoCode , "https://skylink386.shop/promo_details",true );
                    return false;
                }

                cbPromoCode(r);

                return false;
            });


            $(document).on('click'  , '#btn_clear_pcode, #btn-clear-all-promo', function(){
                $('input[name="promo_code"]').prop('disabled',false).val('');
                $('input[name="pcode_not_confirm"]').prop('disabled',false).val('');
                $('#promo_event').prop('disabled',false).val(0);
                $('#btn_apply_pcode').prop('disabled',false);
                $( '#btn_clear_pcode').hide();
                $('#btn_apply_pcode').show();
                $("#promoList").html('');
                $('#promoInfo_de001').hide();
                var msgMin = min_string;
                    adddepositAmtRules(bank_min_amount , bank_max_amount , msgMin );
                return false;
            }
            );

          
            fileUploadReceipt('.file-drop-area-receipt');
            fileUploadReceipt('.file-drop-area-user_identification');

            function fileUploadReceipt(className){
                var droppedFiles = false;
                $(className).on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
                    e.preventDefault();
                    e.stopPropagation();
                })
                .on('dragover dragenter', function() {
                    $(this).addClass('is-dragover');
                })
                .on('dragleave dragend drop', function() {
                    $(this).removeClass('is-dragover');
                })
                .on('drop', function(e) {
                    droppedFiles = e.originalEvent.dataTransfer.files;
                    $(this).find('input[type="file"]').prop('files', droppedFiles);

                    if(droppedFiles){
                    $(this).find('.file-msg').html(droppedFiles[0].name);
                    }
                    else{

                        $(this).find('.file-msg').html('   or drag and drop file here');
                    }
                });

                $(className+' input[type="file"]').on('change', function(e) {
                    var file = e.target.files;
                    if(file){
                        var fileName= file[0]?file[0].name : '   or drag and drop file here' ;

                        $(className+' .file-msg').html(fileName);
                    }
                    else{
                        $(className+' .file-msg').html('   or drag and drop file here');
                    }
                })
            }




            $('#btn_clear_pcode').click(function(){
                $('#promoList').html('');
            });




            var depoValidator =   $("#depositForm").validate({
                // Specify validation rules
                ignore: ".ignore" ,
                rules: {
                    // The key name on the left side is the name attribute
                    // of an input field. Validation rules are defined
                    // on the right side
                    deposite_amount: {
                        required:true,
                        normalizer: function( value ) {
                              return   value? convertToNumber(value) : null   ;
                            },
                        number:true,
                        min: bank_min_amount,
                        max: bank_max_amount,

                    },
                    bank_name: {
                        required:true
                    },
                    bank_user_id: {
                        required:true,
                    },
                    deposite_method: {
                        required:true
                    },
                    // promo_event: {
                    //     required:true
                    // },
                    promo_code : {
                        minlength:2,
                        maxlength:15,
                        // validatePromoCode:true
                    },
                    termcondition:{
                      required:true
                    },
                    receipt: {
                        extension: 'jpeg|jpg|png|bmp',
                    },
                    ref_no :{
                        pattern:/^[a-zA-Z0-9, .\/\\\-]+$/,
                        maxlength:35,
                        minlength:5,
                    }

                },
                // Specify validation error messages
                messages: {

                    deposite_amount: {
                        required: " tidak boleh kosong",
                        number: "Jumlahnya harus berupa angka",
                        min: "Jumlah deposit minimum adalah " + window.currencyCode + window.commaSeparateNumber(bank_min_amount),
                        max: "Jumlah deposit maksimum adalah " + window.currencyCode + window.commaSeparateNumber(bank_max_amount),
                    },
                    bank_name: {
                        required: " tidak boleh kosong",
                    },
                    bank_user_id: {
                        required: " tidak boleh kosong",
                        remote: "Please Select Valid Bank"
                        //remote : transMsgs.bankAccountNamesNotAvailable,
                    },
                    deposite_method: {
                        required: " tidak boleh kosong",
                    },
                    promo_event: {
                        required: "Metode Promosi diperlukan. Silakan pilih Metode Promosi.",
                    },
                    termcondition:{
                      required:"Syarat dan ketentuan diperlukan",
                    },
                    receipt: {
                        extension: "File yang dipilih tidak valid",
                    },
                    ref_no :{
                        pattern: "Hanya huruf, angka, koma, spasi, dan - / \ ",
                        maxlength:  "Maksimal 20 karakter saja",
                        minlength:  "Diperlukan minimal 5 karakter",
                        required:" tidak boleh kosong",
                    }


                },
                errorElement: "em",
                errorPlacement: function (error, element) {
                    // Add the `help-block` class to the error element
                    error.addClass("help-block mlr-15");

                    // Add `has-feedback` class to the parent div.form-group
                    // in order to add icons to inputs
                    //element.parents(".col-sm-6").addClass("has-feedback");
                    element.addClass("has-feedback");
                    if (element.prop("type") === "checkbox") {
                        error.insertAfter(element.parent("label"));
                    } else {
                        error.insertAfter(element);
                    }

                    // Add the span element, if doesn't exists, and apply the icon classes to it.
                    if (!element.next("i")[0]) {
                        $("<i class='icon-cancel form-control-feedback absolute m-15'></i>").insertAfter(element);
                    }
                },
                success: function (label, element) {
                    // Add the span element, if doesn't exists, and apply the icon classes to it.

                    if (!$(element).next("i")[0]) {
                        $("<i class='icon-checkmark  form-control-feedback absolute m-15'></i>").insertAfter($(element));
                    }
                },
                highlight: function (element, errorClass, validClass) {

                    $(element).addClass("has-error").removeClass("has-success");
                    $(element).next("i").addClass("icon-cancel").removeClass("icon-checkmark");
                },
                unhighlight: function (element, errorClass, validClass) {

                    $(element).addClass("has-success").removeClass("has-error");
                    $(element).next("i").addClass("icon-checkmark").removeClass("icon-cancel");
                },
                // Make sure the form is submitted to the destination defined
                // in the "action" attribute of the form when valid
                submitHandler: function (form) {

                    //console.log($(form).serialize());

                 function cbSubmit(){
                        $(form).find('button[type="submit"]').prop('disabled', true);
                        window.ajax_submit(form).done(
                                    function(d){
                                        if(d.status = 's'){//success

                                            $(form).each(function(){
                                                    this.reset();
                                                    $('.info-lst').hide();
                                                    $('.bankInfo-box').html('');
                                                    $('.file-drop-area .file-msg').html('   or drag and drop file here');

                                            });


                                            $(form).validate().resetForm();
                                            if (d.redirectUrl) {
                                                location.href = d.redirectUrl;
                                            }
                                            sweetAlert( d.m ,'success', transMsgs.success).then(function(){
                                                location.reload();
                                            });

                                        }
                                        else {
                                            sweetAlert( d.m );
                                        }
                                    }
                            );

                    }
                    if(!!$('#pcode_not_confirm').val() && !$('#promo_code').val() && (!$('#promo_event').val() || $('#promo_event').val() ==0)   ){
                        sweetAlert( transMsgs.pCodeConfirm , 'warning' , 'Warning' , true ).then(
                            function(isConfirm) {
                                if(isConfirm){
                                    cbSubmit();
                                }
                            }
                        ) ;
                    }else {
                        cbSubmit();
                    }

                    return false;
                }
            });  


            $('#deposite_amount').priceFormat({prefix: '', centsLimit: 0, thousandsSeparator: ',', clearOnEmpty: true});
        });
</script>

 <!-- <script>
    
 
            
       //     $('#deposite_amount').on('keyup',function(e){
        //        if($('#max_depo_alert').length > 0){
         //           checkDepositAmount();
        //        }
      //      });

          //  function checkDepositAmount(){
          //      var amt= parseInt($('#deposite_amount').val().replace(',','')) || 0;
        //        if($('#deposite_amount').hasClass('has-error')
     //           || !$('#max_depo_alert').val() || $('#max_depo_alert').val() == 0
     //           || amt  < parseInt( $('#max_depo_alert').val())){
  //                  $('#user_identification-field').hide();
    //              $('#source-fund-field').hide();
          //          $('#source_fund').prop('disabled',true);
            //        $('#user_identification').prop('disabled',true);
          //          $('#source_fund').prop('disabled',true);
    //            }else{
    //                $('#user_identification-field').show();
  //                  $('#source-fund-field').show();
 //                   $('#user_identification').prop('disabled',false);
  //                  $('#source_fund').prop('disabled',false);
    //            }
//            }


          

 // Add new banks for user form pokerace ------------------------------------------------------------------


            
        // document.getElementById("bank_user_id").onchange = function () {

        //     status = this.options[this.selectedIndex].getAttribute("status");
        //     switch(status ){
        //         case "2" :
        //             $(this).val("");
        //           return sweetAlert( "This account is currently suspend");
        //         break;
        //         case "0" :
        //             $(this).val("");
        //             return sweetAlert( "This account  is currently inactive");
        //         break;
        //      }

        // }


             </script> -->
@endsection