<script>import { useTheme } from "./theme.js";
import newUniqueId from "./utils/uniqId.js";
import FormLabel from "./FormLabel.svelte";
export let error = void 0;
export let errorText = void 0;
export let icon = void 0;
export let name = newUniqueId("sveltify-select");
export let placeholder = "";
export let required = false;
export let label = void 0;
export let description = void 0;
export let value = "";
export let attributes = {};
export let options = [];
export let theme = "default";
const c = useTheme().forms[theme];
const removeError = () => {
  error = false;
};
</script>

<div {...attributes} class={`group flex flex-col ${c.container}`}>
	<FormLabel {label} {error} {errorText} {theme} />
	<div class={`flex items-center transition-all ${c.inputContainer}`}>
		{#if icon}
			<div class={`${c.iconContainer}`}>
				<svelte:component this={icon} size={c.iconSize} />
			</div>
		{/if}
		<select
			class={`flex-1 outline-0 w-full h-full ${c.input}`}
			id={name}
			{name}
			on:change={removeError}
			{required}
			bind:value
		>
			{#if !value}
				<option value="" disabled selected hidden>{placeholder}</option>
			{/if}
			{#each options as option}
				<option value={option.value}>{option.label}</option>
			{/each}
		</select>
	</div>
	{#if description}
		<div class={`${c.description}`}>{description}</div>
	{/if}
</div>
