package com.gh.gamecenter.suggest;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.gh.gamecenter.common.base.fragment.BaseFragment;
import com.gh.common.constant.Config;
import com.gh.common.util.DirectUtils;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.gamecenter.common.utils.ShareUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.databinding.FragmentSuggestSelectBinding;
import com.gh.gamecenter.entity.SettingsEntity;

/**
 * Created by khy on 2017/3/31.
 */
public class SuggestSelectFragment extends BaseFragment {

    public final static int SUGGEST_TYPE_REQUEST = 11; // 只要进入反馈页面(下一个), 无论怎么回退当前页面都会退出

    private FragmentSuggestSelectBinding mBinding;

    private SettingsEntity mSettings;

    @Override
    protected int getLayoutId() {
        return 0;
    }

    @Override
    protected View getInflatedLayout() {
        mBinding = FragmentSuggestSelectBinding.inflate(getLayoutInflater());
        return mBinding.getRoot();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mSettings = Config.getSettings();
        if (mSettings != null && mSettings.getSupport() != null &&
                !TextUtils.isEmpty(mSettings.getSupport().getQQun())) {
            mBinding.suggestQqun.setText(mSettings.getSupport().getQQun());
        }
        mBinding.suggestType1.setOnClickListener(this::OnClick);
        mBinding.suggestType2.setOnClickListener(this::OnClick);
        mBinding.suggestType3.setOnClickListener(this::OnClick);
        mBinding.suggestType4.setOnClickListener(this::OnClick);
        mBinding.suggestType5.setOnClickListener(this::OnClick);
        mBinding.suggestType6.setOnClickListener(this::OnClick);
        mBinding.suggestType7.setOnClickListener(this::OnClick);
        mBinding.suggestQqunRl.setOnClickListener(this::OnClick);
    }

    public void OnClick(View view) {
        SuggestType type = SuggestType.normal;
        switch (view.getId()) {
            case R.id.suggest_type1:
                type = SuggestType.normal;
                MtaHelper.onEvent("意见反馈", "意见反馈", "普通反馈");
                break;
            case R.id.suggest_type2:
                type = SuggestType.crash;
                MtaHelper.onEvent("意见反馈", "意见反馈", "发生闪退");
                break;
            case R.id.suggest_type3:
                type = SuggestType.gameQuestion;
                MtaHelper.onEvent("意见反馈", "意见反馈", "游戏问题");
                break;
            case R.id.suggest_type4:
                type = SuggestType.gameCollect;
                MtaHelper.onEvent("意见反馈", "意见反馈", "游戏收录");
                break;
            case R.id.suggest_type5:
                type = SuggestType.functionSuggest;
                MtaHelper.onEvent("意见反馈", "意见反馈", "功能收录");
                break;
            case R.id.suggest_type6:
                type = SuggestType.articleCollect;
                MtaHelper.onEvent("意见反馈", "意见反馈", "文章投稿");
                break;
            case R.id.suggest_type7:
                type = SuggestType.copyright;
                MtaHelper.onEvent("意见反馈", "意见反馈", "版权申诉");
                break;
            case R.id.suggest_qqun_rl:
                MtaHelper.onEvent("意见反馈", "意见反馈", "点击QQ群号");
                if (ShareUtils.isQQClientAvailable(requireContext())) {
                    String groupNumber = "vd754P2_uNUJqDcgX4V-pyXEGZZVH0DE";
                    if (mSettings != null && mSettings.getSupport() != null &&
                            !TextUtils.isEmpty(mSettings.getSupport().getQQunKey())) {
                        groupNumber = mSettings.getSupport().getQQunKey();
                    }
                    DirectUtils.directToQqGroup(requireContext(), groupNumber); // Q群：367541038 KEY
                } else {
                    toast("请先安装QQ");
                }

                return;
        }

        DirectUtils.directToSuggestion(requireContext(), type, SUGGEST_TYPE_REQUEST);
    }

    @Override
    protected void onDarkModeChanged() {
        super.onDarkModeChanged();
        if (mBinding != null) {
            mBinding.getRoot().setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background_white));
            mBinding.divider1.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background));
            mBinding.divider2.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background));
            mBinding.divider3.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background));
            mBinding.divider4.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background));
            mBinding.divider5.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background));
            mBinding.divider6.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background));
            mBinding.divider7.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background));
            mBinding.suggestQunDesTv.setTextColor(ContextCompat.getColor(requireContext(), R.color.text_subtitleDesc));
            mBinding.suggestQqun.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font));
            mBinding.suggestTitleTv1.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font));
            mBinding.suggestTitleTv2.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font));
            mBinding.suggestTitleTv3.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font));
            mBinding.suggestTitleTv4.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font));
            mBinding.suggestTitleTv5.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font));
            mBinding.suggestTitleTv6.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font));
            mBinding.suggestTitleTv7.setTextColor(ContextCompat.getColor(requireContext(), R.color.theme_font));
            mBinding.suggestDesTv1.setTextColor(ContextCompat.getColor(requireContext(), R.color.content));
            mBinding.suggestDesTv2.setTextColor(ContextCompat.getColor(requireContext(), R.color.content));
            mBinding.suggestDesTv3.setTextColor(ContextCompat.getColor(requireContext(), R.color.content));
            mBinding.suggestDesTv4.setTextColor(ContextCompat.getColor(requireContext(), R.color.content));
            mBinding.suggestDesTv5.setTextColor(ContextCompat.getColor(requireContext(), R.color.content));
            mBinding.suggestDesTv6.setTextColor(ContextCompat.getColor(requireContext(), R.color.content));
            mBinding.suggestDesTv7.setTextColor(ContextCompat.getColor(requireContext(), R.color.content));
        }
    }
}
