package cn.net.caoyao.cpzshandset.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.common.util.StringUtils;
import cn.net.caoyao.cpzshandset.service.presenter.TrainInvoiceConfigConstact;
import cn.net.caoyao.cpzshandset.service.presenter.TrainInvoiceConfigConstact.Presenter;
import cn.net.caoyao.cpzshandset.ui.activity.base.BaseActivity;
import cn.net.caoyao.cpzshandset.ui.weight.MyToast;

public class TrainInvoiceConfigActivity extends BaseActivity implements TrainInvoiceConfigConstact.View, OnClickListener{

	private TrainInvoiceConfigConstact.Presenter presenter;
	private TextView tv_title_common,tv_train_letter,tv_train_start_station_content,tv_train_create_terminal_station_content,
	tv_train_create_time_content,tv_train_create_terminal_consignee;
	private View lin_choice_train_letter,btn_train_letter,rel_train_start_station,btn_train_start_station_content,
	btn_train_chose_terminal_station,btn_train_chose_time,btn_train_invoice_complete,btn_train_chose_consignee;
	private EditText et_create_train_no,et_train_create_invoice_no;
	private Button btn_title_more_option;
	private ViewGroup lin_train_invoice_custom_view;
	private MyToast myToast;
	private Context context;
	@Override
	public int loadView() {
		context = this;
		myToast = new MyToast(context);
		return R.layout.activity_train_invoice_config_template;
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (myToast != null) {
			myToast.cancel();
		}
	}
	@Override
	public void initTitleView() {
		View image_title_back_common = findViewById(R.id.image_title_back_common);
		image_title_back_common.setVisibility(View.VISIBLE);
		image_title_back_common.setOnClickListener(this);
		tv_title_common = (TextView) findViewById(R.id.tv_title_common);
		btn_title_more_option = (Button) findViewById(R.id.btn_title_more_option);
		btn_title_more_option.setVisibility(View.VISIBLE);
		btn_title_more_option.setOnClickListener(this);
	}

	@Override
	public void initView() {
		lin_choice_train_letter = findViewById(R.id.lin_choice_train_letter);
		tv_train_letter = (TextView) findViewById(R.id.tv_train_letter);
		btn_train_letter = findViewById(R.id.btn_train_letter);
		et_create_train_no = (EditText) findViewById(R.id.et_create_train_no);
		et_train_create_invoice_no = (EditText) findViewById(R.id.et_train_create_invoice_no);
		rel_train_start_station = findViewById(R.id.rel_train_start_station);
		btn_train_start_station_content = findViewById(R.id.btn_train_start_station_content);
		tv_train_start_station_content = (TextView) findViewById(R.id.tv_train_start_station_content);
		tv_train_create_terminal_station_content = (TextView) findViewById(R.id.tv_train_create_terminal_station_content);
		btn_train_chose_terminal_station = findViewById(R.id.btn_train_chose_terminal_station);
		tv_train_create_time_content = (TextView) findViewById(R.id.tv_train_create_time_content);
		btn_train_chose_time = findViewById(R.id.btn_train_chose_time);
		btn_train_invoice_complete = findViewById(R.id.btn_train_invoice_complete);
		lin_train_invoice_custom_view = (ViewGroup) findViewById(R.id.lin_train_invoice_custom_view);
		tv_train_create_terminal_consignee = (TextView) findViewById(R.id.tv_train_create_terminal_consignee);
		btn_train_chose_consignee = findViewById(R.id.btn_train_chose_consignee);
	}

	@Override
	public void initPresenter() {
		presenter = createService.createTrainConfigPresenter(cacheG, this, this, getIntent());
		
	}

