import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import styled from "styled-components";
import { XDataType } from "../../../../Common/Data/XDataType";
import { DataUtilities } from "../../../../Common/DataUtilities";
import { XValueEditor } from "../../../../CommonUI/DataEditing";
import { ObserveMultiState } from "../../../../CommonUI/StateManagement/ObserveMultiState";
import { ObserveState } from "../../../../CommonUI/StateManagement/ObserveState";
import { StateManager } from "../../../../CommonUI/StateManagement/StateManager";
import { Error } from "../../CommonUI/Error";
import { ITableRowTestValue, TableRowTestContext } from "../../Common/TableRowTestContext";
export const ValueTableResultDefaultCell = (props) => {
    const { editContext, resultColumn, ruleDefinition } = props;
    const defaultResult = ruleDefinition.getDefaultResultByColumnId(resultColumn._id);
    if (!defaultResult)
        return null;
    const onSelect = () => {
        editContext.selectedCell = defaultResult;
    };
    return (_jsx(TableRowTestContext.Consumer, { children: (value) => (_jsx(ObserveMultiState, { listenTo: [defaultResult, resultColumn], control: () => {
                return (_jsx(ObserveState, { listenTo: editContext, properties: ["selectedCell"], control: () => {
                        let selected = editContext.selectedCell === defaultResult;
                        let issues = defaultResult.validateCellData(ruleDefinition.getResultColumnType(resultColumn) ||
                            DataUtilities.createDataByType(resultColumn.dataType, resultColumn.name));
                        return (_jsxs(DefaultResultCellRender, Object.assign({ "data-testid": `column_${resultColumn._id}`, selected: selected, onClick: onSelect, testValue: value }, { children: [_jsx(XValueEditor, { forData: ruleDefinition.getResultColumnType(resultColumn) ||
                                        DataUtilities.createDataByType(resultColumn.dataType, resultColumn.name), value: defaultResult.value, mode: resultColumn.dataType === XDataType.FILE
                                        ? "display_mode_edit"
                                        : selected
                                            ? "edit_mode"
                                            : "display_mode", navigate: editContext.navigate, onUpdate: (newValue) => {
                                        defaultResult.value = newValue;
                                        StateManager.propertyChanged(defaultResult, "values");
                                        StateManager.changed(ruleDefinition);
                                    }, 
                                    // navigate={navigate}
                                    editMode: resultColumn.dataType === XDataType.FILE ? "layer" : "inline" }, void 0),
                                _jsx(Error, { issues: issues }, void 0)] }), void 0));
                    } }, void 0));
            } }, void 0)) }, void 0));
};
const DefaultResultCellRender = styled.div `
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;

    background: #fff;
    border-radius: 2px;
    position: relative;

    font-family: Inter;
    font-size: 12px;
    font-style: normal;
    font-weight: 400;
    line-height: 17px;
    letter-spacing: 0px;
    text-align: left;

    color: rgba(39, 41, 50, 0.3);

    ${(props) => (props.selected ? `border: 1px solid #3E9BDE` : `border: 1px solid #F1F1F6`)};

    .ValueEditor-root {
        width: 100%;
        padding: 6px 4px;

        .ValueEditor-display {
            padding: 6px 12px;

            ${(props) => props.testValue === ITableRowTestValue.PASSED
    ? ` color: rgba(53, 182, 135);`
    : props.testValue === ITableRowTestValue.FAILED
        ? `
                        color: rgb(238, 62, 84);
                        text-decoration: line-through;
                    `
        : ``}
        }
    }

    .edit-button {
        opacity: 0;
    }

    &:hover {
        .edit-button {
            opacity: 1;
        }
    }
`;
//# sourceMappingURL=ValueTableResultDefaultCell.js.map