import{jsx as r,jsxs as s,Fragment as f}from"react/jsx-runtime";import g,{useMemo as k,useState as C}from"react";import{Dropdown as D}from"@redocly/theme/components/Dropdown/Dropdown";import{CheckmarkIcon as I}from"@redocly/theme/icons/CheckmarkIcon/CheckmarkIcon";import{DropdownMenu as j}from"@redocly/theme/components/Dropdown/DropdownMenu";import{DropdownMenuItem as z}from"@redocly/theme/components/Dropdown/DropdownMenuItem";import{Button as M}from"@redocly/theme/components/Button/Button";import{SearchIcon as F}from"@redocly/theme/icons/SearchIcon/SearchIcon";import{typedMemo as N}from"@redocly/theme/core/openapi";import{styled as n}from"../../../styled-components.js";import{useTranslate as A}from"../../../hooks/index.js";function P({options:t,value:o,onChange:d,className:v,triggerVariant:x="outlined",triggerSize:b="small",withSearch:w=!1}){const[l,h]=C(""),m=A(),a=t.find(e=>e.value===o),p=k(()=>t.filter(e=>e.label?.toLowerCase().includes(l.toLowerCase())??!1),[t,l]);if(t.length===1)return r(V,{children:a?.element||a?.label});const y=e=>{h(e.target.value)},S=()=>w?s(f,{children:[r(R,{prefix:r(L,{children:r(F,{color:"var(--icon-color-additional)",onClick:e=>e.stopPropagation()})}),content:r(O,{placeholder:m("openapi.discriminator.searchPlaceholder","Search items"),onClick:e=>e.stopPropagation(),onChange:y,value:l})}),r(_,{children:p.length?p.map((e,c)=>s(g.Fragment,{children:[e.divider,r(i,{active:e.value===o,onAction:()=>d(e),suffix:e.value===o&&r(u,{}),children:e.element||e.label},e.label)]},c)):r(T,{content:m("openapi.discriminator.searchNoResults","No items found")})})]}):r(f,{children:t.map((e,c)=>s(g.Fragment,{children:[e.divider,r(i,{active:e.value===o,onAction:()=>d(e),suffix:e.value===o&&r(u,{}),children:e.element||e.label},e.label)]},c))});return r(D,{className:v,trigger:r(M,{variant:x,size:b,type:"button",children:a?.element||a?.label}),withArrow:!0,onClose:()=>h(""),children:r(j,{children:S()})})}const Y=N(P),u=n(I)`
  width: 16px;
  height: 16px;
  margin-left: auto;
`,i=n(z)`
  --dropdown-menu-item-justify-content: space-between;

  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-xxs) var(--spacing-sm);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
`,R=n(i)`
  gap: 0;
  padding: var(--spacing-xxs) var(--spacing-xs);
  &:hover {
    background-color: transparent;
  }
`,T=n(i)`
  height: 66px;
  justify-content: center;
  &:hover,
  &:focus-visible {
    background-color: transparent;
  }
`,_=n.div`
  overflow-y: auto;
  max-height: 300px;
`,L=n.div`
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  cursor: pointer;
  flex-shrink: 0;
`,O=n.input`
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-color-primary);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  font-family: var(--font-family-base);
  padding: 0;
  margin-left: var(--spacing-xxs);

  &::placeholder {
    color: var(--search-trigger-color);
  }
`,V=n.span`
  margin-right: var(--spacing-unit);
  cursor: default;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-color-primary);
  font-size: var(--font-size-lg);
  line-height: var(--line-height-lg);
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-regular);
`;export{Y as Dropdown};
