import { addTo, getGroup, getImage, addInteractiveMediaAsset, findChildren, getPrefab, getTextSign, getVideoPlayer, } from '.';
/**
 * Convenient way to create a web page links
 * src can be both image or video url
 * if src is omitted and text is provided, a text sign will be created
 * @example
 * ```ts
  const wp = getWebPageLinker({
    p: [0, 0.5, 5],
    s: [2, 2, 2],
    src: 'https://cdn.hibervr.com/demo/img/gold.jpg',
    ratio: 1000 / 563,
    pageName: 'Hiber.mv',
    pageDesc: 'Visit out web site for more information',
    url: 'https://hiber.mv/',
  });
  addTo(root, wp);

  // Or with text

  const wp = getWebPageLinker({
    p: [0, 0.5, 5],
    text: 'Hiber.mv',
    pageName: 'Hiber.mv',
    pageDesc: 'Visit out web site for more information',
    url: 'https://hiber.mv/',
  });
  addTo(root, wp);

 * ```
 */
export const getWebPageLinker = (options = {}) => {
    const movieUrlRegex = /(\.mp4$|\.webm$)/i;
    let { pageName = 'Hiber.mv', pageDesc = '', url = 'https://hiber.mv/', width = 2, src = undefined, ratio = undefined, text = undefined, musicId = undefined, backside = false, backsideMaterial = 'palette_01_white', backsideImage = undefined, } = options;
    let imaTarget;
    if (text) {
        const textSignGroup = getTextSign({ text: text });
        // You can't add interactive media asset to a group, so we need to find the textSign object
        imaTarget = findChildren('textSign', textSignGroup);
    }
    else {
        src = src || 'https://cdn.hibervr.com/demo/img/gold.jpg';
        const match = src.match(movieUrlRegex);
        if (match) {
            ratio = ratio || 16 / 9;
            imaTarget = getVideoPlayer({
                src: src,
                ratio,
                width,
            });
        }
        else {
            ratio = ratio || 1000 / 563;
            imaTarget = getImage({
                src: src,
                ratio,
            });
        }
    }
    if (!imaTarget) {
        return;
    }
    const wrapper = getGroup(options);
    if (backside) {
        if (backsideImage) {
            addTo(imaTarget, getImage({
                src: backsideImage,
                p: [0, 0, 20],
            }));
        }
        else {
            addTo(imaTarget, getPrefab({ p: [0, 0, 20], s: [1, 1, 10], material: backsideMaterial }));
        }
    }
    addInteractiveMediaAsset(imaTarget, {
        header: pageName,
        preBody: pageDesc,
        url,
        musicId,
    });
    addTo(wrapper, imaTarget);
    return wrapper;
};
//# sourceMappingURL=getWebPageLinker.js.map