import {NgElement, Component, View as NgView, For, PropertySetter} from 'angular2/angular2'
import {IonicComponent} from 'ionic/config/component'
@Component({
selector: 'ion-tabs',
properties: {
tabBarPlacement: 'tab-bar-placement',
tabBarIcons: 'tab-bar-icons'
}
})
@NgView({
template: `
`,
directives: [For]
})
export class Tabs {
constructor(
@NgElement() ngElement: NgElement
) {
this.domElement = ngElement.domElement
this.config = Tabs.config.invoke(this)
this.tabs = []
}
addTab(tab) {
this.tabs.push(tab)
if (this.tabs.length == 1) {
this.select(tab)
}
}
onClickTabItem(ev, tab) {
ev.preventDefault()
if (this.selectedTab !== tab) {
this.select(tab)
} else if (tab._stack.length >= 2) {
tab.popTo(0)
}
}
select(tab) {
this.tabs.forEach(otherTab => {
otherTab.setSelected(false)
})
tab.setSelected(true)
this.selectedTab = tab
}
}
new IonicComponent(Tabs, {
properties: {
tabBarPlacement: {
defaults: {
ios: 'bottom',
android: 'top',
core: 'bottom'
}
},
tabBarIcons: {
defaults: {
ios: 'top',
android: 'top',
core: 'top'
}
}
}
})