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

import android.annotation.SuppressLint
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.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.databinding.FragmentAudioContentOrderBinding
import kr.co.vividnext.sodalive.extensions.moneyFormat
import kotlin.math.ceil

class AudioContentOrderFragment(
    private val price: Int,
    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
    }

    @SuppressLint("SetTextI18n")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        if (SharedPreferenceManager.userId == 17958L) {
            binding.tvKeepDate.text = "(이용기간 1년)"
            binding.ivKeepCan.visibility = View.GONE
            binding.ivRentalCan.visibility = View.GONE
        } else {
            binding.tvKeepDate.text = "(서비스 종료시까지)"
            binding.ivKeepCan.visibility = View.VISIBLE
            binding.ivRentalCan.visibility = View.VISIBLE
        }

        if (SharedPreferenceManager.userId == 17958L) {
            binding.tvKeep.text = "${(price * 110).moneyFormat()}원"
            binding.tvRental.text = "${(ceil(price * 0.7).toInt() * 110).moneyFormat()}원"
        } else {
            binding.tvKeep.text = price.moneyFormat()
            binding.tvRental.text = ceil(price * 0.7).toInt().moneyFormat()
        }

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

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