<script>
  import { CoreCheckbox } from "@budibase/bbui"
  import Field from "./Field.svelte"

  export let field
  export let label
  export let text
  export let disabled = false
  export let size
  export let validation

  let fieldState
  let fieldApi
</script>

<Field
  {label}
  {field}
  {disabled}
  {validation}
  type="boolean"
  bind:fieldState
  bind:fieldApi
  defaultValue={false}
>
  {#if fieldState}
    <CoreCheckbox
      value={$fieldState.value}
      disabled={$fieldState.disabled}
      error={$fieldState.error}
      id={$fieldState.fieldId}
      {size}
      on:change={e => fieldApi.setValue(e.detail)}
      {text}
    />
  {/if}
</Field>
