package com.secspace.sms.popup

import android.content.Context
import android.view.Gravity
import android.view.animation.Animation
import android.widget.TextView
import com.secspace.sms.R
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.Direction
import razerdp.util.animation.TranslationConfig


class TipPopup(mContext: Context, private val sureResult: (Int,String) -> Unit) : BasePopupWindow(mContext) {

    private val tvPhoneNumber by lazy { findViewById<TextView>(R.id.tv_phone_number) }
    private val tvCallPhone by lazy { findViewById<TextView>(R.id.tv_call_phone) }
    private val tvCallPhoneEdit by lazy { findViewById<TextView>(R.id.tv_call_phone_edit) }
    private val tvSendSms by lazy { findViewById<TextView>(R.id.tv_send_sms) }
    private val tvCopy by lazy { findViewById<TextView>(R.id.tv_copy_phone_number) }
    private val tvAddContacts by lazy { findViewById<TextView>(R.id.tv_add_contacts) }
    private val tvSaveContacts by lazy { findViewById<TextView>(R.id.tv_save_contacts) }
    private val tvCancel by lazy { findViewById<TextView>(R.id.tv_cancel_pop) }


    private var phoneNumbers :String = ""
    init {
        setContentView(R.layout.d_ui_tips_popup)

        setBlurBackgroundEnable(false)
        setOutSideDismiss(false)
        setBackPressEnable(false)

        popupGravity = Gravity.BOTTOM

        tvCancel.setOnClickListener {
            dismiss()
        }

        tvCallPhone.setOnClickListener {
            sureResult.invoke(1,phoneNumbers)
            dismiss()
        }
        tvCallPhoneEdit.setOnClickListener {
            sureResult.invoke(2,phoneNumbers)
            dismiss()
        }
        tvSendSms.setOnClickListener {
            sureResult.invoke(3,phoneNumbers)
            dismiss()
        }
        tvCopy.setOnClickListener {
            sureResult.invoke(4,phoneNumbers)
            dismiss()
        }
        tvAddContacts.setOnClickListener {
            sureResult.invoke(5,phoneNumbers)
            dismiss()
        }
        tvSaveContacts.setOnClickListener {
            sureResult.invoke(6,phoneNumbers)
            dismiss()
        }
    }

    fun setPhoneNumberData(phoneNumber: String) {
        tvPhoneNumber.text = phoneNumber
        phoneNumbers = phoneNumber
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withTranslation(
                TranslationConfig()
                    .from(Direction.BOTTOM)
                    .to(Direction.IDLE)
            )
            .toShow()
    }

    /* override fun onCreateDismissAnimation(): Animation {
         return AnimationHelper.asAnimation()
             .withTranslation(
                 TranslationConfig()
                     .from(Direction.TOP)
                     .to(Direction.IDLE)
             )
             .toShow()
     }*/
}
