"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormatColumnFormatWizardSection = exports.getFormatDisplayTypeForScope = exports.renderFormatColumnFormatSummary = exports.getFormatColumnFormatSummaryValue = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const rebass_1 = require("rebass");
const uniq_1 = tslib_1.__importDefault(require("lodash/uniq"));
const clamp_1 = tslib_1.__importDefault(require("lodash/clamp"));
const HelpBlock_1 = tslib_1.__importDefault(require("../../../components/HelpBlock"));
const Input_1 = tslib_1.__importDefault(require("../../../components/Input"));
const SimpleButton_1 = tslib_1.__importDefault(require("../../../components/SimpleButton"));
const CheckBox_1 = require("../../../components/CheckBox");
const FormLayout_1 = tslib_1.__importStar(require("../../../components/FormLayout"));
const AdaptableObjectRow_1 = require("../../Components/AdaptableObjectRow");
const Radio_1 = tslib_1.__importDefault(require("../../../components/Radio"));
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const Tabs_1 = require("../../../components/Tabs");
const StringExtensions_1 = tslib_1.__importDefault(require("../../../Utilities/Extensions/StringExtensions"));
const Tag_1 = require("../../../components/Tag");
const AdaptableContext_1 = require("../../AdaptableContext");
const FormatHelper_1 = tslib_1.__importDefault(require("../../../Utilities/Helpers/FormatHelper"));
const Toggle_1 = require("../../../components/Toggle");
const GeneralConstants_1 = require("../../../Utilities/Constants/GeneralConstants");
const Textarea_1 = tslib_1.__importDefault(require("../../../components/Textarea"));
const ButtonInfo_1 = require("../../Components/Buttons/ButtonInfo");
const DocumentationLinkConstants_1 = require("../../../Utilities/Constants/DocumentationLinkConstants");
const AdaptableColumn_1 = require("../../../AdaptableState/Common/AdaptableColumn");
const DOLLAR_OPTIONS = {
    FractionDigits: 2,
    FractionSeparator: '.',
    IntegerDigits: undefined,
    IntegerSeparator: ',',
    Prefix: '$',
    Suffix: '',
    Multiplier: 1,
    Parentheses: false,
};
const STERLING_OPTIONS = {
    FractionDigits: 2,
    FractionSeparator: '.',
    IntegerDigits: undefined,
    IntegerSeparator: ',',
    Prefix: '£',
    Suffix: '',
    Multiplier: 1,
    Parentheses: false,
};
const MILLION_OPTIONS = {
    FractionDigits: undefined,
    FractionSeparator: '.',
    IntegerDigits: undefined,
    IntegerSeparator: ',',
    Prefix: '',
    Suffix: 'M',
    Multiplier: 0.000001,
    Parentheses: false,
};
const THOUSAND_OPTIONS = {
    FractionDigits: undefined,
    FractionSeparator: '.',
    IntegerDigits: undefined,
    IntegerSeparator: ',',
    Prefix: '',
    Suffix: 'K',
    Multiplier: 0.001,
    Parentheses: false,
};
const PERCENT_OPTIONS = {
    FractionDigits: 2,
    FractionSeparator: '.',
    IntegerDigits: undefined,
    IntegerSeparator: ',',
    Prefix: '',
    Suffix: '%',
    Multiplier: 100,
    Parentheses: false,
};
const DateFormatPresets = [
    'MM/dd/yyyy',
    'dd-MM-yyyy',
    'MMMM do yyyy, h:mm:ss a',
    'EEEE',
    'MMM do yyyy',
    'yyyyMMdd',
    'HH:mm:ss',
];
const getFormatColumnFormatSummaryValue = (data) => {
    let content = 'N/A';
    if (!data.DisplayFormat) {
        content = 'N/A';
    }
    else {
        if (data.DisplayFormat.Formatter === 'NumberFormatter') {
            content = FormatHelper_1.default.NumberFormatter(GeneralConstants_1.DEFAULT_DOUBLE_DISPLAY_VALUE, data.DisplayFormat.Options);
        }
        if (data.DisplayFormat.Formatter === 'DateFormatter') {
            content = FormatHelper_1.default.DateFormatter(new Date(), data.DisplayFormat.Options);
        }
        if (data.DisplayFormat.Formatter === 'StringFormatter') {
            content = FormatHelper_1.default.StringFormatter(GeneralConstants_1.DEFAULT_STRING_DISPLAY_VALUE, data.DisplayFormat.Options);
        }
    }
    return content;
};
exports.getFormatColumnFormatSummaryValue = getFormatColumnFormatSummaryValue;
const renderCustomFormatter = (data, customFormatter, setFormatOption) => (React.createElement(FormLayout_1.FormRow, { key: customFormatter.id, label: customFormatter.label ?? customFormatter.id },
    React.createElement(CheckBox_1.CheckBox, { "data-name": customFormatter.id, checked: data.DisplayFormat.Options.CustomDisplayFormats?.some?.((item) => item === customFormatter.id), onChange: (checked) => {
            let newCustomFormats = data?.DisplayFormat?.Options?.CustomDisplayFormats ?? [];
            if (checked) {
                newCustomFormats = [...newCustomFormats, customFormatter.id];
            }
            else {
                newCustomFormats = newCustomFormats.filter((item) => item !== customFormatter.id);
            }
            setFormatOption('CustomDisplayFormats', newCustomFormats);
        } })));
