import VectorType from '../enum/VectorType.js'
import CustomImage from '../Geometry/CustomImage.js'
import { mathUtil } from '../MathUtil.js'
import { floorplanService } from './FloorplanService'
import Constant from '../Constant'

export default class CustomImageService {
    constructor() {
        this.defaultPix = 60;  
    }

    async createCustomImage(url,center,vectorId) {
        const customImage = new CustomImage(url, center,vectorId)
        if(customImage.url){
            const imageData = await floorplanService.loadImageData(customImage.url)
            customImage.setImageData(imageData)
            customImage.width = imageData.width;
            customImage.height = imageData.height;
            let maxPix = Math.max(imageData.width,imageData.height)
            customImage.ratio = this.defaultPix/maxPix
        }

        floorplanService.addCustomImage(customImage)
        return customImage
    }

    deleteCustomImage(customImageId, floorNum) {
        floorplanService.deleteCustomImage(customImageId, floorNum)
    }

    setCustomImageInfo(customImageInfo) {
        let customImage = floorplanService.getCustomImage(customImageInfo.vectorId)
        customImage.vectorId = customImageInfo.vectorId
        customImage.angle = customImageInfo.angle
        customImage.url = customImageInfo.url
        customImage.scale = customImageInfo.scale
        customImage.center = JSON.parse(JSON.stringify(customImageInfo.center))
    }
}

const customImageService = new CustomImageService()
export { customImageService }