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


export default function Component(props: { children: React.ReactNode, onClick?: Function, delete?: Function, canDel?: boolean }) {
    const { t } = useTranslation()
    function click(e) {
        if (props.onClick) {
            if (process.env.TARO_ENV == 'weapp') {
                e.stopPropagation()
            }
            props.onClick();
        }
        else {
            Taro.vibrateShort({
                type: 'medium'
            });
        }
    }

    function longPress() {
        if (!props.delete) {
            return;
        }
        Taro.showActionSheet({
            itemList: [t('feature.common.action_sheet.delete')]
        })
            .then(res => {
                switch (res.tapIndex) {
                    case 0:
                        Taro.showModal({
                            title: t('feature.common.modal.delete_item_title'),
                            content: t('feature.common.modal.delete_item_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>
}