package kr.co.hanwha.hifive.screen.task;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.adapter.AddTaskSelectCampaignListAdapter;
import kr.co.hanwha.hifive.adapter.contract.AddTaskSelectCampaignListContract;
import kr.co.hanwha.hifive.base.BaseActivity;
import kr.co.hanwha.hifive.data.model.CampaignData;
import kr.co.hanwha.hifive.enums.BaseAnimationType;
import kr.co.hanwha.hifive.enums.BaseToolbarType;
import kr.co.hanwha.hifive.screen.task.contract.AddTaskSelectCampaignContract;
import kr.co.hanwha.hifive.view.HFSearchMemberEditTextView;

/**
 * Created by sanghoonkwon on 2018. 2. 21..
 */

public class AddTaskSelectCampaignActivity extends BaseActivity implements AddTaskSelectCampaignContract.View {
    private RecyclerView mRecyclerView;
    private AddTaskSelectCampaignListAdapter mListAdapter;
    private HFSearchMemberEditTextView mSearchEditTextView;

    private AddTaskSelectCampaignContract.Presenter mPresenter;

    @Override
    protected int getContentViewResource() {
        return R.layout.activity_add_task_select_campaign;
    }

    @Override
    protected BaseToolbarType isToolbarStyle() {
        return null;
    }

    @Override
    protected BaseAnimationType isShowActivityAnimation() {
        return BaseAnimationType.RIGHT;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mSearchEditTextView = (HFSearchMemberEditTextView) findViewById(R.id.searchMemberEditTextView);
        mSearchEditTextView.setOnSearchEditTextListener(onSearchEditTextListener);

        mListAdapter = new AddTaskSelectCampaignListAdapter(onSelectCampaignListListener);

        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(mListAdapter);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());

        findViewById(R.id.confirm_textView).setOnClickListener(onClickListener);
        findViewById(R.id.cancel_textView).setOnClickListener(onClickListener);

        mPresenter = new AddTaskSelectCampaignPresenter(this, mListAdapter, mListAdapter);
        mPresenter.initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        mPresenter.detachView();
    }

    /**************************************************
     * View.OnClickListener
     **************************************************/
    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.confirm_textView:
                    mPresenter.doCompleted();
                    break;
                case R.id.cancel_textView:
                    finish();
                    break;
            }

        }
    };

    /**************************************************
     * AddTaskSelectMemberListContract.OnSelectMemberListListener
     **************************************************/
    AddTaskSelectCampaignListContract.OnSelectCampaignListListener onSelectCampaignListListener = new AddTaskSelectCampaignListContract.OnSelectCampaignListListener() {
        @Override
        public void onItemClicked(@NonNull CampaignData data, int index) {
            mPresenter.updateObjectSelect(data);
        }
    };

    /**************************************************
     * HFSearchMemberEditTextView.OnSearchEditTextListener
     **************************************************/
    HFSearchMemberEditTextView.OnSearchEditTextListener onSearchEditTextListener = new HFSearchMemberEditTextView.OnSearchEditTextListener() {
        @Override
        public void onImeActionSearch(@NonNull HFSearchMemberEditTextView v) {

        }

        @Override
        public void onValueChanged(@NonNull HFSearchMemberEditTextView v) {
            String keyword = v.getText();
            mPresenter.doSearchKeyword(keyword);//            mListAdapter.getFilter().filter(keyword);
        }
    };
}
