@extends('layouts.app')

@section('title', __('medregistry::lang.setup_wizard'))

@section('content')
<section class="content-header">
    <h1>@lang('medregistry::lang.setup_wizard')
        <small>@lang('medregistry::lang.wizard_step2_title') — {{ $type->label }}</small>
    </h1>
</section>

<section class="content">
    <form method="post" action="{{ route('medreg.wizard.apply') }}">
        @csrf

        @unless($type->isCustom())
            {{-- Default modules: pre-checked & locked --}}
            @component('components.widget', ['class' => 'box-primary', 'title' => __('medregistry::lang.default_modules')])
                <p class="help-block">@lang('medregistry::lang.default_modules_help')</p>
                @foreach($defaults as $specKey)
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" checked disabled>
                            <strong>{{ $specKey }}</strong>
                            <span class="text-muted">(@lang('medregistry::lang.required'))</span>
                            @if($specKey === \Modules\MedRegistry\Entities\MedregBusinessType::META_ALL_SPECIALTIES)
                                — @lang('medregistry::lang.all_specialties_note')
                            @elseif(isset($resolution[$specKey]))
                                @if(!empty($resolution[$specKey]))
                                    — <small class="text-success">{{ implode(', ', $resolution[$specKey]) }}</small>
                                @else
                                    — <small class="text-warning">@lang('medregistry::lang.will_be_skipped')</small>
                                @endif
                            @endif
                        </label>
                    </div>
                @endforeach
            @endcomponent

            {{-- Optional modules: toggleable --}}
            @if(!empty($optionalKeys) || $specialtyMode)
                @component('components.widget', ['class' => 'box-info', 'title' => __('medregistry::lang.optional_modules')])
                    @foreach($optionalKeys as $specKey)
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="selected[]" value="{{ $specKey }}">
                                {{ $specKey }} <span class="text-muted">(@lang('medregistry::lang.optional'))</span>
                            </label>
                        </div>
                    @endforeach

                    @if($specialtyMode)
                        <hr>
                        <strong>
                            @if($specialtyMode === 'single')
                                @lang('medregistry::lang.pick_one_specialty')
                            @else
                                @lang('medregistry::lang.pick_specialties')
                            @endif
                        </strong>
                        @forelse($specialties as $specialty)
                            <div class="{{ $specialtyMode === 'single' ? 'radio' : 'checkbox' }}">
                                <label>
                                    <input type="{{ $specialtyMode === 'single' ? 'radio' : 'checkbox' }}"
                                           name="{{ $specialtyMode === 'single' ? 'selected[specialty]' : 'selected[]' }}"
                                           value="{{ $specialty->spec_key }}">
                                    {{ $specialty->display_name }}
                                    <small class="text-muted">({{ $specialty->spec_key }})</small>
                                </label>
                            </div>
                        @empty
                            <p class="text-muted">@lang('medregistry::lang.no_specialties_present')</p>
                        @endforelse
                    @endif
                @endcomponent
            @endif
        @else
            {{-- Custom: full medical catalog multi-select --}}
            @component('components.widget', ['class' => 'box-primary', 'title' => __('medregistry::lang.custom_selection')])
                <p class="help-block">@lang('medregistry::lang.custom_selection_help')</p>
                @forelse($catalog as $module)
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="selected[]" value="{{ $module->spec_key ?: $module->module_key }}">
                            {{ $module->display_name }}
                            <small class="text-muted">
                                (@lang('medregistry::lang.category_' . $module->category)@if($module->spec_key) · {{ $module->spec_key }}@endif)
                            </small>
                        </label>
                    </div>
                @empty
                    <p class="text-muted">@lang('medregistry::lang.catalog_empty')</p>
                @endforelse
            @endcomponent
        @endunless

        <div class="box box-solid">
            <div class="box-body text-right">
                <a href="{{ route('medreg.wizard.step1') }}" class="btn btn-default">@lang('medregistry::lang.back')</a>
                <button type="submit" class="btn btn-primary btn-lg">
                    @lang('medregistry::lang.confirm_and_install')
                </button>
            </div>
        </div>
    </form>
</section>
@endsection
