/*
    Парус 8 - Панели мониторинга - Редакторы панелей
    Общие ресурсы компонента "Редактор условия"
*/

//---------------------
//Подключение библиотек
//---------------------

import PropTypes from "prop-types"; //Контроль свойств компонента

//---------
//Константы
//---------

//Доступные операторы условия
const P8P_CC_OPERATORS = [
    { name: "==", value: "equal" },
    { name: "!=", value: "notEqual" },
    { name: "<=", value: "lessEqual" },
    { name: "<", value: "less" },
    { name: ">=", value: "greaterEqual" },
    { name: ">", value: "greater" },
    { name: "in", value: "in" }
];

//Структура параметра поля условия
const P8P_CC_FIELD_PRM_SHAPE = PropTypes.shape({
    name: PropTypes.string.isRequired,
    value: PropTypes.string.isRequired,
    hasElement: PropTypes.bool,
    icon: PropTypes.string
});

//Структура поля условия
const P8P_CC_FIELD_SHAPE = PropTypes.shape({
    name: PropTypes.string.isRequired,
    value: PropTypes.string.isRequired
});

//Структура оператора условия
const P8P_CC_OPERATOR_SHAPE = PropTypes.shape({
    name: PropTypes.string.isRequired,
    value: PropTypes.string.isRequired
});

//Структура условия
const P8P_CC_SHAPE = PropTypes.shape({
    condField: P8P_CC_FIELD_SHAPE.isRequired,
    condOperator: P8P_CC_OPERATOR_SHAPE.isRequired,
    condElement: PropTypes.string, //Пока
    condValue: PropTypes.string.isRequired,
    resField: P8P_CC_FIELD_SHAPE.isRequired,
    resElement: PropTypes.string, //Пока
    resValue: PropTypes.string.isRequired
});

//Начальное состояние поля условия
const P8P_CC_FIELD_INITIAL = {
    name: "",
    value: ""
};

//Начальное состояние условия
const P8P_CC_INITIAL = {
    condField: { ...P8P_CC_FIELD_INITIAL },
    condOperator: { ...P8P_CC_OPERATORS[0] },
    condElement: "",
    condValue: "",
    resField: { ...P8P_CC_FIELD_INITIAL },
    resElement: "",
    resValue: ""
};

//Начальное состояние условий
const P8P_CCS_INITIAL = [];

//----------------
//Интерфейс модуля
//----------------

export { P8P_CC_OPERATORS, P8P_CC_FIELD_PRM_SHAPE, P8P_CC_FIELD_SHAPE, P8P_CC_SHAPE, P8P_CC_INITIAL, P8P_CCS_INITIAL };
