@extends('layouts.app')
@section('title', $patient->exists ? __('Edit patient') : __('Add patient'))

@section('content')
<h1 class="h4 fw-bold mb-3">{{ $patient->exists ? __('Edit patient') : __('Add patient') }}</h1>

<form method="POST"
      action="{{ $patient->exists ? route('tenant.patients.update', $patient) : route('tenant.patients.store') }}"
      style="max-width:46rem">
    @csrf
    @if($patient->exists) @method('PUT') @endif

    <div class="mb-card p-4">
        <div class="row">
            <div class="col-md-7 mb-3">
                <label class="form-label">{{ __('Full name') }}</label>
                <input name="full_name" value="{{ old('full_name', $patient->full_name) }}" class="form-control @error('full_name') is-invalid @enderror" required>
                @error('full_name')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>
            <div class="col-md-5 mb-3">
                <label class="form-label">{{ __('Phone (WhatsApp)') }}</label>
                <input name="phone" value="{{ old('phone', $patient->phone) }}" dir="ltr" class="form-control @error('phone') is-invalid @enderror" required>
                @error('phone')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>
            <div class="col-md-5 mb-3">
                <label class="form-label">{{ __('Email') }}</label>
                <input type="email" name="email" value="{{ old('email', $patient->email) }}" class="form-control">
            </div>
            <div class="col-md-3 mb-3">
                <label class="form-label">{{ __('Gender') }}</label>
                <select name="gender" class="form-select">
                    <option value="">—</option>
                    <option value="male" @selected(old('gender', $patient->gender) === 'male')>{{ __('Male') }}</option>
                    <option value="female" @selected(old('gender', $patient->gender) === 'female')>{{ __('Female') }}</option>
                </select>
            </div>
            <div class="col-md-4 mb-3">
                <label class="form-label">{{ __('Date of birth') }}</label>
                <input type="date" name="dob" value="{{ old('dob', $patient->dob?->toDateString()) }}" class="form-control">
            </div>
            <div class="col-12 mb-3">
                <label class="form-label">{{ __('Address') }}</label>
                <input name="address" value="{{ old('address', $patient->address) }}" class="form-control">
            </div>
            <div class="col-md-6 mb-3">
                <label class="form-label">{{ __('Allergies') }}</label>
                <textarea name="allergies" rows="2" class="form-control">{{ old('allergies', $patient->allergies) }}</textarea>
            </div>
            <div class="col-md-6 mb-3">
                <label class="form-label">{{ __('Medical history') }}</label>
                <textarea name="medical_history" rows="2" class="form-control">{{ old('medical_history', $patient->medical_history) }}</textarea>
            </div>
            <div class="col-12 mb-3">
                <label class="form-label">{{ __('Notes') }}</label>
                <textarea name="notes" rows="2" class="form-control">{{ old('notes', $patient->notes) }}</textarea>
            </div>
            <div class="col-12">
                <div class="form-check">
                    <input type="hidden" name="whatsapp_opt_in" value="0">
                    <input class="form-check-input" type="checkbox" name="whatsapp_opt_in" value="1" id="optin"
                           @checked(old('whatsapp_opt_in', $patient->whatsapp_opt_in ?? true))>
                    <label class="form-check-label" for="optin">{{ __('Send WhatsApp reminders to this patient') }}</label>
                </div>
            </div>
        </div>
    </div>

    <div class="mt-3 d-flex gap-2">
        <button class="btn mb-btn-primary">{{ __('Save changes') }}</button>
        <a href="{{ url()->previous() }}" class="btn mb-btn-ghost">{{ __('Cancel') }}</a>
    </div>
</form>
@endsection
