"use strict";

const React = require("react");

const Window = require("../window");

module.exports = function FloatingWindowArea({windows, onStartMove, onStartCornerResize, onClose, onFocus, onWindowRef}) {
	return (
		windows.map((window_) => {
			let windowStyle = {
				transform: `translate(${window_.x}px, ${window_.y}px)`,
				width: window_.width,
				height: window_.height,
				zIndex: window_.zIndex
			};

			let handlers = {
				onTitleMouseDown: (event) => {
					onStartMove(window_, event);
				},
				onResizerMouseDown: (event) => {
					onStartCornerResize(window_, event);
				},
				onMouseDown: () => {
					onFocus(window_);
				},
				onClose: () => {
					onClose(window_);
				}
			};

			return (
				<Window elementRef={onWindowRef.bind(null, window_.id)} key={window_.id} style={windowStyle} window={window_} resizeDirection="both" {...handlers} />
			);
		})
	);
};
