import Tag from '../Geometry/Tag.js'
import { floorplanService } from './FloorplanService'
import { floorplanData } from '../FloorplanData'
import { mathUtil } from '../MathUtil.js'

export default class TagService {
    constructor() {}

    // 新建tag
    createTag(position, tagId, floor) {
        let tag = new Tag(position, tagId)
        tag.setPoints2d()
        floorplanService.addTag(tag, floor)
        return tag
    }

    setTagInfo(tagInfo) {
        let tag = floorplanService.getTag(tagInfo.vectorId)
        tag.vectorId = tagInfo.vectorId
        tag.center = JSON.parse(JSON.stringify(tagInfo.center))
        tag.points2d = JSON.parse(JSON.stringify(tagInfo.points2d))
        tag.value = tagInfo.value
        tag.color = tagInfo.color
        tag.fontSize = tagInfo.fontSize
    }

    deleteTag(tagId, floorNum) {
        floorplanService.deleteTag(tagId, floorNum)
    }

    clearDefaultTags() {
        for (let i = 0; i < floorplanData.floors.length; ++i) {
            let tags = floorplanData.floors[i].tags
            for (let key in tags) {
                let tag = tags[key]
                if ((tag.value == null || tag.value.trim() == '')) {
                    this.deleteTag(tag.vectorId, i)
                }
            }
        }
    }

    getTags(floorNum) {
        return floorplanData.floors[floorNum].tags
    }
}

const tagService = new TagService()
export { tagService }
