<?php

namespace App\Filament\Resources\Panel\AttendanceResource\RelationManagers;

use Filament\Forms;
use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Checkbox;
use Filament\Tables\Columns\TextColumn;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Columns\ImageColumn;
use Illuminate\Database\Eloquent\Builder;
use Filament\Forms\Components\FileUpload;
use Filament\Tables\Columns\CheckboxColumn;
use App\Filament\Resources\Panel\AttendanceResource;
use Filament\Resources\RelationManagers\RelationManager;

class EmployeesRelationManager extends RelationManager
{
    protected static string $relationship = 'employees';

    protected static ?string $recordTitleAttribute = 'name';

    public function form(Form $form): Form
    {
        return $form->schema([
            Grid::make(['default' => 1])->schema([
                TextInput::make('name')
                    ->required()
                    ->string()
                    ->autofocus(),

                TextInput::make('address')
                    ->nullable()
                    ->string(),

                TextInput::make('phone')
                    ->nullable()
                    ->string(),

                // Checkbox::make('active')
                //     ->rules(['boolean'])
                //     ->nullable()
                //     ->inline(),

                // FileUpload::make('photo')
                //     ->rules(['image'])
                //     ->nullable()
                //     ->maxSize(1024)
                //     ->image()
                //     ->imageEditor()
                //     ->imageEditorAspectRatios([null, '16:9', '4:3', '1:1']),
            ]),
        ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name'),

                TextColumn::make('address'),

                TextColumn::make('phone'),

                // CheckboxColumn::make('active'),

                // ImageColumn::make('photo')->visibility('public'),
            ])
            ->filters([])
            ->headerActions([
                // Tables\Actions\CreateAction::make(),

                Tables\Actions\AttachAction::make()->form(
                    fn(Tables\Actions\AttachAction $action): array => [
                        $action->getRecordSelect(),
                    ]
                ),
            ])
            ->actions([
                // Tables\Actions\EditAction::make(),
                // Tables\Actions\DeleteAction::make(),
                Tables\Actions\DetachAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),

                    Tables\Actions\DetachBulkAction::make(),
                ]),
            ]);
    }
}
