const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_model = require("../model.js");
const require_index = require("../../notes/NoteBlock/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
//#region src/components/booking/info/notes/index.tsx
const Notes = () => {
	var _modal$state3, _modal$state6;
	const modal = (0, react.useContext)(require_model.Context);
	const orderNote = (0, react.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.default.createElement(require_index.default, {
		noteType: "order",
		maxLength: 1,
		title: `${_pisell_utils.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: _pisell_utils.locales.getText("pisell2.text.add-order-notes"),
		isEdit: false,
		onChange: (e, type, noteType) => {
			noteChange({
				note: e,
				status: type,
				noteType
			});
		}
	});
};
//#endregion
exports.default = Notes;
