function Window_EroStatus_syougou() {
	this.initialize(...arguments);
}

CBR_syougou = null;

DataManager._databaseFiles.push({ name: "CBR_syougou", src: "CBR_h_syougou.json" });

(function () {
	Window_EroStatus_syougou.prototype = Object.create(Window_Selectable.prototype);
	Window_EroStatus_syougou.prototype.constructor = Window_EroStatus_syougou;

	Window_EroStatus_syougou.prototype.initialize = function (rect) {
		Window_Selectable.prototype.initialize.call(this, rect);
		//最初に0番目って指定、commandではデフォでやってるけど

		// デフォではアクティブに
		this.makeList();
		this.select(0);
		this.activate();

		this.refresh();
	};

	Window_EroStatus_syougou.prototype.numVisibleRows = function () {
		return 5;
	};

	Window_EroStatus_syougou.prototype.makeList = function () {
		this._list = CBR_syougou.concat().sort((a, b) => a.dispIdx - b.dispIdx);
	};

	Window_EroStatus_syougou.prototype.maxItems = function () {
		return this._list.length || 0;
	};

	Window_EroStatus_syougou.prototype.drawItem = function (index) {
		const info = this._list[index];
		const rect = this.itemRectWithPadding(index);

		this.resetTextColor();
		//this.changePaintOpacity(this.isEnabled(savefileId));
		//this.drawTitle(savefileId, rect.x, rect.y + 4);
		//数値だったら
		//if (Number.isFinite(info)) {
		this.drawContents(info, rect, index);
		//}
	};

	Window_EroStatus_syougou.prototype.drawContents = function (info, rect, index) {
		const bottom = rect.y + rect.height;

		var switch_chara = "Shirayuki" == $gameParty.menuActor().name() ? "switch_sira" : "switch_yozu";

		this.contents.fontFace = "serif";
		this.contents.fontSize = 24;
		this.changeTextColor("#000000");
		if (!$gameSwitches.value(info[switch_chara])) {
			this.drawTextM("？？？？？", 44, rect.y + 2, 400, "left");
		} else {
			this.drawTextM(`${info.title}`, 44, rect.y + 2, 400, "left");
			this.contents.fontSize = 18;
			var num = (info.text.match(/\n/g) || []).length;
			this.drawTextExM(`${info.text}`, 440, rect.y + 7 - num * 11, 400, "left");
		}

		// const lineHeight = this.lineHeight();
		// const y2 = bottom - lineHeight - 4;
		// if (y2 >= lineHeight) {
		// 	this.drawPlaytime(info, rect.x, y2, rect.width);
		// }
	};
	Window_EroStatus_syougou.prototype.processNewLineM = function (textState) {
		textState.x = textState.startX;
		textState.y += textState.height - 50;
		textState.height = this.calcTextHeight(textState);
	};

	// ################# カーソルの変更 ##################
	Window_EroStatus_syougou.prototype.loadWindowskin = function () {
		this.windowskin = ImageManager.loadSystem("Window");
		this.menu_cursor_skin = ImageManager.loadSystem("erost_syougou_cursor");
		this.menu_item_skin = ImageManager.loadSystem("erost_syougou_item");

		if (!this.menu_item_skin.isReady()) {
			this.menu_item_skin.addLoadListener(() => {
				this.refresh(); // 画像がロードされたら再描画
			});
			return;
		}
	};

	//56×200にする
	Window_EroStatus_syougou.prototype._refreshCursor = function () {
		const drect = this._cursorRect.clone();
		const srect = { x: 0, y: 0, width: 940, height: 78 };
		const m = 0;
		for (const child of this._cursorSprite.children) {
			child.bitmap = this.menu_cursor_skin;
		}
		this._setRectPartsGeometry(this._cursorSprite, srect, drect, m);
	};

	//未選択コマンドの背景を画像に
	Window_EroStatus_syougou.prototype.drawItemBackground = function (index) {
		const rect = this.itemRect(index);
		if (this.menu_item_skin) {
			const bitmap = this.menu_item_skin;
			const dx = rect.x;
			const dy = rect.y;
			const dw = rect.width;
			const dh = rect.height;
			this.contentsBack.blt(bitmap, 0, 0, 940, 78, dx, dy, dw, dh);
		}
	};

	Window_EroStatus_syougou.prototype.lineHeight = function () {
		return 78;
	};

	//コマンド欄の間隔、マウス操作の為なくす
	Window_EroStatus_syougou.prototype.rowSpacing = function () {
		return 4;
	};

	Window_EroStatus_syougou.prototype._refreshAllParts = function () {
		//this._refreshBack();
		//this._refreshFrame();
		this._refreshCursor();
		this._refreshArrows();
		this._refreshPauseSign();
	};
})();
