"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StyledOption = exports.Picker = exports.OptionMetadataComponent = exports.OptionLabelOnlyComponent = exports.OptionLabelContainer = exports.OptionDetails = exports.OptionDetail = exports.OptionDescriptionComponent = exports.OptionDescription = exports.Option = void 0;
var _styled = _interopRequireDefault(require("@emotion/styled"));
var _react = require("react");
var _OdysseyDesignTokensContext = require("../../OdysseyDesignTokensContext.cjs");
var _Typography = require("../../Typography.cjs");
var _ComposablePicker = require("./ComposablePicker.cjs");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/*!
 * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */

const StyledOption = exports.StyledOption = _styled.default.li(({
  hasAdornment
}) => ({
  ...(!hasAdornment && {
    display: "block !important"
  })
}));
const OptionLabelContainer = exports.OptionLabelContainer = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(() => ({
  p: {
    margin: 0
  }
}));
const OptionDescription = exports.OptionDescription = (0, _styled.default)("p", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  margin: `${odysseyDesignTokens.Spacing1} 0 0 !important`,
  color: odysseyDesignTokens.TypographyColorSubordinate
}));
const OptionDetails = exports.OptionDetails = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  display: "flex",
  gap: odysseyDesignTokens.Spacing3,
  marginBlockStart: odysseyDesignTokens.Spacing2
}));
const OptionDetail = exports.OptionDetail = (0, _styled.default)("div", {
  shouldForwardProp: prop => prop !== "odysseyDesignTokens"
})(({
  odysseyDesignTokens
}) => ({
  display: "flex",
  alignItems: "center",
  gap: odysseyDesignTokens.Spacing1,
  svg: {
    width: odysseyDesignTokens.Spacing4,
    color: odysseyDesignTokens.HueNeutral400
  }
}));
const Option = ({
  children,
  hasAdornment = false,
  muiProps
}) => {
  const {
    key,
    ...props
  } = muiProps;
  return (0, _react.createElement)(StyledOption, {
    ...props,
    hasAdornment: hasAdornment,
    key: key
  }, children);
};
exports.Option = Option;
const OptionMetadataComponent = ({
  metaData,
  odysseyDesignTokens
}) => {
  return (0, _jsxRuntime.jsx)(OptionDetails, {
    odysseyDesignTokens: odysseyDesignTokens,
    children: metaData.map((meta, index) => {
      const {
        detailText,
        icon
      } = meta;
      return (0, _jsxRuntime.jsxs)(OptionDetail, {
        odysseyDesignTokens: odysseyDesignTokens,
        children: [icon, detailText]
      }, `${detailText}-${index}`);
    })
  });
};
exports.OptionMetadataComponent = OptionMetadataComponent;
const OptionDescriptionComponent = ({
  description,
  odysseyDesignTokens
}) => {
  return description && (0, _jsxRuntime.jsx)(OptionDescription, {
    odysseyDesignTokens: odysseyDesignTokens,
    children: description
  });
};
exports.OptionDescriptionComponent = OptionDescriptionComponent;
const OptionLabelOnlyComponent = ({
  muiProps,
  odysseyDesignTokens,
  option
}) => {
  const {
    label
  } = option;
  return (0, _jsxRuntime.jsx)(Option, {
    muiProps: muiProps,
    children: (0, _jsxRuntime.jsx)(OptionLabelContainer, {
      odysseyDesignTokens: odysseyDesignTokens,
      children: (0, _jsxRuntime.jsx)(_Typography.Paragraph, {
        children: label
      })
    })
  });
};
exports.OptionLabelOnlyComponent = OptionLabelOnlyComponent;
const OptionLabelDescription = ({
  muiProps,
  odysseyDesignTokens,
  option
}) => {
  const {
    description,
    label
  } = option;
  return (0, _jsxRuntime.jsx)(Option, {
    muiProps: muiProps,
    children: (0, _jsxRuntime.jsxs)(OptionLabelContainer, {
      odysseyDesignTokens: odysseyDesignTokens,
      children: [(0, _jsxRuntime.jsx)(_Typography.Heading6, {
        component: "p",
        children: label
      }), (0, _jsxRuntime.jsx)(OptionDescriptionComponent, {
        description: description,
        odysseyDesignTokens: odysseyDesignTokens
      })]
    })
  });
};
const OptionLabelDescriptionMetadata = ({
  muiProps,
  odysseyDesignTokens,
  option
}) => {
  const {
    description,
    label,
    metaData
  } = option;
  return (0, _jsxRuntime.jsxs)(Option, {
    muiProps: muiProps,
    children: [(0, _jsxRuntime.jsxs)(OptionLabelContainer, {
      odysseyDesignTokens: odysseyDesignTokens,
      children: [(0, _jsxRuntime.jsx)(_Typography.Heading6, {
        component: "p",
        children: label
      }), (0, _jsxRuntime.jsx)(OptionDescriptionComponent, {
        description: description,
        odysseyDesignTokens: odysseyDesignTokens
      })]
    }), (0, _jsxRuntime.jsx)(OptionMetadataComponent, {
      metaData: metaData,
      odysseyDesignTokens: odysseyDesignTokens
    })]
  });
};
const Picker = ({
  ariaDescribedBy,
  defaultValue,
  emptyOptionsText,
  errorMessage,
  errorMessageList,
  getIsOptionEqualToValue,
  hasMultipleChoices,
  id: idOverride,
  inputValue,
  isCustomValueAllowed,
  isDisabled,
  isFullWidth = false,
  isLoading,
  isOptional = false,
  isReadOnly,
  isVirtualized: isVirtualizedProp = false,
  hint,
  HintLinkComponent,
  label,
  name: nameOverride,
  onBlur,
  onChange: onChangeProp,
  onInputChange: onInputChangeProp,
  onFocus,
  options,
  value,
  testId,
  translate
}) => {
  const odysseyDesignTokens = (0, _OdysseyDesignTokensContext.useOdysseyDesignTokens)();
  const customOptionRender = (0, _react.useCallback)((muiProps, option) => {
    const hasDescription = "description" in option && option.description;
    const hasMetadata = "metaData" in option && option.metaData;
    const isLabelOnly = !hasMetadata && !hasDescription;
    return (0, _jsxRuntime.jsx)(_react.Fragment, {
      children: isLabelOnly ? (0, _jsxRuntime.jsx)(OptionLabelOnlyComponent, {
        muiProps: muiProps,
        odysseyDesignTokens: odysseyDesignTokens,
        option: option
      }) : hasMetadata ? (0, _jsxRuntime.jsx)(OptionLabelDescriptionMetadata, {
        muiProps: muiProps,
        odysseyDesignTokens: odysseyDesignTokens,
        option: option
      }) : (0, _jsxRuntime.jsx)(OptionLabelDescription, {
        muiProps: muiProps,
        odysseyDesignTokens: odysseyDesignTokens,
        option: option
      })
    }, option.value);
  }, [odysseyDesignTokens]);
  return (0, _jsxRuntime.jsx)(_ComposablePicker.ComposablePicker, {
    ariaDescribedBy: ariaDescribedBy,
    defaultValue: defaultValue,
    emptyOptionsText: emptyOptionsText,
    errorMessage: errorMessage,
    errorMessageList: errorMessageList,
    getIsOptionEqualToValue: getIsOptionEqualToValue,
    hasMultipleChoices: hasMultipleChoices,
    hint: hint,
    HintLinkComponent: HintLinkComponent,
    id: idOverride,
    inputValue: inputValue,
    isCustomValueAllowed: isCustomValueAllowed,
    isDisabled: isDisabled,
    isFullWidth: isFullWidth,
    isLoading: isLoading,
    isOptional: isOptional,
    isReadOnly: isReadOnly,
    isVirtualized: isVirtualizedProp,
    label: label,
    name: nameOverride,
    onBlur: onBlur,
    onChange: onChangeProp,
    onFocus: onFocus,
    onInputChange: onInputChangeProp,
    options: options,
    renderOption: customOptionRender,
    testId: testId,
    translate: translate,
    value: value
  });
};
const MemoizedPicker = exports.Picker = (0, _react.memo)(Picker);
MemoizedPicker.displayName = "Picker";
//# sourceMappingURL=Picker.cjs.map