@extends('eliteadmin::layouts.app')

@section('title', $module->name)
@section('page_class', 'page-modules')

@section('content')
    <div class="page-header">
        <div>
            <h1 class="page-title">{{ $module->name }}</h1>
            <nav class="breadcrumb">
                <a href="{{ route('dashboard') }}" class="breadcrumb-item">Home</a>
                <a href="{{ route('modules.index') }}" class="breadcrumb-item">Modules</a>
                <span class="breadcrumb-item active">{{ $module->name }}</span>
            </nav>
        </div>
    </div>

    <div class="row g-4">
        <div class="col-lg-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">Module Details</h5>
                </div>
                <div class="card-body">
                    <dl class="row mb-0">
                        <dt class="col-sm-4">Name</dt>
                        <dd class="col-sm-8">{{ $module->name }}</dd>

                        <dt class="col-sm-4">Version</dt>
                        <dd class="col-sm-8">{{ $module->version }}</dd>

                        <dt class="col-sm-4">Status</dt>
                        <dd class="col-sm-8">
                            <span @class([
                                'badge',
                                'bg-success' => $module->status === \App\Enums\ModuleStatus::Installed,
                                'bg-secondary' => $module->status === \App\Enums\ModuleStatus::Disabled,
                                'bg-danger' => $module->status === \App\Enums\ModuleStatus::Failed,
                            ])>
                                {{ ucfirst($module->status->value) }}
                            </span>
                        </dd>

                        <dt class="col-sm-4">Installed</dt>
                        <dd class="col-sm-8">{{ $module->installed_at?->format('M j, Y g:i A') ?? '—' }}</dd>

                        <dt class="col-sm-4">Module UUID</dt>
                        <dd class="col-sm-8"><code class="small">{{ $module->module_uuid }}</code></dd>
                    </dl>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">Actions</h5>
                </div>
                <div class="card-body d-grid gap-2">
                    @if ($module->status === \App\Enums\ModuleStatus::Installed && ($entryUrl ?? null))
                        <a href="{{ $entryUrl }}" class="btn btn-primary">
                            <i class="bi bi-box-arrow-in-right me-1"></i> Open Module
                        </a>
                    @endif

                    <a href="{{ route('modules.index') }}" class="btn btn-outline-secondary">
                        <i class="bi bi-arrow-left me-1"></i> Back to Modules
                    </a>

                    @if ($module->status === \App\Enums\ModuleStatus::Installed)
                        @can('uninstall', $module)
                            <form
                                action="{{ route('modules.destroy', $module) }}"
                                method="POST"
                                onsubmit="return confirm('Uninstall {{ $module->name }}? Users will lose access to this module until it is reinstalled.');"
                            >
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="btn btn-outline-danger w-100">
                                    <i class="bi bi-trash me-1"></i> Uninstall Module
                                </button>
                            </form>
                        @endcan
                    @endif
                </div>
            </div>
        </div>
    </div>
@endsection
