"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportColumnsWizardSection = exports.renderReportColumnsSummary = exports.isValidReportColumnsScope = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const Radio_1 = tslib_1.__importDefault(require("../../../components/Radio"));
const Tabs_1 = require("../../../components/Tabs");
const NewScopeComponent_1 = require("../../Components/NewScopeComponent");
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const Flex_1 = require("../../../components/Flex");
const isValidReportColumnsScope = (report) => {
    if (report.ReportColumnScope === 'ScopeColumns') {
        return report.Scope != null ? true : 'Column scope is not defined';
    }
    return true;
};
exports.isValidReportColumnsScope = isValidReportColumnsScope;
const renderReportColumnsSummary = (report) => {
    return (React.createElement(Flex_1.Box, { className: "twa:text-2" },
        report.ReportColumnScope === 'AllColumns' ? (React.createElement(React.Fragment, null,
            "Include ",
            React.createElement("b", null, "all Columns"),
            " in the Report")) : null,
        report.ReportColumnScope === 'VisibleColumns' ? (React.createElement(React.Fragment, null,
            "Include ",
            React.createElement("b", null, "only visible Columns"),
            " in the Report")) : null,
        report.ReportColumnScope === 'ScopeColumns' ? (React.createElement(React.Fragment, null, (0, NewScopeComponent_1.renderScopeSummary)(report.Scope, {
            scopeColumns: 'Report Columns',
            scopeWholeRow: 'not available',
            scopeDataTypes: 'Report will include columns with the following types',
        }))) : null));
};
exports.renderReportColumnsSummary = renderReportColumnsSummary;
const ReportColumnsWizardSection = (props) => {
    const { api, data } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    return (React.createElement(Flex_1.Flex, { flexDirection: "column", className: "twa:h-full" },
        React.createElement(Tabs_1.Tabs, { className: "twa:m-2", value: data.ReportColumnScope, onValueChange: (ReportColumnScope) => {
                const report = {
                    ...data,
                    ReportColumnScope,
                };
                if (report.ReportColumnScope !== 'ScopeColumns') {
                    delete report.Scope;
                }
                else {
                    if (!report.Scope) {
                        report.Scope = {
                            ColumnIds: [],
                        };
                    }
                }
                props.onChange(report);
            } },
            React.createElement(Tabs_1.Tabs.Tab, { value: "AllColumns" },
                React.createElement(Radio_1.default, { className: "twa:m-0", checked: data.ReportColumnScope == 'AllColumns', tabIndex: -1 }, "All Columns")),
            React.createElement(Tabs_1.Tabs.Tab, { value: "VisibleColumns" },
                React.createElement(Radio_1.default, { className: "twa:m-0", checked: data.ReportColumnScope == 'VisibleColumns', tabIndex: -1 }, "Visible Columns")),
            React.createElement(Tabs_1.Tabs.Tab, { value: "ScopeColumns" },
                React.createElement(Radio_1.default, { className: "twa:m-0", checked: data.ReportColumnScope == 'ScopeColumns', tabIndex: -1 }, "Bespoke Columns")),
            React.createElement(Tabs_1.Tabs.Content, { value: "AllColumns" },
                React.createElement(Flex_1.Box, { className: "twa:p-2 twa:text-2" }, "All Columns in the datasource will be included in the Report, whether visible or not at time of export")),
            React.createElement(Tabs_1.Tabs.Content, { value: "VisibleColumns" },
                React.createElement(Flex_1.Box, { className: "twa:p-2 twa:text-2" }, "Only Columns that are visible at the time the Report is exported will be included")),
            React.createElement(Tabs_1.Tabs.Content, { value: "BespokeColumns" },
                React.createElement(Flex_1.Box, { className: "twa:p-2 twa:text-2" }, "Only selected Columns (which you will choose in the next step) will be exported - whether visible or not"))),
        data.ReportColumnScope === 'ScopeColumns' ? (React.createElement(Flex_1.Box, { className: "twa:p-2 twa:flex-1 twa:overflow-auto" },
            React.createElement(NewScopeComponent_1.NewScopeComponent, { hideWholeRow: true, isColumnAvailable: (column) => Boolean(column.exportable), descriptions: {
                    rowScope: 'Apply Scope for: Row, or one or more Columns, or one or more Data Types',
                    columnScope: 'Selected columns will be included in the report',
                }, scope: data.Scope, updateScope: (Scope) => {
                    const report = { ...data, Scope };
                    props.onChange(report);
                } }))) : null));
};
exports.ReportColumnsWizardSection = ReportColumnsWizardSection;
