@php
/**
* One unit of work on the products board: a product, a compiled unit, or one
* piece of a product that has been split.
*
* Rendered in two settings, because a piece IS a unit of work and reading
* differently would suggest otherwise:
*
* $compact = false a product standing on its own, in its own card on the
* page.
* $compact = true a piece, in its own card on its parent product's
* surface. Tighter, with a status bar across the top and
* its secondary actions reduced to icons — a piece is
* read three or four at a time, so the same seven text
* links that are fine once become noise.
*/
$meta = $statusMeta[$unit['status']] ?? $statusMeta['pending'];
$overdue = $unit['due_date'] && $unit['status'] !== 'done' && $unit['due_date']->isPast();
$marginTone = $unit['revenue'] <= 0
? 'slate'
: ($unit['margin'] >= 30 ? 'emerald' : ($unit['margin'] >= 10 ? 'amber' : 'rose'));
$marginPill = [
'emerald' => 'bg-emerald-50 text-emerald-700 ring-emerald-200',
'amber' => 'bg-amber-50 text-amber-700 ring-amber-200',
'rose' => 'bg-rose-50 text-rose-700 ring-rose-200',
'slate' => 'bg-slate-100 text-slate-500 ring-slate-200',
][$marginTone];
$noteCount = $unit['part_id'] ? ($partNoteCounts[$unit['part_id']] ?? 0) : 0;
$fileCount = $unit['part_id'] ? ($partFileCounts[$unit['part_id']] ?? 0) : 0;
$canTick = $canUpdate && count($units) > 1 && ! $unit['is_group'] && ! $unit['is_part'];
$pad = $compact ? 'px-3.5' : 'px-4 sm:px-5';
@endphp
@if ($compact)
{{-- Where this piece has got to, readable before anything is read. --}}
@endif
{{-- Head --}}
@if ($canTick)
@endif
@if ($compact)
{{ $unit['part_index'] }}
@endif
{{ $unit['label'] }}
@if ($unit['is_group'])
{{ trans_choice('[2,*] :count products', count($unit['line_ids']), ['count' => count($unit['line_ids'])]) }}
@endif
{{ $meta['label'] }}
{{-- On a hybrid job every product says where it is made; on any
other job the job itself already answers for all of them. --}}
@if ($isHybrid)
@if ($unit['is_outsourced'])
{{ $unit['partner']?->name ?: __('Outsourced') }}
@else
{{ __('In-house') }}
@endif
@endif