/**
 * @since Last modified: 2024-01-18 16:17:08
 * @function heightEase
 * @description The element height changes smoothly.
 * @param {object} options  - The parameters of slide down.
 * @param {getEl} [options.elem]  - The target node.The writing is the same as getEl.
 * @param {number} [options.height]  - The height value of the setting element can be a specific value, and if it is not set, it is the height of the element itself.
 * @param {curves} [options.curve=easeOut]  - Animation curve.Can be filled in:'linear'|'ease'|'easeIn'|'easeOut'|'easeInOut'|'easeOutIn'.
 * @param {boolean} [options.cut=true]  - Forced overflow truncation,means to add the style attribute of the element:"overflow:hidden".
 * @param {number} [options.duration]  - The duration of slide down.The unit is ms.The default is automatically calculated by the element height.
 * @param {function} [options.doing]  - The call back in progress.Support parameters:"frame" and "step",That is the current animation frame and height.
 * @param {function} [options.done]  - The call back after completion.Support parameters:"frame" and "step",That is the current animation frame and height(orign height).
 * @returns {*} - The the target dom.
 * @see {@link https://codepen.io/axui/pen/xxMBWKz|demo @ codepen}
 * @example
 * ax.heightEase({elem:'#demo'});
 * <!--return the target dom-->
 */
'use strict';
import getEl from "./getEl";
import getHeights from "./getHeights";
import elState from "./elState";
import ease from "./ease";
let heightEase = ({ elem, height, type = 'down', doing, done, duration, curve = 'easeOut', cut = true }) => {
    let target = getEl(elem);
    if (!target) {
        throw new Error('The target node does not exist!');
    }
    if (elState(target).isCalc) {
        let dftTime = (height) => height / 3 + 250, rawStyle = target.style.cssText, size = getHeights(target).height, _height = ~~height && height !== 0 ? ~~height : size, time = ~~duration && duration !== 0 ? ~~duration : dftTime(_height), dftCss = `${rawStyle} ${cut ? 'overflow:hidden;' : ''};`, from = {}, to = {};
        target.style.cssText = `${dftCss}`;
        if (type === 'to' && ~~height) {
            from = { height: size };
            to = { height };
        }
        else if (type === 'up') {
            from = { height: 0 };
            to = { height: _height };
        }
        else {
            from = { height: _height };
            to = { height: 0 };
        }
        ease({
            from,
            to,
            duration: time,
            curve,
            doing: (e) => {
                target.style.cssText = `
                ${dftCss}
                height: ${e.value.height}px
                `;
                doing && doing.call(target, { frame: e.frame, height: e.value.height, step: e.step });
            }, done: (e) => {
                target.style.cssText = dftCss;
                done && done.call(target, { frame: e.frame, height: e.value.height, step: e.step });
            }
        });
    }
    return target;
};
export default heightEase;
