// Code generated by girgen. DO NOT EDIT.

package adw

import (
	"fmt"
	"runtime"
	"unsafe"

	"github.com/diamondburned/gotk4/pkg/core/gextras"
	coreglib "github.com/diamondburned/gotk4/pkg/core/glib"
	"github.com/diamondburned/gotk4/pkg/glib/v2"
	"github.com/diamondburned/gotk4/pkg/gtk/v4"
)

// #include <stdlib.h>
// #include <adwaita.h>
// #include <glib-object.h>
// extern void _gotk4_adw1_Toast_ConnectDismissed(gpointer, guintptr);
// extern void _gotk4_adw1_Toast_ConnectButtonClicked(gpointer, guintptr);
import "C"

// GType values.
var (
	GTypeToastPriority = coreglib.Type(C.adw_toast_priority_get_type())
	GTypeToast         = coreglib.Type(C.adw_toast_get_type())
)

func init() {
	coreglib.RegisterGValueMarshalers([]coreglib.TypeMarshaler{
		coreglib.TypeMarshaler{T: GTypeToastPriority, F: marshalToastPriority},
		coreglib.TypeMarshaler{T: GTypeToast, F: marshalToast},
	})
}

// ToastPriority: toast behavior when another toast is already displayed.
type ToastPriority C.gint

const (
	// ToastPriorityNormal: toast will be queued if another toast is already
	// displayed.
	ToastPriorityNormal ToastPriority = iota
	// ToastPriorityHigh: toast will be displayed immediately, pushing the
	// previous toast into the queue instead.
	ToastPriorityHigh
)

func marshalToastPriority(p uintptr) (interface{}, error) {
	return ToastPriority(coreglib.ValueFromNative(unsafe.Pointer(p)).Enum()), nil
}

// String returns the name in string for ToastPriority.
func (t ToastPriority) String() string {
	switch t {
	case ToastPriorityNormal:
		return "Normal"
	case ToastPriorityHigh:
		return "High"
	default:
		return fmt.Sprintf("ToastPriority(%d)", t)
	}
}

// ToastOverrides contains methods that are overridable.
type ToastOverrides struct {
}

func defaultToastOverrides(v *Toast) ToastOverrides {
	return ToastOverrides{}
}

// Toast: helper object for toastoverlay.
//
// Toasts are meant to be passed into toastoverlay.AddToast as follows:
//
//	adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));
//
// <picture> <source srcset="toast-simple-dark.png"
// media="(prefers-color-scheme: dark)"> <img src="toast-simple.png"
// alt="toast-simple"> </picture>
//
// Toasts always have a close button. They emit the toast::dismissed signal when
// disappearing.
//
// toast:timeout determines how long the toast stays on screen, while
// toast:priority determines how it behaves if another toast is already being
// displayed.
//
// Toast titles use Pango markup by default, set toast:use-markup to FALSE if
// this is unwanted.
//
// toast:custom-title can be used to replace the title label with a custom
// widget.
//
// # Actions
//
// Toasts can have one button on them, with a label and an attached gio.Action.
//
//	AdwToast *toast = adw_toast_new (_("Toast with Action"));
//
//	adw_toast_set_button_label (toast, _("_Example"));
//	adw_toast_set_action_name (toast, "win.example");
//
//	adw_toast_overlay_add_toast (overlay, toast);
//
// <picture> <source srcset="toast-action-dark.png"
// media="(prefers-color-scheme: dark)"> <img src="toast-action.png"
// alt="toast-action"> </picture>
//
// # Modifying toasts
//
// Toasts can be modified after they have been shown. For this, an AdwToast
// reference must be kept around while the toast is visible.
//
// A common use case for this is using toasts as undo prompts that stack with
// each other, allowing to batch undo the last deleted items:
//
//	static void
//	toast_undo_cb (GtkWidget  *sender,
//	               const char *action,
//	               GVariant   *param)
//	{
//	  // Undo the deletion
//	}
//
//	static void
//	dismissed_cb (MyWindow *self)
//	{
//	  self->undo_toast = NULL;
//
//	  // Permanently delete the items
//	}
//
//	static void
//	delete_item (MyWindow *self,
//	             MyItem   *item)
//	{
//	  g_autofree char *title = NULL;
//	  int n_items;
//
//	  // Mark the item as waiting for deletion
//	  n_items = ... // The number of waiting items
//
//	  if (!self->undo_toast) {
//	    self->undo_toast = adw_toast_new_format (_("‘s’ deleted"), ...);
//
//	    adw_toast_set_priority (self->undo_toast, ADW_TOAST_PRIORITY_HIGH);
//	    adw_toast_set_button_label (self->undo_toast, _("_Undo"));
//	    adw_toast_set_action_name (self->undo_toast, "toast.undo");
//
//	    g_signal_connect_swapped (self->undo_toast, "dismissed",
//	                              G_CALLBACK (dismissed_cb), self);
//
//	    adw_toast_overlay_add_toast (self->toast_overlay, self->undo_toast);
//
//	    return;
//	  }
//
//	  title =
//	    g_strdup_printf (ngettext ("<span font_features='tnum=1'>d</span> item deleted",
//	                               "<span font_features='tnum=1'>d</span> items deleted",
//	                               n_items), n_items);
//
//	  adw_toast_set_title (self->undo_toast, title);
//
//	  // Bump the toast timeout
//	  adw_toast_overlay_add_toast (self->toast_overlay, g_object_ref (self->undo_toast));
//	}
//
//	static void
//	my_window_class_init (MyWindowClass *klass)
//	{
//	  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
//
//	  gtk_widget_class_install_action (widget_class, "toast.undo", NULL, toast_undo_cb);
//	}
//
// <picture> <source srcset="toast-undo-dark.png" media="(prefers-color-scheme:
// dark)"> <img src="toast-undo.png" alt="toast-undo"> </picture>.
type Toast struct {
	_ [0]func() // equal guard
	*coreglib.Object
}