const renderFormatColumnFormatSummary = (data) => {
    return React.createElement(Tag_1.Tag, null, (0, exports.getFormatColumnFormatSummaryValue)(data));
};
exports.renderFormatColumnFormatSummary = renderFormatColumnFormatSummary;
const getFormatDisplayTypeForScope = (scope, api) => {
    if (scope == undefined) {
        return undefined;
    }
    if ('All' in scope) {
        return undefined;
    }
    // Date-related data types that should all be treated as 'date'
    const dateTypes = api.columnApi.internalApi.getColumnDateTypes();
    // Check for ColumnIds in scope
    if ('ColumnIds' in scope) {
        const columns = scope.ColumnIds.map((c) => api.columnApi.getColumnWithColumnId(c)).filter(Boolean);
        const columnDataTypes = (0, uniq_1.default)(columns.map((c) => c.dataType));
        // If there's only one data type
        if (columnDataTypes.length === 1) {
            const dataType = columnDataTypes[0];
            if (dataType === 'number') {
                return 'number';
            }
            if (dateTypes.includes(dataType)) {
                return 'date';
            }
            if (dataType === 'text') {
                return 'text';
            }
        }
        // If there are multiple data types but they're all date types
        else if (columnDataTypes.length > 0 &&
            columnDataTypes.every((type) => dateTypes.includes(type))) {
            return 'date';
        }
        return undefined;
    }
    // Check for DataTypes in scope
    if ('DataTypes' in scope && scope.DataTypes.length === 1) {
        const dataType = scope.DataTypes[0];
        if (dataType === 'number') {
            return 'number';
        }
        if (dateTypes.includes(dataType)) {
            return 'date';
        }
        if (dataType === 'text') {
            return 'text';
        }
    }
    // If there are multiple data types but they're all date types
    else if ('DataTypes' in scope &&
        scope.DataTypes.length > 0 &&
        scope.DataTypes.every((type) => dateTypes.includes(type))) {
        return 'date';
    }
    // Check for ColumnTypes in scope
    if ('ColumnTypes' in scope && scope.ColumnTypes.length) {
        // If a Pivot Total Column Type is specified, we can safely assume that the data type is number
        const pivotTotalTypes = [
            AdaptableColumn_1.PIVOT_ANY_TOTAL_COLUMN_TYPE,
            AdaptableColumn_1.PIVOT_GRAND_TOTAL_COLUMN_TYPE,
            AdaptableColumn_1.PIVOT_COLUMN_TOTAL_COLUMN_TYPE,
            AdaptableColumn_1.PIVOT_AGGREGATION_TOTAL_COLUMN_TYPE,
        ];
        // If all column types are pivot total types, we can safely assume that the data type is number
        if (scope.ColumnTypes.length > 0 &&
            scope.ColumnTypes.every((type) => pivotTotalTypes.includes(type))) {
            return 'number';
        }
        // Check if all columns with this column type have the same data type
        const columns = scope.ColumnTypes.flatMap((columnType) => {
            return api.columnApi.getColumnsByColumnType(columnType);
        });
        if (columns.length) {
            // Check if all columns have the same type
            const allSameType = columns.every((column) => column.dataType === columns[0].dataType);
            // Handle specific data types
            if (allSameType) {
                const dataType = columns[0].dataType;
                if (dataType === 'number') {
                    return 'number';
                }
                if (dateTypes.includes(dataType)) {
                    return 'date';
                }
                if (dataType === 'text') {
                    return 'text';
                }
            }
            // Check if all columns are date types (even if they're different date types)
            const allDateTypes = columns.every((column) => dateTypes.includes(column.dataType));
            if (allDateTypes) {
                return 'date';
            }
        }
    }
    return undefined;
};
exports.getFormatDisplayTypeForScope = getFormatDisplayTypeForScope;
const renderDateFormat = (data, _onChange, setFormatOption, scopedCustomFormatters) => {
    if (data.DisplayFormat.Formatter !== 'DateFormatter') {
        return null;
    }
    return (React.createElement(rebass_1.Box, { padding: 2 },
        React.createElement(Tabs_1.Tabs, null,
            React.createElement(Tabs_1.Tabs.Tab, null, "Format"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(rebass_1.Text, { padding: 2, fontSize: 2 },
                    "Either create your own date pattern, or select one of the preset date formats (check out",
                    ' ',
                    React.createElement("a", { href: "https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table", target: "_blank" }, "available symbols"),
                    ")."),
                React.createElement(FormLayout_1.default, null,
                    React.createElement(FormLayout_1.FormRow, { label: "Pattern" },
                        React.createElement(Input_1.default, { "data-name": "pattern", value: data.DisplayFormat.Options.Pattern ?? '', onChange: (e) => setFormatOption('Pattern', e.currentTarget.value), mr: 2 }),
                        React.createElement("span", null, data.DisplayFormat.Options.Pattern &&
                            FormatHelper_1.default.DateFormatter(new Date(), data.DisplayFormat.Options, true)))))),
        scopedCustomFormatters.length > 0 && (React.createElement(Tabs_1.Tabs, { marginTop: 2, keyboardNavigation: false },
            React.createElement(Tabs_1.Tabs.Tab, null, "Custom Formats"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(FormLayout_1.default, null, scopedCustomFormatters.map((formatter) => renderCustomFormatter(data, formatter, setFormatOption)))))),
        React.createElement(Tabs_1.Tabs, { marginTop: 2, keyboardNavigation: false },
            React.createElement(Tabs_1.Tabs.Tab, null, "Presets"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { style: { fontWeight: 'bold' }, colItems: [
                        { Content: 'Pattern', Size: 1 },
                        { Content: 'Formatted Date', Size: 1 },
                        { Content: '', Size: 1 },
                    ] }),
                DateFormatPresets.map((Pattern, index) => (React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { key: index, colItems: [
                        { Content: Pattern, Size: 1 },
                        {
                            Content: FormatHelper_1.default.DateFormatter(new Date(), { Pattern }),
                            Size: 1,
                        },
                        {
                            Content: (React.createElement(SimpleButton_1.default, { "data-name": "apply-format-pattern", "data-value": Pattern, onClick: () => setFormatOption('Pattern', Pattern) }, "Apply")),
                            Size: 1,
                        },
                    ] })))))));
};
const renderNumberFormat = (data, onChange, setFormatOption, scopedCustomFormatters, api) => {
    if (data.DisplayFormat.Formatter !== 'NumberFormatter') {
        return null;
    }
    const setPercentPreset = () => {
        onChange({
            DisplayFormat: {
                Formatter: 'NumberFormatter',
                Options: PERCENT_OPTIONS,
            },
        });
    };
    const setDivideThousandPreset = () => {
        onChange({
            DisplayFormat: {
                Formatter: 'NumberFormatter',
                Options: THOUSAND_OPTIONS,
            },
        });
    };
    const setDivideMillionPreset = () => {
        onChange({
            DisplayFormat: {
                Formatter: 'NumberFormatter',
                Options: MILLION_OPTIONS,
            },
        });
    };
    const setDollarPreset = () => {
        onChange({
            DisplayFormat: {
                Formatter: 'NumberFormatter',
                Options: DOLLAR_OPTIONS,
            },
        });
    };
    const setSterlingPreset = () => {
        onChange({
            DisplayFormat: {
                Formatter: 'NumberFormatter',
                Options: STERLING_OPTIONS,
            },
        });
    };
    const IS_PERCENT = data.DisplayFormat.Options.Suffix === '%' &&
        data.DisplayFormat.Options.Multiplier === PERCENT_OPTIONS.Multiplier; //isEqual(data.DisplayFormat.Options, PERCENT_OPTIONS);
    const IS_THOUSAND = data.DisplayFormat.Options.Suffix === 'K' &&
        data.DisplayFormat.Options.Multiplier === THOUSAND_OPTIONS.Multiplier; // isEqual(data.DisplayFormat.Options, THOUSAND_OPTIONS);
    const IS_MILLION = data.DisplayFormat.Options.Suffix === 'M' &&
        data.DisplayFormat.Options.Multiplier === MILLION_OPTIONS.Multiplier; //isEqual(data.DisplayFormat.Options, MILLION_OPTIONS);
    const IS_DOLLAR = data.DisplayFormat.Options.Prefix === '$'; //isEqual(data.DisplayFormat.Options, DOLLAR_OPTIONS);
    const IS_STERLING = data.DisplayFormat.Options.Prefix === '£'; //isEqual(data.DisplayFormat, STERLING_OPTIONS);
    const showDocumentationLinks = api.internalApi.isDocumentationLinksDisplayed();
    return (React.createElement(rebass_1.Box, { "data-name": 'format-column-display-format', padding: 2 },
        React.createElement(Tabs_1.Tabs, null,
            React.createElement(Tabs_1.Tabs.Tab, null, "Format"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(rebass_1.Flex, { flexDirection: "row" },
                    React.createElement(FormLayout_1.default, { mr: 3 },
                        React.createElement(FormLayout_1.FormRow, { label: "Fraction Separator" },
                            React.createElement(Input_1.default, { "data-name": "fraction-separator", value: data.DisplayFormat.Options.FractionSeparator ?? '', onChange: (e) => setFormatOption('FractionSeparator', e.currentTarget.value) }),
                            ' '),
                        React.createElement(FormLayout_1.FormRow, { label: "Integer Separator" },
                            React.createElement(Input_1.default, { "data-name": "integer-separator", value: data.DisplayFormat.Options.IntegerSeparator ?? '', onChange: (e) => setFormatOption('IntegerSeparator', e.currentTarget.value) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Prefix" },
                            React.createElement(Input_1.default, { "data-name": "prefix", value: data.DisplayFormat.Options.Prefix ?? '', onChange: (e) => setFormatOption('Prefix', e.currentTarget.value) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Suffix" },
                            React.createElement(Input_1.default, { "data-name": "suffix", value: data.DisplayFormat.Options.Suffix ?? '', onChange: (e) => setFormatOption('Suffix', e.currentTarget.value) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Truncate" },
                            React.createElement(CheckBox_1.CheckBox, { "data-name": "truncate-checkbox", checked: data.DisplayFormat.Options.Truncate, onChange: (checked) => setFormatOption('Truncate', checked) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Ceiling" },
                            React.createElement(CheckBox_1.CheckBox, { "data-name": "ceiling-checkbox", checked: data.DisplayFormat.Options.Ceiling, onChange: (checked) => setFormatOption('Ceiling', checked) })),
                        ' ',
                        React.createElement(FormLayout_1.FormRow, { label: "Absolute" },
                            React.createElement(CheckBox_1.CheckBox, { "data-name": "abs-checkbox", checked: data.DisplayFormat.Options.Abs, onChange: (checked) => setFormatOption('Abs', checked) }))),
                    React.createElement(FormLayout_1.default, null,
                        React.createElement(FormLayout_1.FormRow, { label: "Fraction Digits" },
                            React.createElement(Input_1.default, { "data-name": "fraction-digits", type: "number", min: "0", 
                                // max="20"
                                value: typeof data.DisplayFormat.Options.FractionDigits === 'number'
                                    ? data.DisplayFormat.Options.FractionDigits
                                    : '', onChange: (e) => setFormatOption('FractionDigits', StringExtensions_1.default.IsNumeric(e.currentTarget.value)
                                    ? (0, clamp_1.default)(Number(e.currentTarget.value), 0, 20)
                                    : undefined) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Integer Digits" },
                            React.createElement(Input_1.default, { "data-name": "integer-digits", type: "number", min: "0", value: data.DisplayFormat.Options.IntegerDigits, onChange: (e) => setFormatOption('IntegerDigits', StringExtensions_1.default.IsNumeric(e.currentTarget.value)
                                    ? (0, clamp_1.default)(Number(e.currentTarget.value), 0, 20)
                                    : undefined) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Multiplier" },
                            React.createElement(Input_1.default, { "data-name": "multiplier", type: "number", value: data.DisplayFormat.Options.Multiplier, onChange: (e) => setFormatOption('Multiplier', Number(e.currentTarget.value)) })),
                        ' ',
                        React.createElement(FormLayout_1.FormRow, { label: "Parentheses" },
                            React.createElement(CheckBox_1.CheckBox, { "data-name": "parentheses-checkbox", checked: data.DisplayFormat.Options.Parentheses, onChange: (checked) => setFormatOption('Parentheses', checked) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Floor" },
                            React.createElement(CheckBox_1.CheckBox, { "data-name": "floor-checkbox", checked: data.DisplayFormat.Options.Floor, onChange: (checked) => setFormatOption('Floor', checked) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Round" },
                            React.createElement(CheckBox_1.CheckBox, { "data-name": "round-checkbox", checked: data.DisplayFormat.Options.Round, onChange: (checked) => setFormatOption('Round', checked) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Empty" },
                            React.createElement(CheckBox_1.CheckBox, { "data-name": "empty-checkbox", checked: data.DisplayFormat.Options.Empty, onChange: (checked) => setFormatOption('Empty', checked) })))))),
        scopedCustomFormatters.length > 0 && (React.createElement(Tabs_1.Tabs, { marginTop: 2, keyboardNavigation: false },
            React.createElement(Tabs_1.Tabs.Tab, null, "Custom Formats"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(rebass_1.Flex, { flexDirection: "row" },
                    React.createElement(FormLayout_1.default, null, scopedCustomFormatters.map((formatter) => renderCustomFormatter(data, formatter, setFormatOption))))))),
        React.createElement(Tabs_1.Tabs, { marginTop: 2, autoFocus: false, keyboardNavigation: false },
            React.createElement(Tabs_1.Tabs.Tab, null, "Presets"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(rebass_1.Text, { padding: 2, fontSize: 2 }, "Select a preset for common use cases"),
                React.createElement(rebass_1.Flex, { flexDirection: "row" },
                    React.createElement(FormLayout_1.default, { margin: 2 },
                        React.createElement(FormLayout_1.FormRow, { label: "Show As:" },
                            React.createElement(Radio_1.default, { "data-name": "preset-percentage", marginLeft: 2, checked: IS_PERCENT, onChange: () => setPercentPreset() }, "Percentage"),
                            React.createElement(Radio_1.default, { "data-name": "preset-thousand", marginLeft: 3, checked: IS_THOUSAND, onChange: () => setDivideThousandPreset() }, "K (Thousand)"),
                            React.createElement(Radio_1.default, { "data-name": "preset-million", marginLeft: 3, checked: IS_MILLION, onChange: () => setDivideMillionPreset() }, "M (Million)"),
                            React.createElement(Radio_1.default, { "data-name": "preset-dollar", marginLeft: 3, checked: IS_DOLLAR, onChange: () => setDollarPreset() }, "Dollar"),
                            React.createElement(Radio_1.default, { "data-name": "preset-sterling", marginLeft: 3, checked: IS_STERLING, onChange: () => setSterlingPreset() }, "Sterling")))))),
        React.createElement(Tabs_1.Tabs, { marginTop: 2, autoFocus: false, keyboardNavigation: false },
            React.createElement(Tabs_1.Tabs.Tab, null, "Dynamic Content"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(rebass_1.Text, { padding: 2, fontSize: 2 }, "Provide dynamic content through the use of Placeholders"),
                React.createElement(FormLayout_1.default, { margin: 2 },
                    React.createElement(FormLayout_1.FormRow, { label: "" },
                        React.createElement(Textarea_1.default, { minWidth: 300, rows: 3, placeholder: "", marginTop: 2, type: 'text', autoFocus: false, value: data.DisplayFormat.Options.Content?.toString() ?? '', onChange: (e) => setFormatOption('Content', e.currentTarget.value) }),
                        showDocumentationLinks && (React.createElement(HelpBlock_1.default, { "data-name": "query-documentation", mt: 3, mb: 2, style: {
                                fontSize: 'var(--ab-font-size-3)',
                                padding: 0,
                            } },
                            React.createElement(ButtonInfo_1.ButtonInfo, { mr: 2, onClick: () => window.open(DocumentationLinkConstants_1.FormatColumnPlaceholderDocsLink, '_blank') }),
                            "Learn more about using placeholders"))),
                    ' '))),
        React.createElement(Tabs_1.Tabs, { marginTop: 2, autoFocus: false, keyboardNavigation: false },
            React.createElement(Tabs_1.Tabs.Tab, null, "Examples"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { style: { fontWeight: 'bold' }, colItems: [
                        { Content: 'Raw Number', Size: 1 },
                        { Content: 'Formatted Number', Size: 1 },
                    ] }),
                React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { colItems: [
                        { Content: GeneralConstants_1.DEFAULT_DOUBLE_DISPLAY_VALUE, Size: 1 },
                        {
                            Content: FormatHelper_1.default.NumberFormatter(GeneralConstants_1.DEFAULT_DOUBLE_DISPLAY_VALUE, data.DisplayFormat.Options),
                            Size: 1,
                        },
                    ] }),
                React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { colItems: [
                        { Content: '-' + GeneralConstants_1.DEFAULT_DOUBLE_DISPLAY_VALUE, Size: 1 },
                        {
                            Content: FormatHelper_1.default.NumberFormatter(-GeneralConstants_1.DEFAULT_DOUBLE_DISPLAY_VALUE, data.DisplayFormat.Options),
                            Size: 1,
                        },
                    ] }),
                React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { colItems: [
                        { Content: '0.123', Size: 1 },
                        {
                            Content: FormatHelper_1.default.NumberFormatter(0.123, data.DisplayFormat.Options),
                            Size: 1,
                        },
                    ] })))));
};
const renderStringFormat = (data, _onChange, setFormatOption, scopedCustomFormatters, api) => {
    if (data.DisplayFormat.Formatter !== 'StringFormatter') {
        return null;
    }
    const showDocumentationLinks = api.internalApi.isDocumentationLinksDisplayed();
    return (React.createElement(rebass_1.Box, { "data-name": 'format-column-display-format', padding: 2 },
        React.createElement(Tabs_1.Tabs, null,
            React.createElement(Tabs_1.Tabs.Tab, null, "Format"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(rebass_1.Flex, { flexDirection: "column" },
                    React.createElement(FormLayout_1.default, { mr: 3 },
                        React.createElement(FormLayout_1.FormRow, { label: "Case:" },
                            React.createElement(rebass_1.Flex, null,
                                React.createElement(Toggle_1.ToggleGroup, null,
                                    React.createElement(Toggle_1.Toggle, { pressed: data.DisplayFormat.Options.Case === 'Upper', onPressedChange: (pressed) => setFormatOption('Case', pressed ? 'Upper' : undefined), icon: "case-upper" }),
                                    React.createElement(Toggle_1.Toggle, { pressed: data.DisplayFormat.Options.Case === 'Lower', onPressedChange: (pressed) => setFormatOption('Case', pressed ? 'Lower' : undefined), icon: "case-lower" }),
                                    React.createElement(Toggle_1.Toggle, { pressed: data.DisplayFormat.Options.Case === 'Sentence', onPressedChange: (pressed) => setFormatOption('Case', pressed ? 'Sentence' : undefined), icon: "case-sentence" })),
                                React.createElement(CheckBox_1.CheckBox, { "data-name": "trim-checkbox", marginLeft: 5, checked: data.DisplayFormat.Options.Trim, onChange: (checked) => setFormatOption('Trim', checked) }, "Trim"))),
                        React.createElement(FormLayout_1.FormRow, { label: "Prefix" },
                            React.createElement(Input_1.default, { "data-name": "prefix", value: data.DisplayFormat.Options.Prefix ?? '', onChange: (e) => setFormatOption('Prefix', e.currentTarget.value) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Suffix" },
                            React.createElement(Input_1.default, { "data-name": "suffix", value: data.DisplayFormat.Options.Suffix ?? '', onChange: (e) => setFormatOption('Suffix', e.currentTarget.value) })),
                        React.createElement(FormLayout_1.FormRow, { label: "Content" },
                            React.createElement(Textarea_1.default, { minWidth: 300, rows: 3, placeholder: "", marginTop: 2, type: 'text', autoFocus: false, value: data.DisplayFormat.Options.Content ?? '', onChange: (e) => setFormatOption('Content', e.currentTarget.value) }),
                            showDocumentationLinks && (React.createElement(HelpBlock_1.default, { "data-name": "query-documentation", mt: 3, mb: 2, style: {
                                    fontSize: 'var(--ab-font-size-3)',
                                    padding: 0,
                                } },
                                React.createElement(ButtonInfo_1.ButtonInfo, { mr: 2, onClick: () => window.open(DocumentationLinkConstants_1.FormatColumnPlaceholderDocsLink, '_blank') }),
                                "See how to create dynamic Display Format using placeholders"))),
                        React.createElement(FormLayout_1.FormRow, { label: "Empty" },
                            React.createElement(CheckBox_1.CheckBox, { "data-name": "empty-checkbox", checked: data.DisplayFormat.Options.Empty, onChange: (checked) => setFormatOption('Empty', checked) })))))),
        scopedCustomFormatters.length > 0 && (React.createElement(Tabs_1.Tabs, { marginTop: 2, keyboardNavigation: false },
            React.createElement(Tabs_1.Tabs.Tab, null, "Custom Formats"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(rebass_1.Flex, { flexDirection: "column" },
                    React.createElement(FormLayout_1.default, { mr: 3 }, scopedCustomFormatters.map((formatter) => renderCustomFormatter(data, formatter, setFormatOption))))))),
        React.createElement(Tabs_1.Tabs, { marginTop: 2, keyboardNavigation: false },
            React.createElement(Tabs_1.Tabs.Tab, null, "Example"),
            React.createElement(Tabs_1.Tabs.Content, null,
                React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { style: { fontWeight: 'bold' }, colItems: [
                        { Content: 'Raw String', Size: 1 },
                        { Content: 'Formatted String', Size: 1 },
                    ] }),
                React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { colItems: [
                        { Content: '"' + GeneralConstants_1.DEFAULT_STRING_DISPLAY_VALUE + '"', Size: 1 },
                        {
                            Content: '"' +
                                FormatHelper_1.default.StringFormatter(GeneralConstants_1.DEFAULT_STRING_DISPLAY_VALUE, data.DisplayFormat.Options) +
                                '"',
                            Size: 1,
                        },
                    ] })))));
};
const FormatColumnFormatWizardSection = (props) => {
    const { data } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const formatColumnApi = adaptable.api.formatColumnApi;
    const customDisplayFormatters = adaptable.api.optionsApi.getFormatColumnOptions().customDisplayFormatters ?? [];
    const update = (updated) => {
        props.onChange({ ...data, ...updated });
    };
    const setFormatOption = (key, value) => {
        const DisplayFormat = { ...data.DisplayFormat };
        // @ts-ignore
        DisplayFormat.Options = { ...DisplayFormat.Options, [key]: value };
        update({ DisplayFormat });
    };
    const Type = data.DisplayFormat && data.DisplayFormat.Formatter;
    const customScopedFormatters = customDisplayFormatters.filter((displayFormatter) => adaptable.api.columnScopeApi.isScopeInScope(data.Scope, displayFormatter.scope));
    if (Type === 'NumberFormatter') {
        return renderNumberFormat(data, update, setFormatOption, customScopedFormatters, adaptable.api);
    }
    if (Type === 'DateFormatter') {
        return renderDateFormat(data, update, setFormatOption, customScopedFormatters);
    }
    if (Type === 'StringFormatter') {
        return renderStringFormat(data, update, setFormatOption, customScopedFormatters, adaptable.api);
    }
    return (React.createElement(HelpBlock_1.default, { margin: 3 },
        "Setting a Display Format is only possible if ",
        React.createElement("b", null, "all"),
        " the columns in Scope are Numeric, String or Date"));
};
exports.FormatColumnFormatWizardSection = FormatColumnFormatWizardSection;
