@php $d = $department ?? null; @endphp
<div class="row">
    <div class="col-md-6"><div class="form-group">
        {!! Form::label('name', __('medorganization::lang.department') . ':*') !!}
        {!! Form::text('name', $d->name ?? null, ['class' => 'form-control', 'required', 'maxlength' => 100]) !!}
    </div></div>
    <div class="col-md-3"><div class="form-group">
        {!! Form::label('code', __('medorganization::lang.code') . ':') !!}
        {!! Form::text('code', $d->code ?? null, ['class' => 'form-control', 'maxlength' => 20]) !!}
    </div></div>
    <div class="col-md-3"><div class="form-group">
        {!! Form::label('dept_type', __('medorganization::lang.dept_type') . ':') !!}
        {!! Form::select('dept_type', [
            'clinical'       => __('medorganization::lang.dept_type_clinical'),
            'diagnostic'     => __('medorganization::lang.dept_type_diagnostic'),
            'administrative' => __('medorganization::lang.dept_type_administrative'),
            'support'        => __('medorganization::lang.dept_type_support'),
        ], $d->dept_type ?? null, ['class' => 'form-control', 'placeholder' => __('messages.please_select')]) !!}
    </div></div>
</div>
<div class="row">
    <div class="col-md-4"><div class="form-group">
        {!! Form::label('parent_department_id', __('medorganization::lang.parent_department') . ':') !!}
        {!! Form::select('parent_department_id', $parents, $d->parent_department_id ?? null, ['class' => 'form-control medorg-select2', 'placeholder' => __('messages.please_select')]) !!}
    </div></div>
    <div class="col-md-4"><div class="form-group">
        {!! Form::label('head_user_id', __('medorganization::lang.head_of_department') . ':') !!}
        {!! Form::select('head_user_id', $users, $d->head_user_id ?? null, ['class' => 'form-control medorg-select2', 'placeholder' => __('messages.please_select')]) !!}
    </div></div>
    <div class="col-md-4"><div class="form-group">
        {!! Form::label('business_location_id', __('medorganization::lang.location') . ':') !!}
        {!! Form::select('business_location_id', $locations, $d->business_location_id ?? null, ['class' => 'form-control medorg-select2', 'placeholder' => __('messages.please_select')]) !!}
    </div></div>
</div>
<div class="row">
    <div class="col-md-3"><div class="form-group">
        {!! Form::label('sort_order', __('medorganization::lang.sort_order') . ':') !!}
        {!! Form::number('sort_order', $d->sort_order ?? 0, ['class' => 'form-control', 'min' => 0]) !!}
    </div></div>
    <div class="col-md-3"><div class="form-group">
        {!! Form::label('status', __('medorganization::lang.status') . ':') !!}
        {!! Form::select('status', [
            'active'   => __('medorganization::lang.status_active'),
            'inactive' => __('medorganization::lang.status_inactive'),
        ], $d->status ?? 'active', ['class' => 'form-control']) !!}
    </div></div>
    <div class="col-md-6"><div class="form-group">
        {!! Form::label('description', __('medorganization::lang.description') . ':') !!}
        {!! Form::text('description', $d->description ?? null, ['class' => 'form-control']) !!}
    </div></div>
</div>
<div class="form-group">
    {!! Form::label('working_hours', __('medorganization::lang.working_hours') . ' (JSON):') !!}
    @php
        $wh = $d->working_hours ?? null;
        if (is_string($wh)) { $decoded = json_decode($wh, true); $wh = $decoded !== null ? $decoded : $wh; }
    @endphp
    {!! Form::textarea('working_hours', $wh ? json_encode($wh, JSON_PRETTY_PRINT) : null, ['class' => 'form-control', 'rows' => 3, 'placeholder' => '{"mon": ["09:00-17:00"]}']) !!}
    <p class="help-block">@lang('medorganization::lang.working_hours_help')</p>
</div>
