import { View,Text } from "@tarojs/components";
import React from "react";
import './RecordItem.scss'
import Taro from "@tarojs/taro";
import { TimeFormatter } from "@/utils/time_format";


export default function Component(props: { children: React.ReactNode,onClick?:Function, delete?: Function, canDel?: boolean }) {

    function click(e){
        if (props.onClick) {
            e.stopPropagation()
            props.onClick();
        }
        else {
            Taro.vibrateShort({
                type:'medium'
            });
        }
    }
    
    function longPress() {
        if (!props.delete) {
            return;
        }
        Taro.showActionSheet({
            itemList: ['删除']
        })
            .then(res => {
                switch (res.tapIndex) {
                    case 0:
                        Taro.showModal({
                            title: '删除',
                            content: '确认要删除吗？',
                            success: function (res) {
                                if (res.confirm) {
                                    props.delete!();
                                }
                            }
                        })
                        break;
                    case 1:

                        break;
                }
            })
            .catch(err => {
                console.log(err.errMsg)
            })

    }
    //gesture  onClick onLongPress 有效
    return <View className="recordItem" onLongPress={longPress} onClick={click}>
        {props.children}
        
    </View>
}