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

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

function click() {
    if(!props.disabled) {
        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;
    outline: none;
    gap: 0.5rem;
    white-space: nowrap;
    border-radius: 0.25rem;
    font-weight: 500;
    font-size: 1rem;
    border: none;
}
.button * {
    color: white;
    fill: white;
}
.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;
}
.reverse {
    flex-direction: row-reverse;
}
</style>