package com.wisewoods.eduandroid.ui;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.ActivityUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.wisewoods.base.bean.MettingInfo;
import com.wisewoods.base.bean.VoteInfo;
import com.wisewoods.base.net.JCallback;
import com.wisewoods.base.page.BaseListActivity;
import com.wisewoods.eduandroid.app.App;
import com.wisewoods.eduandroid.databinding.ActivityMettingDetailBinding;
import com.wisewoods.eduandroid.databinding.ViewHeadVoteBinding;
import com.wisewoods.eduandroid.ui.adapter.VoteAdapter;

import retrofit2.Call;
import retrofit2.Response;

public class MettingDetailActivity extends BaseListActivity<ActivityMettingDetailBinding> {

    private MettingInfo.DataBean data;
    private ViewHeadVoteBinding headBinding;
    private VoteAdapter mAdapter;

    public static void start(MettingInfo.DataBean data) {
        Intent intent = new Intent(ActivityUtils.getTopActivity(), MettingDetailActivity.class);
        intent.putExtra("data", data);
        ActivityUtils.startActivity(intent);
    }

    @Override
    protected void initListData() {
        rv = binding.rvVote;
        srf = binding.srf;

        showBarBack(binding.bar.tvTitle, "历史会议详情", binding.bar.ivBack);

        data = (MettingInfo.DataBean) getIntent().getSerializableExtra("data");

        mAdapter = new VoteAdapter();
        headBinding = ViewHeadVoteBinding.inflate(getLayoutInflater());
        mAdapter.addHeaderView(headBinding.getRoot());

        headBinding.tvNum.setText(data.meetingCode);
        headBinding.tvName.setText(data.subject);
        headBinding.tvCreate.setText("发起人:" + data.createName);
        headBinding.tvId.setText("会议ID:" + data.meetingId);
        headBinding.tvTime.setText("会议时间：" + data.startTime + " — " + data.endTime);
        headBinding.tvHost.setText("会议主持人：" + data.userName);
        headBinding.tvHttp.setText("会议链接：" + data.joinUrl);
        headBinding.tvType.setText("会议类型：" + (data.meetingType == 0 ? "预约会议" : "快速会议"));
        if (!TextUtils.isEmpty(data.venue)) {
            headBinding.tvAddress.setText("会议地点：" + data.venue);
        } else {
            headBinding.tvAddress.setVisibility(View.GONE);
        }
        headBinding.tvMute.setText("静音状态：" + (data.muteStatus ? "是" : "否"));
        if (!TextUtils.isEmpty(data.pasword)) {
            headBinding.tvPwd.setText("会议密码：" + data.pasword);
        } else {
            headBinding.tvPwd.setVisibility(View.GONE);
        }

        headBinding.tvPeople.setText(data.getMembersStr());
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return mAdapter;
    }

    @Override
    protected void getData(long page, long size) {
        App.api.getVote(data.meetingId)
                .enqueue(new JCallback<VoteInfo>() {
                    @Override
                    public void onS(Response<VoteInfo> response, VoteInfo voteInfo) {
                        getDataSuccess(voteInfo.data.rows, voteInfo.data.total);
                    }

                    @Override
                    public void onFailure(Call<VoteInfo> call, Throwable t) {
                        super.onFailure(call, t);
                        getDataFail();
                    }
                });
    }
}
