package com.gh.gamecenter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import com.gh.gamecenter.common.base.activity.ToolBarActivity;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.core.utils.DisplayUtils;
import com.gh.gamecenter.common.entity.LinkEntity;
import com.gh.gamecenter.entity.MessageEntity;
import com.gh.gamecenter.qa.comment.CommentActivity;
import com.gh.gamecenter.qa.comment.NewCommentConversationFragment;
import com.halo.assistant.fragment.comment.CommentDetailFragment;

import kotlin.Pair;

/**
 * Created by khy on 2017/3/22.
 */
public class CommentDetailActivity extends ToolBarActivity {

    private View mShadowView;

    @Override
    protected int getLayoutId() {
        return R.layout.toolbar_shadow;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mShadowView = findViewById(R.id.shadowView);
        ViewGroup.LayoutParams layoutParams = mShadowView.getLayoutParams();
        layoutParams.height = DisplayUtils.dip2px(50f) + DisplayUtils.getStatusBarHeight(getResources());
        mShadowView.setLayoutParams(layoutParams);
        DisplayUtils.setStatusBarColor(this, R.color.transparent, !mIsDarkModeOn);
    }

    public View getShadowView() {
        return mShadowView;
    }

    // article 不为空则显示跳转原文按钮
    public static Intent getIntent(Context context, String commentId, MessageEntity.Article article) {
        Bundle args = new Bundle();
        args.putString(EntranceConsts.KEY_COMMENTID, commentId);
        args.putParcelable(MessageEntity.Article.TAG, article);
        return getTargetIntent(context, CommentDetailActivity.class, CommentDetailFragment.class, args);
    }

    public static Intent getAnswerCommentIntent(Context context,
                                                String commentId,
                                                String answerId,
                                                LinkEntity linkEntity) {
        Bundle args = new Bundle();
        args.putString(EntranceConsts.KEY_COMMENTID, commentId);
        args.putString(EntranceConsts.KEY_ANSWER_ID, answerId);
        args.putParcelable(EntranceConsts.KEY_LINK, linkEntity);
        return getTargetIntent(context, CommentDetailActivity.class, NewCommentConversationFragment.class, args);
    }


    public static Intent getCommunityArticleCommentIntent(Context context,
                                                          String articleId,
                                                          String articleCommentId,
                                                          String communityId,
                                                          LinkEntity linkEntity) {
        Bundle args = new Bundle();
        args.putString(CommentActivity.ARTICLE_ID, articleId);
        args.putString(EntranceConsts.KEY_COMMENTID, articleCommentId);
        args.putString(CommentActivity.COMMUNITY_ID, communityId);
        args.putParcelable(EntranceConsts.KEY_LINK, linkEntity);
        return getTargetIntent(context, CommentDetailActivity.class, NewCommentConversationFragment.class, args);
    }

    public static Intent getVideoCommentIntent(Context context,
                                               String commentId,
                                               String videoId,
                                               boolean isVideoAuthor,
                                               LinkEntity linkEntity) {
        Bundle args = new Bundle();
        args.putString(EntranceConsts.KEY_COMMENTID, commentId);
        args.putString(CommentActivity.VIDEO_ID, videoId);
        args.putBoolean(CommentActivity.IS_VIDEO_AUTHOR, isVideoAuthor);
        args.putParcelable(EntranceConsts.KEY_LINK, linkEntity);
        return getTargetIntent(context, CommentDetailActivity.class, NewCommentConversationFragment.class, args);
    }

    @Override
    public Pair<String, String> getBusinessId() {
        CommentDetailFragment fragment = (CommentDetailFragment) getTargetFragment();
        if (fragment != null) {
            if (fragment.getArguments().getString(EntranceConsts.KEY_COMMENTID) != null) {
                return new Pair(fragment.getArguments().getString(EntranceConsts.KEY_COMMENTID), "");
            } else {
                return super.getBusinessId();
            }
        } else {
            return super.getBusinessId();
        }
    }

    @Override
    protected void onDarkModeChanged() {
        super.onDarkModeChanged();
        DisplayUtils.setStatusBarColor(this, R.color.transparent, !mIsDarkModeOn);
    }
}
