import React, { useState } from 'react' import { PutawayStrategyEnum } from '../../../types/wm' import { FaSearch, FaPlus, FaEdit, FaTrash, FaCog, FaBullseye, FaCheckCircle, FaExclamationCircle, FaFilter, FaArrowDown, FaTh, FaList, } from 'react-icons/fa' import { mockPutawayRules } from '../../../mocks/mockPutawayRules' import { mockWarehouses } from '../../../mocks/mockWarehouses' import { mockZones } from '../../../mocks/mockZones' import { mockLocations } from '../../../mocks/mockLocations' import { mockMaterialTypes } from '../../../mocks/mockMaterialTypes' import { mockMaterialGroups } from '../../../mocks/mockMaterialGroups' import { getPutawayStrategyColor, getPutawayStrategyText, getConditionTypeText, getConditionOperatorText, } from '../../../utils/erp' import { Container } from '@/components/shared' const PutawayRules: React.FC = () => { const [searchTerm, setSearchTerm] = useState('') const [selectedStrategy, setSelectedStrategy] = useState('') const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid') const [showRuleForm, setShowRuleForm] = useState(false) const [editingRuleId, setEditingRuleId] = useState(null) const [selectedRule, setSelectedRule] = useState('') // Form States const [formData, setFormData] = useState({ name: '', ruleCode: '', description: '', warehouseId: '', materialTypeId: '', materialGroupId: '', priority: 1, targetZoneId: '', targetLocationId: '', strategy: PutawayStrategyEnum.FIFO, isActive: true, }) // Helper functions for names const getWarehouseName = (warehouseId: string | undefined) => { if (!warehouseId) return 'Belirtilmemiş' const warehouse = mockWarehouses.find((w) => w.id === warehouseId) return warehouse ? warehouse.name : `Depo ${warehouseId}` } const getZoneName = (zoneId: string | undefined) => { if (!zoneId) return 'Belirtilmemiş' const zone = mockZones.find((z) => z.id === zoneId) return zone ? zone.name : `Bölge ${zoneId}` } const getLocationName = (locationId: string | undefined) => { if (!locationId) return 'Belirtilmemiş' const location = mockLocations.find((l) => l.id === locationId) return location ? location.name : `Lokasyon ${locationId}` } const getMaterialTypeName = (materialTypeId: string | undefined) => { if (!materialTypeId) return 'Belirtilmemiş' const materialType = mockMaterialTypes.find((mt) => mt.id === materialTypeId) return materialType ? materialType.name : `Tip ${materialTypeId}` } const getMaterialGroupName = (materialGroupId: string | undefined) => { if (!materialGroupId) return 'Belirtilmemiş' const materialGroup = mockMaterialGroups.find((mg) => mg.id === materialGroupId) return materialGroup ? materialGroup.name : `Grup ${materialGroupId}` } // Form Functions const resetForm = () => { setFormData({ name: '', ruleCode: '', description: '', warehouseId: '', materialTypeId: '', materialGroupId: '', priority: 1, targetZoneId: '', targetLocationId: '', strategy: PutawayStrategyEnum.FIFO, isActive: true, }) } const handleEditRule = (ruleId: string) => { const rule = mockPutawayRules.find((r) => r.id === ruleId) if (rule) { setFormData({ name: rule.name, ruleCode: rule.code, description: rule.description || '', warehouseId: rule.warehouseId, materialTypeId: rule.materialTypeId || '', materialGroupId: rule.materialGroupId || '', priority: rule.priority, targetZoneId: rule.targetZoneId || '', targetLocationId: rule.targetLocationId || '', strategy: rule.strategy, isActive: rule.isActive, }) } setEditingRuleId(ruleId) setShowRuleForm(true) } const handleNewRule = () => { resetForm() setEditingRuleId(null) setShowRuleForm(true) } const handleCloseForm = () => { setShowRuleForm(false) setEditingRuleId(null) resetForm() } const handleSubmitForm = () => { // Form validation and submission logic here console.log('Form Data:', formData) handleCloseForm() } const filteredRules = mockPutawayRules.filter((rule) => { const matchesSearch = rule.name.toLowerCase().includes(searchTerm.toLowerCase()) || rule.code.toLowerCase().includes(searchTerm.toLowerCase()) const matchesStrategy = selectedStrategy === '' || rule.strategy === selectedStrategy return matchesSearch && matchesStrategy }) const RuleDetailModal = () => { const rule = mockPutawayRules.find((r) => r.id === selectedRule) if (!selectedRule || !rule) return null return (
setSelectedRule('')} />

