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.SleepInfo;
import com.wisewoods.base.bean.StudentList;
import com.wisewoods.base.net.JCallback;
import com.wisewoods.base.page.BaseListActivity;
import com.wisewoods.eduandroid.app.App;
import com.wisewoods.eduandroid.app.ImgManager;
import com.wisewoods.eduandroid.databinding.ActivitySleepBinding;
import com.wisewoods.eduandroid.ui.adapter.SleepAdapter;

import retrofit2.Call;
import retrofit2.Response;

public class SleepActivity extends BaseListActivity<ActivitySleepBinding> {

    private SleepAdapter mAdapter;
    private StudentList.DataBean student;

    public static void start(StudentList.DataBean student) {
        Intent intent = new Intent(ActivityUtils.getTopActivity(), SleepActivity.class);
        intent.putExtra("student", student);
        ActivityUtils.startActivity(intent);
    }

    @Override
    protected void initListData() {
        rv = binding.rvSleep;
        srf = binding.srf;
        student = (StudentList.DataBean) getIntent().getSerializableExtra("student");

        showBarBack(binding.bar.tvTitle, "住宿安排", binding.bar.ivBack);
        mAdapter = new SleepAdapter();


        String sex = ImgManager.getSex(student.sex);
        String info = sex + "    " + (student.nationName != null ? student.nationName : "")
                + "    " + (student.teamName != null ? student.teamName : "") +
                (student.groupName != null ? student.groupName : "");

        binding.tvName.setText(student.name);
        binding.tvClassJob.setVisibility(TextUtils.isEmpty(student.teamJobName) ? View.GONE : View.VISIBLE);
        binding.tvClassJob.setText(student.teamJobName);

        binding.tvInfo.setText(info);

    }

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

    @Override
    protected void getData(long page, long size) {
        App.api.queryArrangeRoom(student.resourceStuId + "", page, size)
                .enqueue(new JCallback<SleepInfo>() {
                    @Override
                    public void onS(Response<SleepInfo> response, SleepInfo sleepInfo) {
                        getDataSuccess(sleepInfo.data.rows, sleepInfo.data.total);
                    }

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