@extends('layouts.dashboard')
@section('title','Import Review') @section('page-title','Import Center')
@section('content')
@php
$a=$session->preview_rows??[];$s=$a['summary']??[];$items=$a['items']??[];$groups=$a['duplicate_groups']??[];$changes=$a['changes']??[];
$labels=['main_price_list'=>'Main Price List','clearance_price_list'=>'Clearance Price List','price_update'=>'Price Update','shipment'=>'Shipment','van_stock'=>'Salesman Van Stock'];
$isPrice=in_array($session->confirmed_type,['main_price_list','clearance_price_list','price_update'],true);
if(!$isPrice)$items=collect($items)->map(fn($row,$index)=>array_merge(['key'=>'source-'.$index,'source_row'=>$row['row']??$index+1,'sku'=>'','barcode'=>'','name'=>'','price'=>0,'qty'=>0,'status'=>'Ready','issues'=>[]],$row,['status'=>'Ready','issues'=>[]]))->all();
$canImport=in_array($session->status,['ready','needs_review'],true)&&empty($a['structural_blocker'])&&($s['ready']??0)>0;
@endphp
@if(in_array($session->status,['analysis_queued','analyzing'],true))
Analyzing…
{{$session->original_file}}
The original file is stored safely and analysis continues in the background. You may close this page and return from Import Center history.
@else
@if(session('success'))
{{session('success')}}
@endif @if(session('error'))
{{session('error')}}
@endif
@if($session->status==='failed')
@endif
@if(!empty($a['structural_blocker']))
Import cannot continue{{$a['structural_blocker']}}
@endif
@foreach([['Rows',$s['rows']??0,''],['Ready',$s['ready']??0,'text-success'],['Needs Review',$s['needs_review']??0,'text-warning'],['Invalid',$s['invalid']??0,'text-error'],['Skipped',$s['skipped']??0,''],['Type',$labels[$session->confirmed_type]??$session->confirmed_type,''],['Confidence',$session->confidence.'%',''],['Status',str_replace('_',' ',ucwords($session->status,'_')),'']] as [$label,$value,$tone])@endforeach
@if($changes)
Preview Changes
No data changes yet@foreach(['new_products'=>'New / Added','price_changed'=>'Price Changed','unchanged'=>'Unchanged','removed_from_list'=>'Removed From List','skipped'=>'Skipped'] as $key=>$label)
{{$label}}
{{number_format($changes[$key]??0)}}
@endforeach
@if($session->confirmed_type==='price_update')Price Update changes only included products. Other active-list memberships remain unchanged.
@elseFull replacement archives the previous active list. Removed products remain in the master Product database and historical records.
@endif@endif
@if($groups)
Issues to Review ({{count($groups)}})
Choose explicitly; conflicting prices are never selected silently.
@foreach($groups as $group){{$group['label']}}
{{$group['id']}}@foreach($group['rows'] as $row)
Row {{$row['source_row']}}SKU: {{$row['sku']?:'—'}}
Barcode: {{$row['barcode']?:'—'}}
Price: AED {{number_format($row['price'],2)}}
@endforeach
@endforeach
@endif
Analyzed Rows
Problem rows appear first. Edit or skip without changing the original file.
@foreach(['All','Ready','Needs Review','Invalid','Skipped'] as $filter)
{{$filter}}@endforeach
@forelse(collect($items)->sortBy(fn($row)=>array_search($row['status'],['Needs Review','Invalid','Ready','Skipped'])) as $row)
Row {{$row['source_row']}} · {{$row['sku']?:'No SKU'}} · {{$row['name']?:'Unnamed product'}}
{{$row['status']}} @if($row['issues']){{implode(' · ',$row['issues'])}}
@endif
@if($isPrice)
@endif
@empty
No row preview is available for this import type.
@endforelse
@endif
@endsection