<?php
namespace Autogedal\Extend\Block\Adminhtml\Question\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Magento\Backend\Block\Widget\Context;
use Magediary\ProductQuestion\Model\ResourceModel\Answer\CollectionFactory;

class AnswerButton implements ButtonProviderInterface
{
    protected $context;
    protected $_answersColFactory;

    public function __construct(
        Context $context,
        CollectionFactory $_answersColFactory
    ) {
        $this->_answersColFactory = $_answersColFactory;
        $this->context = $context;
    }

    public function getButtonData()
    {
        $questionId = $this->context->getRequest()->getParam('question_id');
        
        if (!$questionId) {
            return [];
        }

        return [
            'label' => __('Answer Question'),
            'class' => 'save secondary',
            'on_click' => sprintf(
                "location.href = '%s';",
                $this->context->getUrlBuilder()->getUrl(
                    'magediary_productquestion/answer/new',
                    ['question_id' => $questionId]
                )
            ),
            'sort_order' => 550
        ];
    }
}
