<div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
        {!! Form::open(['route' => ['vrc.appointments.update', $appointment->id], 'method' => 'PUT', 'class' => 'vrc-form vrc-appt-form']) !!}
        <div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">@lang('messages.edit') — @lang('vrc::lang.appointment')</h4></div>
        <div class="modal-body">
            @include('vrc::appointments._fields')
            <hr>
            <div class="btn-group">
                <button type="button" class="btn btn-sm btn-success vrc-appt-action" data-action="confirm" data-id="{{ $appointment->id }}"><i class="fa fa-check"></i> @lang('vrc::lang.confirm')</button>
                <button type="button" class="btn btn-sm btn-primary vrc-appt-action" data-action="check-in" data-id="{{ $appointment->id }}"><i class="fa fa-sign-in"></i> @lang('vrc::lang.check_in')</button>
                <button type="button" class="btn btn-sm btn-default vrc-appt-action" data-action="no-show" data-id="{{ $appointment->id }}"><i class="fa fa-user-times"></i> @lang('vrc::lang.no_show')</button>
                <button type="button" class="btn btn-sm btn-danger vrc-appt-action" data-action="cancel" data-id="{{ $appointment->id }}"><i class="fa fa-ban"></i> @lang('messages.cancel')</button>
            </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary">@lang('messages.update')</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">@lang('messages.close')</button>
        </div>
        {!! Form::close() !!}
    </div>
</div>
<script>
$(document).off('click.vrcApptAction').on('click.vrcApptAction', '.vrc-appt-action', function () {
    var action = $(this).data('action'), id = $(this).data('id');
    var url = '{{ url('vrc/appointments') }}/' + id + '/' + action;
    var data = { _token: $('meta[name=csrf-token]').attr('content') };
    if (action === 'cancel' || action === 'no-show') {
        data.reason = window.prompt('{{ __('vrc::lang.reason') }}:') || '';
    }
    $.post(url, data, function (resp) {
        if (resp.success) {
            toastr.success(resp.msg);
            $('.vrc_modal').modal('hide');
            if (window.vrcReloadTables) window.vrcReloadTables();
            if (resp.redirect) window.location = resp.redirect;
        } else { toastr.error(resp.msg || 'Error'); }
    }).fail(function () { toastr.error('Error'); });
});
</script>
