<template>
    <button @click="() => click()" class="base-shape button pointer center" :class="{ loading: loading, reverse: reverse, disabled: disabled }"><UiIcon v-if="icon && !loading">{{ icon }}</UiIcon><UiLoadingIcon v-if="loading"></UiLoadingIcon><slot></slot></button>
</template>

<script setup lang="ts">
import UiIcon from '@/components/ui/UiIcon.vue';

function click() {
    if(props.disabled !== true) { 
        if(props.onclick != null) {
            props.onclick() 
        }
        if(props.to != null) {
            useRouter().push(props.to);
        }
    }
}

const props = defineProps<{
    icon?: string,
    reverse?: boolean,
    loading?: boolean | undefined,
    disabled?: boolean,
    onclick?: () => void
    to?: string
}>();
</script>

<style>
.button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    outline: none;
    gap: 0.5rem;
    border: 2px solid var(--primary-color);
    white-space: nowrap;
    border-radius: 0.25rem;
    font-weight: 500;
}
.button.square {
    padding: 0;
    aspect-ratio: 1/1;
}
.button:hover {
    cursor: pointer;
}
.button * {
    color: white;
    fill: white;
}
.button.secondary {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
}
.button:hover.secondary {
    background-color: var(--secondary-color-alt);
}
.button.reverse {
    flex-direction: row-reverse;
}
.button.loading {
    background-color: #5c5c5c;
    border-color: #5c5c5c;
    cursor: default;
}
.button.disabled {
    background-color: #7a7a7a;
    border-color: #7a7a7a;
    cursor: default;
}
.button.hollow {
    background-color: white;
    border: 2px solid var(--primary-color);;
    color: var(--primary-color);
}
.button.hollow * {
    color: var(--primary-color);
}
.button.hollow:hover {
    background-color: rgba(0, 0, 0, 0.055);
}
.border.secondary.hollow {
    border: 2px solid var(--secondary-color);;
    color: var(--secondary-color);
}
.reverse {
    flex-direction: row-reverse;
}
.button.small {
    height: 2rem;
    padding: 0 0.5rem;
}
.button.small * {
    font-size: 1.25rem;
}
.button.extra-small {
    height: 1.25rem;
    padding: 0 0.25rem;
    border-radius: 0.25rem;
    gap: 0.25rem;
}
</style>