2024-07-12 15:14:14 +02:00
|
|
|
import { area_t } from "@/lib/dimensions";
|
2024-08-10 19:06:25 +02:00
|
|
|
import { Product } from "@/lib/product";
|
2024-07-12 15:14:14 +02:00
|
|
|
import convert, { Area, Length } from "convert";
|
|
|
|
import dayjs, { Dayjs } from "dayjs";
|
|
|
|
import { StyleSheet, Text, View } from "react-native";
|
|
|
|
|
|
|
|
export type AreaRugTagProps = {
|
|
|
|
dimensions: area_t,
|
2024-08-10 19:06:25 +02:00
|
|
|
product: Product,
|
2024-07-12 15:14:14 +02:00
|
|
|
date?: Dayjs
|
|
|
|
currencySymbol?: string
|
|
|
|
};
|
|
|
|
|
|
|
|
export const AreaRugTag = (props: AreaRugTagProps) => {
|
|
|
|
const date = props.date || dayjs();
|
|
|
|
const square = props.dimensions.l * props.dimensions.w;
|
2024-08-10 19:06:25 +02:00
|
|
|
const areaUnits = `sq ${props.dimensions.u}`;
|
|
|
|
const square2 = convert(square, areaUnits as Area).to("sq " + props.product.dimensions.u as Area)
|
|
|
|
const price = (square2 / props.product.pricePerUnit) * props.product.pricePerUnit;
|
2024-07-12 15:14:14 +02:00
|
|
|
const sPrice = price.toLocaleString(undefined, {
|
|
|
|
minimumFractionDigits: 2,
|
|
|
|
maximumFractionDigits: 2,
|
|
|
|
})
|
|
|
|
const currencySymbol = props.currencySymbol || "$";
|
|
|
|
return (
|
2024-08-10 19:06:25 +02:00
|
|
|
<View aria-label="area rug tag" style={styles.component}>
|
|
|
|
<Text aria-label="area rug dimensions" style={styles.dimensions}>{Math.round(props.dimensions.l)} x {Math.round(props.dimensions.w)}</Text>
|
2024-07-12 15:14:14 +02:00
|
|
|
<Text aria-label="area rug price" style={styles.price}>{currencySymbol} {sPrice}</Text>
|
|
|
|
<Text aria-label="area rug date" style={styles.date}>{date.format("YYYY/MM/DD")}</Text>
|
|
|
|
<Text aria-label="this week's color" style={styles.tagColor}>[Curent Tag Color]</Text>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
2024-08-15 23:07:19 +02:00
|
|
|
const BIG_FONT_SIZE = 30;
|
|
|
|
|
2024-07-12 15:14:14 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
component: {
|
2024-08-15 23:07:19 +02:00
|
|
|
alignItems: "center",
|
2024-07-12 15:14:14 +02:00
|
|
|
},
|
|
|
|
dimensions: {
|
2024-08-15 23:07:19 +02:00
|
|
|
fontSize: BIG_FONT_SIZE,
|
2024-07-12 15:14:14 +02:00
|
|
|
},
|
|
|
|
price: {
|
2024-08-15 23:07:19 +02:00
|
|
|
fontSize: BIG_FONT_SIZE,
|
2024-07-12 15:14:14 +02:00
|
|
|
},
|
|
|
|
date: {
|
2024-08-15 23:07:19 +02:00
|
|
|
fontSize: BIG_FONT_SIZE,
|
2024-07-12 15:14:14 +02:00
|
|
|
},
|
|
|
|
tagColor: {
|
2024-08-15 23:07:19 +02:00
|
|
|
fontSize: BIG_FONT_SIZE,
|
2024-07-12 15:14:14 +02:00
|
|
|
},
|
|
|
|
})
|