import { scaleToVec3 } from '@hiberworld/code-kit';
import { addTo, getGroup, getImage, getPrefab, pop3, getRandomSeed, _u } from '.';
const frames = [
    {
        id: 'simplegoldenframe_01',
        p: [0, 1, 0.03],
        s: [3, 1.9, 20],
        offset: 0.045,
    },
    {
        id: 'stoneframe_01',
        p: [0, 1, 0.03],
        s: [0.87 * 4, 0.54 * 4, 10],
        offset: 0.07,
    },
    {
        id: 'modernframe_01',
        p: [0, 1, 0.03],
        s: [0.57 * 4, 1.04 * 4, 20],
        offset: 0.045,
    },
];
/**
 * Get a flat surface with an image placed within a frame.
 * _frame_ property equals:
 * 0 = Golden frame
 * 1 = Stone frame
 * 2 = Modern frame
 * -1 = random
 * @example
 * ```
const img = getFramedImage({
  src: 'https://cdn.hibervr.com/demo/img/Lunch.jpg',
  ratio: 1000 / 750,
  frame: 0,
  p: [0, 1, 0],
  s: pop3(1),
});
addTo(root, img);
 * ```
 */
export const getFramedImage = (opt) => {
    const val = {
        src: opt.src,
        ratio: opt.ratio ?? 1,
        frame: opt?.frame ?? 0,
        backside: opt?.backside ?? true,
        children: [],
        p: opt.p ?? [0, 0, 0],
        r: opt.r ?? [0, 0, 0],
        s: opt.s ?? pop3(2),
    };
    const currentFrames = _u.isNumeric(val.frame) && val.frame > -1 ? frames[val.frame] : getRandomSeed(opt.seed).randomFromArray(frames);
    const sx = scaleToVec3(opt?.s)?.[0] ?? 1;
    let ratio = val?.ratio ?? 1;
    const wrapper = getGroup({
        p: [val.p[0], val.p[1] + currentFrames.offset * sx, val.p[2]],
        r: val.r,
        seed: opt.seed,
        name: 'wrapper',
    });
    const pic = getImage({
        src: val.src,
        p: [0, 0, -0.2],
        s: val.s,
        ratio,
    });
    if (val.backside) {
        const bg = getPrefab({
            id: 'cube_03',
            name: 'back',
            p: [0, 0, 0.1],
            s: [ratio * sx * 4, 4 * sx, 0.3],
            material: 'palette_01_white',
        });
        addTo(wrapper, bg);
    }
    const frame = getPrefab({
        id: currentFrames.id,
        name: 'frame',
        p: [currentFrames.p[0] * sx, currentFrames.p[1] * sx, currentFrames.p[2] * sx],
        s: [ratio * sx * currentFrames.s[0], 1 * sx * currentFrames.s[1], 0.3 * currentFrames.s[2]],
        r: [0, 180, 0],
    });
    addTo(wrapper, [frame, pic]);
    return wrapper;
};
//# sourceMappingURL=getFramedImage.js.map