@extends('layouts.sash')

@section('title', 'Add Staff')

@section('content')
<div class="row mt-4">
<div class="col-xl-10 col-lg-11">
    <div class="card custom-card">
        <div class="card-header">
            <div class="card-title">Add Staff</div>
        </div>
        <div class="card-body">
            <form method="post" action="{{ route('staff.store') }}">
                @csrf

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">First name *</label>
                        <input type="text" name="first_name" value="{{ old('first_name') }}" required class="form-control">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Last name</label>
                        <input type="text" name="last_name" value="{{ old('last_name') }}" class="form-control">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Mobile</label>
                        <input type="text" name="mobile" value="{{ old('mobile') }}" class="form-control">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Email</label>
                        <input type="email" name="email" value="{{ old('email') }}" class="form-control">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Gender</label>
                        <select name="gender" class="form-control form-select">
                            <option value="">Not set</option>
                            <option value="male" {{ old('gender') === 'male' ? 'selected' : '' }}>Male</option>
                            <option value="female" {{ old('gender') === 'female' ? 'selected' : '' }}>Female</option>
                            <option value="other" {{ old('gender') === 'other' ? 'selected' : '' }}>Other</option>
                        </select>
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Designation</label>
                        <input type="text" name="designation" value="{{ old('designation') }}" class="form-control">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Specialization</label>
                        <input type="text" name="specialization" value="{{ old('specialization') }}" class="form-control">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Branch *</label>
                        <select name="branch_id" required class="form-control form-select">
                            <option value="">Select branch</option>
                            @foreach($branches as $b)
                                <option value="{{ $b->id }}" {{ old('branch_id', $branchId) == $b->id ? 'selected' : '' }}>{{ $b->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Joining date</label>
                        <input type="date" name="joining_date" value="{{ old('joining_date') }}" class="form-control">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Employment type</label>
                        <input type="text" name="employment_type" value="{{ old('employment_type') }}" class="form-control">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Basic salary</label>
                        <input type="number" step="0.01" name="basic_salary" value="{{ old('basic_salary') }}" min="0" class="form-control">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Commission type</label>
                        <input type="text" name="commission_type" value="{{ old('commission_type') }}" class="form-control">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Commission value</label>
                        <input type="number" step="0.01" name="commission_value" value="{{ old('commission_value') }}" min="0" class="form-control">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Weekly off day</label>
                        <input type="text" name="weekly_off_day" value="{{ old('weekly_off_day') }}" class="form-control" placeholder="e.g. Sunday">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Shift start time</label>
                        <input type="time" name="shift_start_time" value="{{ old('shift_start_time') }}" class="form-control">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Shift end time</label>
                        <input type="time" name="shift_end_time" value="{{ old('shift_end_time') }}" class="form-control">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Status *</label>
                        <select name="status" required class="form-control form-select">
                            <option value="active" {{ old('status', 'active') === 'active' ? 'selected' : '' }}>Active</option>
                            <option value="inactive" {{ old('status') === 'inactive' ? 'selected' : '' }}>Inactive</option>
                            <option value="on_leave" {{ old('status') === 'on_leave' ? 'selected' : '' }}>On Leave</option>
                        </select>
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Availability</label>
                        <select name="availability_status" class="form-control form-select">
                            <option value="">Not set</option>
                            <option value="available" {{ old('availability_status') === 'available' ? 'selected' : '' }}>Available</option>
                            <option value="busy" {{ old('availability_status') === 'busy' ? 'selected' : '' }}>Busy</option>
                            <option value="on_break" {{ old('availability_status') === 'on_break' ? 'selected' : '' }}>On Break</option>
                            <option value="off" {{ old('availability_status') === 'off' ? 'selected' : '' }}>Off</option>
                        </select>
                    </div>
                </div>

                <div class="mb-3">
                    <label class="form-label">Notes</label>
                    <textarea name="notes" rows="3" class="form-control">{{ old('notes') }}</textarea>
                </div>

                <div class="mb-3">
                    <label class="form-label mb-1">Services this staff can perform</label>
                    <div class="row row-cols-1 row-cols-md-2 g-2 border rounded-3 p-3">
                        @foreach($services as $service)
                        <div class="col">
                            <label class="form-check">
                                <input type="checkbox" name="service_ids[]" value="{{ $service->id }}" class="form-check-input"
                                    {{ in_array($service->id, old('service_ids', [])) ? 'checked' : '' }}>
                                <span class="form-check-label">{{ $service->name }}</span>
                            </label>
                        </div>
                        @endforeach
                    </div>
                </div>

                <div class="form-footer mt-3">
                    <button type="submit" class="btn btn-primary me-2">
                        <i class="fe fe-save me-1"></i>Save
                    </button>
                    <a href="{{ route('staff.index') }}" class="btn btn-secondary">Cancel</a>
                </div>
            </form>
        </div>
    </div>
</div>
</div>
@endsection

