import React, { useEffect, useState } from "react";
import { RelayDataType, RelayTransmissionType, } from "../../../platform/services/bloombergBridge/lib/types";
export const BloombergRelay = ({ config, onChange }) => {
    var _a;
    const [type, setType] = useState(config.type);
    const [data, setData] = useState(config.data);
    const [id, setID] = useState(config.id);
    const [args, setArgs] = useState((_a = config.args) !== null && _a !== void 0 ? _a : {});
    useEffect(() => {
        var _a;
        setType(config.type);
        setData(config.data);
        setID(config.id);
        setArgs((_a = config.args) !== null && _a !== void 0 ? _a : {});
    }, [config]);
    return (React.createElement("div", { className: "bloomberg-relay" },
        React.createElement("select", { className: "bloomberg-relay-type", value: type, onChange: (e) => {
                const { value } = e.currentTarget;
                let newDataType = RelayDataType.BloombergSecurity;
                if (value === RelayTransmissionType.FDC3Intent || value === RelayTransmissionType.FDC3Channel) {
                    newDataType = RelayDataType.FDC3Instrument;
                }
                if (value === RelayTransmissionType.FDC3Intent ||
                    value === RelayTransmissionType.FDC3Channel ||
                    value === RelayTransmissionType.LaunchPadGroup ||
                    value === RelayTransmissionType.BloombergCommand ||
                    value === RelayTransmissionType.BloombergWorksheet) {
                    onChange({ id, type: value, data: newDataType, args });
                }
            } },
            React.createElement("option", { value: RelayTransmissionType.FDC3Intent }, "FDC3 Intent"),
            React.createElement("option", { value: RelayTransmissionType.FDC3Channel }, "FDC3 Channel"),
            React.createElement("option", { value: RelayTransmissionType.LaunchPadGroup }, "LaunchPad Group"),
            React.createElement("option", { value: RelayTransmissionType.BloombergCommand }, "Bloomberg Command"),
            React.createElement("option", { value: RelayTransmissionType.BloombergWorksheet }, "Bloomberg Worksheet")),
        React.createElement("label", null, (config.type === RelayTransmissionType.FDC3Intent && "Intent Name") ||
            (config.type === RelayTransmissionType.FDC3Channel && "Channel Name (optional)") ||
            (config.type === RelayTransmissionType.LaunchPadGroup && "Group Name (optional)") ||
            (config.type === RelayTransmissionType.BloombergCommand && "Command Name") ||
            (config.type === RelayTransmissionType.BloombergWorksheet && "Worksheet Name")),
        React.createElement("input", { type: "text", value: id, onChange: (e) => {
                const { value } = e.currentTarget;
                onChange({ id: value, type, data, args });
            } }),
        type === RelayTransmissionType.BloombergCommand && (React.createElement(React.Fragment, null,
            React.createElement("label", null, "Panel"),
            React.createElement("select", { value: args === null || args === void 0 ? void 0 : args.panel, onChange: (e) => {
                    onChange({
                        id,
                        type,
                        data,
                        args: {
                            ...args,
                            panel: e.currentTarget.value,
                        },
                    });
                } },
                React.createElement("option", { value: "1" }, "1"),
                React.createElement("option", { value: "2" }, "2"),
                React.createElement("option", { value: "3" }, "3"),
                React.createElement("option", { value: "4" }, "4")),
            React.createElement("label", null, "Tails"),
            React.createElement("input", { type: "text", value: args === null || args === void 0 ? void 0 : args.tails, onChange: (e) => {
                    onChange({
                        id,
                        type,
                        data,
                        args: {
                            ...args,
                            tails: e.currentTarget.value,
                        },
                    });
                } })))));
};
//# sourceMappingURL=BloombergRelay.js.map