package com.gh.gamecenter.amway

import android.os.Bundle
import android.view.View
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.GameDetailActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.WebActivity
import com.gh.gamecenter.databinding.FragmentAmwaySuccessBinding
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.common.base.fragment.ToolbarFragment

class AmwaySuccessFragment : ToolbarFragment() {

    private var mGameEntity: GameEntity? = null
    private val mBinding: FragmentAmwaySuccessBinding by lazy { FragmentAmwaySuccessBinding.inflate(layoutInflater) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mGameEntity = arguments?.get(EntranceConsts.KEY_DATA) as GameEntity?
    }

    override fun getLayoutId() = 0
    override fun getInflatedLayout() = mBinding.root

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        setNavigationTitle("安利墙")

        mBinding.run {
            checkCommentBtn.setOnClickListener {
                if (mGameEntity != null) {
                    GameDetailActivity.startGameDetailActivity(
                        requireContext(),
                        mGameEntity,
                        "安利墙",
                        isSkipGameComment = true
                    )
                } else {
                    requireActivity().finish()
                }
            }

            checkAmwayBtn.setOnClickListener {
                requireActivity().finish()
            }

            commentRuleTv.setOnClickListener {
                startActivity(
                    WebActivity.getWebIntent(
                        requireContext(), requireContext().getString(
                            R.string.comment_rules_title
                        ), requireContext().getString(R.string.comment_rules_url)
                    )
                )
            }
        }
    }

}