schema([ Forms\Components\Section::make('اطلاعات تعهدنامه') ->schema([ Forms\Components\TextInput::make('title') ->required() ->maxLength(255) ->label('عنوان'), Forms\Components\Textarea::make('description') ->nullable() ->rows(3) ->label('توضیحات'), Forms\Components\Select::make('direction') ->options([ 'export' => 'صادرات', 'import' => 'واردات', 'both' => 'هر دو', ]) ->default('both') ->required() ->label('جهت ارسال'), Forms\Components\Toggle::make('is_active') ->default(true) ->label('فعال'), Forms\Components\TextInput::make('sort_order') ->numeric() ->default(0) ->label('ترتیب نمایش'), ])->columns(2), Forms\Components\Section::make('فایل') ->schema([ FileUpload::make('file_path') ->label('فایل تعهدنامه') ->disk('public') ->directory('commitment-forms') ->acceptedFileTypes(['application/pdf', 'image/png', 'image/jpeg']) ->maxSize(10240) // 10MB ->required() ->columnSpanFull() ->extraAttributes(['class' => 'w-full']) ->getUploadedFileNameForStorageUsing(function ($file): string { $extension = $file->getClientOriginalExtension(); $filename = time() . '_' . uniqid() . '.' . $extension; return $filename; }), Forms\Components\Placeholder::make('file_info') ->label('اطلاعات فایل') ->content(function ($record) { if (!$record) return 'فایلی آپلود نشده'; $type = strtoupper(pathinfo($record->file_path, PATHINFO_EXTENSION)); $size = $record->formatted_size; return "فرمت: {$type} | حجم: {$size}"; }), ]), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('title') ->searchable() ->label('عنوان'), Tables\Columns\TextColumn::make('direction') ->badge() ->color(fn (string $state): string => match ($state) { 'export' => 'success', 'import' => 'info', 'both' => 'warning', }) ->formatStateUsing(fn (string $state): string => match ($state) { 'export' => 'صادرات', 'import' => 'واردات', 'both' => 'هر دو', }) ->label('جهت'), Tables\Columns\IconColumn::make('is_active') ->boolean() ->label('فعال'), Tables\Columns\TextColumn::make('sort_order') ->sortable() ->label('ترتیب'), Tables\Columns\TextColumn::make('uploader.name') ->label('آپلود کننده'), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable() ->label('تاریخ ایجاد'), ]) ->filters([ Tables\Filters\SelectFilter::make('direction') ->options([ 'export' => 'صادرات', 'import' => 'واردات', 'both' => 'هر دو', ]), Tables\Filters\TernaryFilter::make('is_active') ->label('فعال'), ]) ->actions([ Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(), Tables\Actions\Action::make('download') ->label('دانلود') ->icon('heroicon-o-arrow-down-tray') ->color('info') ->url(fn ($record) => $record->file_url) ->openUrlInNewTab(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]); } public static function getPages(): array { return [ 'index' => Pages\ListCommitmentForms::route('/'), 'create' => Pages\CreateCommitmentForm::route('/create'), 'edit' => Pages\EditCommitmentForm::route('/{record}/edit'), ]; } }