import React, { useEffect, useState } from "react";
import { FEAGlobals } from "../../../../../common";
import { BloombergFDC3 } from "../../../bloomberg/BloombergFDC3";
import { Checkbox } from "../../../common/Checkbox";
import { BloombergStatusBadge } from "../../../toolbar/bloomberg/BloombergStatus";
const BLOOMBERG_ERROR_MESSAGE = "Error received when checking bloomberg bridge config", PREFERENCE_FIELD_SHOW_STATUS = "finsemble.custom.bloomberg.showStatus", PREFERENCE_FIELD_REMOTE_ADDRESS = "finsemble.custom.bloomberg.remoteAddress", PREFERENCE_FIELD_REMOTE = "finsemble.custom.bloomberg.remote";
const Bloomberg = () => {
    const [showBloomberg, setShowBloomberg] = useState(false);
    const [isRemote, setIsRemote] = useState(false);
    const [bbgRemoteAddress, setBbgRemoteAddress] = useState("");
    useEffect(() => {
        (async () => {
            var _a, _b, _c;
            const { err, data: preferences } = await FEAGlobals.FSBL.Clients.ConfigClient.getPreferences();
            if (err) {
                FEAGlobals.FSBL.Clients.Logger.system.error(BLOOMBERG_ERROR_MESSAGE, err);
            }
            setShowBloomberg((_a = preferences === null || preferences === void 0 ? void 0 : preferences[PREFERENCE_FIELD_SHOW_STATUS]) !== null && _a !== void 0 ? _a : false);
            setIsRemote((_b = preferences === null || preferences === void 0 ? void 0 : preferences[PREFERENCE_FIELD_REMOTE]) !== null && _b !== void 0 ? _b : false);
            setBbgRemoteAddress((_c = preferences === null || preferences === void 0 ? void 0 : preferences[PREFERENCE_FIELD_REMOTE_ADDRESS]) !== null && _c !== void 0 ? _c : "");
        })();
        FEAGlobals.FSBL.Clients.ConfigClient.addListener({ field: PREFERENCE_FIELD_SHOW_STATUS }, (err, { value }) => {
            setShowBloomberg(value);
        });
        FEAGlobals.FSBL.Clients.ConfigClient.addListener({ field: PREFERENCE_FIELD_REMOTE }, (err, { value }) => {
            setIsRemote(value);
        });
        FEAGlobals.FSBL.Clients.ConfigClient.addListener({ field: PREFERENCE_FIELD_REMOTE_ADDRESS }, (err, { value }) => {
            setBbgRemoteAddress(value);
        });
    }, []);
    return (React.createElement("div", { className: "bloomberg-config" },
        React.createElement("div", { className: "status-config" },
            React.createElement(Checkbox, { label: "Show status in Toolbar", checked: showBloomberg, onClick: () => {
                    FEAGlobals.FSBL.Clients.ConfigClient.setPreference({
                        field: PREFERENCE_FIELD_SHOW_STATUS,
                        value: !showBloomberg,
                    });
                } }),
            showBloomberg && React.createElement(BloombergStatusBadge, null)),
        React.createElement("div", { className: "remote-config" },
            React.createElement(Checkbox, { label: "Remote", checked: isRemote, onClick: () => {
                    FEAGlobals.FSBL.Clients.ConfigClient.setPreference({
                        field: PREFERENCE_FIELD_REMOTE,
                        value: !isRemote,
                    });
                } })),
        isRemote && (React.createElement("div", { className: "hostname-config" },
            React.createElement("label", { htmlFor: "hostname", style: { display: "block" } }, "Hostname"),
            React.createElement("input", { id: "hostname", type: "text", value: bbgRemoteAddress, onChange: (e) => {
                    FEAGlobals.FSBL.Clients.ConfigClient.setPreference({
                        field: PREFERENCE_FIELD_REMOTE_ADDRESS,
                        value: e.target.value,
                    });
                } }))),
        React.createElement(BloombergFDC3, null)));
};
export default Bloomberg;
//# sourceMappingURL=BloombergPreferences.js.map