package com.bohuikeji.frame.module.admin.entity.web.block;

import com.bohuikeji.frame.module.admin.base.EntityBase;
import com.bohuikeji.frame.module.admin.base.HtmlBlockFormBase;
import com.bohuikeji.frame.module.admin.entity.configure.BaseInputAn;
import com.bohuikeji.frame.module.admin.entity.configure.FieldConf;
import lombok.Data;

import java.lang.reflect.Field;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 时间选择器元素快块
 * @author 10552
 */
@Data
public class DateBlock extends HtmlBlockFormBase<DateBlock> {

    /**
     * 控件样式
     */
    private String type="datetime";


    /**
     * 构造方法，必须调用父类，禁止使用无参构造函数初始化
     *
     * @param field
     */
    public DateBlock(Field field, EntityBase entity) {
        super(field, entity);
        if(field.getType()== LocalDateTime.class){
            type="datetime";
        }
        else if(field.getType()==LocalDate.class){
            type="date";
        }
        else{
            type="time";
        }

    }
    public DateBlock(FieldConf fieldConf, BaseInputAn inputAn){
        super(fieldConf,inputAn);
        if(LocalDateTime.class.getName().equals(fieldConf.getFieldType())){
            type="datetime";
        }
        else if(LocalDate.class.getName().equals(fieldConf.getFieldType())){
            type="date";
        }
        else{
            type="time";
        }

    }
}
