import {lindt, DOM, on} from "https://rosuav.github.io/choc/factory.js";
const {BR, BUTTON, DIV, FORM, H3, INPUT, P, SPAN} = lindt; //autoimport
import socksend from './websocket.js';

on("submit", ".property", e => {
	e.preventDefault();
	socksend("bid", {name: e.match.dataset.name, value: e.match.elements.bid.value});
});

on("click", ".submitmin", e => socksend("bid", {name: e.match.closest("[data-name]").dataset.name, value: e.match.value}));

export default function render(state, property, info) {
	let name = H3({style: "background-color: " + info.color + "; color: " + (info.fg || "black")}, property);
	if (state.all_done) {
		if (!info.bidder) return SPAN(); //Might be able to replace this with "return null"
		return DIV({class: "property"}, [
			name,
			P(info.bidder + " (" + info.highbid + ")"),
		]);
	}
	let minbid = info.bidder ? ((info.highbid|0) + 10) : (info.facevalue|0);
	//FIXME: If you've been outbid, blank the field.
	//if (this.refs.bid && (this.refs.bid.value|0) < minbid) this.refs.bid.value = "";
	return FORM({class: "property", "data-name": property}, [
		name,
		P([
			"Current high bid:", BR(),
			info.bidder || "(nobody)",
			" ", info.highbid || info.facevalue,
		]),
		DIV([
			INPUT({type: "number", name: "bid", value: info.bidder ? "" : info.facevalue}),
			INPUT({type: "submit", value: "Bid"}),
		]),
		DIV([
			info.bidder == state.user ? "YOURS" :
			info.bidder ? BUTTON({type: "button", value: minbid}, "Bid " + minbid)
			: "\xa0"
		]),
	]);
}

@@ -351,16 +351,19 @@
 %22, e =%3E 
+%7B%0A%09
 socksend
@@ -437,23 +437,34 @@
 e.match.
+dataset.
 value%7D)
+;%0A%7D
 );%0A%0Aexpo
@@ -1448,21 +1448,48 @@
 utton%22, 
+class: %22submitmin%22, %22data-
 value
+%22
 : minbid

Fix submitmin button