<?php
namespace Autogedal\AutogedalHelper\Model\Config\Source;

class CategoryTree implements \Magento\Framework\Option\ArrayInterface
{
    protected $categoryCollectionFactory;
    
    public function __construct(
        \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
    ) {
        $this->_categoryCollectionFactory = $categoryCollectionFactory;
    }

    public function toOptionArray()
    {
        $this->_categoryCollectionFactory->create()->addAttributeToSelect('*')->addAttributeToFilter('level',['eq'=> 2]);
        $attributesArrays = [];

        if (!empty($categories)) {
            foreach ($categories as $category) {
                $attributesArrays[] =array(
                    'label' => $category->getName(),
                    'value' => $category->getId(),
                );
            }
        }

        return $attributesArrays;
    }
}