package com.duben.microtribe.ui.widgets

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import com.duben.microtribe.R
import com.duben.microtribe.common.AppConfig
import com.duben.microtribe.mvp.model.VipBean
import com.duben.microtribe.utils.SpanUtils

class PayYesDialog(
    private val context: Context,
    vipBean: VipBean.ListBean,
    private val listener: DialogListener
) : Dialog(
    context, R.style.dialog
) {
    private val lp: WindowManager.LayoutParams
    private val tv_dialog_vip_next: TextView
    private val tv_dialog_vip_count: TextView
    private val iv_dialog_vip_quit: ImageView
    private val iv_dialog_vip_top: ImageView
    private val rl_dialog_vip_bg: RelativeLayout

    init {
        setContentView(R.layout.dialog_payyes)
        // 设置window属性
        lp = window!!.attributes
        lp.gravity = Gravity.CENTER
        lp.width = WindowManager.LayoutParams.MATCH_PARENT
        lp.windowAnimations = R.style.DialogAnimBottom
        window!!.attributes = lp

        // 设置外部不可关闭
        setCancelable(false)
        setCanceledOnTouchOutside(false)
        setOnKeyListener { dialogInterface, i, keyEvent ->
            i == KeyEvent.KEYCODE_BACK
        }


        // 查找View
        iv_dialog_vip_quit = findViewById<View>(R.id.iv_dialog_vip_quit) as ImageView
        iv_dialog_vip_top = findViewById<View>(R.id.iv_dialog_vip_top) as ImageView
        tv_dialog_vip_next = findViewById<View>(R.id.tv_dialog_vip_next) as TextView
        tv_dialog_vip_count = findViewById<View>(R.id.tv_dialog_vip_count) as TextView
        rl_dialog_vip_bg = findViewById<View>(R.id.rl_dialog_vip_bg) as RelativeLayout
        iv_dialog_vip_quit.setOnClickListener(listener)
        tv_dialog_vip_next.setOnClickListener(listener)

        if (vipBean.trial == 0) {
            //0-没签约 无0.01
            tv_dialog_vip_count.text = SpanUtils()
                .append("" + vipBean.price)
                .setFontSize(30, true)
                .append(" 元")
                .setFontSize(16, true)
                .create()
            iv_dialog_vip_top.setImageResource(R.mipmap.ic_vip_pay_top2)
        } else {
            tv_dialog_vip_count.text = SpanUtils()
                .append(""+vipBean.price)
                .setFontSize(30, true)
                .append(" 元")
                .setFontSize(16, true)
                .create()
            iv_dialog_vip_top.setImageResource(R.mipmap.ic_vip_pay_top2)
        }
    }
}