<template>
  <div>
    <div id="map" class="map-container"></div>
  </div>
</template>

<script>
import 'maptalks/dist/maptalks.css'
import * as maptalks from 'maptalks'
import { getRailListJson, getPersonEntity, getPositioningHistory } from '@/api/positioning/map'

import Dayjs from 'dayjs'

export default {
  props: {
    query: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      locationData: null,
      baseRelativeCoordinate0: null,
      baseRelativeCoordinate1: null,
      baseRelativeExtent: null,
      baseGPSCoordinate0: null,
      baseGPSCoordinate1: null,
      baseGPSExtent: null,
      baseExtent: null,

      buildNo: 0,
      buildPanelPos: 0,
      floorNo: 0,
      floorPanelPos: 0,
      floorNoArray: null,

      postExtent: null,
      buildData: null,

      mapBaseLayer: null,
      map: null,
      mapLayer: null,
      personLayer: null,
      railLayer: null,
      railAlarmLayer: null,
      historyLayer: null,
      historyLayer2: null,

      floorPanel: null,
      buildPanel: null,
      marker: null,
    }
  },

  created() {
    window.moveBuildPanel = this.moveBuildPanel
    window.changeBuild = this.changeBuild
    window.moveFloorPanel = this.moveFloorPanel
    window.changeFloor = this.changeFloor
  },
  mounted() {
    this.$nextTick((_) => {
      this.getLocationData()
    })
  },
  methods: {
    getLocationData() {
      this.locationData = this.$setting

      if (this.locationData) {
        this.buildNo = this.locationData.DefaultBuild
        this.buildData = this.locationData.BuildList[this.buildNo]
        this.mapBaseLayer = this.locationData.MapBaseLayer //地图底图

        this.floorNo = this.buildData.DefaultFloor
        if (this.buildData.FloorList[this.floorNo].No instanceof Array) {
          this.floorNoArray = this.buildData.FloorList[this.floorNo].No
        } else {
          this.floorNoArray = [this.buildData.FloorList[this.floorNo].No]
        }

        this.baseRelativeCoordinate0 = new maptalks.Coordinate(this.buildData.RelativeCoordinate0)
        this.baseRelativeCoordinate1 = new maptalks.Coordinate(this.buildData.RelativeCoordinate1)
        this.baseRelativeExtent = new maptalks.Extent(this.baseRelativeCoordinate0, this.baseRelativeCoordinate1)

        if (this.buildData.MultiMap) {
          this.postExtent = [
            this.baseRelativeCoordinate0.x,
            this.baseRelativeCoordinate0.y,
            this.baseRelativeCoordinate1.x,
            this.baseRelativeCoordinate1.y,
          ]
        } else {
          this.postExtent = null
        }

        if (this.buildData.Projection == 'identity') {
          this.baseExtent = new maptalks.Extent(
            new maptalks.Coordinate(0, 0),
            new maptalks.Coordinate(
              this.baseRelativeCoordinate1.x - this.baseRelativeCoordinate0.x,
              this.baseRelativeCoordinate0.y - this.baseRelativeCoordinate1.y
            )
          )
        } else {
          this.baseGPSCoordinate0 = new maptalks.Coordinate(this.buildData.GPSCoordinate0)
          this.baseGPSCoordinate1 = new maptalks.Coordinate(this.buildData.GPSCoordinate1)
          this.baseGPSExtent = new maptalks.Extent(this.baseGPSCoordinate0, this.baseGPSCoordinate1)
          this.baseExtent = this.baseGPSExtent
        }
        this.createMap()
      } else {
        console.log('获取定位配置文件失败')
      }
    },
    createMap() {
      let zoom, maxZoom, minZoom, baseLayer, resolution0, resolutionMax

      if (this.buildData.Projection == 'identity') {
        zoom = this.buildData.RelativeMapZoom
        maxZoom = this.buildData.RelativeMapMaxZoom
        minZoom = this.buildData.RelativeMapMinZoom
        resolution0 = this.buildData.RelativeResolution0
        resolutionMax = this.buildData.RelativeResolutionMax
        baseLayer = null
      } else {
        zoom = this.buildData.GPSMapZoom
        maxZoom = this.buildData.GPSMapMaxZoom
        minZoom = this.buildData.GPSMapMinZoom
        resolution0 = this.buildData.GPSResolution0
        resolutionMax = this.buildData.GPSResolutionMax
        baseLayer = new maptalks.TileLayer('base', this.mapBaseLayer)
      }

      if (this.map) this.map.remove()
      this.map = new maptalks.Map('map', {
        center: this.baseExtent.getCenter(),
        //centerCross: true,
        zoom: zoom,
        maxZoom: maxZoom,
        minZoom: minZoom,
        bearing: this.buildData.MapBearing,
        pitch: this.buildData.MapPitch,
        maxExtent: this.baseExtent,
        zoomControl: {
          position: 'top-left',
          slider: false,
          zoomLevel: false,
        },
        scaleControl: true,
        spatialReference: {
          projection: this.buildData.Projection,
          resolutions: (function () {
            const resolutions = []
            for (let i = 0; i <= resolutionMax; i++) {
              resolutions[i] = resolution0 / Math.pow(2, i)
            }
            return resolutions
          })(),
        },
        baseLayer: baseLayer,
      })

      this.map.fitExtent(this.baseExtent, 0)

      this.mapLayer = new maptalks.ImageLayer(
        'map',
        [
          {
            url: this.buildData.FloorList[this.floorNo].MapPath,
            extent: this.baseExtent,
            opacity: 1,
          },
        ],
        {
          forceRenderOnMoving: true,
          forceRenderOnZooming: true,
          forceRenderOnRotating: true,
        }
      ).addTo(this.map)

      this.personLayer = new maptalks.VectorLayer('person', {
        zIndex: 100,
        forceRenderOnMoving: true,
        forceRenderOnZooming: true,
        forceRenderOnRotating: true,
      }).addTo(this.map)

      this.railLayer = new maptalks.VectorLayer('rail', {
        zIndex: 1,
        visible: false,
        forceRenderOnMoving: true,
        forceRenderOnZooming: true,
        forceRenderOnRotating: true,
      }).addTo(this.map)

      this.railAlarmLayer = new maptalks.VectorLayer('railAlarm', {
        zIndex: 2,
        visible: true,
        forceRenderOnMoving: true,
        forceRenderOnZooming: true,
        forceRenderOnRotating: true,
      }).addTo(this.map)

      this.historyLayer = new maptalks.VectorLayer('history', {
        zIndex: 2,
        forceRenderOnMoving: true,
        forceRenderOnZooming: true,
        forceRenderOnRotating: true,
      }).addTo(this.map)

      this.historyLayer2 = new maptalks.VectorLayer('history2', {
        zIndex: 3,
        forceRenderOnMoving: true,
        forceRenderOnZooming: true,
        forceRenderOnRotating: true,
      }).addTo(this.map)

      let _this = this
      new maptalks.control.Toolbar({
        items: [
          {
            item: '复位地图',
            click: function () {
              _this.map.animateTo(
                {
                  //center: baseGPSExtent.getCenter(),
                  //zoom: locationData[buildNo].GPSMapZoom,
                  bearing: _this.buildData.MapBearing,
                  pitch: _this.buildData.MapPitch,
                },
                {
                  duration: 1000,
                },
                frame => {
                  if (frame.state.playState === 'finished') {
                    _this.map.fitExtent(_this.baseExtent, 0, {
                      duration: 1000,
                    })
                  }
                }
              )
            },
          },
          {
            item: '显示围栏',
            click: function () {
              _this.railLayer.show()
            },
          },
          {
            item: '隐藏围栏',
            click: function () {
              _this.railLayer.hide()
            },
          },
        ],
      }).addTo(this.map)

      if (this.buildData.FloorPanelDisplay) {
        this.createFloorPanel()
      }

      if (this.locationData.BuildPanelDisplay) {
        this.createBuildPanel()
      }

      this.getRail()
    },
    async getRail() {
      this.railLayer.clear()
      this.railAlarmLayer.clear()
      const params = {
        BuildId: this.buildData.BuildId,
        FloorNoArray: this.floorNoArray,
        Extent: this.postExtent,
      }
      try {
        const res = await getRailListJson(params)
        const data = res.data.content
        if (data.length > 0) {
          data.forEach((r) => {
            let inExtent = true
            let points = []
            r.points.forEach((p) => {
              if (!this.baseRelativeExtent.contains(new maptalks.Coordinate(p.x, p.y))) inExtent = false
              points.push(this.getNewCoordinate(p.x, p.y))
            })
            if (inExtent) {
              this.railLayer.addGeometry(
                new maptalks.Polygon(points, {
                  symbol: {
                    lineColor: 'rgb(0,196,240)',
                    lineWidth: 2,
                    lineOpacity: 1,
                    polygonFill: 'rgb(135,196,240)',
                    polygonOpacity: 0.6,
                  },
                })
              )
              this.railAlarmLayer.addGeometry(
                new maptalks.Polygon(points, {
                  id: r.uuid,
                  visible: false,
                  symbol: {
                    lineColor: '#C06173',
                    lineWidth: 2,
                    lineOpacity: 1,
                    polygonFill: '#E08193',
                    polygonOpacity: 0.6,
                  },
                })
              )
            }
          })
        }
      } catch (error) {
        console.log(error)
        this.$message.error(error)
      }
    },

    getOffset(geometry, person) {
      let start = geometry.getCoordinates()
      let end = this.getNewCoordinate(
        person.locationData.xMillimeter,
        person.locationData.yMillimeter
      )
      return end.sub(start)
    },

    getNewCoordinate(x, y) {
      if (this.buildData.Projection == 'identity') {
        return new maptalks.Coordinate(x - this.baseRelativeCoordinate0.x, this.baseRelativeCoordinate0.y - y)
      } else {
        return this.map.locate(
          this.baseGPSCoordinate0,
          (x - this.baseRelativeCoordinate0.x) / 1000,
          -(y - this.baseRelativeCoordinate0.y) / 1000
        )
      }
    },

    async displayHistory(id, timeRange) {
      //console.log(timeRange)
      // console.log(this.query)
      this.clearHistory()
      try {
        const personRes = await getPersonEntity({ id })
        if (personRes.code === 20000) {
          const personData = personRes.data
          // const pf = personData.locationData.floorNo
          // if (floorNo) {
          //   if ('Floor' + floorNo !== pf) {
          //     this.changeFloor(Number(pf.replace('Floor', '')) - 1)
          //     this.sendMes(pf.replace('Floor', ''))
          //   }
          // } else {
          //   if ('Floor' + buildData.DefaultFloor !== pf) {
          //     this.changeFloor(Number(pf.replace('Floor', '')) - 1)
          //     this.sendMes(pf.replace('Floor', ''))
          //   }
          // }

          const historyParams = {
            BuildId: this.buildData.BuildId,
            FloorNoArray: this.floorNoArray,
            Extent: this.postExtent,
            MAC: personData.labelMAC,
            StartTime: Dayjs(timeRange[0]).format(),
            EndTime: Dayjs(timeRange[1]).format(),
          }
          const historyRes = await getPositioningHistory(historyParams)
          const historyData = historyRes.data.content
          if (historyData.length > 0) {
            let linesList = []
            let maxX, minX, maxY, minY
            for (let i = 0; i < historyData.length; i++) {
              let data = historyData[i]
              if (data.length > 0) {
                let lines = []
                if (data.length == 1) {
                  data.push({ x: data[0].x, y: data[0].y })
                }
                for (let j = 0; j < data.length - 1; j++) {
                  if (i == 0 && j == 0) {
                    maxX = data[j].x
                    minX = data[j].x
                    maxY = data[j].y
                    minY = data[j].y
                  } else {
                    if (data[j].x > maxX) maxX = data[j].x
                    if (data[j].x < minX) minX = data[j].x
                    if (data[j].y > maxY) maxY = data[j].y
                    if (data[j].y < minY) minY = data[j].y
                  }

                  let points = [
                    this.getNewCoordinate(data[j].x, data[j].y),
                    this.getNewCoordinate(data[j + 1].x, data[j + 1].y),
                  ]

                  new maptalks.LineString(points, {
                    arrowStyle: null, // arrow-style : now we only have classic
                    arrowPlacement: 'vertex-last', // arrow's placement: vertex-first, vertex-last, vertex-firstlast, point
                    visible: true,
                    editable: false,
                    cursor: null,
                    shadowBlur: 0,
                    shadowColor: 'black',
                    draggable: false,
                    dragShadow: false, // display a shadow during dragging
                    drawOnAxis: null, // force dragging stick on a axis, can be: x, y
                    symbol: {
                      lineColor: '#CCFF00',
                      lineWidth: 1,
                    },
                  }).addTo(this.historyLayer)

                  let line = new maptalks.LineString(points, {
                    arrowStyle: null, // arrow-style : now we only have classic
                    arrowPlacement: 'vertex-last', // arrow's placement: vertex-first, vertex-last, vertex-firstlast, point
                    visible: false,
                    editable: false,
                    cursor: null,
                    shadowBlur: 0,
                    shadowColor: 'black',
                    draggable: false,
                    dragShadow: false, // display a shadow during dragging
                    drawOnAxis: null, // force dragging stick on a axis, can be: x, y
                    symbol: {
                      lineColor: '#00FFCC',
                      lineWidth: 2,
                    },
                  }).addTo(this.historyLayer2)
                  lines.push(line)
                }
                linesList.push(lines)
              }
            }
            this.createMarker(linesList[0][0].getFirstCoordinate(), personData)
            //console.log(maxX, minX, maxY, minY)
            this.map.fitExtent(
              new maptalks.Extent(
                this.getNewCoordinate(minX, minY),
                this.getNewCoordinate(maxX, maxY)
              ),
              0,
              { duration: 1000 },
              frame => {
                if (frame.state.playState === 'finished') {
                  this.markerRun(linesList)
                }
              }
            )
          }
        }
      } catch (error) {
        console.log(error)
      }
    },
    sendMes(f) {
      this.$message({
        showClose: true,
        message: '楼层切换至' + f + '层',
        type: 'success',
      })
    },
    clearHistory() {
      this.historyLayer.getGeometries().forEach((a) => a.remove())
      this.historyLayer2.getGeometries().forEach((a) => a.remove())
      this.personLayer.getGeometries().forEach((a) => a.remove())
    },
    createMarker(Coordinate, person) {
      this.marker = new maptalks.Marker(Coordinate, {
        symbol: {
          markerFile: [process.env.VUE_APP_BASE_API] + person.iconPath,
          markerWidth: 40,
          markerHeight: 40,
          markerDx: 0,
          markerDy: 20,
          textName: person.name,
          textDx: 0,
          textDy: 20,
        },
        properties: {
          Name: person.name,
        },
      }).addTo(this.personLayer)
    },

    markerRun(linesList) {
      let lineEnd = false
      let markerEnd = false
      let d =
        this.map.computeLength(
          linesList[0][0].getFirstCoordinate(),
          linesList[0][0].getLastCoordinate()
        ) * 10
      let t = linesList[0][0].getLastCoordinate().sub(linesList[0][0].getFirstCoordinate())
      this.marker.animate(
        {
          translate: t,
        },
        {
          duration: d,
          easing: 'linear',
        },
        (frame) => {
          if (frame.state.playState === 'finished') {
            markerEnd = true
            if (lineEnd) {
              if (linesList[0].length > 1) {
                linesList[0].shift()
                this.markerRun(linesList)
              } else if (linesList.length > 1) {
                linesList.shift()
                this.marker.setCoordinates(linesList[0][0].getFirstCoordinate())
                this.markerRun(linesList)
              }
            }
          }
        }
      )

      linesList[0][0].animateShow(
        {
          duration: d,
          easing: 'linear',
        },
        (frame) => {
          if (frame.state.playState === 'finished') {
            lineEnd = true
            if (markerEnd) {
              if (linesList[0].length > 1) {
                linesList[0].shift()
                this.markerRun(linesList)
              } else if (linesList.length > 1) {
                linesList.shift()
                this.marker.setCoordinates(linesList[0][0].getFirstCoordinate())
                this.markerRun(linesList)
              }
            }
          }
        }
      )
    },

    createBuildPanel() {
      if (this.buildNo <= 1) {
        this.buildPanelPos = 0
      } else if (this.buildNo >= this.locationData.BuildList.length - 3) {
        this.buildPanelPos = this.locationData.BuildList.length - 3
      } else {
        this.buildPanelPos = this.buildNo - 1
      }

      let mapdiv = document.getElementById('map')
      let mapdivh = mapdiv.clientHeight || mapdiv.offsetHeight

      this.buildPanel = new maptalks.control.Panel({
        position: { top: mapdivh / 2 - 60, left: '20' },
        draggable: false,
        custom: true,
        content: this.makeBuildPanelContent(),
        closeButton: false,
      }).addTo(this.map)
    },

    makeBuildPanelContent() {
      let content
      content = '<table class="map-buildpanel" cellpadding="0" frame=void rules=none>'
      content +=
        '<tr><td><button onclick="moveBuildPanel(0)"><div class="up-arrows"></div></button></td></tr>'
      for (let i = this.buildPanelPos; i <= this.buildPanelPos + 2; i++) {
        if (i == this.buildNo) {
          content +=
            '<tr><td><button style="background: rgb(28,188,156)">' +
            this.locationData.BuildList[i].BuildAbbName +
            '</button></td></tr>'
        } else {
          if (this.locationData.BuildList[i]) {
            content +=
              '<tr><td><button onclick="changeBuild(' +
              i +
              ')">' +
              this.locationData.BuildList[i].BuildAbbName +
              '</button></td></tr>'
          } else {
            content += '<tr><td><button></button></td></tr>'
          }
        }
      }

      content +=
        '<tr><td><button onclick="moveBuildPanel(1)"><div class="down-arrows"></div></button></td></tr>'
      content += '</table>'
      return content
    },

    moveBuildPanel(s) {
      let b = this.buildPanelPos
      if (s == 0) {
        if (b > 0) b--
      } else if (s == 1) {
        if (b < this.buildData.FloorList.length - 3) b++
      }
      if (b != this.buildPanelPos) {
        this.buildPanelPos = b
        this.buildPanel.setContent(this.makeBuildPanelContent())
      }
    },

    changeBuild(b) {
      this.buildNo = b
      this.buildPanel.setContent(this.makeBuildPanelContent())

      this.buildData = this.locationData.BuildList[this.buildNo]

      this.floorNo = this.buildData.DefaultFloor
      if (this.buildData.FloorList[this.floorNo].No instanceof Array) {
        this.floorNoArray = this.buildData.FloorList[this.floorNo].No
      } else {
        this.floorNoArray = [this.buildData.FloorList[this.floorNo].No]
      }

      this.baseRelativeCoordinate0 = new maptalks.Coordinate(this.buildData.RelativeCoordinate0)
      this.baseRelativeCoordinate1 = new maptalks.Coordinate(this.buildData.RelativeCoordinate1)
      this.baseRelativeExtent = new maptalks.Extent(this.baseRelativeCoordinate0, this.baseRelativeCoordinate1)

      if (this.buildData.MultiMap) {
        this.postExtent = [
          this.baseRelativeCoordinate0.x,
          this.baseRelativeCoordinate0.y,
          this.baseRelativeCoordinate1.x,
          this.baseRelativeCoordinate1.y,
        ]
      } else {
        this.postExtent = null
      }

      if (this.buildData.Projection == 'identity') {
        this.baseExtent = new maptalks.Extent(
          new maptalks.Coordinate(0, 0),
          new maptalks.Coordinate(
            this.baseRelativeCoordinate1.x - this.baseRelativeCoordinate0.x,
            this.baseRelativeCoordinate0.y - this.baseRelativeCoordinate1.y
          )
        )
      } else {
        this.baseGPSCoordinate0 = new maptalks.Coordinate(this.buildData.GPSCoordinate0)
        this.baseGPSCoordinate1 = new maptalks.Coordinate(this.buildData.GPSCoordinate1)
        this.baseGPSExtent = new maptalks.Extent(this.baseGPSCoordinate0, this.baseGPSCoordinate1)
        this.baseExtent = this.baseGPSExtent
      }

      this.createMap()
    },

    createFloorPanel() {
      if (this.floorNo <= 1) {
        this.floorPanelPos = 0
      } else if (this.floorNo >= this.buildData.FloorList.length - 3) {
        this.floorPanelPos = this.buildData.FloorList.length - 3
      } else {
        this.floorPanelPos = this.floorNo - 1
      }

      let mapdiv = document.getElementById('map')
      let mapdivh = mapdiv.clientHeight || mapdiv.offsetHeight

      if (this.floorPanel) this.floorPanel.remove()

      this.floorPanel = new maptalks.control.Panel({
        position: { top: mapdivh / 2 - 60, right: '20' },
        draggable: false,
        custom: true,
        content: this.makeFloorPanelContent(),
        closeButton: false,
      }).addTo(this.map)
    },

    makeFloorPanelContent() {
      let content
      content = '<table class="map-floorpanel" cellpadding="0" frame=void rules=none>'
      content +=
        '<tr><td><button onclick="moveFloorPanel(0)"><div class="up-arrows"></div></button></td></tr>'
      for (let i = this.floorPanelPos; i <= this.floorPanelPos + 2; i++) {
        if (i == this.floorNo) {
          content +=
            '<tr><td><button style="background: rgb(28,188,156)">' +
            this.buildData.FloorList[i].Name +
            '</button></td></tr>'
        } else {
          if (this.buildData.FloorList[i]) {
            content +=
              '<tr><td><button onclick="changeFloor(' +
              i +
              ')">' +
              this.buildData.FloorList[i].Name +
              '</button></td></tr>'
          } else {
            content += '<tr><td><button></button></td></tr>'
          }
        }
      }

      content +=
        '<tr><td><button onclick="moveFloorPanel(1)"><div class="down-arrows"></div></button></td></tr>'
      content += '</table>'
      return content
    },

    moveFloorPanel(s) {
      let f = this.floorPanelPos
      if (s == 0) {
        if (f > 0) f--
      } else if (s == 1) {
        if (f < this.buildData.FloorList.length - 3) f++
      }
      if (f != this.floorPanelPos) {
        this.floorPanelPos = f
        this.floorPanel.setContent(this.makeFloorPanelContent())
      }
    },

    changeFloor(f) {
      this.clearHistory()

      this.floorNo = f
      this.floorPanel.setContent(this.makeFloorPanelContent())

      if (this.buildData.FloorList[this.floorNo].No instanceof Array) {
        this.floorNoArray = this.buildData.FloorList[this.floorNo].No
      } else {
        this.floorNoArray = [this.buildData.FloorList[this.floorNo].No]
      }

      this.mapLayer.setImages([
        {
          url: this.buildData.FloorList[this.floorNo].MapPath,
          extent: this.baseExtent,
          opacity: 1,
        },
      ])
      this.getRail()
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .map-container {
  width: 100%;
  height: calc(100vh - 156px);
}

::v-deep .map-panel {
  background: rgba(135, 196, 240, 0.8);
  width: 450px;
  height: 120px;
  border: 2px #fff solid;
  padding: 10px;
  color: #fff;
}

::v-deep .map-panel input {
  color: #bbb;
}

::v-deep .map-panel a {
  color: #fff;
  float: right;
  margin-right: 15px;
}
::v-deep .map-floorpanel {
  background: rgb(52, 73, 94);
  width: 40px;
  height: 120px;
  padding: 0px;
  color: #fff;
  border: 0px solid rgb(231, 234, 236) !important;
}

::v-deep .map-floorpanel tr {
  text-align: center;
  height: 30px;
}

::v-deep .map-floorpanel td {
  text-align: center;
  height: 30px;
}

::v-deep .map-floorpanel button {
  width: 40px;
  height: 30px;
  border: none;
  background: rgb(52, 73, 94);
  color: #fff;
}

::v-deep .map-buildpanel {
  background: rgb(52, 73, 94);
  width: 40px;
  height: 120px;
  padding: 0px;
  color: #fff;
  border: 0px solid rgb(231, 234, 236) !important;
  font-size: 14px;
}

::v-deep .map-buildpanel tr {
  text-align: center;
  height: 30px;
}

::v-deep .map-buildpanel td {
  text-align: center;
  height: 30px;
}

::v-deep .map-buildpanel button {
  width: 40px;
  height: 30px;
  border: none;
  background: rgb(52, 73, 94);
  color: #fff;
}

::v-deep .up-arrows {
  width: 0;
  height: 0;
  border-bottom: 20px solid white;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
}

::v-deep .down-arrows {
  width: 0;
  height: 0;
  border-top: 20px solid white;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>
