<?php
namespace PortalPeople\DisabledDates\Block\Adminhtml;

class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
{
    protected $_collectionFactory;
    protected $_logger;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Backend\Helper\Data $backendHelper,
        \PortalPeople\DisabledDates\Model\ResourceModel\DisabledDate\CollectionFactory $collectionFactory,
        array $data = []
    ) {
        $this->_collectionFactory = $collectionFactory;
        parent::__construct($context, $backendHelper, $data);
    }

    public function getGridUrl()
    {
        return $this->getUrl('*/*/grid', ['_current' => true]);
    }

    protected function _prepareCollection()
    {
        try {
            $collection = $this->_collectionFactory->create();
            $this->setCollection($collection);
            return parent::_prepareCollection();
        } catch (\Exception $e) {
            $this->_logger->error('DisabledDates Grid Collection Error: ' . $e->getMessage());
            $this->setCollection(new \Magento\Framework\Data\Collection());
            return $this;
        }
    }

    protected function _prepareColumns()
    {
        // Ensure all columns have proper sorting/filtering setup
        $this->addColumn('entity_id', [
            'header' => __('ID'),
            'type' => 'number',
            'index' => 'entity_id',
            'header_css_class' => 'col-id',
            'column_css_class' => 'col-id'
        ]);
        
        return parent::_prepareColumns();
    }
}