import { Arr } from '@ephox/katamari';
import { Attribute, Class, SugarNode } from '@ephox/sugar';
// Just use "disabled" attribute for these, not "aria-disabled"
const nativeDisabled = [
    'input',
    'button',
    'textarea',
    'select'
];
const onLoad = (component, disableConfig, disableState) => {
    const f = disableConfig.disabled() ? disable : enable;
    f(component, disableConfig, disableState);
};
const hasNative = (component, config) => config.useNative === true && Arr.contains(nativeDisabled, SugarNode.name(component.element));
const nativeIsDisabled = (component) => Attribute.has(component.element, 'disabled');
const nativeDisable = (component) => {
    Attribute.set(component.element, 'disabled', 'disabled');
};
const nativeEnable = (component) => {
    Attribute.remove(component.element, 'disabled');
};
const ariaIsDisabled = (component) => Attribute.get(component.element, 'aria-disabled') === 'true';
const ariaDisable = (component) => {
    Attribute.set(component.element, 'aria-disabled', 'true');
};
const ariaEnable = (component) => {
    Attribute.set(component.element, 'aria-disabled', 'false');
};
const disable = (component, disableConfig, _disableState) => {
    disableConfig.disableClass.each((disableClass) => {
        Class.add(component.element, disableClass);
    });
    const f = hasNative(component, disableConfig) ? nativeDisable : ariaDisable;
    f(component);
    disableConfig.onDisabled(component);
};
const enable = (component, disableConfig, _disableState) => {
    disableConfig.disableClass.each((disableClass) => {
        Class.remove(component.element, disableClass);
    });
    const f = hasNative(component, disableConfig) ? nativeEnable : ariaEnable;
    f(component);
    disableConfig.onEnabled(component);
};
const isDisabled = (component, disableConfig) => hasNative(component, disableConfig) ? nativeIsDisabled(component) : ariaIsDisabled(component);
const set = (component, disableConfig, disableState, disabled) => {
    const f = disabled ? disable : enable;
    f(component, disableConfig, disableState);
};
export { enable, disable, isDisabled, onLoad, set };
//# sourceMappingURL=DisableApis.js.map