// Code generated by girgen. DO NOT EDIT.

package adw

import (
	"runtime"
	"unsafe"

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

// #include <stdlib.h>
// #include <adwaita.h>
// #include <glib-object.h>
import "C"

// GType values.
var (
	GTypePreferencesDialog = coreglib.Type(C.adw_preferences_dialog_get_type())
)

func init() {
	coreglib.RegisterGValueMarshalers([]coreglib.TypeMarshaler{
		coreglib.TypeMarshaler{T: GTypePreferencesDialog, F: marshalPreferencesDialog},
	})
}

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

func defaultPreferencesDialogOverrides(v *PreferencesDialog) PreferencesDialogOverrides {
	return PreferencesDialogOverrides{}
}

// PreferencesDialog: dialog showing application's preferences.
//
// <picture> <source srcset="preferences-dialog-dark.png"
// media="(prefers-color-scheme: dark)"> <img src="preferences-dialog.png"
// alt="preferences-dialog"> </picture>
//
// The AdwPreferencesDialog widget presents an application's preferences
// gathered into pages and groups. The preferences are searchable by the user.
//
// # CSS nodes
//
// AdwPreferencesDialog has a main CSS node with the name dialog and the style
// class .preferences.
type PreferencesDialog struct {
	_ [0]func() // equal guard
	Dialog
}

var (
	_ gtk.Widgetter = (*PreferencesDialog)(nil)
)

func init() {
	coreglib.RegisterClassInfo[*PreferencesDialog, *PreferencesDialogClass, PreferencesDialogOverrides](
		GTypePreferencesDialog,
		initPreferencesDialogClass,
		wrapPreferencesDialog,
		defaultPreferencesDialogOverrides,
	)
}

func initPreferencesDialogClass(gclass unsafe.Pointer, overrides PreferencesDialogOverrides, classInitFunc func(*PreferencesDialogClass)) {
	if classInitFunc != nil {
		class := (*PreferencesDialogClass)(gextras.NewStructNative(gclass))
		classInitFunc(class)
	}
}

func wrapPreferencesDialog(obj *coreglib.Object) *PreferencesDialog {
	return &PreferencesDialog{
		Dialog: Dialog{
			Widget: gtk.Widget{
				InitiallyUnowned: coreglib.InitiallyUnowned{
					Object: obj,
				},
				Object: obj,
				Accessible: gtk.Accessible{
					Object: obj,
				},
				Buildable: gtk.Buildable{
					Object: obj,
				},
				ConstraintTarget: gtk.ConstraintTarget{
					Object: obj,
				},
			},
		},
	}
}

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

// NewPreferencesDialog creates a new AdwPreferencesDialog.
//
// The function returns the following values:
//
//   - preferencesDialog: newly created AdwPreferencesDialog.
func NewPreferencesDialog() *PreferencesDialog {
	var _cret *C.AdwDialog // in

	_cret = C.adw_preferences_dialog_new()

	var _preferencesDialog *PreferencesDialog // out

	_preferencesDialog = wrapPreferencesDialog(coreglib.Take(unsafe.Pointer(_cret)))

	return _preferencesDialog
}

// Add adds a preferences page to self.
//
// The function takes the following parameters:
//
//   - page to add.
func (self *PreferencesDialog) Add(page *PreferencesPage) {
	var _arg0 *C.AdwPreferencesDialog // out
	var _arg1 *C.AdwPreferencesPage   // out

	_arg0 = (*C.AdwPreferencesDialog)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.AdwPreferencesPage)(unsafe.Pointer(coreglib.InternObject(page).Native()))

	C.adw_preferences_dialog_add(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(page)
}

// AddToast displays toast.
//
// See toastoverlay.AddToast.
//
// The function takes the following parameters:
//
//   - toast: toast.
func (self *PreferencesDialog) AddToast(toast *Toast) {
	var _arg0 *C.AdwPreferencesDialog // out
	var _arg1 *C.AdwToast             // out

	_arg0 = (*C.AdwPreferencesDialog)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.AdwToast)(unsafe.Pointer(coreglib.InternObject(toast).Native()))
	C.g_object_ref(C.gpointer(coreglib.InternObject(toast).Native()))

	C.adw_preferences_dialog_add_toast(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(toast)
}

// SearchEnabled gets whether search is enabled for self.
//
// The function returns the following values:
//
//   - ok: whether search is enabled for self.
func (self *PreferencesDialog) SearchEnabled() bool {
	var _arg0 *C.AdwPreferencesDialog // out
	var _cret C.gboolean              // in

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

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

	var _ok bool // out

	if _cret != 0 {
		_ok = true
	}

	return _ok
}

// VisiblePage gets the currently visible page of self.
//
// The function returns the following values:
//
//   - preferencesPage (optional): visible page.
func (self *PreferencesDialog) VisiblePage() *PreferencesPage {
	var _arg0 *C.AdwPreferencesDialog // out
	var _cret *C.AdwPreferencesPage   // in

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

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

	var _preferencesPage *PreferencesPage // out

	if _cret != nil {
		_preferencesPage = wrapPreferencesPage(coreglib.Take(unsafe.Pointer(_cret)))
	}

	return _preferencesPage
}

// VisiblePageName gets the name of currently visible page of self.
//
// The function returns the following values:
//
//   - utf8 (optional): name of the visible page.
func (self *PreferencesDialog) VisiblePageName() string {
	var _arg0 *C.AdwPreferencesDialog // out
	var _cret *C.char                 // in

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

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

	var _utf8 string // out

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

	return _utf8
}

// PopSubpage: pop the visible page from the subpage stack of self.
//
// The function returns the following values:
//
//   - ok: TRUE if a page has been popped.
func (self *PreferencesDialog) PopSubpage() bool {
	var _arg0 *C.AdwPreferencesDialog // out
	var _cret C.gboolean              // in

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

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

	var _ok bool // out

	if _cret != 0 {
		_ok = true
	}

	return _ok
}

// PushSubpage pushes page onto the subpage stack of self.
//
// The page will be automatically removed when popped.
//
// The function takes the following parameters:
//
//   - page: subpage.
func (self *PreferencesDialog) PushSubpage(page *NavigationPage) {
	var _arg0 *C.AdwPreferencesDialog // out
	var _arg1 *C.AdwNavigationPage    // out

	_arg0 = (*C.AdwPreferencesDialog)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.AdwNavigationPage)(unsafe.Pointer(coreglib.InternObject(page).Native()))

	C.adw_preferences_dialog_push_subpage(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(page)
}

// Remove removes a page from self.
//
// The function takes the following parameters:
//
//   - page to remove.
func (self *PreferencesDialog) Remove(page *PreferencesPage) {
	var _arg0 *C.AdwPreferencesDialog // out
	var _arg1 *C.AdwPreferencesPage   // out

	_arg0 = (*C.AdwPreferencesDialog)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.AdwPreferencesPage)(unsafe.Pointer(coreglib.InternObject(page).Native()))

	C.adw_preferences_dialog_remove(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(page)
}

// SetSearchEnabled sets whether search is enabled for self.
//
// The function takes the following parameters:
//
//   - searchEnabled: whether search is enabled.
func (self *PreferencesDialog) SetSearchEnabled(searchEnabled bool) {
	var _arg0 *C.AdwPreferencesDialog // out
	var _arg1 C.gboolean              // out

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

	C.adw_preferences_dialog_set_search_enabled(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(searchEnabled)
}

// SetVisiblePage makes page the visible page of self.
//
// The function takes the following parameters:
//
//   - page of self.
func (self *PreferencesDialog) SetVisiblePage(page *PreferencesPage) {
	var _arg0 *C.AdwPreferencesDialog // out
	var _arg1 *C.AdwPreferencesPage   // out

	_arg0 = (*C.AdwPreferencesDialog)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.AdwPreferencesPage)(unsafe.Pointer(coreglib.InternObject(page).Native()))

	C.adw_preferences_dialog_set_visible_page(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(page)
}

// SetVisiblePageName makes the page with the given name visible.
//
// See preferencesdialog:visible-page.
//
// The function takes the following parameters:
//
//   - name of the page to make visible.
func (self *PreferencesDialog) SetVisiblePageName(name string) {
	var _arg0 *C.AdwPreferencesDialog // out
	var _arg1 *C.char                 // out

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

	C.adw_preferences_dialog_set_visible_page_name(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(name)
}
