var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
import { useDomRect } from "powerhooks/useDomRect";
import { useEffect, useState } from "react";
import { useStateRef } from "powerhooks/useStateRef";
export function useMediaAspectRatio(params) {
    var _a;
    var internallyCreateRef = useStateRef(null);
    var ref = (_a = params === null || params === void 0 ? void 0 : params.ref) !== null && _a !== void 0 ? _a : internallyCreateRef;
    var _b = useDomRect({ ref: ref }).domRect, width = _b.width, height = _b.height;
    var _c = __read(useState(undefined), 2), aspectRatio = _c[0], setAspectRatio = _c[1];
    useEffect(function () {
        if (aspectRatio !== undefined && !isNaN(aspectRatio)) {
            return;
        }
        setAspectRatio(width / height);
    }, [width, height]);
    return {
        "aspectRatio": aspectRatio === undefined ? NaN : aspectRatio,
        ref: ref,
    };
}
//# sourceMappingURL=useMediaAspectRatio.js.map