var (
	_ coreglib.Objector = (*Toast)(nil)
)

func init() {
	coreglib.RegisterClassInfo[*Toast, *ToastClass, ToastOverrides](
		GTypeToast,
		initToastClass,
		wrapToast,
		defaultToastOverrides,
	)
}

func initToastClass(gclass unsafe.Pointer, overrides ToastOverrides, classInitFunc func(*ToastClass)) {
	if classInitFunc != nil {
		class := (*ToastClass)(gextras.NewStructNative(gclass))
		classInitFunc(class)
	}
}

func wrapToast(obj *coreglib.Object) *Toast {
	return &Toast{
		Object: obj,
	}
}

func marshalToast(p uintptr) (interface{}, error) {
	return wrapToast(coreglib.ValueFromNative(unsafe.Pointer(p)).Object()), nil
}

// ConnectButtonClicked is emitted after the button has been clicked.
//
// It can be used as an alternative to setting an action.
func (self *Toast) ConnectButtonClicked(f func()) coreglib.SignalHandle {
	return coreglib.ConnectGeneratedClosure(self, "button-clicked", false, unsafe.Pointer(C._gotk4_adw1_Toast_ConnectButtonClicked), f)
}

// ConnectDismissed is emitted when the toast has been dismissed.
func (self *Toast) ConnectDismissed(f func()) coreglib.SignalHandle {
	return coreglib.ConnectGeneratedClosure(self, "dismissed", false, unsafe.Pointer(C._gotk4_adw1_Toast_ConnectDismissed), f)
}

// NewToast creates a new AdwToast.
//
// The toast will use title as its title.
//
// title can be marked up with the Pango text markup language.
//
// The function takes the following parameters:
//
//   - title to be displayed.
//
// The function returns the following values:
//
//   - toast: new created AdwToast.
func NewToast(title string) *Toast {
	var _arg1 *C.char     // out
	var _cret *C.AdwToast // in

	_arg1 = (*C.char)(unsafe.Pointer(C.CString(title)))
	defer C.free(unsafe.Pointer(_arg1))

	_cret = C.adw_toast_new(_arg1)
	runtime.KeepAlive(title)

	var _toast *Toast // out

	_toast = wrapToast(coreglib.AssumeOwnership(unsafe.Pointer(_cret)))

	return _toast
}

// Dismiss dismisses self.
//
// Does nothing if self has already been dismissed, or hasn't been added to an
// toastoverlay.
func (self *Toast) Dismiss() {
	var _arg0 *C.AdwToast // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	C.adw_toast_dismiss(_arg0)
	runtime.KeepAlive(self)
}

// ActionName gets the name of the associated action.
//
// The function returns the following values:
//
//   - utf8 (optional): action name.
func (self *Toast) ActionName() string {
	var _arg0 *C.AdwToast // out
	var _cret *C.char     // in

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_toast_get_action_name(_arg0)
	runtime.KeepAlive(self)

	var _utf8 string // out

	if _cret != nil {
		_utf8 = C.GoString((*C.gchar)(unsafe.Pointer(_cret)))
	}

	return _utf8
}

