/**
 * @since Last modified: 2024-07-20 16:03:41
 * @function fadeToggle
 * @description Toggle fadeIn and fadeOut.
 * @param {object} options  - The parameters of fade.
 * @param {getEl} [options.el]  - The target node.The writing is the same as getEl.
 * @param {string} [options.display=block]  - The display of box.Can be filled in:'block'|'flex'|'inline-flex'|'inline-block'|'grid'.
 * @param {curve} [options.curve=easeOut]  - Animation curve.Can be filled in:'linear'|'ease'|'easeIn'|'easeOut'|'easeInOut'|'easeOutIn'.
 * @param {number} [options.duration=200]  - The duration of fade.The default is 200,the unit is ms.
 * @param {object} [options.doing]  - The cbs in progress.Properties include "in" and  "out".
 * @param {fn_cb_ease_app} [options.doing.in]  - The call back in fade in.Support parameters:"frame"(animation frame) , "step"(progress) and "value" (height).
 * @param {fn_cb_ease_app} [options.doing.out]  - The call back in fade out.Support parameters:"frame"(animation frame) , "step"(progress) and "value" (height).
 * @param {fn_cb_ease_app} [options.done]  - The call back in progress.Support parameters:"frame"(animation frame) , "step"(progress) and "value" (height).
 * @returns {*} - The the target dom.
 * @see {@link https://codepen.io/axui/pen/gOqEdxG|demo @ codepen}
 * @example
 * ax.fadeToggle({el:'#demo'});
 * <!--return the target dom-->
 */
'use strict';
import getEl from "./getEl";
import elState from "./elState";
import fadeIn from "./fadeIn";
import style from "./style";
import fadeOut from "./fadeOut";
type Options = { el: any, display?: string, done?: Function, doing?: { in: Function, out: Function }, curve?: string, duration?: number }
let fadeToggle = ({ el, display = 'block', doing, done, duration=200, curve = 'easeOut' }: Options) => {
    let target = getEl(el);
    if (!target) {
        throw new Error('The target node does not exist!');
    }
    let state = elState(target),
        opacity = parseFloat(style(target).opacity);
    if (state.isHidden) {
        fadeIn({ el: target, display, duration, curve, doing: doing?.in, done });
    } else if (state.isCalc) {
        if (opacity <= 0.5) {
            fadeIn({ el: target, display, duration, curve, doing: doing?.in, done });
        } else {
            fadeOut({ el: target,display, duration, curve, doing: doing?.out, done });
        }
    }
    return target;
}
export default fadeToggle;
