'use client';

import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _extends from "@babel/runtime/helpers/esm/extends";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import { styled, createUseThemeProps } from '../zero-styled';
import capitalize from '../utils/capitalize';
import Paper from '../Paper';
import { getAppBarUtilityClass } from './appBarClasses';
import { jsx as _jsx } from "react/jsx-runtime";
var useThemeProps = createUseThemeProps('MuiAppBar');
var useUtilityClasses = function useUtilityClasses(ownerState) {
  var color = ownerState.color,
    position = ownerState.position,
    classes = ownerState.classes;
  var slots = {
    root: ['root', "color".concat(capitalize(color)), "position".concat(capitalize(position))]
  };
  return composeClasses(slots, getAppBarUtilityClass, classes);
};

// var2 is the fallback.
// Ex. var1: 'var(--a)', var2: 'var(--b)'; return: 'var(--a, var(--b))'
var joinVars = function joinVars(var1, var2) {
  return var1 ? "".concat(var1 == null ? void 0 : var1.replace(')', ''), ", ").concat(var2, ")") : var2;
};
var AppBarRoot = styled(Paper, {
  name: 'MuiAppBar',
  slot: 'Root',
  overridesResolver: function overridesResolver(props, styles) {
    var ownerState = props.ownerState;
    return [styles.root, styles["position".concat(capitalize(ownerState.position))], styles["color".concat(capitalize(ownerState.color))]];
  }
})(function (_ref) {
  var _theme$vars;
  var theme = _ref.theme;
  return {
    display: 'flex',
    flexDirection: 'column',
    width: '100%',
    boxSizing: 'border-box',
    // Prevent padding issue with the Modal and fixed positioned AppBar.
    flexShrink: 0,
    variants: [{
      props: {
        position: 'fixed'
      },
      style: {
        position: 'fixed',
        zIndex: (theme.vars || theme).zIndex.appBar,
        top: 0,
        left: 'auto',
        right: 0,
        '@media print': {
          // Prevent the app bar to be visible on each printed page.
          position: 'absolute'
        }
      }
    }, {
      props: {
        position: 'absolute'
      },
      style: {
        position: 'absolute',
        zIndex: (theme.vars || theme).zIndex.appBar,
        top: 0,
        left: 'auto',
        right: 0
      }
    }, {
      props: {
        position: 'sticky'
      },
      style: {
        // ⚠️ sticky is not supported by IE11.
        position: 'sticky',
        zIndex: (theme.vars || theme).zIndex.appBar,
        top: 0,
        left: 'auto',
        right: 0
      }
    }, {
      props: {
        position: 'static'
      },
      style: {
        position: 'static'
      }
    }, {
      props: {
        position: 'relative'
      },
      style: {
        position: 'relative'
      }
    }, {
      props: {
        color: 'inherit'
      },
      style: {
        '--AppBar-color': 'inherit'
      }
    }, {
      props: {
        color: 'default'
      },
      style: _extends({
        '--AppBar-background': theme.vars ? theme.vars.palette.AppBar.defaultBg : theme.palette.grey[100],
        '--AppBar-color': theme.vars ? theme.vars.palette.text.primary : theme.palette.getContrastText(theme.palette.grey[100])
      }, theme.applyStyles('dark', {
        '--AppBar-background': theme.vars ? theme.vars.palette.AppBar.defaultBg : theme.palette.grey[900],
        '--AppBar-color': theme.vars ? theme.vars.palette.text.primary : theme.palette.getContrastText(theme.palette.grey[900])
      }))
    }].concat(_toConsumableArray(Object.keys(((_theme$vars = theme.vars) != null ? _theme$vars : theme).palette).filter(function (key) {
      var _theme$vars2, _theme$vars3;
      return ((_theme$vars2 = theme.vars) != null ? _theme$vars2 : theme).palette[key].main && ((_theme$vars3 = theme.vars) != null ? _theme$vars3 : theme).palette[key].contrastText;
    }).map(function (color) {
      var _theme$vars4, _theme$vars5;
      return {
        props: {
          color: color
        },
        style: {
          '--AppBar-background': ((_theme$vars4 = theme.vars) != null ? _theme$vars4 : theme).palette[color].main,
          '--AppBar-color': ((_theme$vars5 = theme.vars) != null ? _theme$vars5 : theme).palette[color].contrastText
        }
      };
    })), [{
      props: {
        enableColorOnDark: true
      },
      style: {
        backgroundColor: 'var(--AppBar-background)',
        color: 'var(--AppBar-color)'
      }
    }, {
      props: {
        enableColorOnDark: false
      },
      style: _extends({
        backgroundColor: 'var(--AppBar-background)',
        color: 'var(--AppBar-color)'
      }, theme.applyStyles('dark', {
        backgroundColor: theme.vars ? joinVars(theme.vars.palette.AppBar.darkBg, 'var(--AppBar-background)') : null,
        color: theme.vars ? joinVars(theme.vars.palette.AppBar.darkColor, 'var(--AppBar-color)') : null
      }))
    }, {
      props: {
        color: 'transparent'
      },
      style: _extends({
        '--AppBar-background': 'transparent',
        '--AppBar-color': 'inherit',
        backgroundColor: 'var(--AppBar-background)',
        color: 'var(--AppBar-color)'
      }, theme.applyStyles('dark', {
        backgroundImage: 'none'
      }))
    }])
  };
});
var AppBar = /*#__PURE__*/React.forwardRef(function AppBar(inProps, ref) {
  var props = useThemeProps({
    props: inProps,
    name: 'MuiAppBar'
  });
  var className = props.className,
    _props$color = props.color,
    color = _props$color === void 0 ? 'primary' : _props$color,
    _props$enableColorOnD = props.enableColorOnDark,
    enableColorOnDark = _props$enableColorOnD === void 0 ? false : _props$enableColorOnD,
    _props$position = props.position,
    position = _props$position === void 0 ? 'fixed' : _props$position,
    other = _objectWithoutProperties(props, ["className", "color", "enableColorOnDark", "position"]);
  var ownerState = _extends({}, props, {
    color: color,
    position: position,
    enableColorOnDark: enableColorOnDark
  });
  var classes = useUtilityClasses(ownerState);
  return /*#__PURE__*/_jsx(AppBarRoot, _extends({
    square: true,
    component: "header",
    ownerState: ownerState,
    elevation: 4,
    className: clsx(classes.root, className, position === 'fixed' && 'mui-fixed'),
    ref: ref
  }, other));
});
process.env.NODE_ENV !== "production" ? AppBar.propTypes /* remove-proptypes */ = {
  // ┌────────────────────────────── Warning ──────────────────────────────┐
  // │ These PropTypes are generated from the TypeScript type definitions. │
  // │    To update them, edit the d.ts file and run `pnpm proptypes`.     │
  // └─────────────────────────────────────────────────────────────────────┘
  /**
   * The content of the component.
   */
  children: PropTypes.node,
  /**
   * Override or extend the styles applied to the component.
   */
  classes: PropTypes.object,
  /**
   * @ignore
   */
  className: PropTypes.string,
  /**
   * The color of the component.
   * It supports both default and custom theme colors, which can be added as shown in the
   * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
   * @default 'primary'
   */
  color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['default', 'inherit', 'primary', 'secondary', 'transparent', 'error', 'info', 'success', 'warning']), PropTypes.string]),
  /**
   * If true, the `color` prop is applied in dark mode.
   * @default false
   */
  enableColorOnDark: PropTypes.bool,
  /**
   * The positioning type. The behavior of the different options is described
   * [in the MDN web docs](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning).
   * Note: `sticky` is not universally supported and will fall back to `static` when unavailable.
   * @default 'fixed'
   */
  position: PropTypes.oneOf(['absolute', 'fixed', 'relative', 'static', 'sticky']),
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
} : void 0;
export default AppBar;