package com.base.browserwhite.ui.activity.bookmark

import android.graphics.Color
import androidx.activity.addCallback
import androidx.core.view.updatePadding
import androidx.core.widget.addTextChangedListener
import com.base.browserwhite.databinding.ActivityBookmarkFolderAddBinding
import com.base.browserwhite.ui.activity.BaseActivity
import com.base.browserwhite.utils.BarUtils
import com.base.browserwhite.utils.SpBeanUtils
import com.base.browserwhite.utils.SpBeanUtils.BOOKMARK_FOLDER_SP_KEY

class BookmarkFolderAddActivity : BaseActivity<ActivityBookmarkFolderAddBinding>() {

    override val binding: ActivityBookmarkFolderAddBinding by lazy {
        ActivityBookmarkFolderAddBinding.inflate(layoutInflater)
    }

    override fun initView() {
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarColor(this, Color.WHITE)
        binding.root.updatePadding(top = BarUtils.getStatusBarHeight())

        binding.editName.setText(editFolder)

    }

    override fun initListener() {
        super.initListener()
        onBackPressedDispatcher.addCallback {
            finish()
        }
        binding.flFanhui.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }

        binding.editName.addTextChangedListener {
            binding.tvSave.isEnabled = !it.isNullOrEmpty()
        }
        binding.tvSave.setOnClickListener {
            SpBeanUtils.addSpBean(BOOKMARK_FOLDER_SP_KEY, binding.editName.text.toString())
            finish()
        }
    }

    companion object {
        var editFolder: String = ""
    }

}