"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleLinkChange = exports.handleWindowChange = exports.handleDropComponent = exports.handleCopyComponent = exports.handleRemoveComponent = exports.handleUpdateComponent = exports.handleSelectComponent = exports.handleChange = exports.handleInit = exports.framePoster = exports.poster = void 0;
const ACTIONS = __importStar(require("./actions"));
/**
 * poster
 * @param type action
 * @param data data info
 */
const poster = (type, data, frame = window.parent) => {
    // console.log('---------------poster', type);
    // console.log(data);
    frame.postMessage({
        data,
        type,
    }, '*');
};
exports.poster = poster;
/**
 * iframe poster
 * @param type
 * @param data
 */
const framePoster = (type, data) => {
    var _a;
    // @ts-ignore
    const frameWin = (_a = document.getElementById('main-view')) === null || _a === void 0 ? void 0 : _a.contentWindow;
    if (frameWin) {
        (0, exports.poster)(type, data, frameWin);
    }
};
exports.framePoster = framePoster;
/**
 * init data
 * @param data init data
 */
const handleInit = (data) => {
    (0, exports.framePoster)(ACTIONS.INIT, data);
};
exports.handleInit = handleInit;
/**
 * change data
 * @param data changed data
 */
const handleChange = (data) => {
    (0, exports.framePoster)(ACTIONS.CHANGE, data);
};
exports.handleChange = handleChange;
/**
 * select component handler
 * @param component selected component(structure node)
 */
const handleSelectComponent = (component) => {
    (0, exports.poster)(ACTIONS.SELECT_COMPONENT, component);
};
exports.handleSelectComponent = handleSelectComponent;
/**
 * update component handler
 * @param component new update component
 */
const handleUpdateComponent = (component) => {
    (0, exports.poster)(ACTIONS.UPDATE_COMPONENT, component);
};
exports.handleUpdateComponent = handleUpdateComponent;
/**
 * remove component handler
 * @param component component info
 */
const handleRemoveComponent = (component) => {
    (0, exports.poster)(ACTIONS.REMOVE_COMPONENT, component);
};
exports.handleRemoveComponent = handleRemoveComponent;
/**
 * copy component handler
 * @param component component info
 */
const handleCopyComponent = (component) => {
    (0, exports.poster)(ACTIONS.COPY_COMPONENT, component);
};
exports.handleCopyComponent = handleCopyComponent;
/**
 * drop component handler
 * @param dndInfo dnd info
 */
const handleDropComponent = (dndInfo) => {
    (0, exports.poster)(ACTIONS.DROP_COMPONENT, dndInfo);
};
exports.handleDropComponent = handleDropComponent;
/**
 * bind condition handler
 * @param target window target
 * @param opt options
 */
const handleWindowChange = (target, opt) => {
    (0, exports.poster)(ACTIONS.WINDOW_CHANGE, { target, opt });
};
exports.handleWindowChange = handleWindowChange;
/**
 * handle link jump
 * for iframe emit root to link jump
 * @param target jump target
 * @param opt
 */
const handleLinkChange = (target, opt) => {
    (0, exports.poster)(ACTIONS.LINK_JUMP, { target, opt });
};
exports.handleLinkChange = handleLinkChange;
