import React__default, { useId, useRef } from 'react';
import { o as omit } from '../omit-es.js';
import { k as FormField, j as useFormFieldWrapperStyles, b as useAtlantisFormFieldName, f as FormFieldWrapper, l as FormFieldPostFix, m as mergeRefs } from '../FormField-es.js';
import classnames from 'classnames';
import '../tslib.es6-es.js';
import 'react-hook-form';
import '@jobber/hooks';
import 'framer-motion';
import '@jobber/design';
import '../Button-es.js';
import { f as filterDataAttributes } from '../filterDataAttributes-es.js';
import '../_commonjsHelpers-es.js';
import '../_getAllKeys-es.js';
import '../isTypedArray-es.js';
import '../isObjectLike-es.js';
import '../isSymbol-es.js';
import '../identity-es.js';
import '../_getTag-es.js';
import '../keysIn-es.js';
import '../_baseAssignValue-es.js';
import '../_baseFlatten-es.js';
import '../_setToString-es.js';
import '../Icon-es.js';
import '../Text-es.js';
import '../Typography-es.js';
import '../useFormFieldFocus-es.js';
import '../InputValidation-es.js';
import '../Spinner-es.js';
import 'react-router-dom';

function Select$1(props) {
    const formFieldProps = omit(Object.assign({}, props), ["version"]);
    return React__default.createElement(FormField, Object.assign({ type: "select" }, formFieldProps));
}

/**
 * Hook with actions on the Select component.
 */
function useSelectActions({ onChange, onBlur, onFocus, }) {
    function handleChange(event) {
        const newValue = event.currentTarget.value;
        onChange === null || onChange === void 0 ? void 0 : onChange(newValue, event);
    }
    function handleBlur(event) {
        onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
    }
    function handleFocus(event) {
        onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
    }
    return {
        handleChange,
        handleBlur,
        handleFocus,
    };
}

var styles = {"select":"-hmXAsAfH9U-","selectPostfix":"_5ST4c1fXDYU-","spinning":"oOACJmrVDf0-"};

function SelectRebuilt(props) {
    var _a;
    const { mergedRef, wrapperRef } = useSelectRefs(props.inputRef);
    const { inputStyle } = useFormFieldWrapperStyles(Object.assign({}, omit(props, ["version"])));
    const dataAttrs = filterDataAttributes(props);
    const generatedId = useId();
    const id = props.id || generatedId;
    const descriptionIdentifier = `descriptionUUID--${id}`;
    const { name } = useAtlantisFormFieldName({
        nameProp: props.name,
        id: id,
    });
    const { handleChange, handleBlur, handleFocus } = useSelectActions({
        onChange: props.onChange,
        onBlur: props.onBlur,
        onFocus: props.onFocus,
    });
    const descriptionVisible = props.description && !props.inline;
    const isInvalid = Boolean(props.error || props.invalid);
    return (React__default.createElement(FormFieldWrapper, { disabled: props.disabled, size: props.size, align: props.align, inline: props.inline, name: name, wrapperRef: wrapperRef, error: (_a = props.error) !== null && _a !== void 0 ? _a : "", invalid: props.invalid, identifier: id, descriptionIdentifier: descriptionIdentifier, description: props.description, type: "select", placeholder: props.placeholder, value: props.value, prefix: props.prefix, suffix: props.suffix, clearable: "never" },
        React__default.createElement(React__default.Fragment, null,
            React__default.createElement("select", Object.assign({ id: id, name: name, disabled: props.disabled, autoFocus: props.autoFocus, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, value: props.value, "aria-label": props["aria-label"], "aria-describedby": descriptionVisible
                    ? descriptionIdentifier
                    : props["aria-describedby"], "aria-invalid": isInvalid ? true : undefined, "aria-required": props["aria-required"], ref: mergedRef, className: classnames(inputStyle, props.UNSAFE_experimentalStyles && styles.select) }, dataAttrs), props.children),
            React__default.createElement(FormFieldPostFix, { variation: "select", className: styles.selectPostfix }))));
}
function useSelectRefs(inputRef) {
    const internalRef = useRef(null);
    const mergedRef = mergeRefs([
        internalRef,
        inputRef,
    ]);
    const wrapperRef = useRef(null);
    return { mergedRef, wrapperRef };
}

function SelectOption({ children, disabled, value }) {
    return (React__default.createElement("option", { disabled: disabled, value: value }, children));
}

function OptionGroup({ children, label, disabled, UNSAFE_className, UNSAFE_style, }) {
    return (React__default.createElement("optgroup", { label: label, disabled: disabled, className: UNSAFE_className, style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.container }, children));
}

function isNewSelectProps(props) {
    return props.version === 2;
}
function Select(props) {
    if (isNewSelectProps(props)) {
        return React__default.createElement(SelectRebuilt, Object.assign({}, props));
    }
    else {
        return React__default.createElement(Select$1, Object.assign({}, props));
    }
}
Select.Option = SelectOption;
Select.OptionGroup = OptionGroup;

export { SelectOption as Option, Select };
