package kr.co.vividnext.sodalive.audio_content.order

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kr.co.vividnext.sodalive.databinding.FragmentAudioContentOrderBinding
import kotlin.math.ceil

class AudioContentOrderFragment(
    private val price: Int,
    private val isOnlyRental: Boolean,
    private val onClickRental: () -> Unit,
    private val onClickKeep: () -> Unit
) : BottomSheetDialogFragment() {

    private lateinit var binding: FragmentAudioContentOrderBinding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentAudioContentOrderBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        if (isOnlyRental) {
            binding.tvRental.text = "$price"
            binding.rlKeep.visibility = View.GONE
        } else {
            binding.tvKeep.text = "$price"
            binding.tvRental.text = "${ceil(price * 0.6).toInt()}"

            binding.rlKeep.visibility = View.VISIBLE
            binding.llKeep.setOnClickListener {
                onClickKeep()
                dismiss()
            }
        }

        binding.llRental.setOnClickListener {
            onClickRental()
            dismiss()
        }
    }
}
