package kr.co.hanwha.hifive.screen.main.setting;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.base.BaseActivity;
import kr.co.hanwha.hifive.enums.BaseAnimationType;
import kr.co.hanwha.hifive.enums.BaseToolbarType;
import kr.co.hanwha.hifive.enums.MainTab;
import kr.co.hanwha.hifive.util.HFInfoUtil;

public class SettingScreenActivity extends BaseActivity {
    private TextView mTextViewGuide;
    private LinearLayout mLayoutTodo;
    private LinearLayout mLayoutUnit;
    private LinearLayout mLayoutDashboard;
    private LinearLayout mLayoutSetting;
    private ImageView mImageViewTodoCheck;
    private ImageView mImageViewUnitCheck;
    private ImageView mImageViewDashboardCheck;
    private ImageView mImageViewSettingCheck;

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

    @Override
    protected BaseToolbarType isToolbarStyle() {
        return BaseToolbarType.ONLY_BACK;
    }

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

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

        setTitle(getString(R.string.main_setting_default_tab));

        mTextViewGuide = (TextView) findViewById(R.id.guide_textView);
        mLayoutTodo = (LinearLayout) findViewById(R.id.todo_linearLayout);
        mLayoutUnit = (LinearLayout) findViewById(R.id.unit_linearLayout);
        mLayoutDashboard = (LinearLayout) findViewById(R.id.dashboard_linearLayout);
        mLayoutSetting = (LinearLayout) findViewById(R.id.setting_linearLayout);
        mImageViewTodoCheck = (ImageView) findViewById(R.id.todoCheck_imageView);
        mImageViewUnitCheck = (ImageView) findViewById(R.id.unitCheck_imageView);
        mImageViewDashboardCheck = (ImageView) findViewById(R.id.dashboardCheck_imageView);
        mImageViewSettingCheck = (ImageView) findViewById(R.id.settingCheck_imageView);

        mLayoutTodo.setOnClickListener(onClickListener);
        mLayoutUnit.setOnClickListener(onClickListener);
        mLayoutDashboard.setOnClickListener(onClickListener);
        mLayoutSetting.setOnClickListener(onClickListener);

        MainTab tab = HFInfoUtil.getDefaultScreen(this);
        setDefaultScreen(tab);
    }

    @Override
    public void finish() {
        super.finish();
    }

    /**************************************************
     * Support methods
     **************************************************/
    private void setDefaultScreen(@NonNull MainTab tab) {
        HFInfoUtil.setDefaultScreen(this, tab);

        mImageViewTodoCheck.setVisibility(tab == MainTab.HOME ? View.VISIBLE : View.GONE);
        mImageViewUnitCheck.setVisibility(tab == MainTab.PROJECT ? View.VISIBLE : View.GONE);
        mImageViewDashboardCheck.setVisibility(tab == MainTab.DASHBOARD ? View.VISIBLE : View.GONE);
        mImageViewSettingCheck.setVisibility(tab == MainTab.SETTING ? View.VISIBLE : View.GONE);

        String selectedTab = "";
        if (tab == MainTab.HOME) {
            selectedTab = getString(R.string.main_setting_default_tab_todo);
        } else if (tab == MainTab.PROJECT) {
            selectedTab = getString(R.string.main_setting_default_tab_unit);
        } else if (tab == MainTab.DASHBOARD) {
            selectedTab = getString(R.string.main_setting_default_tab_dashboard);
        } else if (tab == MainTab.SETTING) {
            selectedTab = getString(R.string.main_setting_default_tab_setting);
        }
        mTextViewGuide.setText(Html.fromHtml(String.format(getString(R.string.main_setting_default_tab_guide_2), selectedTab)));
    }

    /**************************************************
     * View.OnClickListener
     **************************************************/
    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showToast(R.string.main_setting_default_tab_message);
            switch (v.getId()) {
                case R.id.todo_linearLayout:
                    setDefaultScreen(MainTab.HOME);
                    break;
                case R.id.unit_linearLayout:
                    setDefaultScreen(MainTab.PROJECT);
                    break;
                case R.id.dashboard_linearLayout:
                    setDefaultScreen(MainTab.DASHBOARD);
                    break;
                case R.id.setting_linearLayout:
                    setDefaultScreen(MainTab.SETTING);
                    break;
            }
        }
    };
}
