import { _decorator, Component, EditBox, Node } from 'cc';
import { tools } from '../../tools';
import { search_node } from './search_node';
import { event_item } from '../../../data/data';
import { config } from '../../config';
import { Attributes } from '../Attributes';
const { ccclass, property } = _decorator;

@ccclass('Search')
export class Search extends Component {
    @property(Node) btn_id_search:Node = null;
    @property(EditBox) editbox_id:EditBox = null;
    @property(Node) btn_text_search:Node = null;
    @property(EditBox) editbox_text:EditBox = null;
    @property(Node) search_node:Node = null;
    private m_id_callback: Function = null;
    private m_text_callback: Function = null;
    protected start(): void {
        this.btn_id_search.on(Node.EventType.TOUCH_END,()=>{
            if(this.editbox_id.string.length<=0){
                return tools.showToast("输入错误！")
            }

            // this.search_node.getComponent(search_node).show(this.editbox_id.string)
            if(this.m_id_callback != null) {
                this.m_id_callback(this.editbox_id.string)
            }
        })

        this.btn_text_search.on(Node.EventType.TOUCH_END,()=>{
            if(this.editbox_text.string.length<=0){
                return tools.showToast("输入错误！")
            }

            if(this.m_text_callback != null) {
                this.m_text_callback(this.editbox_text.string)
            }
        })

    }

    public searchClick(id_callback: Function, text_callback: Function) {
        this.m_id_callback = id_callback
        this.m_text_callback = text_callback
    }

    public showTip(item: event_item) {
        this.search_node.getComponent(search_node).show(item)
    }
}


