import Bind from "@web-atoms/core/dist/core/Bind";
import XNode from "@web-atoms/core/dist/core/XNode";
import { AtomControl } from "@web-atoms/core/dist/web/controls/AtomControl";
import { AtomStyle } from "@web-atoms/core/dist/web/styles/AtomStyle";
import { IStyleDeclaration } from "@web-atoms/core/dist/web/styles/IStyleDeclaration";

class FileViewerStyle extends AtomStyle {
    public get root(): IStyleDeclaration {
        return {
            position: "absolute",
            width: "100%",
            height: "100%",
            margin: 0,
            padding: 0,
            overflow: "hidden",
            border: "none"
        };
    }
}

export default class FileViewer extends AtomControl {

    public url: string;

    constructor(app, e) {
        super(app, e || document.createElement("iframe"));
    }

    public create() {
        this.defaultControlStyle = FileViewerStyle;
        this.url = null;
        this.render(<iframe
            class={this.controlStyle.name}
            src={Bind.oneWay(() => this.url || "about:none")}
            />);
    }
}
