<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class DashboardProject extends Model
{
    protected $fillable = [
        'title',
        'icon',
        'start_color',
        'end_color',
        'link',
        'is_active',
        'allowed_for_inactive',
        'off_popup_title',
        'off_popup_message',
        'inactive_popup_title',
        'inactive_popup_message',
        'blocked_referrals',
        'blocked_popup_title',
        'blocked_popup_message',
        'sort_order',
    ];

    // Blocked referrals -> array (trim + lower)
    public function blockedRefArray(): array
    {
        if (!$this->blocked_referrals)
            return [];
        $raw = str_replace(["\r"], '', $this->blocked_referrals);
        $parts = preg_split('/[\n,]+/', $raw);
        return array_values(array_filter(array_map(function ($v) {
            return strtolower(trim($v));
        }, $parts)));
    }
}
