const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
let react = require("react");
react = require_runtime.__toESM(react);
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./BucketButtonGroup.less");
//#region src/plus/pisellReservation/components/BucketButtonGroup.tsx
function isBucketChecked(bucket, valueSet) {
	return bucket.keys.some((k) => valueSet.has(k));
}
function toggleBucket(bucket, current) {
	const set = new Set(current.map(String));
	if (isBucketChecked(bucket, set)) for (const k of bucket.keys) set.delete(k);
	else for (const k of bucket.keys) set.add(k);
	return Array.from(set);
}
function BucketButtonGroup(props) {
	const { value, onChange, buckets } = props;
	const valueSet = (0, react.useMemo)(() => new Set(Array.isArray(value) ? value.map(String) : []), [value]);
	const handleToggle = (0, react.useCallback)((bucket) => {
		onChange === null || onChange === void 0 || onChange(toggleBucket(bucket, Array.isArray(value) ? value : []));
	}, [value, onChange]);
	return /* @__PURE__ */ react.default.createElement("div", { className: "reservation-bucket-button-group" }, buckets.map((bucket) => {
		const checked = isBucketChecked(bucket, valueSet);
		return /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			key: bucket.id,
			title: bucket.label,
			className: (0, classnames.default)("reservation-bucket-button-group__item", { "reservation-bucket-button-group__item--checked": checked }),
			onClick: () => handleToggle(bucket),
			"aria-pressed": checked
		}, /* @__PURE__ */ react.default.createElement("span", {
			className: "reservation-bucket-button-group__dot",
			"aria-hidden": "true"
		}), /* @__PURE__ */ react.default.createElement("span", { className: "reservation-bucket-button-group__label" }, bucket.label));
	}));
}
//#endregion
exports.default = BucketButtonGroup;
