<?php
namespace Extension;
 use TCMS\ControlExtension;
 use TCMS\TException;
 class DateTimePickerDefault extends ControlExtension {
 public $option = [ 'name' => 'datetime', 'format' => 'd/m/Y H:i', 'error' => false ];
 public function render($value, $option = null) {
 if(empty($option['name'])) throw new TException('Vui lòng truyền option cho extension datetime picker', 501);
 copy_option($this->option, $option);
 $this->addStyle(asset('/style/bootstrap.min.css'));
 $this->addStyle(asset('/style/datetime-picker-default/pikaday.min.css'));
 if($value && $value instanceof \DateTime) {
 $value = $value->format($this->option['format']);
 }
 else if($value) {
 if($this->option['format'] == 'H:i' || $this->option['format'] == 'H:i:s') {
 $a = explode(' ', $value);
 if(count($a) > 1) $value = $a[1];
 }
 }
 $className = $this->option['format'] == 'H:i' || $this->option['format'] == 'H:i:s' ? "time-picker-ext" : "datetime-picker-ext";
 echo '<input autocomplete="off" type="text" data-format="'.$this->option['format'].'" name="'.$this->option['name'].'" value="'.$value.'" class="'. $className .' form-control'. ($this->option['error'] ? ' error' : '') .'" id="'.$this->option['name'].'" />';
 $this->addScript(asset('/script/jquery.min.js'));
 if($this->option['format'] == 'H:i' || $this->option['format'] == 'H:i:s') {
 $this->addStyle(asset('/clockpicker/jquery-clockpicker.min.css'));
 $this->addScript(asset('/clockpicker/jquery-clockpicker.min.js'));
 $this->addScript(asset('/script/datetime-picker-default/time-picker-default.js'));
 }
 else {
 $this->addScript(asset('/script/datetime-picker-default/moment.min.js'));
 $this->addScript(asset('/script/datetime-picker-default/pikaday.min.js'));
 $this->addScript(asset('/script/datetime-picker-default/datetime-picker-default.js'));
 }
 }
 }
 ?>