package cn.yyxx.eyuangame.core.impl.floating

import android.app.Activity
import android.app.Service
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Binder
import android.os.IBinder
import cn.yyxx.eyuangame.core.entity.FloatFeature
import cn.yyxx.support.ResUtils
import cn.yyxx.support.ui.floating.FloatItem
import cn.yyxx.support.ui.floating.FloatLogoMenu
import cn.yyxx.support.ui.floating.FloatMenuView

/**
 * @author #Suyghur.
 * Created on 2021/06/28
 */
class FloatCenterService : Service() {

        private var floatCenter: FloatLogoMenu? = null
//    private var floatCenter: FloatCenter? = null
    private var mActivity: Activity? = null

    override fun onCreate() {
        super.onCreate()
    }

    fun initService(activity: Activity) {
        this.mActivity = activity
    }

    fun show() {
        if (floatCenter == null && mActivity != null) {
//            val features = mutableListOf(
//                FloatCenterItem(mActivity!!, "", FloatFeature.FEATURE_MEMBER),
//                FloatCenterItem(mActivity!!, "", FloatFeature.FEATURE_GIF),
//                FloatCenterItem(mActivity!!, "", FloatFeature.FEATURE_GM),
//                FloatCenterItem(mActivity!!, "", FloatFeature.FEATURE_CHARGE),
//                FloatCenterItem(mActivity!!, "", FloatFeature.FEATURE_INVITE),
//            )
            val features = mutableListOf(
                FloatItem(
                    ResUtils.getResString(mActivity, "yyxx_tv_float_member_desc"),
                    "#1DB1AD",
                    "#000000",
                    BitmapFactory.decodeResource(mActivity!!.resources, ResUtils.getResId(mActivity, "yyxx_float_member_img", "drawable"))
                ),
                FloatItem(
                    ResUtils.getResString(mActivity, "yyxx_tv_float_gif_desc"),
                    "#1DB1AD",
                    "#000000",
                    BitmapFactory.decodeResource(mActivity!!.resources, ResUtils.getResId(mActivity, "yyxx_float_gif_img", "drawable"))
                ),
                FloatItem(
                    ResUtils.getResString(mActivity, "yyxx_tv_float_gm_desc"),
                    "#1DB1AD",
                    "#000000",
                    BitmapFactory.decodeResource(mActivity!!.resources, ResUtils.getResId(mActivity, "yyxx_float_gm_img", "drawable"))
                ),
                FloatItem(
                    ResUtils.getResString(mActivity, "yyxx_tv_float_charge_desc"),
                    "#1DB1AD",
                    "#000000",
                    BitmapFactory.decodeResource(mActivity!!.resources, ResUtils.getResId(mActivity, "yyxx_float_charge_img", "drawable"))
                ),
                FloatItem(
                    ResUtils.getResString(mActivity, "yyxx_tv_float_invite_desc"),
                    "#1DB1AD",
                    "#000000",
                    BitmapFactory.decodeResource(mActivity!!.resources, ResUtils.getResId(mActivity, "yyxx_float_invite_img", "drawable"))
                ),
            )

            floatCenter = FloatLogoMenu.Builder()
                .withActivity(mActivity)
                .logo(BitmapFactory.decodeResource(mActivity!!.resources, ResUtils.getResId(mActivity, "yyxx_float_logo_img", "drawable")))
                .drawCicleMenuBg(true)
                .backMenuColor("#FFFFFF")
                .setBgDrawable(mActivity!!.resources.getDrawable(ResUtils.getResId(mActivity, "yyxx_float_menu_bg", "drawable")))
                //这个背景色需要和logo的背景色一致
                .setFloatItems(features)
                .defaultLocation(FloatLogoMenu.LEFT)
                .drawRedPointNum(false)
                .showWithListener(object : FloatMenuView.OnMenuClickListener {
                    override fun onItemClick(p0: Int, p1: String?) {
                    }

                    override fun dismiss() {
                    }

                })
//            floatCenter = FloatCenter(mActivity!!, features)
        }
        floatCenter?.show()
    }

    fun hide() {
        floatCenter?.hide()
    }

    fun release() {
        floatCenter?.release()
    }

    override fun onBind(intent: Intent?): IBinder {
        return FloatCenterServiceBinder()
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        return super.onStartCommand(intent, flags, startId)
    }

    inner class FloatCenterServiceBinder : Binder() {
        val service: FloatCenterService = this@FloatCenterService
    }

}