New-Thanasoft/thanasoft-back/app/Http/Resources/Client/ClientActivityTimelineResource.php
2026-01-12 16:37:41 +03:00

67 lines
2.2 KiB
PHP

<?php
namespace App\Http\Resources\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ClientActivityTimelineResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'client_id' => $this->client_id,
'actor_type' => $this->actor_type,
'actor_name' => $this->actor ? $this->actor->firstname . ' ' . $this->actor->lastname : 'System',
'event_type' => $this->event_type,
'entity_type' => $this->entity_type,
'entity_id' => $this->entity_id,
'title' => $this->title,
'description' => $this->description,
'metadata' => $this->metadata,
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
'time_ago' => $this->created_at?->diffForHumans(),
// Helper properties for frontend display
'icon' => $this->getIcon(),
'color' => $this->getColor(),
];
}
protected function getIcon()
{
// Map event types to icons (using Nucleo icons as requested)
return match($this->event_type) {
'call' => 'mobile-button',
'email_sent', 'email_received' => 'email-83',
'invoice_created', 'invoice_sent', 'invoice_paid' => 'money-coins',
'quote_created', 'quote_sent' => 'single-copy-04',
'file_uploaded', 'attachment_sent', 'attachment_received' => 'cloud-upload-96',
'client_created' => 'badge-24',
'meeting', 'intervention_created' => 'laptop',
default => 'bell-55'
};
}
protected function getColor()
{
// Map event types to colors
return match($this->event_type) {
'client_created' => 'success',
'call' => 'info',
'email_sent' => 'success',
'invoice_paid' => 'success',
'invoice_created' => 'warning',
'quote_created' => 'primary',
'quote_sent' => 'primary',
default => 'dark'
};
}
}