import Container from "../Container/index.js";
import React, { useEffect, useState } from "react";
import { Form, InputNumber, Select } from "antd";
import { locales } from "@pisell/utils";
import "./index.less";
//#region src/components/productExtension/fields/Actor/CutOffTime/index.tsx
const { Option } = Select;
const maxNumber = {
	days: 365,
	hours: 8760,
	minutes: 525600
};
const CutOffTime = ({ value, onChange, name }) => {
	const [cutTimeMax, setCutTimeMax] = useState(365);
	const timeOptions = [
		{
			label: locales.getText("pisell2.text.product-extension.days"),
			value: "days"
		},
		{
			label: locales.getText("pisell2.text.product-extension.hours"),
			value: "hours"
		},
		{
			label: locales.getText("pisell2.text.product-extension.minutes"),
			value: "minutes"
		}
	];
	useEffect(() => {
		if (value) setCutTimeMax(maxNumber[value === null || value === void 0 ? void 0 : value.unit_type]);
	}, [value]);
	return /* @__PURE__ */ React.createElement("div", { className: "pisell2_product-extension-cut-off-time-wrap" }, /* @__PURE__ */ React.createElement(Container, {
		title: locales.getText("pisell2.text.product-extension.cut-off-time"),
		desc: locales.getText("pisell2.text.product-extension.cut-off-time.desc"),
		isMargin: true
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell2_product-extension-cut-off-time-input-wrap" }, /* @__PURE__ */ React.createElement(Form.Item, {
		name: [...name, "unit"],
		noStyle: true,
		initialValue: 1
	}, /* @__PURE__ */ React.createElement(InputNumber, {
		min: 1,
		size: "large",
		max: cutTimeMax,
		className: "pisell2_product-extension-cut-off-time-input-small"
	})), /* @__PURE__ */ React.createElement(Form.Item, {
		name: [...name, "unit_type"],
		noStyle: true,
		initialValue: "days"
	}, /* @__PURE__ */ React.createElement(Select, {
		size: "large",
		className: "pisell2_product-extension-cut-off-time-select-wrap",
		onChange: (value) => {
			setCutTimeMax(maxNumber[value]);
		}
	}, timeOptions.map((i) => /* @__PURE__ */ React.createElement(Option, { key: i.value }, i.label)))))), /* @__PURE__ */ React.createElement(Container, {
		title: locales.getText("pisell2.text.product-extension.future-day"),
		desc: locales.getText("pisell2.text.product-extension.future-day.hint")
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell2_product-extension-cut-off-time-input-wrap" }, /* @__PURE__ */ React.createElement(Form.Item, {
		name: [...name, "future_day"],
		noStyle: true,
		initialValue: 365
	}, /* @__PURE__ */ React.createElement(InputNumber, {
		size: "large",
		min: 0,
		max: 365,
		addonAfter: locales.getText("pisell2.text.product-extension.days"),
		className: "pisell2_product-extension-cut-off-time-input-big"
	})))));
};
//#endregion
export { CutOffTime as default };
