import React, { ReactNode, ReactElement, ButtonHTMLAttributes } from "react"; import clsx from "clsx"; import { ChartBarIcon, DocumentChartBarIcon, EyeIcon, FolderPlusIcon, PencilIcon, PencilSquareIcon, TrashIcon, ViewfinderCircleIcon, } from "@heroicons/react/24/outline"; import { bgPrimaryColor, mobileBorders, textColorOnPrimary, } from "../../data/getColorBasedOnMode"; import { checkIsMobile } from "../../utils/checkIsMobile"; import { inputWidths } from "../../data/getItemsWidth"; import { PlusIcon } from "@heroicons/react/24/solid"; import { useUserProfileStore } from "../../context/zustand-store/userStore"; import excel from "../../assets/images/svg/excel.svg?react"; import SVGImage from "../SvgImage/SvgImage"; import api from "../../utils/axios"; import { useBackdropStore } from "../../context/zustand-store/appStore"; import { useToast } from "../../hooks/useToast"; type ExcelProps = { link: string; title: string; }; type ButtonProps = { children?: ReactNode | string; icon?: ReactElement; direction?: "row" | "row-reverse" | "col" | "col-reverse"; iconColor?: string; iconBgColor?: string; iconSize?: number | string; className?: string; variant?: | "submit" | "secondary-submit" | "edit" | "secondary-edit" | "detail" | "delete" | "view" | "info" | "chart"; access?: string; height?: string | number; fullWidth?: boolean; excelInfo?: ExcelProps; rounded?: boolean; size?: "small" | "medium" | "large"; } & ButtonHTMLAttributes; const Button: React.FC = ({ children, icon, direction = "row", iconSize, className = "", variant = "", access = "", height, fullWidth = false, excelInfo, rounded = false, size = "medium", ...props }) => { const directionClass = { row: "flex-row", "row-reverse": "flex-row-reverse", col: "flex-col", "col-reverse": "flex-col-reverse", }[direction]; const sizeStyles = { small: { padding: "h-[32px] px-2", text: "text-xs", icon: iconSize ?? 14, }, medium: { padding: "h-[40px] px-2", text: "text-sm", icon: iconSize ?? 18, }, large: { padding: "h-[48px] px-2", text: "text-base", icon: iconSize ?? 20, }, }[size] ?? { padding: "px-4 py-2", text: "text-sm", icon: iconSize ?? 18, }; const getVariantIcon = () => { switch (variant) { case "submit": return ( ); case "secondary-submit": return ( ); case "edit": return ( ); case "secondary-edit": return ( ); case "detail": return ( ); case "view": return ( ); case "delete": return ; case "info": return ( ); case "chart": return ( ); default: return null; } }; const { profile } = useUserProfileStore(); const { openBackdrop, closeBackdrop } = useBackdropStore(); const showToast = useToast(); const ableToSeeButton = () => { if (!access) { return true; } else { const permissions = profile?.permissions || []; // Check if access exists in the permissions array (simple array of strings) return permissions.includes(access); } }; return ( ); }; export default Button;