import { Context } from "../model.js";
import NoteBlock from "../../notes/NoteBlock/index.js";
import React, { useContext, useMemo } from "react";
import { locales } from "@pisell/utils";
//#region src/components/booking/info/notes/index.tsx
const Notes = () => {
	var _modal$state3, _modal$state6;
	const modal = useContext(Context);
	const orderNote = useMemo(() => {
		var _modal$state, _modal$state2;
		if (!((_modal$state = modal.state) === null || _modal$state === void 0 || (_modal$state = _modal$state.notes) === null || _modal$state === void 0 ? void 0 : _modal$state.orderNote)) return [];
		return [{
			id: 0,
			content: ((_modal$state2 = modal.state) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.notes) === null || _modal$state2 === void 0 ? void 0 : _modal$state2.orderNote) || ""
		}];
	}, [(_modal$state3 = modal.state) === null || _modal$state3 === void 0 || (_modal$state3 = _modal$state3.notes) === null || _modal$state3 === void 0 ? void 0 : _modal$state3.orderNote]);
	const noteChange = ({ note, status, noteType }) => {
		if (noteType === "internal") {
			var _modal$state4, _modal$state5, _modal$state5$refresh;
			let _list = [...(_modal$state4 = modal.state) === null || _modal$state4 === void 0 ? void 0 : _modal$state4.notes.internalNotes];
			if (status == "add") _list.push(note);
			if (status == "remove") _list = _list.filter((item) => item.id != note.id);
			if (status == "edit") _list = _list.map((item) => {
				if (item.id == note.id) return note;
				return item;
			});
			modal.dispatch({
				type: "setNotes",
				payload: { internalNotes: _list }
			});
			(_modal$state5 = modal.state) === null || _modal$state5 === void 0 || (_modal$state5$refresh = _modal$state5.refreshData) === null || _modal$state5$refresh === void 0 || _modal$state5$refresh.call(_modal$state5, {});
			return;
		}
		if (noteType === "order") modal.dispatch({
			type: "setNotes",
			payload: {
				orderNote: note.content || "",
				edit: false
			}
		});
	};
	if (orderNote.length === 0 && modal.state.disableEventBookingEdit) return null;
	return /* @__PURE__ */ React.createElement(NoteBlock, {
		noteType: "order",
		maxLength: 1,
		title: `${locales.getText("pisell2.text.order-notes")}:`,
		describe: "",
		notes: orderNote,
		apis: modal === null || modal === void 0 || (_modal$state6 = modal.state) === null || _modal$state6 === void 0 ? void 0 : _modal$state6.apis,
		placeholder: locales.getText("pisell2.text.add-order-notes"),
		isEdit: false,
		onChange: (e, type, noteType) => {
			noteChange({
				note: e,
				status: type,
				noteType
			});
		}
	});
};
//#endregion
export { Notes as default };
