<?php

namespace App\Form\Input;

class CreditCardDetails extends \Engine\Form\Input\ElementWithElements
{

	/**
	 * Determines the display template.
	 * @var string
	 */
	protected $class = "creditCardDetails";


	public function __construct($label=null, $name=null, $value=null)
	{
		parent::__construct($label, $name, null);
		$this->setStyle('renderOrder', ['main', 'post']);
		$this->setStyle('renderMode', 'inline');

		// number
		$ccNumberFld = \App\Form\Input\CreditCardNumber::create(null, $name.'[number]', $value['number']);
		$this->addElement( $ccNumberFld, 'main' );

		// company
		$ccCompanyFld = \App\Form\Input\Select_CreditCardVendors::create(null, $name.'[company]', $value['company']);
		$ccCompanyFld->showDefaultOption(true);
		$this->addElement( $ccCompanyFld, 'post');

		// expire date
		$_LANG = \App\Loader_Lang::getInstance()->getGlobal();
		$possibleValues = [];
		for ( $y = TODAY_YEAR-1 ; $y<=TODAY_YEAR + 6 ; $y++ ) {
			$possibleValues[$y] = [];
			for ($m=1 ; $m<=12 ; $m++) {
				$possibleValues[$y][$y.'-'.sprintf('%02d', $m)] = $_LANG['date']['month']['short'][$m].' '.($y%100);
			}
		}
		$expireDateFld = \Engine\Form\Input\Select::create(null, $name.'[expireYm]', $value['expireYm']);
		$expireDateFld->showDefaultOption();
		$expireDateFld->setPossibleValues($possibleValues);
		$this->addElement( $expireDateFld, 'post');

	}

}
