<script lang="ts">
    import { preferences } from '../stores/auth';
    import type { Size, Preference } from '../types';
    import { createEventDispatcher } from 'svelte';
   export let open: boolean; 

    let preference: Preference = {
        color: "#00FF00",
        size: {
            size: 8,
            unit: 'oz'
        }
    }

    const dispatch = createEventDispatcher();
    
    preferences.subscribe((value) => {
        preference = value;
    });

    function onPreferencesSave(): void {
        preferences.set(preference);
        dispatch('close')
    }

</script>
<dialog {open} on:submit|preventDefault={onPreferencesSave}>
    <h2>User Preferences</h2>
    <form method="dialog">
        <div class="form input group">
            <label for="color">Color</label>
            <input id="color" name="color" type="color" bind:value={preference.color}/>
        </div>
        <div class="form input group">
            <label for="size">Bottle Size</label>
            <input id="size" name="size" type="number" min="8" max="48" step="8" bind:value={preference.size.size}/>
        </div>
        <button type="submit">Save</button>
    </form>
</dialog>
<style>
dialog {
    background: white;
    color: black;
}

input[type="color"] {
   width: 100%;
   height: 100%;
}
</style>
