package com.example.uitugasakhir.ViewModel

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.uitugasakhir.model.RiwayatItem
import kotlinx.coroutines.launch
import com.example.uitugasakhir.api.RetrofitClient

class RiwayatViewModel : ViewModel() {

    var riwayatList by mutableStateOf<List<RiwayatItem>>(emptyList())
        private set

    fun loadRiwayat(userId: Int) {
        viewModelScope.launch {
            try {
                riwayatList = RetrofitClient.api.getRiwayat(userId)
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }
}