import React, { Component, useState } from 'react';
import CustomTrigger from './CustomTrigger';
import AutoComplete from '../index';
import { Form, Avatar } from '../../index';
import { IconSearch } from '@douyinfe/semi-icons';
import { debounce } from 'lodash';
export default {
    title: 'AutoComplete',
    parameters: {
        chromatic: { disableSnapshot: true },
    },
};
const props = {
    onBlur: (v, e) => {
        console.log('onBlur');
        console.log(v, e);
    },
    onFocus: (v, e) => {
        console.log('onFocus');
        console.log(v, e);
    },
};
class Demo extends React.Component {
    constructor() {
        super();
        this.state = {
            data: [],
            data2: ['mike', 'tony', 'steve'],
        };
        this.acref = React.createRef();
    }
    handleSearch(value) {
        // let data =  !value ? [] : [value, value + value, value + value + value];
        let result; // if (!value || value.indexOf('@') >= 0) {
        //     result = [];
        // } else {
        if (value) {
            result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
        } else {
            result = [];
        } // }
        this.setState({
            data: result,
        });
    }
    handleSearch2(value) {
        // let data2 =  !value ? [] : [value, value + value, value + value + value];
        let result;
        if (!value || value.indexOf('@') >= 0) {
            result = [];
        } else {
            result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
        }
        this.setState({
            data2: result,
        });
    }
    render() {
        const { data, data2 } = this.state;
        return (
            
                }
                    showClear
                    data={data}
                    style={{
                        width: 300,
                    }}
                    onSearch={this.handleSearch.bind(this)}
                    onSelect={v => console.log(v)}
                    {...props}
                    ref={this.acref}
                />
            
 
        );
    }
}
export const BasicUsage = () => ;
class CustomOptionDemo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            data: [],
            data2: [],
        };
    }
    search = value => {
        let result;
        if (!value) {
            result = [];
        } else {
            result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
        }
        this.setState({
            data: result,
        });
    };
    renderOption = item => {
        return (
            <>
                
                    邮箱
                
                : {item}
            >
        );
    };
    search2 = value => {
        let result;
        if (!value) {
            result = [];
        } else {
            result = ['gmail.com', '163.com', 'qq.com'].map(domain => {
                return {
                    email: `${value}@${domain}`,
                    time: new Date().valueOf(),
                    value: `${value}@${domain}`,
                };
            });
        }
        this.setState({
            data2: result,
        });
    };
    renderObjectOption = item => {
        return (
            
                
                    邮箱
                
                : {item.email}
                time: {item.time}
            
        );
    };
    render() {
        return (
            <>
                
                
                
                 node.email}
                    data={this.state.data2}
                    onSearch={this.search2}
                />
            >
        );
    }
}
export const RenderItem = () => ;
class WithDefaultValue extends React.Component {
    constructor() {
        super();
        this.state = {
            data: ['semi@bytedance.com', 'semi@gmail.com', 'semi@163.com'],
        };
        this.onSearch = this.onSearch.bind(this);
    }
    onSearch(value) {
        let result;
        if (!value) {
            result = [];
        } else {
            result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
        }
        this.setState({
            data: result,
        });
    }
    render() {
        let { data } = this.state;
        return (
            <>
                {/*  */}
                
            >
        );
    }
}
export const DefaultValue = () => ;
class ControlledMode extends React.Component {
    constructor() {
        super();
        this.state = {
            data: [],
            dataObject: [],
            value: '',
        };
        this.onSearch = this.onSearch.bind(this);
        this.onChange = this.onChange.bind(this);
    }
    onSearch(value) {
        let result, resultObject;
        if (!value) {
            result = [];
            resultObject = [];
        } else {
            result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
            resultObject = ['gmail.com', '163.com', 'qq.com'].map(domain => ({
                label: `${value}@${domain}`,
                value: `${value}@${domain}`,
            }));
        }
        this.setState({
            data: result,
            dataObject: resultObject,
        });
    }
    onChange(value) {
        this.setState({
            value: value,
        });
    }
    render() {
        let { data, value, dataObject } = this.state;
        return (
            <>
                
                
                
                
                
            >
        );
    }
}
export const EmptyContent = () => {
    let [data, setData] = useState([]);
    const [loading, setLoading] = useState(false);
    const fetchData = v => {
        setLoading(true);
        setTimeout(() => {
            if (!v) {
                setData([]);
                setLoading(false);
                return;
            }
            setData(() => {
                const res = Array.from(Array(5)).map(c => Math.random());
                return res;
            });
            setLoading(false);
        }, 1000);
    };
    return ;
};
export const AutoFocus = () => {
    return ;
};
export const ControlledValue = () => ;
export const CustomTriggerDemo = () => ;
export const Disabled = () => ;
export const KeyDown = () => (
     {
            console.log('onKeyDown', e.keyCode);
        }}
    />
);
export const ControlledOnSelectWithObjectDemo = () => {
    const [v, setV] = useState();
    return (
        
    );
};
export const AutoScrollToKeyboardUpDown = () => {
    const [data, setData] = useState([]);
    const getData = (v) => {
        let newData = Array.from({ length: 20 }, (v, i) => ({ label: `option-${i}`, value: i, 'data-cy': `option-${i}` }));
        setData(newData);
    };
    
    const renderOption = (item) => {
        let optionStyle = {
            display: 'flex',
        };
        return (
            <>
                
                    Semi
                
                
                    {item.label}
                    {item.value}
                 
            >
        );
    }
    return <>
         getData(v)}
            style={{ width: 320 }}
        >
        
         getData(v)}
            style={{ width: 320 }}
        >
        
    >
}
export const Fix2951 = () => {
     let initList = [
        '1.60','1.62','1.63','1.64'
    ];
    const [loading, setLoading] = useState(false);
    const [list, setList] = useState([]);
    const handleSearch = (inputValue) => {
        setLoading(true);
        let newList = [];
        if (inputValue) {
            newList = initList.filter(item => item.includes(inputValue));
        }
        setTimeout(() => {
            setList(newList);
            setLoading(false);
        }, 1000);
    };
    const search = debounce(handleSearch, 200);
    return (
        }
            onSearch={search}
            loading={loading}
            defaultActiveFirstOption={true}
        >
    );
}