// πŸ‘¨β€πŸ« ꡐ사 νšŒμ›κ°€μž… ν™”λ©΄. ꡐ사 인증 μ½”λ“œ 확인 ν›„ μ‹ κ·œ ꡐ사 계정을 μƒμ„±ν•œλ‹€. import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import '../config.dart'; class TeacherRegisterScreen extends StatefulWidget { const TeacherRegisterScreen({super.key}); @override State createState() => _TeacherRegisterScreenState(); } class _TeacherRegisterScreenState extends State { final _idController = TextEditingController(); final _pwController = TextEditingController(); final _nameController = TextEditingController(); final _secretController = TextEditingController(); bool _isLoading = false; Future _registerTeacher() async { String id = _idController.text.trim(); String pw = _pwController.text.trim(); String name = _nameController.text.trim(); String secret = _secretController.text.trim(); // πŸ’‘ ν…ŒμŠ€νŠΈμš© κ³ μœ κ°’ (μ‹€μ œ λ””λ°”μ΄μŠ€ UUID 연동 둜직이 μžˆλ‹€λ©΄ κ·Έκ±Έ λ„£μœΌμ„Έμš”) String dummyUuid = "TEACHER_PHONE_$id"; if (id.isEmpty || pw.isEmpty || name.isEmpty || secret.isEmpty) { ScaffoldMessenger.of( context, ).showSnackBar(const SnackBar(content: Text('⚠️ λͺ¨λ“  λΉˆμΉΈμ„ μž…λ ₯ν•΄ μ£Όμ„Έμš”.'))); return; } setState(() => _isLoading = true); try { final response = await http.post( Uri.parse('$baseUrl/api/users/register-teacher'), headers: {"Content-Type": "application/json"}, body: jsonEncode({ "teacherId": id, "password": pw, "name": name, "secretCode": secret, "deviceUuid": dummyUuid, }), ); final res = jsonDecode(response.body); if (response.statusCode == 200 && res['status'] == 'success') { ScaffoldMessenger.of( context, ).showSnackBar(SnackBar(content: Text('βœ… ${res['message']}'))); Navigator.pop(context); // κ°€μž… 성곡 μ‹œ 둜그인 ν™”λ©΄μœΌλ‘œ 볡귀 } else { // λ°±μ—”λ“œμ—μ„œ 보낸 μ—λŸ¬ λ©”μ‹œμ§€(detail ν˜Ήμ€ message) 좜λ ₯ String errorMsg = res['detail'] ?? res['message'] ?? 'νšŒμ›κ°€μž…μ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.'; ScaffoldMessenger.of( context, ).showSnackBar(SnackBar(content: Text('❌ $errorMsg'))); } } catch (e) { ScaffoldMessenger.of( context, ).showSnackBar(const SnackBar(content: Text('❌ μ„œλ²„μ™€ 톡신에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.'))); } finally { setState(() => _isLoading = false); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('ꡐ사 νšŒμ›κ°€μž…'), backgroundColor: Colors.indigo, foregroundColor: Colors.white, ), body: SingleChildScrollView( padding: const EdgeInsets.all(24.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( 'πŸ‘¨β€πŸ« ꡐ직원 μ „μš© 인증', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), const SizedBox(height: 4), const Text( 'ν•™κ΅μ—μ„œ λ°œκΈ‰ν•œ ꡐ사 κ°€μž… λΉ„λ°€μ½”λ“œκ°€ ν•„μš”ν•©λ‹ˆλ‹€.', style: TextStyle(color: Colors.grey), ), const SizedBox(height: 24), TextField( controller: _secretController, obscureText: true, decoration: const InputDecoration( labelText: 'πŸ”‘ ꡐ사 인증 λΉ„λ°€μ½”λ“œ μž…λ ₯', border: OutlineInputBorder(), ), ), const SizedBox(height: 16), const Divider(), const SizedBox(height: 16), TextField( controller: _idController, decoration: const InputDecoration( labelText: 'ꡐ직원 번호 (ID둜 μ‚¬μš©)', border: OutlineInputBorder(), ), ), const SizedBox(height: 12), TextField( controller: _nameController, decoration: const InputDecoration( labelText: 'μ„ μƒλ‹˜ 성함', border: OutlineInputBorder(), ), ), const SizedBox(height: 12), TextField( controller: _pwController, obscureText: true, decoration: const InputDecoration( labelText: 'μ‚¬μš©ν•  λΉ„λ°€λ²ˆν˜Έ μž…λ ₯', border: OutlineInputBorder(), ), ), const SizedBox(height: 24), SizedBox( width: double.infinity, height: 50, child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.indigo, foregroundColor: Colors.white, ), onPressed: _isLoading ? null : _registerTeacher, child: _isLoading ? const CircularProgressIndicator(color: Colors.white) : const Text('ꡐ사 계정 μƒμ„±ν•˜κΈ°'), ), ), ], ), ), ); } }