<template>
    <div
        class="canvas"
        :style="{
            ...getCanvasStyle(canvasStyle),
            width: changeStyleWithScale(canvasStyle.width) + 'px',
            height: changeStyleWithScale(canvasStyle.height) + 'px',
        }"
    >
        <ComponentWrapper
            v-for="(item, index) in canvasData"
            :key="index"
            :config="item"
        />
    </div>
</template>

<script>
import { getStyle, getCanvasStyle } from '@/utils/style'
import { mapState } from 'vuex'
import ComponentWrapper from '../components/Editor/ComponentWrapper'
import { changeStyleWithScale } from '@/utils/translate'
import { toPng } from 'html-to-image'
import { deepCopy } from '@/utils/utils'

export default {
    name: 'Preview',
    components: { ComponentWrapper },
    props: {
        isScreenshot: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            canvasStyle: require('../assets/test/canvasStyle.json'),
            canvasData: require('../assets/test/canvasData.json'),
            timer: '',
        }
    },
    // computed: mapState([
    //     'componentData',
    //     'canvasStyleData',
    // ]),
    created() {
        // this.$set(this, 'copyData', deepCopy(this.componentData))
        // let that = this
        // this.timer = setTimeout(() => {
        //     that.isView = true
        //     console.log('start')
        // }, 1000)
    },
    // beforeDestroy() {
    //     clearTimeout(this.timer)
    // },
    methods: {
        getStyle,
        getCanvasStyle,
        changeStyleWithScale,
    },
}
</script>

<style scoped>

</style>

<style lang="scss" scoped>
.bg {
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    position: fixed;
    background: rgb(0, 0, 0, .5);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;

.canvas-container {
    width: calc(100% - 40px);
    height: calc(100% - 120px);
    overflow: auto;

.canvas {
    background: #fff;
    position: relative;
    margin: auto;
}
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
}
}
</style>
