@extends('admin.master')
@section('title') Owner Details | SHOP @endsection
@section('shop-owner') active @endsection
@section('styles')

@section('main_content_section')
<div class="container-fluid p-0">
    <div class=" d-flex align-items-center justify-content-between my-3">
        <div class="d-flex align-items-center">
            <h3 class="mb-0 pb-0">Owner Details</h3>
        </div>
    </div>

    <div class="row">

        @include('admin.shop.profile.partials.sidebar')

        <div class="col-md-8 mb-2">
            <div class="h-100 border-0">

                @include('admin.shop.profile.partials.header')

                <div class="table_data rounded p-0 mt-3">
                    <div class="card shadow">
                        <div class="card border-0">
                            <div class="card-header border-0">
                                <div
                                    class=" d-flex justify-content-between align-items-center aggregate-section border px-3 py-1">
                                    <div class="d-flex align-items-center">
                                        <p class="mb-0">
                                            <a href="{{route('shop-profile',$singleShopData->id)}}"
                                                class="text-primary py-2 px-3 active">All(0)</a>
                                        </p>
                                    </div>
                                    <div class="d-none d-sm-block">
                                        @if(Auth::user()->can('shop-create'))
                                        <a href="javascript:void(0)"
                                            class="btn btn-success rounded-0 d-flex align-items-center px-2 border-0"
                                            data-bs-toggle="modal" data-bs-target="#addPayment"><span class="">New
                                                Payment</span></a>
                                        @endif
                                    </div>
                                </div>

                                @if(Auth::user()->can('shop-create'))
                                <div class="mt-2 btn btn-success d-block rounded-0 d-sm-none" data-bs-toggle="modal"
                                    data-bs-target="#addPayment">
                                    New Payment</div>
                                @endif
                            </div>


                            <div id="card_body_1" class="card-body">
                                <div class="">
                                    <section class="row">
                                        <div class="col-lg-12 table-responsive">
                                            <table class="table table-bordered table-striped">
                                                <thead>
                                                    <tr>
                                                        <th scope="col"><span>Customer</span></th>
                                                        <th scope="col"><span>Address</span></th>
                                                        <th scope="col"><span>Visiting Card</span></th>
                                                        <th scope="col"><span>Status</span></th>
                                                    </tr>
                                                </thead>
                                                <tbody>

                                                    <?php $i = 1; ?>
                                                    @foreach ($shopPaymentData as $customer)
                                                    @if(isset($customer) && $customer != null)
                                                    <tr>
                                                    
                                                        <td>
                                                            <strong>Name: </strong> {{ $customer->customer_name }}<br>
                                                            <strong>Email: </strong> {{ $customer->customer_email }} <br>
                                                            <strong>Mobile: </strong> {{ $customer->customer_mobile_1 }} <br>
                                                    
                                                            <div class="row-actions">
                                                    
                                                                <span><a href="javascript:void(0)" class="text-primary fw-bolder" data-bs-toggle="modal"
                                                                        data-bs-target="#editContact{{$customer->id}}"><span class="">Edit</span></a>
                                                                </span>
                                                    
                                                                @if($customer->status == true)
                                                                <span>
                                                                    | <a class="text-danger fw-bolder" href="{{route('customer-inactive',$customer->id)}}">Inactive</a>
                                                                </span>
                                                                @else
                                                                <span>
                                                                    | <a class="text-success fw-bolder" href="{{route('customer-active',$customer->id)}}">Active</a>
                                                                </span>
                                                                @endif
                                                    
                                                            </div>
                                                    
                                                        </td>
                                                        <td> {{ $customer->post }}</td>
                                                    
                                                        <td>
                                                            @if(isset($customer->visiting_card) && $customer->visiting_card != null)
                                                            <a href="{{ asset('uploads/visiting_card/'.$customer->visiting_card ) }}" data-rel="lightcase">
                                                                <img src="{{asset('uploads/visiting_card/'.$customer->visiting_card)}}" height="60" width="80"
                                                                    id="myImgVisifront">
                                                            </a>
                                                            @else
                                                            <a href="{{ asset('backend/template-assets/') }}/images/img_preview.png" data-rel="lightcase">
                                                                <img src="{{ asset('backend/template-assets/') }}/images/img_preview.png"
                                                                    style="height: 60px; width: 80px;">
                                                            </a>
                                                            @endif
                                                    
                                                            @if(isset($customer->back_card) && $customer->back_card != null)
                                                            <a href="{{ asset('uploads/back_card/'.$customer->back_card ) }}" data-rel="lightcase">
                                                                <img src="{{asset('uploads/back_card/'.$customer->back_card)}}" height="60" width="80" id="myImgVisiback">
                                                            </a>
                                                            @else
                                                            <a href="{{ asset('backend/template-assets/') }}/images/img_preview.png" data-rel="lightcase">
                                                                <img src="{{ asset('backend/template-assets/') }}/images/img_preview.png"
                                                                    style="height: 60px; width: 80px;">
                                                            </a>
                                                            @endif
                                                        </td>
                                                    
                                                        <td>
                                                            @if($customer->status == true)
                                                            <span class="badge bg-success">Active</span>
                                                            @else
                                                            <span class="badge bg-danger">Inactive</span>
                                                            @endif
                                                        </td>
                                                    
                                                    </tr>
                                                    
                                                    
                                                    <!-- edit contact -->
                                                    <div class="modal fade" id="editContact{{$customer->id}}" tabindex="-1" aria-labelledby="oneInputModalLabel"
                                                        aria-hidden="true" data-bs-backdrop="static">
                                                        <div class="modal-dialog modal-dialog-centered max-width-900px">
                                                            <div class="modal-content">
                                                                <div class="modal-header">
                                                                    <h1 class="modal-title fs-5" id="oneInputModalLabel">Update Contact</h1>
                                                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                                </div>
                                                                <form action="{{route('customer.update',$customer->id)}}" method="post" enctype="multipart/form-data">
                                                                    @csrf
                                                    
                                                                    <input type="hidden" class="form-control" name="lead_id" value="{{$lead->id}}">
                                                    
                                                                    <div class="modal-body p-0">
                                                                        <div class="row px-4 my-4">
                                                                            <div class="col-md-6 mb-3">
                                                                                <div class="form-group">
                                                                                    <label for="customer_name">Name <span class="text-danger">(required)</span>
                                                                                    </label>
                                                                                    <input type="text" name="customer_name" required class="form-control form-control-solid"
                                                                                        value="{{ $customer->customer_name }}" placeholder="Name">
                                                                                </div>
                                                    
                                                                                @error('customer_name')
                                                                                <span class=text-danger>{{$message}}</span>
                                                                                @enderror
                                                                            </div>
                                                    
                                                                            <div class="col-md-6 mb-3">
                                                                                <div class="form-group">
                                                                                    <label for="mobile_1">Email
                                                                                    </label>
                                                                                    <input type="email" name="customer_email" id="customer_email"
                                                                                        class="form-control form-control-solid" value="{{ $customer->customer_email }}"
                                                                                        placeholder="Email">
                                                                                </div>
                                                    
                                                                                @error('customer_email')
                                                                                <span class=text-danger>{{$message}}</span>
                                                                                @enderror
                                                                            </div>
                                                    
                                                                            <div class="col-md-6 mb-3">
                                                                                <div class="form-group">
                                                                                    <label for="customer_mobile_1">Mobile 1<span class="text-danger">(required)</span>
                                                                                    </label>
                                                                                    <input type="number" name="customer_mobile_1" id="customer_mobile_1" required
                                                                                        class="form-control form-control-solid" value="{{ $customer->customer_mobile_1 }}"
                                                                                        placeholder="Mobile Number 1">
                                                                                </div>
                                                    
                                                                                @error('mobile_1')
                                                                                <span class=text-danger>{{$message}}</span>
                                                                                @enderror
                                                                            </div>
                                                    
                                                                            <div class="col-md-6 mb-3">
                                                                                <div class="form-group">
                                                                                    <label for="customer_mobile_2">Mobile 2
                                                                                    </label>
                                                                                    <input type="number" name="customer_mobile_2" id="customer_mobile_2"
                                                                                        class="form-control form-control-solid" value="{{ $customer->customer_mobile_2 }}"
                                                                                        placeholder="Mobile Number 2">
                                                                                </div>
                                                    
                                                                                @error('mobile_1')
                                                                                <span class=text-danger>{{$message}}</span>
                                                                                @enderror
                                                                            </div>
                                                    
                                                                            <div class="com-md-12 mb-3">
                                                                                <div class="form-group">
                                                                                    <label for="post">Address</label>
                                                    
                                                                                    <textarea class="form-control" name="post" id="post" cols="2"
                                                                                        rows="2">{!! $customer->post !!}</textarea>
                                                                                </div>
                                                                            </div>
                                                    
                                                                            <div class="col-md-6 h-100 mb-3">
                                                                                <div class="form-group">
                                                                                    <label for="name">Front Side <span class=" text-danger"></span></label> <br>
                                                                                    <div class=" position-relative custom-soft-setting dropzone">
                                                                                        <div class="select_imgWith_preview py-2">
                                                                                            @if($customer->visiting_card != null)
                                                                                            <img id="uploadPreviewFFU{{$customer->id}}"
                                                                                                src="{{ asset('uploads/visiting_card/'.$customer->visiting_card) }}">
                                                                                            <div id="dropzone-block" class="custom-media-upload-block mt-3">
                                                                                                <span class="dropzone-label fw-bolder">Upload Photo</span>
                                                                                            </div>
                                                                                            @else
                                                                                            <img id="uploadPreviewFFU{{$customer->id}}"
                                                                                                src="{{ asset('backend/template-assets/') }}/images/img_preview.png">
                                                    
                                                                                            <div id="dropzone-block" class="custom-media-upload-block mt-3">
                                                                                                <span class="dropzone-label fw-bolder">Upload Photo</span>
                                                                                            </div>
                                                                                            @endif
                                                    
                                                                                            <input id="uploadImageFFU{{$customer->id}}" type="file" name="visiting_card"
                                                                                                onchange="PreviewImageFP('uploadImageFFU{{$customer->id}}','uploadPreviewFFU{{$customer->id}}');" />
                                                                                        </div>
                                                                                    </div>
                                                    
                                                                                    @error('visiting_card')
                                                                                    <span class=text-danger>{{$message}}</span>
                                                                                    @enderror
                                                                                </div>
                                                                            </div>
                                                    
                                                    
                                                                            <div class="col-md-6 h-100 mb-3">
                                                                                <div class="form-group">
                                                                                    <label for="name">Back Side <span class=" text-danger"></span></label> <br>
                                                                                    <div class=" position-relative custom-soft-setting dropzone">
                                                                                        <div class="select_imgWith_preview py-2">
                                                                                            @if($customer->back_card != null)
                                                                                            <img id="uploadPreviewFBU{{$customer->id}}"
                                                                                                src="{{ asset('uploads/back_card/'.$customer->back_card) }}">
                                                                                            <div id="dropzone-block" class="custom-media-upload-block mt-3">
                                                                                                <span class="dropzone-label fw-bolder">Upload Photo</span>
                                                                                            </div>
                                                                                            @else
                                                                                            <img id="uploadPreviewFBU{{$customer->id}}"
                                                                                                src="{{ asset('backend/template-assets/') }}/images/img_preview.png">
                                                    
                                                                                            <div id="dropzone-block" class="custom-media-upload-block mt-3">
                                                                                                <span class="dropzone-label fw-bolder">Upload Photo</span>
                                                                                            </div>
                                                                                            @endif
                                                    
                                                                                            <input id="uploadImageFBU{{$customer->id}}" type="file" name="back_card"
                                                                                                onchange="PreviewImageFP('uploadImageFBU{{$customer->id}}','uploadPreviewFBU{{$customer->id}}');" />
                                                                                        </div>
                                                                                    </div>
                                                    
                                                                                    @error('back_card')
                                                                                    <span class=text-danger>{{$message}}</span>
                                                                                    @enderror
                                                                                </div>
                                                                            </div>
                                                    
                                                    
                                                                        </div>
                                                                    </div>
                                                                    <div class="modal-footer">
                                                                        <button type="submit" class="btn btn-success"
                                                                            onclick="return checkContactValidate()">Update</button>
                                                                        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    @endif
                                                    @endforeach


                                                </tbody>

                                            </table>
                                        </div>

                                        @if(isset($allShopPaymentCount) && $allShopPaymentCount > 10)
                                        <div class="clearfix d-flex">
                                            <div class="float-left">
                                                <p class="text-muted">
                                                    {{ __('Showing') }}
                                                    <span class="font-weight-bold">{{ $shopPaymentData->firstItem() }}</span>
                                                    {{ __('to') }}
                                                    <span class="font-weight-bold">{{ $shopPaymentData->lastItem() }}</span>
                                                    {{ __('of') }}
                                                    <span class="font-weight-bold">{{ $shopPaymentData->total() }}</span>
                                                    {{ __('results') }}
                                                </p>
                                            </div>

                                            <div class="float-right custom-table-pagination">
                                                {!! $shopPaymentData->links('pagination::bootstrap-4') !!}
                                            </div>
                                        </div>
                                        @endif
                                    </section>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>

        </div>
    </div>
