package com.bokecc.livemodule.live.function.lottery.view;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bokecc.dwlivedemo.R;
import com.bokecc.livemodule.utils.PopupAnimUtil;
import com.bokecc.livemodule.view.BasePopupWindow;
import com.bokecc.sdk.mobile.live.pojo.LotteryAction;
import com.bokecc.sdk.mobile.live.pojo.LotteryUserInfo;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 抽奖开始弹出框
 */
public class OneArmHanditResultPopup extends BasePopupWindow {

    public OneArmHanditResultPopup(Context context) {
        super(context);
    }

    private ImageView closeBtn;
    private TextView tv_prize_name,lotteryNum;
    private View lottery_self_header;
    private View lottery_no_self_header;
    private GridView gridview;
    private OneArmHanditResultAdapter adapter;
    private ArrayList<LotteryUserInfo> userInfos = new ArrayList<>();

    @Override
    protected void onViewCreated() {
        closeBtn = findViewById(R.id.close);

        lottery_self_header = findViewById(R.id.lottery_self_header);
        lottery_no_self_header = findViewById(R.id.lottery_no_self_header);

        tv_prize_name = findViewById(R.id.tv_prize_name);
        lotteryNum = findViewById(R.id.lotteryNum);

        gridview = findViewById(R.id.gridview);

        closeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    public void setUserData(LotteryAction lotteryAction){
        userInfos.clear();
        userInfos.addAll(lotteryAction.getLotteryWinInfo().getUserInfos());
//        adapter.notifyDataSetChanged();
        adapter = new OneArmHanditResultAdapter(mContext,userInfos);
        gridview.setAdapter(adapter);

        if (lotteryAction.getLotteryWinInfo().isWinner()){
            lottery_self_header.setVisibility(View.VISIBLE);
            lottery_no_self_header.setVisibility(View.GONE);

            tv_prize_name.setText(lotteryAction.getLotteryWinInfo().getPrize().getName());
            lotteryNum.setText(lotteryAction.getLotteryWinInfo().getOwnUserInfo().getPrizeCode());
        } else {
            lottery_self_header.setVisibility(View.GONE);
            lottery_no_self_header.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected int getContentView() {
        return R.layout.view_one_arm_handit_result;
    }

    @Override
    protected Animation getEnterAnimation() {
        return PopupAnimUtil.getDefScaleEnterAnim();
    }

    @Override
    protected Animation getExitAnimation() {
        return PopupAnimUtil.getDefScaleExitAnim();
    }
}
