import { _ as __assign } from '../tslib.es6-faad35dc.js';
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { styled } from '@mui/material/styles';
import MuiBox from '@mui/material/Box';
import MuiFade from '@mui/material/Fade';
import MuiPopper from '@mui/material/Popper';
import MuiClickAwayListener from '@mui/material/ClickAwayListener';
import MuiFormControl from '@mui/material/FormControl';
import Icon from './Icon.js';
import Button from './Button.js';
import AutocompleteDropdown from './AutocompleteDropdown.js';
import boxShadow from '../theme/boxShadow.js';
import '../icons/ArrowLeft.js';
import '../icons/ArrowRight.js';
import '../icons/CloseCircle.js';
import '../icons/InfoCircle.js';
import '../icons/ErrorCircle.js';
import '../icons/Attention.js';
import '../icons/HelpCircle.js';
import '../icons/Document.js';
import '../icons/DocumentText.js';
import '../icons/Lock.js';
import '../icons/Delete.js';
import '../icons/Users.js';
import '../icons/Stakefish.js';
import '../icons/Sound.js';
import '../icons/Beacon.js';
import '../icons/TriangleRight.js';
import '../icons/TriangleLeft.js';
import '../icons/TriangleUp.js';
import '../icons/TriangleDown.js';
import '../icons/Sent.js';
import '../icons/Download.js';
import '../icons/Faster.js';
import '../icons/Slower.js';
import '../icons/Usb.js';
import '../icons/Key.js';
import '../icons/Edit.js';
import '../icons/Expand.js';
import '../icons/Collapse.js';
import '../icons/Success.js';
import '../icons/SuccessCircle.js';
import '../icons/Fail.js';
import '../icons/Desktop.js';
import '../icons/Mobile.js';
import '../icons/Loading.js';
import '../icons/Upload.js';
import '../icons/Check.js';
import '../icons/ChevronLeft.js';
import '../icons/ChevronRight.js';
import '../icons/Plus.js';
import '../icons/Minus.js';
import '../icons/Globe.js';
import '../icons/Link.js';
import '../icons/Copy.js';
import '../icons/Medium.js';
import '../icons/Twitter.js';
import '../icons/Telegram.js';
import '../icons/Eth.js';
import '../icons/Sort.js';
import '../icons/Close.js';
import '../icons/DollarSign.js';
import '../icons/Search.js';
import '../icons/Range.js';
import '../icons/Instagram.js';
import '../icons/LinkedIn.js';
import '../icons/Reddit.js';
import '../icons/YouTube.js';
import '../icons/Chrome.js';
import '../icons/CloudConnect.js';
import '../icons/Update.js';
import '../icons/Menu.js';
import '../icons/Settings.js';
import '../clsx.m-6243b874.js';
import '@mui/material/Button';
import '../theme/colors.js';
import '@mui/material/Autocomplete';
import './TextField.js';
import '@mui/material/TextField';
import './EndAdornment.js';
import '@mui/material/InputAdornment';
import './Input.js';
import '@mui/material/Input';

var StyledFormControl = styled(MuiFormControl)(function () { return ({
    position: "relative"
}); });
var StyledButton = styled(Button)(function (_a) {
    var theme = _a.theme;
    return ({
        color: theme.palette.icon.secondary,
        backgroundColor: "".concat(theme.palette.gray[100], " !important"),
        ".MuiButton-endIcon": {
            marginLeft: theme.spacing(3)
        }
    });
});
var StyledMenu = styled(MuiBox)(function (_a) {
    var theme = _a.theme;
    return ({
        backgroundColor: theme.palette.gray.white,
        borderRadius: "".concat(theme.borders.radius.md, "px ").concat(theme.borders.radius.md, "px 0 0"),
        boxShadow: boxShadow.lg,
        ".MuiFormControl-root": {
            padding: theme.spacing(2, 2, 0, 2)
        },
        ".MuiInputBase-adornedEnd .icon": {
            display: "none"
        }
    });
});
var SelectAutocompleteDropdown = function (_a) {
    var id = _a.id, fullWidth = _a.fullWidth; _a.label; var buttonProps = _a.buttonProps, formControlProps = _a.formControlProps, autocompleteDropdownProps = _a.autocompleteDropdownProps;
    var getPlaceholderEl = buttonProps.getPlaceholderEl, getOptionLabelEl = buttonProps.getOptionLabelEl;
    var _b = useState(null), anchorEl = _b[0], setAnchorEl = _b[1];
    var _c = useState(null), value = _c[0], setValue = _c[1];
    var _d = useState(Boolean(anchorEl)), isOpen = _d[0], setIsOpen = _d[1];
    var formId = isOpen ? id : undefined;
    var handleButtonClick = function (event) {
        setAnchorEl(!isOpen ? event.currentTarget : null);
        setIsOpen(!isOpen);
    };
    var handleMenuClose = function (event, reason) {
        if (reason === "toggleInput")
            return;
        if (anchorEl)
            anchorEl.focus();
        setIsOpen(false);
        setAnchorEl(null);
    };
    var handleOptionChange = function (event, newValue) {
        setValue(newValue);
    };
    return (jsxs(StyledFormControl, __assign({ fullWidth: fullWidth }, formControlProps, { children: [jsxs(StyledButton, __assign({ size: "sm", variant: "contained", onClick: handleButtonClick, fullWidth: fullWidth, align: "left", endIcon: jsx(Icon, { iconKey: "triangleUp", size: "xs1", rotate: isOpen ? 0 : 180 }, void 0) }, { children: [value && getOptionLabelEl(value), !value && getPlaceholderEl()] }), void 0), jsx(MuiClickAwayListener, __assign({ onClickAway: function (event) {
                    setIsOpen(!!(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.contains(event.target)));
                } }, { children: jsx(MuiPopper, { id: formId, open: isOpen, anchorEl: anchorEl, style: { width: "100%", maxWidth: fullWidth ? "auto" : "590px" }, popperOptions: {
                        modifiers: [
                            {
                                name: "offset",
                                options: {
                                    offset: [0, 12]
                                }
                            }
                        ]
                    }, children: function () { return (jsx(MuiFade, __assign({ in: true }, { children: jsx("div", { children: jsx(StyledMenu, { children: jsx(AutocompleteDropdown, __assign({}, autocompleteDropdownProps, { open: true, sx: { marginTop: "12px" }, fullWidth: fullWidth, id: formId, value: value, onChange: handleOptionChange, onClose: handleMenuClose, textFieldProps: {
                                        color: "secondary"
                                    }, popperProps: {
                                        className: "select-autocomplete-popper"
                                    } }), void 0) }, void 0) }, void 0) }), void 0)); } }, void 0) }), void 0)] }), void 0));
};

export { SelectAutocompleteDropdown as default };
