<?php

namespace Dreamfox\DeliveryDate\Views;

use Dreamfox\DeliveryDate\Helpers\TimeslotHelper;
use Dreamfox\DeliveryDate\Interfaces\ApplicationInterface;
use Dreamfox\DeliveryDate\Repositories\OrderRepository;
class EmailView extends BaseView {
    protected $_orderId;

    public function __construct( ApplicationInterface $app, $order ) {
        parent::__construct( $app );
        $this->setTemplate( 'email_view' );
        $this->_orderId = $order;
    }

    public function getDeliveryDate() {
        $repository = new OrderRepository($this->_orderId);
        $data = $repository->load();
        $deliveryDate = $data->getDeliveryDate();
        if ( empty( $deliveryDate ) ) {
            return $deliveryDate;
        }
        $dateYmd = TimeslotHelper::parseDateToYmd( $deliveryDate );
        $dateObj = \DateTime::createFromFormat( 'Y-m-d', $dateYmd );
        if ( !$dateObj ) {
            return $deliveryDate;
        }
        return wp_date( get_option( 'date_format' ), $dateObj->getTimestamp() );
    }

    public function getTimeslot() {
        $repository = new OrderRepository($this->_orderId);
        $data = $repository->load();
        return $data->getTimeslot();
    }

    public function getLabel() {
        $label = 'Select delivery date';
        return $label;
    }

}
