@extends('layouts.master')

@section('navigation')
    @if (Auth::user()->role == 1)
        @include('local.managers.admins._new_navigation')
    @elseif(Auth::user()->role == 2)
        @include('local.managers.sCoords._new_navigation')
    @elseif(Auth::user()->role == 3)
        @include('local.managers.pCoords._new_navigation')
    @endif
@stop

@section('main')
    <div class="row">
        <div class="table-responsive">
            <table class="table table-bordered datatable">
                <thead>
                    <tr>
                        <th class="active col-sm-2 col-md-2">Program</th>
                        <th class="active col-sm-2 col-md-2">School</th>
                        @foreach ($quinquenniums as $quinquennium)
                            <th class="active">
                                {{ date('Y', strtotime($quinquennium->start_date)) }}-{{ date('Y', strtotime($quinquennium->end_date)) }}
                                Quinquennium</th>
                        @endforeach
                    </tr>
                </thead>
                @foreach ($programs as $program)
                    <tr>
                        <th class="active col-sm-2 col-md-2"> {{ $program->name }} </th>
                        <td class="col-sm-2 col-md-2"> {{ $program->school->name }} </td>
                        @foreach ($quinquenniums as $quinquennium)
                            <td>
                                <?php $five_year_plan = FiveYearPlan::where('program_id', $program->id)
                                    ->where('quinquennium_id', $quinquennium->id)
                                    ->first(); ?>
                                @if ($five_year_plan)
                                    <a class="btn btn-sm btn-default"
                                        href="{{ URL::action('FiveYearPlansController@show', [$program->id, $five_year_plan->id]) }}">
                                        <span class="glyphicon glyphicon-eye-open"></span>
                                        View
                                    </a>
                                    @if (date('Y-m-d') <= $current_quinquennium->five_year_plan_due_date)
                                        <a class="btn btn-sm btn-default"
                                            href="{{ URL::action('FiveYearPlansController@edit', [$program->id, $five_year_plan->id]) }}">
                                            <span class="glyphicon glyphicon-pencil"></span>
                                            Edit
                                        </a>
                                    @endif
                                @elseif($quinquennium->id == $current_quinquennium->id && // Quinquennium is running
                                date('Y-m-d') >= $current_quinquennium->start_date && // Current date
                                    date('Y-m-d') <= $current_quinquennium->end_date)
                                    <a class="btn btn-sm btn-default"
                                        href="{{ URL::action('FiveYearPlansController@create', [$program->id]) }}">
                                        <span class="glyphicon glyphicon-plus"></span>
                                        Create
                                    </a>
                                @elseif($current_quinquennium->start_date < $quinquennium->start_date)
                                    Available {{ date('M/d/Y', strtotime($quinquennium->start_date)) }}
                                @else
                                    Plan not available
                                @endif
                            </td>
                        @endforeach
                    </tr>
                @endforeach
            </table>
        </div>
    </div>
@stop

@section('included-js')

@stop

@section('javascript')

    table = $('.datatable').dataTable({
    "columnDefs": [
    { "searchable": true, "sortable": true, "targets": [0, 1]},
    ]
    });

    $('a.toggle-vis').on('click', function (e) {
    e.preventDefault();

    // Get the column API object
    var column = table.column( $(this).attr('data-column') );

    // Toggle the visibility
    column.visible( ! column.visible() );
    } );

@stop
