package com.gh.vspace.shortcut

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Window
import com.gh.common.util.ColorResId
import com.gh.common.util.NewFlatLogUtils
import com.gh.common.util.buildSpannableString
import com.gh.gamecenter.databinding.DialogShortcutPermissionTipsBinding
import com.muugi.shortcut.core.Executor
import splitties.systemservices.layoutInflater

/**
 * @author : liujiarui
 * date : 2023/3/22
 * description : 畅玩助手唤起 创建快捷方式权限提示弹框
 */
class ShortcutPermissionTipsDialog(
    context: Context,
    private val mGameId: String,
    private val mExecutor: Executor? = null
) : Dialog(context) {
    private val mBinding by lazy {
        DialogShortcutPermissionTipsBinding.inflate(context.layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        setCancelable(true)
        setCanceledOnTouchOutside(true)
        setContentView(mBinding.root)
        initUI()
        NewFlatLogUtils.logCwFunShortcutPermissionDialogShow(mGameId)
    }


    private fun initUI() {
        mBinding.contentTv.buildSpannableString {
            addText("检测到光环助手未开启") {
                setColor(ColorResId(com.gh.gamecenter.common.R.color.text_secondary))
            }
            addText("创建图标快捷方式") {
                setColor(ColorResId(com.gh.gamecenter.common.R.color.text_theme))
            }
            addText("，请前往系统设置开启") {
                setColor(ColorResId(com.gh.gamecenter.common.R.color.text_secondary))
            }
        }
        mBinding.cancelTv.setOnClickListener {
            NewFlatLogUtils.logCwFunShortcutPermissionDialogButtonClick(
                mGameId, mBinding.cancelTv.text.toString()
            )
            dismiss()
        }
        mBinding.positiveTv.setOnClickListener {
            NewFlatLogUtils.logCwFunShortcutPermissionDialogButtonClick(
                mGameId, mBinding.positiveTv.text.toString()
            )
            mExecutor?.executeSetting()
            dismiss()
        }
    }
}