<script lang="ts">
	import type { BrandConfig } from '$lib/config';

	export let brand: BrandConfig = {};
	export let color = 'var(--text)';

	function masked() {
		return brand.logo != undefined && brand.asmask == true;
	}

	function logoURL(): string {
		if (brand.logo == undefined) {
			return '';
		}
		if (brand.logo.startsWith('https://') || brand.logo.startsWith('http://')) {
			return brand.logo;
		}
		return '/' + brand.logo;
	}
</script>

<div style="--mask: url({logoURL()}); --mask-color: {color}" class:masked={masked()}>
	{#if brand.logo}
		{#if brand.asmask != true}
			<img src={logoURL()} alt="logo" />
		{/if}
	{:else if brand.icon}
		<i class={brand.icon} />
	{/if}
</div>

<style>
	div {
		height: 100%;
		width: 100%;
		color: var(--mask-color);
		display: flex;
		justify-content: center;
		align-items: center;
	}

	img {
		max-width: 100%;
		max-height: 100%;
	}

	.masked {
		background: var(--mask-color);
		mask: var(--mask) center no-repeat;
		mask-size: 100%;
		-webkit-mask: var(--mask) center no-repeat;
		-webkit-mask-size: 100%;
	}
</style>
