// 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/gtk/v4"
)

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

// GType values.
var (
	GTypeViewSwitcherPolicy = coreglib.Type(C.adw_view_switcher_policy_get_type())
	GTypeViewSwitcher       = coreglib.Type(C.adw_view_switcher_get_type())
)

func init() {
	coreglib.RegisterGValueMarshalers([]coreglib.TypeMarshaler{
		coreglib.TypeMarshaler{T: GTypeViewSwitcherPolicy, F: marshalViewSwitcherPolicy},
		coreglib.TypeMarshaler{T: GTypeViewSwitcher, F: marshalViewSwitcher},
	})
}

// ViewSwitcherPolicy describes the adaptive modes of viewswitcher.
type ViewSwitcherPolicy C.gint

const (
	// ViewSwitcherPolicyNarrow: force the narrow mode.
	ViewSwitcherPolicyNarrow ViewSwitcherPolicy = iota
	// ViewSwitcherPolicyWide: force the wide mode.
	ViewSwitcherPolicyWide
)

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

// String returns the name in string for ViewSwitcherPolicy.
func (v ViewSwitcherPolicy) String() string {
	switch v {
	case ViewSwitcherPolicyNarrow:
		return "Narrow"
	case ViewSwitcherPolicyWide:
		return "Wide"
	default:
		return fmt.Sprintf("ViewSwitcherPolicy(%d)", v)
	}
}

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

func defaultViewSwitcherOverrides(v *ViewSwitcher) ViewSwitcherOverrides {
	return ViewSwitcherOverrides{}
}

// ViewSwitcher: adaptive view switcher.
//
// <picture> <source srcset="view-switcher-dark.png"
// media="(prefers-color-scheme: dark)"> <img src="view-switcher.png"
// alt="view-switcher"> </picture>
//
// An adaptive view switcher designed to switch between multiple views contained
// in a viewstack in a similar fashion to gtk.StackSwitcher.
//
// AdwViewSwitcher buttons always have an icon and a label. They can be
// displayed side by side, or icon on top of the label. This can be controlled
// via the viewswitcher:policy property.
//
// AdwViewSwitcher is intended to be used in a header bar together with
// viewswitcherbar at the bottom of the window, and a breakpoint showing the
// view switcher bar on narrow sizes, while removing the view switcher from the
// header bar, as follows:
//
//	<object class="AdwWindow">
//	  <child>
//	    <object class="AdwBreakpoint">
//	      <condition>max-width: 550sp</condition>
//	      <setter object="switcher_bar" property="reveal">True</setter>
//	      <setter object="header_bar" property="title-widget"/>
//	    </object>
//	  </child>
//	  <property name="content">
//	    <object class="AdwToolbarView">
//	      <child type="top">
//	        <object class="AdwHeaderBar" id="header_bar">
//	          <property name="title-widget">
//	            <object class="AdwViewSwitcher">
//	              <property name="stack">stack</property>
//	              <property name="policy">wide</property>
//	            </object>
//	          </property>
//	        </object>
//	      </child>
//	      <property name="content">
//	        <object class="AdwViewStack" id="stack"/>
//	      </property>
//	      <child type="bottom">
//	        <object class="AdwViewSwitcherBar" id="switcher_bar">
//	          <property name="stack">stack</property>
//	        </object>
//	      </child>
//	    </object>
//	  </property>
//	</object>
//
// It's recommended to set viewswitcher:policy to ADW_VIEW_SWITCHER_POLICY_WIDE
// in this case.
//
// You may have to adjust the breakpoint condition for your specific pages.
//
// # CSS nodes
//
// AdwViewSwitcher has a single CSS node with name viewswitcher. It can have the
// style classes .wide and .narrow, matching its policy.
//
// # Accessibility
//
// AdwViewSwitcher uses the GTK_ACCESSIBLE_ROLE_TAB_LIST role and uses the
// GTK_ACCESSIBLE_ROLE_TAB for its buttons.
type ViewSwitcher struct {
	_ [0]func() // equal guard
	gtk.Widget
}

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

