package com.usai.redant.CommonEditor.CommonEditor;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.usai.redant.CommonEditor.CommonEditorActivity;
import com.usai.redant.CommonEditor.DatePickerActivity;
import com.usai.redant.redantmobile.R;

import org.json.JSONObject;

/**
 * Created by macmini1 on 2017/12/13.
 */

public class CommonEditorDateRangeCellHolder extends CommonEditorCellHolder {

    public TextView title_lb;
    public Button min_btn;
    public Button max_btn;
    public Button reset_btn;
    public DateButtonClickListener clickListener;

    public CommonEditorDateRangeCellHolder(Context context, View view) {
        super(context, view);

        title_lb = view.findViewById(R.id.range_title_tv);
        min_btn = view.findViewById(R.id.range_minimum_btn);
        max_btn = view.findViewById(R.id.range_maximum_btn);
        reset_btn = view.findViewById(R.id.range_reset_btn);

        clickListener = new DateButtonClickListener();
        min_btn.setOnClickListener(clickListener);
        max_btn.setOnClickListener(clickListener);

        reset_btn.setOnClickListener(new ResetClickListener());

    }

    private class ResetClickListener implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            ((CommonEditorActivity)mCtx).commonEditorRangeDidChange("","",group,child);
        }
    }



    @Override
    public void setItem(JSONObject item_json, boolean readonly, View view) {
        super.setItem(item_json, readonly, view);
    }

    public class DateButtonClickListener implements View.OnClickListener {

        @Override
        public void onClick(View view) {

            Intent intent = new Intent(mCtx, DatePickerActivity.class);

            intent.putExtra("group",group);
            intent.putExtra("child",child);

            if (view.equals(min_btn)) {
                intent.putExtra("value","min");
            } else {
                intent.putExtra("value","max");
            }

            intent.putExtra("min",min_btn.getText().toString());
            intent.putExtra("max",max_btn.getText().toString());

            ((Activity)mCtx).startActivityForResult(intent,14);

        }
    }
}
