"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    SearchBox: ()=>SearchBox_SearchBox
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const index_cjs_namespaceObject = require("../../utils/index.cjs");
const external_react_namespaceObject = require("react");
const icon_registry_cjs_namespaceObject = require("../../utils/icon-registry.cjs");
const external_SearchBox_styles_cjs_namespaceObject = require("./SearchBox.styles.cjs");
const SearchBox_SearchBox = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(function({ value, onChange, clear, placeholder = 'Search...', inputRef: externalInputRef, clearButtonRef, onNavigationKeyDown, navigateToFirstItem, activeDescendantId }) {
    const internalRef = (0, external_react_namespaceObject.useRef)(null);
    const inputRef = externalInputRef ?? internalRef;
    (0, external_react_namespaceObject.useEffect)(()=>{
        inputRef.current?.focus();
    }, [
        inputRef
    ]);
    const handleClearButtonKeyDown = (e)=>{
        if ('Tab' === e.key) {
            e.preventDefault();
            inputRef.current?.focus();
            if (!e.shiftKey) navigateToFirstItem?.();
        }
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_SearchBox_styles_cjs_namespaceObject.StyledSearchForm, {
        autoComplete: "off",
        className: "searchbox-form",
        onSubmit: (e)=>e.preventDefault(),
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
            className: (0, index_cjs_namespaceObject.cx)("searchbox-container", {
                'has-value': !!value
            }),
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                    className: "searchbox-icon",
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                        icon: "search",
                        size: 16
                    })
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
                    ref: inputRef,
                    autoComplete: "off",
                    type: "text",
                    role: "combobox",
                    "aria-controls": "toolbox-listbox",
                    "aria-expanded": true,
                    className: "searchbox-input",
                    placeholder: placeholder,
                    value: value,
                    onChange: (e)=>onChange(e.target.value),
                    onKeyDown: onNavigationKeyDown,
                    "aria-activedescendant": activeDescendantId
                }),
                value && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
                    ref: clearButtonRef,
                    type: "button",
                    className: "searchbox-clear",
                    onClick: clear,
                    onKeyDown: handleClearButtonKeyDown,
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                        icon: "x",
                        size: 16
                    })
                })
            ]
        })
    });
});
exports.SearchBox = __webpack_exports__.SearchBox;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "SearchBox"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