func init() {
	coreglib.RegisterClassInfo[*ViewSwitcher, *ViewSwitcherClass, ViewSwitcherOverrides](
		GTypeViewSwitcher,
		initViewSwitcherClass,
		wrapViewSwitcher,
		defaultViewSwitcherOverrides,
	)
}

func initViewSwitcherClass(gclass unsafe.Pointer, overrides ViewSwitcherOverrides, classInitFunc func(*ViewSwitcherClass)) {
	if classInitFunc != nil {
		class := (*ViewSwitcherClass)(gextras.NewStructNative(gclass))
		classInitFunc(class)
	}
}

func wrapViewSwitcher(obj *coreglib.Object) *ViewSwitcher {
	return &ViewSwitcher{
		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 marshalViewSwitcher(p uintptr) (interface{}, error) {
	return wrapViewSwitcher(coreglib.ValueFromNative(unsafe.Pointer(p)).Object()), nil
}

// NewViewSwitcher creates a new AdwViewSwitcher.
//
// The function returns the following values:
//
//   - viewSwitcher: newly created AdwViewSwitcher.
func NewViewSwitcher() *ViewSwitcher {
	var _cret *C.GtkWidget // in

	_cret = C.adw_view_switcher_new()

	var _viewSwitcher *ViewSwitcher // out

	_viewSwitcher = wrapViewSwitcher(coreglib.Take(unsafe.Pointer(_cret)))

	return _viewSwitcher
}

// Policy gets the policy of self.
//
// The function returns the following values:
//
//   - viewSwitcherPolicy: policy of self.
func (self *ViewSwitcher) Policy() ViewSwitcherPolicy {
	var _arg0 *C.AdwViewSwitcher      // out
	var _cret C.AdwViewSwitcherPolicy // in

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

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

	var _viewSwitcherPolicy ViewSwitcherPolicy // out

	_viewSwitcherPolicy = ViewSwitcherPolicy(_cret)

	return _viewSwitcherPolicy
}

// Stack gets the stack controlled by self.
//
// The function returns the following values:
//
//   - viewStack (optional): stack.
func (self *ViewSwitcher) Stack() *ViewStack {
	var _arg0 *C.AdwViewSwitcher // out
	var _cret *C.AdwViewStack    // in

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

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

	var _viewStack *ViewStack // out

	if _cret != nil {
		_viewStack = wrapViewStack(coreglib.Take(unsafe.Pointer(_cret)))
	}

	return _viewStack
}

// SetPolicy sets the policy of self.
//
// The function takes the following parameters:
//
//   - policy: new policy.
func (self *ViewSwitcher) SetPolicy(policy ViewSwitcherPolicy) {
	var _arg0 *C.AdwViewSwitcher      // out
	var _arg1 C.AdwViewSwitcherPolicy // out

	_arg0 = (*C.AdwViewSwitcher)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = C.AdwViewSwitcherPolicy(policy)

	C.adw_view_switcher_set_policy(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(policy)
}

// SetStack sets the stack controlled by self.
//
// The function takes the following parameters:
//
//   - stack (optional): stack.
func (self *ViewSwitcher) SetStack(stack *ViewStack) {
	var _arg0 *C.AdwViewSwitcher // out
	var _arg1 *C.AdwViewStack    // out

	_arg0 = (*C.AdwViewSwitcher)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if stack != nil {
		_arg1 = (*C.AdwViewStack)(unsafe.Pointer(coreglib.InternObject(stack).Native()))
	}

	C.adw_view_switcher_set_stack(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(stack)
}

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

// viewSwitcherClass is the struct that's finalized.
type viewSwitcherClass struct {
	native *C.AdwViewSwitcherClass
}

func (v *ViewSwitcherClass) ParentClass() *gtk.WidgetClass {
	valptr := &v.native.parent_class
	var _v *gtk.WidgetClass // out
	_v = (*gtk.WidgetClass)(gextras.NewStructNative(unsafe.Pointer(valptr)))
	return _v
}
