@extends('layouts.master')
@section('content')
    <div class="az-content-breadcrumb">
        <span>Supplier</span>
        <span>Edit Supplier</span>
    </div>
    <h2 class="az-content-title" style="display: inline">Edit Supplier
        <span> <a href="{{ route('supplier.list') }}" class="btn border" style="float: right"><i
                    class="fa-solid fa-bars-staggered"></i>
                Back to Supplier
            </a></span>
    </h2>

    <div class="row">
        <div class="col-md-12 col-lg-12 col-xl-12">
            <div class="card card-body pd-40">
                <h5 class="card-title mg-b-20">Edit Supplier Details</h5>
                <form method="POST" action="{{ route('supplier.update', \Crypt::encrypt($edit->id_supplier)) }}">
                    @csrf
                    @if (count($errors) > 0)
                        <div class="p-1">
                            @foreach ($errors->all() as $error)
                                <div class="alert alert-warning alert-danger fade show" role="alert">{{ $error }}
                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                            @endforeach
                        </div>
                    @endif

                    <div class="row row-sm mg-b-20">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label class="">Opening Balance Date <span style="color:red;">*</span></label>
                                <input type="text" id="opening_date" value="{{ $edit->opening_date }}"
                                    name="supplier_opening_date" class="form-control" placeholder="dd/mm/yyyy" />
                                {{-- <input type="date" name="opening_date" value="{{ $edit->opening_date }}" --}}
                                {{-- class="form-control" /> --}}
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label class="">Supplier Name (English) <span style="color:red;">*</span></label>
                                <input type="text" name="supplier_name" value="{{ $edit->supplier_name }}"
                                    class="form-control" required />
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label class="" style="float: inline-end;">کھا تہ </label>
                                <input type="text" name="supplier_name_urdu" value="{{ $edit->supplier_name_urdu }}"
                                    class="form-control" id="supplier_name_urdu" dir="rtl" />
                            </div>
                        </div>
                    </div>

                    <div class="row row-sm mg-b-20">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Email <span style="color:red;">*</span></label>
                                <input type="text" name="email" value="{{ $edit->supplier_email }}"
                                    class="form-control" />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Contact Person</label>
                                <input type="text" name="contact_person" value="{{ $edit->contact_person }}"
                                    class="form-control" />
                            </div>
                        </div>
                    </div>

                    <div class="row row-sm mg-b-20">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Address (English)</label>
                                <input type="text" name="address" value="{{ $edit->supplier_address }}"
                                    class="form-control" />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label style="float: inline-end;"> گاہک کا پتہ </label>
                                <input type="text" name="supplier_address_urdu"
                                    value="{{ $edit->supplier_address_urdu }}" class="form-control"
                                    id="supplier_address_urdu" />
                            </div>
                        </div>
                    </div>

                    <div class="row row-sm mg-b-20">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Phone 1</label>
                                <input type="text" name="phone_1" value="{{ $edit->phone_1 }}" class="form-control" />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Phone 2</label>
                                <input type="text" name="phone_2" value="{{ $edit->phone_2 }}" class="form-control" />
                            </div>
                        </div>
                    </div>

                    <div class="row row-sm mg-b-20">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Website</label>
                                <input type="text" name="website" value="{{ $edit->website }}" class="form-control" />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Status</label>
                                <select class="form-control" name="status">
                                    <option value="0" {{ $edit->status == 0 ? 'selected' : '' }}>Active</option>
                                    <option value="1" {{ $edit->status == 1 ? 'selected' : '' }}>In-Active</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="row row-sm mg-b-20">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Opening Balance Dr</label>
                                <input type="text" name="blance_dr" value="{{ $edit->opening_bal_dr }}"
                                    class="form-control" />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="">Opening Balance Cr</label>
                                <input type="text" name="blance_cr" value="{{ $edit->opening_bal_cr }}"
                                    class="form-control" />
                            </div>
                        </div>

                    </div>

                    <a href="{{ route('supplier.list') }}" class="btn btn-danger btn-block mt-2">Cancel</a>
                    <button type="submit" class="btn btn-az-primary btn-block mt-2" style="float: right">Update</button>
                </form>
            </div>
        </div>
    </div>
@endsection

@push('scripts')
    <script>
        $(document).ready(function() {
            $("#opening_date").datepicker({
                dateFormat: "yy-mm-dd" // You can customize the date format here
            });
        });


        // document.getElementById('supplier_name_urdu').addEventListener('input', function(e) {
        //     var urduPattern = /[\u0600-\u06FF\u0750-\u077F ]/g;
        //     var inputValue = e.target.value;
        //     e.target.value = inputValue.replace(/[^\u0600-\u06FF\u0750-\u077F ]/g, '');
        // });

        // document.getElementById('supplier_address_urdu').addEventListener('input', function(e) {
        //     var urduPattern = /[\u0600-\u06FF\u0750-\u077F ]/g;
        //     var inputValue = e.target.value;
        //     e.target.value = inputValue.replace(/[^\u0600-\u06FF\u0750-\u077F ]/g, '');
        // });
    </script>
@endpush
