{{--
    결재서명란 (전통 테이블 형식)
    Props:
        $approval (Approval model) - 결재 문서
--}}
@php
    $drafter = $approval->drafter;
    $approverSteps = $approval->steps->whereIn('step_type', ['approval', 'agreement'])->sortBy('step_order')->values();
@endphp

<table style="border-collapse: collapse; border: 2px solid #4338ca; font-size: 12px; min-width: 120px;">
    <tbody>
        {{-- 1행: 직급/역할 --}}
        <tr>
            <td rowspan="3" style="border: 1px solid #a5b4fc; padding: 4px 6px; text-align: center; font-weight: 700; color: #4338ca; background: #eef2ff; writing-mode: vertical-rl; letter-spacing: 6px; width: 28px; font-size: 13px;">
                결재
            </td>
            <td style="border: 1px solid #c7d2fe; padding: 4px 10px; text-align: center; font-weight: 600; color: #374151; background: #f9fafb; min-width: 64px; white-space: nowrap;">
                작성자
            </td>
            @foreach($approverSteps as $step)
                <td style="border: 1px solid #c7d2fe; padding: 4px 10px; text-align: center; font-weight: 600; color: #374151; background: #f9fafb; min-width: 64px; white-space: nowrap;">
                    {{ $step->approver_position ?: ($step->step_type === 'agreement' ? '합의' : '결재') }}
                </td>
            @endforeach
        </tr>
        {{-- 2행: 서명/도장 영역 --}}
        <tr>
            <td style="border: 1px solid #c7d2fe; padding: 6px 10px; text-align: center; height: 40px; vertical-align: middle;">
                @if(in_array($approval->status, ['pending', 'approved', 'rejected', 'cancelled', 'on_hold']))
                    <span style="color: #2563eb; font-size: 11px; font-weight: 500;">{{ $drafter?->name ?? '-' }}</span>
                @endif
            </td>
            @foreach($approverSteps as $step)
                <td style="border: 1px solid #c7d2fe; padding: 6px 10px; text-align: center; height: 40px; vertical-align: middle;">
                    @if($step->status === 'approved')
                        @if(($step->approval_type ?? 'normal') === 'pre_decided')
                            <div style="display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 2px solid #6366f1; border-radius: 50%; color: #6366f1; font-size: 9px; font-weight: 700; line-height: 1;">
                                전결
                            </div>
                        @else
                            <div style="display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 2px solid #dc2626; border-radius: 50%; color: #dc2626; font-size: 9px; font-weight: 700; line-height: 1;">
                                승인
                            </div>
                        @endif
                    @elseif($step->status === 'rejected')
                        <div style="display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 2px solid #dc2626; border-radius: 50%; color: #dc2626; font-size: 9px; font-weight: 700; line-height: 1;">
                            반려
                        </div>
                    @elseif($step->status === 'on_hold')
                        <div style="display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 2px solid #d97706; border-radius: 50%; color: #d97706; font-size: 9px; font-weight: 700; line-height: 1;">
                            보류
                        </div>
                    @elseif($step->status === 'skipped')
                        <span style="color: #9ca3af; font-size: 10px;">-</span>
                    @endif
                </td>
            @endforeach
        </tr>
        {{-- 3행: 이름 + 처리일시 --}}
        <tr>
            <td style="border: 1px solid #c7d2fe; padding: 3px 10px; text-align: center; white-space: nowrap;">
                @if(in_array($approval->status, ['pending', 'approved', 'rejected', 'cancelled', 'on_hold']))
                    <div style="font-size: 10px; color: #6b7280;">
                        {{ $approval->drafted_at?->format('m/d') ?? '' }}
                    </div>
                @endif
            </td>
            @foreach($approverSteps as $step)
                <td style="border: 1px solid #c7d2fe; padding: 3px 10px; text-align: center; white-space: nowrap;">
                    <div style="font-size: 11px; color: #374151; font-weight: 500;">
                        {{ $step->approver_name ?? ($step->approver?->name ?? '') }}
                    </div>
                    @if($step->acted_at)
                        <div style="font-size: 10px; color: #6b7280;">
                            {{ $step->acted_at->format('m/d') }}
                        </div>
                    @endif
                </td>
            @endforeach
        </tr>
    </tbody>
</table>
