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

import android.content.Context;
import android.content.Intent;
import android.view.View;
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.service.presenter.TruckInvoiceInputConfigConstact;
import cn.net.caoyao.cpzshandset.service.presenter.TruckInvoiceInputConfigConstact.Presenter;
import cn.net.caoyao.cpzshandset.ui.activity.base.BaseActivity;
import cn.net.caoyao.cpzshandset.ui.weight.AllCapTransformationMethod;
import cn.net.caoyao.cpzshandset.ui.weight.MyToast;

public class TruckInvoiceInputStyleConfigActivity extends BaseActivity
		implements TruckInvoiceInputConfigConstact.View, OnClickListener {
	private Context context;
	private MyToast myToast;
	private TruckInvoiceInputConfigConstact.Presenter presenter;
	private TextView tv_title_common, tv_truck_start_truck_input_liscense, tv_truck_start_station_content,
			tv_truck_create_terminal_station_code_content_content,tv_truck_create_terminal_station_content,tv_train_create_terminal_consignee,
			tv_truck_shipment_group_content,tv_truck_create_time_content,et_truck_create_responsible_person;
	private Button btn_title_more_option,btn_single_label,btn_pallet_label;
	private View lin_choice_truck_liscense, lin_truck_create_invoice_no, lin_truck_create_drivername,
			lin_truck_create_driverphone, lin_truck_create_start_station, rel_truck_start_station,
			btn_truck_chose_terminal_station_code,rel_truck_shipment_group,btn_truck_chose_time,
			lin_truck_create_responsible_person,lin_bottom;
	private EditText et_truck_create_truck_no, et_truck_create_invoice_no, et_truck_create_drivername,
			et_truck_create_driverphone;

	@Override
	public int loadView() {
		context = this;
		myToast = new MyToast(context);
		return R.layout.activity_truck_invoice_input_config_template;
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (myToast != null) {
			myToast.cancel();
		}
	}

	@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 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_truck_liscense = findViewById(R.id.lin_choice_truck_liscense);
		tv_truck_start_truck_input_liscense = (TextView) findViewById(R.id.tv_truck_start_truck_input_liscense);
		et_truck_create_truck_no = (EditText) findViewById(R.id.et_truck_create_truck_no);
		lin_truck_create_invoice_no = findViewById(R.id.lin_truck_create_invoice_no);
		et_truck_create_invoice_no = (EditText) findViewById(R.id.et_truck_create_invoice_no);
		lin_truck_create_drivername = findViewById(R.id.lin_truck_create_drivername);
		et_truck_create_drivername = (EditText) findViewById(R.id.et_truck_create_drivername);
		lin_truck_create_driverphone = findViewById(R.id.lin_truck_create_driverphone);
		et_truck_create_driverphone = (EditText) findViewById(R.id.et_truck_create_driverphone);
		lin_truck_create_start_station = findViewById(R.id.lin_truck_create_start_station);
		rel_truck_start_station = findViewById(R.id.rel_truck_start_station);
		tv_truck_start_station_content = (TextView) findViewById(R.id.tv_truck_start_station_content);
		tv_truck_create_terminal_station_code_content_content = (TextView) findViewById(R.id.tv_truck_create_terminal_station_code_content_content);
		btn_truck_chose_terminal_station_code = findViewById(R.id.btn_truck_chose_terminal_station_code);
		tv_truck_create_terminal_station_content = (TextView) findViewById(R.id.tv_truck_create_terminal_station_content);
		tv_train_create_terminal_consignee = (TextView) findViewById(R.id.tv_train_create_terminal_consignee);
		rel_truck_shipment_group = findViewById(R.id.rel_truck_shipment_group);
		tv_truck_shipment_group_content = (TextView) findViewById(R.id.tv_truck_shipment_group_content);
		tv_truck_create_time_content = (TextView) findViewById(R.id.tv_truck_create_time_content);
		btn_truck_chose_time = findViewById(R.id.btn_truck_chose_time);
		
		lin_truck_create_responsible_person = findViewById(R.id.lin_truck_create_responsible_person);
		et_truck_create_responsible_person = (TextView) findViewById(R.id.et_truck_create_responsible_person);
		
		lin_bottom = findViewById(R.id.lin_bottom);
		btn_single_label = (Button) findViewById(R.id.btn_single_label);
		btn_pallet_label = (Button) findViewById(R.id.btn_pallet_label);
	}

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

	@Override
	public void setListener() {
		lin_choice_truck_liscense.setOnClickListener(this);
		rel_truck_start_station.setOnClickListener(this);
		btn_truck_chose_terminal_station_code.setOnClickListener(this);
		tv_truck_create_terminal_station_content.setOnClickListener(this);
		tv_train_create_terminal_consignee.setOnClickListener(this);
		rel_truck_shipment_group.setOnClickListener(this);
		btn_truck_chose_time.setOnClickListener(this);
		et_truck_create_truck_no.setTransformationMethod(new AllCapTransformationMethod());
		btn_single_label.setOnClickListener(this);
		btn_pallet_label.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) {
			startActivityForResult(intent, reqCode);
		}
	}

	@Override
	public void showMsgToast(String msg, int duration) {
		if(myToast == null || msg == null) return;
		myToast.show(msg, duration);
	}

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

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

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

	@Override
	public void addCustomView(View view) {

	}

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

	@Override
	public void setTruckNoProvince(String letter) {
		if (tv_truck_start_truck_input_liscense == null || letter == null)
			return;
		tv_truck_start_truck_input_liscense.setText(letter + "");
	}

	@Override
	public String getTruckNo() {
		return et_truck_create_truck_no == null ? "" : et_truck_create_truck_no.getText().toString().trim().toUpperCase();
	}

	@Override
	public void setTruckNo(String trainNo) {
		if (et_truck_create_truck_no == null || trainNo == null)
			return;
		et_truck_create_truck_no.setText(trainNo + "");
	}

	@Override
	public void setOrderNo(String orderNoStr) {
		if (et_truck_create_invoice_no == null || orderNoStr == null)
			return;
		et_truck_create_invoice_no.setText(orderNoStr + "");
	}

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

	@Override
	public void setDriverName(String driverName) {
		if (et_truck_create_drivername == null || driverName == null)
			return;
		et_truck_create_drivername.setText(driverName);
	}

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

	@Override
	public void setDriverTel(String driverTel) {
		if (et_truck_create_driverphone == null || driverTel == null)
			return;
		et_truck_create_driverphone.setText(driverTel);
	}

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

	@Override
	public void setStartStation(String startStationStr) {
		if (tv_truck_start_station_content == null || startStationStr == null)
			return;
		tv_truck_start_station_content.setText(startStationStr + "");
	}

	@Override
	public void setEndStation(String endStationStr) {
		if (tv_truck_create_terminal_station_code_content_content == null || endStationStr == null)
			return;
		tv_truck_create_terminal_station_code_content_content.setText(endStationStr + "");
	}

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

	@Override
	public void setDate(String dateStr) {
		if(tv_truck_create_time_content == null || dateStr == null) return;
		tv_truck_create_time_content.setText(dateStr+"");
	}

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

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

	@Override
	public View getTruckNoProvinceView() {
		return lin_choice_truck_liscense;
	}

	@Override
	public TextView getTruckNoProvinceTextView() {
		return tv_truck_start_truck_input_liscense;
	}

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

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

	@Override
	public void setConsigneeStr(String consigneeStr) {
		if(tv_train_create_terminal_consignee == null || consigneeStr == null) return;
		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 void setDriverInfoVisiable(int visibility) {
		if (lin_truck_create_drivername != null)
			lin_truck_create_drivername.setVisibility(visibility);
		if (lin_truck_create_driverphone != null)
			lin_truck_create_driverphone.setVisibility(visibility);
	}

	@Override
	public void setOrderNoVisiable(int visibility) {
		if (lin_truck_create_invoice_no != null) {
			lin_truck_create_invoice_no.setVisibility(visibility);
		}
	}

	@Override
	public void setStartStationVisiable(int visibility) {
		if (lin_truck_create_start_station != null) {
			lin_truck_create_start_station.setVisibility(visibility);
		}
	}
	
	@Override
	public void setEndStationDetail(String detailStr) {
		if(tv_truck_create_terminal_station_content == null || detailStr == null) return;
		tv_truck_create_terminal_station_content.setText(detailStr+"");

	}

	@Override
	public String getEndStationDetail() {
		return tv_truck_create_terminal_station_content == null ? "" : tv_truck_create_terminal_station_content.getText().toString().trim();
	}
	@Override
	public TextView getGroupInfoTextView() {
		return tv_truck_shipment_group_content;
	}

	@Override
	public View getGroupInfoView() {
		return rel_truck_shipment_group;
	}

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

	@Override
	public void setGroupInfo(String groupStr) {
		if(tv_truck_shipment_group_content == null || groupStr == null) return;
		tv_truck_shipment_group_content.setText(groupStr);
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_title_more_option:
			if (presenter != null) {
				presenter.moreOptionClick();
			}
			break;
		case R.id.image_title_back_common:
			if (presenter != null) {
				presenter.backClick();
			}
			break;

		case R.id.lin_choice_truck_liscense:
			if (presenter != null) {
				presenter.choiceTruckNoProvince();
			}
			break;
		case R.id.rel_truck_start_station:
			if (presenter != null) {
				presenter.choiceStartStation();
			}
			break;
		case R.id.btn_truck_chose_terminal_station_code:
			if (presenter != null) {
				presenter.choiceEndStationCode();
			}
			break;
		case R.id.tv_truck_create_terminal_station_content:
			if (presenter != null) {
				presenter.inputEndStationDetail();
			}
			break;
		case R.id.tv_train_create_terminal_consignee:
			if (presenter != null) {
				presenter.inputConsignee();
			}
			break;
		case R.id.rel_truck_shipment_group:
			if (presenter != null) {
				presenter.choiceGroupInfo();
			}
			break;
		case R.id.btn_truck_chose_time:
			if (presenter != null) {
				presenter.choiceDate();
			}
			break;
		case R.id.btn_single_label:
			if(presenter == null) return;
			presenter.singleBtnClick();
			break;
		case R.id.btn_pallet_label:
			if(presenter == null) return;
			presenter.palletBtnClick();
			break;
		}
	}

	@Override
	public void setResponsiblePersonVisibiliy(int visibility) {
		if(lin_truck_create_responsible_person == null) return;
		lin_truck_create_responsible_person.setVisibility(visibility);
	}

	@Override
	public void setResponsiblePersonStr(String responsiblePreson) {
		if(et_truck_create_responsible_person == null || responsiblePreson == null) return;
		et_truck_create_responsible_person.setText(responsiblePreson);
	}

	@Override
	public void setBottomViewVisibiliy(int visibility) {
		if(lin_bottom == null) return;
		lin_bottom.setVisibility(visibility);
		
	}

	@Override
	public void setSingleBtnVisibiliy(int visibility) {
		if(btn_single_label == null) return;
		btn_single_label.setVisibility(visibility);
	}

	@Override
	public void setPalletBtnVisibiliy(int visibility) {
		if(btn_pallet_label == null) return;
		btn_pallet_label.setVisibility(visibility);
	}

	@Override
	public void setMoreOptionVisibiliy(int visibility) {
		if(btn_title_more_option == null) return;
		btn_title_more_option.setVisibility(visibility);
	}


}
