<?php

namespace App\Filament\Resources\ProductSerialResource\Pages;

use App\Filament\Resources\ProductSerialResource;
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\Pages\ViewRecord;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class ViewProductSerial extends ViewRecord
{
    protected static string $resource = ProductSerialResource::class;

    public function infolist(Schema $schema): Schema
    {
        return $schema->components([
            Section::make()->schema([
                TextEntry::make('serial_number'),
                TextEntry::make('product.name'),
                TextEntry::make('branch.name')->placeholder('—'),
                TextEntry::make('status.name')->badge()->color(fn () => $this->record->status?->color ?? 'gray'),
                TextEntry::make('currentCustomer.name')->label('Current Customer')->placeholder('—'),
            ])->columns(3),
            Section::make('Repair History')->schema([
                RepeatableEntry::make('repairHistory')
                    ->schema([
                        TextEntry::make('description'),
                        TextEntry::make('started_at')->date(),
                        TextEntry::make('completed_at')->date()->placeholder('Open'),
                        TextEntry::make('outcome')->placeholder('—'),
                    ])
                    ->columns(4)
                    ->columnSpanFull(),
            ]),
        ]);
    }
}
