'use strict';

var tslib_es6 = require('./tslib.es6-cjs.js');
var React = require('react');
var classnames = require('classnames');
var Icon = require('./Icon-cjs.js');
var OverlaySeparator = require('./OverlaySeparator-cjs.js');
var SelectGroupLabel = require('./SelectGroupLabel-cjs.js');

var styles = {"trigger":"WQiJQH4jadQ-","value":"P2HhjOjxY34-","iconWrapper":"cxgFUCKcXcw-","iconRotate":"_3BEK4Z1gGis-","positioner":"g221yZJtRrU-","popup":"vifRnCQ18ss-","list":"WsOmdkQ0SWU-","item":"wQ2wXu1YH-k-","itemText":"_--Vi-17OUiU-","itemIndicator":"CfjooR3I8Jc-","separator":"lI5-MyBERFY-","group":"_21z9KBWR06w-","groupLabel":"ZhtKkgZiSQI-","spinning":"sIXiKKpdSj8-"};

function mergeClassName(baseClassName, className) {
    if (typeof className === "function") {
        return (state) => classnames(baseClassName, className(state));
    }
    return classnames(baseClassName, className);
}

/**
 * The offset (px) between the trigger bottom edge and the popup top edge,
 * matching the Menu dropdown spacing.
 */
const SELECT_OFFSET = 6;
// ─── Trigger ─────────────────────────────────────────────────────────────────
function TriggerChevron() {
    return (React.createElement("span", { "aria-hidden": "true", className: styles.iconWrapper },
        React.createElement("span", { className: styles.iconRotate },
            React.createElement(Icon.Icon, { color: "greyBlue", name: "arrowDown", size: "base" }))));
}
function SelectPrimitiveFieldTrigger(_a) {
    var { valueSlot, className } = _a, props = tslib_es6.__rest(_a, ["valueSlot", "className"]);
    return (React.createElement("button", Object.assign({ type: "button", className: classnames(styles.trigger, className) }, props),
        valueSlot,
        React.createElement(TriggerChevron, null)));
}
function SelectPrimitiveTrigger(_a) {
    var { className, children } = _a, props = tslib_es6.__rest(_a, ["className", "children"]);
    return (React.createElement(SelectGroupLabel.SelectTrigger, Object.assign({ className: mergeClassName(styles.trigger, className) }, props),
        children,
        React.createElement(TriggerChevron, null)));
}
// ─── Value ───────────────────────────────────────────────────────────────────
function SelectPrimitiveValue(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return (React.createElement(SelectGroupLabel.SelectValue, Object.assign({ className: mergeClassName(styles.value, className) }, props)));
}
function SelectPrimitiveValueText(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return React.createElement("span", Object.assign({ className: classnames(styles.value, className) }, props));
}
// ─── Positioner ───────────────────────────────────────────────────────────────
function SelectPrimitivePositioner(_a) {
    var { className, sideOffset = SELECT_OFFSET, alignItemWithTrigger = false } = _a, props = tslib_es6.__rest(_a, ["className", "sideOffset", "alignItemWithTrigger"]);
    return (React.createElement(SelectGroupLabel.SelectPositioner, Object.assign({ className: mergeClassName(styles.positioner, className), sideOffset: sideOffset, alignItemWithTrigger: alignItemWithTrigger }, props)));
}
// ─── Popup ────────────────────────────────────────────────────────────────────
function SelectPrimitivePopup(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return (React.createElement(SelectGroupLabel.SelectPopup, Object.assign({ className: mergeClassName(styles.popup, className) }, props)));
}
// ─── List ─────────────────────────────────────────────────────────────────────
function SelectPrimitiveList(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return (React.createElement(SelectGroupLabel.SelectList, Object.assign({ className: mergeClassName(styles.list, className) }, props)));
}
// ─── Item ─────────────────────────────────────────────────────────────────────
function SelectPrimitiveItem(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return (React.createElement(SelectGroupLabel.SelectItem, Object.assign({ className: mergeClassName(styles.item, className) }, props)));
}
// ─── ItemText ─────────────────────────────────────────────────────────────────
function SelectPrimitiveItemText(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return (React.createElement(SelectGroupLabel.SelectItemText, Object.assign({ className: mergeClassName(styles.itemText, className) }, props)));
}
// ─── ItemIndicator ────────────────────────────────────────────────────────────
function SelectPrimitiveItemIndicator(_a) {
    var { className, children } = _a, props = tslib_es6.__rest(_a, ["className", "children"]);
    return (React.createElement(SelectGroupLabel.SelectItemIndicator, Object.assign({ keepMounted: true, className: mergeClassName(styles.itemIndicator, className) }, props), children !== null && children !== void 0 ? children : React.createElement(Icon.Icon, { color: "icon", name: "checkmark", size: "base" })));
}
// ─── Group ────────────────────────────────────────────────────────────────────
function SelectPrimitiveGroup(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return (React.createElement(SelectGroupLabel.SelectGroup, Object.assign({ className: mergeClassName(styles.group, className) }, props)));
}
// ─── GroupLabel ───────────────────────────────────────────────────────────────
function SelectPrimitiveGroupLabel(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return (React.createElement(SelectGroupLabel.SelectGroupLabel, Object.assign({ className: mergeClassName(styles.groupLabel, className) }, props)));
}
// ─── Separator ────────────────────────────────────────────────────────────────
function SelectPrimitiveSeparator(_a) {
    var { className } = _a, props = tslib_es6.__rest(_a, ["className"]);
    return (React.createElement(OverlaySeparator.OverlaySeparator, Object.assign({ className: classnames(styles.separator, className), "data-testid": "ATL-SelectPrimitive-Separator" }, props)));
}
// ─── Display names ───────────────────────────────────────────────────────────
SelectPrimitiveTrigger.displayName = "SelectPrimitive.Trigger";
SelectPrimitiveFieldTrigger.displayName = "SelectPrimitive.FieldTrigger";
SelectPrimitiveValue.displayName = "SelectPrimitive.Value";
SelectPrimitiveValueText.displayName = "SelectPrimitive.ValueText";
SelectPrimitivePositioner.displayName = "SelectPrimitive.Positioner";
SelectPrimitivePopup.displayName = "SelectPrimitive.Popup";
SelectPrimitiveList.displayName = "SelectPrimitive.List";
SelectPrimitiveItem.displayName = "SelectPrimitive.Item";
SelectPrimitiveItemText.displayName = "SelectPrimitive.ItemText";
SelectPrimitiveItemIndicator.displayName = "SelectPrimitive.ItemIndicator";
SelectPrimitiveGroup.displayName = "SelectPrimitive.Group";
SelectPrimitiveGroupLabel.displayName = "SelectPrimitive.GroupLabel";
SelectPrimitiveSeparator.displayName = "SelectPrimitive.Separator";
// ─── Compound export ─────────────────────────────────────────────────────────
const SelectPrimitive = {
    Root: SelectGroupLabel.SelectRoot,
    Trigger: SelectPrimitiveTrigger,
    FieldTrigger: SelectPrimitiveFieldTrigger,
    Value: SelectPrimitiveValue,
    ValueText: SelectPrimitiveValueText,
    Portal: SelectGroupLabel.SelectPortal,
    Positioner: SelectPrimitivePositioner,
    Popup: SelectPrimitivePopup,
    List: SelectPrimitiveList,
    Item: SelectPrimitiveItem,
    ItemText: SelectPrimitiveItemText,
    ItemIndicator: SelectPrimitiveItemIndicator,
    Group: SelectPrimitiveGroup,
    GroupLabel: SelectPrimitiveGroupLabel,
    Separator: SelectPrimitiveSeparator,
};

exports.SelectPrimitive = SelectPrimitive;
