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.common.util.StringUtils;
import cn.net.caoyao.cpzshandset.service.presenter.TruckInvoiceConfigConstact;
import cn.net.caoyao.cpzshandset.service.presenter.TruckInvoiceConfigConstact.Presenter;
import cn.net.caoyao.cpzshandset.ui.activity.base.BaseActivity;
import cn.net.caoyao.cpzshandset.ui.weight.MyToast;

public class TruckInvoiceConfigActivity extends BaseActivity implements TruckInvoiceConfigConstact.View, OnClickListener {
	private Context context;
	private TruckInvoiceConfigConstact.Presenter presenter;
	private TextView tv_truck_start_struck_liscense, tv_truck_start_station_content,
			tv_truck_create_terminal_station_content, tv_truck_create_time_content,
			tv_title_common;
	private View lin_choice_truck_liscense, btn_truck_chose_terminal_station, btn_truck_chose_time,
			btn_truck_invoice_complete, rel_truck_start_station;// btn_truck_start_station_content
	private EditText et_truck_create_truck_no, et_truck_create_invoice_no, et_truck_create_drivername,
			et_truck_create_driverphone;
	private Button btn_title_more_option;
	private MyToast myToast;

	@Override
	public int loadView() {
		context = this;
		myToast = new MyToast(context);
		return R.layout.activity_truck_invoice_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() {
		tv_truck_start_struck_liscense = (TextView) findViewById(R.id.tv_truck_start_struck_liscense);
		tv_truck_start_station_content = (TextView) findViewById(R.id.tv_truck_start_station_content);
		tv_truck_create_terminal_station_content = (TextView)findViewById(R.id.tv_truck_create_terminal_station_content);
		tv_truck_create_time_content = (TextView) findViewById(R.id.tv_truck_create_time_content);
		lin_choice_truck_liscense = findViewById(R.id.lin_choice_truck_liscense);
//		btn_truck_start_station_content = findViewById(R.id.btn_truck_start_station_content);
		btn_truck_chose_terminal_station = findViewById(R.id.btn_truck_chose_terminal_station);
		btn_truck_chose_time = findViewById(R.id.btn_truck_chose_time);
		btn_truck_invoice_complete = findViewById(R.id.btn_truck_invoice_complete);
		et_truck_create_truck_no = (EditText) findViewById(R.id.et_truck_create_truck_no);
		et_truck_create_invoice_no = (EditText) findViewById(R.id.et_truck_create_invoice_no);
		et_truck_create_drivername = (EditText) findViewById(R.id.et_truck_create_drivername);
		et_truck_create_driverphone = (EditText) findViewById(R.id.et_truck_create_driverphone);
		rel_truck_start_station = findViewById(R.id.rel_truck_start_station);

	}

	@Override
	public void initPresenter() {
		presenter = createService.createTruckShipmentConfigPresenter(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.setOnClickListener(this);
		btn_truck_chose_time.setOnClickListener(this);

	}

	@Override
	public void initData() {

	}

	@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 || 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 setMoreOptionStr(String moreOptionStr) {
		if (btn_title_more_option != null && moreOptionStr != null) {
			btn_title_more_option.setText(moreOptionStr);
		}

	}

	@Override
	public void addCustomView(View view) {
		// TODO Auto-generated method stub

	}

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

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

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

	@Override
	public void setTruckNo(String trainNo) {
		if (et_truck_create_truck_no != null && trainNo != null) {
			et_truck_create_truck_no.setText(trainNo);
		}
	}

	@Override
	public void setOrderNo(String orderNoStr) {
		if (et_truck_create_invoice_no != null && orderNoStr != null) {
			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) {
			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) {
			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) {
			tv_truck_start_station_content.setText(startStationStr);
		}

	}

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

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

	@Override
	public void setDate(String dateStr) {
		if (tv_truck_create_time_content != null && dateStr != null) {
			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_struck_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) {
		// TODO Auto-generated method stub

	}

	@Override
	public String getConsigneeStr() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.image_title_back_common:
			finish();
			break;
		case R.id.btn_title_more_option:
			if (presenter != null) {
				presenter.moreOptionClick();
			}
			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:
			if (presenter != null) {
				presenter.choiceEndStation();
			}
			break;
		case R.id.btn_truck_chose_time:
			if (presenter != null) {
				presenter.choiceDate();
			}
			break;
		}
		
	}

}
