@extends('layouts.app')

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

@section('content')
<section class="content-header">
    <h1>@lang('medregistry::lang.registry')
        <small>@lang('medregistry::lang.registry_subtitle')</small>
    </h1>
</section>

<section class="content">
    @component('components.widget', ['class' => 'box-primary'])
        @slot('tool')
            <div class="box-tools">
                <form method="get" action="{{ route('medreg.registry.index') }}" class="form-inline" style="display:inline-block;">
                    <select name="category" class="form-control input-sm" onchange="this.form.submit()">
                        <option value="">@lang('medregistry::lang.all_categories')</option>
                        @foreach($categories as $cat)
                            <option value="{{ $cat }}" @if($category === $cat) selected @endif>
                                @lang('medregistry::lang.category_' . $cat)
                            </option>
                        @endforeach
                    </select>
                </form>
            </div>
        @endslot

        <div class="table-responsive">
            <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th>@lang('medregistry::lang.module')</th>
                        <th>@lang('medregistry::lang.category')</th>
                        <th>@lang('medregistry::lang.spec_key')</th>
                        <th>@lang('medregistry::lang.installable_per')</th>
                        <th>@lang('medregistry::lang.dependencies')</th>
                        <th>@lang('medregistry::lang.version')</th>
                        <th>@lang('medregistry::lang.presence')</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($modules as $module)
                        <tr>
                            <td>
                                <strong>{{ $module->display_name }}</strong>
                                <br><small class="text-muted">{{ $module->module_key }}</small>
                            </td>
                            <td><span class="label label-default">@lang('medregistry::lang.category_' . $module->category)</span></td>
                            <td>{{ $module->spec_key ?: '—' }}</td>
                            <td>@lang('medregistry::lang.per_' . $module->installable_per)</td>
                            <td>
                                @if(!empty($module->dependencies))
                                    {{ implode(', ', (array) $module->dependencies) }}
                                @else
                                    —
                                @endif
                            </td>
                            <td>{{ $module->version ?: '—' }}</td>
                            <td>
                                @if($module->is_present)
                                    <span class="label label-success">@lang('medregistry::lang.present')</span>
                                    @if(!empty($installed[$module->module_key]))
                                        <span class="label label-primary">@lang('medregistry::lang.installed')</span>
                                    @else
                                        <span class="label label-warning">@lang('medregistry::lang.not_installed')</span>
                                    @endif
                                @else
                                    <span class="label label-danger">@lang('medregistry::lang.absent')</span>
                                @endif
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7" class="text-center text-muted">@lang('medregistry::lang.catalog_empty')</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    @endcomponent
</section>
@endsection
