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__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_antd_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__async_data_provider_index_mjs__ from "../../../../async-data-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../../../schema-component/index.mjs";
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      position: relative;\n      .ant-input {\n        width: 100%;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        input: css(_templateObject())
    };
});
const SQLInput = (param)=>{
    let { disabled } = param;
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const { run, loading, error } = (0, __WEBPACK_EXTERNAL_MODULE__async_data_provider_index_mjs__.useAsyncData)();
    const { styles } = useStyles();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const execute = ()=>{
        if (!field.value) return;
        run(field.value);
    };
    const toggleEditing = ()=>{
        if (!disabled && !field.value) return;
        if (!disabled) run(field.value);
        field.setComponentProps({
            disabled: !disabled
        });
    };
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        if (error) field.setComponentProps({
            disabled: false
        });
    }, [
        field,
        error
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        className: styles.input,
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.Input.TextArea, {
                value: field.value,
                disabled: disabled,
                onChange: (e)=>field.value = e.target.value
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_antd__.Button.Group, {
                children: [
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
                        onClick: toggleEditing,
                        ghost: true,
                        size: "small",
                        type: "primary",
                        icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.EditOutlined, {}),
                        children: t(disabled ? 'Edit' : 'Confirm')
                    }),
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
                        onClick: ()=>execute(),
                        loading: loading,
                        ghost: true,
                        size: "small",
                        type: "primary",
                        icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.RightSquareOutlined, {}),
                        children: t('Execute')
                    })
                ]
            })
        ]
    });
};
export { SQLInput };
