package com.qimai.android.widget

import android.graphics.Color
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.qimai.android.tools.dpTopx
import com.qimai.android.widgetlib.topbar.QmTopBar

class TopBarActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_top_bar)
        val toolbar = findViewById<QmTopBar>(R.id.toolbar)
        val topbar2 = findViewById<QmTopBar>(R.id.topbar2)
        setSupportActionBar(toolbar)
        supportActionBar?.setDisplayShowCustomEnabled(false)
        toolbar.registerViewClickListener {

            backImgClick {
                finish()

            }
            rightImgClick {
                Toast.makeText(this@TopBarActivity, "rightImg", Toast.LENGTH_SHORT).show()
            }

            rightTextClick {
                Toast.makeText(this@TopBarActivity, "rightText", Toast.LENGTH_SHORT).show()

            }

        }

        findViewById<Button>(R.id.line).setOnClickListener {
            toolbar.qmTopBarNeedSeparator = !toolbar.qmTopBarNeedSeparator

        }

        findViewById<Button>(R.id.leftTextview).setOnClickListener {
            toolbar.rightTextProperty = toolbar.rightTextProperty.apply {
                text = "确定"
                textColor = ContextCompat.getColor(
                    this@TopBarActivity,
                    R.color.abc_btn_colored_borderless_text_material
                )
                textBackground =
                    ContextCompat.getDrawable(this@TopBarActivity, R.drawable.btn_shape)

            }

        }
        findViewById<Button>(R.id.center).setOnClickListener {
            toolbar.centerTextProperty = toolbar.centerTextProperty.apply {
                text = "修改"
                textColor = ContextCompat.getColor(
                    this@TopBarActivity,
                    R.color.abc_btn_colored_borderless_text_material
                )
                textSize = 20
                bold   = true
            }

        }


        findViewById<Button>(R.id.customleft).setOnClickListener {
            var text = TextView(this)
            text.text = "自定义"
            text.setTextColor(Color.RED)
            text.textSize = 16f
            toolbar.customLeftView(text, null)

        }

        findViewById<Button>(R.id.customright).setOnClickListener {

            var text = TextView(this)
            text.text = "自定义"
            text.setTextColor(Color.RED)
            text.textSize = 16f
            toolbar.customRightView(text, null)

        }


        val rightView =
            layoutInflater.inflate(R.layout.goodmanager_rightview_titlebar, topbar2, false)
        val rightText = rightView.findViewById<TextView>(R.id.rightText)
        rightText.text = "堂食"
        topbar2.customRightView(rightView, null)


    }
}
