@php
    $p = $profile ?? null;
    $capacity = $p->capacity ?? [];
@endphp
<div class="modal-dialog modal-lg" role="document"><div class="modal-content">
    {!! Form::open(['route' => ['medorg.facilities.update', $location->id], 'method' => 'PUT', 'class' => 'medorg-form']) !!}
    <div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title">@lang('medorganization::lang.facility_profile') — {{ $location->name }}</h4></div>
    <div class="modal-body">
        <div class="row">
            <div class="col-md-4"><div class="form-group">
                {!! Form::label('code', __('medorganization::lang.code') . ':') !!}
                {!! Form::text('code', $p->code ?? null, ['class' => 'form-control', 'maxlength' => 20]) !!}
            </div></div>
            <div class="col-md-4"><div class="form-group">
                {!! Form::label('facility_type', __('medorganization::lang.facility_type') . ':*') !!}
                {!! Form::select('facility_type', [
                    'hospital'   => __('medorganization::lang.facility_type_hospital'),
                    'clinic'     => __('medorganization::lang.facility_type_clinic'),
                    'lab'        => __('medorganization::lang.facility_type_lab'),
                    'imaging'    => __('medorganization::lang.facility_type_imaging'),
                    'pharmacy'   => __('medorganization::lang.facility_type_pharmacy'),
                    'dialysis'   => __('medorganization::lang.facility_type_dialysis'),
                    'physio'     => __('medorganization::lang.facility_type_physio'),
                    'diagnostic' => __('medorganization::lang.facility_type_diagnostic'),
                    'other'      => __('medorganization::lang.facility_type_other'),
                ], $p->facility_type ?? 'other', ['class' => 'form-control', 'required']) !!}
            </div></div>
            <div class="col-md-4"><div class="form-group">
                {!! Form::label('parent_location_id', __('medorganization::lang.parent_facility') . ':') !!}
                {!! Form::select('parent_location_id', $parents, $p->parent_location_id ?? null, ['class' => 'form-control medorg-select2', 'placeholder' => __('messages.please_select')]) !!}
                <p class="help-block">@lang('medorganization::lang.hierarchy_help')</p>
            </div></div>
        </div>
        <div class="row">
            <div class="col-md-3"><div class="form-group">
                {!! Form::label('capacity_beds', __('medorganization::lang.capacity_beds') . ':') !!}
                {!! Form::number('capacity_beds', $capacity['beds'] ?? null, ['class' => 'form-control', 'min' => 0]) !!}
            </div></div>
            <div class="col-md-3"><div class="form-group">
                {!! Form::label('capacity_outpatient', __('medorganization::lang.capacity_outpatient') . ':') !!}
                {!! Form::number('capacity_outpatient', $capacity['daily_outpatient'] ?? null, ['class' => 'form-control', 'min' => 0]) !!}
            </div></div>
            <div class="col-md-3"><div class="form-group">
                {!! Form::label('capacity_lab_samples', __('medorganization::lang.capacity_lab_samples') . ':') !!}
                {!! Form::number('capacity_lab_samples', $capacity['daily_lab_samples'] ?? null, ['class' => 'form-control', 'min' => 0]) !!}
            </div></div>
            <div class="col-md-3"><div class="form-group">
                {!! Form::label('capacity_imaging', __('medorganization::lang.capacity_imaging') . ':') !!}
                {!! Form::number('capacity_imaging', $capacity['daily_imaging'] ?? null, ['class' => 'form-control', 'min' => 0]) !!}
            </div></div>
        </div>
        <div class="row">
            <div class="col-md-3"><div class="form-group">
                {!! Form::label('geo_lat', __('medorganization::lang.geo_lat') . ':') !!}
                {!! Form::text('geo_lat', $p->geo_lat ?? null, ['class' => 'form-control']) !!}
            </div></div>
            <div class="col-md-3"><div class="form-group">
                {!! Form::label('geo_lng', __('medorganization::lang.geo_lng') . ':') !!}
                {!! Form::text('geo_lng', $p->geo_lng ?? null, ['class' => 'form-control']) !!}
            </div></div>
            <div class="col-md-6"><div class="form-group">
                {!! Form::label('status', __('medorganization::lang.status') . ':*') !!}
                {!! Form::select('status', [
                    'active'             => __('medorganization::lang.status_active'),
                    'inactive'           => __('medorganization::lang.status_inactive'),
                    'under_construction' => __('medorganization::lang.status_under_construction'),
                ], $p->status ?? 'active', ['class' => 'form-control', 'required']) !!}
            </div></div>
        </div>
        <div class="form-group">
            {!! Form::label('working_hours', __('medorganization::lang.working_hours') . ' (JSON):') !!}
            {!! Form::textarea('working_hours', $p && $p->working_hours ? json_encode($p->working_hours, JSON_PRETTY_PRINT) : null, ['class' => 'form-control', 'rows' => 4, 'placeholder' => '{"mon": ["08:00-20:00"], "tue": ["08:00-20:00"]}']) !!}
            <p class="help-block">@lang('medorganization::lang.working_hours_help')</p>
        </div>
    </div>
    <div class="modal-footer"><button type="submit" class="btn btn-primary">@lang('messages.save')</button><button type="button" class="btn btn-default" data-dismiss="modal">@lang('messages.close')</button></div>
    {!! Form::close() !!}
</div></div>
