export class MarkerShape {
  DEFAULT_SHAPES = [
    {
      name: "waterdrop",
      class: "gogo-icon-marker",
      includeIconInside: true
    },
    {
      name: "waterdrop-circle",
      class: "gogo-icon-marker",
      includeIconInside: true,
      surroundIncludedIcon: true
    },
    {
      name: "waterdrop-thin",
      class: "fa fa-map-marker",
      includeIconInside: true
    },
    {
      name: "waterdrop-thin-circle",
      class: "fa fa-map-marker",
      includeIconInside: true,
      surroundIncludedIcon: true
    },
    { name: "sign", class: "fas fa-map-signs" },
    { name: "pin", class: "fas fa-map-pin" },
    { name: "thumbtack", class: "gogo-icon-stamp-1" },
    { name: "thunderbolt", class: "fas fa-bolt" },
    { name: "dollar", class: "fas fa-dollar-sign" },
    { name: "exclamation", class: "fas fa-exclamation" },
    { name: "heart", class: "fas fa-heart" },
    { name: "feather", url: "assets/images/marker-feather.svg" },
  ]

  name : string
  class : string
  url : string
  // Whether or not there is space to include another icon inside
  includeIconInside : false
  // Surround the included icon with a white circle (or something else)
  surroundIncludedIcon : false

  constructor(config) {
    if (typeof config == 'string') {
      // Is it a default shape name
      for (let markerConf of this.DEFAULT_SHAPES) {
        if (config == markerConf.name)  {
          this.initFromObject(markerConf)
          return
        }
      }
      // Is it an image
      let imagePattern = new RegExp('.*\.(svg|png|jpg|jpeg|gif)')
      if (imagePattern.test(config.toLowerCase())) {
        this.url = config
      } else {
        this.class = config
      }
    } else {
      this.initFromObject(config)
    }
    if (!this.name) {
      this.name = this.class ? this.class : this.url.split('/').slice(-1)[0]
    }
  }

  initFromObject(config) {
    this.name = config.name
    this.class = config.class
    this.url = config.url
    this.includeIconInside = config.includeIconInside
    this.surroundIncludedIcon = config.surroundIncludedIcon
  }
}