<?php

namespace App\Filament\Tenant\Resources\TaskCollectionResource\Pages;

use App\Filament\Tenant\Resources\TaskCollectionResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;

class CreateTaskCollection extends CreateRecord
{
    protected static string $resource = TaskCollectionResource::class;

    protected function mutateFormDataBeforeCreate(array $data): array
    {
        $tenantId = Auth::user()?->tenant_id;

        $data['tenant_id'] = $tenantId;
        $data['slug'] = TaskCollectionResource::generateSlug(
            $data['name_translations']['en'] ?? $data['name_translations']['de'] ?? 'collection',
            $tenantId
        );

        return $data;
    }
}
