<!DOCTYPE html>
<!--
Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/ui/base/table.html">

<dom-module id='tr-ui-a-stack-frame'>
  <template>
    <style>
    :host {
      display: flex;
      flex-direction: row;
      align-items: center;
      font-size: 12px;
    }
    </style>
    <tr-ui-b-table id="table"></tr-ui-b-table>
  </template>
</dom-module>
<script>
'use strict';

Polymer({
  is: 'tr-ui-a-stack-frame',

  ready: function() {
    this.stackFrame_ = undefined;
    this.$.table.tableColumns = [];
    this.$.table.showHeader = true;
  },

  get stackFrame() {
    return this.stackFrame_;
  },

  set stackFrame(stackFrame) {
    var table = this.$.table;

    this.stackFrame_ = stackFrame;
    if (stackFrame === undefined) {
      table.tableColumns = [];
      table.tableRows = [];
      table.rebuild();
      return;
    }

    var hasName = false;
    var hasTitle = false;

    table.tableRows = stackFrame.stackTrace;
    table.tableRows.forEach(function(row) {
      hasName |= row.name !== undefined;
      hasTitle |= row.title !== undefined;
    });

    var cols = [];
    if (hasName) {
      cols.push({
        title: 'Name',
        value: function(row) { return row.name; }
      });
    }

    if (hasTitle) {
      cols.push({
        title: 'Title',
        value: function(row) { return row.title; }
      });
    }

    table.tableColumns = cols;
    table.rebuild();
  },

  tableForTesting: function() {
    return this.$.table;
  }
});
</script>
