"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormGroup = void 0;
const react_1 = __importStar(require("react"));
const hooks_1 = require("../../hooks");
const utils_1 = require("./utils");
const Grid_1 = require("./Grid");
const Column_1 = require("./Column");
const FormGroup = ({ onChange, config = [], style, alwaysAccept, values, confirmationLabel, confirmationVariant, variant = 'column', autoFocus, labelWidth = 160, fieldWidth = 185, }) => {
    const valuesChanged = (0, react_1.useRef)({});
    const { width } = (0, hooks_1.useWindowResize)();
    const [hasChanges, setChanges] = (0, react_1.useState)(false);
    const update = (0, hooks_1.useUpdate)();
    const onChangeField = (field, value) => {
        if (alwaysAccept) {
            const newV = {};
            (0, utils_1.setValue)(field, newV, value);
            onChange(newV);
        }
        else {
            setChanges(true);
            (0, utils_1.setValue)(field, valuesChanged.current, value);
            if (values && (0, utils_1.equalChanges)(valuesChanged.current, values)) {
                console.log('asdasdas');
                setChanges(false);
            }
            else {
                update();
            }
        }
    };
    const parsedData = (0, utils_1.parseData)(config);
    if (variant === 'grid' && width >= 480) {
        return (react_1.default.createElement(Grid_1.FormGroupGrid, { autoFocus: autoFocus, onChange: onChange, confirmationVariant: confirmationVariant, confirmationLabel: confirmationLabel, parsedData: parsedData, labelWidth: labelWidth, fieldWidth: fieldWidth, onChangeField: onChangeField, style: style, hasChanges: hasChanges, valuesChanged: valuesChanged, values: values, setChanges: setChanges, alwaysAccept: alwaysAccept }));
    }
    return (react_1.default.createElement(Column_1.FormGroupColumn, { confirmationLabel: confirmationLabel, confirmationVariant: confirmationVariant, autoFocus: autoFocus, onChange: onChange, parsedData: parsedData, labelWidth: labelWidth, fieldWidth: fieldWidth, onChangeField: onChangeField, style: style, hasChanges: hasChanges, valuesChanged: valuesChanged, values: values, setChanges: setChanges, alwaysAccept: alwaysAccept }));
};
exports.FormGroup = FormGroup;
//# sourceMappingURL=index.js.map