<script>import { classNames } from '../../functions/classNames';
const [className] = classNames('Button');
/**
 * Rounded button
 */
export let rounded = false;
export let icon = '';
export let iconRight = '';
/**
 * Label text
 */
export let label = '';
export let disabled = false;
export let isIcon = false;
export let theme = '';
export let raised = false;
$: noLabel = !label && !$$slots.default && !$$slots.left && !$$slots.right;
</script>

<button
	class={[className, theme, $$props.class].join(' ')}
	class:rounded
	on:click
	{disabled}
	class:noLabel
	class:iconLeft={!icon && !!$$slots.left}
	class:iconRight={!icon && !!$$slots.right}
	class:isIcon
	class:raised
	style={$$props.style}
>
	{#if !!icon || $$slots.left}
		<div class="left">
			{#if $$slots.left}
				<slot name="left" />
			{:else}
				<i class={icon} />
			{/if}
		</div>
	{/if}
	<slot>
		<span>{label}</span>
	</slot>
	{#if !!icon || $$slots.right}
		<div class="right">
			{#if $$slots.right}
				<slot name="right" />
			{:else}
				<i class={iconRight} />
			{/if}
		</div>
	{/if}
</button>

<style>[disabled] {
  opacity: 0.6;
}

button {
  height: var(--ui-button_size-height, 33px);
  min-width: var(--ui-button_size-min-width, 33px);
  width: var(--ui-button_size-width, auto);
  display: inline-flex;
  align-items: center;
  position: relative;
  padding: 0;
  margin-right: 0.1em;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
  color: var(--ui-theme-secondary);
  background-color: -internal-light-dark(rgb(239, 239, 239), rgb(59, 59, 59));
  margin: 0;
  border: 0;
  outline: 0 none;
  border-radius: var(--ui-border-default);
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
}

span {
  display: block;
  line-height: normal;
  padding: 0.5rem 1rem;
}

.left {
  padding-left: 10px;
}

.iconLeft span {
  padding-left: 5px;
}

.iconRight span {
  padding-right: 5px;
}

.right {
  padding-right: 10px;
}

.rounded {
  border-radius: 2rem;
}

.noLabel .left,
.noLabel .right {
  padding: 0;
}
.noLabel span {
  display: none;
}

.raised {
  box-shadow: var(--ui-raised);
}

.isIcon {
  justify-content: center;
  --ui-button_size-width: 33px;
  --ui-button_size-height: 33px;
}

.primary {
  background-color: var(--ui-primary);
  color: var(--ui-theme-primary);
}
.primary:hover {
  opacity: 0.9;
}

.secondary {
  background-color: var(--ui-secondary);
  color: var(--ui-theme-primary);
}
.secondary:hover {
  opacity: 0.9;
}

.danger {
  background-color: var(--ui-danger);
  color: var(--ui-theme-primary);
}
.danger:hover {
  opacity: 0.9;
}

.info {
  background-color: var(--ui-info);
  color: var(--ui-theme-primary);
}
.info:hover {
  opacity: 0.9;
}

.success {
  background-color: var(--ui-success);
  color: var(--ui-theme-primary);
}
.success:hover {
  opacity: 0.9;
}

.warning {
  background-color: var(--ui-warning);
  color: var(--ui-theme-primary);
}
.warning:hover {
  opacity: 0.9;
}

.default {
  background-color: var(--ui-default);
  color: var(--ui-theme-primary);
}
.default:hover {
  opacity: 0.9;
}

.dark {
  background-color: var(--ui-dark);
  color: var(--ui-theme-primary);
}
.dark:hover {
  opacity: 0.9;
}

.white {
  background-color: var(--ui-white);
  color: var(--ui-theme-primary);
}
.white:hover {
  opacity: 0.9;
}</style>