</div>

{{-- //Add new Leads... --}}
<div class="modal fade" id="addPayment" tabindex="-1" aria-labelledby="oneInputModalLabel" aria-hidden="true"
    data-bs-backdrop="static">
    <div class="modal-dialog modal-dialog-centered max-width-900px">
        <div class="modal-content">
            <div class="modal-header">
                <h1 class="modal-title fs-5" id="oneInputModalLabel">Contact Create</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="{{route('shop.create')}}" method="post" enctype="multipart/form-data">
                @csrf

                <input type="hidden" class="form-control" name="lead_id" value="{{$singleShopData->id}}">

                <div class="modal-body p-0">
                    <div class="row px-4 my-4">
                        <div class="col-md-6 mb-3">
                            <div class="form-group">
                                <label for="customer_name">Name <span class="text-danger">(required)</span>
                                </label>
                                <input type="text" name="customer_name" required class="form-control form-control-solid"
                                    value="{{old('customer_name')}}" placeholder="Name">
                            </div>

                            @error('customer_name')
                            <span class=text-danger>{{$message}}</span>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <div class="form-group">
                                <label for="mobile_1">Email
                                </label>
                                <input type="email" name="customer_email" id="customer_email"
                                    class="form-control form-control-solid" value="{{old('customer_email')}}"
                                    placeholder="Email">
                            </div>

                            @error('customer_email')
                            <span class=text-danger>{{$message}}</span>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <div class="form-group">
                                <label for="customer_mobile_1">Mobile 1<span class="text-danger">(required)</span>
                                </label>
                                <input type="number" name="customer_mobile_1" id="customer_mobile_1" required
                                    class="form-control form-control-solid" value="{{old('customer_mobile_1')}}"
                                    placeholder="Mobile Number 1">
                            </div>

                            @error('mobile_1')
                            <span class=text-danger>{{$message}}</span>
                            @enderror
                        </div>

                        <div class="col-md-6 mb-3">
                            <div class="form-group">
                                <label for="customer_mobile_2">Mobile 2
                                </label>
                                <input type="number" name="customer_mobile_2" id="customer_mobile_2"
                                    class="form-control form-control-solid" value="{{old('customer_mobile_2')}}"
                                    placeholder="Mobile Number 2">
                            </div>

                            @error('mobile_1')
                            <span class=text-danger>{{$message}}</span>
                            @enderror
                        </div>


                        <div class="col-md-12 mb-3">
                            <div class="form-group">
                                <label for="address_1">Address
                                </label>

                                <textarea name="post" id="post" cols="10" rows="2" placeholder="Enter Address"
                                    class="form-control form-control-solid"></textarea>
                            </div>

                            @error('post')
                            <span class=text-danger>{{$message}}</span>
                            @enderror
                        </div>

                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success" onclick="return checkContactValidate()">Save</button>
                    <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
                </div>
            </form>
        </div>
    </div>
</div>

@endsection


@section('scripts')

<script>
    $(document).ready(function(){
        $("#project_id").select2({
        dropdownParent: $('#editLeads')
        });
        $("#district_id").select2({
        dropdownParent: $('#editLeads')
        });
        $("#interest").select2({
        dropdownParent: $('#editLeads')
        })
        $("#leadstatus").select2({
        dropdownParent: $('#changeLeadStatus')
        })
    });
</script>

<script>
    function checkContactValidate() {
        var mobileNumber = $("#customer_mobile_1").val();

        if (mobileNumber != '' && mobileNumber.length != 11) { 
            event.preventDefault();
            toastr.error("Customer Mobile number must be 11 digit."); 
        }

        var mobileNumber = $("#customer_mobile_2").val();

        if (mobileNumber != '' && mobileNumber.length != 11) { 
            event.preventDefault();
            toastr.error("Customer Mobile number 2 must be 11 digit."); 
        }

        return true;
    }


    function checkValidate() {
        var mobileNumber = $("#mobile_1").val();

        if (mobileNumber != '' && mobileNumber.length != 11) { 
            event.preventDefault();
            toastr.error("Mobile number must be 11 digit."); 
        }

        var mobileNumber = $("#mobile_2").val();

        if (mobileNumber != '' && mobileNumber.length != 11) { 
            event.preventDefault();
            toastr.error("Mobile number 2 must be 11 digit."); 
        }

        return true;
    }


    //For image preview...
    function PreviewImageFP(selectFile, previewImg) {
        var oFReader = new FileReader();
        oFReader.readAsDataURL(document.getElementById(selectFile).files[0]);

        oFReader.onload = function (oFREvent) {
            document.getElementById(previewImg).src = oFREvent.target.result;
        };
    }

    function cancelPreviewFP(selectFile, previewImg) {
        const img = document.getElementById(previewImg);
        img.src = window.location.origin + "/backend/template-assets/images/img_preview.png";
        $("#" + selectFile).val('');
    }
    

</script>
@endsection