"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderFormatColumnStyleSummary = exports.renderFormatColumnStyleWizardSummary = exports.isFormatColumnStyleValid = void 0;
exports.FormatColumnStyleWizardSection = FormatColumnStyleWizardSection;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const StyleHelper_1 = require("../../../Utilities/Helpers/StyleHelper");
const StyleComponent_1 = require("../../Components/StyleComponent");
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const UIHelper_1 = tslib_1.__importDefault(require("../../UIHelper"));
const Flex_1 = require("../../../components/Flex");
const isFormatColumnStyleValid = (data, api) => {
    if (data.Style &&
        UIHelper_1.default.IsEmptyStyle(data.Style) &&
        data.DisplayFormat === undefined &&
        !api.columnScopeApi.isSingleBooleanColumnScope(data.Scope)) {
        return 'No format applied';
    }
    return true;
};
exports.isFormatColumnStyleValid = isFormatColumnStyleValid;
const toStyle = (data) => {
    return {
        ...(0, StyleHelper_1.convertAdaptableStyleToCSS)(data.Style ?? {}),
        borderWidth: data.Style?.BorderColor ? 2 : 0,
        borderStyle: 'solid',
        // ToDO abcdefg
        textAlign: data.Style?.Alignment ? data.Style.Alignment.toLowerCase() : undefined,
    };
};
const renderFormatColumnStyleWizardSummary = (data) => {
    const { api } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    return (0, exports.renderFormatColumnStyleSummary)(data, api);
};
exports.renderFormatColumnStyleWizardSummary = renderFormatColumnStyleWizardSummary;
const renderFormatColumnStyleSummary = (data, api) => {
    return (React.createElement(Flex_1.Box, { className: "ab-FormatPreview twa:p-2", style: toStyle(data) }, "Preview result"));
};
exports.renderFormatColumnStyleSummary = renderFormatColumnStyleSummary;
function FormatColumnStyleWizardSection(props) {
    const { data, api } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    return (React.createElement(StyleComponent_1.StyleComponent, { headless: true, api: api, Style: data.Style ?? {}, UpdateStyle: (Style) => {
            props.onChange({ ...data, Style });
        } }));
}
