'use strict';
'use client';
import { jsxs, jsx } from 'react/jsx-runtime';
import React from 'react';
import { Select as Select$1 } from '@base-ui/react/select';
import { cn } from '../../../fd-toolbox/lib/utils.js';
import { Icon, iconNames } from '../icon/Icon.js';
import { LabelAnimation } from '../animation/LabelAnimation.js';
import { cva } from 'class-variance-authority';
import { isNullOrUndefined } from '../../../fd-toolbox/functions/value-checking-functions.js';
import { componentVariantNames, floatingPositionStrategies } from '../../../fd-toolbox/constants/html-constants.js';
import { wellKnownMetaProps } from '../../../fd-toolbox-core/constants/meta-constants.js';
import { reactProperties } from '../constants/component-toolbox-constants.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
const selectVariants = cva("ring-offset-background placeholder:text-muted-foreground flex h-8 w-full items-center justify-between bg-transparent py-2 pr-1 pl-1 text-sm whitespace-nowrap focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", {
  variants: {
    variant: {
      bordered: "border-input focus:ring-ring rounded-md border shadow-sm focus:ring-1",
      float: "border-border hover:border-fd-accent rounded-none border-0 border-b shadow-none transition"
    },
    size: {
      default: "",
      short: ""
    }
  },
  defaultVariants: {
    variant: componentVariantNames.float,
    size: componentVariantNames.default
  }
});
const Select = Select$1.Root;
const SelectGroup = Select$1.Group;
const SelectValue = Select$1.Value;
function isReactElementWithStringChildren(element) {
  return React.isValidElement(element) && !isNullOrUndefined(element.props) && typeof element.props === "object" && reactProperties.children in element.props && typeof element.props.children === "string";
}
__name(isReactElementWithStringChildren, "isReactElementWithStringChildren");
function SelectTrigger({
  className,
  children,
  label,
  shouldAnimate,
  skipAnimationOnce,
  variant,
  size,
  iconClassName,
  noUnderline,
  id,
  ref
}) {
  const isChildrenEmptyString = !children || isReactElementWithStringChildren(children) && children.props.children.trim() === "";
  const shouldShowIcon = isChildrenEmptyString || size !== "short";
  return /* @__PURE__ */jsxs(Select$1.Trigger, {
    ref,
    className: cn("border-input ring-offset-background placeholder:text-muted-foreground focus:ring-primary flex h-8 w-full items-center justify-between rounded-md border bg-transparent py-2 pr-3 text-sm whitespace-nowrap shadow-sm focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", selectVariants({
      variant
    }), className, noUnderline && "border-0"),
    id,
    children: [/* @__PURE__ */jsxs("div", {
      className: cn(!!label && "first-letter:text-sm", className),
      children: [children, label && /* @__PURE__ */jsx(LabelAnimation, {
        variant: componentVariantNames.float,
        label,
        shouldAnimate,
        skipAnimationOnce,
        className: "top-0 max-w-full"
      })]
    }), shouldShowIcon && /* @__PURE__ */jsx(Select$1.Icon, {
      children: /* @__PURE__ */jsx(Icon, {
        name: iconNames.caretSort,
        className: cn("text-foreground size-3.5 shrink-0 opacity-50", iconClassName)
      })
    })]
  });
}
__name(SelectTrigger, "SelectTrigger");
SelectTrigger.displayName = Select$1.Trigger.displayName;
function SelectContent({
  className,
  children,
  position,
  disablePortal
}) {
  const resolvedPosition = position ?? floatingPositionStrategies.popper;
  const content = /* @__PURE__ */jsxs(Select$1.Positioner, {
    sideOffset: 4,
    alignItemWithTrigger: resolvedPosition === floatingPositionStrategies.itemAligned,
    className: "z-50",
    children: [/* @__PURE__ */jsx(Select$1.ScrollUpArrow, {
      className: "flex items-center justify-center py-1",
      children: /* @__PURE__ */jsx(Icon, {
        name: iconNames.caretSort
      })
    }), /* @__PURE__ */jsx(Select$1.Popup, {
      className: cn("bg-popover text-popover-foreground max-h-96 min-w-[var(--anchor-width)] overflow-y-auto rounded-md border p-1 shadow-md", resolvedPosition === floatingPositionStrategies.popper && "w-full", className),
      children: /* @__PURE__ */jsx(Select$1.List, {
        className: "p-1",
        children
      })
    }), /* @__PURE__ */jsx(Select$1.ScrollDownArrow, {
      className: "flex items-center justify-center py-1",
      children: /* @__PURE__ */jsx(Icon, {
        name: iconNames.caretSort
      })
    })]
  });
  if (disablePortal) {
    return content;
  }
  return /* @__PURE__ */jsx(Select$1.Portal, {
    children: content
  });
}
__name(SelectContent, "SelectContent");
SelectContent.displayName = Select$1.Popup.displayName;
function SelectLabel({
  className,
  children,
  ref
}) {
  return /* @__PURE__ */jsx(Select$1.GroupLabel, {
    ref,
    className: cn("px-2 py-1.5 text-sm font-semibold", className),
    children
  });
}
__name(SelectLabel, "SelectLabel");
SelectLabel.displayName = Select$1.GroupLabel.displayName;
function SelectItem({
  className,
  value,
  children,
  id
}) {
  const itemProps = {};
  if (id) {
    itemProps[wellKnownMetaProps.id] = id;
  }
  return /* @__PURE__ */jsxs(Select$1.Item, {
    value,
    className: cn("focus:bg-muted/50 relative flex w-full cursor-default items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className),
    ...itemProps,
    children: [/* @__PURE__ */jsx("span", {
      className: "absolute right-2 flex size-3.5 items-center justify-center",
      children: /* @__PURE__ */jsx(Select$1.ItemIndicator, {
        children: /* @__PURE__ */jsx(Icon, {
          name: iconNames.check
        })
      })
    }), /* @__PURE__ */jsx(Select$1.ItemText, {
      children
    })]
  });
}
__name(SelectItem, "SelectItem");
SelectItem.displayName = Select$1.Item.displayName;
function SelectSeparator({
  className
}) {
  return /* @__PURE__ */jsx(Select$1.Separator, {
    className: cn("bg-muted -mx-1 my-1 h-px", className)
  });
}
__name(SelectSeparator, "SelectSeparator");
SelectSeparator.displayName = Select$1.Separator.displayName;

export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, selectVariants };
