<?php
namespace Dreamfox\DeliveryDate\Premium;

use Dreamfox\DeliveryDate\Abstracts\AbstractCheckoutFieldManager;
use Dreamfox\DeliveryDate\Helpers\CartHelper;
use Dreamfox\DeliveryDate\Premium\Facades\SystemFacade;

class CheckoutFieldManager extends AbstractCheckoutFieldManager
{

  public function process()
  {
    $system = SystemFacade::getInstance();
    $categorySetting = $system->loadCategorySettings();
    $appliedCategories = $categorySetting->getCategories();
    $appliedCategories = array_map(function($item) {
      return $item->id;
    }, $appliedCategories);
    if (!$this->_isAvailable($appliedCategories)) {
      return;
    }
    $commonSetting = $system->loadCommonSettings();
    $datesToDeliver = $commonSetting->getDeliveryDays();
    $minDeliveryDate = $this->_getMinDeliveryDate($datesToDeliver);
    $otherSetting = $system->loadOtherSettings();
    $label = $otherSetting->getLabelOnCheckout();
    $required = $otherSetting->getRequired();
		$this->_fields[DREAMFOX_WDD_FIELD_NAME] = array(
			DREAMFOX_WDD_FIELD_NAME => array(
				'type' => 'text',
				'class' => array('dreamfox-delivery-date form-row-wide'),
				'label' => $label,
				'default' => $minDeliveryDate,
				'required' => $required,
			)
		);
  }
}