'use client';
import * as React from 'react';
import { clsx } from '../../../clsx/dist/clsx.mjs';
import nativeSelectClasses, { getNativeSelectUtilityClasses } from './nativeSelectClasses.mjs';
import rootShouldForwardProp from '../styles/rootShouldForwardProp.mjs';
import { jsxs, jsx } from 'react/jsx-runtime';
import capitalize from '../../utils/esm/capitalize/capitalize.mjs';
import composeClasses from '../../utils/esm/composeClasses/composeClasses.mjs';
import styled from '../styles/styled.mjs';

const useUtilityClasses$h = ownerState => {
  const {
    classes,
    variant,
    disabled,
    multiple,
    open,
    error
  } = ownerState;
  const slots = {
    select: ['select', variant, disabled && 'disabled', multiple && 'multiple', error && 'error'],
    icon: ['icon', `icon${capitalize(variant)}`, open && 'iconOpen', disabled && 'disabled']
  };
  return composeClasses(slots, getNativeSelectUtilityClasses, classes);
};
const StyledSelectSelect = styled('select')(({
  theme
}) => ({
  // Reset
  MozAppearance: 'none',
  // Reset
  WebkitAppearance: 'none',
  // When interacting quickly, the text can end up selected.
  // Native select can't be selected either.
  userSelect: 'none',
  // Reset
  borderRadius: 0,
  cursor: 'pointer',
  '&:focus': {
    // Reset Chrome style
    borderRadius: 0
  },
  [`&.${nativeSelectClasses.disabled}`]: {
    cursor: 'default'
  },
  '&[multiple]': {
    height: 'auto'
  },
  '&:not([multiple]) option, &:not([multiple]) optgroup': {
    backgroundColor: (theme.vars || theme).palette.background.paper
  },
  variants: [{
    props: ({
      ownerState
    }) => ownerState.variant !== 'filled' && ownerState.variant !== 'outlined',
    style: {
      // Bump specificity to allow extending custom inputs
      '&&&': {
        paddingRight: 24,
        minWidth: 16 // So it doesn't collapse.
      }
    }
  }, {
    props: {
      variant: 'filled'
    },
    style: {
      '&&&': {
        paddingRight: 32
      }
    }
  }, {
    props: {
      variant: 'outlined'
    },
    style: {
      borderRadius: (theme.vars || theme).shape.borderRadius,
      '&:focus': {
        borderRadius: (theme.vars || theme).shape.borderRadius // Reset the reset for Chrome style
      },
      '&&&': {
        paddingRight: 32
      }
    }
  }]
}));
const NativeSelectSelect = styled(StyledSelectSelect, {
  name: 'MuiNativeSelect',
  slot: 'Select',
  shouldForwardProp: rootShouldForwardProp,
  overridesResolver: (props, styles) => {
    const {
      ownerState
    } = props;
    return [styles.select, styles[ownerState.variant], ownerState.error && styles.error, {
      [`&.${nativeSelectClasses.multiple}`]: styles.multiple
    }];
  }
})({});
const StyledSelectIcon = styled('svg')(({
  theme
}) => ({
  // We use a position absolute over a flexbox in order to forward the pointer events
  // to the input and to support wrapping tags..
  position: 'absolute',
  right: 0,
  // Center vertically, height is 1em
  top: 'calc(50% - .5em)',
  // Don't block pointer events on the select under the icon.
  pointerEvents: 'none',
  color: (theme.vars || theme).palette.action.active,
  [`&.${nativeSelectClasses.disabled}`]: {
    color: (theme.vars || theme).palette.action.disabled
  },
  variants: [{
    props: ({
      ownerState
    }) => ownerState.open,
    style: {
      transform: 'rotate(180deg)'
    }
  }, {
    props: {
      variant: 'filled'
    },
    style: {
      right: 7
    }
  }, {
    props: {
      variant: 'outlined'
    },
    style: {
      right: 7
    }
  }]
}));
const NativeSelectIcon = styled(StyledSelectIcon, {
  name: 'MuiNativeSelect',
  slot: 'Icon',
  overridesResolver: (props, styles) => {
    const {
      ownerState
    } = props;
    return [styles.icon, ownerState.variant && styles[`icon${capitalize(ownerState.variant)}`], ownerState.open && styles.iconOpen];
  }
})({});

/**
 * @ignore - internal component.
 */
const NativeSelectInput = /*#__PURE__*/React.forwardRef(function NativeSelectInput(props, ref) {
  const {
    className,
    disabled,
    error,
    IconComponent,
    inputRef,
    variant = 'standard',
    ...other
  } = props;
  const ownerState = {
    ...props,
    disabled,
    variant,
    error
  };
  const classes = useUtilityClasses$h(ownerState);
  return /*#__PURE__*/jsxs(React.Fragment, {
    children: [/*#__PURE__*/jsx(NativeSelectSelect, {
      ownerState: ownerState,
      className: clsx(classes.select, className),
      disabled: disabled,
      ref: inputRef || ref,
      ...other
    }), props.multiple ? null : /*#__PURE__*/jsx(NativeSelectIcon, {
      as: IconComponent,
      ownerState: ownerState,
      className: classes.icon
    })]
  });
});

export { StyledSelectIcon, StyledSelectSelect, NativeSelectInput as default };
//# sourceMappingURL=NativeSelectInput.mjs.map
