import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Button, Form, Input } from 'antd';
import { useEffect } from 'react';
import Base64Upload from './Base64Upload';
export default function DatabaseForm({ db, deployment, loading = false, disabled = false, hostname = '', onSubmit, }) {
    const [form] = Form.useForm();
    useEffect(() => {
        form.setFieldsValue({ CUBEJS_DB_HOST: hostname });
    }, [hostname]);
    const defaultValues = (deployment.envVariables || []).reduce((obj, envVar) => {
        obj[envVar.name] = envVar.value;
        return obj;
    }, {});
    return (_jsxs(Form, { "data-testid": "wizard-db-form", form: form, layout: "vertical", onFinish: (v) => {
            v['CUBEJS_DB_TYPE'] = db.driver;
            onSubmit(v);
        }, initialValues: defaultValues, children: [db.settings.map((param) => param.type === 'base64upload' ? (_jsx(Base64Upload, { onInput: ({ raw, encoded }) => {
                    if (param.uploadTarget) {
                        form.setFieldsValue({ [param.uploadTarget]: encoded });
                    }
                    if (param.extractField) {
                        form.setFieldsValue({
                            [param.extractField.formField]: raw[param.extractField.jsonField],
                        });
                    }
                } })) : (_jsx(Form.Item, { label: param.title || param.env, name: param.env, children: param.title ? (param.env === 'CUBEJS_DB_PASS' ? (_jsx(Input.Password, { "data-testid": param.env })) : (_jsx(Input, { "data-testid": param.env }))) : (_jsx(Input.TextArea, { "data-testid": param.env, rows: 1, style: {
                        overflow: 'hidden',
                        resize: 'none',
                    } })) }, param.env))), _jsx(Button, { "data-testid": "wizard-form-submit-btn", type: "primary", htmlType: "submit", loading: loading, disabled: disabled, children: "Apply" })] }));
}
//# sourceMappingURL=DatabaseForm.js.map