import { Product } from "@/lib/product" import { useState } from "react" import { FlatList, StyleSheet, Text, TouchableHighlight, View } from "react-native" import {ProductAttributeEditor} from "./ProductAttributeEditor"; import React from "react"; export type ProductUpdatedFunc = (product_id: string, product: Product) => any; export type ProductDeletedFunc = (product_id: string) => any; export type ProductEditorItemProps = { product: Product, onProductUpdated?: ProductUpdatedFunc, onProductDeleted?: ProductDeletedFunc, } export const ProductEditorItem = ({ product, onProductUpdated, onProductDeleted }: ProductEditorItemProps) => { const [showAttributes, setShowAttributes] = useState(false); function onAttributeChanged(product_id: string, key: string, newValue: string) { product.attributes[key] = newValue; onProductUpdated && onProductUpdated(product_id, product); } function onAttributeDelete(product_id: string, key: string) { product.removeAttribute(key); onProductDeleted && onProductDeleted(product_id); } return ( setShowAttributes(!showAttributes)} aria-label="Product Item" > {product.attributes.name || `Product ${product.id}`} {showAttributes && ( ( )} keyExtractor={(item) => `${product.id}-${item.key}`} /> ) } ) } const styles = StyleSheet.create({ product: {}, })