<?php

namespace App\Filament\Resources\Projects;

use App\Filament\Resources\Projects\Pages\ManageProjects;
use App\Models\Project;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class ProjectResource extends Resource
{
    protected static ?string $model = Project::class;

    protected static bool $shouldRegisterNavigation = false;

    protected static string|\BackedEnum|null $navigationIcon = Heroicon::OutlinedFolderOpen;

    protected static ?string $recordTitleAttribute = 'name';

    public static function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                TextInput::make('name')->label('Nome')->required()->maxLength(255),
                TextInput::make('client')->label('Cliente')->required()->maxLength(255),
                TextInput::make('fluig_number')->label('Fluig')->maxLength(30),
                TextInput::make('status')->label('Status')->required()->maxLength(50),
                TextInput::make('current_phase')->label('Fase atual')->required()->maxLength(100),
                Textarea::make('objective')->label('Objetivo')->required()->rows(4)->columnSpanFull(),
                Textarea::make('client_request')->label('Solicitação original')->required()->rows(10)->columnSpanFull(),
                Textarea::make('interpretation')->label('Nossa interpretação')->required()->rows(8)->columnSpanFull(),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')->label('Projeto')->searchable()->sortable(),
                TextColumn::make('client')->label('Cliente')->searchable()->sortable(),
                TextColumn::make('status')->label('Status')->badge(),
                TextColumn::make('current_phase')->label('Fase atual'),
                TextColumn::make('updated_at')->label('Atualizado em')->dateTime('d/m/Y H:i')->sortable(),
            ])
            ->recordActions([
                EditAction::make(),
            ]);
    }

    public static function getNavigationLabel(): string
    {
        return 'Projetos';
    }

    public static function getModelLabel(): string
    {
        return 'projeto';
    }

    public static function getPluralModelLabel(): string
    {
        return 'projetos';
    }

    public static function getPages(): array
    {
        return [
            'index' => ManageProjects::route('/'),
        ];
    }
}
