"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__, {
    CodeMirror: ()=>CodeMirror
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_lodash_namespaceObject = require("lodash");
const external_index_js_namespaceObject = require("../../../index.js");
const external_VariableSelect_js_namespaceObject = require("./VariableSelect.js");
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n          display: flex;\n          border: dashed 1px #eee;\n          flex-direction: row;\n        "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
function _templateObject1() {
    const data = _tagged_template_literal([
        "\n            flex: 1;\n            text-align: center;\n            color: #e5e5e5;\n          "
    ]);
    _templateObject1 = function() {
        return data;
    };
    return data;
}
function _templateObject2() {
    const data = _tagged_template_literal([
        ""
    ]);
    _templateObject2 = function() {
        return data;
    };
    return data;
}
function _templateObject3() {
    const data = _tagged_template_literal([
        "\n          border: dashed 1px #eee;\n        "
    ]);
    _templateObject3 = function() {
        return data;
    };
    return data;
}
const CodeMirror = (props)=>{
    const { value = '', changeOnSelect, onChange, ...others } = props;
    const scope = 'function' == typeof props.scope ? props.scope() : props.scope;
    const { t } = (0, external_index_js_namespaceObject.useTranslation)();
    const [options, setOptions] = (0, external_react_namespaceObject.useState)(scope ? (0, external_lodash_namespaceObject.cloneDeep)(scope) : []);
    const [codeValue, setCodeValue] = (0, external_react_namespaceObject.useState)(value);
    const form = (0, schema_namespaceObject.useForm)();
    const disabled = props.disabled || form.disabled;
    const onInsert = (selected)=>{
        const variable = "{{".concat(selected.join('.'), "}}");
        const nextValue = "".concat(variable, "\n").concat(codeValue);
        setCodeValue(nextValue);
        null == onChange || onChange(nextValue);
    };
    const handleChange = (nextValue)=>{
        setCodeValue(nextValue);
        null == onChange || onChange(nextValue);
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                className: (0, external_index_js_namespaceObject.css)(_templateObject()),
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                        className: (0, external_index_js_namespaceObject.css)(_templateObject1()),
                        children: t('Click on the right to select variables →')
                    }),
                    disabled ? null : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_VariableSelect_js_namespaceObject.VariableSelect, {
                        className: (0, external_index_js_namespaceObject.css)(_templateObject2()),
                        options: options,
                        setOptions: setOptions,
                        onInsert: onInsert,
                        changeOnSelect: changeOnSelect
                    })
                ]
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.CodeMirror, {
                className: (0, external_index_js_namespaceObject.css)(_templateObject3()),
                value: codeValue,
                defaultLanguage: "Plain Text",
                onChange: handleChange,
                ...others
            })
        ]
    });
};
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
});
