web/components/Cards/CardNormal/page.jsx

121 lines
4.1 KiB
React
Raw Permalink Normal View History

2024-02-05 01:40:57 +03:30
"use client";
2024-02-22 20:45:50 +03:30
import React, { useContext } from "react";
import { SwiperSlide } from "swiper/react";
2024-02-11 17:24:30 +03:30
import logo from "../../../public/images/logo.png";
2024-02-05 01:40:57 +03:30
import Image from "next/image";
import PersianNumber from "plugins/PersianNumber";
2024-02-22 20:45:50 +03:30
import AppContext from "@ctx/AppContext";
2024-03-01 16:31:14 +03:30
import AddToCart from "../Components/AddToCart/page";
2024-02-22 20:45:50 +03:30
import Link from "next/link";
2024-04-12 19:00:01 +03:30
import hyphenateString from "plugins/HyphenateString/page";
2024-02-05 01:40:57 +03:30
2024-03-03 22:37:31 +03:30
const CardNormal = ({ data, priority }) => {
2024-02-05 01:40:57 +03:30
const CTX = useContext(AppContext);
const cart = CTX.state.cart;
2024-04-26 01:26:50 +03:30
2024-04-12 19:00:01 +03:30
const hyphenatedName = hyphenateString(data.persianName);
2024-02-27 21:23:20 +03:30
2024-02-05 01:40:57 +03:30
return (
<>
{" "}
<>
2024-04-12 19:00:01 +03:30
<Link href={`/products/${data.id}/${hyphenatedName}`}>
2024-02-16 18:23:02 +03:30
<div
className={` tr03 py-2 overflow-hidden xs:h-[200px] lg:h-[230px] border border-gray-100 ${
1 == 1 ? "bg-white rounded-xl" : " opacity-70"
}`}
// key={index}
// onClick={() => handleRoutineShiftPlanWithDay(index)}
>
{data.hasDiscount && (
<div className="absolute m-3 ">
2024-08-23 12:46:00 +03:30
<div className="px-1 overflow-hidden bg-red-600 rounded-lg w-fit ">
2024-02-16 18:23:02 +03:30
<p className="mb-0 text-[10px] text-white pt-[3px] ">
<PersianNumber
number={data.discountPercent}
style={"!text-[10px]"}
/>
<small className="text-[10px] ml-1">%</small>
</p>
</div>
2024-02-11 17:24:30 +03:30
</div>
2024-02-16 18:23:02 +03:30
)}
2024-02-11 17:24:30 +03:30
2024-08-23 12:46:00 +03:30
<div className="flex justify-center w-full h-fit ">
2024-02-16 18:23:02 +03:30
{!!data.mainImage ? (
2024-02-11 17:24:30 +03:30
<Image
2024-08-23 12:46:00 +03:30
src={`${process.env.NEXT_PUBLIC_STORAGE_URL}/${data?.mainImage}`}
2024-02-22 20:45:50 +03:30
width={200}
height={200}
className="xs:!w-[110px] lg:!w-[130px] mx-auto"
2024-03-03 22:37:31 +03:30
priority={!!priority}
2024-02-29 11:59:52 +03:30
alt={`${data.persianName} - ${data.englishName}`}
2024-02-11 17:24:30 +03:30
/>
2024-02-16 18:23:02 +03:30
) : (
2024-02-22 20:45:50 +03:30
<div className="xs:!w-[85px] lg:!w-[85px] h-[90px] xs:mt-5 lg:mt-10 ">
2024-02-16 18:23:02 +03:30
<Image
src={logo}
2024-02-22 20:45:50 +03:30
className="xs:!w-[70px] lg:!w-[70px] mx-auto opacity-25 mt-5"
2024-02-29 11:59:52 +03:30
alt="وسمه"
2024-02-16 18:23:02 +03:30
/>
</div>
)}
</div>
<div className="p-3 text-right">
<p className="mb-0 text-[14px] max-h-[44px] overflow-hidden ">
2024-02-22 20:45:50 +03:30
{data.persianName}
2024-02-11 17:24:30 +03:30
</p>
2024-02-16 18:23:02 +03:30
2024-02-22 20:45:50 +03:30
{data.stock <= 3 && data.stock !== 0 && (
2024-02-16 18:23:02 +03:30
<p className="mb-0 text-[11px] text-red-600 font-medium">
2024-02-22 20:45:50 +03:30
{data.stock} عدد موجود انبار
2024-02-16 18:23:02 +03:30
</p>
)}
</div>
2024-02-05 01:40:57 +03:30
</div>
2024-02-16 18:23:02 +03:30
</Link>
2024-02-05 01:40:57 +03:30
</>
2024-08-23 12:46:00 +03:30
<div className="flex p-1 mt-2 border border-gray-100 rounded-lg bg-gray-50 ltr">
2024-02-11 17:24:30 +03:30
<div className="flex w-full">
2024-02-16 18:23:02 +03:30
<AddToCart data={data} theme={1} />
2024-02-05 01:40:57 +03:30
</div>
2024-08-23 12:46:00 +03:30
<div className="w-full pr-2 text-right rounded-full">
2024-02-11 17:24:30 +03:30
{data?.hasDiscount ? (
2024-02-05 01:40:57 +03:30
<>
<p className="mb-0 font-bold text-sm absolute right-3 opacity-30 mt-[-5px] text-red-600">
<del>
2024-02-11 17:24:30 +03:30
<PersianNumber
number={(data?.cost / 10).toLocaleString()}
style="!text-[11px]"
/>
2024-02-05 01:40:57 +03:30
</del>
</p>
<div className="flex rtl mt-[8px]">
{" "}
<p className="mb-0 font-bold">
2024-02-11 17:24:30 +03:30
<PersianNumber
number={(data?.costWithDiscount / 10).toLocaleString()}
/>
2024-02-05 01:40:57 +03:30
</p>
<small className="mr-1 mt-[3px]">تومان</small>
</div>
</>
) : (
<div className="flex rtl mt-[3px]">
{" "}
2024-08-23 12:46:00 +03:30
<p className="mb-0 text-lg font-bold">
2024-02-11 17:24:30 +03:30
<PersianNumber number={(data?.cost / 10).toLocaleString()} />
2024-02-05 01:40:57 +03:30
</p>
<small className="mr-1 mt-[6px]">تومان</small>
</div>
)}
</div>
</div>
</>
);
};
export default CardNormal;