package cn.net.caoyao.cpzshandset.service.presenter.impl.home.jinLine;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;

import cn.net.caoyao.cpzshandset.common.config.HandsetOperation;
import cn.net.caoyao.cpzshandset.service.presenter.HomeConstact;
import cn.net.caoyao.cpzshandset.service.presenter.base.impl.HomeConstactImpl;
import cn.net.caoyao.cpzshandset.ui.activity.CheckLabelStatusActivity;
import cn.net.caoyao.cpzshandset.ui.activity.JianCeActivity;
import cn.net.caoyao.cpzshandset.ui.activity.OptionHistoryListStyleActivity;
import cn.net.caoyao.cpzshandset.ui.activity.SettingActivity;
import cn.net.caoyao.cpzshandset.ui.activity.UploadStatusActivity;
import cn.net.caoyao.cpzshandset.ui.adapter.HomeAdapter;

public class JinLineHomePresenter extends HomeConstactImpl {
	private final HomeConstact.View homeView;
	private Context context;
	private List<HandsetOperation> homeBeans = new ArrayList<HandsetOperation>();
	
	public JinLineHomePresenter(Context context,HomeConstact.View homeView){
		this.context = context;
		this.homeView = homeView;
		start();
	}

	@Override
	public void start() {
		initHomeEumnBeans();
		if (!checkViewAvailable()) return;
		//清除七天前的提交记录数据
		clearStatusData();
		homeView.setAdapter(new HomeAdapter(homeBeans));
		homeView.setHomeTitle("产线终端");
	}

	private void clearStatusData() {
//		UploadStatusBll uploadStatusBll = new UploadStatusBll(context);
//		uploadStatusBll.delete7DaysBefore();
	}

	private void initHomeEumnBeans() {
		homeBeans.add(HandsetOperation.OPERATION_DATA_SYNCHRONISM_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_PACK_BOTTLE_GIFTBOX_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_PACK_GIFTBOX_BOX_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_CHECK_BOTTLE_GIFTBOX_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_CHECK_GIFTBOX_BOX_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_CHECK_BOX_TRAY_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_INSPECT_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_SETTING_CONSTANT);
	}

	@Override
	public boolean checkViewAvailable() {
		boolean b = false;
        if (homeView != null && context != null) {
            b = true;
        }
        return b;
	}

	
	@Override
	public void onItemClickListener(int position) {
		if (!checkViewAvailable() || homeBeans == null || homeBeans.size() < position)return;
		switchCurrentOption(homeBeans.get(position));
	}


	private void switchCurrentOption(HandsetOperation option) {
//		if (homeBean == null || homeBean.getOperationId() < 0) return;
		switch (option) {
		case OPERATION_CHECK_BOTTLE_GIFTBOX_CONSTANT:
		case OPERATION_CHECK_GIFTBOX_BOX_CONSTANT:
		case OPERATION_CHECK_BOX_TRAY_CONSTANT:
			Intent intent1 = new Intent(context, CheckLabelStatusActivity.class);
			intent1.putExtra("option_type", option);
			context.startActivity(intent1);
			break;
		case OPERATION_SETTING_CONSTANT:
			//设置  
			if (!checkViewAvailable()) return;
			Intent settingIntent = new Intent(context,SettingActivity.class);
			context.startActivity(settingIntent);
			break;
		case OPERATION_UPLOAD_STATUS_CONSTANT:
			//提交状态
			if (!checkViewAvailable()) return;
//			homeView.showMsgToast("提交状态", Toast.LENGTH_SHORT);
			Intent statusIntent = new Intent(context, UploadStatusActivity.class);
			context.startActivity(statusIntent);
			break;
		case OPERATION_INSPECT_CONSTANT:
			//检测
			if (!checkViewAvailable()) return;
//			homeView.showMsgToast("检测", Toast.LENGTH_SHORT);
			Intent intent = new Intent(context, JianCeActivity.class);
			context.startActivity(intent);
			break;
			default :
				switchPage(option);
				break;

		}
		
	}

	private void switchPage(HandsetOperation option) {
		Intent activateIntent = new Intent(context, OptionHistoryListStyleActivity.class);
		activateIntent.putExtra("optionMode", option);
		context.startActivity(activateIntent);		
	}

}
