<template>
    <div class="minder-editor-container">
        <div class="quickbar">
            <ETooltip placement="top" effect="light">
                <div><i class="ft icon" :title="$L('缩放')">&#xE7B3;</i></div>
                <div slot="content" class="minder-editor-slider">
                    <Slider v-model="zoom" :min="10" :max="300"></Slider>
                </div>
            </ETooltip>
            <ETooltip v-if="readOnly!==true" placement="top" effect="light">
                <div><i class="ft icon" :title="$L('图形')">&#xE621;</i></div>
                <div slot="content">
                    <ul class="minder-editor-quickul mold">
                        <li @click="execCommand('template', 'default')"><span class="default"></span></li>
                        <li @click="execCommand('template', 'structure')"><span class="structure"></span></li>
                        <li @click="execCommand('template', 'filetree')"><span class="filetree"></span></li>
                        <li @click="execCommand('template', 'right')"><span class="right"></span></li>
                        <li @click="execCommand('template', 'fish-bone')"><span class="fish-bone"></span></li>
                        <li @click="execCommand('template', 'tianpan')"><span class="tianpan"></span></li>
                    </ul>
                </div>
            </ETooltip>
            <ETooltip v-if="readOnly!==true" placement="top" effect="light">
                <div><i class="ft icon" :title="$L('样式')">&#xE678;</i></div>
                <div slot="content">
                    <ul class="minder-editor-quickul">
                        <li @click="execCommand('theme', 'fresh-blue')">{{$L('天空蓝')}}</li>
                        <li @click="execCommand('theme', 'wire')">{{$L('线框')}}</li>
                        <li @click="execCommand('theme', 'fish')">{{$L('鱼骨图')}}</li>
                        <li @click="execCommand('theme', 'classic')">{{$L('脑图经典')}}</li>
                        <li @click="execCommand('theme', 'classic-compact')">{{$L('紧凑经典')}}</li>
                        <li @click="execCommand('theme', 'snow')">{{$L('温柔冷光')}}</li>
                        <li @click="execCommand('theme', 'snow-compact')">{{$L('紧凑冷光')}}</li>
                        <li @click="execCommand('theme', 'tianpan')">{{$L('经典天盘')}}</li>
                        <li @click="execCommand('theme', 'tianpan-compact')">{{$L('紧凑天盘')}}</li>
                    </ul>
                </div>
            </ETooltip>
            <ETooltip placement="top" effect="light">
                <div><i class="ft icon" :title="$L('折叠')">&#xE779;</i></div>
                <div slot="content">
                    <ul class="minder-editor-quickul">
                        <li @click="execCommand('ExpandToLevel', 1)">{{$L('展开到一级节点')}}</li>
                        <li @click="execCommand('ExpandToLevel', 2)">{{$L('展开到二级节点')}}</li>
                        <li @click="execCommand('ExpandToLevel', 3)">{{$L('展开到三级节点')}}</li>
                        <li @click="execCommand('ExpandToLevel', 4)">{{$L('展开到四级节点')}}</li>
                        <li @click="execCommand('ExpandToLevel', 5)">{{$L('展开到五级节点')}}</li>
                        <li @click="execCommand('ExpandToLevel', 99)">{{$L('展开全部节点')}}</li>
                    </ul>
                </div>
            </ETooltip>
            <ETooltip placement="top" :content="$L('居中')">
                <div @click="execCommand('goCenter')"><i class="ft icon">&#xE61F;</i></div>
            </ETooltip>
            <ETooltip placement="top" :content="$L('移动')">
                <div @click="onHand"><i class="ft icon" :class="{active:isHand}">&#xE6CF;</i></div>
            </ETooltip>
        </div>
        <div class="minder-content">
            <IFrame ref="frame" class="minder-iframe" :src="url" @on-message="onMessage"/>
            <div v-if="loadIng" class="minder-loading"><Loading/></div>
        </div>
    </div>
</template>

<style lang="less" scoped>
    .basebtn {
        color: #fff;
        background-color: #409eff;
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        border: 1px solid #dcdfe6;
        -webkit-appearance: none;
        text-align: center;
        box-sizing: border-box;
        outline: none;
        margin: 0;
        transition: 0.1s;
        font-weight: 500;
        user-select: none;
        padding: 8px 12px;
        font-size: 14px;
        border-radius: 4px;
    }

    .baseSelect {
        height: 32px;
        option {
            min-height: 1.5em;
        }
    }

    .quickbar {
        position: fixed;
        left: 20px;
        bottom: 20px;
        height: 34px;
        border-radius: 3px;
        box-shadow: 3px 3px 10px rgba(0,0,0,.2);
        background-color: #fff;
        color: #666;
        z-index: 10;
        display: flex;
        padding: 0 6px;
        align-items: center;
        i {
            font-size: 22px;
            width: 34px;
            height: 34px;
            line-height: 34px;
            display: block;
            text-align: center;
            transform: scale(1);
            cursor: pointer;
            padding: 0;
            color: #666666;
            font-style: normal;
            &:hover {
                color: #232323;
            }
            &.active {
                color: #0285d7;
            }
        }
    }

    .minder-content {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        .minder-iframe {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: 0 0;
            border: 0;
            float: none;
            margin: -1px 0 0;
            max-width: none;
            outline: 0;
            padding: 0;
        }
        .minder-loading {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }
    }
