import { _asyncToGenerator } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import ShiftModal from "./components/shiftModal/index.js";
import ShiftPreview from "./components/shiftModal/ShiftPreview.js";
import React, { useState } from "react";
import { Button, Form, Radio } from "antd";
import { locales } from "@pisell/utils";
import { Icon } from "@pisell/materials";
//#region src/plus/saasAttendance/settings/ShiftScheduleTab.tsx
const ScheduleSetting = (props) => {
	const { value, onChange } = props;
	const [open, setOpen] = useState(false);
	const label = Array.isArray(value) && value.some((d) => {
		var _d$times;
		return d === null || d === void 0 || (_d$times = d.times) === null || _d$times === void 0 ? void 0 : _d$times.length;
	}) ? locales.getText("pisell2.attendance.group-settings.shift-schedule.scheduled-shifts.change-shifts") : locales.getText("pisell2.attendance.group-settings.shift-schedule.scheduled-shifts.set-shifts");
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Button, {
		type: "primary",
		onClick: () => setOpen(true)
	}, label), /* @__PURE__ */ React.createElement(ShiftModal, {
		open,
		value,
		onCancel: () => setOpen(false),
		onOk: (next) => {
			onChange === null || onChange === void 0 || onChange(next);
		}
	}));
};
const ShiftScheduleTab = (props) => {
	return /* @__PURE__ */ React.createElement("div", {
		className: "saas-attendance-group-settings__panel",
		id: props.id
	}, /* @__PURE__ */ React.createElement("div", { className: "saas-attendance-group-settings__banner banner-blue" }, /* @__PURE__ */ React.createElement("div", { className: "banner-icon" }, /* @__PURE__ */ React.createElement(Icon, {
		type: "pisell2-calendar",
		size: 20
	})), /* @__PURE__ */ React.createElement("div", { className: "banner-body" }, /* @__PURE__ */ React.createElement("div", { className: "banner-title" }, locales.getText("pisell2.attendance.group-settings.shift-schedule.fixed-shifts.title")), /* @__PURE__ */ React.createElement("div", { className: "banner-desc" }, locales.getText("pisell2.attendance.group-settings.shift-schedule.fixed-shifts.desc")))), /* @__PURE__ */ React.createElement(Form.Item, {
		label: locales.getText("pisell2.attendance.group-settings.shift-schedule.attendance-type.label"),
		name: ["shift", "type"],
		initialValue: "fixed"
	}, /* @__PURE__ */ React.createElement(Radio.Group, { className: "saas-attendance-group-settings__radio-cards" }, /* @__PURE__ */ React.createElement("label", { className: "saas-attendance-group-settings__radio-card saas-attendance-group-settings__radio-card--selected" }, /* @__PURE__ */ React.createElement(Radio, { value: "fixed" }), /* @__PURE__ */ React.createElement("div", { className: "saas-attendance-group-settings__radio-content" }, /* @__PURE__ */ React.createElement("div", { className: "saas-attendance-group-settings__radio-title" }, locales.getText("pisell2.attendance.group-settings.shift-schedule.attendance-type.scheduled-shifts.title")), /* @__PURE__ */ React.createElement("div", { className: "saas-attendance-group-settings__radio-desc" }, locales.getText("pisell2.attendance.group-settings.shift-schedule.fixed-shifts.desc")))))), /* @__PURE__ */ React.createElement(Form.Item, {
		name: ["shift", "fixed"],
		rules: [{ validator: function() {
			var _ref = _asyncToGenerator(function* (_rule, value) {
				if (!(Array.isArray(value) && value.some((item) => Array.isArray(item === null || item === void 0 ? void 0 : item.times) && item.times.length > 0))) throw new Error(locales.getText("pisell2.attendance.group-settings.shift-schedule.validation.fixed-required"));
			});
			return function validator(_x, _x2) {
				return _ref.apply(this, arguments);
			};
		}() }]
	}, /* @__PURE__ */ React.createElement(ScheduleSetting, null)), /* @__PURE__ */ React.createElement(Form.Item, {
		noStyle: true,
		shouldUpdate: true
	}, (form) => /* @__PURE__ */ React.createElement(ShiftPreview, { value: form.getFieldValue(["shift", "fixed"]) })));
};
//#endregion
export { ShiftScheduleTab as default };
