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.entity.CommentEntity;
import com.gh.gamecenter.entity.ConcernEntity;
import com.gh.gamecenter.message.MessageDetailFragment;
import com.halo.assistant.HaloApp;

import kotlin.Pair;

/**
 * Created by khy on 2016/11/8.
 * 消息详情界面(评论详情）
 */
@Deprecated
public class MessageDetailActivity 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;
    }

    // 评论回复
    public static Intent getMessageDetailIntent(Context context, CommentEntity entity, String newsId) {
        Intent intent = new Intent(context, MessageDetailActivity.class);
        intent.putExtra("commentNum", -1);
        intent.putExtra(EntranceConsts.KEY_NEWSID, newsId);
        intent.putExtra("openSoftInput", true);
        intent.putExtra(CommentEntity.TAG, entity);

        return getTargetIntent(context, MessageDetailActivity.class, MessageDetailFragment.class, intent.getExtras());
    }

    public static Intent getIntentByEntity(Context context, ConcernEntity concernEntity, String entrance) {
        Intent intent = new Intent(context, MessageDetailActivity.class);
//        intent.putExtra(ConcernEntity.TAG, concernEntity);
        HaloApp.put(ConcernEntity.TAG, concernEntity);
        intent.putExtra(EntranceConsts.KEY_ENTRANCE, entrance);
//        return intent;
        return getTargetIntent(context, MessageDetailActivity.class, MessageDetailFragment.class, intent.getExtras());
    }

    public static Intent getIntentById(Context context, String newsId, Integer commentNum, Boolean openSoftInput, String entrance) {
        Intent intent = new Intent(context, MessageDetailActivity.class);
        intent.putExtra(EntranceConsts.KEY_NEWSID, newsId);
        intent.putExtra(EntranceConsts.KEY_ENTRANCE, entrance);
        intent.putExtra("commentNum", commentNum);
        intent.putExtra("openSoftInput", openSoftInput);
//        return intent;
        return getTargetIntent(context, MessageDetailActivity.class, MessageDetailFragment.class, intent.getExtras());
    }

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

    @Override
    public Pair<String, String> getBusinessId() {
        MessageDetailFragment fragment = (MessageDetailFragment) getTargetFragment();
        if (fragment.getArguments() != null) {
            Object concernEntity = HaloApp.get(ConcernEntity.TAG, false);
            Object commentEntity = fragment.requireArguments().getParcelable(CommentEntity.TAG);
            if (fragment.getArguments().getString(EntranceConsts.KEY_NEWSID) != null && commentEntity != null) {
                return new Pair(((CommentEntity) commentEntity).getId(), fragment.getArguments().getString(EntranceConsts.KEY_NEWSID));
            } else if (fragment.getArguments().getString(EntranceConsts.KEY_NEWSID) != null) {
                return new Pair(fragment.getArguments().getString(EntranceConsts.KEY_NEWSID), "");
            } else if (concernEntity != null) {
                return new Pair(((ConcernEntity) concernEntity).getId(), "");
            } else {
                return super.getBusinessId();
            }
        } else {
            return super.getBusinessId();
        }
    }
}