</style>
<style lang="less">
.minder-editor-quickul {
    li {
        list-style: none;
        cursor: pointer;
        padding: 8px 0;
        &:hover {
            color: #0285d7
        }
    }
    &.mold {
        span {
            display: block;
            width: 30px;
            background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAAoCAYAAAAIXQhqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOVKFPDrYH49PSMTJvYACFUjgBCAQ5svCZwXFAADwA3l4fnSwP/wBr28AAgBw1S4kEsfh/4O6UCZXACCRAOAiEucLAZBSAMguVMgUAMgYALBTs2QKAJQAAGx5fEIiAKoNAOz0ST4FANipk9wXANiiHKkIAI0BAJkoRyQCQLsAYFWBUiwCwMIAoKxAIi4EwK4BgFm2MkcCgL0FAHaOWJAPQGAAgJlCLMwAIDgCAEMeE80DIEwDoDDSv+CpX3CFuEgBAMDLlc2XS9IzFLiV0Bp38vDg4iHiwmyxQmEXKRBmCeQinJebIxNI5wNMzgwAABr50cH+OD+Q5+bk4eZm52zv9MWi/mvwbyI+IfHf/ryMAgQAEE7P79pf5eXWA3DHAbB1v2upWwDaVgBo3/ldM9sJoFoK0Hr5i3k4/EAenqFQyDwdHAoLC+0lYqG9MOOLPv8z4W/gi372/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ExdmnaJru6+z0VimK/DJjrDTYF63mE0AQlhR0giAIgiCGLxJVAUEQBEEMf/5/AJFbIIR0qdf/AAAAAElFTkSuQmCC) no-repeat;background-size: 300px 24px;
            height: 30px;
            &.default {
                background-position: 0 3px
            }
            &.structure {
                background-position: -30px 3px
            }
            &.filetree {
                background-position: -60px 3px
            }
            &.right {
                background-position: -90px 3px
            }
            &.fish-bone {
                background-position: -120px 3px
            }
            &.tianpan {
                background-position: -150px 3px
            }
        }
    }
}
.minder-editor-slider {
    width: 200px;
    margin: 0 6px;
}
</style>
<script>
    import IFrame from "../pages/manage/components/IFrame.vue";
    export default {
        name: 'mind-editor',
        components: {IFrame},
        props: {
            value: {
                default: function () {
                    return {}
                }
            },
            readOnly: {
                type: Boolean,
                default: false
            },
        },
        data() {
            return {
                loadIng: true,
                isHand: this.readOnly,
                zoom: 100,

                backup: null
            };
        },
        mounted() {
            window.addEventListener('message', this.handleMessage)
        },
        beforeDestroy() {
            window.removeEventListener('message', this.handleMessage)
        },
        methods: {
            onMessage(data) {
                if (data.app !== 'minder') {
                    return
                }
                switch (data.action) {
                    case 'ready':
                        this.loadIng = false
                        this.rendData()
                        break;

                    case 'content':
                        this.backup = JSON.stringify(data.content)
                        this.$emit('input', data.content);
                        break;

                    case "save":
                        this.$emit('saveData');
                        break;
                }
            },

            onHand() {
                if (this.readOnly) {
                    this.execCommand('removeAllSelected')
                    return
                }
                this.execCommand('Hand')
                this.isHand = !this.isHand
            },

            execCommand(command, value) {
                this.$refs.frame.postMessage({
                    app: 'minder',
                    action: 'command',
                    command,
                    value
                })
                if (command === 'goCenter' || command === 'removeAllSelected') {
                    return
                }
                setTimeout(_ => {
                    if (this.isHand) {
                        this.$refs.frame.postMessage({
                            app: 'minder',
                            action: 'commandAlways',
                            command: 'Hand',
                            value
                        })
                    }
                }, 300)
            },

            exportHandle(type, filename) {
                this.$refs.frame.postMessage({
                    app: 'minder',
                    action: 'export',
                    type,
                    name: filename || (this.value.root.data.text || this.$L('无标题'))
                })
            },

            rendData() {
                if (this.loadIng) {
                    return
                }
                if (this.backup === JSON.stringify(this.value)) {
                    return
                }
                this.$refs.frame.postMessage({
                    app: 'minder',
                    action: 'setContent',
                    content: this.value
                })
            }
        },
        computed: {
            url() {
                return $A.mainUrl(`minder/index.html?type=manual&readonly=${this.readOnly ? 'yes' : 'no'}`)
            }
        },
        watch: {
            value: {
                handler: function (json) {
                    if (typeof json !== "object" || json === null) {
                        json = {
                            root: json,
                            theme: "fresh-blue",
                            template: "default",
                        };
                    }
                    if (typeof json.root !== "object" || json.root === null || json.root.length == 0) {
                        json.root = {
                            data: {
                                id: $A.randomString(12),
                                text: this.$L('默认节点'),
                            },
                            children: []
                        }
                    }
                    if (typeof json.theme !== "string") {
                        json.theme = "fresh-blue";
                    }
                    if (typeof json.template !== "string") {
                        json.template = "default";
                    }
                    this.rendData();
                },
                deep: true,
                immediate: true
            },

            zoom(val) {
                this.execCommand('Zoom', val)
            }
        }
    };
</script>
