package kr.co.vividnext.sodalive.audio_content.detail

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.R
import kr.co.vividnext.sodalive.databinding.DialogAudioContentDetailMenuBinding

class AudioContentDetailMenuBottomSheetDialog(
    private val isPin: Boolean,
    private val isCreator: Boolean,
    private val onClickPin: () -> Unit,
    private val onClickModify: () -> Unit,
    private val onClickDelete: () -> Unit,
    private val onClickReport: () -> Unit
) : BottomSheetDialogFragment() {
    private lateinit var dialog: DialogAudioContentDetailMenuBinding

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

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

        if (isCreator) {
            dialog.tvReport.visibility = View.GONE
            dialog.llMenuCreator.visibility = View.VISIBLE

            if (isPin) {
                dialog.ivPin.setImageResource(R.drawable.ic_pin_cancel)
                dialog.tvPin.text = "내 채널에 고정 취소"
            } else {
                dialog.ivPin.setImageResource(R.drawable.ic_pin)
                dialog.tvPin.text = "내 채널에 고정"
            }

            dialog.llPin.setOnClickListener {
                dismiss()
                onClickPin()
            }
            dialog.llModify.setOnClickListener {
                dismiss()
                onClickModify()
            }
            dialog.llDelete.setOnClickListener {
                dismiss()
                onClickDelete()
            }
        } else {
            dialog.llMenuCreator.visibility = View.GONE
            dialog.tvReport.visibility = View.VISIBLE
            dialog.tvReport.setOnClickListener {
                dismiss()
                onClickReport()
            }
        }
    }
}
