<?php

namespace FiloBlu\Esb\Ui\Component\Producer\Listing\Column;

use FiloBlu\Esb\Api\Data\ProducerConfigurationInterface;
use Magento\Ui\Component\Listing\Columns\Column;

/**
 * Class Actions
 * @package FiloBlu\Esb\Ui\Component\Producer\Listing\Column
 */
class Actions extends Column
{
    /**
     * Prepare Data Source
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                $item[$this->getData('name')] = [
                    'edit' => [
                        'href' => $this->context->getUrl(
                            'esb/producer/edit',
                            (isset($item[ProducerConfigurationInterface::ID]) ? ['id' => $item[ProducerConfigurationInterface::ID]] : [])
                        ),
                        'label' => __('Edit')
                    ]
                ];
            }
        }

        return $dataSource;
    }
}
