<?php
/**
 * Column field for sender name in quote conversation grid
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */

namespace Magetop\Quotesystem\Block\Adminhtml\Managequotes\Grid;

use Magetop\Quotesystem\Helper\Data;
use Magetop\Quotesystem\Api\QuoteRepositoryInterface;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;

class RendererReceiverTime extends AbstractRenderer
{
    /**
     * Array to store all options data
     *
     * @var array
     */
    protected $_actions = [];
    /**
     * @var Magetop\Quotesystem\Helper\Data
     */
    protected $_quoteHelper;
    /**
     * @var Magetop\Quotesystem\Api\QuoteRepositoryInterface
     */
    protected $_quoteRepository;
    /**
     * @var Context
     */
    protected $_timezone;
    /**
     * @var \Magetop\Quotesystem\Helper\Data
     */
    protected $_helper;
    /**
     * @param \Magento\Backend\Block\Context    $context
     * @param Data                              $quoteHelper
     * @param \Magetop\Quotesystem\Helper\Data   $dataHelper
     * @param QuoteRepositoryInterface          $quoteRepository
     * @param \Magento\Framework\Escaper        $escaper
     * @param array                             $data
     */
    public function __construct(
        \Magento\Backend\Block\Context $context,
        Data $quoteHelper,
        \Magetop\Quotesystem\Helper\Data $dataHelper,
        QuoteRepositoryInterface $quoteRepository,
        \Magento\Framework\Escaper $escaper,
        array $data = []
    ) {
        $this->_quoteHelper = $quoteHelper;
        $this->_quoteRepository = $quoteRepository;
        $this->_timezone = $context->getLocaleDate();
        $this->_helper = $dataHelper;
        $this->escaper = $escaper;
        parent::__construct($context, $data);
    }

    /**
     * Render
     *
     * @param \Magento\Framework\DataObject $row
     * @return string
     */
    public function render(\Magento\Framework\DataObject $row)
    {
        $time = $row->getData($this->getColumn()->getIndex());
        return $this->_localeDate->date(
            new \DateTime($this->_localeDate->date(new \DateTime($time))->format('Y-m-d H:i:s'))
        )->format('M j, Y, H:i:s A');
    }

    /**
     * Render options array as a HTML string
     *
     * @param  array $actions
     * @return string
     */
    protected function _actionsToHtml(array $actions = [])
    {
        $html = [];
        $attributesObject = new \Magento\Framework\DataObject();

        if (empty($actions)) {
            $actions = $this->_actions;
        }
        foreach ($actions[0] as $action) {
            $html[] = '<span>' . $action . '</span>';
        }
        return implode('', $html);
    }

    /**
     * Add one action array to all options data storage
     *
     * @param  array $actionArray
     * @return void
     */
    public function addToActions($actionArray)
    {
        $this->_actions[] = $actionArray;
    }
}
