summaryrefslogtreecommitdiff
path: root/lib/vendors/table/update-vendor-sheet.tsx
blob: d8d4ad67396e700015234f92e87abf0edb361315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
"use client"

import * as React from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { 
  Loader, 
  Activity, 
  AlertCircle, 
  AlertTriangle, 
  ClipboardList, 
  FilePenLine, 
  XCircle, 
  ClipboardCheck, 
  FileCheck2, 
  FileX2, 
  BadgeCheck,
  CheckCircle2,
  Circle as CircleIcon,
  User,
  Building
} from "lucide-react"
import { toast } from "sonner"

import { Button } from "@/components/ui/button"
import {
  Form,
  FormControl,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
  FormDescription
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import {
  Sheet,
  SheetClose,
  SheetContent,
  SheetDescription,
  SheetFooter,
  SheetHeader,
  SheetTitle,
} from "@/components/ui/sheet"
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select"
import { Separator } from "@/components/ui/separator"
import { useSession } from "next-auth/react" // Import useSession

import { VendorWithType, vendors } from "@/db/schema/vendors"
import { updateVendorSchema, type UpdateVendorSchema } from "../validations"
import { modifyVendor } from "../service"

interface UpdateVendorSheetProps
  extends React.ComponentPropsWithRef<typeof Sheet> {
  vendor: VendorWithType | null
}
type StatusType = (typeof vendors.status.enumValues)[number];

type StatusConfig = {
  Icon: React.ElementType;
  className: string;
  label: string;
};

// 상태 표시 유틸리티 함수
const getStatusConfig = (status: StatusType): StatusConfig => {
  switch(status) {
    case "PENDING_REVIEW":
      return { 
        Icon: ClipboardList,
        className: "text-yellow-600", 
        label: "가입 신청 중"
      };
    case "IN_REVIEW":
      return { 
        Icon: FilePenLine,
        className: "text-blue-600", 
        label: "심사 중"
      };
    case "REJECTED":
      return { 
        Icon: XCircle,
        className: "text-red-600", 
        label: "심사 거부됨"
      };
    case "IN_PQ":
      return { 
        Icon: ClipboardCheck,
        className: "text-purple-600",
        label: "PQ 진행 중"
      };
    case "PQ_SUBMITTED":
      return { 
        Icon: FileCheck2,
        className: "text-indigo-600", 
        label: "PQ 제출"
      };
    case "PQ_FAILED":
      return { 
        Icon: FileX2,
        className: "text-red-600", 
        label: "PQ 실패"
      };
    case "PQ_APPROVED":
      return { 
        Icon: BadgeCheck,
        className: "text-green-600", 
        label: "PQ 통과"
      };
    case "APPROVED":
      return { 
        Icon: CheckCircle2,
        className: "text-green-600", 
        label: "승인됨"
      };
    case "READY_TO_SEND":
      return { 
        Icon: CheckCircle2,
        className: "text-emerald-600", 
        label: "MDG 송부대기"
      };
    case "ACTIVE":
      return { 
        Icon: Activity,
        className: "text-emerald-600", 
        label: "활성 상태"
      };
    case "INACTIVE":
      return { 
        Icon: AlertCircle,
        className: "text-gray-600", 
        label: "비활성 상태"
      };
    case "BLACKLISTED":
      return { 
        Icon: AlertTriangle,
        className: "text-slate-800", 
        label: "거래 금지"
      };
    default:
      return { 
        Icon: CircleIcon,
        className: "text-gray-600", 
        label: status
      };
  }
};

// 신용평가기관 목록
const creditAgencies = [
  { value: "NICE", label: "NICE평가정보" },
  { value: "KIS", label: "KIS (한국신용평가)" },
  { value: "KED", label: "KED (한국기업데이터)" },
  { value: "SCI", label: "SCI평가정보" },
]

// 신용등급 스케일
const creditRatingScaleMap: Record<string, string[]> = {
  NICE: ["AAA", "AA", "A", "BBB", "BB", "B", "C", "D"],
  KIS: ["AAA", "AA+", "AA", "A+", "A", "BBB+", "BBB", "BB", "B", "C"],
  KED: ["AAA", "AA", "A", "BBB", "BB", "B", "CCC", "CC", "C", "D"],
  SCI: ["AAA", "AA+", "AA", "AA-", "A+", "A", "A-", "BBB+", "BBB-", "B"],
}

// 현금흐름등급 스케일
const cashFlowRatingScaleMap: Record<string, string[]> = {
  NICE: ["우수", "양호", "보통", "미흡", "불량"],
  KIS: ["A+", "A", "B+", "B", "C", "D"],
  KED: ["1등급", "2등급", "3등급", "4등급", "5등급"],
  SCI: ["Level 1", "Level 2", "Level 3", "Level 4"],
}

// 폼 컴포넌트
export function UpdateVendorSheet({ vendor, ...props }: UpdateVendorSheetProps) {
  const [isPending, startTransition] = React.useTransition()
  const [selectedAgency, setSelectedAgency] = React.useState<string>(vendor?.creditAgency || "NICE")
  const { data: session } = useSession()

  // 폼 정의 - UpdateVendorSchema 타입을 직접 사용
  const form = useForm<UpdateVendorSchema>({
    resolver: zodResolver(updateVendorSchema),
    defaultValues: {
      // 업체 기본 정보
      vendorName: vendor?.vendorName ?? "",
      vendorCode: vendor?.vendorCode ?? "",
      address: vendor?.address ?? "",
      addressDetail: vendor?.addressDetail ?? "",
      postalCode: vendor?.postalCode ?? "",
      country: vendor?.country ?? "",
      phone: vendor?.phone ?? "",
      email: vendor?.email ?? "",
      website: vendor?.website ?? "",
      creditRating: vendor?.creditRating ?? "",
      cashFlowRating: vendor?.cashFlowRating ?? "",
      status: (vendor?.status as any) ?? "ACTIVE",
      vendorTypeId: vendor?.vendorTypeId ?? undefined,
      isAssociationMember: (vendor as any)?.isAssociationMember ?? "NONE",
      
      // 대표자 정보
      representativeName: (vendor as any)?.representativeName ?? "",
      representativeBirth: (vendor as any)?.representativeBirth ?? "",
      representativeEmail: (vendor as any)?.representativeEmail ?? "",
      representativePhone: (vendor as any)?.representativePhone ?? "",
      representativeWorkExpirence: (vendor as any)?.representativeWorkExpirence ?? false,
      corporateRegistrationNumber: vendor?.corporateRegistrationNumber ?? "",
      
      // 사업 정보
      businessSize: vendor?.businessSize ?? "",
      
      // 구매담당자 정보 (기본값은 비어있음)
      buyerName: "",
      buyerDepartment: "",
      contractStartDate: undefined,
      contractEndDate: undefined,
      internalNotes: "",
      // evaluationScore: "",
    },
  })

  React.useEffect(() => {
    if (vendor) {
      form.reset({
        vendorName: vendor?.vendorName ?? "",
        vendorCode: vendor?.vendorCode ?? "",
        address: vendor?.address ?? "",
        addressDetail: vendor?.addressDetail ?? "",
        postalCode: vendor?.postalCode ?? "",
        country: vendor?.country ?? "",
        phone: vendor?.phone ?? "",
        email: vendor?.email ?? "",
        website: vendor?.website ?? "",
        creditRating: vendor?.creditRating ?? "",
        cashFlowRating: vendor?.cashFlowRating ?? "",
        status: (vendor?.status as any) ?? "ACTIVE",
        vendorTypeId: vendor?.vendorTypeId ?? undefined,
        isAssociationMember: (vendor as any)?.isAssociationMember ?? "NONE",
        
        // 대표자 정보
        representativeName: (vendor as any)?.representativeName ?? "",
        representativeBirth: (vendor as any)?.representativeBirth ?? "",
        representativeEmail: (vendor as any)?.representativeEmail ?? "",
        representativePhone: (vendor as any)?.representativePhone ?? "",
        representativeWorkExpirence: (vendor as any)?.representativeWorkExpirence ?? false,
        corporateRegistrationNumber: vendor?.corporateRegistrationNumber ?? "",
        
        // 사업 정보
        businessSize: vendor?.businessSize ?? "",
        
        // 구매담당자 필드는 유지
        buyerName: form.getValues("buyerName"),
        buyerDepartment: form.getValues("buyerDepartment"),
        contractStartDate: form.getValues("contractStartDate"),
        contractEndDate: form.getValues("contractEndDate"),
        internalNotes: form.getValues("internalNotes"),
        // evaluationScore: form.getValues("evaluationScore"),
      });
    }
  }, [vendor, form]);

  // 신용평가기관 변경 시 등급 필드를 초기화하는 효과
  React.useEffect(() => {
    // 선택된 평가기관에 따라 현재 선택된 등급이 유효한지 확인
    const currentCreditRating = form.getValues("creditRating");
    const currentCashFlowRating = form.getValues("cashFlowRating");
    
    // 선택된 기관에 따른 유효한 등급 목록
    const validCreditRatings = creditRatingScaleMap[selectedAgency] || [];
    const validCashFlowRatings = cashFlowRatingScaleMap[selectedAgency] || [];
    
    // 현재 등급이 유효하지 않으면 초기화
    if (currentCreditRating && !validCreditRatings.includes(currentCreditRating)) {
      form.setValue("creditRating", "");
    }
    
    if (currentCashFlowRating && !validCashFlowRatings.includes(currentCashFlowRating)) {
      form.setValue("cashFlowRating", "");
    }
    
    // 신용평가기관 필드 업데이트
    if(selectedAgency){
      form.setValue("creditAgency", selectedAgency as "NICE" | "KIS" | "KED" | "SCI");
    }

  }, [selectedAgency, form]);

  // 제출 핸들러
  function onSubmit(data: UpdateVendorSchema) {
    if (!vendor) return
    
    if (!session?.user?.id) {
      toast.error("사용자 인증 정보를 찾을 수 없습니다.")
      return
    }

    startTransition(async () => {
    try {
      // Add status change comment if status has changed
      const oldStatus = (vendor.status as any) ?? "ACTIVE" // Default to ACTIVE if undefined
      const newStatus = (data.status as any) ?? "ACTIVE" // Default to ACTIVE if undefined
      
      const statusComment = 
        oldStatus !== newStatus 
          ? `상태 변경: ${getStatusConfig(oldStatus).label} → ${getStatusConfig(newStatus).label}`
          : ""  // Empty string instead of undefined
      
      // 업체 정보 업데이트 - userId와 상태 변경 코멘트 추가
      const { error } = await modifyVendor({ 
        id: String(vendor.id),
        userId: Number(session.user.id), // Add user ID from session
        comment: statusComment, // Add comment for status changes
        ...data  // 모든 데이터 전달 - 서비스 함수에서 필요한 필드만 처리
      } as any)
      
      if (error) throw new Error(error)
      
      toast.success("업체 정보가 업데이트되었습니다!")
      form.reset()
      props.onOpenChange?.(false)
    } catch (err: any) {
      toast.error(String(err))
    }
  })
}

  return (
    <Sheet {...props}>
      <SheetContent className="flex flex-col gap-6 sm:max-w-lg overflow-y-auto">
        <SheetHeader className="text-left">
          <SheetTitle>업체 정보 수정</SheetTitle>
          <SheetDescription>
            업체 세부 정보를 수정하고 변경 사항을 저장하세요
          </SheetDescription>
        </SheetHeader>
        <Form {...form}>
          <form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-6">
            {/* 업체 기본 정보 섹션 */}
            <div className="space-y-4">
              <div className="flex items-center">
                <h3 className="text-sm font-medium">협력업체 정보 수정</h3>
              </div>
              <div className="grid grid-cols-1 gap-4 md:grid-cols-2">
                {/* vendorName */}
                <FormField
                  control={form.control}
                  name="vendorName"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>업체명</FormLabel>
                      <FormControl>
                        <Input placeholder="업체명 입력" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* vendorCode - 읽기전용 */}
                <FormField
                  control={form.control}
                  name="vendorCode"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>업체 코드</FormLabel>
                      <FormControl>
                        <Input  
                          {...field} 
                          readOnly 
                          className="bg-gray-50 text-gray-600 cursor-not-allowed"
                        />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* address */}
                <FormField
                  control={form.control}
                  name="address"
                  render={({ field }) => (
                    <FormItem className="md:col-span-2">
                      <FormLabel>주소</FormLabel>
                      <FormControl>
                        <Input placeholder="주소 입력" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* addressDetail */}
                <FormField
                  control={form.control}
                  name="addressDetail"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>상세주소</FormLabel>
                      <FormControl>
                        <Input placeholder="상세주소 입력" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* postalCode */}
                <FormField
                  control={form.control}
                  name="postalCode"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>우편번호</FormLabel>
                      <FormControl>
                        <Input placeholder="우편번호 입력" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* country */}
                <FormField
                  control={form.control}
                  name="country"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>국가</FormLabel>
                      <FormControl>
                        <Input placeholder="예: 대한민국" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* phone */}
                <FormField
                  control={form.control}
                  name="phone"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>전화번호</FormLabel>
                      <FormControl>
                        <Input placeholder="예: 010-1234-5678" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* email */}
                <FormField
                  control={form.control}
                  name="email"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>이메일</FormLabel>
                      <FormControl>
                        <Input placeholder="예: info@company.com" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* website */}
                <FormField
                  control={form.control}
                  name="website"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>웹사이트</FormLabel>
                      <FormControl>
                        <Input placeholder="예: https://www.company.com" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* status with icons */}
                <FormField
                  control={form.control}
                  name="status"
                  render={({ field }) => {
                    // 현재 선택된 상태의 구성 정보 가져오기
                    const selectedConfig = getStatusConfig(field.value ?? "ACTIVE");
                    const SelectedIcon = selectedConfig?.Icon || CircleIcon;

                    return (
                      <FormItem>
                        <FormLabel>업체승인상태</FormLabel>
                        <FormControl>
                          <Select
                            value={field.value}
                            onValueChange={field.onChange}
                          >
                            <SelectTrigger className="w-full">
                              <SelectValue>
                                {field.value && (
                                  <div className="flex items-center">
                                    <SelectedIcon className={`mr-2 h-4 w-4 ${selectedConfig.className}`} />
                                    <span>{selectedConfig.label}</span>
                                  </div>
                                )}
                              </SelectValue>
                            </SelectTrigger>
                            <SelectContent>
                              <SelectGroup>
                                {vendors.status.enumValues.map((status) => {
                                  const config = getStatusConfig(status);
                                  const StatusIcon = config.Icon;
                                  return (
                                    <SelectItem key={status} value={status}>
                                      <div className="flex items-center">
                                        <StatusIcon className={`mr-2 h-4 w-4 ${config.className}`} />
                                        <span>{config.label}</span>
                                      </div>
                                    </SelectItem>
                                  );
                                })}
                              </SelectGroup>
                            </SelectContent>
                          </Select>
                        </FormControl>
                        <FormMessage />
                      </FormItem>
                    );
                  }}
                />

                {/* 성조회 가입여부 */}
                <FormField
                  control={form.control}
                  name="isAssociationMember"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>성조회 가입여부</FormLabel>
                      <FormControl>
                        <Select
                          value={field.value || "NONE"}
                          onValueChange={(value) => {
                            field.onChange(value === "NONE" ? null : value);
                          }}
                        >
                          <SelectTrigger className="w-full">
                            <SelectValue placeholder="가입여부 선택" />
                          </SelectTrigger>
                          <SelectContent>
                            <SelectGroup>
                              <SelectItem value="NONE">정보없음</SelectItem>
                              <SelectItem value="Y">가입</SelectItem>
                              <SelectItem value="N">미가입</SelectItem>
                              <SelectItem value="E">해당없음</SelectItem>
                            </SelectGroup>
                          </SelectContent>
                        </Select>
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
                                
                {/* 신용평가기관 선택 */}
                <FormField
                  control={form.control}
                  name="creditAgency"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>신용평가기관</FormLabel>
                      <FormControl>
                        <Select
                          value={field.value || ""}
                          onValueChange={(value) => {
                            field.onChange(value);
                            setSelectedAgency(value);
                          }}
                        >
                          <SelectTrigger className="w-full">
                            <SelectValue placeholder="평가기관 선택" />
                          </SelectTrigger>
                          <SelectContent>
                            <SelectGroup>
                              {creditAgencies.map((agency) => (
                                <SelectItem key={agency.value} value={agency.value}>
                                  {agency.label}
                                </SelectItem>
                              ))}
                            </SelectGroup>
                          </SelectContent>
                        </Select>
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
                
                {/* 평가년도 - 나중에 추가 가능 */}
                
                {/* 신용등급 - 선택된 기관에 따라 옵션 변경 */}
                <FormField
                  control={form.control}
                  name="creditRating"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>신용등급</FormLabel>
                      <FormControl>
                        <Select
                          value={field.value || ""}
                          onValueChange={field.onChange}
                          disabled={!selectedAgency}
                        >
                          <SelectTrigger className="w-full">
                            <SelectValue placeholder="신용등급 선택" />
                          </SelectTrigger>
                          <SelectContent>
                            <SelectGroup>
                              {(creditRatingScaleMap[selectedAgency] || []).map((rating) => (
                                <SelectItem key={rating} value={rating}>
                                  {rating}
                                </SelectItem>
                              ))}
                            </SelectGroup>
                          </SelectContent>
                        </Select>
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
                
                {/* 현금흐름등급 - 선택된 기관에 따라 옵션 변경 */}
                <FormField
                  control={form.control}
                  name="cashFlowRating"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>현금흐름등급</FormLabel>
                      <FormControl>
                        <Select
                          value={field.value || ""}
                          onValueChange={field.onChange}
                          disabled={!selectedAgency}
                        >
                          <SelectTrigger className="w-full">
                            <SelectValue placeholder="현금흐름등급 선택" />
                          </SelectTrigger>
                          <SelectContent>
                            <SelectGroup>
                              {(cashFlowRatingScaleMap[selectedAgency] || []).map((rating) => (
                                <SelectItem key={rating} value={rating}>
                                  {rating}
                                </SelectItem>
                              ))}
                            </SelectGroup>
                          </SelectContent>
                        </Select>
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

              </div>
            </div>

            {/* 구분선 */}
            <Separator className="my-2" />

            {/* 대표자 정보 섹션 */}
            <div className="space-y-4">
              <div className="flex items-center">
                <User className="mr-2 h-5 w-5 text-muted-foreground" />
                <h3 className="text-sm font-medium">대표자 정보</h3>
              </div>
              <FormDescription>
                업체 대표자의 정보를 입력하세요.
              </FormDescription>
              
              <div className="grid grid-cols-1 gap-4 md:grid-cols-2">
                {/* 대표자명 */}
                <FormField
                  control={form.control}
                  name="representativeName"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>대표자명</FormLabel>
                      <FormControl>
                        <Input placeholder="대표자명 입력" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* 대표자 생년월일 */}
                <FormField
                  control={form.control}
                  name="representativeBirth"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>대표자 생년월일</FormLabel>
                      <FormControl>
                        <Input placeholder="예: 1970-01-01" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* 대표자 이메일 */}
                <FormField
                  control={form.control}
                  name="representativeEmail"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>대표자 이메일</FormLabel>
                      <FormControl>
                        <Input placeholder="예: ceo@company.com" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* 대표자 전화번호 */}
                <FormField
                  control={form.control}
                  name="representativePhone"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>대표자 전화번호</FormLabel>
                      <FormControl>
                        <Input placeholder="예: 010-1234-5678" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* 법인등록번호 */}
                <FormField
                  control={form.control}
                  name="corporateRegistrationNumber"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>법인등록번호</FormLabel>
                      <FormControl>
                        <Input placeholder="법인등록번호 입력" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* 사업 규모 */}
                <FormField
                  control={form.control}
                  name="businessSize"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>사업 규모</FormLabel>
                      <FormControl>
                        <Input placeholder="예: 중소기업, 대기업" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                {/* 대표자 경력 */}
                <FormField
                  control={form.control}
                  name="representativeWorkExpirence"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>대표자 삼성중공업 근무경험 여부</FormLabel>
                      <FormControl>
                        <Select
                          value={field.value ? "true" : "false"}
                          onValueChange={(value) => field.onChange(value === "true")}
                        >
                          <SelectTrigger className="w-full">
                            <SelectValue placeholder="경력 보유 여부 선택" />
                          </SelectTrigger>
                          <SelectContent>
                            <SelectGroup>
                              <SelectItem value="false">없음</SelectItem>
                              <SelectItem value="true">있음</SelectItem>
                            </SelectGroup>
                          </SelectContent>
                        </Select>
                      </FormControl>
                      <div className="space-y-1 leading-none">
                        
                      </div>
                    </FormItem>
                  )}
                />
              </div>
            </div>

            {/* 구분선 */}
            <Separator className="my-2" />

            {/* 구매담당자 입력 섹션 */}
            <div className="space-y-4 bg-slate-50 p-4 rounded-md border border-slate-200">
              <div className="flex items-center">
                <User className="mr-2 h-5 w-5 text-blue-600" />
                <h3 className="text-sm font-medium text-blue-800">구매담당자 정보</h3>
              </div>
              <FormDescription>
                구매담당자가 관리하는 추가 정보입니다. 이 정보는 내부용으로만 사용됩니다.
              </FormDescription>
              
              <div className="grid grid-cols-1 gap-4 md:grid-cols-2">
                {/* 여기에 구매담당자 필드 추가 */}
                <FormField
                  control={form.control}
                  name="buyerName"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>담당자 이름</FormLabel>
                      <FormControl>
                        <Input placeholder="담당자 이름" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
                
                <FormField
                  control={form.control}
                  name="buyerDepartment"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel>담당 부서</FormLabel>
                      <FormControl>
                        <Input placeholder="예: 구매부" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />

                
                <FormField
                  control={form.control}
                  name="internalNotes"
                  render={({ field }) => (
                    <FormItem className="md:col-span-2">
                      <FormLabel>내부 메모</FormLabel>
                      <FormControl>
                        <Input placeholder="내부 참고사항을 입력하세요" {...field} />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
              </div>
            </div>

            <SheetFooter className="gap-2 pt-2 sm:space-x-0">
              <SheetClose asChild>
                <Button type="button" variant="outline">
                  취소
                </Button>
              </SheetClose>
              <Button disabled={isPending}>
                {isPending && (
                  <Loader className="mr-2 h-4 w-4 animate-spin" aria-hidden="true" />
                )}
                저장
              </Button>
            </SheetFooter>
          </form>
        </Form>
      </SheetContent>
    </Sheet>
  )
}