package com.gh.gamecenter.qa.comment

import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.common.utils.goneIf
import com.gh.gamecenter.CommentDetailActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.common.baselist.ListAdapter
import com.lightgame.utils.Util_System_Keyboard
import kotlin.math.abs

class StairsCommentFragment : NewCommentFragment() {
    override fun getLayoutId(): Int = R.layout.fragment_comment_dark

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

    }

    override fun provideListAdapter(): ListAdapter<*> {
        if (mAdapter == null) {
            val entrance = when (mViewModel.commentType) {
                CommentType.ANSWER,
                CommentType.ANSWER_CONVERSATION -> "(答案详情-评论列表)"

                CommentType.COMMUNITY_ARTICLE,
                CommentType.COMMUNITY_ARTICLE_CONVERSATION -> "(文章详情-评论列表)"

                CommentType.VIDEO,
                CommentType.VIDEO_CONVERSATION -> "(视频详情-评论列表)"

                CommentType.COMMUNITY_QUESTION,
                CommentType.COMMUNITY_QUESTION_CONVERSATION -> "(问题详情-评论列表)"

                CommentType.GAME_COLLECTION,
                CommentType.GAME_COLLECTION_CONVERSATION -> "(游戏单详情-评论列表)"
            }
            mAdapter = StairsCommentAdapter(requireContext(), mViewModel, true, this, this, entrance)
        }
        return mAdapter!!
    }

    override fun popInputLayout(isPopup: Boolean, height: Int) {
        mShadowView?.goneIf(!isPopup)
        if (requireActivity() is CommentDetailActivity) {
            val shadowView = (requireActivity() as CommentDetailActivity).shadowView
            shadowView.visibility = if (isPopup && !mShowInputOnly) View.VISIBLE else View.GONE
            DisplayUtils.setLightStatusBar(requireActivity(), !isPopup)
            shadowView.setOnClickListener { Util_System_Keyboard.hideSoftKeyboard(activity) }
        }
        mAnswerContent.orientation = if (isPopup) LinearLayout.VERTICAL else LinearLayout.HORIZONTAL
        if (isPopup) {
            mAnswerContent.background =
                ContextCompat.getDrawable(requireActivity(), R.drawable.bg_shape_dark_radius_10_top_only)
        } else {
            mAnswerContent.setBackgroundColor(ContextCompat.getColor(requireActivity(), R.color.bg_1F1F23))
            mOffset = abs(height)
        }

        val mScrollViewParams = mScrollView.layoutParams as LinearLayout.LayoutParams
        mScrollViewParams.width = if (isPopup) LinearLayout.LayoutParams.MATCH_PARENT else 0
        mScrollViewParams.height = if (isPopup) DisplayUtils.dip2px(64f) else DisplayUtils.dip2px(28f)
        mScrollView.layoutParams = mScrollViewParams

        val mLayoutParams = commentInputContainer?.layoutParams as FrameLayout.LayoutParams
        mLayoutParams.height = if (isPopup) DisplayUtils.dip2px(130f) else LinearLayout.LayoutParams.WRAP_CONTENT
        mLayoutParams.bottomMargin = if (isPopup) height + mOffset - DisplayUtils.dip2px(12F) else 0
        commentInputContainer?.layoutParams = mLayoutParams
    }
}