package com.zswc.creativity.widget

import android.content.Context
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.databinding.DataBindingUtil
import com.qmuiteam.qmui.kotlin.onClick
import com.zswc.creativity.R
import com.zswc.creativity.activity.WebViewActivity
import com.zswc.creativity.databinding.WidgetPolicyBinding
import com.ysnows.base.utils.B
import com.ysnows.base.utils.UiSwitch

open class WidgetPolicy constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearLayout(context, attrs, defStyleAttr) {
    lateinit var binding: WidgetPolicyBinding

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

    private fun initView(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.widget_policy, this, true)
        orientation = HORIZONTAL
        gravity = Gravity.CENTER

    }

    private fun listeners() {
        binding.tvPrivatePolicy.onClick {
            UiSwitch.bundle(context, WebViewActivity::class.java, B.with().putString("url", "http://www.baidu.com").ok())
        }
        binding.tvUserPolicy.onClick {
            UiSwitch.bundle(context, WebViewActivity::class.java, B.with().putString("url", "http://www.baidu.com").ok())
        }

    }

    init {
        initView(context, attrs, defStyleAttr)
        listeners()
    }
}
