public function toArray($values = []): array
    {
        if (! $values) {
            $values = $this->all();
        }

        $array = [];

        if (is_array($values)) {
            foreach ($values as $key => $value) {
                $array[$key] = is_array($value) ? $this->toArray($value) : $value;

                // Convert Item object instance to an array
                if (is_object($value)) {
                    $array[$key] = [
                        'title'    => $value->title,
                        'url'      => $value->url,
                        'children' => $value->children,
                        'fields'   => $value->fields
                    ];

                    // Use recursion to convert all child elements
                    if ($value->children) {
                        $array[$key]['children'] = $this->toArray($value->children);
                    }
                }
            }
        }

        return $array;
    }