<script lang="ts">
  import { Command as CommandPrimitive } from "cmdk-sv";
  import { Search } from "lucide-svelte";
  import { cn } from "$lib/utils";
  import { createEventDispatcher } from "svelte";

  type $$Props = CommandPrimitive.InputProps;

  let className: string | undefined | null = undefined;
  export { className as class };
  export let value: string = "";

  const dispatch = createEventDispatcher();

  function handleInput(event: Event) {
    const target = event.target as HTMLInputElement;
    value = target.value;
    dispatch("input", value);
  }
</script>

<div class="flex items-center border-b px-3" data-cmdk-input-wrapper="">
  <Search class="mr-2 h-4 w-4 shrink-0 opacity-50" />
  <input
    class={cn(
      "flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
      className
    )}
    type="text"
    bind:value
    on:input={handleInput}
    {...$$restProps}
  />
</div>
