package com.lukouguoji.module_base.ui.signature

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.lukouguoji.module_base.R
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.databinding.ActivitySignatureBinding
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.ktx.showToast
import dev.utils.app.PathUtils
import dev.utils.common.DateUtils
import dev.utils.common.FileUtils

class SignatureActivity : BaseBindingActivity<ActivitySignatureBinding, SignatureViewModel>() {

    override fun layoutId() = R.layout.activity_signature

    override fun viewModelClass() = SignatureViewModel::class.java

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("请签名")
        binding.tvReset.setOnClickListener {
            binding.sign.clear()
        }
        binding.tvConfirm.setOnClickListener {
            if (!binding.sign.touched) {
                showToast("请签名")
                return@setOnClickListener
            }
            val path =
                PathUtils.getAppExternal().appPicturesPath + "/signature${DateUtils.getCurrentTimeMillis()}.png"
            binding.sign.save(path, true, 10)

            FlowBus.with<String>(ConstantEvent.SIGNATURE_SUCCESS)
                .tryEmit(path)
            finish()
        }
    }

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, SignatureActivity::class.java)
            context.startActivity(starter)
        }
    }
}