package com.bassbooster.equalizer

import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
import android.widget.RemoteViews

/**
 * Implementation of App Widget functionality.
 */
class AppWidget : AppWidgetProvider() {
    override fun onUpdate(
        context: Context,
        appWidgetManager: AppWidgetManager,
        appWidgetIds: IntArray
    ) {
        // There may be multiple widgets active, so update all of them
        for (appWidgetId in appWidgetIds) {
            updateAppWidget(context, appWidgetManager, appWidgetId,"mmmmm")
        }
    }

    override fun onEnabled(context: Context) {
        // Enter relevant functionality for when the first widget is created
    }

    override fun onDisabled(context: Context) {
        // Enter relevant functionality for when the last widget is disabled
    }

    override fun onReceive(context: Context?, intent: Intent?) {
        super.onReceive(context, intent)
        val views = RemoteViews(context?.packageName, R.layout.app_widget)
        views.apply {
            setTextViewText(R.id.mTxtNameBass, "Bass:")
            setTextViewText(R.id.mTxtNameStereo, "Stereo")
            setTextViewText(R.id.textView, "text")
            setTextViewText(R.id.mTxtStereo, "100")
//        setOnClickPendingIntent(
//            R.id.icLeft,
//            CustomNotificationService.onButtonNotificationClick(
//                context = context,
//                id = R.id.icLeft,
//                text = text
//            )
//        )
//        setOnClickPendingIntent(
//            R.id.icRight,
//            CustomNotificationService.onButtonNotificationClick(
//                context = context,
//                id = R.id.icRight,
//                text = text
//            )
//        )
//        setOnClickPendingIntent(
//            R.id.icLight,
//            CustomNotificationService.onButtonNotificationClick(
//                context = context,
//                id = R.id.icLight
//            )
//        )
//        setOnClickPendingIntent(
//            R.id.mOff,
//            CustomNotificationService.onButtonNotificationClick(context = context, id = R.id.mOff)
//        )
        }

        // Instruct the widget manager to update the widget
//        appWidgetManager.updateAppWidget(appWidgetId, views)
    }
}

internal fun updateAppWidget(
    context: Context,
    appWidgetManager: AppWidgetManager,
    appWidgetId: Int,
    text: String
) {
//    val widgetText = context.getString(R.string.appwidget_text)
    // Construct the RemoteViews object
    val views = RemoteViews(context.packageName, R.layout.app_widget)
    views.apply {
        setTextViewText(R.id.mTxtNameBass, "Bass:")
        setTextViewText(R.id.mTxtNameStereo, "Stereo")
        setTextViewText(R.id.textView, text)
        setTextViewText(R.id.mTxtStereo, "100")
//        setOnClickPendingIntent(
//            R.id.icLeft,
//            CustomNotificationService.onButtonNotificationClick(
//                context = context,
//                id = R.id.icLeft,
//                text = text
//            )
//        )
//        setOnClickPendingIntent(
//            R.id.icRight,
//            CustomNotificationService.onButtonNotificationClick(
//                context = context,
//                id = R.id.icRight,
//                text = text
//            )
//        )
//        setOnClickPendingIntent(
//            R.id.icLight,
//            CustomNotificationService.onButtonNotificationClick(
//                context = context,
//                id = R.id.icLight
//            )
//        )
//        setOnClickPendingIntent(
//            R.id.mOff,
//            CustomNotificationService.onButtonNotificationClick(context = context, id = R.id.mOff)
//        )
    }

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views)
}