@include('header')
<div class="container-fluid flex-grow-1 container-p-y">
    <h4 class="font-weight-bold py-3 mb-0">Update Vendor</h4>

    <form id="validation-form" method="POST" action="">

        <input type="hidden" name="action" id="action" value="Edit">
        <input type="hidden" name="saveid" id="saveid" value="{{$data->id}}">
        @csrf
        <div class="card mb-12 mb-4">
            <div class="card-body">
                <div class="row">


                  
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="floating-label" for="Name">Vendor Name <span
                                    class="text-danger">*</span></label>
                            <input type="text" class="form-control" name="VedName" id="VedName" placeholder=""
                                value="{{$data->VedName}}">
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="floating-label" for="Name">Phone </label>
                            <input type="text" class="form-control" name="Phone" id="Phone" placeholder=""
                                value="{{$data->Phone}}">
                        </div>
                    </div>


                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="floating-label" for="Name">Email Id </label>
                            <input type="email" class="form-control" name="EmailId" id="EmailId" placeholder=""
                                value="{{$data->EmailId}}">
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="floating-label" for="Name">Address </label>
                            <textarea class="form-control" name="Address" id="Address" placeholder="">{{$data->Address}}</textarea>
                        </div>
                    </div>
                    
                    <div class="col-sm-6" style="padding-top:20px;">
                        <button class="btn btn-primary" type="submit" name="submit" id="submit">Save</button>
                       
                    </div><br>
                    

                    <input type="hidden" id="CurrDate" value="{{date('Y-m-d')}}">

                </div>
            </div>



    </form>


</div>

<script src="{{url('assets/js/jquery-3.6.0.min.js')}}"></script>
@include('footerscript')
<script>
   
function success_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.notice({
        title: 'Success',
        message: 'Vendor Details Updated Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}

function error_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.error({
        title: 'Error',
        message: 'Record Not Saved',
        location: isRtl ? 'tl' : 'tr'
    });
}

$(document).ready(function() {
    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "{{ url('saveNewVendor') }}",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit').attr('disabled', 'disabled');
                    $('#submit').text('Please Wait...');
                },
                success: function(data) {
                    if (data == 1) {
                        success_toast();
                        window.location.href = "{{ url('vendors') }}";
                    } else {
                        error_toast();
                    }
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Save');
                }
            });
        }
    });




});
</script>