"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const button_1 = __importStar(require("../button"));
const core_1 = require("../core");
const popover_1 = require("../popover");
const utils_1 = require("../utils");
const context_1 = require("./context");
/**
 * Displays a custom button component, which opens a popover on click.
 * Text within the button is either selected value or placeholder.
 * Includes special styling for disabled, readOnly and invalid states.
 */
exports.SelectButton = (0, core_1.vui)((props, ref) => {
    var _a;
    const { className } = props, rest = __rest(props, ["className"]);
    const { disabled, isInvalid, placeholder, readOnly, valueText } = (_a = (0, context_1.useSelectContext)()) !== null && _a !== void 0 ? _a : {};
    const styles = (0, core_1.useStyleConfig)('Select', (0, context_1.useSelectContext)());
    const text = valueText || placeholder;
    const disabledProps = disabled
        ? {
            activeBg: 'sandstone.79',
            cursor: 'not-allowed',
            backgroundColor: 'sandstone.79',
            borderColor: 'sandstone.79',
            hoverBg: 'sandstone.79',
            hoverBorderColor: 'sandstone.79',
            activeBorderColor: 'sandstone.79',
        }
        : undefined;
    const readOnlyProps = readOnly
        ? {
            activeBg: 'sandstone.95',
            bg: 'sandstone.95',
            color: 'seaBlue.main',
            cursor: 'auto',
            disabled: true,
            hoverBg: 'sandstone.95',
            opacity: 1,
        }
        : undefined;
    const isInvalidProps = isInvalid
        ? {
            borderColor: 'energyRed.45',
            hoverBorderColor: 'energyRed.45',
        }
        : undefined;
    const textColor = 'sandstone.10';
    const iconColor = disabled ? 'sandstone.10' : 'seaBlue.main';
    return ((0, jsx_runtime_1.jsx)(popover_1.PopoverTrigger, Object.assign({ as: button_1.LineButton, bg: "white", className: (0, utils_1.cs)('vui-selectButton', className), disabled: disabled, focusRing: 2, fontWeight: "regular", iconRight: (0, jsx_runtime_1.jsx)(button_1.default.Icon, { color: iconColor, ml: "auto", name: "falAngleDown" }), isFullWidth: true, px: 1, ref: ref, text: (0, jsx_runtime_1.jsx)(button_1.default.Text, Object.assign({ color: textColor }, utils_1.ellipsisOverflow, { children: text })), userSelect: "text" }, styles.button, disabledProps, readOnlyProps, isInvalidProps, rest)));
});
exports.SelectButton.displayName = 'SelectButton';
exports.default = exports.SelectButton;
//# sourceMappingURL=selectButton.js.map