@extends('admin.layouts.app') @section('title', __('whmcs_import.title')) @section('content') @include('admin.whmcs-import._styles') @php $fieldLabel = fn (string $field) => str_starts_with($field, 'custom_field:') ? substr($field, 13).' ('.__('whmcs_import.custom_field').')' : $field; $mappedCount = collect($sourceColumns)->filter(fn ($c) => ($selected[$c['name']] ?? '__skip__') !== '__skip__')->count(); $totalColumns = count($sourceColumns); $types = [ 'clients' => ['icon' => 'fa-users', 'table' => $prefix.'clients', 'label' => __('whmcs_import.target_clients')], 'domains' => ['icon' => 'fa-globe', 'table' => $prefix.'domains', 'label' => __('whmcs_import.target_domains')], 'services' => ['icon' => 'fa-server', 'table' => $prefix.'hosting', 'label' => __('whmcs_import.target_services')], ]; $filledConstants = collect($mapping['constants'] ?? [])->filter(fn ($v) => is_string($v) && $v !== '')->count(); $filledTransforms = collect($mapping['transforms'] ?? [])->filter(fn ($t) => ! empty($t['pattern']))->count(); @endphp

{{ __('whmcs_import.field_mapping') }}

{{ $connection->name ?: $connection->database }} · {{ $connection->host }}:{{ $connection->port }} / {{ $connection->database }}

{{ __('whmcs_import.total_rows', ['count' => number_format($totalCount)]) }} {{ __('whmcs_import.badge_read_only') }}
@include('admin.whmcs-import._steps', ['current' => 2]) @if($target === 'domains')
{{ __('whmcs_import.domains_client_hint') }}
@endif @if(!empty($errors)) @endif
@csrf

{{ __('whmcs_import.import_mode') }}

{{ __('whmcs_import.field_mapping') }}

{{ __('whmcs_import.mapped_count', ['count' => $mappedCount, 'total' => $totalColumns]) }}
@foreach($sourceColumns as $column) @php $name = $column['name']; $suggested = $suggestions[$name] ?? null; $current = $selected[$name] ?? ($suggested ?? '__skip__'); @endphp @endforeach
{{ __('whmcs_import.source_column') }} {{ __('whmcs_import.target_field') }}
{{ $name }}{{ $column['type'] }} @if($suggested !== null && $current === $suggested)
{{ __('whmcs_import.suggested') }}
@endif
{{ __('whmcs_import.constants') }}@if($filledConstants){{ $filledConstants }}@endif
@foreach($targetFields as $field) @endforeach
{{ __('whmcs_import.target_field') }} {{ __('whmcs_import.constant_value') }}
{{ $fieldLabel($field) }}
{{ __('whmcs_import.transforms') }}@if($filledTransforms){{ $filledTransforms }}@endif

{{ __('whmcs_import.transforms_hint') }}

@foreach($targetFields as $field) @endforeach
{{ __('whmcs_import.target_field') }} {{ __('whmcs_import.transform_pattern') }} {{ __('whmcs_import.transform_replacement') }}
{{ $fieldLabel($field) }}
@if($target === 'services' && count($whmcsProducts))
{{ __('whmcs_import.product_mapping') }}

{{ __('whmcs_import.product_mapping_hint') }}

@foreach($whmcsProducts as $wp) @endforeach
{{ __('whmcs_import.whmcs_product') }} {{ __('whmcs_import.pnlcs_product') }}
{{ $wp['name'] }}{{ $wp['type'] }} {{-- Keyed by the WHMCS product id: a name containing brackets would corrupt a key built from the name. --}}
@endif
@if($preview !== null)

{{ __('whmcs_import.preview_title', ['count' => count($preview)]) }}

@if(count($preview) === 0)
{{ __('whmcs_import.no_preview_rows') }}
@else @foreach($preview as $i => $record) @php $person = trim(($record['target']['first_name'] ?? '').' '.($record['target']['last_name'] ?? '')); $heading = $person ?: ($record['target']['domain'] ?? null) ?: ($record['target']['email'] ?? ($record['source']['email'] ?? '')) ?: '#'.($i + 1); @endphp
{{ $i + 1 }}{{ $heading }}
{{ __('whmcs_import.preview_source') }}
@foreach($mapping['columns'] as $src => $tgt)
{{ $src }}{{ $record['source'][$src] ?? '' }}
@endforeach
{{ __('whmcs_import.preview_target') }}
@foreach($record['target'] as $field => $value)
{{ $fieldLabel($field) }}{{ $value }}
@endforeach
@endforeach @endif
@endif
@endsection