package com.zswc.creativity.utils;

import android.content.Context;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.zswc.creativity.inte.ChoiceData;
import com.ysnows.base.utils.TimeUtil;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by shihuiyun
 * on 2020/9/13
 */
public class PopupUtils {

    /**
     * 有回调
     * 选择时间
     */
    public static void setChoseTime(Context context, TextView tv, ChoiceData choiceData) {
//        Calendar startDate = Calendar.getInstance();
//        startDate.set(1980, 0, 23);

        Calendar endDate = Calendar.getInstance();
        endDate.set(2020, 12, 31);

        Calendar startDate = Calendar.getInstance();//当前时间

        TimePickerView timePickerView = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                //判断选择的其实
                Calendar cal = Calendar.getInstance();
                Date date2 = cal.getTime();

                boolean compareTo = date2.before(date);
                if(!compareTo){
                   Toast.makeText(context,"选择的时间不能小于当前时间！",Toast.LENGTH_SHORT).show();
                  return;
                }

                tv.setText(TimeUtil.getTime(date));
                if(null!=choiceData){
                    choiceData.onRestuse(TimeUtil.getTime(date));
                }

            }
        }).setRangDate(startDate, endDate)
                .setDate(endDate)
                .setType(new boolean[]{true, true, true, true, true, true})
                .build();

        timePickerView.setDate(Calendar.getInstance());
        timePickerView.show();
    }

    public static void setChoseTime(Context context,ChoiceData choiceData) {
//        Calendar startDate = Calendar.getInstance();
//        startDate.set(1980, 0, 23);

        Calendar startDate = Calendar.getInstance();//当前时间


        Calendar endDate = Calendar.getInstance();
        endDate.set(2020, 12, 31);


        TimePickerView timePickerView = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                //判断选择的其实
                Calendar cal = Calendar.getInstance();
                Date date2 = cal.getTime();

                boolean compareTo = date2.before(date);
                if(!compareTo){
                    Toast.makeText(context,"选择的时间不能小于当前时间！",Toast.LENGTH_SHORT).show();
                    return;
                }

                if(null!=choiceData){
                    choiceData.onRestuse(TimeUtil.getTime(date));
                }

            }
        }).setRangDate(startDate, endDate)
                .setDate(endDate)
                .setType(new boolean[]{true, true, true, true, true, true})
                .build();

        timePickerView.setDate(Calendar.getInstance());
        timePickerView.show();
    }



    /**
     * 有回调
     * 选择时间
     * 年-月-日
     */
    public static void setChoseTime(Context context, TextView tv, int year,ChoiceData choiceData) {
        Calendar startDate = Calendar.getInstance();
        startDate.set(1980, 0, 23);

        Calendar endDate = Calendar.getInstance();
        endDate.set(year, 12, 31);

//        Calendar endDate = Calendar.getInstance();//当前时间

        TimePickerView timePickerView = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                if(null!=tv) {
                    tv.setText(TimeUtil.getTime(date));
                }
                if(null!=choiceData){
                    choiceData.onRestuse(TimeUtil.getTimeTo(date));
                }

            }
        }).setRangDate(startDate, endDate)
                .setDate(endDate)
                .setType(new boolean[]{true, true, true, false, false, false})
                .build();

        timePickerView.setDate(Calendar.getInstance());
        timePickerView.show();
    }







}
