<?php

namespace App\Modules\Shared\Domain;

class ActionUtils
{

    /**
     * @param ActionElement[] $actionList
     */
    public static function find(string $action, array $actionList)
    {
        if (empty($actionList)) {
            return [];
        }

        foreach ($actionList as $value) {
            if ($value->name == $action) {
                return $value->values;
            }
        }
        $default = ArrayUtils::find($actionList, fn(ActionElement $value) => $value->defaultValue);
        return $default->values ?? $actionList[0]->values;
    }
}
