@extends('layouts.app')
@section('content')

<div class="row">
    <div class="col-sm-3">
        @include('side_menu')
    </div>
    <div class="col-sm-9">
        <div class="row">
            <div class="col-sm-12 add-container">
                <form action="/circular/save" method="post" class="add-form">
                    <div class="container">
                        <div class="row">
                            @csrf
                            @if ($errors->any())
                            <div class="alert alert-danger" role="alert">
                                Please fix the following errors
                            </div>
                            @endif
                            @if($selectedCircular != null)
                            <input type="hidden" id="selected_circular" name="selected_circular" value="{{$selectedCircular->src_circular_id}}" />
                            @endif
                            <div class="col-sm-9">
                                <div class="form-group">
                                    <label for="subject">Subject</label>
                                    <input type="text" class="form-control @error('subject') is-invalid @enderror" id="subject" name="subject" placeholder="Subject" value="@if($selectedCircular != null){{$selectedCircular->subject}}@else{{ old('subject') }}@endif">
                                    @error('subject')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-9">
                                <div class="form-group">
                                    <label for="ref_no">Reference Number</label>
                                    <input type="text" class="form-control @error('ref_no') is-invalid @enderror" id="ref_no" name="ref_no" placeholder="Reference Number" value="@if($selectedCircular != null){{$selectedCircular->ref_no}}@else{{ old('ref_no') }}@endif">
                                    @error('ref_no')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-9">
                                <div class="form-group">
                                    <label for="ref_no">Date Issued</label>
                                    <input type="text" class="form-control @error('date_issued') is-invalid @enderror" id="date_issued" name="date_issued" placeholder="Date Issued" value="@if($selectedCircular != null){{$selectedCircular->date_issued}}@else{{ old('date_issued') }}@endif">
                                    @error('date_issued')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-9">
                                <button type="submit" class="btn btn-primary bt-margin">Save</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="container">
                <div class="row search-mg">
                    <div class="col-md-12 search-col">
                        <button class="btn float-right search-bt" onclick="searchCirculars()">Search</button>
                        <input type="text" class="form-control float-right search-txt" id="search-circular" name="search-circular" placeholder="Search" />
                    </div>
                </div>
                <div class="row t-header">
                    <div class="col-4">Subject</div>
                    <div class="col-4">Ref No.</div>
                    <div class="col-2">Date Issued</div>
                    <div class="col-2"></div>
                </div>
                <div id="circulars-data">
                    @foreach ($circulars as $circular)
                    <div class="row t-content">
                        <div class="col-4">
                            {!! $circular->subject !!}
                        </div>
                        <div class="col-4">
                            {{ $circular->ref_no }}
                        </div>
                        <div class="col-2">
                            {{ date("d-m-Y", strtotime($circular->date_issued)) }}
                        </div>
                        <div class="col-2 edit-butts">
                            <span>
                                <a href="/circular/edit/{{$circular->src_circular_id}}">
                                    <img src="/images/edit.png" width="15px" alt="Edit" />
                                </a>
                                <button rel="{{$circular->src_circular_id}}" class="btn delcircular" data-toggle="modal" data-target="#circularsModal">
                                    <img src="/images/delete.png" width="15px" alt="Delete" />
                                </button>
                            </span>
                        </div>
                    </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="circularsModal" tabindex="-1" role="dialog" aria-labelledby="circularsModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="circularsModalLabel">Confirm Delete</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    Are you sure you would like to delete the selected circular?
                </div>
                <div class="modal-footer">
                    <div class="row" style="width:100%">
                        <div class="col-8">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                        </div>
                        <div class="col-4">
                            <form action="/circular/del" method="post">
                                @csrf
                                <input type="hidden" id="del-circular" name="deletecircular" />
                                <button type="submit" class="btn btn-primary">Confirm</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @endsection