package com.dlc.exam.ui.learn

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import com.dlc.exam.R
import com.dlc.exam.databinding.DialogLearnCompletedBinding
import com.rc.httpcore.vo.response.LearnBonusBean

/**
 * 学习完成Dialog
 *
 * @author ReiChin_
 */
class LearnCompletedDialog(
    context: Context,
    private val data: LearnBonusBean,
    private val endChapter: Boolean,
    private val assessStatus: Boolean,
    val listener: () -> Unit
) :
    Dialog(context, R.style.AlertDialogStyle) {

    private val viewBinding: DialogLearnCompletedBinding by lazy {
        DialogLearnCompletedBinding.inflate(LayoutInflater.from(context))
    }

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(viewBinding.root)

        viewBinding.close.setOnClickListener { dismiss() }
        viewBinding.learnBonusScore.text =
            "已学习时长${data.durationStr ?: "0"}，共获得${data.points ?: "0"}奖励分"

        if (endChapter) {
            viewBinding.title.text = "您已学习完最后一章节"
        } else {
            viewBinding.title.text = "您已学习完该章节"
        }

        if (assessStatus) {
            // 需要课后考核
            viewBinding.nextChapter.text = "课后考核"
            viewBinding.nextChapter.visibility = View.VISIBLE
        } else {
            viewBinding.nextChapter.text = "学习下一章节"
            viewBinding.nextChapter.visibility = if (endChapter) View.GONE else View.VISIBLE
        }

        viewBinding.nextChapter.setOnClickListener {
            // 学习下一章节/课后考核
            dismiss()
            listener.invoke()
        }
    }

}