// ActionTargetValue gets the parameter for action invocations.
//
// The function returns the following values:
//
//   - variant (optional): action target.
func (self *Toast) ActionTargetValue() *glib.Variant {
	var _arg0 *C.AdwToast // out
	var _cret *C.GVariant // in

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_toast_get_action_target_value(_arg0)
	runtime.KeepAlive(self)

	var _variant *glib.Variant // out

	if _cret != nil {
		_variant = (*glib.Variant)(gextras.NewStructNative(unsafe.Pointer(_cret)))
		C.g_variant_ref(_cret)
		runtime.SetFinalizer(
			gextras.StructIntern(unsafe.Pointer(_variant)),
			func(intern *struct{ C unsafe.Pointer }) {
				C.g_variant_unref((*C.GVariant)(intern.C))
			},
		)
	}

	return _variant
}

// ButtonLabel gets the label to show on the button.
//
// The function returns the following values:
//
//   - utf8 (optional): button label.
func (self *Toast) ButtonLabel() string {
	var _arg0 *C.AdwToast // out
	var _cret *C.char     // in

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_toast_get_button_label(_arg0)
	runtime.KeepAlive(self)

	var _utf8 string // out

	if _cret != nil {
		_utf8 = C.GoString((*C.gchar)(unsafe.Pointer(_cret)))
	}

	return _utf8
}

// CustomTitle gets the custom title widget of self.
//
// The function returns the following values:
//
//   - widget (optional): custom title widget.
func (self *Toast) CustomTitle() gtk.Widgetter {
	var _arg0 *C.AdwToast  // out
	var _cret *C.GtkWidget // in

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_toast_get_custom_title(_arg0)
	runtime.KeepAlive(self)

	var _widget gtk.Widgetter // out

	if _cret != nil {
		{
			objptr := unsafe.Pointer(_cret)

			object := coreglib.Take(objptr)
			casted := object.WalkCast(func(obj coreglib.Objector) bool {
				_, ok := obj.(gtk.Widgetter)
				return ok
			})
			rv, ok := casted.(gtk.Widgetter)
			if !ok {
				panic("no marshaler for " + object.TypeFromInstance().String() + " matching gtk.Widgetter")
			}
			_widget = rv
		}
	}

	return _widget
}

// Priority gets priority for self.
//
// The function returns the following values:
//
//   - toastPriority: priority.
func (self *Toast) Priority() ToastPriority {
	var _arg0 *C.AdwToast        // out
	var _cret C.AdwToastPriority // in

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_toast_get_priority(_arg0)
	runtime.KeepAlive(self)

	var _toastPriority ToastPriority // out

	_toastPriority = ToastPriority(_cret)

	return _toastPriority
}

// Timeout gets timeout for self.
//
// The function returns the following values:
//
//   - guint: timeout.
func (self *Toast) Timeout() uint {
	var _arg0 *C.AdwToast // out
	var _cret C.guint     // in

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_toast_get_timeout(_arg0)
	runtime.KeepAlive(self)

	var _guint uint // out

	_guint = uint(_cret)

	return _guint
}

// Title gets the title that will be displayed on the toast.
//
// If a custom title has been set with adw.Toast.SetCustomTitle() the return
// value will be NULL.
//
// The function returns the following values:
//
//   - utf8 (optional): title.
func (self *Toast) Title() string {
	var _arg0 *C.AdwToast // out
	var _cret *C.char     // in

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_toast_get_title(_arg0)
	runtime.KeepAlive(self)

	var _utf8 string // out

	if _cret != nil {
		_utf8 = C.GoString((*C.gchar)(unsafe.Pointer(_cret)))
	}

	return _utf8
}

// UseMarkup gets whether to use Pango markup for the toast title.
//
// The function returns the following values:
//
//   - ok: whether the toast uses markup.
func (self *Toast) UseMarkup() bool {
	var _arg0 *C.AdwToast // out
	var _cret C.gboolean  // in

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_toast_get_use_markup(_arg0)
	runtime.KeepAlive(self)

	var _ok bool // out

	if _cret != 0 {
		_ok = true
	}

	return _ok
}

// SetActionName sets the name of the associated action.
//
// It will be activated when clicking the button.
//
// See toast:action-target.
//
// The function takes the following parameters:
//
//   - actionName (optional): action name.
func (self *Toast) SetActionName(actionName string) {
	var _arg0 *C.AdwToast // out
	var _arg1 *C.char     // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if actionName != "" {
		_arg1 = (*C.char)(unsafe.Pointer(C.CString(actionName)))
		defer C.free(unsafe.Pointer(_arg1))
	}

	C.adw_toast_set_action_name(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(actionName)
}

// SetActionTargetValue sets the parameter for action invocations.
//
// If the action_target variant has a floating reference this function will sink
// it.
//
// The function takes the following parameters:
//
//   - actionTarget (optional): action target.
func (self *Toast) SetActionTargetValue(actionTarget *glib.Variant) {
	var _arg0 *C.AdwToast // out
	var _arg1 *C.GVariant // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if actionTarget != nil {
		_arg1 = (*C.GVariant)(gextras.StructNative(unsafe.Pointer(actionTarget)))
	}

	C.adw_toast_set_action_target_value(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(actionTarget)
}

