"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSegmentDimensions = useSegmentDimensions;
const streamplace_1 = require("streamplace");
const livestream_store_1 = require("../livestream-store");
const video_store_1 = require("../video-store");
function useSegmentDimensions() {
    const video = (0, video_store_1.useVideoStoreOptional)((x) => x.video);
    const latestSegment = (0, livestream_store_1.useLivestreamStoreOptional)((x) => x.segment);
    let height = 0;
    let width = 0;
    if (video) {
        const meta = getVideoMetadata(video);
        if (meta) {
            height = meta.height || 0;
            width = meta.width || 0;
        }
    }
    else {
        let seg = latestSegment?.video && latestSegment.video[0];
        height = seg?.height || 0;
        width = seg?.width || 0;
    }
    return {
        isPlayerRatioGreater: width > height,
        height: height,
        width: width,
    };
}
function getVideoMetadata(view) {
    if (!view.tracks) {
        return null;
    }
    for (const track of view.tracks) {
        const meta = track.record.metadata;
        if (!streamplace_1.PlaceStreamMediaTrack.isCommonMetadata(meta)) {
            continue;
        }
        if (!meta.video) {
            continue;
        }
        return meta.video;
    }
    return null;
}
//# sourceMappingURL=useSegmentDimensions.js.map