package com.gh.gamecenter.feedback.view.suggest;

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

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

import com.alibaba.android.arouter.launcher.ARouter;
import com.gh.gamecenter.common.base.fragment.BaseFragment;
import com.gh.gamecenter.common.constant.CommonConsts;
import com.gh.gamecenter.common.constant.RouteConsts;
import com.gh.gamecenter.common.entity.SuggestType;
import com.gh.gamecenter.feature.provider.ILinkDirectUtilsProvider;
import com.gh.gamecenter.common.utils.ShareUtils;
import com.gh.gamecenter.core.provider.IConfigProvider;
import com.gh.gamecenter.core.provider.IDirectProvider;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.gamecenter.feedback.R;
import com.gh.gamecenter.feedback.databinding.FragmentSuggestSelectBinding;

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

    private FragmentSuggestSelectBinding mBinding;
    private IConfigProvider mConfigProvider;

    @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);
        mConfigProvider = (IConfigProvider) ARouter.getInstance().build(RouteConsts.provider.config).navigation();
        final String qQun = mConfigProvider.getQQun();
        if (!TextUtils.isEmpty(qQun)) {
            mBinding.suggestQqun.setText(qQun);
        }
        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.suggestType8.setOnClickListener(this::OnClick);
        mBinding.suggestQqunRl.setOnClickListener(this::OnClick);
    }

    public void OnClick(View view) {
        IDirectProvider directProvider = (IDirectProvider) ARouter.getInstance().build(RouteConsts.provider.directUtils).navigation();
        SuggestType type = SuggestType.normal;
        int id = view.getId();
        if (id == R.id.suggest_type1) {
            type = SuggestType.normal;
            MtaHelper.onEvent("意见反馈", "意见反馈", "普通反馈");
        } else if (id == R.id.suggest_type2) {
            type = SuggestType.crash;
            MtaHelper.onEvent("意见反馈", "意见反馈", "发生闪退");
        } else if (id == R.id.suggest_type3) {
            type = SuggestType.cwzsQuestion;
            MtaHelper.onEvent("意见反馈", "意见反馈", "畅玩问题");
        } else if (id == R.id.suggest_type4) {
            type = SuggestType.gameQuestion;
            MtaHelper.onEvent("意见反馈", "意见反馈", "游戏问题");
        } else if (id == R.id.suggest_type5) {
            type = SuggestType.gameCollect;
            MtaHelper.onEvent("意见反馈", "意见反馈", "游戏收录");
        } else if (id == R.id.suggest_type6) {
            type = SuggestType.functionSuggest;
            MtaHelper.onEvent("意见反馈", "意见反馈", "功能收录");
        } else if (id == R.id.suggest_type7) {
            type = SuggestType.articleCollect;
            MtaHelper.onEvent("意见反馈", "意见反馈", "文章投稿");
        } else if (id == R.id.suggest_type8) {
            type = SuggestType.copyright;
            MtaHelper.onEvent("意见反馈", "意见反馈", "版权申诉");
        } else if (id == R.id.suggest_qqun_rl) {
            MtaHelper.onEvent("意见反馈", "意见反馈", "点击QQ群号");
            if (ShareUtils.isQQClientAvailable(requireContext())) {
                String groupNumber = "vd754P2_uNUJqDcgX4V-pyXEGZZVH0DE";
                if (!TextUtils.isEmpty(mConfigProvider.getQQunKey())) {
                    groupNumber = mConfigProvider.getQQunKey();
                }
                directProvider.directToQqGroup(requireContext(), groupNumber); // Q群：367541038 KEY
            } else {
                toast("请先安装QQ");
            }
            return;
        }
        ILinkDirectUtilsProvider directUtils = (ILinkDirectUtilsProvider) ARouter.getInstance().build(RouteConsts.provider.linkDirectUtils).navigation();
        directUtils.directToSuggestion(requireContext(), type, CommonConsts.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.divider8.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.suggestTitleTv8.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));
            mBinding.suggestDesTv8.setTextColor(ContextCompat.getColor(requireContext(), R.color.content));
        }
    }
}
