"use strict";
// The require scope
var __webpack_require__ = {};
/************************************************************************/ // webpack/runtime/compat_get_default_export
(()=>{
    // getDefaultExport function for compatibility with non-ESM modules
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
// webpack/runtime/define_property_getters
(()=>{
    __webpack_require__.d = function(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/runtime/has_own_property
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
// webpack/runtime/make_namespace_object
(()=>{
    // define __esModule on exports
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
/************************************************************************/ var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
    default: ()=>/* binding */ SearchField_rslib_entry_
});
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const useKey_js_namespaceObject = require("../../hooks/useKey.js");
var useKey_js_default = /*#__PURE__*/ __webpack_require__.n(useKey_js_namespaceObject);
const md_namespaceObject = require("react-icons/md");
const react_namespaceObject = require("@chakra-ui/react");
const SearchField = ({ setSearchText, searchText, placeholderText = 'Search...', icon = 'search', isDisabled = false, ...chakraProps })=>{
    // State
    const isEmpty = !searchText || '' === searchText;
    const inputRef = (0, external_react_namespaceObject.useRef)(null);
    // Actions
    const isAlreadyFocused = ()=>document.activeElement && inputRef?.current && document.activeElement !== inputRef?.current && 'INPUT' === document.activeElement.tagName;
    const reset = ()=>setSearchText('');
    const focus = ()=>!isDisabled && !isAlreadyFocused() && inputRef?.current && inputRef.current.focus();
    const blur = ()=>inputRef?.current && inputRef.current.blur();
    // Keyboard shortcuts
    useKey_js_default()('Escape', isEmpty ? blur : reset);
    useKey_js_default()('/', focus);
    const tagColorScheme = (0, react_namespaceObject.useColorModeValue)('gray', 'light');
    return /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.InputGroup, chakraProps, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.InputLeftElement, {
        width: "2rem"
    }), /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Tooltip, {
        isDisabled: isDisabled,
        placement: "bottom",
        hasArrow: true,
        py: 1,
        label: isEmpty ? /*#__PURE__*/ external_react_default().createElement("span", null, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Tag, {
            colorScheme: tagColorScheme,
            size: "sm"
        }, "/"), ' ', "to focus") : /*#__PURE__*/ external_react_default().createElement("span", null, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Tag, {
            colorScheme: tagColorScheme,
            size: "sm"
        }, "Esc"), ' ', "to clear")
    }, isEmpty ? /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.InputLeftElement, {
        onClick: focus
    }, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Icon, {
        "data-testid": "search-field-search-icon",
        as: 'filter' === icon ? md_namespaceObject.MdOutlineFilterList : md_namespaceObject.MdSearch,
        color: "gray.300",
        "aria-label": "search-icon-focus"
    })) : /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.InputLeftElement, {
        onClick: reset
    }, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Icon, {
        "data-testid": "search-field-reset-icon",
        as: md_namespaceObject.MdClose,
        color: "gray.300",
        "aria-label": "search-icon-reset"
    }))), /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Input, {
        "data-testid": "search-field-input",
        ref: inputRef,
        type: "text",
        className: "search-control",
        placeholder: placeholderText,
        onChange: (event)=>setSearchText(event.target.value),
        value: searchText,
        isDisabled: isDisabled
    }));
};
/* ESM default export */ const SearchField_rslib_entry_ = SearchField;
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
