// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import type { JSXElement } from "@coreai-ds/react-components";
import { useId } from "@coreai-ds/react-components";
import { makeStyles } from "@coreai-ds/react-components";
import { Label } from "@coreai-ds/react-components";
import { Input } from "@coreai-ds/react-components";
import type { InputProps } from "@coreai-ds/react-components";
import * as React from 'react';

const useStyles = makeStyles({
    root: {
        // Stack the label above the field
        display: 'flex',
        flexDirection: 'column',
        // Use 2px gap below the label (per the design system)
        gap: '2px',
        // Prevent the example from taking the full width of the page (optional)
        maxWidth: '400px',
    },
});

const onChange: InputProps['onChange'] = (ev, data) => {
    // Uncontrolled inputs can be notified of changes to the value
    console.log(`New value: "${data.value}"`);
};

export const Uncontrolled = (): JSXElement => {
    const inputId = useId('input');
    const styles = useStyles();
    return (<div className={styles.root}>
      <Label htmlFor={inputId}>Uncontrolled input with default value</Label>
      <Input defaultValue="default value" onChange={onChange} id={inputId}/>
    </div>);
};

export default Uncontrolled;