// SetButtonLabel sets the label to show on the button.
//
// Underlines in the button text can be used to indicate a mnemonic.
//
// If set to NULL, the button won't be shown.
//
// See toast:action-name.
//
// The function takes the following parameters:
//
//   - buttonLabel (optional): button label.
func (self *Toast) SetButtonLabel(buttonLabel string) {
	var _arg0 *C.AdwToast // out
	var _arg1 *C.char     // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if buttonLabel != "" {
		_arg1 = (*C.char)(unsafe.Pointer(C.CString(buttonLabel)))
		defer C.free(unsafe.Pointer(_arg1))
	}

	C.adw_toast_set_button_label(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(buttonLabel)
}

// SetCustomTitle sets the custom title widget of self.
//
// It will be displayed instead of the title if set. In this case, toast:title
// is ignored.
//
// Setting a custom title will unset toast:title.
//
// The function takes the following parameters:
//
//   - widget (optional): custom title widget.
func (self *Toast) SetCustomTitle(widget gtk.Widgetter) {
	var _arg0 *C.AdwToast  // out
	var _arg1 *C.GtkWidget // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if widget != nil {
		_arg1 = (*C.GtkWidget)(unsafe.Pointer(coreglib.InternObject(widget).Native()))
	}

	C.adw_toast_set_custom_title(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(widget)
}

// SetDetailedActionName sets the action name and its parameter.
//
// detailed_action_name is a string in the format accepted by
// gio.Action().ParseDetailedName.
//
// The function takes the following parameters:
//
//   - detailedActionName (optional): detailed action name.
func (self *Toast) SetDetailedActionName(detailedActionName string) {
	var _arg0 *C.AdwToast // out
	var _arg1 *C.char     // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if detailedActionName != "" {
		_arg1 = (*C.char)(unsafe.Pointer(C.CString(detailedActionName)))
		defer C.free(unsafe.Pointer(_arg1))
	}

	C.adw_toast_set_detailed_action_name(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(detailedActionName)
}

// SetPriority sets priority for self.
//
// Priority controls how the toast behaves when another toast is already being
// displayed.
//
// If priority is ADW_TOAST_PRIORITY_NORMAL, the toast will be queued.
//
// If priority is ADW_TOAST_PRIORITY_HIGH, the toast will be displayed
// immediately, pushing the previous toast into the queue instead.
//
// The function takes the following parameters:
//
//   - priority: priority.
func (self *Toast) SetPriority(priority ToastPriority) {
	var _arg0 *C.AdwToast        // out
	var _arg1 C.AdwToastPriority // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = C.AdwToastPriority(priority)

	C.adw_toast_set_priority(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(priority)
}

// SetTimeout sets timeout for self.
//
// If timeout is 0, the toast is displayed indefinitely until manually
// dismissed.
//
// Toasts cannot disappear while being hovered, pressed (on touchscreen),
// or have keyboard focus inside them.
//
// The function takes the following parameters:
//
//   - timeout: timeout.
func (self *Toast) SetTimeout(timeout uint) {
	var _arg0 *C.AdwToast // out
	var _arg1 C.guint     // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = C.guint(timeout)

	C.adw_toast_set_timeout(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(timeout)
}

// SetTitle sets the title that will be displayed on the toast.
//
// The title can be marked up with the Pango text markup language.
//
// Setting a title will unset toast:custom-title.
//
// If toast:custom-title is set, it will be used instead.
//
// The function takes the following parameters:
//
//   - title: title.
func (self *Toast) SetTitle(title string) {
	var _arg0 *C.AdwToast // out
	var _arg1 *C.char     // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.char)(unsafe.Pointer(C.CString(title)))
	defer C.free(unsafe.Pointer(_arg1))

	C.adw_toast_set_title(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(title)
}

// SetUseMarkup: whether to use Pango markup for the toast title.
//
// See also pango.ParseMarkup().
//
// The function takes the following parameters:
//
//   - useMarkup: whether to use markup.
func (self *Toast) SetUseMarkup(useMarkup bool) {
	var _arg0 *C.AdwToast // out
	var _arg1 C.gboolean  // out

	_arg0 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if useMarkup {
		_arg1 = C.TRUE
	}

	C.adw_toast_set_use_markup(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(useMarkup)
}

// ToastClass: instance of this type is always passed by reference.
type ToastClass struct {
	*toastClass
}

// toastClass is the struct that's finalized.
type toastClass struct {
	native *C.AdwToastClass
}
