"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    useEnvironmentVariableOptions: ()=>useEnvironmentVariableOptions,
    TextAreaWithGlobalScope: ()=>TextAreaWithGlobalScope
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const useGlobalVariable_js_namespaceObject = require("../../../application/hooks/useGlobalVariable.js");
const index_js_namespaceObject = require("../input/index.js");
const external_password_index_js_namespaceObject = require("../password/index.js");
const external_RawTextArea_js_namespaceObject = require("./RawTextArea.js");
const external_TextArea_js_namespaceObject = require("./TextArea.js");
const external_Variable_js_namespaceObject = require("./Variable.js");
const useEnvironmentVariableOptions = (scope)=>{
    const environmentVariables = (0, useGlobalVariable_js_namespaceObject.useGlobalVariable)('$env');
    return (0, external_react_namespaceObject.useMemo)(()=>{
        if (environmentVariables) return [
            environmentVariables
        ].filter(Boolean);
        return scope;
    }, [
        environmentVariables,
        scope
    ]);
};
const isVariable = (value)=>{
    const regex = /{{.*?}}/;
    return regex.test(value);
};
const TextAreaWithGlobalScope = (0, schema_namespaceObject.connect)((props)=>{
    const { supportsLineBreak, password, number, boolean, ...others } = props;
    const scope = useEnvironmentVariableOptions(props.scope);
    const fieldNames = {
        value: 'name',
        label: 'title'
    };
    if (supportsLineBreak) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_RawTextArea_js_namespaceObject.RawTextArea, {
        ...others,
        scope: scope,
        fieldNames: fieldNames,
        rows: 3
    });
    if (number) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_Variable_js_namespaceObject.Variable.Input, {
        ...props,
        scope: scope,
        fieldNames: fieldNames
    });
    if (password && props.value && !isVariable(props.value)) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_password_index_js_namespaceObject.Password, {
        ...others,
        autoFocus: true
    });
    if (boolean) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_Variable_js_namespaceObject.Variable.Input, {
        ...props,
        scope: scope,
        fieldNames: fieldNames
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_TextArea_js_namespaceObject.TextArea, {
        ...others,
        scope: scope,
        fieldNames: fieldNames
    });
}, (0, schema_namespaceObject.mapReadPretty)(index_js_namespaceObject.Input.ReadPretty));
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
