"use strict";(self.webpackChunknocobase=self.webpackChunknocobase||[]).push([[6534,1442],{41442:function(_,n,e){e.r(n),e.d(n,{JSItemRunJSContext:function(){return r}});var s=e(72004),t=e.n(s),a=e(12444),l=e.n(a),i=e(31996),m=e.n(i),d=e(26037),u=e.n(d),c=e(67946),r=function(b){m()(o,b);var p=u()(o);function o(){return l()(this,o),p.apply(this,arguments)}return t()(o)}(c.Uo);r.define({label:"JSItem RunJS context",properties:{element:`ElementProxy instance providing a safe DOM container for form item rendering.
      Supports innerHTML, append, and other DOM manipulation methods.`,resource:`Current resource instance (read-only).
      Provides access to the data resource associated with the current form context.`,record:`Current record data object (read-only).
      Contains all field values of the parent record.`,formValues:{description:"Snapshot of current form values (object). Available in form contexts (CreateForm/EditForm).",detail:"Record<string, any>",examples:["const { name, status } = ctx.formValues || {};"]}},methods:{onRefReady:`Wait for form item container DOM element to be ready before executing callback.
      Parameters: (ref: React.RefObject, callback: (element: HTMLElement) => void, timeout?: number) => void`}}),r.define({label:"JS \u8868\u5355\u9879 RunJS \u4E0A\u4E0B\u6587",properties:{element:"ElementProxy\uFF0C\u8868\u5355\u9879\u6E32\u67D3\u5BB9\u5668\uFF0C\u652F\u6301 innerHTML/append \u7B49 DOM \u64CD\u4F5C",resource:"\u5F53\u524D\u8D44\u6E90\uFF08\u53EA\u8BFB\uFF09",record:"\u5F53\u524D\u8BB0\u5F55\uFF08\u53EA\u8BFB\uFF09",formValues:{description:"\u5F53\u524D\u8868\u5355\u503C\u5FEB\u7167\uFF08\u5BF9\u8C61\uFF09\u3002\u4EC5\u8868\u5355\u76F8\u5173\u4E0A\u4E0B\u6587\u53EF\u7528\uFF08Create/Edit Form\uFF09\u3002",detail:"Record<string, any>",examples:["const { name, status } = ctx.formValues || {};"]}},methods:{onRefReady:"\u5BB9\u5668\u5C31\u7EEA\u540E\u6267\u884C\u56DE\u8C03\u3002\u53C2\u6570\uFF1A(ref, callback, timeout?)"}},{locale:"zh-CN"})},76534:function(_,n,e){e.r(n);var s=e(41442),t={contexts:[s.JSItemRunJSContext],prefix:"sn-link-copy",label:"Copy value from another field",description:"Copy value from one field to another when checkbox is checked",locales:{"zh-CN":{label:"\u590D\u5236\u5B57\u6BB5\u503C",description:"\u52FE\u9009\u590D\u9009\u6846\u65F6\uFF0C\u5C06\u4E00\u4E2A\u5B57\u6BB5\u7684\u503C\u590D\u5236\u5230\u53E6\u4E00\u4E2A\u5B57\u6BB5"}},content:`
// When 'sameAsAbove' is checked, copy billing address to shipping address
const sameAsAbove = ctx.record?.sameAsAbove;

if (!sameAsAbove) {
  return;
}

const items = ctx.model?.subModels?.grid?.subModels?.items;
const candidates = Array.isArray(items) ? items : Array.from(items?.values?.() || items || []);

// Source and target field mappings
const fieldMappings = [
  { from: 'billingAddress', to: 'shippingAddress' },
  { from: 'billingCity', to: 'shippingCity' },
  { from: 'billingZipCode', to: 'shippingZipCode' },
];

fieldMappings.forEach(({ from, to }) => {
  const sourceValue = ctx.record?.[from];
  const targetField = candidates.find((item) => item?.props?.name === to);

  if (targetField) {
    targetField.setProps({ value: sourceValue });
  }
});

ctx.message?.success?.(ctx.t('Address copied successfully'));
`};n.default=t}}]);
