/////////////////////////////////////////////////////////////////
  //
  //
  /////////////////////////////////////////////////////////////////
  async createControls() {

    const properties = await Toolkit.getProperties(
      this.viewer.model,
      this.dbId,
      this.properties)

    const sortedProperties = properties.sort((a, b)=>{

      var nameA = a.displayName.toLowerCase()
      var nameB = b.displayName.toLowerCase()

      return nameA > nameB ? 1 : -1
    })

    var menuItems = sortedProperties.map((prop)=>{

      return {
        name: prop.displayName,
        value: prop.displayValue
      }
    })

    var $container = $(`#${this.controlsId}`)

    this.dropdown = new Dropdown({
      container: $container,
      title: 'Property',
      pos: {
        top: 0, left: 0
      },
      menuItems
    })

    this.dropdown.on('item.selected', (item) => {

      LabelMarker.prototype.labelName = item.name

      this.item = item

      this.emit('labelSelected')
    })

    var occlusionSwitchId = this.guid()
    var bindSwitchId = this.guid()
    var btnRemoveId = this.guid()
    var btnExitId = this.guid()

    var html = `
      <br>
      <div style="width: 150px;">

        <div id="${bindSwitchId}"
          style="margin-right:10px; float:left; padding-top:1px;">
        </div>
        <div style="height:30px">
          <b>Bind to state</b>
        </div>

        <div id="${occlusionSwitchId}"
          style="margin-right:10px; float:left; padding-top:1px;">
        </div>
        <div style="height:30px">
          <b>Occlusion</b>
        </div>

        <button id="${btnRemoveId}" class="btn btn-danger btn-ctrl"
          style="float: left; margin-right: 3px;"
          data-placement="bottom"
          data-toggle="tooltip"
          data-delay='{"show":"500", "hide":"100"}'
          title="delete markup">
         <span class="fa fa-remove btn-span"></span>
        </button>
        <button id="${btnExitId}" class="btn btn-success btn-ctrl"
          data-placement="bottom"
          data-toggle="tooltip"
          data-delay='{"show":"500", "hide":"100"}'
          title="exit edit mode">
         <span class="fa fa-sign-out btn-span"></span>
         </button>
      </div>
    `

    $container.append(html)

    const $target = $container.find('label[data-toggle="tooltip"]')

    if ($target.tooltip) {

      $target.tooltip({
        container: 'body',
        animated: 'fade',
        html: true
      })
    }


    this.bindSwitch =
      new SwitchButton('#' + bindSwitchId,
        this.parent.bindToState)

    this.bindSwitch.on('checked', (checked)=>{

      this.parent.bindToState = checked
    })

    this.occlusionSwitch =
      new SwitchButton('#' + occlusionSwitchId,
        this.parent.occlusion)

    this.occlusionSwitch.on('checked', (checked)=>{

      this.parent.occlusion = checked
    })

    $('#' + btnRemoveId).click(()=>{

      this.parent.remove()
    })

    $('#' + btnExitId).click(()=>{

      // ensure some default is set for next markup
      if (!this.item) {

        this.item = menuItems[0]

        LabelMarker.prototype.labelName =
          this.item.name
      }

      this.showControls(false)

      this.updateLabel(
        this.item.name,
        this.item.value)
    })
  }
  constructor(viewer, properties, componentIds, buttonElement) {

    super($('.viewer-view')[0], 'Visual Reports', {
      shadow: true,
      buttonElement
    });

    this.viewer = viewer;

    this.componentIds = componentIds;

    $(this.container).addClass('visual-report');

    //Properties dropdown

    var menuItems = properties.map((prop)=>{

      var value = prop.replace(':', '');

      return {
        name: value,
        value: value
      }
    });

    this.dropdown = new Dropdown({
      container: '#' + this.propsContainerId,
      title: 'Property',
      prompt: 'Select a property ...',
      pos: {
        top: 0, left: 0
      },
      menuItems
    });

    this.onPropertyChangedHandler =
      (e) => this.onPropertyChanged(e);

    this.dropdown.on('item.selected', (item)=>{

      this.onPropertyChangedHandler(item.value);
    });

    //Tab Control

    this.TabManager = new TabManager(
      '#' + this.tabsContainerId);

    this.onTabVisibleHandler =
      (e) => this.onTabVisible(e);

    this.TabManager.on('tab.visible', (tabInfo)=>{

      this.onTabVisibleHandler(tabInfo);
    });

    this.pieChartSelector = ToolPanelBase.guid();

    this.pieTabId = this.TabManager.addTab({
      name: 'Pie Chart',
      active: true,
      html: `<p class="d3 d3-pie c${this.pieChartSelector}"></p>`
    });

    this.barChartSelector = ToolPanelBase.guid();

    this.barTabId = this.TabManager.addTab({
      name: 'Bar Chart',
      html: `<p class="d3 d3-bar c${this.barChartSelector}"></p>`
    });

    this.$container = $(this.container)

    this.$container.mousedown(() => {

      this.size = {
        h: this.$container.height(),
        w: this.$container.width()
      }

      this.mousedown = true
    })

    this.$container.parent().mouseup(() => {

      if(this.mousedown) {

        if(this.size.w !== this.$container.width() ||
          this.size.h !== this.$container.height()) {

          if(this.data) {

            this.redraw(this.data)
          }
        }
      }

      this.mousedown = false
    })
  }