//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// `NSSearchToolbarItem` provides the standard UI behavior for integrating a search field into the toolbar.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nssearchtoolbaritem?language=objc)
    #[unsafe(super(NSToolbarItem, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "NSToolbarItem")]
    pub struct NSSearchToolbarItem;
);

#[cfg(feature = "NSToolbarItem")]
extern_conformance!(
    unsafe impl NSCopying for NSSearchToolbarItem {}
);

#[cfg(feature = "NSToolbarItem")]
unsafe impl CopyingHelper for NSSearchToolbarItem {
    type Result = Self;
}

#[cfg(feature = "NSToolbarItem")]
extern_conformance!(
    unsafe impl NSObjectProtocol for NSSearchToolbarItem {}
);

#[cfg(feature = "NSToolbarItem")]
impl NSSearchToolbarItem {
    extern_methods!(
        #[cfg(all(
            feature = "NSControl",
            feature = "NSResponder",
            feature = "NSSearchField",
            feature = "NSTextField",
            feature = "NSView"
        ))]
        /// An `NSSearchField` displayed in the toolbar item.
        /// While inside the toolbar item, the field properties and layout constraints are managed by the item.
        /// The field should be configured before assigned.
        /// The width constraint for the field could be updated after assigned.
        /// When set to nil, will reset to a search field with the default configuration.
        #[unsafe(method(searchField))]
        #[unsafe(method_family = none)]
        pub fn searchField(&self) -> Retained<NSSearchField>;

        #[cfg(all(
            feature = "NSControl",
            feature = "NSResponder",
            feature = "NSSearchField",
            feature = "NSTextField",
            feature = "NSView"
        ))]
        /// Setter for [`searchField`][Self::searchField].
        #[unsafe(method(setSearchField:))]
        #[unsafe(method_family = none)]
        pub fn setSearchField(&self, search_field: &NSSearchField);

        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
        /// The base view property is owned by the toolbar item and not available for customization.
        #[unsafe(method(view))]
        #[unsafe(method_family = none)]
        pub unsafe fn view(&self) -> Option<Retained<NSView>>;

        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
        /// Setter for [`view`][Self::view].
        #[unsafe(method(setView:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setView(&self, view: Option<&NSView>);

        /// When YES, the cancel button in the field resigns the first responder status of the search field as clearing the contents.
        /// The default is YES.
        #[unsafe(method(resignsFirstResponderWithCancel))]
        #[unsafe(method_family = none)]
        pub fn resignsFirstResponderWithCancel(&self) -> bool;

        /// Setter for [`resignsFirstResponderWithCancel`][Self::resignsFirstResponderWithCancel].
        #[unsafe(method(setResignsFirstResponderWithCancel:))]
        #[unsafe(method_family = none)]
        pub fn setResignsFirstResponderWithCancel(&self, resigns_first_responder_with_cancel: bool);

        #[cfg(feature = "objc2-core-foundation")]
        /// The preferred width for the search field.
        /// This value is used to configure the search field width whenever it gets the keyboard focus.
        /// If specifying custom width constraints to the search field, they should not conflict with this value.
        #[unsafe(method(preferredWidthForSearchField))]
        #[unsafe(method_family = none)]
        pub fn preferredWidthForSearchField(&self) -> CGFloat;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`preferredWidthForSearchField`][Self::preferredWidthForSearchField].
        #[unsafe(method(setPreferredWidthForSearchField:))]
        #[unsafe(method_family = none)]
        pub fn setPreferredWidthForSearchField(&self, preferred_width_for_search_field: CGFloat);

        /// Starts a search interaction.
        /// If necessary, expands to the preferred width and moves the keyboard focus to the search field.
        #[unsafe(method(beginSearchInteraction))]
        #[unsafe(method_family = none)]
        pub fn beginSearchInteraction(&self);

        /// Ends a search interaction.
        /// Gives up the first responder by calling `-endEditing:` to the search field.
        /// Adjusts to the natural available width for the toolbar item if necessary.
        #[unsafe(method(endSearchInteraction))]
        #[unsafe(method_family = none)]
        pub fn endSearchInteraction(&self);
    );
}

/// Methods declared on superclass `NSToolbarItem`.
#[cfg(feature = "NSToolbarItem")]
impl NSSearchToolbarItem {
    extern_methods!(
        #[cfg(feature = "NSToolbar")]
        /// Initialize the toolbar item with an identifier which is a development language string used by the toolbar and its delegate for identification purposes.
        #[unsafe(method(initWithItemIdentifier:))]
        #[unsafe(method_family = init)]
        pub fn initWithItemIdentifier(
            this: Allocated<Self>,
            item_identifier: &NSToolbarItemIdentifier,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "NSToolbarItem")]
impl NSSearchToolbarItem {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
    );
}
