import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__application_hooks_useGlobalVariable_mjs__ from "../../../application/hooks/useGlobalVariable.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__input_index_mjs__ from "../input/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__password_index_mjs__ from "../password/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__RawTextArea_mjs__ from "./RawTextArea.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__TextArea_mjs__ from "./TextArea.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__Variable_mjs__ from "./Variable.mjs";
const useEnvironmentVariableOptions = (scope)=>{
    const environmentVariables = (0, __WEBPACK_EXTERNAL_MODULE__application_hooks_useGlobalVariable_mjs__.useGlobalVariable)('$env');
    return (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        if (environmentVariables) return [
            environmentVariables
        ].filter(Boolean);
        return scope;
    }, [
        environmentVariables,
        scope
    ]);
};
const isVariable = (value)=>{
    const regex = /{{.*?}}/;
    return regex.test(value);
};
const TextAreaWithGlobalScope = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__RawTextArea_mjs__.RawTextArea, {
        ...others,
        scope: scope,
        fieldNames: fieldNames,
        rows: 3
    });
    if (number) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__Variable_mjs__.Variable.Input, {
        ...props,
        scope: scope,
        fieldNames: fieldNames
    });
    if (password && props.value && !isVariable(props.value)) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__password_index_mjs__.Password, {
        ...others,
        autoFocus: true
    });
    if (boolean) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__Variable_mjs__.Variable.Input, {
        ...props,
        scope: scope,
        fieldNames: fieldNames
    });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__TextArea_mjs__.TextArea, {
        ...others,
        scope: scope,
        fieldNames: fieldNames
    });
}, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)(__WEBPACK_EXTERNAL_MODULE__input_index_mjs__.Input.ReadPretty));
export { TextAreaWithGlobalScope, useEnvironmentVariableOptions };
