|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { Map as MapIcon, Shirt, Wind } from "lucide-react"; |
| 4 | +import type { MachinePosition, UserMachine } from "@/entities/machine"; |
| 5 | +import { Badge } from "@/shared/ui/badge"; |
| 6 | +import { Button } from "@/shared/ui/button"; |
| 7 | +import { |
| 8 | + Dialog, |
| 9 | + DialogContent, |
| 10 | + DialogDescription, |
| 11 | + DialogHeader, |
| 12 | + DialogTitle, |
| 13 | + DialogTrigger, |
| 14 | +} from "@/shared/ui/dialog"; |
| 15 | +import { |
| 16 | + getMachineCardStatus, |
| 17 | + MACHINE_STATUS_LEGEND, |
| 18 | +} from "../lib/machineCardStatus"; |
| 19 | + |
| 20 | +interface LayoutModalProps { |
| 21 | + floor: number; |
| 22 | + // 해당 층의 세탁기와 건조기 |
| 23 | + machines: UserMachine[]; |
| 24 | +} |
| 25 | + |
| 26 | +const MIN_SLOTS_PER_SIDE = 3; |
| 27 | + |
| 28 | +export default function LayoutModal({ floor, machines }: LayoutModalProps) { |
| 29 | + const maxNumber = Math.max( |
| 30 | + MIN_SLOTS_PER_SIDE, |
| 31 | + ...machines.map((machine) => machine.placement?.number ?? 0), |
| 32 | + ); |
| 33 | + // 입구에서 먼 번호부터 위에 둔다 (예: 3 → 2 → 1) |
| 34 | + const numbers = Array.from( |
| 35 | + { length: maxNumber }, |
| 36 | + (_, index) => maxNumber - index, |
| 37 | + ); |
| 38 | + |
| 39 | + const findMachine = ( |
| 40 | + position: MachinePosition, |
| 41 | + number: number, |
| 42 | + type: UserMachine["type"], |
| 43 | + ) => |
| 44 | + machines.find( |
| 45 | + (machine) => |
| 46 | + machine.type === type && |
| 47 | + machine.placement?.position === position && |
| 48 | + machine.placement.number === number, |
| 49 | + ); |
| 50 | + |
| 51 | + const renderColumn = (position: MachinePosition) => { |
| 52 | + const sideCode = position === "LEFT" ? "L" : "R"; |
| 53 | + |
| 54 | + return ( |
| 55 | + <div className="space-y-4"> |
| 56 | + <h4 className="mb-2 text-center font-medium text-[#6487DB]"> |
| 57 | + {position === "LEFT" ? "왼쪽" : "오른쪽"} |
| 58 | + </h4> |
| 59 | + {numbers.map((number) => ( |
| 60 | + <div key={number} className="space-y-2"> |
| 61 | + <MachineSlot |
| 62 | + machine={findMachine(position, number, "DRYER")} |
| 63 | + placeholder={`D${sideCode}${number}`} |
| 64 | + icon="DRYER" |
| 65 | + /> |
| 66 | + <MachineSlot |
| 67 | + machine={findMachine(position, number, "WASHER")} |
| 68 | + placeholder={`W${sideCode}${number}`} |
| 69 | + icon="WASHER" |
| 70 | + /> |
| 71 | + </div> |
| 72 | + ))} |
| 73 | + </div> |
| 74 | + ); |
| 75 | + }; |
| 76 | + |
| 77 | + return ( |
| 78 | + <Dialog> |
| 79 | + <DialogTrigger asChild> |
| 80 | + <Button |
| 81 | + variant="outline" |
| 82 | + size="sm" |
| 83 | + className="border-[#86A9FF] text-[#6487DB] hover:bg-[#EDF2FF]" |
| 84 | + > |
| 85 | + <MapIcon className="mr-1 h-4 w-4" /> |
| 86 | + 배치도 |
| 87 | + </Button> |
| 88 | + </DialogTrigger> |
| 89 | + <DialogContent className="max-h-[90vh] max-w-2xl overflow-y-auto sm:max-w-2xl"> |
| 90 | + <DialogHeader> |
| 91 | + <DialogTitle className="text-[#6487DB]"> |
| 92 | + {floor}층 세탁실 배치도 |
| 93 | + </DialogTitle> |
| 94 | + <DialogDescription> |
| 95 | + 세탁기는 아래, 건조기는 위에 배치되어 있습니다. |
| 96 | + </DialogDescription> |
| 97 | + </DialogHeader> |
| 98 | + |
| 99 | + <div className="space-y-6"> |
| 100 | + <div className="flex flex-wrap justify-center gap-2"> |
| 101 | + {MACHINE_STATUS_LEGEND.map(({ color, text }) => ( |
| 102 | + <Badge key={text} className={`${color} text-white`}> |
| 103 | + {text} |
| 104 | + </Badge> |
| 105 | + ))} |
| 106 | + </div> |
| 107 | + |
| 108 | + <div |
| 109 | + className="relative rounded-xl p-6 pb-12" |
| 110 | + style={{ |
| 111 | + background: |
| 112 | + "linear-gradient(135deg, #f0f4ff 0%, #e6f0ff 50%, #dae8ff 100%)", |
| 113 | + boxShadow: "inset 0 2px 10px rgba(100, 135, 219, 0.1)", |
| 114 | + }} |
| 115 | + > |
| 116 | + <div className="mx-auto grid max-w-md grid-cols-2 gap-8"> |
| 117 | + {renderColumn("LEFT")} |
| 118 | + {renderColumn("RIGHT")} |
| 119 | + </div> |
| 120 | + |
| 121 | + <div className="absolute bottom-3 left-1/2 -translate-x-1/2"> |
| 122 | + <div className="rounded-full bg-[#86A9FF] px-3 py-1 text-xs font-medium text-white"> |
| 123 | + 입구 |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + </div> |
| 127 | + </div> |
| 128 | + </DialogContent> |
| 129 | + </Dialog> |
| 130 | + ); |
| 131 | +} |
| 132 | + |
| 133 | +interface MachineSlotProps { |
| 134 | + machine?: UserMachine; |
| 135 | + placeholder: string; |
| 136 | + icon: UserMachine["type"]; |
| 137 | +} |
| 138 | + |
| 139 | +function MachineSlot({ machine, placeholder, icon }: MachineSlotProps) { |
| 140 | + const Icon = icon === "DRYER" ? Wind : Shirt; |
| 141 | + const status = machine ? getMachineCardStatus(machine) : null; |
| 142 | + |
| 143 | + return ( |
| 144 | + <div |
| 145 | + className={`relative flex h-16 transform items-center justify-center rounded-lg border-2 border-gray-300 text-xs font-medium transition-all duration-200 hover:scale-105 hover:shadow-lg ${ |
| 146 | + status ? `${status.color} text-white` : "text-gray-400" |
| 147 | + }`} |
| 148 | + style={{ |
| 149 | + background: status |
| 150 | + ? undefined |
| 151 | + : "linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%)", |
| 152 | + boxShadow: status |
| 153 | + ? "0 4px 12px rgba(0,0,0,0.15)" |
| 154 | + : "0 2px 6px rgba(0,0,0,0.1)", |
| 155 | + }} |
| 156 | + > |
| 157 | + <Icon className="mr-1 h-4 w-4 shrink-0" /> |
| 158 | + <span className="truncate px-1"> |
| 159 | + {machine ? machine.name : placeholder} |
| 160 | + </span> |
| 161 | + {machine && ( |
| 162 | + <div className="absolute -top-1 -right-1"> |
| 163 | + <div className="h-3 w-3 animate-pulse rounded-full bg-white/30" /> |
| 164 | + </div> |
| 165 | + )} |
| 166 | + </div> |
| 167 | + ); |
| 168 | +} |
0 commit comments