components([ Forms\Components\Select::make('kind') ->label(__('Tip')) ->options(\App\Support\I18n::opts(ServiceTemplateItem::KINDS)) ->default('labor') ->live() ->required(), Forms\Components\Select::make('labor_id') ->label(__('Manoperă')) ->options(fn () => Labor::where('is_active', true)->get() ->mapWithKeys(fn ($l) => [$l->id => $l->label()]) ->all()) ->searchable() ->visible(fn (Get $get) => $get('kind') === 'labor') ->live() ->afterStateUpdated(function ($state, Set $set) { if ($state && $l = Labor::find($state)) { $set('name', $l->label()); $set('hours', $l->hours); } }), Forms\Components\Select::make('part_id') ->label(__('Piesă')) ->options(fn () => Part::where('is_active', true) ->get()->mapWithKeys(fn ($p) => [$p->id => "{$p->name} " . ($p->article ? "[{$p->article}]" : '')])->toArray()) ->searchable() ->visible(fn (Get $get) => $get('kind') === 'part') ->live() ->afterStateUpdated(function ($state, Set $set) { if ($state && $p = Part::find($state)) $set('name', $p->name); }), Forms\Components\TextInput::make('name')->label(__('Denumire'))->required()->columnSpanFull(), Forms\Components\TextInput::make('hours')->label(__('Ore'))->numeric() ->visible(fn (Get $get) => $get('kind') === 'labor'), Forms\Components\TextInput::make('qty')->label(__('Cantitate'))->numeric()->default(1) ->visible(fn (Get $get) => $get('kind') === 'part'), ]); } public function table(Table $table): Table { return $table ->recordTitleAttribute('name') ->columns([ Tables\Columns\TextColumn::make('kind') ->label(__('Tip')) ->formatStateUsing(fn ($s) => __(ServiceTemplateItem::KINDS[$s] ?? $s)) ->badge() ->color(fn ($s) => $s === 'labor' ? 'info' : 'gray'), Tables\Columns\TextColumn::make('name')->wrap(), Tables\Columns\TextColumn::make('hours')->label(__('Ore'))->placeholder('—')->alignRight(), Tables\Columns\TextColumn::make('qty')->label(__('Cant.'))->placeholder('—')->alignRight(), ]) ->headerActions([ Actions\CreateAction::make() ->label(__('Adaugă rând')) ->modalHeading(__('Adaugă rând în șablon')), ]) ->actions([ Actions\EditAction::make()->modalHeading(__('Editează rând')), Actions\DeleteAction::make(), ]) ->emptyStateHeading(__('Șablonul nu are rânduri')) ->emptyStateDescription(__('Adaugă manopere și piese care se aplică împreună când selectezi acest șablon pe o fișă.')) ->emptyStateIcon('heroicon-o-clipboard-document-list'); } }