package com.base.scanqrclear.ui.widget

import android.app.AlertDialog
import android.content.Context
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import com.base.scanqrclear.databinding.DialogLogContentBinding
import com.base.scanqrclear.utils.AppPreferences
import com.base.scanqrclear.utils.ClipboardUtils.copyText
import com.base.scanqrclear.utils.ToastUtils.toast

object LogDialog {

    fun Context.showLogDialog(log: String) {
        val dialog = AlertDialog.Builder(this).create()
        val binding = DialogLogContentBinding.inflate(LayoutInflater.from(this))
        dialog.setView(binding.root)
        dialog.setCanceledOnTouchOutside(true)

        dialog.show()

        val params = dialog.window?.attributes
//        params?.width = resources.getDimensionPixelOffset(R.dimen.dp_320)
//        params?.height = LinearLayout.LayoutParams.WRAP_CONTENT
//        params?.gravity = Gravity.BOTTOM
//        params?.y = 50

        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        binding.tvLog.movementMethod = ScrollingMovementMethod()
        binding.tvLog.text = log

        binding.btnCopy.setOnClickListener {
            val uuid = AppPreferences.getInstance().getString("uuid", "NUll")
            this.copyText("uuid", uuid)
            toast("copyed", true)
        }
    }
}