package com.develop.step.details

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import com.develop.food.base.ui.BaseFragment
import com.develop.step.databinding.FragmentDetailCookServingBinding
import com.develop.step.databinding.FragmentDetailCookSourceBinding
import com.develop.step.widgets.AmountSelectDialog

class CookDetailServeFragment: BaseFragment() {

    private lateinit var binding: FragmentDetailCookServingBinding
    private val adapter = CookDetailSourceAdapter()
    private val viewModel by activityViewModels<CookDetailViewModel>()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentDetailCookServingBinding.inflate(
            inflater, container, false
        )
        binding.rvList.adapter = adapter
        viewModel.getRecipeLiveData().observe(viewLifecycleOwner) {
            val sourceItems = mutableListOf<CookSourceItem>()
            for (nutrition in it.nutrition) {
                sourceItems.add(CookSourceItem(
                    nutrition.nutritionName ?: "",
                    "${nutrition.amount} ${nutrition.unit}"
                ))
            }
            adapter.setNewInstance(sourceItems)
        }
        return binding.root
    }

}