var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/authentication/admin/ChannelAuthSetting/PageSettingItem/index.tsx
var PageSettingItem_exports = {};
__export(PageSettingItem_exports, {
  default: () => PageSettingItem_default
});
module.exports = __toCommonJS(PageSettingItem_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("./locales"));
var import_useEngineContext = __toESM(require("../../../../../hooks/useEngineContext"));
var import_materials = require("@pisell/materials");
var import_PageSettingItem = require("./PageSettingItem.less");
var PageSettingItem = (0, import_react.forwardRef)(({
  className,
  style,
  value,
  onChange,
  showImageUpload = true
}, ref) => {
  var _a, _b, _c, _d;
  const context = (0, import_useEngineContext.default)();
  const appHelper = context == null ? void 0 : context.appHelper;
  import_utils.locales.init(import_locales.default, ((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "en");
  const [form] = import_antd.Form.useForm();
  (0, import_react.useImperativeHandle)(ref, () => ({
    validateFields: () => form.validateFields()
  }));
  const previousValueRef = (0, import_react.useRef)(value);
  (0, import_react.useEffect)(() => {
    const prevValue = previousValueRef.current;
    const hasValueChanged = (value == null ? void 0 : value.backgroundImage) !== (prevValue == null ? void 0 : prevValue.backgroundImage) || JSON.stringify(value == null ? void 0 : value.termsConditions) !== JSON.stringify(prevValue == null ? void 0 : prevValue.termsConditions);
    if (hasValueChanged) {
      const defaultName = {
        en: "",
        "zh-CN": "",
        "zh-HK": "",
        ja: "",
        pt: "",
        original: ""
      };
      form.setFieldsValue({
        backgroundImage: (value == null ? void 0 : value.backgroundImage) || "",
        termsConditions: (value == null ? void 0 : value.termsConditions) || [
          {
            name: {
              en: "Terms of Service",
              "zh-CN": "服务条款",
              "zh-HK": "服務條款",
              original: "Terms of Service",
              ja: "利用規約",
              pt: "Termos de Serviço"
            },
            url: "https://example.com/terms"
          },
          {
            name: {
              en: "Privacy Policy",
              "zh-CN": "隐私政策",
              "zh-HK": "隱私政策",
              original: "Privacy Policy",
              ja: "プライバシーポリシー",
              pt: "Política de Privacidade"
            },
            url: "https://example.com/privacy"
          }
        ]
      });
      previousValueRef.current = value;
    }
  }, [value, form]);
  const handleFormChange = () => {
    const formValues = form.getFieldsValue();
    const newValue = {
      backgroundImage: formValues.backgroundImage || "",
      termsConditions: formValues.termsConditions || []
    };
    onChange == null ? void 0 : onChange(newValue);
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("page-setting-item", className), style }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form, { form, onValuesChange: handleFormChange }, showImageUpload && /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-section page-setting-item-background" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-section-title" }, import_utils.locales.getText("page.setting.item.background.title")), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "backgroundImage", style: { margin: 0 } }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.FormItemUpload,
    {
      renderMode: "edit",
      mediaUploadUrl: (_c = appHelper == null ? void 0 : appHelper.constants) == null ? void 0 : _c.mediaUploadUrl,
      getHeaders: (_d = appHelper == null ? void 0 : appHelper.constants) == null ? void 0 : _d.getHeaders,
      maxCount: 1,
      multiple: false,
      enableCustomType: true,
      customType: [".png", ".jpg", ".jpeg"],
      allowPreview: true
    }
  ))), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-section page-setting-item-terms" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-section-header" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-section-title" }, import_utils.locales.getText("page.setting.item.terms.title")), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-section-subtitle" }, import_utils.locales.getText("page.setting.item.terms.subtitle"))), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-terms-table" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-terms-table-header" }, /* @__PURE__ */ import_react.default.createElement("div", null, import_utils.locales.getText("page.setting.item.terms.table.name")), /* @__PURE__ */ import_react.default.createElement("div", null, import_utils.locales.getText("page.setting.item.terms.table.url")), /* @__PURE__ */ import_react.default.createElement("div", { style: { textAlign: "center" } }, import_utils.locales.getText("page.setting.item.terms.table.action"))), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.List, { name: "termsConditions" }, (fields, { add, remove }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-terms-table-body" }, fields.map((field) => /* @__PURE__ */ import_react.default.createElement("div", { key: field.key, className: "page-setting-item-terms-table-row" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-terms-table-cell" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      ...field,
      name: [field.name, "name"],
      validateTrigger: ["onChange", "onBlur"],
      rules: [
        {
          validator: (_, value2) => {
            if (!value2 || !value2.original || !value2.original.trim()) {
              return Promise.reject(
                new Error(import_utils.locales.getText("page.setting.item.terms.error.name.required"))
              );
            }
            return Promise.resolve();
          }
        }
      ],
      style: { margin: 0, flex: 1 }
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_materials.BaseTranslation,
      {
        renderMode: "edit",
        placeholder: import_utils.locales.getText(
          "page.setting.item.terms.table.name.placeholder"
        )
      }
    )
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-terms-table-cell" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      ...field,
      name: [field.name, "url"],
      validateTrigger: ["onChange", "onBlur"],
      rules: [
        {
          validator: (_, value2) => {
            if (!value2 || !value2.trim()) {
              return Promise.reject(
                new Error(import_utils.locales.getText("page.setting.item.terms.error.url.required"))
              );
            }
            return Promise.resolve();
          }
        },
        {
          type: "url",
          message: import_utils.locales.getText("page.setting.item.terms.error.url.invalid")
        }
      ],
      style: { margin: 0, flex: 1 }
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Input,
      {
        placeholder: import_utils.locales.getText(
          "page.setting.item.terms.table.url.placeholder"
        )
      }
    )
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-terms-table-actions" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Button,
    {
      type: "text",
      danger: true,
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.DeleteOutlined, null),
      size: "small",
      onClick: () => remove(field.name)
    }
  ))))), /* @__PURE__ */ import_react.default.createElement("div", { className: "page-setting-item-terms-add-row" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Button,
    {
      type: "default",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null),
      onClick: () => add({
        name: {
          en: "",
          "zh-CN": "",
          "zh-HK": "",
          ja: "",
          pt: "",
          original: ""
        },
        url: ""
      }),
      className: "page-setting-item-terms-add-button"
    },
    import_utils.locales.getText("page.setting.item.terms.button.add")
  ))))))));
});
PageSettingItem.displayName = "PageSettingItem";
var PageSettingItem_default = PageSettingItem;
