import { Accordion, Box, Button, FieldGroup, Skeleton } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import React, { useMemo } from 'react';
import {
useEditableSettings,
useEditableSettingsDispatch,
} from '../../contexts/EditableSettingsContext';
import { useTranslation } from '../../contexts/TranslationContext';
import { Setting } from './Setting';
export function Section({ children, groupId, hasReset = true, help, sectionName, solo }) {
const editableSettings = useEditableSettings(useMemo(() => ({
group: groupId,
section: sectionName,
}), [groupId, sectionName]));
const changed = useMemo(
() => editableSettings.some(({ changed }) => changed),
[editableSettings],
);
const canReset = useMemo(
() => editableSettings.some(({ value, packageValue }) => JSON.stringify(value) !== JSON.stringify(packageValue)),
[editableSettings],
);
const dispatch = useEditableSettingsDispatch();
const reset = useMutableCallback(() => {
dispatch(
editableSettings
.filter(({ disabled }) => !disabled)
.map(({ _id, value, packageValue, editor, packageEditor }) => ({
_id,
value: packageValue,
editor: packageEditor,
changed:
JSON.stringify(value) !== JSON.stringify(packageValue)
|| JSON.stringify(editor) !== JSON.stringify(packageEditor),
})),
);
});
const t = useTranslation();
const handleResetSectionClick = () => {
reset();
};
return
{help && {help}}
{editableSettings.map((setting) => )}
{children}
{hasReset && canReset && }
;
}
export function SectionSkeleton() {
return }>
{Array.from({ length: 10 }).map((_, i) => )}
;
}
Section.Skeleton = SectionSkeleton;