import React, { useState } from 'react'; import { Card, Typography, Tag, Button, Modal, Row, Col, Space } from 'antd'; import { EyeOutlined, DeleteOutlined, CheckOutlined } from '@ant-design/icons'; import dayjs from 'dayjs'; const { Text, Title } = Typography; const CustomSparepartCard = ({ sparepart, isSelected = false, isReadOnly = false, showPreview = true, showDelete = false, onPreview, onDelete, onCardClick, loading = false, size = 'small', style = {}, }) => { const [previewModalVisible, setPreviewModalVisible] = useState(false); const getImageSrc = () => { if (sparepart.sparepart_foto) { if (sparepart.sparepart_foto.startsWith('http')) { return sparepart.sparepart_foto; } else { const fileName = sparepart.sparepart_foto.split('/').pop(); if (fileName === 'defaultSparepartImg.jpg') { return `/assets/defaultSparepartImg.jpg`; } else { const token = localStorage.getItem('token'); const baseURL = import.meta.env.VITE_API_SERVER || ''; return `${baseURL}/file-uploads/images/${encodeURIComponent(fileName)}${token ? `?token=${encodeURIComponent(token)}` : ''}`; } } } return 'https://via.placeholder.com/150'; }; const handlePreview = () => { if (onPreview) { onPreview(sparepart); } else { setPreviewModalVisible(true); } }; const truncateText = (text, maxLength = 15) => { if (!text) return 'Unnamed'; return text.length > maxLength ? `${text.substring(0, maxLength)}...` : text; }; const handleCardClick = () => { if (!isReadOnly && onCardClick) { onCardClick(sparepart); } }; const getCardActions = () => { const actions = []; if (showPreview) { actions.push( } title="Lihat Detail" style={{ color: '#1890ff' }} onClick={(e) => { e.stopPropagation(); handlePreview(); }} /> ); } if (showDelete && !isReadOnly) { actions.push( } title="Hapus" style={{ color: '#ff4d4f' }} onClick={(e) => { e.stopPropagation(); onDelete?.(sparepart); }} /> ); } return actions; }; const getCardStyle = () => { const baseStyle = { borderRadius: '12px', overflow: 'hidden', border: isSelected ? '2px solid #1890ff' : '1px solid #E0E0E0', cursor: isReadOnly ? 'default' : 'pointer', position: 'relative', boxShadow: '0 2px 8px rgba(0,0,0,0.06)', transition: 'all 0.3s ease' }; switch (size) { case 'small': return { ...baseStyle, height: '180px', minHeight: '180px' }; case 'large': return { ...baseStyle, height: '280px', minHeight: '280px' }; default: return { ...baseStyle, height: '220px', minHeight: '220px' }; } }; return ( <>