@extends('layouts.app')
@section('title', __('Days off'))

@section('content')
<h1 class="h4 fw-bold mb-3">{{ __('Days off & extra hours') }}</h1>

<div class="row g-3">
    <div class="col-lg-4">
        <div class="mb-card p-4">
            <form method="POST" action="{{ route('tenant.exceptions.store') }}">
                @csrf
                <div class="mb-3">
                    <label class="form-label">{{ __('Dentist') }}</label>
                    <select name="dentist_id" class="form-select">
                        <option value="">{{ __('Whole clinic') }}</option>
                        @foreach($dentists as $d)
                            <option value="{{ $d->id }}" @selected(old('dentist_id') == $d->id)>{{ $d->name }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="mb-3">
                    <label class="form-label">{{ __('Date') }}</label>
                    <input type="date" name="date" value="{{ old('date') }}" class="form-control @error('date') is-invalid @enderror" required>
                    @error('date')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
                <div class="mb-3">
                    <label class="form-label">{{ __('Type') }}</label>
                    <select name="type" class="form-select">
                        <option value="off">{{ __('Day off / closure') }}</option>
                        <option value="extra">{{ __('Extra working hours') }}</option>
                    </select>
                </div>
                <div class="row">
                    <div class="col-6 mb-3">
                        <label class="form-label">{{ __('From') }}</label>
                        <input type="time" name="start_time" value="{{ old('start_time') }}" class="form-control @error('start_time') is-invalid @enderror">
                        @error('start_time')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                    <div class="col-6 mb-3">
                        <label class="form-label">{{ __('To') }}</label>
                        <input type="time" name="end_time" value="{{ old('end_time') }}" class="form-control @error('end_time') is-invalid @enderror">
                        @error('end_time')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>
                <p class="mb-muted small">{{ __('Leave times empty on a day off to block the whole day.') }}</p>
                <div class="mb-3">
                    <input name="reason" value="{{ old('reason') }}" class="form-control" placeholder="{{ __('Reason (optional)') }}">
                </div>
                <button class="btn mb-btn-primary w-100">{{ __('Add') }}</button>
            </form>
        </div>
    </div>

    <div class="col-lg-8">
        <div class="mb-card p-3">
            <table class="table mb-table align-middle mb-0">
                <thead><tr><th>{{ __('Date') }}</th><th>{{ __('Dentist') }}</th><th>{{ __('Type') }}</th><th>{{ __('Hours') }}</th><th>{{ __('Reason') }}</th><th></th></tr></thead>
                <tbody>
                @forelse($exceptions as $e)
                    <tr>
                        <td>{{ $e->date->format('D, d M Y') }}</td>
                        <td>{{ $e->dentist?->name ?? __('Whole clinic') }}</td>
                        <td><span class="badge text-bg-{{ $e->type === 'off' ? 'secondary' : 'info' }}">{{ $e->type === 'off' ? __('Off') : __('Extra') }}</span></td>
                        <td class="mb-muted" dir="ltr">{{ $e->isWholeDay() ? __('All day') : substr($e->start_time, 0, 5).'–'.substr($e->end_time, 0, 5) }}</td>
                        <td class="mb-muted">{{ $e->reason }}</td>
                        <td class="text-end">
                            <form method="POST" action="{{ route('tenant.exceptions.destroy', $e) }}" onsubmit="return confirm('{{ __('Remove this exception?') }}')">
                                @csrf @method('DELETE')
                                <button class="btn btn-sm mb-btn-ghost">✕</button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="mb-muted py-4 text-center">{{ __('No exceptions scheduled.') }}</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
        {{ $exceptions->links() }}
    </div>
</div>
@endsection
