@extends ('layouts/template')

@section('content')

    <div class="p-3 mcp-theme-1">
    <div class="card">

        <div class="card-header px-2 py-1 d-flex align-items-center">
            <strong class="">
                <i class="fas fa-user"></i>
                Handouts
            </strong>
            <span class="mx-2 text-secondary">|</span>
            <div moe>
                <a start show>Add</a>
                <form url="/api/handout/create">
                    <div class="mb-2">
                        <label class="mb-1 text-secondary text-sm">Internal Name *</label>
                        <input type="text" class="form-control form-control-sm"
                               name="internalName" required>
                    </div>
                    <div class="mb-2">
                        <label class="mb-1 text-secondary text-sm">Display Name *</label>
                        <input type="text" class="form-control form-control-sm"
                               name="displayName" required>
                    </div>
                    <div class="mb-2">
                        <label class="mb-1 text-secondary text-sm">Tags</label>
                        <input type="text" class="form-control form-control-sm"
                               name="tags">
                    </div>
                    <div class="mb-2">
                        <label class="mb-1 text-secondary text-sm">PDF</label>
                        <input type="file" accept="application/pdf" class="form-control form-control-sm"
                               name="pdfFile">
                    </div>
                    <div class="form-group m-0">
                        <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
                        <button cancel class="btn btn-default border btn-sm mr-2">Cancel</button>
                    </div>
                </form>
            </div>
        </div>
        <div class="card-body p-0">
            <table class="table table-sm table-striped p-0 m-0">
                <thead class="bg-light">
                <tr>
                    <th class="border-0"></th>
                    <th class="border-0">Display Name</th>
                    <th class="border-0">Internal Name</th>
                    <th class="border-0">Tags</th>
                    <th class="border-0">PDF</th>
                    <th class="border-0 w-25">&nbsp;</th>
                </tr>
                </thead>
                <tbody>
                @foreach($handouts as $handout)
                    <tr class="{{$handout->is_active ? '' : 'bg-light text-secondary'}}">
                        <td>
                            <img width="50" src="/api/handout/download-thumbnail/{{ $handout->uid }}" alt="{{$handout->display_name}}"  onerror="if (this.src != '/img/pdf.png') this.src = '/img/pdf.png';">
                        </td>
                        <td>{{ $handout->display_name }}</td>
                        <td>{{ $handout->internal_name }}</td>
                        <td>{{ $handout->tags }}</td>
                        <td>
                            <a class="pdf-viewer-trigger" native target="_blank"
                               href="/api/handout/download/{{ $handout->uid }}"
                               title="View">View</a>
                        </td>
                        <td>
                            <div class="d-flex align-items-center">
                                <div moe relative>
                                    <a start show>Edit</a>
                                    <form url="/api/handout/updateBasic" right>
                                        <input type="hidden" name="uid" value="{{$handout->uid}}">
                                        <div class="mb-2">
                                            <label class="mb-1 text-secondary text-sm">Internal Name *</label>
                                            <input type="text" class="form-control form-control-sm"
                                                   name="internalName" value="{{$handout->internal_name}}" required>
                                        </div>
                                        <div class="mb-2">
                                            <label class="mb-1 text-secondary text-sm">Display Name *</label>
                                            <input type="text" class="form-control form-control-sm"
                                                   name="displayName" value="{{$handout->display_name}}" required>
                                        </div>
                                        <div class="mb-2">
                                            <label class="mb-1 text-secondary text-sm">Tags</label>
                                            <input type="text" class="form-control form-control-sm"
                                                   name="tags" value="{{$handout->tags}}">
                                        </div>
                                        <div class="form-group m-0">
                                            <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
                                            <button cancel class="btn btn-default border btn-sm mr-2">Cancel</button>
                                        </div>
                                    </form>
                                </div>
                                <span class="mx-2 text-secondary">|</span>
                                @if($handout->is_active)
                                    <div moe relative="">
                                        <a start show class="py-0 mb-3">Deactivate</a>
                                        <form url="/api/handout/deactivate" class="mcp-theme-1" right="">
                                            <input type="hidden" name="uid" value="{{$handout->uid}}">
                                            <p>Deactivate this handout?</p>
                                            <div>
                                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                            </div>
                                        </form>
                                    </div>
                                @else
                                    <div moe relative="">
                                        <a start show class="py-0 mb-3">Reactivate</a>
                                        <form url="/api/handout/reactivate" class="mcp-theme-1" right="">
                                            <input type="hidden" name="uid" value="{{$handout->uid}}">
                                            <p>Reactivate this handout?</p>
                                            <div>
                                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                            </div>
                                        </form>
                                    </div>
                                @endif
                            </div>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
    </div>

@endsection
