import { Class } from '@ephox/sugar';
const updateAriaState = (component, toggleConfig, toggleState) => {
    const ariaInfo = toggleConfig.aria;
    ariaInfo.update(component, ariaInfo, toggleState.get());
};
const updateClass = (component, toggleConfig, toggleState) => {
    toggleConfig.toggleClass.each((toggleClass) => {
        if (toggleState.get()) {
            Class.add(component.element, toggleClass);
        }
        else {
            Class.remove(component.element, toggleClass);
        }
    });
};
const set = (component, toggleConfig, toggleState, state) => {
    const initialState = toggleState.get();
    toggleState.set(state);
    updateClass(component, toggleConfig, toggleState);
    updateAriaState(component, toggleConfig, toggleState);
    if (initialState !== state) {
        toggleConfig.onToggled(component, state);
    }
};
const toggle = (component, toggleConfig, toggleState) => {
    set(component, toggleConfig, toggleState, !toggleState.get());
};
const on = (component, toggleConfig, toggleState) => {
    set(component, toggleConfig, toggleState, true);
};
const off = (component, toggleConfig, toggleState) => {
    set(component, toggleConfig, toggleState, false);
};
const isOn = (component, toggleConfig, toggleState) => toggleState.get();
const onLoad = (component, toggleConfig, toggleState) => {
    // There used to be a bit of code in here that would only overwrite
    // the attribute if it didn't have a current value. I can't remember
    // what case that was for, so I'm removing it until it is required.
    set(component, toggleConfig, toggleState, toggleConfig.selected);
};
export { onLoad, toggle, isOn, on, off, set };
//# sourceMappingURL=ToggleApis.js.map