// "use client"; // import React, { useEffect, useState } from "react"; // import { useForm, Controller } from "react-hook-form"; // import { Input } from "@/components/ui/input"; // import { Button } from "@/components/ui/button"; // import { Label } from "@/components/ui/label"; // import { Card } from "@/components/ui/card"; // import { zodResolver } from "@hookform/resolvers/zod"; // import * as z from "zod"; // import Swal from "sweetalert2"; // import withReactContent from "sweetalert2-react-content"; // import { useParams } from "next/navigation"; // import { // Select, // SelectContent, // SelectItem, // SelectTrigger, // SelectValue, // } from "@/components/ui/select"; // import { Avatar, AvatarImage } from "@/components/ui/avatar"; // import { // deleteTicket, // getTicketingDetail, // getTicketingInternalDetail, // getTicketingInternalDiscussion, // getTicketingReply, // saveTicketing, // saveTicketInternalReply, // saveTicketReply, // } from "@/service/communication/communication"; // import { Icon } from "@iconify/react/dist/iconify.js"; // import { list, parse } from "postcss"; // import { htmlToString } from "@/utils/globals"; // import { Textarea } from "@/components/ui/textarea"; // import { error } from "@/lib/swal"; // import { useRouter } from "next/navigation"; // import InfoLainnyaModal from "./info-lainnya"; // import { DetailTicket } from "./info-lainnya-types"; // import { useMediaQuery } from "react-responsive"; // import { ArrowLeft, ChevronDownIcon } from "lucide-react"; // import { // Popover, // PopoverContent, // PopoverTrigger, // } from "@/components/ui/popover"; // import { getOperatorUser } from "@/service/management-user/management-user"; // const taskSchema = z.object({ // title: z.string().min(1, { message: "Judul diperlukan" }), // naration: z.string().min(2, { // message: "Narasi Penugasan harus lebih dari 2 karakter.", // }), // }); // export type taskDetail = { // id: number; // title: string; // createdAt: string; // referenceNumber: string | number; // createdBy: { // id: number; // fullname: string; // }; // sendTo: { // id: number; // fullname: string; // }; // status: { // id: number; // name: string; // }; // priority: { // id: number; // name: string; // }; // broadcastType: string; // description: string; // is_active: string; // }; // export type replyDetail = { // id: number; // comments: string; // createdAt: string; // user: { // id: number; // fullname: string; // }; // messageTo: { // id: number; // fullname: string; // }; // }; // export type internalDetail = { // id: number; // message: string; // createdAt: string; // commentFromUserName: string; // feedTitle: string; // createdBy: { // id: number; // fullname: string; // }; // sendTo: { // id: number; // fullname: string; // }; // }; // type Props = { id: string }; // export default function FormDetailTicketing({ id }: Props) { // const MySwal = withReactContent(Swal); // // const { id } = useParams() as { id: string }; // const router = useRouter(); // const isMobile = useMediaQuery({ // maxWidth: 768, // }); // const [detail, setDetail] = useState(); // const [ticketReply, setTicketReply] = useState([]); // const [ticketInternal, setTicketInternal] = useState( // null // ); // const [detailTickets, setDetailTickets] = useState(null); // const [replyVisible, setReplyVisible] = useState(false); // const [replyMessage, setReplyMessage] = useState(""); // const [selectedPriority, setSelectedPriority] = useState(""); // const [selectedStatus, setSelectedStatus] = useState(""); // const [openEmergencyModal, setOpenEmergencyModal] = useState(false); // const [replyValue, setReplyValue] = useState(0); // const [replyText, setReplyText] = useState(""); // const [operatorOpt, setOperatorOpt] = useState< // { id: string; label: string; value: string }[] // >([]); // const [selectedOperator, setSelectedOperator] = useState([]); // const { // control, // handleSubmit, // formState: { errors }, // } = useForm({ // resolver: zodResolver(taskSchema), // }); // useEffect(() => { // async function initState() { // setReplyValue(0); // const response = await getTicketingDetail(id); // setTicketInternal(response?.data?.data || null); // setDetail(response?.data?.data); // if (response?.data !== null) { // setDetailTickets(response?.data?.data); // } // } // initState(); // getTicketReply(); // }, [id]); // useEffect(() => { // async function getOperator() { // const res = await getOperatorUser(detailTickets?.typeId); // if (res?.data !== null) { // const rawUser = res?.data?.data; // const optionArr = rawUser?.map((option: any) => ({ // id: option.id, // label: option.fullName, // value: option.id.toString(), // })); // setOperatorOpt(optionArr); // if (detailTickets?.assignedTeams) { // const assigned = detailTickets.assignedTeams // .split(":") // .filter((id: string) => id); // setSelectedOperator(assigned); // } // } // } // getOperator(); // }, [detailTickets]); // const handleReply = () => { // setReplyValue((prev) => (prev === 1 ? 0 : 1)); // }; // const handleSendReplyData = async () => { // if (!replyText.trim()) { // console.warn("Balasan kosong!"); // return; // } // try { // const res = await saveTicketReply({ // ticketId: id, // comment: replyText, // parentCommentId: detailTickets?.commentId, // isFromInternal: true, // }); // console.log("Berhasil kirim balasan:", res?.data); // setReplyText(""); // setReplyValue(0); // getTicketReply(); // } catch (err) { // console.error("Gagal kirim balasan:", err); // } // }; // async function getTicketReply() { // const res = await getTicketingReply(id); // if (res?.data !== null) { // setTicketReply(res?.data?.data); // } // } // const handleSendReply = async () => { // if (replyMessage.trim() === "") { // MySwal.fire({ // title: "Error", // text: "Pesan tidak boleh kosong!", // icon: "error", // }); // return; // } // const data = { // ticketId: id, // comment: replyMessage, // }; // try { // const response = await saveTicketReply(data); // const newReply: replyDetail = { // id: response?.data?.id, // comments: replyMessage, // createdAt: response?.data?.createdAt, // user: response?.data?.messageFrom, // messageTo: response?.data?.messageTo, // }; // setTicketReply((prevReplies) => [newReply, ...prevReplies]); // MySwal.fire({ // title: "Sukses", // text: "Pesan berhasil dikirim.", // icon: "success", // }); // setReplyMessage(""); // setReplyVisible(false); // } catch (error) { // MySwal.fire({ // title: "Error", // text: "Gagal mengirim balasan.", // icon: "error", // }); // console.error("Error sending reply:", error); // } // }; // async function doDelete(id: any) { // const response = await deleteTicket(id); // if (response?.error) { // error(response.message); // return false; // } // success("/in/supervisor/ticketing"); // } // function success(redirect: string) { // MySwal.fire({ // title: "Sukses", // icon: "success", // confirmButtonColor: "#3085d6", // confirmButtonText: "OK", // }).then(() => { // router.push(redirect); // }); // } // const handleDelete = (id: any) => { // MySwal.fire({ // title: "Hapus Data", // text: "", // icon: "warning", // showCancelButton: true, // cancelButtonColor: "#3085d6", // confirmButtonColor: "#d33", // confirmButtonText: "Hapus", // }).then((result) => { // if (result.isConfirmed) { // doDelete(id); // } // }); // }; // const openEmergencyIssueDetail = () => { // setOpenEmergencyModal(true); // }; // return ( //
//
//
// //
// {replyValue === 1 && ( //
//