/* @oracle/oraclejet-preact: undefined */
'use strict';

var jsxRuntime = require('preact/jsx-runtime');
var IconButton = require('./IconButton-7503293b.js');
var NavLeft = require('./NavLeft-a33ac5d2.js');
var hooks = require('preact/hooks');
require('./keyboardUtils-b42fe7d5.js');
require('preact/compat');
var StyledTextField = require('./StyledTextField-7839c90d.js');

require('./useAccessibleContext-c49d8d1b.js');
require('./logger-2b636482.js');
require('./FormContext-d1d05967.js');
require('./FormFieldContext-69fe83d2.js');
var useFormFieldContext = require('./useFormFieldContext-4632eb73.js');
require('./TabbableModeContext-e99d527e.js');
var useTranslationBundle = require('./useTranslationBundle-12dd087d.js');
require('./textAlign-f41f49db.js');


require('./UNSAFE_TextField/themes/redwood/ReadonlyTextFieldInputVariants.css.js');
var TextField = require('./TextField-5c164264.js');

require('./LayerHost-3cd73603.js');
require('./UNSAFE_TextField/themes/TextFieldStyles.css.js');




require('./UNSAFE_TextField/themes/redwood/TextFieldVariants.css.js');
var useSelectCommon = require('./useSelectCommon-27afecfa.js');
var LiveRegion = require('./LiveRegion-62ce9ac7.js');



require('./UNSAFE_Label/themes/redwood/LabelVariants.css.js');
require('./UNSAFE_TextField/themes/FormLayoutStyles.css.js');

require('./Flex-3a257bc3.js');

require('./InputGroupContext-05f2a46f.js');


require('./hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentVariants.css.js');
require('./tooltipUtils-2bc15136.js');

function SelectSingleField({ children, hasInsideLabel, isBackButtonShown, isClearButtonShown, isDropdownArrowShown, onBackButtonClick, onClearButtonClick, onDropdownArrowClick, ...passThroughTextFieldProps }) {
    const translations = useTranslationBundle.useTranslationBundle('@oracle/oraclejet-preact');
    const { isDisabled, isLoading } = useFormFieldContext.useFormFieldContext();
    const startContent = isBackButtonShown ? (jsxRuntime.jsx(IconButton.IconButton, { "aria-label": translations.selectMultiple_back(), size: "xs", variant: "ghost", onAction: onBackButtonClick, children: jsxRuntime.jsx(NavLeft.SvgNavLeft, {}) })) : null;
    const endContent = isLoading ? undefined : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isClearButtonShown && (jsxRuntime.jsx(IconButton.IconButton, { "aria-label": translations.formControl_clear(), size: "sm", variant: "ghost", onAction: onClearButtonClick, children: jsxRuntime.jsx(NavLeft.SvgCancelS, {}) })), isDropdownArrowShown && (jsxRuntime.jsx(useSelectCommon.DropdownArrow, { isDisabled: isDisabled, onClick: onDropdownArrowClick, testId: `${passThroughTextFieldProps.testId}_dropdownarrow` }))] }));
    return (jsxRuntime.jsx(TextField.TextField, { startContent: startContent, mainContent: children, endContent: endContent, ...passThroughTextFieldProps }));
}

function SelectSingleFieldInput({ displayValue, isAddToListShown, isAdvancedSearchShown, isUserFiltering, liveRegionText, userInput, virtualKeyboard, ...passThroughTextFieldInputProps }) {
    const translations = useTranslationBundle.useTranslationBundle('@oracle/oraclejet-preact');
    const addToListAccText = translations.select_addToListAvailable();
    const advancedSearchAccText = translations.select_moreSearchOptionsAvailable();
    const combinedLiveRegionText = `${liveRegionText} ${isAddToListShown ? addToListAccText : ''} ${isAdvancedSearchShown ? advancedSearchAccText : ''}`;
    return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(StyledTextField.TextFieldInput, { ...passThroughTextFieldInputProps, hasEndContent: true, "aria-autocomplete": "list", autoComplete: "off", role: "combobox", spellcheck: false, type: virtualKeyboard === 'auto' ? 'search' : virtualKeyboard, value: isUserFiltering ? userInput : displayValue }), jsxRuntime.jsx(LiveRegion.LiveRegion, { children: combinedLiveRegionText })] }));
}

/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
function useDisplayValue(itemText, valueItem, componentName = 'SelectSingle') {
    // create the text displayed in the field from the selected value
    const displayValue = hooks.useMemo(() => {
        return valueItem === undefined ? '' : useSelectCommon.renderItemText(valueItem, itemText, componentName) ?? '';
    }, [valueItem, itemText, componentName]);
    return displayValue;
}

exports.SelectSingleField = SelectSingleField;
exports.SelectSingleFieldInput = SelectSingleFieldInput;
exports.useDisplayValue = useDisplayValue;
//# sourceMappingURL=useDisplayValue-4ace417c.js.map