{rule.name} - Kural Detayları

{/* Rule Info */}

Kural Bilgileri

Kod: {rule.code}
Açıklama: {rule.description}
Öncelik: {rule.priority}
Strateji: {getPutawayStrategyText(rule.strategy)}
Durum: {rule.isActive ? ( Aktif ) : ( Pasif )}
{/* Conditions */}

Koşullar ({rule.conditions.length})

{rule.conditions.map((condition, index) => (
Koşul {index + 1}
{getConditionTypeText(condition.conditionType)} {getConditionOperatorText(condition.operator)} {condition.value}
))} {rule.conditions.length === 0 && (
Koşul tanımlanmamış
)}
{/* Target Info */}

Hedef Lokasyon

Depo: {getWarehouseName(rule.warehouseId)}
Hedef Bölge: {getZoneName(rule.targetZoneId)}
Hedef Lokasyon: {getLocationName(rule.targetLocationId)}
{rule.materialTypeId && (
Malzeme Tipi: {getMaterialTypeName(rule.materialTypeId)}
)} {rule.materialGroupId && (
Malzeme Grubu: {getMaterialGroupName(rule.materialGroupId)}
)}
) } return (

Yerleştirme Kuralları

Malzeme yerleştirme kurallarını tanımlayın ve yönetin

{/* View Mode Toggle */}
{/* Filters */}
setSearchTerm(e.target.value)} className="pl-10 pr-4 py-1.5 text-sm w-full border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" />
{/* Rules Display */} {viewMode === 'grid' ? ( // Grid View (Kart Görünümü)
{filteredRules.map((rule) => (

{rule.name}

{rule.code}

Öncelik: {rule.priority} {rule.isActive ? ( ) : ( )}

{rule.description}

{getPutawayStrategyText(rule.strategy)} {/* Conditions Summary */}

Koşullar ({rule.conditions.length})

{rule.conditions.length > 0 ? (
{rule.conditions.slice(0, 2).map((condition) => (
{getConditionTypeText(condition.conditionType)} {getConditionOperatorText(condition.operator)} {condition.value}
))} {rule.conditions.length > 2 && (
+{rule.conditions.length - 2} koşul daha
)}
) : (
Koşul tanımlanmamış
)} {/* Target Info */}

Hedef

Depo: {getWarehouseName(rule.warehouseId)}
{rule.targetZoneId &&
Bölge: {getZoneName(rule.targetZoneId)}
} {rule.targetLocationId && (
Lokasyon: {getLocationName(rule.targetLocationId)}
)} {rule.materialTypeId && (
Malzeme Tipi: {getMaterialTypeName(rule.materialTypeId)}
)} {rule.materialGroupId && (
Malzeme Grubu: {getMaterialGroupName(rule.materialGroupId)}
)}
{rule.isActive ? ( <> Aktif ) : ( <> Pasif )}
))}
) : ( // List View (Liste Görünümü)
{filteredRules.map((rule) => ( ))}
Kural Strateji Depo Hedef Lokasyon Koşullar Öncelik Durum İşlemler
{rule.name}
{rule.code}
{getPutawayStrategyText(rule.strategy)} {getWarehouseName(rule.warehouseId)}
{rule.targetZoneId &&
Bölge: {getZoneName(rule.targetZoneId)}
} {rule.targetLocationId && (
Lokasyon: {getLocationName(rule.targetLocationId)}
)}
{rule.conditions.length > 0 ? (
{rule.conditions.slice(0, 1).map((condition) => (
{getConditionTypeText(condition.conditionType)}{' '} {getConditionOperatorText(condition.operator)} {condition.value}
))} {rule.conditions.length > 1 && (
+{rule.conditions.length - 1} koşul daha
)}
) : ( Koşul yok )}
{rule.priority}
{rule.isActive ? ( <> Aktif ) : ( <> Pasif )}
)} {filteredRules.length === 0 && (

Kural bulunamadı

Arama kriterlerinize uygun yerleştirme kuralı bulunamadı.

)}
{/* Rule Detail Modal */} {/* Rule Form Modal */} {showRuleForm && (
{ setShowRuleForm(false) setEditingRuleId(null) }} />

{editingRuleId ? 'Yerleştirme Kuralını Güncelle' : 'Yeni Yerleştirme Kuralı'}

{/* Form Content */}
{/* Basic Information */}
setFormData({ ...formData, name: e.target.value })} className="w-full px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Kural adını girin" required />
setFormData({ ...formData, ruleCode: e.target.value })} className="w-full px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="PR001" required />