<script>
	import Tab, { Label } from '@smui/tab';
	import TabBar from '@smui/tab-bar';
	import {Meteor} from "meteor/meteor";
	import AssetList from "/imports/ui/Assets/AssetList.svelte";
	import AddAssets from "/imports/ui/Assets/AddAssets.svelte";
	import {useTracker} from "meteor/rdb:svelte-meteor-data";

	let canManageLaptops = false;
	let isAdmin = false;
	let currentUser
	$: currentUser = useTracker(() => Meteor.user());

	Tracker.autorun(() => {
		// For some reason currentUser is always null here, and is not reactive (user changes and this does not get re-called).
		let user = Meteor.user();
		canManageLaptops = user && Roles.userIsInRole(user._id, 'laptop-management', 'global');
		isAdmin = user && Roles.userIsInRole(user._id, 'admin', 'global');
	});

	let tabs = [];

	if(isAdmin) {
		tabs.push({id: 'listAssets', label: 'Asset List'});
		tabs.push({id: 'addAssets', label: 'Add Assets'});
	}
	let activeTab = tabs[0];
</script>

<div class="container">
	<TabBar tabs={tabs} minWidth let:tab bind:active={activeTab}>
		<Tab {tab}>
			<Label>{tab.label}</Label>
		</Tab>
	</TabBar>
	{#if activeTab && activeTab.id === 'listAssets'}
		<AssetList></AssetList>
	{:else if activeTab && activeTab.id === 'addAssets'}
		<AddAssets></AddAssets>
	{/if}
</div>

<style>
</style>