@extends('layouts.layout')

@section('content')
    <div class="main-panel">

        @include('layouts.component.navbar')

        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header card-header-primary">
{{--                                <button onclick="md.showNotification('bottom','center')">asdasd</button>--}}
                                <h4 class="card-title ">View Data @if($dat->count() > 0 )<a href="{{ route('download.data') }}" target="_blank"><button class="btn btn-warning">Download</button></a>@endif</h4>
                            </div>
                            <div class="card-body">

                                <div class="table-responsive">
                                    <table class="table">
                                        <thead class=" text-primary">
                                        <th>
                                            #
                                        </th>
                                        <th>
                                            Date Of Purchase
                                        </th>
                                        <th>
                                            Name
                                        </th>
                                        <th>
                                            User
                                        </th>
                                        <th>
                                            Id
                                        </th>
                                        <th>
                                            Type
                                        </th>
                                        <th>
                                            Action
                                        </th>
                                        </thead>
                                        <tbody>
                                        @forelse($dat as $data)
                                        <tr>
                                            <td>{{ $loop->index + 1 }}</td>
                                            <td>{{ $data->dateOfPurchase }}</td>
                                            <td>{{ $data->name }}</td>
                                            <td>{{ $data->user }}</td>
                                            <td>{{ $data->idSecond }}</td>
                                            <td>{{ $data->type }}</td>
                                            @php
                                                $dataForCode = 'Date Of Purchase: ' . $data->dateOfPurchase . ' | ' . "Name: ". $data->name . ' | ' .  'User : ' . $data->user . ' | Id:' . $data->id;
                                            @endphp
                                            <td>
                                                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#barCode{{ $data->id }}">
                                                    View Bar Code
                                                </button>
                                                <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#cancelBarCode{{ $data->id }}">
                                                    Cancel
                                                </button>
                                                <div class="modal fade" id="cancelBarCode{{ $data->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h5 class="modal-title" id="exampleModalLabel">Cancel</h5>
                                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                    <span aria-hidden="true">&times;</span>
                                                                </button>
                                                            </div>
                                                                <form action="{{ route('cancel.data',['id'=>$data->id]) }}" method="post">
                                                            <div class="modal-body text-center" >
                                                              <h3>Are You sure you want to cancel</h3>
                                                                    @csrf
                                                                    <input type="hidden" name="dataId">
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
                                                                <button type="submit" class="btn btn-danger">Yes</button>
                                                            </div>
                                                                </form>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="modal fade" id="barCode{{ $data->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h5 class="modal-title" id="exampleModalLabel">Barcode</h5>
                                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                    <span aria-hidden="true">&times;</span>
                                                                </button>
                                                            </div>
                                                            <div class="modal-body text-center" >

                                                           
                                                                     {!!  barCodeSvg($data->idSecond,'2d') !!}

      <h3>{{ $data->idSecond }}</h3>

                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                        @empty
                                            <tr>
                                                <td colspan="7" class="text-center"><h3>No Data Found</h3></td>
                                            </tr>
                                        @endforelse
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        @include('layouts.component.footer')
        @section('page-script')
            @endsection
    </div>
@endsection
