<script lang="ts">
	import { Select as SelectPrimitive, type WithoutChild } from "bits-ui";
	import ChevronDown from "@lucide/svelte/icons/chevron-down";
	import { cn } from "$lib/utils.js";

	const inputSizes = {
		sm: "px-3 py-2 text-sm file:text-sm",
		default: "px-4 py-3",
		lg: "px-5 py-3 text-lg file:text-lg",
		xl: "px-6 py-4 text-xl file:text-xl",
	};

	let {
		ref = $bindable(null),
		class: className,
		children,
		inputSize = "default",
		overrideClasses = false,
		...restProps
	}: WithoutChild<SelectPrimitive.TriggerProps> & {
		inputSize?: keyof typeof inputSizes;
		overrideClasses?: boolean;
	} = $props();
</script>

<SelectPrimitive.Trigger
	bind:ref
	class={cn(
		!overrideClasses &&
			"flex w-full items-center justify-between rounded-lg border border-input bg-white shadow-sm transition-all file:border-0 file:bg-transparent file:font-medium placeholder:text-muted-foreground focus-visible:border-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-50 data-[placeholder]:text-muted-foreground [&>span]:line-clamp-1",
		inputSizes[inputSize],
		className,
	)}
	{...restProps}
>
	{@render children?.()}
	<ChevronDown class="size-4 opacity-50" />
</SelectPrimitive.Trigger>
