{{-- SHIFT SEGMENT FORM --}}

{{-- BASIC INFO --}}
<div class="row mb-3">
    
    <div class="col-md-3">
        <label class="form-label">Branch</label>
        <select name="branch_id" class="form-control">
            <option value="">All Branches</option>
            @foreach($branches as $branch)
                <option value="{{ $branch->id }}"
                    @selected(old('branch_id', $shiftSegment->branch_id ?? '') == $branch->id)>
                    {{ $branch->name }}
                </option>
            @endforeach
        </select>
    </div>
    <div class="col-md-4">
        <label class="form-label">Segment Name <span class="text-danger">*</span></label>
        <input type="text"
               name="name"
               class="form-control"
               maxlength="150"
               value="{{ old('name', $shiftSegment->name ?? '') }}"
               required>
    </div>

    <div class="col-md-3">
        <label class="form-label">Effective From <span class="text-danger">*</span></label>
        <input type="date"
               name="effective_from"
               id="effectiveFrom"
               class="form-control"
               value="{{ old('effective_from', $shiftSegment->effective_from ?? now()->toDateString()) }}"
               required>
    </div>

    <div class="col-md-2 d-flex align-items-end">
        <div class="form-check">
            <input type="checkbox"
                   name="status"
                   class="form-check-input"
                   value="1"
                   @checked(old('status', $shiftSegment->status ?? true))>
            <label class="form-check-label">Active</label>
        </div>
    </div>
</div>

{{-- WEEKDAY SHIFT MAPPING --}}
<table class="table table-bordered" id="weekdayTable">
    <thead>
        <tr>
            <th width="200">Week Day</th>
            <th>Shift</th>
        </tr>
    </thead>
    <tbody>
        @php
            $weekDays = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday'];
        @endphp

        @foreach($weekDays as $day)
            <tr data-weekday="{{ $day }}">
                <td class="text-capitalize fw-semibold">
                    {{ $day }}
                </td>
                <td>
                    <select name="days[{{ $day }}]" class="form-control" required>
                        <option value="">-- Select --</option>
                        @foreach($shifts as $shift)
                            <option value="{{ $shift->id }}"
                                @selected(
                                    isset($shiftSegment) &&
                                    optional(
                                        $shiftSegment->days->where('weekday', $day)->first()
                                    )->shift_id == $shift->id
                                )>
                                {{ $shift->code }} - {{ $shift->name }}
                            </option>
                        @endforeach
                    </select>
                </td>
            </tr>
        @endforeach
    </tbody>
</table>


