@extends('layouts.app')

@section('content')
    <section class="page-header row">
        <h2> Amazon Test Orders </h2>
        <ol class="breadcrumb">
            <li><a href="{{ url('') }}"> Dashboard </a></li>
            <li class="active"> Amazon Test Orders </li>
        </ol>
    </section>

    <div class="page-content row">
        <div class="page-content-wrapper no-margin">
            <div class="sbox">
                <div class="sbox-content">
                    <form id="uploaderForm" action="{{ url('/amazon-test-orders/upload') }}" method="POST" enctype="multipart/form-data">
                        <div class="row">
                            <div class="col-md-12">
                                <label for="report_type"> Upload File </label>
                                <br>
                                <input type="file" name="file" id="file" placeholder="Select File" required>
                            </div>
                            <button type="submit" class="btn btn-primary m">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    @if ($files && !empty($files))
        <div class="page-content row">
            <div class="page-content-wrapper no-margin">
                <div class="sbox">
                    <div class="sbox-content">
                        <div class="table-responsive">
                            <table class="table table-striped table-hover" id="filesTable">
                                <thead>
                                <tr>
                                    <th style="width: 10% !important;">{{ __('core.btn_action') }}</th>
                                    <th>File Name</th>
                                    <th>Size</th>
                                    <th>Last Modified</th>
                                </tr>
                                </thead>

                                <tbody>
                                @foreach($files as $file)
                                    <tr>
                                        <td>
                                            <div class="actions">
                                                <ul class="actions-menu" style="    list-style-type: none;margin: 0;padding-left: 0;">
                                                    <li>
                                                        <a href="#" onclick="DeleteFile('{{ $file['original'] }}')"
                                                           data-toggle="tooltip"
                                                           class="tips btn btn-sm btn-danger btn-fs"
                                                           title="{{ __('core.btn_remove') }}">
                                                            <i class="fa fa-trash"></i>
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td><a href="{{ $file['url'] }}" target="_blank">{{ $file['filename'] }}</a></td>
                                        <td>{{ $file['size'] }}</td>
                                        <td>{{ date('Y-m-d H:i:s', $file['last_modified']) }}</td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    @endif

    <script>
        function DeleteFile(file) {
            if (confirm('Are you sure you want to delete this row?')) {
                $.ajax({
                    type: 'DELETE',
                    data: {
                        file: file
                    },
                    url: 'amazon-test-orders/delete',
                    success: function () {
                        window.location.reload();
                    }
                });
            }
        }
    </script>
@endsection