<?php

namespace App\Filament\Resources\PatientResource\RelationManagers;

use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class VisitsRelationManager extends RelationManager
{
    protected static string $relationship = 'visits';

    public function form(Form $form): Form
    {
        return $form
            ->schema([
            Forms\Components\Select::make('chamber_id')
            ->relationship('chamber', 'name')
            ->required(),
            Forms\Components\DateTimePicker::make('visit_date')
            ->required(),
            Forms\Components\Select::make('status')
            ->options([
                'Scheduled' => 'Scheduled',
                'Completed' => 'Completed',
                'Cancelled' => 'Cancelled',
            ])
            ->required(),
            Forms\Components\TextInput::make('fee_collected')
            ->numeric()
            ->prefix('৳'),
        ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('id')
            ->columns([
            Tables\Columns\TextColumn::make('visit_date')
            ->dateTime()
            ->sortable(),
            Tables\Columns\TextColumn::make('chamber.name')
            ->label('Clinic'),
            Tables\Columns\BadgeColumn::make('status')
            ->colors([
                'warning' => 'Scheduled',
                'success' => 'Completed',
                'danger' => 'Cancelled',
            ]),
            Tables\Columns\TextColumn::make('fee_collected')
            ->money('BDT'),
        ])
            ->filters([
            //
        ])
            ->headerActions([
            Tables\Actions\CreateAction::make(),
        ])
            ->actions([
            Tables\Actions\EditAction::make(),
            Tables\Actions\DeleteAction::make(),
        ])
            ->bulkActions([
            Tables\Actions\BulkActionGroup::make([
                Tables\Actions\DeleteBulkAction::make(),
            ]),
        ]);
    }
}
