package com.sheep.gamegroup.view.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sheep.gamegroup.absBase.BaseActivity;
import com.sheep.gamegroup.model.entity.GiftBagApp;
import com.sheep.gamegroup.util.DataUtil;
import com.sheep.gamegroup.util.GlideImageLoader;
import com.sheep.gamegroup.util.StringUtils;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.gamegroup.util.share.ShareLinkConfig;
import com.sheep.gamegroup.view.adapter.GiftCenterAdapter;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.G;
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;

import butterknife.BindView;

import static com.sheep.gamegroup.util.UMConfigUtils.Event.GIFT_BAG_COPY_CODE;

/**
 * Created by realicing on 2018/9/14.
 * realicing@sina.com
 */
public class ActGiftDetail extends BaseActivity {
    @BindView(R.id.gift_detail_time)
    TextView gift_detail_time;
    @BindView(R.id.gift_detail_content)
    TextView gift_detail_content;
    @BindView(R.id.gift_detail_tip)
    TextView gift_detail_tip;

    @BindView(R.id.item_download_welfare_iv)
    ImageView item_download_welfare_iv;
    @BindView(R.id.item_download_welfare_name_tv)
    TextView item_download_welfare_name_tv;
    @BindView(R.id.item_download_welfare_iv2)
    ImageView item_download_welfare_iv2;
    @BindView(R.id.item_download_welfare_date_tv)
    TextView item_download_welfare_date_tv;
    @BindView(R.id.item_download_welfare_num_tv)
    TextView item_download_welfare_num_tv;
    @BindView(R.id.item_download_welfare_money)
    TextView item_download_welfare_money;
    @BindView(R.id.item_download_welfare_btn_center)
    TextView item_download_welfare_btn_center;
    @BindView(R.id.item_download_welfare_btn_bottom)
    TextView item_download_welfare_btn_bottom;
    @BindView(R.id.item_download_welfare_line)
    View item_download_welfare_line;

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

    @Override
    public void initView() {
        TitleBarUtils.getInstance()
                .setTitleFinish(this)
                .setShowOrHide(this, true)
                .setTitle(this, "礼包详情")
                .setRightBtn(this, "分享", 0, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        new ShareLinkConfig().toShare(ActGiftDetail.this);
                    }
                });
        item_download_welfare_line.setVisibility(View.GONE);
        item_download_welfare_btn_bottom.setVisibility(View.GONE);
        item_download_welfare_date_tv.setVisibility(View.GONE);
        item_download_welfare_iv2.setVisibility(View.GONE);
        item_download_welfare_money.setVisibility(View.GONE);
        item_download_welfare_num_tv.setVisibility(View.GONE);
        item_download_welfare_btn_bottom.setVisibility(View.GONE);
        ViewUtil.setDefaultText(item_download_welfare_name_tv);
        item_download_welfare_btn_center.setVisibility(View.VISIBLE);

    }

    private GiftBagApp data;

    @Override
    public void initData() {
        data = DataUtil.getObject(getIntent(), GiftBagApp.class);
        if (data.getApp() != null)
            GlideImageLoader.setGameImage(item_download_welfare_iv, data.getApp().getIcon());
        if (data.getGift_bag() != null) {
            ViewUtil.setText(item_download_welfare_name_tv, data.getGift_bag().getGiftName());
            ViewUtil.setText(gift_detail_time, data.getGift_bag().getDateText2());
            ViewUtil.setText(gift_detail_content, data.getGift_bag().getGiftContent());
            ViewUtil.setText(gift_detail_tip, data.getGift_bag().getUseMethod());
            if (TextUtils.isEmpty(data.getCode())) {//没有code，就视为没有领取礼包
                item_download_welfare_btn_center.setText("领取");
                item_download_welfare_btn_center.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        GiftCenterAdapter.receiveGiftBag(ActGiftDetail.this, data, null);
                    }
                });
            } else {
                item_download_welfare_btn_center.setText("复制");
                item_download_welfare_btn_center.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        GIFT_BAG_COPY_CODE.onEvent("gift_bag_id", data.getGift_bag().getId(), "gift_bag_code", data.getCode());
                        StringUtils.CopyText(data.getCode());
                        G.showToast("复制成功");
                    }
                });
            }
        } else {
            ViewUtil.setDefaultText(item_download_welfare_name_tv);
            ViewUtil.setDefaultText(gift_detail_time);
            ViewUtil.setDefaultText(gift_detail_content);
            ViewUtil.setDefaultText(gift_detail_tip);
        }
    }

}
