@extends('template.vendorapp')

@section('meta')
@endsection

@section('title')
    Change Password
@endsection

@section('styles')
<link href="{{ asset('assets/css/dropify.min.css') }}" rel="stylesheet">
<link href="{{ asset('assets/css/sweetalert2.bundle.css') }}" rel="stylesheet">
@endsection

@section('content')
<div class="page-breadcrumb">
    <div class="row">
        <div class="col-7 align-self-center">
            <h4 class="page-title text-truncate text-dark font-weight-medium mb-1">Vendor</h4>
            <div class="d-flex align-items-center">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb m-0 p-0">
                        <li class="breadcrumb-item"><a href="{{ route('vendordashboard') }}" class="text-muted">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('vendor') }}" class="text-muted">Vendor</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">Change Password</li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <form action="{{ route('vendor.change_password.save') }}" name="form" id="form" method="post" enctype="multipart/form-data">
                        @csrf
                        @method('POST')
                        
                      @if(session('message'))
    <div class="alert alert-success">
        {{ session('message') }}
    </div>
@endif

                        <div class="row">
                          
                          
                            <div class="form-group col-sm-5">
                                <label for="password">Password</label>
                                <input type="password" name="new_password" class="form-control" placeholder="Please enter password">
                                <span class="kt-form__help error password"></span>
                            </div>
                        
                         
                       
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn waves-effect waves-light btn-rounded btn-outline-primary">Submit</button>
                            <a href="{{ route('vendor') }}" class="btn waves-effect waves-light btn-rounded btn-outline-secondary">Cancel</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script src="{{ asset('assets/js/dropify.min.js') }}"></script>
<script src="{{ asset('assets/js/promise.min.js') }}"></script>
<script src="{{ asset('assets/js/sweetalert2.bundle.js') }}"></script>

<script>
    $(document).ready(function(){
        $("#contact_number").keypress(function(e){
            var keyCode = e.keyCode || e.which;
            var $this = $(this);
            //Regex for Valid Characters i.e. Numbers.
            var regex = new RegExp("^[0-9\b]+$");

            var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
            // for 10 digit number only
            if ($this.val().length > 9) {
                e.preventDefault();
                return false;
            }
            if (e.charCode < 54 && e.charCode > 47) {
                if ($this.val().length == 0) {
                    e.preventDefault();
                    return false;
                } else {
                    return true;
                }
            }
            if (regex.test(str)) {
                return true;
            }
            e.preventDefault();
            return false;
        });
    });
</script>
<script>
    // $(document).ready(function(){
    //     $('.dropify').dropify({
    //         messages: {
    //             'default': 'Drag and drop profile image here or click',
    //             'remove':  'Remove',
    //             'error':   'Ooops, something wrong happended.'
    //         }
    //     });

    //     var drEvent = $('.dropify').dropify();

    //     var dropifyElements = {};
    //     $('.dropify').each(function () {
    //         dropifyElements[this.id] = false;
    //     });

    //     drEvent.on('dropify.beforeClear', function(event, element){
    //         id = event.target.id;
    //         if(!dropifyElements[id]){
    //             var url = "";
    //             <?php if(isset($data) && isset($data->id)){ ?>
    //                 var id_encoded = "{{ base64_encode($data->id) }}";

    //                 Swal.fire({
    //                     title: 'Are you sure want delete this image?',
    //                     text: "",
    //                     type: 'warning',
    //                     showCancelButton: true,
    //                     confirmButtonColor: '#3085d6',
    //                     cancelButtonColor: '#d33',
    //                     confirmButtonText: 'Yes'
    //                 }).then(function (result){
    //                     if (result.value){
    //                         $.ajax({
    //                             url: url,
    //                             type: "POST",
    //                             data:{
    //                                 id: id_encoded,
    //                                 _token: "{{ csrf_token() }}"
    //                             },
    //                             dataType: "JSON",
    //                             success: function (data){
    //                                 if(data.code == 200){
    //                                     Swal.fire('Deleted!', 'Deleted Successfully.', 'success');
    //                                     dropifyElements[id] = true;
    //                                     element.clearElement();
    //                                 }else{
    //                                     Swal.fire('', 'Failed to delete', 'error');
    //                                 }
    //                             },
    //                             error: function (jqXHR, textStatus, errorThrown){
    //                                 Swal.fire('', 'Failed to delete', 'error');
    //                             }
    //                         });
    //                     }
    //                 });

    //                 return false;
    //             <?php } else { ?>
    //                 Swal.fire({
    //                     title: 'Are you sure want delete this image?',
    //                     text: "",
    //                     type: 'warning',
    //                     showCancelButton: true,
    //                     confirmButtonColor: '#3085d6',
    //                     cancelButtonColor: '#d33',
    //                     confirmButtonText: 'Yes'
    //                 }).then(function (result){
    //                     if (result.value){
    //                         Swal.fire('Deleted!', 'Deleted Successfully.', 'success');
    //                         dropifyElements[id] = true;
    //                         element.clearElement();
    //                     }else{
    //                         Swal.fire('Cancelled', 'Discard Last Operation.', 'error');
    //                     }
    //                 });
    //                 return false;
    //             <?php } ?>
    //         } else {
    //             dropifyElements[id] = false;
    //             return true;
    //         }
    //     });
    // });
</script>

<script>
    $(document).ready(function() {
        var form = $('#form');
        $('.kt-form__help').html('');
        form.submit(function(e) {
            $('.help-block').html('');
            $('.m-form__help').html('');
            $.ajax({
                url: form.attr('action'),
                type: form.attr('method'),
                data: new FormData($(this)[0]),
                dataType: 'json',
                async: false,
                processData: false,
                contentType: false,
                success: function(json) {
                    return true;
                },
                error: function(json) {
                    if (json.status === 422) {
                        e.preventDefault();
                        var errors_ = json.responseJSON;
                        $('.kt-form__help').html('');
                        $.each(errors_.errors, function(key, value) {
                            $('.' + key).html(value);
                        });
                    }
                }
            });
        });
    });
</script>
@endsection