	@Override
	public void setListener() {
		lin_choice_train_letter.setOnClickListener(this);
//		btn_train_start_station_content.setOnClickListener(this);
		btn_train_chose_terminal_station.setOnClickListener(this);
		btn_train_chose_time.setOnClickListener(this);
		btn_train_invoice_complete.setOnClickListener(this);
		btn_train_chose_consignee.setOnClickListener(this);
		rel_train_start_station.setOnClickListener(this);
	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setPresenter(Presenter presenter) {
		if (presenter != null) {
			this.presenter = presenter;
		}
		
	}

	@Override
	public void startAcForResult(int reqCode, Intent intent) {
		if(intent == null) return;
		startActivityForResult(intent, reqCode);
		
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (presenter != null) {
			presenter.onActivityResult(requestCode, resultCode, data);
		}
	}
	@Override
	public void showMsgToast(String msg, int duration) {
		if (myToast == null || StringUtils.isEmpty(msg) || duration < 0) return;
		myToast.show(msg, duration);
	}

	@Override
	public void setPageTitle(String homeTitle) {
		if (tv_title_common != null && homeTitle != null) {
			tv_title_common.setText(homeTitle +"");
		}
		
	}

	@Override
	public void finishPage() {
		finish();
		
	}

	@Override
	public void addCustomView(View view) {
		if(lin_train_invoice_custom_view == null || view == null) return;
		lin_train_invoice_custom_view.removeAllViews();
		lin_train_invoice_custom_view.addView(view);
		
	}

	@Override
	public String getTrainLetter() {
		return tv_train_letter == null ? "" : tv_train_letter.getText().toString().trim();
	}

	@Override
	public void setTrainLetter(String letter) {
		if (tv_train_letter != null && letter != null) {
			tv_train_letter.setText(letter+"");
		}
	}

	@Override
	public String getTrainNo() {
		return et_create_train_no == null ? "" : et_create_train_no.getText().toString().trim();
	}

	@Override
	public void setTrainNo(String trainNo) {
		if (et_create_train_no != null && trainNo != null) {
			et_create_train_no.setText(trainNo+"");
		}
	}

	@Override
	public void setOrderNo(String orderNoStr) {
		if (et_train_create_invoice_no != null && orderNoStr != null) {
			et_train_create_invoice_no.setText(orderNoStr);
		}
	}

	@Override
	public String getOrderNo() {
		return et_train_create_invoice_no == null ?"":et_train_create_invoice_no.getText().toString().trim();
	}

	@Override
	public void setStartStation(String startStationStr) {
		if (tv_train_start_station_content != null && startStationStr != null) {
			tv_train_start_station_content.setText(startStationStr+"");
		}
	}

	@Override
	public void setEndStation(String endStationStr) {
		if (tv_train_create_terminal_station_content != null && endStationStr != null) {
			tv_train_create_terminal_station_content.setText(endStationStr);
		}
	}

	@Override
	public void setDate(String dateStr) {
		if (tv_train_create_time_content != null && dateStr != null) {
			tv_train_create_time_content.setText(dateStr +"");
		}
	}

	@Override
	public String getDate() {
		return tv_train_create_time_content == null ? "" : tv_train_create_time_content.getText().toString().trim();
	}

	@Override
	public View getLetterView() {
		return lin_choice_train_letter;
	}

	@Override
	public TextView getLetterTextView() {
		return tv_train_letter;
	}

	@Override
	public View getStartStationView() {
		return rel_train_start_station;
	}

	@Override
	public TextView getStartStationTextView() {
		return tv_train_start_station_content;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.image_title_back_common:
			finish();
			break;

		case R.id.lin_choice_train_letter:
			if (presenter != null) {
				presenter.choiceTrainLetter();
			}
			break;
		case R.id.rel_train_start_station:
			if (presenter != null) {
				presenter.choiceStartStation();
			}
			break;
		case R.id.btn_train_chose_terminal_station:
			if (presenter != null) {
				presenter.choiceEndStation();
			}
			break;
		case R.id.btn_train_chose_time:
			if (presenter != null) {
				presenter.choiceDate();
			}
			break;
		case R.id.btn_train_invoice_complete:
			if (presenter != null) {
				presenter.complete();
			}
			break;
		case R.id.btn_title_more_option:
			if (presenter != null) {
				presenter.moreOptionClick();
			}
			break;
		case R.id.btn_train_chose_consignee:
			if (presenter != null) {
				presenter.choiceConsigneeClick();
			}
			break;
		}
		
	}

	@Override
	public void setMoreOptionStr(String moreOptionStr) {
		if (btn_title_more_option != null && moreOptionStr != null) {
			btn_title_more_option.setText(moreOptionStr);
		}
		
	}

	@Override
	public void setConsigneeStr(String consigneeStr) {
		if(tv_train_create_terminal_consignee != null && consigneeStr != null){
			tv_train_create_terminal_consignee.setText(consigneeStr+"");
		}
		
	}

	@Override
	public String getConsigneeStr() {
		return tv_train_create_terminal_consignee == null ? "" : tv_train_create_terminal_consignee.getText().toString().trim();
	}

	@Override
	public TextView getDateTextView() {
		return tv_train_create_time_content;
	}

	@Override
	public String getEndStationName() {
		return tv_train_create_terminal_station_content == null ? "" :tv_train_create_terminal_station_content.getText().toString();
	}

}
