<script>import { BEM } from "../../models/BEM";
import Closeable from "./Closeable.svelte";
import { createEventDispatcher } from "svelte";
import { fade } from "svelte/transition";
const dispatch = createEventDispatcher();
export let theme = "secondary";
export let isCloseable = false;
export let showIcon = true;
export let customIcon = '';
export let description = '';
export let message = '';
export let timeout = null;
export let inline = false;
$: bm = new BEM('UI-Alert', {
    [theme]: !!theme
}, $$props.class);
$: icon = () => {
    if (customIcon)
        return customIcon;
    switch (theme) {
        case "success":
            return "fa fa-check";
        case "info":
            return 'fa fa-info';
        case "warning":
            return 'fa fa-warning';
        case 'danger':
            return 'fa fa-times';
    }
    return 'fa fa-envelope';
};
const onClose = () => dispatch("close");
if (timeout && isCloseable) {
    setTimeout(onClose, timeout);
}
</script>
<div
	in:fade
	out:fade
	on:click
	class={bm.toString()}
	style={$$props.style}
	class:isDescription={!!description}
	class:inline
>
	<div class="wrapper">
		{#if showIcon}
			<span class="icon">
				<i class="{icon()}"></i>
			</span>
		{/if}
		<span class="detail">
			<slot>{message}</slot>
		</span>
		{#if isCloseable}
			<Closeable on:click={onClose}/>
		{/if}
	</div>
	{#if description}
		<div class="description">{description}</div>
	{/if}
</div>
<style>.UI-Alert {
  margin-bottom: var(--ui-margin);
  border-radius: var(--ui-radius);
  pointer-events: all;
}

.wrapper {
  display: flex;
  align-items: center;
  padding: 1.25rem 1.75rem;
  gap: 10px;
}

i {
  font-size: 15px;
  color: inherit;
}

.description {
  padding-left: 1.75rem;
  padding-bottom: 1.25rem;
  padding-top: 0.5rem;
  color: var(--ui-text-color);
}

.isDescription .wrapper {
  padding-bottom: 0;
}

.detail {
  flex: 1;
  font-size: var(--ui-text-font-size);
}

.icon {
  display: inline-flex;
}

.primary {
  background: whitesmoke;
  color: #556ee6;
  border: 1px solid #556ee6;
  border-left: 6px solid #556ee6;
}

.secondary {
  background: whitesmoke;
  color: #74788d;
  border: 1px solid #74788d;
  border-left: 6px solid #74788d;
}

.danger {
  background: whitesmoke;
  color: #f46a6a;
  border: 1px solid #f46a6a;
  border-left: 6px solid #f46a6a;
}

.info {
  background: whitesmoke;
  color: #50a5f1;
  border: 1px solid #50a5f1;
  border-left: 6px solid #50a5f1;
}

.success {
  background: whitesmoke;
  color: #34c38f;
  border: 1px solid #34c38f;
  border-left: 6px solid #34c38f;
}

.warning {
  background: whitesmoke;
  color: #f1b44c;
  border: 1px solid #f1b44c;
  border-left: 6px solid #f1b44c;
}

.default {
  background: whitesmoke;
  color: rgb(222, 203, 203);
  border: 1px solid rgb(222, 203, 203);
  border-left: 6px solid rgb(222, 203, 203);
}

.dark {
  background: whitesmoke;
  color: #343a40;
  border: 1px solid #343a40;
  border-left: 6px solid #343a40;
}

.white {
  background: whitesmoke;
  color: white;
  border: 1px solid white;
  border-left: 6px solid white;
}

.inline {
  border: 0;
  display: inline-flex;
}
.inline.primary {
  background-color: var(--ui-primary);
  color: var(--ui-theme-primary);
}
.inline.secondary {
  background-color: var(--ui-secondary);
  color: var(--ui-theme-primary);
}
.inline.danger {
  background-color: var(--ui-danger);
  color: var(--ui-theme-primary);
}
.inline.info {
  background-color: var(--ui-info);
  color: var(--ui-theme-primary);
}
.inline.success {
  background-color: var(--ui-success);
  color: var(--ui-theme-primary);
}
.inline.warning {
  background-color: var(--ui-warning);
  color: var(--ui-theme-primary);
}
.inline.default {
  background-color: var(--ui-default);
  color: var(--ui-theme-primary);
}
.inline.dark {
  background-color: var(--ui-dark);
  color: var(--ui-theme-primary);
}
.inline.white {
  background-color: var(--ui-white);
  color: var(--ui-theme-primary);
}
.inline .wrapper {
  padding: 0.5rem;
}
.inline .detail {
  font-size: calc(var(--ui-text-font-size) - 4px);
}
.inline.white, .inline.default {
  color: black;
}</style>
