package com.police.policedatasystem.apply.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.police.policedatasystem.apply.viewmodel.ApplyResultViewModel;
import com.police.policedatasystem.databinding.ActivityQueryApplyResultBinding;
import com.police.policedatasystem.mine.activity.ApplyDetailActivity;
import com.police.policedatasystem.mine.adapter.MineApplyListAdapter;
import com.police.policedatasystem.mine.model.Apply;

import java.util.List;

public class QueryApplyResultActivity extends AppCompatActivity {

    private ActivityQueryApplyResultBinding binding;
    private MineApplyListAdapter adapter;
    private List<Apply> applyList;
    private ApplyResultViewModel viewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityQueryApplyResultBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        viewModel = new ApplyResultViewModel(this);
        binding.ivBack.setOnClickListener(view -> finish());
        binding.mineRvGroup.setLayoutManager(new LinearLayoutManager(this));
        adapter = new MineApplyListAdapter();
        binding.mineRvGroup.setAdapter(adapter);
        adapter.setOnItemClickListener((adapter1, view, position) -> applyDetail(applyList.get(position).getBh()));
        viewModel.getApplyList(getIntent().getStringExtra("jqbh"));
//        viewModel.getApplyList("22010020240411234457000018");
    }

    public void applyList(List<Apply> list) {
        applyList = list;
        adapter.setList(list);
    }

    public void applyDetail(String applyDetail) {
        Intent intent = new Intent(this, ApplyDetailActivity.class);
        intent.putExtra("applyDetail", applyDetail);
        startActivity(intent);
    }

    public void loadingShow() {
        binding.rlLoading.setVisibility(View.VISIBLE);
    }

    public void loadingNone() {
        binding.rlLoading.setVisibility(View.GONE);
    }
}