@object-ui/fields 7.2.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/index.cjs +3 -3
- package/dist/index.js +17 -67
- package/dist/widgets/UserField.d.ts +12 -3
- package/package.json +7 -7
- package/src/index.tsx +5 -0
- package/src/widgets/UserField.tsx +29 -78
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @object-ui/fields
|
|
2
2
|
|
|
3
|
+
## 7.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 788dbf9: feat(fields): wire the `user` field picker to a real `sys_user` search
|
|
8
|
+
|
|
9
|
+
The `user`/`owner` field widgets previously rendered a placeholder ("User
|
|
10
|
+
selection component requires integration with user management system") and the
|
|
11
|
+
form-type map fell through to `field:text`, so a `user` field rendered as a
|
|
12
|
+
plain text input.
|
|
13
|
+
|
|
14
|
+
`UserField` now **delegates to the shared `LookupField`** with the reference
|
|
15
|
+
fixed to `sys_user` — reusing the existing debounced candidate search, the
|
|
16
|
+
record-picker dialog, and id resolution — so selecting a person works the same
|
|
17
|
+
way as any lookup, with zero bespoke data plumbing. `mapFieldTypeToFormType`
|
|
18
|
+
now maps `user`/`owner` to `field:user`/`field:owner`, satisfying the existing
|
|
19
|
+
`field-type-coverage` regression guard (which already listed both but had no
|
|
20
|
+
mapping wired — the widget map and cell renderers were registered, the form-type
|
|
21
|
+
map was the missing link). Table-cell display continues to use `UserCellRenderer`
|
|
22
|
+
(avatars/initials).
|
|
23
|
+
|
|
24
|
+
Pairs with the framework `user` field type (a lookup specialized to `sys_user`).
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- @object-ui/types@7.3.0
|
|
29
|
+
- @object-ui/core@7.3.0
|
|
30
|
+
- @object-ui/i18n@7.3.0
|
|
31
|
+
- @object-ui/react@7.3.0
|
|
32
|
+
- @object-ui/components@7.3.0
|
|
33
|
+
- @object-ui/providers@7.3.0
|
|
34
|
+
|
|
3
35
|
## 7.2.0
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(e&&(t=e(e=0)),t),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,a)=>(a=n==null?{}:e(i(n)),c(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let u=require("react");u=l(u,1);let d=require("@object-ui/core"),f=require("@object-ui/i18n"),p=require("@object-ui/components"),m=require("lucide-react"),h=require("@object-ui/react"),g=require("react/jsx-runtime"),_=require("@object-ui/providers"),v=require("react-markdown");v=l(v,1);let y=require("remark-gfm");y=l(y,1);let b=require("rehype-sanitize");b=l(b,1);var x=s({TextField:()=>S});function S({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema;if(r)return(0,g.jsx)(`span`,{className:`text-sm`,children:e||(0,g.jsx)(p.EmptyValue,{})});let o=a?.rows,{inputType:s,...c}=i;return o&&o>1?(0,g.jsx)(p.Textarea,{...c,value:e||``,onChange:e=>t(e.target.value),placeholder:a?.placeholder,disabled:r||c.disabled}):(0,g.jsx)(p.Input,{...c,type:a?.type===`password`?`password`:`text`,value:e||``,onChange:e=>t(e.target.value),placeholder:a?.placeholder,disabled:r||c.disabled})}var C=o((()=>{})),w=s({NumberField:()=>T});function T({value:e,onChange:t,field:n,readonly:r,...i}){if(r)return e==null?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`text-sm`,children:e});let a=n||i.schema,o=a?.precision,{inputType:s,...c}=i;return(0,g.jsx)(p.Input,{...c,type:`number`,value:e??``,onChange:e=>{let n=e.target.value;t(n===``?null:Number(n))},placeholder:a?.placeholder,disabled:r||c.disabled,step:o?10**-o:`any`})}var E=o((()=>{})),D=s({BooleanField:()=>O});function O({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=a?.widget,s=(0,u.useId)(),c=a?.name||s,l=a?.label||`Checkbox`;if(r)return(0,g.jsx)(`span`,{className:`text-sm`,children:e?`Yes`:`No`});let{inputType:d,...f}=i;return o===`checkbox`?(0,g.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,g.jsx)(p.Checkbox,{...f,id:c,checked:!!e,onCheckedChange:e=>t(!!e),disabled:r||f.disabled}),(0,g.jsx)(p.Label,{htmlFor:c,className:`sr-only`,children:l})]}):(0,g.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,g.jsx)(p.Switch,{...f,id:c,checked:!!e,onCheckedChange:t,disabled:r||f.disabled}),(0,g.jsx)(p.Label,{htmlFor:c,className:`sr-only`,children:l})]})}var k=o((()=>{})),A,ee,j=o((()=>{A={"common.selectOption":`Select an option`,"common.select":`Select...`,"common.search":`Search`,"common.loading":`Loading...`,"common.noResults":`No results found`,"common.cancel":`Cancel`,"common.confirm":`Confirm`,"table.selected":`{{count}} selected`,"table.search":`Search...`,"lookup.loading":`Loading…`,"lookup.noOptions":`No options found`,"lookup.noRecords":`No records found`,"lookup.recentlyUsed":`Recently used`,"lookup.allResults":`All results`,"lookup.createNew":`Create new`,"lookup.createNamed":`Create new "{{name}}"`,"lookup.showingResults":`Showing {{shown}} of {{total}} results`,"lookup.showAllResults":`Show all results ({{count}})`,"lookup.selectedBadge":`Selected`,"lookup.browseAll":`Browse all records`,"lookup.remove":`Remove {{label}}`,"lookup.selectFirst":`Select {{fields}} first`,"lookup.selectRecord":`Select record`,"lookup.recordCount":`{{count}} records`,"lookup.recordCountOne":`1 record`,"lookup.pageOf":`Page {{current}} of {{total}}`,"lookup.filters":`Filters`,"lookup.clear":`Clear`,"lookup.yes":`Yes`,"lookup.filterPlaceholder":`Filter {{label}}`,"lookup.prevPage":`Previous page`,"lookup.nextPage":`Next page`,"lookup.jumpToPage":`Jump to page`,"lookup.retry":`Retry`},ee=(0,f.createSafeTranslation)(A,`common.selectOption`)})),M=s({SelectField:()=>N});function N({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=a?.options||[],{t:s}=ee(),c=i.name||a?.name||i.id||``;if(r){let t=o.find(t=>t.value===e)?.label||e;return t?(0,g.jsx)(`span`,{className:`text-sm`,children:t}):(0,g.jsx)(p.EmptyValue,{})}return o.length===0?(0,g.jsx)(`div`,{"data-testid":c?`select-empty-${c}`:void 0,className:`flex h-9 w-full items-center rounded-md border border-input bg-muted/30 px-3 py-2 text-sm text-muted-foreground`,children:`No options available`}):(0,g.jsxs)(p.Select,{...i,value:e,onValueChange:t,disabled:r||i.disabled,children:[(0,g.jsx)(p.SelectTrigger,{className:i.className,id:i.id,"data-testid":c?`select-trigger-${c}`:void 0,children:(0,g.jsx)(p.SelectValue,{placeholder:a?.placeholder||s(`common.selectOption`)})}),(0,g.jsx)(p.SelectContent,{position:`popper`,children:o.map(e=>(0,g.jsx)(p.SelectItem,{value:e.value,"data-testid":`select-option-${e.value}`,children:e.label},e.value))})]})}var P=o((()=>{j()})),F=s({DateField:()=>I});function I({value:e,onChange:t,field:n,readonly:r,...i}){if(r)return e?(0,g.jsx)(`span`,{className:`text-sm`,children:new Date(e).toLocaleDateString()}):(0,g.jsx)(p.EmptyValue,{});let{inputType:a,...o}=i;return(0,g.jsx)(p.Input,{...o,type:`date`,value:e||``,onChange:e=>t(e.target.value),disabled:r||o.disabled})}var L=o((()=>{})),te=s({EmailField:()=>R});function R({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){let o=n||a.schema;if(r)return e?(0,g.jsx)(`a`,{href:`mailto:${e}`,className:`text-sm text-blue-600 hover:text-blue-800 hover:underline`,children:e}):(0,g.jsx)(p.EmptyValue,{});let{inputType:s,...c}=a;return(0,g.jsx)(p.Input,{...c,type:`email`,value:e||``,onChange:e=>t(e.target.value),placeholder:o?.placeholder||`email@example.com`,disabled:r||c.disabled,"aria-invalid":!!i})}var ne=o((()=>{})),z=s({PhoneField:()=>B});function B({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){let o=n||a.schema;if(r)return e?(0,g.jsx)(`a`,{href:`tel:${e}`,className:`text-sm text-blue-600 hover:text-blue-800 hover:underline`,children:e}):(0,g.jsx)(p.EmptyValue,{});let{inputType:s,...c}=a;return(0,g.jsx)(p.Input,{...c,type:`tel`,value:e||``,onChange:e=>t(e.target.value),placeholder:o?.placeholder||`(555) 123-4567`,disabled:r||c.disabled,"aria-invalid":!!i})}var V=o((()=>{})),H=s({UrlField:()=>re});function re({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){let o=n||a.schema;if(r)return e?e.startsWith(`http://`)||e.startsWith(`https://`)?(0,g.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-sm text-blue-600 hover:text-blue-800 hover:underline`,children:e}):(0,g.jsx)(`span`,{className:`text-sm`,children:e}):(0,g.jsx)(p.EmptyValue,{});let{inputType:s,...c}=a;return(0,g.jsx)(p.Input,{...c,type:`url`,value:e||``,onChange:e=>t(e.target.value),placeholder:o?.placeholder||`https://example.com`,disabled:r||c.disabled,"aria-invalid":!!i})}var U=o((()=>{})),ie=o((()=>{})),ae=s({CurrencyField:()=>G});function W(e,t,n){if(t)try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,minimumFractionDigits:n,maximumFractionDigits:n}).format(e)}catch{return`${t} ${e.toFixed(n)}`}try{return new Intl.NumberFormat(`en-US`,{minimumFractionDigits:n,maximumFractionDigits:n}).format(e)}catch{return e.toFixed(n)}}function G({value:e,onChange:t,field:n,readonly:r,errorMessage:i,className:a,...o}){let s=n||o.schema,{currency:c}=(0,f.useLocalization)(),l=(0,f.resolveFieldCurrency)(s,c),u=s?.precision??2;if(r)return e==null?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`text-sm font-medium tabular-nums`,children:W(Number(e),l,u)});let d=e=>{let n=parseFloat(e.target.value);isNaN(n)||t(parseFloat(n.toFixed(u)))},m=l?l===`USD`?`$`:l:``;return(0,g.jsxs)(`div`,{className:`relative`,children:[m&&(0,g.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-sm text-gray-500`,children:m}),(0,g.jsx)(p.Input,{...o,type:`number`,value:e??``,onChange:e=>{t(e.target.value===``?null:parseFloat(e.target.value))},onBlur:d,placeholder:s?.placeholder||`0.00`,disabled:r||o.disabled,className:`${m?`pl-8`:``} ${a||``}`,step:(10**-u).toFixed(u),"aria-invalid":!!i})]})}var oe=o((()=>{ie()})),K=s({TextAreaField:()=>q});function q({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){if(r)return(0,g.jsx)(`div`,{className:`text-sm whitespace-pre-wrap`,children:e||(0,g.jsx)(p.EmptyValue,{})});let o=n||a.schema,s=o?.rows||4,c=o?.max_length,l=!!(a.mobileFullscreen??o?.mobile_fullscreen??a.mobile_fullscreen??a.schema?.mobile_fullscreen),[d,f]=(0,u.useState)(!1),[h,_]=(0,u.useState)(e??``),v=()=>{_(e??``),f(!0)},y=()=>f(!1),b=()=>{t(h),f(!1)},{inputType:x,mobileFullscreen:S,...C}=a;return(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(p.Textarea,{...C,value:e||``,onChange:e=>t(e.target.value),placeholder:o?.placeholder,disabled:r||C.disabled,rows:s,maxLength:c,"aria-invalid":!!i,className:C.className}),l&&(0,g.jsx)(`button`,{type:`button`,onClick:v,className:`absolute top-1.5 right-1.5 inline-flex items-center justify-center size-7 rounded-md bg-background/80 text-muted-foreground hover:text-foreground hover:bg-background border shadow-sm transition-colors`,"aria-label":`Edit ${o?.label??`text`} fullscreen`,"data-testid":`textarea-fullscreen-toggle`,children:(0,g.jsx)(m.Maximize2,{className:`size-3.5`})}),c&&(0,g.jsxs)(`div`,{className:`absolute bottom-2 right-2 text-xs text-gray-400`,"aria-live":`polite`,"aria-label":`Character count: ${(e||``).length} of ${c}`,children:[(e||``).length,`/`,c]}),l&&(0,g.jsx)(p.Dialog,{open:d,onOpenChange:f,children:(0,g.jsxs)(p.DialogContent,{className:`sm:max-w-3xl h-[100dvh] sm:h-[80vh] max-h-[100dvh] sm:max-h-[80vh] flex flex-col p-0 gap-0`,"data-testid":`textarea-fullscreen-dialog`,children:[(0,g.jsx)(p.DialogHeader,{className:`p-4 border-b`,children:(0,g.jsx)(p.DialogTitle,{className:`text-base`,children:o?.label??`Edit text`})}),(0,g.jsx)(`div`,{className:`flex-1 min-h-0 p-4`,children:(0,g.jsx)(p.Textarea,{autoFocus:!0,value:h,onChange:e=>_(e.target.value),maxLength:c,placeholder:o?.placeholder,className:`h-full min-h-full resize-none text-base`,"data-testid":`textarea-fullscreen-input`})}),(0,g.jsxs)(p.DialogFooter,{className:`p-3 border-t flex-row justify-between sm:justify-end gap-2`,children:[c&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground self-center`,children:[h.length,`/`,c]}),(0,g.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,g.jsxs)(p.Button,{type:`button`,variant:`ghost`,onClick:y,children:[(0,g.jsx)(m.X,{className:`size-4 mr-1`}),` Cancel`]}),(0,g.jsxs)(p.Button,{type:`button`,onClick:b,"data-testid":`textarea-fullscreen-save`,children:[(0,g.jsx)(m.Check,{className:`size-4 mr-1`}),` Done`]})]})]})]})})]})}var J=o((()=>{})),se=s({RichTextField:()=>Y});function Y({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){let{t:o}=(0,h.useObjectTranslation)();if(r)return(0,g.jsx)(`div`,{className:`text-sm prose prose-sm max-w-none`,children:e||(0,g.jsx)(p.EmptyValue,{})});let s=n||a.schema,c=s?.rows||8,l=s?.format||`markdown`;return(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-gray-500`,children:[(0,g.jsx)(`span`,{children:o(`fields.richText.format`,{format:l,defaultValue:`Format: ${l}`})}),(0,g.jsx)(`span`,{className:`italic`,children:o(`fields.richText.basicEditorHint`,{defaultValue:`Rich text editor (basic)`})})]}),(0,g.jsx)(p.Textarea,{value:e||``,onChange:e=>t(e.target.value),placeholder:s?.placeholder||o(`fields.richText.placeholder`,{defaultValue:`Enter text...`}),disabled:r||a.disabled,rows:c,className:`font-mono text-sm ${a.className||``}`,"aria-invalid":!!i})]})}var X=o((()=>{}));function ce(e){return typeof e==`string`?{field:e}:e}function le(e){return e.replace(/_/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function ue(e){let t={};for(let n of e)switch(n.operator){case`eq`:t[n.field]=n.value;break;case`ne`:t[n.field]={$ne:n.value};break;case`gt`:t[n.field]={$gt:n.value};break;case`lt`:t[n.field]={$lt:n.value};break;case`gte`:t[n.field]={$gte:n.value};break;case`lte`:t[n.field]={$lte:n.value};break;case`contains`:t[n.field]={$contains:n.value};break;case`in`:t[n.field]={$in:n.value};break;case`notIn`:t[n.field]={$nin:n.value};break}return t}function de(e,t){let n={};for(let r of t){let t=e[r.field];t==null||t===``||(r.type===`boolean`?n[r.field]=!!t:r.type===`text`?n[r.field]={$contains:t}:n[r.field]=t)}return n}function fe({open:e,onOpenChange:t,title:n=`Select Record`,multiple:r=!1,dataSource:i,objectName:a,columns:o,displayField:s=`name`,titleFormat:c,idField:l=`id`,pageSize:d=pe,value:f,onSelect:h,onSelectRecords:_,lookupFilters:v,cellRenderer:y,filterColumns:b,renderFilterBar:x,renderGrid:S}){let{t:C}=ee(),[w,T]=(0,u.useState)([]),[E,D]=(0,u.useState)(!1),[O,k]=(0,u.useState)(null),[A,j]=(0,u.useState)(0),[M,N]=(0,u.useState)(``),[P,F]=(0,u.useState)(1),I=(0,u.useRef)(null),[L,te]=(0,u.useState)(null),[R,ne]=(0,u.useState)(`asc`),[z,B]=(0,u.useState)(new Set),V=(0,u.useRef)(new Map),[H,re]=(0,u.useState)(-1),U=(0,u.useRef)(null),[ie,ae]=(0,u.useState)(!1),[W,G]=(0,u.useState)({}),[oe,K]=(0,u.useState)({}),q=(0,u.useRef)(null),[J,se]=(0,u.useState)(``),Y=(0,u.useMemo)(()=>o&&o.length>0?o.map(ce):[{field:s,label:le(s)}],[o,s]),X=(0,u.useMemo)(()=>{if(b&&b.length>0)return b;if(v&&v.length>0)return v.map(e=>{let t=`text`;return typeof e.value==`boolean`?t=`boolean`:Array.isArray(e.value)?t=`select`:typeof e.value==`number`||e.operator===`gt`||e.operator===`lt`||e.operator===`gte`||e.operator===`lte`?t=`number`:(e.operator===`in`||e.operator===`notIn`)&&(t=`select`),{field:e.field,label:le(e.field),type:t,...Array.isArray(e.value)?{options:e.value.map(e=>{if(typeof e==`object`&&e){let t=e;return{label:String(t.name||t.label||t.title||e),value:e}}return{label:String(e),value:e}})}:{}}})},[b,v]),fe=(0,u.useMemo)(()=>{let e=v?.length?ue(v):{},t=X?.length?de(W,X):{},n={...e,...t};return Object.keys(n).length>0?n:void 0},[v,X,W]),Z=Math.max(1,Math.ceil(A/d)),ge=(0,u.useCallback)(async(e,t=1,n,r)=>{if(!(!i||!a)){D(!0),k(null);try{let o={$top:d,$skip:(t-1)*d};e&&e.trim()&&(o.$search=e.trim()),n&&(o.$orderby={[n.field]:n.direction});let s=r===void 0?fe:r;s&&Object.keys(s).length>0&&(o.$filter=s);let c=await i.find(a,o),l=c?.data??c??[];T(l),j(c?.total??l.length),re(-1)}catch(e){k(e instanceof Error?e.message:String(e)),T([])}finally{D(!1)}}},[i,a,d,fe]),_e=(0,u.useMemo)(()=>L?{field:L,direction:R}:null,[L,R]);(0,u.useEffect)(()=>{e||(N(``),F(1),k(null),T([]),te(null),ne(`asc`),re(-1),ae(!1),G({}),K({}),se(``),B(new Set(r&&Array.isArray(f)?f:[])),V.current.clear())},[e]),(0,u.useEffect)(()=>{e&&ge(M||void 0,P,_e)},[e,P,_e,fe]),(0,u.useEffect)(()=>{e&&r&&B(new Set(Array.isArray(f)?f:[]))},[e,r,f]);let ve=(0,u.useCallback)(e=>{N(e),F(1),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{ge(e||void 0,1,_e)},300)},[ge,_e]);(0,u.useEffect)(()=>()=>{I.current&&clearTimeout(I.current)},[]);let ye=(0,u.useCallback)(e=>{te(t=>t===e?(ne(e=>e===`asc`?`desc`:`asc`),e):(ne(`asc`),e)),F(1)},[]),be=(0,u.useCallback)(e=>e[l]??e.id??e._id,[l]),xe=(0,u.useCallback)(e=>{let t=be(e);return r?z.has(t):f===t},[r,f,z,be]),Se=(0,u.useCallback)(e=>{let n=be(e);r?B(t=>{let r=new Set(t);return r.has(n)?(r.delete(n),V.current.delete(n)):(r.add(n),V.current.set(n,e)),r}):(h(n),_?.([e]),t(!1))},[r,be,h,_,t]),Ce=(0,u.useCallback)(()=>{let e=Array.from(z);h(e);let n=e.map(e=>V.current.get(e)).filter(Boolean);_?.(n),t(!1)},[z,h,_,t]),we=(0,u.useCallback)(()=>{F(e=>Math.max(1,e-1))},[]),Te=(0,u.useCallback)(()=>{F(e=>Math.min(Z,e+1))},[Z]),Ee=(0,u.useCallback)(e=>{if(e.key!==`Enter`)return;let t=parseInt(J,10);!isNaN(t)&&t>=1&&t<=Z&&F(t),se(``)},[J,Z]),De=(0,u.useCallback)(e=>{w.length!==0&&(e.key===`ArrowDown`?(e.preventDefault(),re(e=>Math.min(e+1,w.length-1))):e.key===`ArrowUp`?(e.preventDefault(),re(e=>Math.max(e-1,0))):(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),H>=0&&H<w.length&&Se(w[H])))},[w,H,Se]);(0,u.useEffect)(()=>{if(H>=0&&U.current){let e=U.current.querySelector(`[data-row-index="${H}"]`);e&&typeof e.scrollIntoView==`function`&&e.scrollIntoView({block:`nearest`})}},[H]);let Oe=(0,u.useCallback)((e,t)=>{if(c&&t.field===s){let t=`[-\\u2013\\u2014|/·,:]`,n=!1,r=c.replace(/\{([^{}]+)\}/g,(t,r)=>{let i=e[r.trim()];return i!=null&&i!==``?(n=!0,String(i)):`\0`});if(n){let e=r.replace(RegExp(`\\s*${t}\\s*`,`g`),``).replace(RegExp(`\\s*${t}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim();if(e)return e}}let n=e[t.field];if(t.type&&y){let e=y(t.type);if(e)return(0,g.jsx)(e,{value:n,field:{name:t.field,type:t.type}})}return n==null?``:typeof n==`object`?n.$numberDecimal?String(Number(n.$numberDecimal)):n.$oid?String(n.$oid):n.$date?new Date(n.$date).toLocaleDateString():n.name||n.label?String(n.name||n.label):JSON.stringify(n):typeof n==`boolean`?n?`Yes`:`No`:String(n)},[y,c,s]),ke=(0,u.useCallback)(e=>L===e?R===`asc`?(0,g.jsx)(m.ArrowUp,{className:`ml-1 size-3`}):(0,g.jsx)(m.ArrowDown,{className:`ml-1 size-3`}):(0,g.jsx)(m.ArrowUpDown,{className:`ml-1 size-3 opacity-40`}),[L,R]),Ae=(0,u.useCallback)((e,t,n)=>{e.preventDefault(),e.stopPropagation(),q.current={field:t,startX:e.clientX,startWidth:n};let r=e=>{if(!q.current)return;let t=e.clientX-q.current.startX,n=Math.max(me,q.current.startWidth+t);K(e=>({...e,[q.current.field]:n}))},i=()=>{q.current=null,document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[]),je=(0,u.useCallback)((e,t)=>{G(n=>({...n,[e]:t})),F(1)},[]),Me=(0,u.useCallback)(()=>{G({}),F(1)},[]),Ne=(0,u.useMemo)(()=>Object.values(W).filter(e=>e!=null&&e!==``).length,[W]),Pe=(0,u.useCallback)(e=>{let t=W[e.field],n=e.label||le(e.field);switch(e.type){case`select`:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsxs)(p.Select,{value:t==null?``:String(t),onValueChange:t=>je(e.field,t),children:[(0,g.jsx)(p.SelectTrigger,{className:`h-8 text-xs`,children:(0,g.jsx)(p.SelectValue,{placeholder:C(`lookup.filterPlaceholder`,{label:n})})}),(0,g.jsx)(p.SelectContent,{children:e.options?.map(e=>(0,g.jsx)(p.SelectItem,{value:String(e.value),children:e.label},String(e.value)))})]})]});case`number`:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsx)(p.Input,{type:`number`,className:`h-8 text-xs`,value:t??``,placeholder:C(`lookup.filterPlaceholder`,{label:n}),onChange:t=>{let n=t.target.value;je(e.field,n===``?``:Number(n))}})]});case`date`:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsx)(p.Input,{type:`date`,className:`h-8 text-xs`,value:t??``,onChange:t=>je(e.field,t.target.value)})]});case`boolean`:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,g.jsx)(p.Checkbox,{checked:!!t,onCheckedChange:t=>je(e.field,!!t)}),(0,g.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:C(`lookup.yes`)})]})]});default:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsx)(p.Input,{className:`h-8 text-xs`,value:t??``,placeholder:C(`lookup.filterPlaceholder`,{label:n}),onChange:t=>je(e.field,t.target.value)})]})}},[W,je]),Fe=(0,u.useCallback)((e,t)=>e?`bg-primary/5 hover:bg-primary/10`:t%2==1?`bg-muted/20 hover:bg-accent/30`:`hover:bg-accent/30`,[]);return(0,g.jsx)(p.Dialog,{open:e,onOpenChange:t,children:(0,g.jsxs)(p.DialogContent,{className:`w-[95vw] sm:max-w-3xl lg:max-w-5xl max-h-[85vh] sm:max-h-[80vh] flex flex-col gap-0`,"data-testid":`record-picker-dialog`,children:[(0,g.jsx)(p.DialogHeader,{children:(0,g.jsxs)(p.DialogTitle,{children:[n,r&&(0,g.jsx)(`span`,{className:`sr-only`,children:` (multiple selection)`})]})}),(0,g.jsxs)(`div`,{className:`relative rounded-md border bg-muted/30 mb-3`,children:[(0,g.jsx)(m.Search,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground`}),(0,g.jsx)(p.Input,{placeholder:C(`table.search`),value:M,onChange:e=>ve(e.target.value),className:`pl-9 border-0 bg-transparent shadow-none focus-visible:ring-0`,"data-testid":`record-picker-search`}),E&&(0,g.jsx)(m.Loader2,{className:`absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground`,"data-testid":`record-picker-loading-indicator`})]}),X&&X.length>0&&(0,g.jsx)(`div`,{className:`py-2`,children:x?(0,g.jsx)(`div`,{"data-testid":`record-picker-filter-bar`,children:x({filterColumns:X,values:W,onChange:je,onClear:Me,activeCount:Ne})}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`record-picker-filter-bar`,children:[(0,g.jsxs)(p.Button,{type:`button`,variant:Ne>0?`secondary`:`outline`,size:`sm`,className:`gap-1.5 shrink-0`,onClick:()=>ae(e=>!e),children:[(0,g.jsx)(m.SlidersHorizontal,{className:`size-3.5`}),C(`lookup.filters`),Ne>0&&(0,g.jsx)(`span`,{className:`inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary`,children:Ne})]}),Ne>0&&(0,g.jsxs)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`gap-1 text-xs`,onClick:Me,children:[(0,g.jsx)(m.X,{className:`size-3`}),C(`lookup.clear`)]})]}),ie&&(0,g.jsx)(`div`,{className:`mt-2 grid gap-3 sm:grid-cols-2 lg:grid-cols-3 border rounded-md p-3 bg-muted/30`,"data-testid":`record-picker-filter-panel`,children:X.map(e=>(0,g.jsx)(`div`,{children:Pe(e)},e.field))})]})}),O&&(0,g.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-4`,role:`alert`,children:[(0,g.jsx)(m.AlertCircle,{className:`size-5 text-destructive`}),(0,g.jsx)(`p`,{className:`text-sm text-destructive`,children:O}),(0,g.jsx)(p.Button,{variant:`outline`,size:`sm`,onClick:()=>ge(M||void 0,P,_e),type:`button`,children:C(`lookup.retry`)})]}),S?(0,g.jsx)(`div`,{className:`flex-1 min-h-0`,"data-testid":`record-picker-grid-slot`,children:S({columns:Y,records:w,loading:E,totalCount:A,currentPage:P,pageSize:d,sortField:L,sortDirection:R,onSort:ye,onPageChange:F,onRowClick:Se,isSelected:xe,multiple:r,idField:l,cellRenderer:y})}):(0,g.jsxs)(g.Fragment,{children:[E&&w.length===0&&!O&&(0,g.jsx)(`div`,{className:`flex-1 overflow-hidden min-h-0 border rounded-md`,role:`status`,"aria-live":`polite`,"data-testid":`record-picker-skeleton`,children:(0,g.jsxs)(p.Table,{children:[(0,g.jsx)(p.TableHeader,{children:(0,g.jsxs)(p.TableRow,{className:`bg-muted/40`,children:[r&&(0,g.jsx)(p.TableHead,{className:`w-10`}),Y.map(e=>(0,g.jsx)(p.TableHead,{children:(0,g.jsx)(p.Skeleton,{className:`h-4 w-20`})},e.field))]})}),(0,g.jsx)(p.TableBody,{children:Array.from({length:he},(e,t)=>(0,g.jsxs)(p.TableRow,{children:[r&&(0,g.jsx)(p.TableCell,{className:`w-10`,children:(0,g.jsx)(p.Skeleton,{className:`size-4 rounded`})}),Y.map(e=>(0,g.jsx)(p.TableCell,{children:(0,g.jsx)(p.Skeleton,{className:`h-4 w-full`})},e.field))]},t))})]})}),!E&&!O&&w.length===0&&(0,g.jsx)(`div`,{className:`py-8 text-center`,children:(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:C(`lookup.noRecords`)})}),!O&&w.length>0&&(0,g.jsxs)(`div`,{className:`relative flex-1 overflow-auto min-h-0 border rounded-md`,"aria-busy":E||void 0,"data-state":E?`loading`:`idle`,tabIndex:0,onKeyDown:De,role:`grid`,"aria-label":`Records`,children:[E&&(0,g.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/60`,"data-testid":`record-picker-loading-overlay`,children:(0,g.jsx)(m.Loader2,{className:`size-6 animate-spin text-muted-foreground`})}),(0,g.jsxs)(p.Table,{style:Object.keys(oe).length>0?{tableLayout:`fixed`}:void 0,children:[(0,g.jsx)(p.TableHeader,{className:`sticky top-0 z-[5] bg-muted/50 [&_tr]:border-b`,"data-testid":`record-picker-sticky-header`,children:(0,g.jsxs)(p.TableRow,{children:[r&&(0,g.jsx)(p.TableHead,{className:`w-10`}),Y.map(e=>{let t=oe[e.field];return(0,g.jsxs)(p.TableHead,{style:t?{width:`${t}px`,minWidth:`${t}px`}:e.width?{width:e.width}:void 0,className:`cursor-pointer select-none relative group text-xs font-semibold uppercase tracking-wider`,onClick:()=>ye(e.field),"aria-sort":L===e.field?R===`asc`?`ascending`:`descending`:`none`,children:[(0,g.jsxs)(`span`,{className:`inline-flex items-center`,children:[e.label||le(e.field),ke(e.field)]}),(0,g.jsx)(`span`,{role:`separator`,"aria-orientation":`vertical`,className:`absolute right-0 top-0 bottom-0 w-1 cursor-col-resize opacity-0 group-hover:opacity-100 bg-border hover:bg-primary/50 transition-opacity`,onMouseDown:t=>{let n=t.currentTarget.parentElement?.getBoundingClientRect();Ae(t,e.field,n?.width??100)},onClick:e=>e.stopPropagation(),"data-testid":`resize-handle-${e.field}`})]},e.field)})]})}),(0,g.jsx)(p.TableBody,{ref:U,children:w.map((e,t)=>{let n=be(e),i=xe(e),a=t===H;return(0,g.jsxs)(p.TableRow,{"data-row-index":t,className:(0,p.cn)(`cursor-pointer transition-colors`,Fe(i,t),a&&`ring-2 ring-primary ring-inset`),onClick:()=>Se(e),"data-testid":`record-row-${n}`,"aria-selected":i,children:[r&&(0,g.jsx)(p.TableCell,{className:`w-10`,children:i&&(0,g.jsx)(m.Check,{className:`size-4 text-primary`})}),Y.map(t=>(0,g.jsx)(p.TableCell,{className:`py-2.5`,children:Oe(e,t)},t.field))]},n??t)})})]})]}),!O&&A>0&&(0,g.jsxs)(`div`,{className:`flex items-center justify-between text-sm text-muted-foreground border-t pt-3 mt-2 px-1`,"data-testid":`record-picker-pagination`,children:[(0,g.jsxs)(`span`,{children:[A===1?C(`lookup.recordCountOne`):C(`lookup.recordCount`,{count:A}),Z>1&&` · ${C(`lookup.pageOf`,{current:P,total:Z})}`]}),Z>1&&(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,g.jsx)(p.Button,{variant:`outline`,size:`icon`,className:`size-7`,onClick:we,disabled:P<=1,type:`button`,"aria-label":C(`lookup.prevPage`),children:(0,g.jsx)(m.ChevronLeft,{className:`size-4`})}),(0,g.jsx)(p.Input,{className:`h-7 w-12 text-center text-xs px-1`,placeholder:String(P),value:J,onChange:e=>se(e.target.value),onKeyDown:Ee,"aria-label":C(`lookup.jumpToPage`),"data-testid":`record-picker-page-jump`}),(0,g.jsx)(p.Button,{variant:`outline`,size:`icon`,className:`size-7`,onClick:Te,disabled:P>=Z,type:`button`,"aria-label":C(`lookup.nextPage`),children:(0,g.jsx)(m.ChevronRight,{className:`size-4`})})]})]})]}),r&&(0,g.jsx)(p.DialogFooter,{children:(0,g.jsxs)(`div`,{className:`flex items-center gap-2 w-full justify-between`,children:[(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:C(`table.selected`,{count:z.size})}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsx)(p.Button,{variant:`outline`,type:`button`,onClick:()=>t(!1),children:C(`common.cancel`)}),(0,g.jsx)(p.Button,{type:`button`,onClick:Ce,children:C(`common.confirm`)})]})]})})]})})}var pe,me,he,Z=o((()=>{j(),pe=10,me=60,he=5}));function ge(e){let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n}function _e(e,{displayField:t,max:n=4}){let r=e?.fields??{},i=e=>r[e]??{},a=e=>{let t=i(e);return{field:e,...t.label?{label:t.label}:{},...t.type?{type:t.type}:{}}};if(Object.keys(r).length===0)return[];let o=e?.displayFields;return Array.isArray(o)&&o.length>0?ge([t,...o.filter(e=>typeof e==`string`&&e.length>0).filter(e=>e!==t)]).slice(0,n).map(a):ge([t,...Object.keys(r).filter(e=>{if(e===t||ve.has(e))return!1;let n=i(e);return!(n.hidden||n.type&&ye.has(n.type))})]).slice(0,n).map(a)}var ve,ye,be=o((()=>{ve=new Set([`id`,`_id`,`created`,`modified`,`created_at`,`updated_at`,`created_by`,`updated_by`,`modified_by`,`owner_id`,`organization_id`,`space`,`company_id`,`instance_state`,`locked`,`is_deleted`,`deleted`]),ye=new Set([`json`,`object`,`grid`,`html`,`richtext`,`markdown`,`code`,`image`,`file`,`avatar`,`vector`,`location`,`geometry`,`textarea`,`secret`,`password`,`encrypted`])}));function xe(){try{return typeof localStorage<`u`?localStorage:null}catch{return null}}function Se(e){let t=xe();if(!e||!t)return[];try{let n=t.getItem(we+e);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?r.slice(0,Te):[]}catch{return[]}}function Ce(e,t){let n=xe();if(!(!e||t==null||t===``||!n))try{let r=[t,...Se(e).filter(e=>e!==t)].slice(0,Te);n.setItem(we+e,JSON.stringify(r))}catch{}}var we,Te,Ee=o((()=>{we=`objectui:lookup:recent:`,Te=5}));function De(e){ke=e}function Oe(){return ke}var ke,Ae=o((()=>{})),je=s({LookupField:()=>Fe});function Me(e,t){if(!e||typeof e!=`object`||!t)return null;let n=`[-\\u2013\\u2014|/·,:]`,r=!1,i=t.replace(/\{([^{}]+)\}/g,(t,n)=>{let i=e[n.trim()];return i!=null&&i!==``?(r=!0,String(i)):`\0`});return r&&i.replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim()||null}function Ne(e,t,n,r,i){let a=e[n]??e.id??e._id,o=(i?Me(e,i):null)??e[t]??e.label??e.name??e.full_name??e.title??e.subject??String(a),s=r?e[r]:void 0;return{value:a,label:String(o),description:s,...e}}function Pe(e){return{text:`text`,number:`number`,currency:`number`,percent:`number`,select:`select`,status:`select`,date:`date`,datetime:`date`,boolean:`boolean`}[e]}function Fe({value:e,onChange:t,field:n,readonly:r,...i}){let[a,o]=(0,u.useState)(!1),[s,c]=(0,u.useState)(``),{t:l}=ee(),d=u.default.useId(),[f,h]=(0,u.useState)([]),[_,v]=(0,u.useState)(!1),[y,b]=(0,u.useState)(null),[x,S]=(0,u.useState)(0),C=(0,u.useRef)(null),[w,T]=(0,u.useState)([]),[E,D]=(0,u.useState)(-1),O=(0,u.useRef)(null),k=n||i.schema,A=k?.field,j=A&&typeof A==`object`&&(`reference_to`in A||`reference`in A||`type`in A)?A:k,M=j?.options||[],N=j?.multiple||!1,P=j?.display_field||j?.displayField||j?.reference_field||`name`,F=j?.description_field??j?.descriptionField,I=j?.id_field||`id`,L=j?.reference_to||j?.reference,te=!!(j?.allow_create??j?.allowCreate),R=j?.lookup_columns??j?.lookupColumns,ne=j?.lookup_page_size??j?.lookupPageSize,z=j?.lookup_filters??j?.lookupFilters,B=(0,u.useMemo)(()=>{let e=j?.depends_on??j?.dependsOn;return e&&Array.isArray(e)?e.map(e=>typeof e==`string`?{field:e,param:e}:{field:e.field,param:e.param??e.field}):[]},[j?.depends_on,j?.dependsOn]),V=i.dependentValues,H=(0,u.useContext)(Le),re=H?.dataSource??null,U=i.dataSource??k?.dataSource??j?.dataSource??re,ie=(0,u.useMemo)(()=>V||(H?.formValues??H?.data??{}),[V,H?.formValues,H?.data]),ae=(0,u.useMemo)(()=>B.length===0?!1:B.some(({field:e})=>{let t=ie[e];return t==null||t===``||Array.isArray(t)&&t.length===0}),[B,ie]),W=U!=null&&typeof U.find==`function`&&!!L,[G,oe]=(0,u.useState)(null);(0,u.useEffect)(()=>{if(!U||!L)return;let e=U.getObjectSchema;if(typeof e!=`function`)return;let t=!0;return Promise.resolve(e.call(U,L)).then(e=>{t&&oe(e)}).catch(()=>{}),()=>{t=!1}},[U,L]);let K=(0,u.useMemo)(()=>{let e=G?.titleFormat;return typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:null},[G]),q=(0,u.useMemo)(()=>{if(R&&R.length>0)return R;let e=_e(G,{displayField:P});return e.length>0?e:void 0},[R,G,P]),J=(0,u.useMemo)(()=>{if(F)return F;let e=q?.find(e=>(typeof e==`string`?e:e.field)!==P);if(e)return typeof e==`string`?e:e.field},[F,q,P]),se=(0,u.useMemo)(()=>{if(!q)return;let e=[];for(let t of q)if(typeof t==`object`&&t.type){let n=Pe(t.type);n&&e.push({field:t.field,label:t.label,type:n})}return e.length>0?e:void 0},[q]),Y=i.onCreateNew??k?.onCreateNew,[X,ce]=(0,u.useState)(!1),le=W?f:M,de=(0,u.useMemo)(()=>{if(W||!s)return le;let e=s.toLowerCase();return le.filter(t=>t.label.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[W,le,s]);(0,u.useEffect)(()=>{D(-1)},[de.length]);let pe=(0,u.useCallback)(async e=>{if(!(!U||!L)){if(ae){h([]),S(0);return}v(!0),b(null);try{let t={$top:Ie};if(e&&e.trim()&&(t.$search=e.trim()),B.length>0){let e={};for(let{field:t,param:n}of B){let r=ie[t];r==null||r===``||(e[n]=typeof r==`number`?r:String(r))}Object.keys(e).length>0&&(t.$filter=e)}z&&z.length>0&&(t.$filter={...t.$filter??{},...ue(z)});let n=await U.find(L,t),r=n?.data??n??[];h(r.map(e=>Ne(e,P,I,J,K))),S(n?.total??r.length)}catch(e){b(e instanceof Error?e.message:String(e)),h([])}finally{v(!1)}}},[U,L,P,I,J,K,ae,B,ie,z]);(0,u.useEffect)(()=>{a&&W&&B.length>0&&pe(s||void 0)},[(0,u.useMemo)(()=>B.map(e=>`${e.param}=${ie[e.field]??``}`).join(`|`),[B,ie])]),(0,u.useEffect)(()=>{a&&W&&pe(s||void 0),a||(c(``),b(null),D(-1))},[a]);let me=(0,u.useCallback)(e=>{c(e),W&&(C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{pe(e||void 0)},300))},[W,pe]);(0,u.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]),(0,u.useEffect)(()=>{if(!W||!U||!L)return;let t=N?Array.isArray(e)?e:[]:e!=null&&e!==``?[e]:[];if(!t.length)return;let n=t.filter(e=>!he(e));if(!n.length)return;let r=!1;return(async()=>{try{let e=[];for(let t of n)if(typeof U.findOne==`function`){let n=await U.findOne(L,t);n&&e.push(Ne(n,P,I,J,K))}else{let n=await U.find(L,{$filter:{[I]:t},$top:1}),r=n?.data??n??[];r[0]&&e.push(Ne(r[0],P,I,J,K))}!r&&e.length&&T(t=>{let n=new Map(t.map(e=>[e.value,e]));for(let t of e)n.set(t.value,t);return Array.from(n.values())})}catch{}})(),()=>{r=!0}},[e,W,L,P,I,J,N]);let he=(0,u.useCallback)(e=>M.find(t=>t.value===e)??f.find(t=>t.value===e)??w.find(t=>t.value===e),[M,f,w]),Z=N?(Array.isArray(e)?e:[]).map(he).filter(Boolean):e?[he(e)].filter(Boolean):[],ge=i.onSelectRecord,ve=(0,u.useCallback)(n=>{if(N){let r=Array.isArray(e)?e:[];r.includes(n.value)?t(r.filter(e=>e!==n.value)):(L&&Ce(L,n.value),t([...r,n.value]))}else L&&Ce(L,n.value),ge?ge(n):t(n.value),o(!1)},[N,e,t,ge,L]),ye=n=>{t(N?(Array.isArray(e)?e:[]).filter(e=>e!==n):null)},be=(0,u.useCallback)(e=>{let t=e.map(e=>Ne(e,P,I,J,K));L&&t.forEach(e=>Ce(L,e.value)),T(t)},[P,I,J,K,L]),[xe,we]=(0,u.useState)([]);(0,u.useEffect)(()=>{if(!a||!W||!U||!L||s)return;let e=Se(L);if(!e.length){we([]);return}let t=!1;return(async()=>{try{let n=[];for(let t of e){let e=he(t);if(e){n.push(e);continue}if(typeof U.findOne==`function`){let e=await U.findOne(L,t);e&&n.push(Ne(e,P,I,J,K))}}t||we(n)}catch{t||we([])}})(),()=>{t=!0}},[a,W,L,s]);let Te=!s&&W?xe.length:0,Ee=(0,u.useMemo)(()=>{if(s||!W||xe.length===0)return de;let e=new Set(xe.map(e=>e.value));return[...xe,...de.filter(t=>!e.has(t.value))]},[s,W,xe,de]);(0,u.useEffect)(()=>{D(-1)},[Ee.length]);let[De,ke]=(0,u.useState)(!1),Ae=!!Y||te&&W,je=(0,u.useCallback)(async e=>{let t=(e||``).trim();if(Y){Y(t),o(!1);return}if(!(!te||!U||!L||!t)){ke(!0),b(null);try{let e=Ne(await U.create(L,{[P]:t}),P,I,J,K);T(t=>[e,...t.filter(t=>t.value!==e.value)]),ve(e)}catch(e){b(e instanceof Error?e.message:String(e))}finally{ke(!1)}}},[Y,te,U,L,P,I,J,K,ve]),Me=(0,u.useCallback)(e=>{if(!q||q.length===0)return;let t=[];for(let n of q){let r=typeof n==`string`?n:n.field;if(r===P)continue;let i=e[r];if(i==null||i===``)continue;let a=typeof n==`string`?r:n.label||r,o=typeof i==`object`?i.name??i.label??JSON.stringify(i):i;t.push(`${a}: ${o}`)}return t.length?t.join(` · `):void 0},[q,P]),Fe=(0,u.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),D(e=>e<Ee.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),D(e=>e>0?e-1:0)):e.key===`Enter`&&(e.preventDefault(),E>=0&&E<Ee.length&&ve(Ee[E]))},[Ee,E,ve]);if((0,u.useEffect)(()=>{E>=0&&O.current&&O.current.querySelector(`[data-lookup-index="${E}"]`)?.scrollIntoView({block:`nearest`})},[E]),r)return Z.length?N?(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Z.map((e,t)=>(0,g.jsx)(p.Badge,{variant:`outline`,children:e?.label||e?.[P]},t))}):(0,g.jsx)(`span`,{className:`text-sm`,children:Z[0]?.label||Z[0]?.[P]}):(0,g.jsx)(p.EmptyValue,{});let Re=!!i.compact,ze=Z[0]?.label||Z[0]?.[P];return(0,g.jsxs)(`div`,{className:Re?``:`space-y-2`,children:[Z.length>0&&!Re&&(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Z.map((e,t)=>(0,g.jsxs)(p.Badge,{variant:`outline`,className:`gap-1`,children:[e?.label||e?.[P],(0,g.jsx)(`button`,{onClick:()=>ye(e?.value),className:`ml-1 hover:text-destructive`,type:`button`,"aria-label":l(`lookup.remove`,{label:e?.label||e?.[P]}),children:(0,g.jsx)(m.X,{className:`size-3`})})]},t))}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,g.jsxs)(p.Popover,{open:a,onOpenChange:e=>!ae&&o(e),children:[(0,g.jsx)(p.PopoverTrigger,{asChild:!0,children:(0,g.jsxs)(p.Button,{variant:`outline`,className:(0,p.cn)(`min-w-0 flex-1 justify-start text-left font-normal`,Re&&`h-8 rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:ring-1 focus-visible:ring-ring/60`),type:`button`,"aria-haspopup":`listbox`,"aria-expanded":a,"aria-controls":d,disabled:ae||i.disabled,"data-testid":ae?`lookup-trigger-gated`:i.name||k?.name?`lookup-trigger-${i.name||k.name}`:`lookup-trigger`,title:ae?l(`lookup.selectFirst`,{fields:B.map(e=>e.field).join(`, `)}):void 0,children:[(0,g.jsx)(m.Search,{className:(0,p.cn)(`size-4 shrink-0 text-muted-foreground`,Re?`mr-1.5`:`mr-2`)}),(0,g.jsx)(`span`,{className:(0,p.cn)(`truncate`,Re&&Z.length===0&&`text-muted-foreground`),children:ae?l(`lookup.selectFirst`,{fields:B.map(e=>e.field).join(`, `)}):Re&&!N&&Z.length>0?ze:Z.length===0?k?.placeholder||l(`common.select`):N?l(`table.selected`,{count:Z.length}):l(`common.select`)})]})}),(0,g.jsxs)(p.PopoverContent,{className:`w-[var(--radix-popover-trigger-width)] p-0`,align:`start`,children:[(0,g.jsx)(`div`,{className:`p-2`,children:(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(m.Search,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground`}),(0,g.jsx)(p.Input,{placeholder:l(`common.search`)+`...`,value:s,onChange:e=>me(e.target.value),onKeyDown:Fe,className:`w-full pl-9 h-8 text-sm`,role:`combobox`,"aria-autocomplete":`list`,"aria-controls":d,"aria-expanded":a,"aria-activedescendant":E>=0?`${d}-opt-${E}`:void 0}),_&&(0,g.jsx)(m.Loader2,{className:`absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground`,"data-testid":`lookup-loading`})]})}),y&&(0,g.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-4 px-2`,role:`alert`,children:[(0,g.jsx)(m.AlertCircle,{className:`size-5 text-destructive`}),(0,g.jsx)(`p`,{className:`text-sm text-destructive`,children:y}),(0,g.jsx)(p.Button,{variant:`outline`,size:`sm`,onClick:()=>pe(s||void 0),type:`button`,children:l(`lookup.retry`)})]}),_&&de.length===0&&!y&&(0,g.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-6`,role:`status`,"aria-live":`polite`,children:[(0,g.jsx)(m.Loader2,{className:`size-6 animate-spin text-muted-foreground`}),(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l(`lookup.loading`)})]}),!y&&!(_&&de.length===0)&&(0,g.jsx)(`div`,{ref:O,className:`max-h-64 overflow-y-auto px-1 pb-1`,role:`listbox`,id:d,children:Ee.length===0?(0,g.jsxs)(`div`,{className:`py-4 text-center`,children:[(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l(`lookup.noOptions`)}),Ae&&(0,g.jsxs)(p.Button,{variant:`ghost`,size:`sm`,className:`mt-2 gap-1`,type:`button`,disabled:De,onClick:()=>je(s),children:[De?(0,g.jsx)(m.Loader2,{className:`size-4 animate-spin`}):(0,g.jsx)(m.Plus,{className:`size-4`}),s?l(`lookup.createNamed`,{name:s}):l(`lookup.createNew`)]})]}):(0,g.jsxs)(g.Fragment,{children:[Ee.map((t,n)=>{let r=N?(Array.isArray(e)?e:[]).includes(t.value):e===t.value,i=n===E,a=Te>0&&n===0,o=Te>0&&n===Te;return(0,g.jsxs)(u.default.Fragment,{children:[a&&(0,g.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:l(`lookup.recentlyUsed`)}),o&&(0,g.jsx)(`div`,{className:`mt-1 border-t px-3 pt-2 pb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:l(`lookup.allResults`)}),(0,g.jsxs)(`button`,{id:`${d}-opt-${n}`,"data-lookup-index":n,role:`option`,"aria-selected":r,title:Me(t),onClick:()=>ve(t),className:`w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent flex items-center justify-between ${i?`bg-accent text-accent-foreground`:r?`bg-accent/50 text-accent-foreground`:``}`,type:`button`,children:[(0,g.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,g.jsx)(`span`,{className:`block truncate`,children:t.label}),t.description&&(0,g.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:t.description})]}),r&&(0,g.jsx)(p.Badge,{variant:`default`,className:`ml-2 shrink-0`,children:l(`lookup.selectedBadge`)})]})]},t.value)}),W&&x>de.length&&(0,g.jsx)(`p`,{className:`text-xs text-muted-foreground text-center py-2`,children:l(`lookup.showingResults`,{shown:de.length,total:x})}),W&&x>de.length&&(0,g.jsxs)(`button`,{type:`button`,className:`w-full text-center px-3 py-2 rounded-md text-sm font-medium text-primary hover:bg-accent flex items-center justify-center gap-1.5`,onClick:()=>{o(!1),ce(!0)},"data-testid":`show-all-results`,children:[(0,g.jsx)(m.TableProperties,{className:`size-3.5`}),l(`lookup.showAllResults`,{count:x})]}),Ae&&(0,g.jsxs)(`button`,{type:`button`,className:`w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent flex items-center gap-1.5 text-muted-foreground`,disabled:De,onClick:()=>je(s),children:[De?(0,g.jsx)(m.Loader2,{className:`size-3.5 animate-spin`}):(0,g.jsx)(m.Plus,{className:`size-3.5`}),s?l(`lookup.createNamed`,{name:s}):l(`lookup.createNew`)]})]})})]})]}),W&&(0,g.jsx)(p.Button,{variant:`outline`,size:`icon`,className:`shrink-0`,type:`button`,onClick:()=>ce(!0),"aria-label":l(`lookup.browseAll`),title:l(`lookup.browseAll`),"data-testid":`browse-all-records`,children:(0,g.jsx)(m.TableProperties,{className:`size-4`})})]}),W&&U&&L&&(0,g.jsx)(fe,{open:X,onOpenChange:ce,title:k?.label||l(`common.select`),multiple:N,dataSource:U,objectName:L,columns:q,displayField:P,titleFormat:K,idField:I,pageSize:ne,value:e,onSelect:t,onSelectRecords:be,lookupFilters:z,cellRenderer:Oe(),filterColumns:se})]})}var Ie,Le,Re=o((()=>{Z(),be(),Ee(),Ae(),j(),Ie=50,Le=h.SchemaRendererContext})),ze=s({DateTimeField:()=>Be});function Be({value:e,onChange:t,field:n,readonly:r,...i}){if(r){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=new Date(e);return(0,g.jsxs)(`span`,{className:`text-sm`,children:[t.toLocaleDateString(),` `,t.toLocaleTimeString()]})}let{inputType:a,...o}=i;return(0,g.jsx)(p.Input,{...o,type:`datetime-local`,value:e||``,onChange:e=>t(e.target.value),disabled:r||o.disabled})}var Ve=o((()=>{})),He=s({TimeField:()=>Ue});function Ue({value:e,onChange:t,field:n,readonly:r,...i}){if(r)return(0,g.jsx)(`span`,{className:`text-sm`,children:e||(0,g.jsx)(p.EmptyValue,{})});let{inputType:a,...o}=i;return(0,g.jsx)(p.Input,{...o,type:`time`,value:e||``,onChange:e=>t(e.target.value),disabled:r||o.disabled})}var We=o((()=>{})),Ge=s({PercentField:()=>Ke});function Ke({value:e,onChange:t,field:n,readonly:r,errorMessage:i,className:a,...o}){let s=n||o.schema,c=s?.precision??2,l=typeof s?.max==`number`?s.max:void 0,u=l!=null&&l>1,d=e=>u?e:e*100,f=e=>u?e:e/100,m=u?l:100;if(r)return e==null?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsxs)(`span`,{className:`text-sm font-medium tabular-nums`,children:[d(e).toFixed(c),`%`]});let h=e==null?``:d(e),_=e==null?0:d(e),v=e=>{if(e.target.value===``){t(null);return}let n=parseFloat(e.target.value);t(isNaN(n)?null:f(n))},y=e=>{if(r||o.disabled)return;if(!Array.isArray(e)||e.length===0){t(null);return}let n=e[0];t(typeof n==`number`?f(n):null)},b=10**-c;return(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(p.Input,{...o,type:`number`,value:h,onChange:v,placeholder:s?.placeholder||`0`,disabled:r||o.disabled,className:`pr-8 ${a||``}`,step:(10**-c).toFixed(c),"aria-invalid":!!i}),(0,g.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-sm text-gray-500`,children:`%`})]}),(0,g.jsx)(p.Slider,{value:[_],onValueChange:y,min:0,max:m,step:b,disabled:r||o.disabled,className:`w-full`,"aria-label":`Percentage`,"data-testid":`percent-slider`})]})}var qe=o((()=>{})),Je=s({PasswordField:()=>Ye});function Ye({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let[o,s]=(0,u.useState)(!1),c=n||a.schema;if(r)return(0,g.jsx)(`span`,{className:`text-sm`,children:`••••••••`});let{inputType:l,...d}=a;return(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(p.Input,{...d,type:o?`text`:`password`,value:e||``,onChange:e=>t(e.target.value),placeholder:c?.placeholder,disabled:r||d.disabled,className:`pr-10 ${i||``}`}),(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent`,onClick:()=>s(!o),tabIndex:-1,children:o?(0,g.jsx)(m.EyeOff,{className:`size-4 text-gray-500`}):(0,g.jsx)(m.Eye,{className:`size-4 text-gray-500`})})]})}var Xe=o((()=>{})),Ze=s({FileField:()=>Qe});function Qe({value:e,onChange:t,field:n,readonly:r,...i}){let a=(0,u.useRef)(null),o=(0,u.useRef)(null),s=n||i.schema,c=s?.multiple||!1,l=s?.accept?s.accept.join(`,`):void 0,d=s?.maxSize,f=s?.capture??null,h=!l||l.split(`,`).some(e=>e.trim().startsWith(`image/`)||e.trim()===`image/*`||e.trim().startsWith(`.jp`)||e.trim().startsWith(`.png`)||e.trim().startsWith(`.gif`)||e.trim().startsWith(`.webp`)),v=typeof navigator<`u`&&(navigator.maxTouchPoints>0||/Mobi|Android/i.test(navigator.userAgent)),y=f===!1?!1:f??(h&&v?`environment`:null),[b,x]=(0,u.useState)(!1),[S,C]=(0,u.useState)([]),{upload:w}=(0,_.useUpload)(),[T,E]=(0,u.useState)({}),[D,O]=(0,u.useState)(!1),k=e?Array.isArray(e)?e:[e]:[],A=(0,u.useCallback)(async e=>{if(e.length===0)return;let n=[],r=e.filter(e=>{if(d&&e.size>d){let t=(d/(1024*1024)).toFixed(1);return n.push(`"${e.name}" exceeds max size (${t} MB)`),!1}return!0});if(C(n),r.length!==0){O(!0);try{let e=(await Promise.all(r.map(async e=>{try{let t=await w(e,{onProgress:t=>E(n=>({...n,[e.name]:t}))});return{name:t.name,original_name:e.name,size:t.size,mime_type:t.mimeType,url:t.url}}catch(t){return n.push(`Failed to upload "${e.name}": ${t.message}`),C([...n]),null}}))).filter(Boolean);if(e.length===0)return;t(c?[...k,...e]:e[0])}finally{O(!1),E({})}}},[k,c,t,d,w]),ee=(0,u.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),x(!0)},[]),j=(0,u.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),x(!1)},[]),M=(0,u.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),x(!1);let t=Array.from(e.dataTransfer.files);if(l){let e=l.split(`,`).map(e=>e.trim().toLowerCase());A(t.filter(t=>{let n=t.name.split(`.`),r=n.length>1?`.`+n.pop()?.toLowerCase():``;return e.some(e=>e===t.type||r&&e===r||e.endsWith(`/*`)&&t.type.startsWith(e.replace(`/*`,`/`)))}))}else A(t)},[l,A]);if(r)return e?(0,g.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(Array.isArray(e)?e:[e]).map((e,t)=>(0,g.jsx)(`span`,{className:`text-sm truncate max-w-xs`,children:e.name||e.original_name||`File`},t))}):(0,g.jsx)(p.EmptyValue,{});let N=e=>{A(Array.from(e.target.files||[]))},P=e=>{if(c){let n=k.filter((t,n)=>n!==e);t(n.length>0?n:null)}else t(null)},F=e=>(e.mime_type||``).startsWith(`image/`);return(0,g.jsxs)(`div`,{className:i.className,children:[(0,g.jsx)(`input`,{ref:a,type:`file`,multiple:c,accept:l,onChange:N,className:`hidden`}),y&&(0,g.jsx)(`input`,{ref:o,type:`file`,accept:`image/*`,capture:y,onChange:N,className:`hidden`,"aria-label":`Camera capture`,"data-testid":`file-field-camera-input`}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(`div`,{onDragOver:ee,onDragLeave:j,onDrop:M,onClick:()=>a.current?.click(),className:`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(e&&(t=e(e=0)),t),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,a)=>(a=n==null?{}:e(i(n)),c(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let u=require("react");u=l(u,1);let d=require("@object-ui/core"),f=require("@object-ui/i18n"),p=require("@object-ui/components"),m=require("lucide-react"),h=require("@object-ui/react"),g=require("react/jsx-runtime"),_=require("@object-ui/providers"),v=require("react-markdown");v=l(v,1);let y=require("remark-gfm");y=l(y,1);let b=require("rehype-sanitize");b=l(b,1);var x=s({TextField:()=>S});function S({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema;if(r)return(0,g.jsx)(`span`,{className:`text-sm`,children:e||(0,g.jsx)(p.EmptyValue,{})});let o=a?.rows,{inputType:s,...c}=i;return o&&o>1?(0,g.jsx)(p.Textarea,{...c,value:e||``,onChange:e=>t(e.target.value),placeholder:a?.placeholder,disabled:r||c.disabled}):(0,g.jsx)(p.Input,{...c,type:a?.type===`password`?`password`:`text`,value:e||``,onChange:e=>t(e.target.value),placeholder:a?.placeholder,disabled:r||c.disabled})}var C=o((()=>{})),w=s({NumberField:()=>T});function T({value:e,onChange:t,field:n,readonly:r,...i}){if(r)return e==null?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`text-sm`,children:e});let a=n||i.schema,o=a?.precision,{inputType:s,...c}=i;return(0,g.jsx)(p.Input,{...c,type:`number`,value:e??``,onChange:e=>{let n=e.target.value;t(n===``?null:Number(n))},placeholder:a?.placeholder,disabled:r||c.disabled,step:o?10**-o:`any`})}var E=o((()=>{})),D=s({BooleanField:()=>O});function O({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=a?.widget,s=(0,u.useId)(),c=a?.name||s,l=a?.label||`Checkbox`;if(r)return(0,g.jsx)(`span`,{className:`text-sm`,children:e?`Yes`:`No`});let{inputType:d,...f}=i;return o===`checkbox`?(0,g.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,g.jsx)(p.Checkbox,{...f,id:c,checked:!!e,onCheckedChange:e=>t(!!e),disabled:r||f.disabled}),(0,g.jsx)(p.Label,{htmlFor:c,className:`sr-only`,children:l})]}):(0,g.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,g.jsx)(p.Switch,{...f,id:c,checked:!!e,onCheckedChange:t,disabled:r||f.disabled}),(0,g.jsx)(p.Label,{htmlFor:c,className:`sr-only`,children:l})]})}var k=o((()=>{})),A,ee,j=o((()=>{A={"common.selectOption":`Select an option`,"common.select":`Select...`,"common.search":`Search`,"common.loading":`Loading...`,"common.noResults":`No results found`,"common.cancel":`Cancel`,"common.confirm":`Confirm`,"table.selected":`{{count}} selected`,"table.search":`Search...`,"lookup.loading":`Loading…`,"lookup.noOptions":`No options found`,"lookup.noRecords":`No records found`,"lookup.recentlyUsed":`Recently used`,"lookup.allResults":`All results`,"lookup.createNew":`Create new`,"lookup.createNamed":`Create new "{{name}}"`,"lookup.showingResults":`Showing {{shown}} of {{total}} results`,"lookup.showAllResults":`Show all results ({{count}})`,"lookup.selectedBadge":`Selected`,"lookup.browseAll":`Browse all records`,"lookup.remove":`Remove {{label}}`,"lookup.selectFirst":`Select {{fields}} first`,"lookup.selectRecord":`Select record`,"lookup.recordCount":`{{count}} records`,"lookup.recordCountOne":`1 record`,"lookup.pageOf":`Page {{current}} of {{total}}`,"lookup.filters":`Filters`,"lookup.clear":`Clear`,"lookup.yes":`Yes`,"lookup.filterPlaceholder":`Filter {{label}}`,"lookup.prevPage":`Previous page`,"lookup.nextPage":`Next page`,"lookup.jumpToPage":`Jump to page`,"lookup.retry":`Retry`},ee=(0,f.createSafeTranslation)(A,`common.selectOption`)})),te=s({SelectField:()=>M});function M({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=a?.options||[],{t:s}=ee(),c=i.name||a?.name||i.id||``;if(r){let t=o.find(t=>t.value===e)?.label||e;return t?(0,g.jsx)(`span`,{className:`text-sm`,children:t}):(0,g.jsx)(p.EmptyValue,{})}return o.length===0?(0,g.jsx)(`div`,{"data-testid":c?`select-empty-${c}`:void 0,className:`flex h-9 w-full items-center rounded-md border border-input bg-muted/30 px-3 py-2 text-sm text-muted-foreground`,children:`No options available`}):(0,g.jsxs)(p.Select,{...i,value:e,onValueChange:t,disabled:r||i.disabled,children:[(0,g.jsx)(p.SelectTrigger,{className:i.className,id:i.id,"data-testid":c?`select-trigger-${c}`:void 0,children:(0,g.jsx)(p.SelectValue,{placeholder:a?.placeholder||s(`common.selectOption`)})}),(0,g.jsx)(p.SelectContent,{position:`popper`,children:o.map(e=>(0,g.jsx)(p.SelectItem,{value:e.value,"data-testid":`select-option-${e.value}`,children:e.label},e.value))})]})}var N=o((()=>{j()})),P=s({DateField:()=>F});function F({value:e,onChange:t,field:n,readonly:r,...i}){if(r)return e?(0,g.jsx)(`span`,{className:`text-sm`,children:new Date(e).toLocaleDateString()}):(0,g.jsx)(p.EmptyValue,{});let{inputType:a,...o}=i;return(0,g.jsx)(p.Input,{...o,type:`date`,value:e||``,onChange:e=>t(e.target.value),disabled:r||o.disabled})}var I=o((()=>{})),ne=s({EmailField:()=>L});function L({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){let o=n||a.schema;if(r)return e?(0,g.jsx)(`a`,{href:`mailto:${e}`,className:`text-sm text-blue-600 hover:text-blue-800 hover:underline`,children:e}):(0,g.jsx)(p.EmptyValue,{});let{inputType:s,...c}=a;return(0,g.jsx)(p.Input,{...c,type:`email`,value:e||``,onChange:e=>t(e.target.value),placeholder:o?.placeholder||`email@example.com`,disabled:r||c.disabled,"aria-invalid":!!i})}var re=o((()=>{})),R=s({PhoneField:()=>z});function z({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){let o=n||a.schema;if(r)return e?(0,g.jsx)(`a`,{href:`tel:${e}`,className:`text-sm text-blue-600 hover:text-blue-800 hover:underline`,children:e}):(0,g.jsx)(p.EmptyValue,{});let{inputType:s,...c}=a;return(0,g.jsx)(p.Input,{...c,type:`tel`,value:e||``,onChange:e=>t(e.target.value),placeholder:o?.placeholder||`(555) 123-4567`,disabled:r||c.disabled,"aria-invalid":!!i})}var B=o((()=>{})),V=s({UrlField:()=>ie});function ie({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){let o=n||a.schema;if(r)return e?e.startsWith(`http://`)||e.startsWith(`https://`)?(0,g.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-sm text-blue-600 hover:text-blue-800 hover:underline`,children:e}):(0,g.jsx)(`span`,{className:`text-sm`,children:e}):(0,g.jsx)(p.EmptyValue,{});let{inputType:s,...c}=a;return(0,g.jsx)(p.Input,{...c,type:`url`,value:e||``,onChange:e=>t(e.target.value),placeholder:o?.placeholder||`https://example.com`,disabled:r||c.disabled,"aria-invalid":!!i})}var H=o((()=>{})),ae=o((()=>{})),oe=s({CurrencyField:()=>W});function U(e,t,n){if(t)try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,minimumFractionDigits:n,maximumFractionDigits:n}).format(e)}catch{return`${t} ${e.toFixed(n)}`}try{return new Intl.NumberFormat(`en-US`,{minimumFractionDigits:n,maximumFractionDigits:n}).format(e)}catch{return e.toFixed(n)}}function W({value:e,onChange:t,field:n,readonly:r,errorMessage:i,className:a,...o}){let s=n||o.schema,{currency:c}=(0,f.useLocalization)(),l=(0,f.resolveFieldCurrency)(s,c),u=s?.precision??2;if(r)return e==null?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`text-sm font-medium tabular-nums`,children:U(Number(e),l,u)});let d=e=>{let n=parseFloat(e.target.value);isNaN(n)||t(parseFloat(n.toFixed(u)))},m=l?l===`USD`?`$`:l:``;return(0,g.jsxs)(`div`,{className:`relative`,children:[m&&(0,g.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-sm text-gray-500`,children:m}),(0,g.jsx)(p.Input,{...o,type:`number`,value:e??``,onChange:e=>{t(e.target.value===``?null:parseFloat(e.target.value))},onBlur:d,placeholder:s?.placeholder||`0.00`,disabled:r||o.disabled,className:`${m?`pl-8`:``} ${a||``}`,step:(10**-u).toFixed(u),"aria-invalid":!!i})]})}var se=o((()=>{ae()})),G=s({TextAreaField:()=>K});function K({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){if(r)return(0,g.jsx)(`div`,{className:`text-sm whitespace-pre-wrap`,children:e||(0,g.jsx)(p.EmptyValue,{})});let o=n||a.schema,s=o?.rows||4,c=o?.max_length,l=!!(a.mobileFullscreen??o?.mobile_fullscreen??a.mobile_fullscreen??a.schema?.mobile_fullscreen),[d,f]=(0,u.useState)(!1),[h,_]=(0,u.useState)(e??``),v=()=>{_(e??``),f(!0)},y=()=>f(!1),b=()=>{t(h),f(!1)},{inputType:x,mobileFullscreen:S,...C}=a;return(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(p.Textarea,{...C,value:e||``,onChange:e=>t(e.target.value),placeholder:o?.placeholder,disabled:r||C.disabled,rows:s,maxLength:c,"aria-invalid":!!i,className:C.className}),l&&(0,g.jsx)(`button`,{type:`button`,onClick:v,className:`absolute top-1.5 right-1.5 inline-flex items-center justify-center size-7 rounded-md bg-background/80 text-muted-foreground hover:text-foreground hover:bg-background border shadow-sm transition-colors`,"aria-label":`Edit ${o?.label??`text`} fullscreen`,"data-testid":`textarea-fullscreen-toggle`,children:(0,g.jsx)(m.Maximize2,{className:`size-3.5`})}),c&&(0,g.jsxs)(`div`,{className:`absolute bottom-2 right-2 text-xs text-gray-400`,"aria-live":`polite`,"aria-label":`Character count: ${(e||``).length} of ${c}`,children:[(e||``).length,`/`,c]}),l&&(0,g.jsx)(p.Dialog,{open:d,onOpenChange:f,children:(0,g.jsxs)(p.DialogContent,{className:`sm:max-w-3xl h-[100dvh] sm:h-[80vh] max-h-[100dvh] sm:max-h-[80vh] flex flex-col p-0 gap-0`,"data-testid":`textarea-fullscreen-dialog`,children:[(0,g.jsx)(p.DialogHeader,{className:`p-4 border-b`,children:(0,g.jsx)(p.DialogTitle,{className:`text-base`,children:o?.label??`Edit text`})}),(0,g.jsx)(`div`,{className:`flex-1 min-h-0 p-4`,children:(0,g.jsx)(p.Textarea,{autoFocus:!0,value:h,onChange:e=>_(e.target.value),maxLength:c,placeholder:o?.placeholder,className:`h-full min-h-full resize-none text-base`,"data-testid":`textarea-fullscreen-input`})}),(0,g.jsxs)(p.DialogFooter,{className:`p-3 border-t flex-row justify-between sm:justify-end gap-2`,children:[c&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground self-center`,children:[h.length,`/`,c]}),(0,g.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,g.jsxs)(p.Button,{type:`button`,variant:`ghost`,onClick:y,children:[(0,g.jsx)(m.X,{className:`size-4 mr-1`}),` Cancel`]}),(0,g.jsxs)(p.Button,{type:`button`,onClick:b,"data-testid":`textarea-fullscreen-save`,children:[(0,g.jsx)(m.Check,{className:`size-4 mr-1`}),` Done`]})]})]})]})})]})}var q=o((()=>{})),ce=s({RichTextField:()=>J});function J({value:e,onChange:t,field:n,readonly:r,errorMessage:i,...a}){let{t:o}=(0,h.useObjectTranslation)();if(r)return(0,g.jsx)(`div`,{className:`text-sm prose prose-sm max-w-none`,children:e||(0,g.jsx)(p.EmptyValue,{})});let s=n||a.schema,c=s?.rows||8,l=s?.format||`markdown`;return(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-gray-500`,children:[(0,g.jsx)(`span`,{children:o(`fields.richText.format`,{format:l,defaultValue:`Format: ${l}`})}),(0,g.jsx)(`span`,{className:`italic`,children:o(`fields.richText.basicEditorHint`,{defaultValue:`Rich text editor (basic)`})})]}),(0,g.jsx)(p.Textarea,{value:e||``,onChange:e=>t(e.target.value),placeholder:s?.placeholder||o(`fields.richText.placeholder`,{defaultValue:`Enter text...`}),disabled:r||a.disabled,rows:c,className:`font-mono text-sm ${a.className||``}`,"aria-invalid":!!i})]})}var Y=o((()=>{}));function le(e){return typeof e==`string`?{field:e}:e}function ue(e){return e.replace(/_/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function de(e){let t={};for(let n of e)switch(n.operator){case`eq`:t[n.field]=n.value;break;case`ne`:t[n.field]={$ne:n.value};break;case`gt`:t[n.field]={$gt:n.value};break;case`lt`:t[n.field]={$lt:n.value};break;case`gte`:t[n.field]={$gte:n.value};break;case`lte`:t[n.field]={$lte:n.value};break;case`contains`:t[n.field]={$contains:n.value};break;case`in`:t[n.field]={$in:n.value};break;case`notIn`:t[n.field]={$nin:n.value};break}return t}function fe(e,t){let n={};for(let r of t){let t=e[r.field];t==null||t===``||(r.type===`boolean`?n[r.field]=!!t:r.type===`text`?n[r.field]={$contains:t}:n[r.field]=t)}return n}function pe({open:e,onOpenChange:t,title:n=`Select Record`,multiple:r=!1,dataSource:i,objectName:a,columns:o,displayField:s=`name`,titleFormat:c,idField:l=`id`,pageSize:d=me,value:f,onSelect:h,onSelectRecords:_,lookupFilters:v,cellRenderer:y,filterColumns:b,renderFilterBar:x,renderGrid:S}){let{t:C}=ee(),[w,T]=(0,u.useState)([]),[E,D]=(0,u.useState)(!1),[O,k]=(0,u.useState)(null),[A,j]=(0,u.useState)(0),[te,M]=(0,u.useState)(``),[N,P]=(0,u.useState)(1),F=(0,u.useRef)(null),[I,ne]=(0,u.useState)(null),[L,re]=(0,u.useState)(`asc`),[R,z]=(0,u.useState)(new Set),B=(0,u.useRef)(new Map),[V,ie]=(0,u.useState)(-1),H=(0,u.useRef)(null),[ae,oe]=(0,u.useState)(!1),[U,W]=(0,u.useState)({}),[se,G]=(0,u.useState)({}),K=(0,u.useRef)(null),[q,ce]=(0,u.useState)(``),J=(0,u.useMemo)(()=>o&&o.length>0?o.map(le):[{field:s,label:ue(s)}],[o,s]),Y=(0,u.useMemo)(()=>{if(b&&b.length>0)return b;if(v&&v.length>0)return v.map(e=>{let t=`text`;return typeof e.value==`boolean`?t=`boolean`:Array.isArray(e.value)?t=`select`:typeof e.value==`number`||e.operator===`gt`||e.operator===`lt`||e.operator===`gte`||e.operator===`lte`?t=`number`:(e.operator===`in`||e.operator===`notIn`)&&(t=`select`),{field:e.field,label:ue(e.field),type:t,...Array.isArray(e.value)?{options:e.value.map(e=>{if(typeof e==`object`&&e){let t=e;return{label:String(t.name||t.label||t.title||e),value:e}}return{label:String(e),value:e}})}:{}}})},[b,v]),pe=(0,u.useMemo)(()=>{let e=v?.length?de(v):{},t=Y?.length?fe(U,Y):{},n={...e,...t};return Object.keys(n).length>0?n:void 0},[v,Y,U]),X=Math.max(1,Math.ceil(A/d)),_e=(0,u.useCallback)(async(e,t=1,n,r)=>{if(!(!i||!a)){D(!0),k(null);try{let o={$top:d,$skip:(t-1)*d};e&&e.trim()&&(o.$search=e.trim()),n&&(o.$orderby={[n.field]:n.direction});let s=r===void 0?pe:r;s&&Object.keys(s).length>0&&(o.$filter=s);let c=await i.find(a,o),l=c?.data??c??[];T(l),j(c?.total??l.length),ie(-1)}catch(e){k(e instanceof Error?e.message:String(e)),T([])}finally{D(!1)}}},[i,a,d,pe]),ve=(0,u.useMemo)(()=>I?{field:I,direction:L}:null,[I,L]);(0,u.useEffect)(()=>{e||(M(``),P(1),k(null),T([]),ne(null),re(`asc`),ie(-1),oe(!1),W({}),G({}),ce(``),z(new Set(r&&Array.isArray(f)?f:[])),B.current.clear())},[e]),(0,u.useEffect)(()=>{e&&_e(te||void 0,N,ve)},[e,N,ve,pe]),(0,u.useEffect)(()=>{e&&r&&z(new Set(Array.isArray(f)?f:[]))},[e,r,f]);let ye=(0,u.useCallback)(e=>{M(e),P(1),F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{_e(e||void 0,1,ve)},300)},[_e,ve]);(0,u.useEffect)(()=>()=>{F.current&&clearTimeout(F.current)},[]);let be=(0,u.useCallback)(e=>{ne(t=>t===e?(re(e=>e===`asc`?`desc`:`asc`),e):(re(`asc`),e)),P(1)},[]),xe=(0,u.useCallback)(e=>e[l]??e.id??e._id,[l]),Se=(0,u.useCallback)(e=>{let t=xe(e);return r?R.has(t):f===t},[r,f,R,xe]),Ce=(0,u.useCallback)(e=>{let n=xe(e);r?z(t=>{let r=new Set(t);return r.has(n)?(r.delete(n),B.current.delete(n)):(r.add(n),B.current.set(n,e)),r}):(h(n),_?.([e]),t(!1))},[r,xe,h,_,t]),we=(0,u.useCallback)(()=>{let e=Array.from(R);h(e);let n=e.map(e=>B.current.get(e)).filter(Boolean);_?.(n),t(!1)},[R,h,_,t]),Te=(0,u.useCallback)(()=>{P(e=>Math.max(1,e-1))},[]),Ee=(0,u.useCallback)(()=>{P(e=>Math.min(X,e+1))},[X]),De=(0,u.useCallback)(e=>{if(e.key!==`Enter`)return;let t=parseInt(q,10);!isNaN(t)&&t>=1&&t<=X&&P(t),ce(``)},[q,X]),Oe=(0,u.useCallback)(e=>{w.length!==0&&(e.key===`ArrowDown`?(e.preventDefault(),ie(e=>Math.min(e+1,w.length-1))):e.key===`ArrowUp`?(e.preventDefault(),ie(e=>Math.max(e-1,0))):(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),V>=0&&V<w.length&&Ce(w[V])))},[w,V,Ce]);(0,u.useEffect)(()=>{if(V>=0&&H.current){let e=H.current.querySelector(`[data-row-index="${V}"]`);e&&typeof e.scrollIntoView==`function`&&e.scrollIntoView({block:`nearest`})}},[V]);let ke=(0,u.useCallback)((e,t)=>{if(c&&t.field===s){let t=`[-\\u2013\\u2014|/·,:]`,n=!1,r=c.replace(/\{([^{}]+)\}/g,(t,r)=>{let i=e[r.trim()];return i!=null&&i!==``?(n=!0,String(i)):`\0`});if(n){let e=r.replace(RegExp(`\\s*${t}\\s*`,`g`),``).replace(RegExp(`\\s*${t}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim();if(e)return e}}let n=e[t.field];if(t.type&&y){let e=y(t.type);if(e)return(0,g.jsx)(e,{value:n,field:{name:t.field,type:t.type}})}return n==null?``:typeof n==`object`?n.$numberDecimal?String(Number(n.$numberDecimal)):n.$oid?String(n.$oid):n.$date?new Date(n.$date).toLocaleDateString():n.name||n.label?String(n.name||n.label):JSON.stringify(n):typeof n==`boolean`?n?`Yes`:`No`:String(n)},[y,c,s]),Ae=(0,u.useCallback)(e=>I===e?L===`asc`?(0,g.jsx)(m.ArrowUp,{className:`ml-1 size-3`}):(0,g.jsx)(m.ArrowDown,{className:`ml-1 size-3`}):(0,g.jsx)(m.ArrowUpDown,{className:`ml-1 size-3 opacity-40`}),[I,L]),je=(0,u.useCallback)((e,t,n)=>{e.preventDefault(),e.stopPropagation(),K.current={field:t,startX:e.clientX,startWidth:n};let r=e=>{if(!K.current)return;let t=e.clientX-K.current.startX,n=Math.max(he,K.current.startWidth+t);G(e=>({...e,[K.current.field]:n}))},i=()=>{K.current=null,document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[]),Me=(0,u.useCallback)((e,t)=>{W(n=>({...n,[e]:t})),P(1)},[]),Ne=(0,u.useCallback)(()=>{W({}),P(1)},[]),Pe=(0,u.useMemo)(()=>Object.values(U).filter(e=>e!=null&&e!==``).length,[U]),Fe=(0,u.useCallback)(e=>{let t=U[e.field],n=e.label||ue(e.field);switch(e.type){case`select`:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsxs)(p.Select,{value:t==null?``:String(t),onValueChange:t=>Me(e.field,t),children:[(0,g.jsx)(p.SelectTrigger,{className:`h-8 text-xs`,children:(0,g.jsx)(p.SelectValue,{placeholder:C(`lookup.filterPlaceholder`,{label:n})})}),(0,g.jsx)(p.SelectContent,{children:e.options?.map(e=>(0,g.jsx)(p.SelectItem,{value:String(e.value),children:e.label},String(e.value)))})]})]});case`number`:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsx)(p.Input,{type:`number`,className:`h-8 text-xs`,value:t??``,placeholder:C(`lookup.filterPlaceholder`,{label:n}),onChange:t=>{let n=t.target.value;Me(e.field,n===``?``:Number(n))}})]});case`date`:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsx)(p.Input,{type:`date`,className:`h-8 text-xs`,value:t??``,onChange:t=>Me(e.field,t.target.value)})]});case`boolean`:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,g.jsx)(p.Checkbox,{checked:!!t,onCheckedChange:t=>Me(e.field,!!t)}),(0,g.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:C(`lookup.yes`)})]})]});default:return(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Label,{className:`text-xs text-muted-foreground`,children:n}),(0,g.jsx)(p.Input,{className:`h-8 text-xs`,value:t??``,placeholder:C(`lookup.filterPlaceholder`,{label:n}),onChange:t=>Me(e.field,t.target.value)})]})}},[U,Me]),Ie=(0,u.useCallback)((e,t)=>e?`bg-primary/5 hover:bg-primary/10`:t%2==1?`bg-muted/20 hover:bg-accent/30`:`hover:bg-accent/30`,[]);return(0,g.jsx)(p.Dialog,{open:e,onOpenChange:t,children:(0,g.jsxs)(p.DialogContent,{className:`w-[95vw] sm:max-w-3xl lg:max-w-5xl max-h-[85vh] sm:max-h-[80vh] flex flex-col gap-0`,"data-testid":`record-picker-dialog`,children:[(0,g.jsx)(p.DialogHeader,{children:(0,g.jsxs)(p.DialogTitle,{children:[n,r&&(0,g.jsx)(`span`,{className:`sr-only`,children:` (multiple selection)`})]})}),(0,g.jsxs)(`div`,{className:`relative rounded-md border bg-muted/30 mb-3`,children:[(0,g.jsx)(m.Search,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground`}),(0,g.jsx)(p.Input,{placeholder:C(`table.search`),value:te,onChange:e=>ye(e.target.value),className:`pl-9 border-0 bg-transparent shadow-none focus-visible:ring-0`,"data-testid":`record-picker-search`}),E&&(0,g.jsx)(m.Loader2,{className:`absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground`,"data-testid":`record-picker-loading-indicator`})]}),Y&&Y.length>0&&(0,g.jsx)(`div`,{className:`py-2`,children:x?(0,g.jsx)(`div`,{"data-testid":`record-picker-filter-bar`,children:x({filterColumns:Y,values:U,onChange:Me,onClear:Ne,activeCount:Pe})}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`record-picker-filter-bar`,children:[(0,g.jsxs)(p.Button,{type:`button`,variant:Pe>0?`secondary`:`outline`,size:`sm`,className:`gap-1.5 shrink-0`,onClick:()=>oe(e=>!e),children:[(0,g.jsx)(m.SlidersHorizontal,{className:`size-3.5`}),C(`lookup.filters`),Pe>0&&(0,g.jsx)(`span`,{className:`inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary`,children:Pe})]}),Pe>0&&(0,g.jsxs)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`gap-1 text-xs`,onClick:Ne,children:[(0,g.jsx)(m.X,{className:`size-3`}),C(`lookup.clear`)]})]}),ae&&(0,g.jsx)(`div`,{className:`mt-2 grid gap-3 sm:grid-cols-2 lg:grid-cols-3 border rounded-md p-3 bg-muted/30`,"data-testid":`record-picker-filter-panel`,children:Y.map(e=>(0,g.jsx)(`div`,{children:Fe(e)},e.field))})]})}),O&&(0,g.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-4`,role:`alert`,children:[(0,g.jsx)(m.AlertCircle,{className:`size-5 text-destructive`}),(0,g.jsx)(`p`,{className:`text-sm text-destructive`,children:O}),(0,g.jsx)(p.Button,{variant:`outline`,size:`sm`,onClick:()=>_e(te||void 0,N,ve),type:`button`,children:C(`lookup.retry`)})]}),S?(0,g.jsx)(`div`,{className:`flex-1 min-h-0`,"data-testid":`record-picker-grid-slot`,children:S({columns:J,records:w,loading:E,totalCount:A,currentPage:N,pageSize:d,sortField:I,sortDirection:L,onSort:be,onPageChange:P,onRowClick:Ce,isSelected:Se,multiple:r,idField:l,cellRenderer:y})}):(0,g.jsxs)(g.Fragment,{children:[E&&w.length===0&&!O&&(0,g.jsx)(`div`,{className:`flex-1 overflow-hidden min-h-0 border rounded-md`,role:`status`,"aria-live":`polite`,"data-testid":`record-picker-skeleton`,children:(0,g.jsxs)(p.Table,{children:[(0,g.jsx)(p.TableHeader,{children:(0,g.jsxs)(p.TableRow,{className:`bg-muted/40`,children:[r&&(0,g.jsx)(p.TableHead,{className:`w-10`}),J.map(e=>(0,g.jsx)(p.TableHead,{children:(0,g.jsx)(p.Skeleton,{className:`h-4 w-20`})},e.field))]})}),(0,g.jsx)(p.TableBody,{children:Array.from({length:ge},(e,t)=>(0,g.jsxs)(p.TableRow,{children:[r&&(0,g.jsx)(p.TableCell,{className:`w-10`,children:(0,g.jsx)(p.Skeleton,{className:`size-4 rounded`})}),J.map(e=>(0,g.jsx)(p.TableCell,{children:(0,g.jsx)(p.Skeleton,{className:`h-4 w-full`})},e.field))]},t))})]})}),!E&&!O&&w.length===0&&(0,g.jsx)(`div`,{className:`py-8 text-center`,children:(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:C(`lookup.noRecords`)})}),!O&&w.length>0&&(0,g.jsxs)(`div`,{className:`relative flex-1 overflow-auto min-h-0 border rounded-md`,"aria-busy":E||void 0,"data-state":E?`loading`:`idle`,tabIndex:0,onKeyDown:Oe,role:`grid`,"aria-label":`Records`,children:[E&&(0,g.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/60`,"data-testid":`record-picker-loading-overlay`,children:(0,g.jsx)(m.Loader2,{className:`size-6 animate-spin text-muted-foreground`})}),(0,g.jsxs)(p.Table,{style:Object.keys(se).length>0?{tableLayout:`fixed`}:void 0,children:[(0,g.jsx)(p.TableHeader,{className:`sticky top-0 z-[5] bg-muted/50 [&_tr]:border-b`,"data-testid":`record-picker-sticky-header`,children:(0,g.jsxs)(p.TableRow,{children:[r&&(0,g.jsx)(p.TableHead,{className:`w-10`}),J.map(e=>{let t=se[e.field];return(0,g.jsxs)(p.TableHead,{style:t?{width:`${t}px`,minWidth:`${t}px`}:e.width?{width:e.width}:void 0,className:`cursor-pointer select-none relative group text-xs font-semibold uppercase tracking-wider`,onClick:()=>be(e.field),"aria-sort":I===e.field?L===`asc`?`ascending`:`descending`:`none`,children:[(0,g.jsxs)(`span`,{className:`inline-flex items-center`,children:[e.label||ue(e.field),Ae(e.field)]}),(0,g.jsx)(`span`,{role:`separator`,"aria-orientation":`vertical`,className:`absolute right-0 top-0 bottom-0 w-1 cursor-col-resize opacity-0 group-hover:opacity-100 bg-border hover:bg-primary/50 transition-opacity`,onMouseDown:t=>{let n=t.currentTarget.parentElement?.getBoundingClientRect();je(t,e.field,n?.width??100)},onClick:e=>e.stopPropagation(),"data-testid":`resize-handle-${e.field}`})]},e.field)})]})}),(0,g.jsx)(p.TableBody,{ref:H,children:w.map((e,t)=>{let n=xe(e),i=Se(e),a=t===V;return(0,g.jsxs)(p.TableRow,{"data-row-index":t,className:(0,p.cn)(`cursor-pointer transition-colors`,Ie(i,t),a&&`ring-2 ring-primary ring-inset`),onClick:()=>Ce(e),"data-testid":`record-row-${n}`,"aria-selected":i,children:[r&&(0,g.jsx)(p.TableCell,{className:`w-10`,children:i&&(0,g.jsx)(m.Check,{className:`size-4 text-primary`})}),J.map(t=>(0,g.jsx)(p.TableCell,{className:`py-2.5`,children:ke(e,t)},t.field))]},n??t)})})]})]}),!O&&A>0&&(0,g.jsxs)(`div`,{className:`flex items-center justify-between text-sm text-muted-foreground border-t pt-3 mt-2 px-1`,"data-testid":`record-picker-pagination`,children:[(0,g.jsxs)(`span`,{children:[A===1?C(`lookup.recordCountOne`):C(`lookup.recordCount`,{count:A}),X>1&&` · ${C(`lookup.pageOf`,{current:N,total:X})}`]}),X>1&&(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,g.jsx)(p.Button,{variant:`outline`,size:`icon`,className:`size-7`,onClick:Te,disabled:N<=1,type:`button`,"aria-label":C(`lookup.prevPage`),children:(0,g.jsx)(m.ChevronLeft,{className:`size-4`})}),(0,g.jsx)(p.Input,{className:`h-7 w-12 text-center text-xs px-1`,placeholder:String(N),value:q,onChange:e=>ce(e.target.value),onKeyDown:De,"aria-label":C(`lookup.jumpToPage`),"data-testid":`record-picker-page-jump`}),(0,g.jsx)(p.Button,{variant:`outline`,size:`icon`,className:`size-7`,onClick:Ee,disabled:N>=X,type:`button`,"aria-label":C(`lookup.nextPage`),children:(0,g.jsx)(m.ChevronRight,{className:`size-4`})})]})]})]}),r&&(0,g.jsx)(p.DialogFooter,{children:(0,g.jsxs)(`div`,{className:`flex items-center gap-2 w-full justify-between`,children:[(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:C(`table.selected`,{count:R.size})}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsx)(p.Button,{variant:`outline`,type:`button`,onClick:()=>t(!1),children:C(`common.cancel`)}),(0,g.jsx)(p.Button,{type:`button`,onClick:we,children:C(`common.confirm`)})]})]})})]})})}var me,he,ge,X=o((()=>{j(),me=10,he=60,ge=5}));function _e(e){let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n}function ve(e,{displayField:t,max:n=4}){let r=e?.fields??{},i=e=>r[e]??{},a=e=>{let t=i(e);return{field:e,...t.label?{label:t.label}:{},...t.type?{type:t.type}:{}}};if(Object.keys(r).length===0)return[];let o=e?.displayFields;return Array.isArray(o)&&o.length>0?_e([t,...o.filter(e=>typeof e==`string`&&e.length>0).filter(e=>e!==t)]).slice(0,n).map(a):_e([t,...Object.keys(r).filter(e=>{if(e===t||ye.has(e))return!1;let n=i(e);return!(n.hidden||n.type&&be.has(n.type))})]).slice(0,n).map(a)}var ye,be,xe=o((()=>{ye=new Set([`id`,`_id`,`created`,`modified`,`created_at`,`updated_at`,`created_by`,`updated_by`,`modified_by`,`owner_id`,`organization_id`,`space`,`company_id`,`instance_state`,`locked`,`is_deleted`,`deleted`]),be=new Set([`json`,`object`,`grid`,`html`,`richtext`,`markdown`,`code`,`image`,`file`,`avatar`,`vector`,`location`,`geometry`,`textarea`,`secret`,`password`,`encrypted`])}));function Se(){try{return typeof localStorage<`u`?localStorage:null}catch{return null}}function Ce(e){let t=Se();if(!e||!t)return[];try{let n=t.getItem(Te+e);if(!n)return[];let r=JSON.parse(n);return Array.isArray(r)?r.slice(0,Ee):[]}catch{return[]}}function we(e,t){let n=Se();if(!(!e||t==null||t===``||!n))try{let r=[t,...Ce(e).filter(e=>e!==t)].slice(0,Ee);n.setItem(Te+e,JSON.stringify(r))}catch{}}var Te,Ee,De=o((()=>{Te=`objectui:lookup:recent:`,Ee=5}));function Oe(e){Ae=e}function ke(){return Ae}var Ae,je=o((()=>{})),Me=s({LookupField:()=>Ie});function Ne(e,t){if(!e||typeof e!=`object`||!t)return null;let n=`[-\\u2013\\u2014|/·,:]`,r=!1,i=t.replace(/\{([^{}]+)\}/g,(t,n)=>{let i=e[n.trim()];return i!=null&&i!==``?(r=!0,String(i)):`\0`});return r&&i.replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim()||null}function Pe(e,t,n,r,i){let a=e[n]??e.id??e._id,o=(i?Ne(e,i):null)??e[t]??e.label??e.name??e.full_name??e.title??e.subject??String(a),s=r?e[r]:void 0;return{value:a,label:String(o),description:s,...e}}function Fe(e){return{text:`text`,number:`number`,currency:`number`,percent:`number`,select:`select`,status:`select`,date:`date`,datetime:`date`,boolean:`boolean`}[e]}function Ie({value:e,onChange:t,field:n,readonly:r,...i}){let[a,o]=(0,u.useState)(!1),[s,c]=(0,u.useState)(``),{t:l}=ee(),d=u.default.useId(),[f,h]=(0,u.useState)([]),[_,v]=(0,u.useState)(!1),[y,b]=(0,u.useState)(null),[x,S]=(0,u.useState)(0),C=(0,u.useRef)(null),[w,T]=(0,u.useState)([]),[E,D]=(0,u.useState)(-1),O=(0,u.useRef)(null),k=n||i.schema,A=k?.field,j=A&&typeof A==`object`&&(`reference_to`in A||`reference`in A||`type`in A)?A:k,te=j?.options||[],M=j?.multiple||!1,N=j?.display_field||j?.displayField||j?.reference_field||`name`,P=j?.description_field??j?.descriptionField,F=j?.id_field||`id`,I=j?.reference_to||j?.reference,ne=!!(j?.allow_create??j?.allowCreate),L=j?.lookup_columns??j?.lookupColumns,re=j?.lookup_page_size??j?.lookupPageSize,R=j?.lookup_filters??j?.lookupFilters,z=(0,u.useMemo)(()=>{let e=j?.depends_on??j?.dependsOn;return e&&Array.isArray(e)?e.map(e=>typeof e==`string`?{field:e,param:e}:{field:e.field,param:e.param??e.field}):[]},[j?.depends_on,j?.dependsOn]),B=i.dependentValues,V=(0,u.useContext)(Re),ie=V?.dataSource??null,H=i.dataSource??k?.dataSource??j?.dataSource??ie,ae=(0,u.useMemo)(()=>B||(V?.formValues??V?.data??{}),[B,V?.formValues,V?.data]),oe=(0,u.useMemo)(()=>z.length===0?!1:z.some(({field:e})=>{let t=ae[e];return t==null||t===``||Array.isArray(t)&&t.length===0}),[z,ae]),U=H!=null&&typeof H.find==`function`&&!!I,[W,se]=(0,u.useState)(null);(0,u.useEffect)(()=>{if(!H||!I)return;let e=H.getObjectSchema;if(typeof e!=`function`)return;let t=!0;return Promise.resolve(e.call(H,I)).then(e=>{t&&se(e)}).catch(()=>{}),()=>{t=!1}},[H,I]);let G=(0,u.useMemo)(()=>{let e=W?.titleFormat;return typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:null},[W]),K=(0,u.useMemo)(()=>{if(L&&L.length>0)return L;let e=ve(W,{displayField:N});return e.length>0?e:void 0},[L,W,N]),q=(0,u.useMemo)(()=>{if(P)return P;let e=K?.find(e=>(typeof e==`string`?e:e.field)!==N);if(e)return typeof e==`string`?e:e.field},[P,K,N]),ce=(0,u.useMemo)(()=>{if(!K)return;let e=[];for(let t of K)if(typeof t==`object`&&t.type){let n=Fe(t.type);n&&e.push({field:t.field,label:t.label,type:n})}return e.length>0?e:void 0},[K]),J=i.onCreateNew??k?.onCreateNew,[Y,le]=(0,u.useState)(!1),ue=U?f:te,fe=(0,u.useMemo)(()=>{if(U||!s)return ue;let e=s.toLowerCase();return ue.filter(t=>t.label.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[U,ue,s]);(0,u.useEffect)(()=>{D(-1)},[fe.length]);let me=(0,u.useCallback)(async e=>{if(!(!H||!I)){if(oe){h([]),S(0);return}v(!0),b(null);try{let t={$top:Le};if(e&&e.trim()&&(t.$search=e.trim()),z.length>0){let e={};for(let{field:t,param:n}of z){let r=ae[t];r==null||r===``||(e[n]=typeof r==`number`?r:String(r))}Object.keys(e).length>0&&(t.$filter=e)}R&&R.length>0&&(t.$filter={...t.$filter??{},...de(R)});let n=await H.find(I,t),r=n?.data??n??[];h(r.map(e=>Pe(e,N,F,q,G))),S(n?.total??r.length)}catch(e){b(e instanceof Error?e.message:String(e)),h([])}finally{v(!1)}}},[H,I,N,F,q,G,oe,z,ae,R]);(0,u.useEffect)(()=>{a&&U&&z.length>0&&me(s||void 0)},[(0,u.useMemo)(()=>z.map(e=>`${e.param}=${ae[e.field]??``}`).join(`|`),[z,ae])]),(0,u.useEffect)(()=>{a&&U&&me(s||void 0),a||(c(``),b(null),D(-1))},[a]);let he=(0,u.useCallback)(e=>{c(e),U&&(C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{me(e||void 0)},300))},[U,me]);(0,u.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]),(0,u.useEffect)(()=>{if(!U||!H||!I)return;let t=M?Array.isArray(e)?e:[]:e!=null&&e!==``?[e]:[];if(!t.length)return;let n=t.filter(e=>!ge(e));if(!n.length)return;let r=!1;return(async()=>{try{let e=[];for(let t of n)if(typeof H.findOne==`function`){let n=await H.findOne(I,t);n&&e.push(Pe(n,N,F,q,G))}else{let n=await H.find(I,{$filter:{[F]:t},$top:1}),r=n?.data??n??[];r[0]&&e.push(Pe(r[0],N,F,q,G))}!r&&e.length&&T(t=>{let n=new Map(t.map(e=>[e.value,e]));for(let t of e)n.set(t.value,t);return Array.from(n.values())})}catch{}})(),()=>{r=!0}},[e,U,I,N,F,q,M]);let ge=(0,u.useCallback)(e=>te.find(t=>t.value===e)??f.find(t=>t.value===e)??w.find(t=>t.value===e),[te,f,w]),X=M?(Array.isArray(e)?e:[]).map(ge).filter(Boolean):e?[ge(e)].filter(Boolean):[],_e=i.onSelectRecord,ye=(0,u.useCallback)(n=>{if(M){let r=Array.isArray(e)?e:[];r.includes(n.value)?t(r.filter(e=>e!==n.value)):(I&&we(I,n.value),t([...r,n.value]))}else I&&we(I,n.value),_e?_e(n):t(n.value),o(!1)},[M,e,t,_e,I]),be=n=>{t(M?(Array.isArray(e)?e:[]).filter(e=>e!==n):null)},xe=(0,u.useCallback)(e=>{let t=e.map(e=>Pe(e,N,F,q,G));I&&t.forEach(e=>we(I,e.value)),T(t)},[N,F,q,G,I]),[Se,Te]=(0,u.useState)([]);(0,u.useEffect)(()=>{if(!a||!U||!H||!I||s)return;let e=Ce(I);if(!e.length){Te([]);return}let t=!1;return(async()=>{try{let n=[];for(let t of e){let e=ge(t);if(e){n.push(e);continue}if(typeof H.findOne==`function`){let e=await H.findOne(I,t);e&&n.push(Pe(e,N,F,q,G))}}t||Te(n)}catch{t||Te([])}})(),()=>{t=!0}},[a,U,I,s]);let Ee=!s&&U?Se.length:0,De=(0,u.useMemo)(()=>{if(s||!U||Se.length===0)return fe;let e=new Set(Se.map(e=>e.value));return[...Se,...fe.filter(t=>!e.has(t.value))]},[s,U,Se,fe]);(0,u.useEffect)(()=>{D(-1)},[De.length]);let[Oe,Ae]=(0,u.useState)(!1),je=!!J||ne&&U,Me=(0,u.useCallback)(async e=>{let t=(e||``).trim();if(J){J(t),o(!1);return}if(!(!ne||!H||!I||!t)){Ae(!0),b(null);try{let e=Pe(await H.create(I,{[N]:t}),N,F,q,G);T(t=>[e,...t.filter(t=>t.value!==e.value)]),ye(e)}catch(e){b(e instanceof Error?e.message:String(e))}finally{Ae(!1)}}},[J,ne,H,I,N,F,q,G,ye]),Ne=(0,u.useCallback)(e=>{if(!K||K.length===0)return;let t=[];for(let n of K){let r=typeof n==`string`?n:n.field;if(r===N)continue;let i=e[r];if(i==null||i===``)continue;let a=typeof n==`string`?r:n.label||r,o=typeof i==`object`?i.name??i.label??JSON.stringify(i):i;t.push(`${a}: ${o}`)}return t.length?t.join(` · `):void 0},[K,N]),Ie=(0,u.useCallback)(e=>{e.key===`ArrowDown`?(e.preventDefault(),D(e=>e<De.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),D(e=>e>0?e-1:0)):e.key===`Enter`&&(e.preventDefault(),E>=0&&E<De.length&&ye(De[E]))},[De,E,ye]);if((0,u.useEffect)(()=>{E>=0&&O.current&&O.current.querySelector(`[data-lookup-index="${E}"]`)?.scrollIntoView({block:`nearest`})},[E]),r)return X.length?M?(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:X.map((e,t)=>(0,g.jsx)(p.Badge,{variant:`outline`,children:e?.label||e?.[N]},t))}):(0,g.jsx)(`span`,{className:`text-sm`,children:X[0]?.label||X[0]?.[N]}):(0,g.jsx)(p.EmptyValue,{});let Z=!!i.compact,ze=X[0]?.label||X[0]?.[N];return(0,g.jsxs)(`div`,{className:Z?``:`space-y-2`,children:[X.length>0&&!Z&&(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:X.map((e,t)=>(0,g.jsxs)(p.Badge,{variant:`outline`,className:`gap-1`,children:[e?.label||e?.[N],(0,g.jsx)(`button`,{onClick:()=>be(e?.value),className:`ml-1 hover:text-destructive`,type:`button`,"aria-label":l(`lookup.remove`,{label:e?.label||e?.[N]}),children:(0,g.jsx)(m.X,{className:`size-3`})})]},t))}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,g.jsxs)(p.Popover,{open:a,onOpenChange:e=>!oe&&o(e),children:[(0,g.jsx)(p.PopoverTrigger,{asChild:!0,children:(0,g.jsxs)(p.Button,{variant:`outline`,className:(0,p.cn)(`min-w-0 flex-1 justify-start text-left font-normal`,Z&&`h-8 rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:ring-1 focus-visible:ring-ring/60`),type:`button`,"aria-haspopup":`listbox`,"aria-expanded":a,"aria-controls":d,disabled:oe||i.disabled,"data-testid":oe?`lookup-trigger-gated`:i.name||k?.name?`lookup-trigger-${i.name||k.name}`:`lookup-trigger`,title:oe?l(`lookup.selectFirst`,{fields:z.map(e=>e.field).join(`, `)}):void 0,children:[(0,g.jsx)(m.Search,{className:(0,p.cn)(`size-4 shrink-0 text-muted-foreground`,Z?`mr-1.5`:`mr-2`)}),(0,g.jsx)(`span`,{className:(0,p.cn)(`truncate`,Z&&X.length===0&&`text-muted-foreground`),children:oe?l(`lookup.selectFirst`,{fields:z.map(e=>e.field).join(`, `)}):Z&&!M&&X.length>0?ze:X.length===0?k?.placeholder||l(`common.select`):M?l(`table.selected`,{count:X.length}):l(`common.select`)})]})}),(0,g.jsxs)(p.PopoverContent,{className:`w-[var(--radix-popover-trigger-width)] p-0`,align:`start`,children:[(0,g.jsx)(`div`,{className:`p-2`,children:(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(m.Search,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground`}),(0,g.jsx)(p.Input,{placeholder:l(`common.search`)+`...`,value:s,onChange:e=>he(e.target.value),onKeyDown:Ie,className:`w-full pl-9 h-8 text-sm`,role:`combobox`,"aria-autocomplete":`list`,"aria-controls":d,"aria-expanded":a,"aria-activedescendant":E>=0?`${d}-opt-${E}`:void 0}),_&&(0,g.jsx)(m.Loader2,{className:`absolute right-3 top-1/2 -translate-y-1/2 size-4 animate-spin text-muted-foreground`,"data-testid":`lookup-loading`})]})}),y&&(0,g.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-4 px-2`,role:`alert`,children:[(0,g.jsx)(m.AlertCircle,{className:`size-5 text-destructive`}),(0,g.jsx)(`p`,{className:`text-sm text-destructive`,children:y}),(0,g.jsx)(p.Button,{variant:`outline`,size:`sm`,onClick:()=>me(s||void 0),type:`button`,children:l(`lookup.retry`)})]}),_&&fe.length===0&&!y&&(0,g.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-6`,role:`status`,"aria-live":`polite`,children:[(0,g.jsx)(m.Loader2,{className:`size-6 animate-spin text-muted-foreground`}),(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l(`lookup.loading`)})]}),!y&&!(_&&fe.length===0)&&(0,g.jsx)(`div`,{ref:O,className:`max-h-64 overflow-y-auto px-1 pb-1`,role:`listbox`,id:d,children:De.length===0?(0,g.jsxs)(`div`,{className:`py-4 text-center`,children:[(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l(`lookup.noOptions`)}),je&&(0,g.jsxs)(p.Button,{variant:`ghost`,size:`sm`,className:`mt-2 gap-1`,type:`button`,disabled:Oe,onClick:()=>Me(s),children:[Oe?(0,g.jsx)(m.Loader2,{className:`size-4 animate-spin`}):(0,g.jsx)(m.Plus,{className:`size-4`}),s?l(`lookup.createNamed`,{name:s}):l(`lookup.createNew`)]})]}):(0,g.jsxs)(g.Fragment,{children:[De.map((t,n)=>{let r=M?(Array.isArray(e)?e:[]).includes(t.value):e===t.value,i=n===E,a=Ee>0&&n===0,o=Ee>0&&n===Ee;return(0,g.jsxs)(u.default.Fragment,{children:[a&&(0,g.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:l(`lookup.recentlyUsed`)}),o&&(0,g.jsx)(`div`,{className:`mt-1 border-t px-3 pt-2 pb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:l(`lookup.allResults`)}),(0,g.jsxs)(`button`,{id:`${d}-opt-${n}`,"data-lookup-index":n,role:`option`,"aria-selected":r,title:Ne(t),onClick:()=>ye(t),className:`w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent flex items-center justify-between ${i?`bg-accent text-accent-foreground`:r?`bg-accent/50 text-accent-foreground`:``}`,type:`button`,children:[(0,g.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,g.jsx)(`span`,{className:`block truncate`,children:t.label}),t.description&&(0,g.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:t.description})]}),r&&(0,g.jsx)(p.Badge,{variant:`default`,className:`ml-2 shrink-0`,children:l(`lookup.selectedBadge`)})]})]},t.value)}),U&&x>fe.length&&(0,g.jsx)(`p`,{className:`text-xs text-muted-foreground text-center py-2`,children:l(`lookup.showingResults`,{shown:fe.length,total:x})}),U&&x>fe.length&&(0,g.jsxs)(`button`,{type:`button`,className:`w-full text-center px-3 py-2 rounded-md text-sm font-medium text-primary hover:bg-accent flex items-center justify-center gap-1.5`,onClick:()=>{o(!1),le(!0)},"data-testid":`show-all-results`,children:[(0,g.jsx)(m.TableProperties,{className:`size-3.5`}),l(`lookup.showAllResults`,{count:x})]}),je&&(0,g.jsxs)(`button`,{type:`button`,className:`w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent flex items-center gap-1.5 text-muted-foreground`,disabled:Oe,onClick:()=>Me(s),children:[Oe?(0,g.jsx)(m.Loader2,{className:`size-3.5 animate-spin`}):(0,g.jsx)(m.Plus,{className:`size-3.5`}),s?l(`lookup.createNamed`,{name:s}):l(`lookup.createNew`)]})]})})]})]}),U&&(0,g.jsx)(p.Button,{variant:`outline`,size:`icon`,className:`shrink-0`,type:`button`,onClick:()=>le(!0),"aria-label":l(`lookup.browseAll`),title:l(`lookup.browseAll`),"data-testid":`browse-all-records`,children:(0,g.jsx)(m.TableProperties,{className:`size-4`})})]}),U&&H&&I&&(0,g.jsx)(pe,{open:Y,onOpenChange:le,title:k?.label||l(`common.select`),multiple:M,dataSource:H,objectName:I,columns:K,displayField:N,titleFormat:G,idField:F,pageSize:re,value:e,onSelect:t,onSelectRecords:xe,lookupFilters:R,cellRenderer:ke(),filterColumns:ce})]})}var Le,Re,Z=o((()=>{X(),xe(),De(),je(),j(),Le=50,Re=h.SchemaRendererContext})),ze=s({DateTimeField:()=>Be});function Be({value:e,onChange:t,field:n,readonly:r,...i}){if(r){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=new Date(e);return(0,g.jsxs)(`span`,{className:`text-sm`,children:[t.toLocaleDateString(),` `,t.toLocaleTimeString()]})}let{inputType:a,...o}=i;return(0,g.jsx)(p.Input,{...o,type:`datetime-local`,value:e||``,onChange:e=>t(e.target.value),disabled:r||o.disabled})}var Ve=o((()=>{})),He=s({TimeField:()=>Ue});function Ue({value:e,onChange:t,field:n,readonly:r,...i}){if(r)return(0,g.jsx)(`span`,{className:`text-sm`,children:e||(0,g.jsx)(p.EmptyValue,{})});let{inputType:a,...o}=i;return(0,g.jsx)(p.Input,{...o,type:`time`,value:e||``,onChange:e=>t(e.target.value),disabled:r||o.disabled})}var We=o((()=>{})),Ge=s({PercentField:()=>Ke});function Ke({value:e,onChange:t,field:n,readonly:r,errorMessage:i,className:a,...o}){let s=n||o.schema,c=s?.precision??2,l=typeof s?.max==`number`?s.max:void 0,u=l!=null&&l>1,d=e=>u?e:e*100,f=e=>u?e:e/100,m=u?l:100;if(r)return e==null?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsxs)(`span`,{className:`text-sm font-medium tabular-nums`,children:[d(e).toFixed(c),`%`]});let h=e==null?``:d(e),_=e==null?0:d(e),v=e=>{if(e.target.value===``){t(null);return}let n=parseFloat(e.target.value);t(isNaN(n)?null:f(n))},y=e=>{if(r||o.disabled)return;if(!Array.isArray(e)||e.length===0){t(null);return}let n=e[0];t(typeof n==`number`?f(n):null)},b=10**-c;return(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(p.Input,{...o,type:`number`,value:h,onChange:v,placeholder:s?.placeholder||`0`,disabled:r||o.disabled,className:`pr-8 ${a||``}`,step:(10**-c).toFixed(c),"aria-invalid":!!i}),(0,g.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-sm text-gray-500`,children:`%`})]}),(0,g.jsx)(p.Slider,{value:[_],onValueChange:y,min:0,max:m,step:b,disabled:r||o.disabled,className:`w-full`,"aria-label":`Percentage`,"data-testid":`percent-slider`})]})}var qe=o((()=>{})),Je=s({PasswordField:()=>Ye});function Ye({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let[o,s]=(0,u.useState)(!1),c=n||a.schema;if(r)return(0,g.jsx)(`span`,{className:`text-sm`,children:`••••••••`});let{inputType:l,...d}=a;return(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(p.Input,{...d,type:o?`text`:`password`,value:e||``,onChange:e=>t(e.target.value),placeholder:c?.placeholder,disabled:r||d.disabled,className:`pr-10 ${i||``}`}),(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent`,onClick:()=>s(!o),tabIndex:-1,children:o?(0,g.jsx)(m.EyeOff,{className:`size-4 text-gray-500`}):(0,g.jsx)(m.Eye,{className:`size-4 text-gray-500`})})]})}var Xe=o((()=>{})),Ze=s({FileField:()=>Qe});function Qe({value:e,onChange:t,field:n,readonly:r,...i}){let a=(0,u.useRef)(null),o=(0,u.useRef)(null),s=n||i.schema,c=s?.multiple||!1,l=s?.accept?s.accept.join(`,`):void 0,d=s?.maxSize,f=s?.capture??null,h=!l||l.split(`,`).some(e=>e.trim().startsWith(`image/`)||e.trim()===`image/*`||e.trim().startsWith(`.jp`)||e.trim().startsWith(`.png`)||e.trim().startsWith(`.gif`)||e.trim().startsWith(`.webp`)),v=typeof navigator<`u`&&(navigator.maxTouchPoints>0||/Mobi|Android/i.test(navigator.userAgent)),y=f===!1?!1:f??(h&&v?`environment`:null),[b,x]=(0,u.useState)(!1),[S,C]=(0,u.useState)([]),{upload:w}=(0,_.useUpload)(),[T,E]=(0,u.useState)({}),[D,O]=(0,u.useState)(!1),k=e?Array.isArray(e)?e:[e]:[],A=(0,u.useCallback)(async e=>{if(e.length===0)return;let n=[],r=e.filter(e=>{if(d&&e.size>d){let t=(d/(1024*1024)).toFixed(1);return n.push(`"${e.name}" exceeds max size (${t} MB)`),!1}return!0});if(C(n),r.length!==0){O(!0);try{let e=(await Promise.all(r.map(async e=>{try{let t=await w(e,{onProgress:t=>E(n=>({...n,[e.name]:t}))});return{name:t.name,original_name:e.name,size:t.size,mime_type:t.mimeType,url:t.url}}catch(t){return n.push(`Failed to upload "${e.name}": ${t.message}`),C([...n]),null}}))).filter(Boolean);if(e.length===0)return;t(c?[...k,...e]:e[0])}finally{O(!1),E({})}}},[k,c,t,d,w]),ee=(0,u.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),x(!0)},[]),j=(0,u.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),x(!1)},[]),te=(0,u.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),x(!1);let t=Array.from(e.dataTransfer.files);if(l){let e=l.split(`,`).map(e=>e.trim().toLowerCase());A(t.filter(t=>{let n=t.name.split(`.`),r=n.length>1?`.`+n.pop()?.toLowerCase():``;return e.some(e=>e===t.type||r&&e===r||e.endsWith(`/*`)&&t.type.startsWith(e.replace(`/*`,`/`)))}))}else A(t)},[l,A]);if(r)return e?(0,g.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(Array.isArray(e)?e:[e]).map((e,t)=>(0,g.jsx)(`span`,{className:`text-sm truncate max-w-xs`,children:e.name||e.original_name||`File`},t))}):(0,g.jsx)(p.EmptyValue,{});let M=e=>{A(Array.from(e.target.files||[]))},N=e=>{if(c){let n=k.filter((t,n)=>n!==e);t(n.length>0?n:null)}else t(null)},P=e=>(e.mime_type||``).startsWith(`image/`);return(0,g.jsxs)(`div`,{className:i.className,children:[(0,g.jsx)(`input`,{ref:a,type:`file`,multiple:c,accept:l,onChange:M,className:`hidden`}),y&&(0,g.jsx)(`input`,{ref:o,type:`file`,accept:`image/*`,capture:y,onChange:M,className:`hidden`,"aria-label":`Camera capture`,"data-testid":`file-field-camera-input`}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(`div`,{onDragOver:ee,onDragLeave:j,onDrop:te,onClick:()=>a.current?.click(),className:`
|
|
2
2
|
flex flex-col items-center justify-center gap-2 p-6
|
|
3
3
|
border-2 border-dashed rounded-lg cursor-pointer
|
|
4
4
|
transition-colors duration-200
|
|
5
5
|
${b?`border-primary bg-primary/5 text-primary`:`border-muted-foreground/25 hover:border-primary/50 text-muted-foreground hover:text-foreground`}
|
|
6
|
-
`,role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a.current?.click())},children:[(0,g.jsx)(m.Upload,{className:`size-8 ${b?`text-primary`:`text-muted-foreground`}`}),(0,g.jsxs)(`div`,{className:`text-center`,children:[(0,g.jsx)(`p`,{className:`text-sm font-medium`,children:b?`Drop files here`:`Drag & drop files here`}),(0,g.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:[`or click to browse`,y?` • use the camera button below`:``]})]})]}),y&&(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,className:`w-full`,onClick:e=>{e.stopPropagation(),o.current?.click()},"data-testid":`file-field-camera-button`,children:[(0,g.jsx)(m.Camera,{className:`size-4 mr-2`}),y===`user`?`Take selfie`:`Take photo`]}),D&&(0,g.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,"data-testid":`file-field-uploading`,children:[(0,g.jsx)(m.Loader2,{className:`size-3 animate-spin`}),(0,g.jsxs)(`span`,{children:[`Uploading…`,Object.keys(T).length>0&&` (${Math.round(Object.values(T).reduce((e,t)=>e+t,0)/Object.keys(T).length*100)}%)`]})]}),S.length>0&&(0,g.jsx)(`div`,{className:`space-y-0.5`,children:S.map((e,t)=>(0,g.jsx)(`p`,{className:`text-xs text-destructive`,children:e},t))}),k.length>0&&(0,g.jsx)(`div`,{className:`space-y-1`,children:k.map((e,t)=>(0,g.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-2 bg-muted/50 rounded-md border`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0`,children:[F(e)&&e.url?(0,g.jsx)(`img`,{src:e.url,alt:e.name,className:`size-8 object-cover rounded shrink-0`}):F(e)?(0,g.jsx)(m.ImageIcon,{className:`size-4 text-muted-foreground shrink-0`}):(0,g.jsx)(m.File,{className:`size-4 text-muted-foreground shrink-0`}),(0,g.jsx)(`span`,{className:`text-sm truncate`,children:e.name||e.original_name||`File`}),e.size&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,(e.size/1024).toFixed(1),` KB)`]})]}),(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:e=>{e.stopPropagation(),P(t)},className:`h-6 w-6 p-0`,children:(0,g.jsx)(m.X,{className:`size-3`})})]},t))})]})]})}var $e=o((()=>{})),et=s({ImageCropperDialog:()=>tt}),tt,nt=o((()=>{tt=({open:e,onOpenChange:t,src:n,outputType:r=`image/png`,outputName:i=`cropped.png`,onConfirm:a})=>{let o=(0,u.useRef)(null),s=(0,u.useRef)(null),[c,l]=(0,u.useState)(0),[d,f]=(0,u.useState)({x:0,y:0,width:100,height:100}),[h,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(!1);(0,u.useEffect)(()=>{if(!e||!n)return;y(!1);let t=new Image;t.crossOrigin=`anonymous`,t.onload=()=>{s.current=t;let e=t.naturalWidth*.8,n=t.naturalHeight*.8;f({x:(t.naturalWidth-e)/2,y:(t.naturalHeight-n)/2,width:e,height:n}),l(0),y(!0)},t.onerror=()=>y(!1),t.src=n},[e,n]),(0,u.useEffect)(()=>{if(!v||!s.current||!o.current)return;let e=s.current,t=o.current,n=t.getContext(`2d`);if(!n)return;let r=480/e.naturalWidth,i=e.naturalHeight*r;t.width=480,t.height=i,n.clearRect(0,0,480,i),n.save(),n.translate(480/2,i/2),n.rotate(c*Math.PI/180);let a=c%180==0?480:i,l=c%180==0?i:480;n.drawImage(e,-a/2,-l/2,a,l),n.restore();let u=d.x*r,f=d.y*r,p=d.width*r,m=d.height*r;n.fillStyle=`rgba(0,0,0,0.45)`,n.fillRect(0,0,480,f),n.fillRect(0,f+m,480,i-f-m),n.fillRect(0,f,u,m),n.fillRect(u+p,f,480-u-p,m),n.strokeStyle=`#3b82f6`,n.lineWidth=2,n.strokeRect(u,f,p,m)},[v,d,c]);let b=(0,u.useCallback)(e=>{if(!s.current||!o.current)return;let t=o.current.getBoundingClientRect(),n=s.current.naturalWidth/t.width;_({ox:(e.clientX-t.left)*n,oy:(e.clientY-t.top)*n,cx:d.x,cy:d.y}),e.target.setPointerCapture(e.pointerId)},[d]),x=(0,u.useCallback)(e=>{if(!h||!s.current||!o.current)return;let t=o.current.getBoundingClientRect(),n=s.current.naturalWidth/t.width,r=(e.clientX-t.left)*n-h.ox,i=(e.clientY-t.top)*n-h.oy,a=Math.max(0,Math.min(h.cx+r,s.current.naturalWidth-d.width)),c=Math.max(0,Math.min(h.cy+i,s.current.naturalHeight-d.height));f(e=>({...e,x:a,y:c}))},[h,d.width,d.height]),S=(0,u.useCallback)(()=>_(null),[]),C=(0,u.useCallback)(()=>l(e=>(e+90)%360),[]),w=(0,u.useCallback)(async()=>{if(!s.current)return;let e=s.current,n=document.createElement(`canvas`),o=d.width,l=d.height;n.width=c%180==0?o:l,n.height=c%180==0?l:o;let u=n.getContext(`2d`);if(!u)return;u.save(),u.translate(n.width/2,n.height/2),u.rotate(c*Math.PI/180),u.drawImage(e,d.x,d.y,o,l,-o/2,-l/2,o,l),u.restore();let f=await new Promise(e=>n.toBlob(e,r));f&&(a(f,i),t(!1))},[d,c,i,r,a,t]);return(0,g.jsx)(p.Dialog,{open:e,onOpenChange:t,children:(0,g.jsxs)(p.DialogContent,{className:`max-w-xl`,children:[(0,g.jsxs)(p.DialogHeader,{children:[(0,g.jsx)(p.DialogTitle,{children:`Crop & rotate image`}),(0,g.jsx)(p.DialogDescription,{children:`Drag the highlighted box to reposition the crop. Use the rotate button to spin the image in 90° increments.`})]}),(0,g.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[v?(0,g.jsx)(`canvas`,{ref:o,"data-testid":`image-cropper-canvas`,role:`img`,"aria-label":`Image crop preview`,className:`border rounded-md cursor-move touch-none max-w-full`,onPointerDown:b,onPointerMove:x,onPointerUp:S,onPointerCancel:S}):(0,g.jsx)(`div`,{className:`flex h-[270px] w-full items-center justify-center text-sm text-muted-foreground`,children:`Loading image…`}),(0,g.jsxs)(`div`,{className:`flex w-full items-center justify-between text-xs text-muted-foreground`,children:[(0,g.jsxs)(`span`,{children:[`Crop: `,Math.round(d.width),` × `,Math.round(d.height),` px`]}),(0,g.jsxs)(`span`,{children:[`Rotation: `,c,`°`]})]})]}),(0,g.jsxs)(p.DialogFooter,{className:`flex justify-between sm:justify-between`,children:[(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,onClick:C,"data-testid":`image-cropper-rotate`,children:[(0,g.jsx)(m.RotateCw,{className:`size-4 mr-2`}),`Rotate 90°`]}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,onClick:()=>t(!1),children:`Cancel`}),(0,g.jsxs)(p.Button,{type:`button`,onClick:w,disabled:!v,"data-testid":`image-cropper-confirm`,children:[(0,g.jsx)(m.Crop,{className:`size-4 mr-2`}),`Apply crop`]})]})]})]})})}})),rt=s({ImageField:()=>it});function it({value:e,onChange:t,field:n,readonly:r,...i}){let a=(0,u.useRef)(null),o=n||i.schema,s=o?.multiple||!1,c=o?.accept?o.accept.join(`,`):`image/*`,l=o?.crop!==!1,[d,f]=(0,u.useState)(null),{upload:h}=(0,_.useUpload)(),[v,y]=(0,u.useState)(!1);if(r)return e?(0,g.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(Array.isArray(e)?e:[e]).map((e,t)=>(0,g.jsx)(`img`,{src:e.url||``,alt:e.name||`Image ${t+1}`,className:`size-20 rounded-md object-cover border border-gray-200`},t))}):(0,g.jsx)(p.EmptyValue,{});let b=e?Array.isArray(e)?e:[e]:[],x=async e=>{let n=Array.from(e.target.files||[]);if(n.length!==0){y(!0);try{let e=await Promise.all(n.map(async e=>{let t=await h(e);return{name:t.name,original_name:e.name,size:t.size,mime_type:t.mimeType,url:t.url}}));t(s?[...b,...e]:e[0])}finally{y(!1),a.current&&(a.current.value=``)}}},S=e=>{if(s){let n=b.filter((t,n)=>n!==e);t(n.length>0?n:null)}else t(null)},C=(0,u.useCallback)(async(e,n)=>{if(d){y(!0);try{let r=await h(e),i={name:r.name||n,original_name:n,size:r.size,mime_type:r.mimeType,url:r.url};if(s){let e=[...b];e[d.index]=i,t(e)}else t(i)}finally{y(!1),f(null)}}},[d,b,s,t,h]),w=(0,u.useCallback)(e=>{let t=b[e];t?.url&&f({index:e,src:t.url,name:t.name||`image-${e}.png`})},[b]);return(0,g.jsxs)(`div`,{className:i.className,children:[(0,g.jsx)(`input`,{ref:a,type:`file`,multiple:s,accept:c,onChange:x,className:`hidden`}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[b.length>0&&(0,g.jsx)(`div`,{className:`grid grid-cols-4 gap-2`,children:b.map((e,t)=>(0,g.jsxs)(`div`,{className:`relative group`,children:[(0,g.jsx)(`img`,{src:e.url||``,alt:e.name||`Image ${t+1}`,className:`size-20 rounded-md object-cover border border-gray-200`}),(0,g.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[l&&(0,g.jsx)(p.Button,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>w(t),className:`h-6 w-6 p-0`,"aria-label":`Crop image ${t+1}`,"data-testid":`image-field-crop-${t}`,children:(0,g.jsx)(m.Crop,{className:`size-3`})}),(0,g.jsx)(p.Button,{type:`button`,variant:`destructive`,size:`sm`,onClick:()=>S(t),className:`h-6 w-6 p-0`,children:(0,g.jsx)(m.X,{className:`size-3`})})]})]},t))}),(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,onClick:()=>a.current?.click(),className:`w-full`,disabled:v,"data-testid":`image-field-upload-button`,children:[v?(0,g.jsx)(m.Loader2,{className:`size-4 mr-2 animate-spin`}):(0,g.jsx)(m.Image,{className:`size-4 mr-2`}),v?`Uploading…`:b.length>0?`Add More Images`:`Upload Image`]})]}),l&&d&&(0,g.jsx)(u.Suspense,{fallback:null,children:(0,g.jsx)(at,{open:!0,onOpenChange:e=>!e&&f(null),src:d.src,outputName:d.name,onConfirm:C})})]})}var at,ot=o((()=>{at=(0,u.lazy)(()=>Promise.resolve().then(()=>(nt(),et)).then(e=>({default:e.ImageCropperDialog})))})),st=s({LocationField:()=>ct});function ct({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=e&&typeof e==`object`?`${e.latitude||0}, ${e.longitude||0}`:``;return r?(0,g.jsx)(`span`,{className:`text-sm`,children:o||(0,g.jsx)(p.EmptyValue,{})}):(0,g.jsx)(p.Input,{type:`text`,value:o,onChange:e=>{let n=e.target.value;if(!n.trim()){t(null);return}let r=n.split(`,`).map(e=>e.trim());if(r.length===2){let e=parseFloat(r[0]),n=parseFloat(r[1]);!isNaN(e)&&!isNaN(n)&&t({latitude:e,longitude:n})}},placeholder:a?.placeholder||`latitude, longitude`,disabled:r||i.disabled,className:i.className})}var lt=o((()=>{})),ut=s({FormulaField:()=>dt});function dt({value:e,field:t,...n}){let r=(t||n.schema)?.return_type||`text`;if(e==null)return(0,g.jsx)(p.EmptyValue,{className:n.className});let i;return i=r===`number`||r===`currency`?typeof e==`number`?e.toFixed(2):String(e):r===`boolean`?e?`Yes`:`No`:r===`date`?new Date(e).toLocaleDateString():String(e),(0,g.jsx)(`span`,{className:`text-sm font-mono text-gray-700 ${n.className||``}`,children:i})}var ft=o((()=>{})),pt=s({SummaryField:()=>mt});function mt({value:e,field:t,...n}){let r=(t||n.schema)?.summary_type||`count`;if(e==null)return(0,g.jsx)(p.EmptyValue,{className:n.className});let i;return i=r===`count`?String(e):[`sum`,`avg`,`min`,`max`].includes(r)&&typeof e==`number`?e.toFixed(2):String(e),(0,g.jsx)(`span`,{className:`text-sm font-medium tabular-nums text-gray-700 ${n.className||``}`,children:i})}var ht=o((()=>{})),gt=s({AutoNumberField:()=>_t});function _t({value:e,field:t,...n}){return e==null?(0,g.jsx)(p.EmptyValue,{className:n.className}):(0,g.jsx)(`span`,{className:`text-sm font-mono text-gray-700 ${n.className||``}`,children:String(e)})}var vt=o((()=>{})),yt=s({UserField:()=>bt});function bt({value:e,onChange:t,field:n,readonly:r,...i}){let a=(n||i.schema)?.multiple||!1;if(r){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=Array.isArray(e)?e:[e];return(0,g.jsxs)(`div`,{className:`flex -space-x-2`,children:[t.slice(0,3).map((e,t)=>{let n=e.name||e.username||`User`;return(0,g.jsx)(p.Avatar,{className:`size-8 border-2 border-white`,title:n,children:(0,g.jsx)(p.AvatarFallback,{className:`bg-blue-500 text-white text-xs`,children:n.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)})},t)}),t.length>3&&(0,g.jsx)(p.Avatar,{className:`size-8 border-2 border-white`,children:(0,g.jsxs)(p.AvatarFallback,{className:`bg-gray-200 text-gray-600 text-xs`,children:[`+`,t.length-3]})})]})}let o=e?Array.isArray(e)?e:[e]:[],s=e=>{if(a){let n=o.filter((t,n)=>n!==e);t(n.length>0?n:null)}else t(null)};return(0,g.jsxs)(`div`,{className:i.className,children:[o.length>0&&(0,g.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-2`,children:o.map((e,t)=>{let n=e.name||e.username||`User`;return(0,g.jsxs)(p.Badge,{variant:`outline`,className:`gap-2 pr-1`,children:[(0,g.jsx)(p.Avatar,{className:`size-5`,children:(0,g.jsx)(p.AvatarFallback,{className:`bg-blue-500 text-white text-xs`,children:n.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)})}),(0,g.jsx)(`span`,{className:`text-sm`,children:n}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:`ml-1 rounded-full hover:bg-gray-200 p-0.5`,children:(0,g.jsx)(m.X,{className:`size-3`})})]},t)})}),(0,g.jsx)(`div`,{className:`text-sm text-gray-500 italic`,children:`User selection component requires integration with user management system`})]})}var xt=o((()=>{})),St=s({ObjectField:()=>Ct});function Ct({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,[o,s]=(0,u.useState)(()=>e==null?``:JSON.stringify(e,null,2)),[c,l]=(0,u.useState)(null);return(0,u.useEffect)(()=>{try{if(e==null){s(``);return}let t=o?JSON.parse(o):null;JSON.stringify(t)!==JSON.stringify(e)&&s(JSON.stringify(e,null,2))}catch{s(JSON.stringify(e,null,2))}},[e,o]),r?e?(0,g.jsx)(`pre`,{className:(0,p.cn)(`text-xs bg-gray-50 p-2 rounded border border-gray-200 overflow-auto max-h-40`,i.className),children:JSON.stringify(e,null,2)}):(0,g.jsx)(p.EmptyValue,{}):(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Textarea,{value:o,onChange:e=>{let n=e.target.value;if(s(n),l(null),!n.trim()){t(null);return}try{t(JSON.parse(n))}catch{l(`Invalid JSON`)}},placeholder:a?.placeholder||`{
|
|
6
|
+
`,role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a.current?.click())},children:[(0,g.jsx)(m.Upload,{className:`size-8 ${b?`text-primary`:`text-muted-foreground`}`}),(0,g.jsxs)(`div`,{className:`text-center`,children:[(0,g.jsx)(`p`,{className:`text-sm font-medium`,children:b?`Drop files here`:`Drag & drop files here`}),(0,g.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:[`or click to browse`,y?` • use the camera button below`:``]})]})]}),y&&(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,className:`w-full`,onClick:e=>{e.stopPropagation(),o.current?.click()},"data-testid":`file-field-camera-button`,children:[(0,g.jsx)(m.Camera,{className:`size-4 mr-2`}),y===`user`?`Take selfie`:`Take photo`]}),D&&(0,g.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,"data-testid":`file-field-uploading`,children:[(0,g.jsx)(m.Loader2,{className:`size-3 animate-spin`}),(0,g.jsxs)(`span`,{children:[`Uploading…`,Object.keys(T).length>0&&` (${Math.round(Object.values(T).reduce((e,t)=>e+t,0)/Object.keys(T).length*100)}%)`]})]}),S.length>0&&(0,g.jsx)(`div`,{className:`space-y-0.5`,children:S.map((e,t)=>(0,g.jsx)(`p`,{className:`text-xs text-destructive`,children:e},t))}),k.length>0&&(0,g.jsx)(`div`,{className:`space-y-1`,children:k.map((e,t)=>(0,g.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-2 bg-muted/50 rounded-md border`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0`,children:[P(e)&&e.url?(0,g.jsx)(`img`,{src:e.url,alt:e.name,className:`size-8 object-cover rounded shrink-0`}):P(e)?(0,g.jsx)(m.ImageIcon,{className:`size-4 text-muted-foreground shrink-0`}):(0,g.jsx)(m.File,{className:`size-4 text-muted-foreground shrink-0`}),(0,g.jsx)(`span`,{className:`text-sm truncate`,children:e.name||e.original_name||`File`}),e.size&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,(e.size/1024).toFixed(1),` KB)`]})]}),(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:e=>{e.stopPropagation(),N(t)},className:`h-6 w-6 p-0`,children:(0,g.jsx)(m.X,{className:`size-3`})})]},t))})]})]})}var $e=o((()=>{})),et=s({ImageCropperDialog:()=>tt}),tt,nt=o((()=>{tt=({open:e,onOpenChange:t,src:n,outputType:r=`image/png`,outputName:i=`cropped.png`,onConfirm:a})=>{let o=(0,u.useRef)(null),s=(0,u.useRef)(null),[c,l]=(0,u.useState)(0),[d,f]=(0,u.useState)({x:0,y:0,width:100,height:100}),[h,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(!1);(0,u.useEffect)(()=>{if(!e||!n)return;y(!1);let t=new Image;t.crossOrigin=`anonymous`,t.onload=()=>{s.current=t;let e=t.naturalWidth*.8,n=t.naturalHeight*.8;f({x:(t.naturalWidth-e)/2,y:(t.naturalHeight-n)/2,width:e,height:n}),l(0),y(!0)},t.onerror=()=>y(!1),t.src=n},[e,n]),(0,u.useEffect)(()=>{if(!v||!s.current||!o.current)return;let e=s.current,t=o.current,n=t.getContext(`2d`);if(!n)return;let r=480/e.naturalWidth,i=e.naturalHeight*r;t.width=480,t.height=i,n.clearRect(0,0,480,i),n.save(),n.translate(480/2,i/2),n.rotate(c*Math.PI/180);let a=c%180==0?480:i,l=c%180==0?i:480;n.drawImage(e,-a/2,-l/2,a,l),n.restore();let u=d.x*r,f=d.y*r,p=d.width*r,m=d.height*r;n.fillStyle=`rgba(0,0,0,0.45)`,n.fillRect(0,0,480,f),n.fillRect(0,f+m,480,i-f-m),n.fillRect(0,f,u,m),n.fillRect(u+p,f,480-u-p,m),n.strokeStyle=`#3b82f6`,n.lineWidth=2,n.strokeRect(u,f,p,m)},[v,d,c]);let b=(0,u.useCallback)(e=>{if(!s.current||!o.current)return;let t=o.current.getBoundingClientRect(),n=s.current.naturalWidth/t.width;_({ox:(e.clientX-t.left)*n,oy:(e.clientY-t.top)*n,cx:d.x,cy:d.y}),e.target.setPointerCapture(e.pointerId)},[d]),x=(0,u.useCallback)(e=>{if(!h||!s.current||!o.current)return;let t=o.current.getBoundingClientRect(),n=s.current.naturalWidth/t.width,r=(e.clientX-t.left)*n-h.ox,i=(e.clientY-t.top)*n-h.oy,a=Math.max(0,Math.min(h.cx+r,s.current.naturalWidth-d.width)),c=Math.max(0,Math.min(h.cy+i,s.current.naturalHeight-d.height));f(e=>({...e,x:a,y:c}))},[h,d.width,d.height]),S=(0,u.useCallback)(()=>_(null),[]),C=(0,u.useCallback)(()=>l(e=>(e+90)%360),[]),w=(0,u.useCallback)(async()=>{if(!s.current)return;let e=s.current,n=document.createElement(`canvas`),o=d.width,l=d.height;n.width=c%180==0?o:l,n.height=c%180==0?l:o;let u=n.getContext(`2d`);if(!u)return;u.save(),u.translate(n.width/2,n.height/2),u.rotate(c*Math.PI/180),u.drawImage(e,d.x,d.y,o,l,-o/2,-l/2,o,l),u.restore();let f=await new Promise(e=>n.toBlob(e,r));f&&(a(f,i),t(!1))},[d,c,i,r,a,t]);return(0,g.jsx)(p.Dialog,{open:e,onOpenChange:t,children:(0,g.jsxs)(p.DialogContent,{className:`max-w-xl`,children:[(0,g.jsxs)(p.DialogHeader,{children:[(0,g.jsx)(p.DialogTitle,{children:`Crop & rotate image`}),(0,g.jsx)(p.DialogDescription,{children:`Drag the highlighted box to reposition the crop. Use the rotate button to spin the image in 90° increments.`})]}),(0,g.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[v?(0,g.jsx)(`canvas`,{ref:o,"data-testid":`image-cropper-canvas`,role:`img`,"aria-label":`Image crop preview`,className:`border rounded-md cursor-move touch-none max-w-full`,onPointerDown:b,onPointerMove:x,onPointerUp:S,onPointerCancel:S}):(0,g.jsx)(`div`,{className:`flex h-[270px] w-full items-center justify-center text-sm text-muted-foreground`,children:`Loading image…`}),(0,g.jsxs)(`div`,{className:`flex w-full items-center justify-between text-xs text-muted-foreground`,children:[(0,g.jsxs)(`span`,{children:[`Crop: `,Math.round(d.width),` × `,Math.round(d.height),` px`]}),(0,g.jsxs)(`span`,{children:[`Rotation: `,c,`°`]})]})]}),(0,g.jsxs)(p.DialogFooter,{className:`flex justify-between sm:justify-between`,children:[(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,onClick:C,"data-testid":`image-cropper-rotate`,children:[(0,g.jsx)(m.RotateCw,{className:`size-4 mr-2`}),`Rotate 90°`]}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,onClick:()=>t(!1),children:`Cancel`}),(0,g.jsxs)(p.Button,{type:`button`,onClick:w,disabled:!v,"data-testid":`image-cropper-confirm`,children:[(0,g.jsx)(m.Crop,{className:`size-4 mr-2`}),`Apply crop`]})]})]})]})})}})),rt=s({ImageField:()=>it});function it({value:e,onChange:t,field:n,readonly:r,...i}){let a=(0,u.useRef)(null),o=n||i.schema,s=o?.multiple||!1,c=o?.accept?o.accept.join(`,`):`image/*`,l=o?.crop!==!1,[d,f]=(0,u.useState)(null),{upload:h}=(0,_.useUpload)(),[v,y]=(0,u.useState)(!1);if(r)return e?(0,g.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(Array.isArray(e)?e:[e]).map((e,t)=>(0,g.jsx)(`img`,{src:e.url||``,alt:e.name||`Image ${t+1}`,className:`size-20 rounded-md object-cover border border-gray-200`},t))}):(0,g.jsx)(p.EmptyValue,{});let b=e?Array.isArray(e)?e:[e]:[],x=async e=>{let n=Array.from(e.target.files||[]);if(n.length!==0){y(!0);try{let e=await Promise.all(n.map(async e=>{let t=await h(e);return{name:t.name,original_name:e.name,size:t.size,mime_type:t.mimeType,url:t.url}}));t(s?[...b,...e]:e[0])}finally{y(!1),a.current&&(a.current.value=``)}}},S=e=>{if(s){let n=b.filter((t,n)=>n!==e);t(n.length>0?n:null)}else t(null)},C=(0,u.useCallback)(async(e,n)=>{if(d){y(!0);try{let r=await h(e),i={name:r.name||n,original_name:n,size:r.size,mime_type:r.mimeType,url:r.url};if(s){let e=[...b];e[d.index]=i,t(e)}else t(i)}finally{y(!1),f(null)}}},[d,b,s,t,h]),w=(0,u.useCallback)(e=>{let t=b[e];t?.url&&f({index:e,src:t.url,name:t.name||`image-${e}.png`})},[b]);return(0,g.jsxs)(`div`,{className:i.className,children:[(0,g.jsx)(`input`,{ref:a,type:`file`,multiple:s,accept:c,onChange:x,className:`hidden`}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[b.length>0&&(0,g.jsx)(`div`,{className:`grid grid-cols-4 gap-2`,children:b.map((e,t)=>(0,g.jsxs)(`div`,{className:`relative group`,children:[(0,g.jsx)(`img`,{src:e.url||``,alt:e.name||`Image ${t+1}`,className:`size-20 rounded-md object-cover border border-gray-200`}),(0,g.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[l&&(0,g.jsx)(p.Button,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>w(t),className:`h-6 w-6 p-0`,"aria-label":`Crop image ${t+1}`,"data-testid":`image-field-crop-${t}`,children:(0,g.jsx)(m.Crop,{className:`size-3`})}),(0,g.jsx)(p.Button,{type:`button`,variant:`destructive`,size:`sm`,onClick:()=>S(t),className:`h-6 w-6 p-0`,children:(0,g.jsx)(m.X,{className:`size-3`})})]})]},t))}),(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,onClick:()=>a.current?.click(),className:`w-full`,disabled:v,"data-testid":`image-field-upload-button`,children:[v?(0,g.jsx)(m.Loader2,{className:`size-4 mr-2 animate-spin`}):(0,g.jsx)(m.Image,{className:`size-4 mr-2`}),v?`Uploading…`:b.length>0?`Add More Images`:`Upload Image`]})]}),l&&d&&(0,g.jsx)(u.Suspense,{fallback:null,children:(0,g.jsx)(at,{open:!0,onOpenChange:e=>!e&&f(null),src:d.src,outputName:d.name,onConfirm:C})})]})}var at,ot=o((()=>{at=(0,u.lazy)(()=>Promise.resolve().then(()=>(nt(),et)).then(e=>({default:e.ImageCropperDialog})))})),st=s({LocationField:()=>ct});function ct({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=e&&typeof e==`object`?`${e.latitude||0}, ${e.longitude||0}`:``;return r?(0,g.jsx)(`span`,{className:`text-sm`,children:o||(0,g.jsx)(p.EmptyValue,{})}):(0,g.jsx)(p.Input,{type:`text`,value:o,onChange:e=>{let n=e.target.value;if(!n.trim()){t(null);return}let r=n.split(`,`).map(e=>e.trim());if(r.length===2){let e=parseFloat(r[0]),n=parseFloat(r[1]);!isNaN(e)&&!isNaN(n)&&t({latitude:e,longitude:n})}},placeholder:a?.placeholder||`latitude, longitude`,disabled:r||i.disabled,className:i.className})}var lt=o((()=>{})),ut=s({FormulaField:()=>dt});function dt({value:e,field:t,...n}){let r=(t||n.schema)?.return_type||`text`;if(e==null)return(0,g.jsx)(p.EmptyValue,{className:n.className});let i;return i=r===`number`||r===`currency`?typeof e==`number`?e.toFixed(2):String(e):r===`boolean`?e?`Yes`:`No`:r===`date`?new Date(e).toLocaleDateString():String(e),(0,g.jsx)(`span`,{className:`text-sm font-mono text-gray-700 ${n.className||``}`,children:i})}var ft=o((()=>{})),pt=s({SummaryField:()=>mt});function mt({value:e,field:t,...n}){let r=(t||n.schema)?.summary_type||`count`;if(e==null)return(0,g.jsx)(p.EmptyValue,{className:n.className});let i;return i=r===`count`?String(e):[`sum`,`avg`,`min`,`max`].includes(r)&&typeof e==`number`?e.toFixed(2):String(e),(0,g.jsx)(`span`,{className:`text-sm font-medium tabular-nums text-gray-700 ${n.className||``}`,children:i})}var ht=o((()=>{})),gt=s({AutoNumberField:()=>_t});function _t({value:e,field:t,...n}){return e==null?(0,g.jsx)(p.EmptyValue,{className:n.className}):(0,g.jsx)(`span`,{className:`text-sm font-mono text-gray-700 ${n.className||``}`,children:String(e)})}var vt=o((()=>{})),yt=s({UserField:()=>bt});function bt(e){let t=e.field||e.schema,n=t?.field&&typeof t.field==`object`&&(`reference`in t.field||`reference_to`in t.field||`type`in t.field),r=n?t.field:t,i={...r||{},reference:r?.reference||r?.reference_to||`sys_user`,display_field:r?.display_field||r?.displayField||r?.reference_field||`name`},a=n?{...t,field:i}:i;return(0,g.jsx)(Ie,{...e,field:a})}var xt=o((()=>{Z()})),St=s({ObjectField:()=>Ct});function Ct({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,[o,s]=(0,u.useState)(()=>e==null?``:JSON.stringify(e,null,2)),[c,l]=(0,u.useState)(null);return(0,u.useEffect)(()=>{try{if(e==null){s(``);return}let t=o?JSON.parse(o):null;JSON.stringify(t)!==JSON.stringify(e)&&s(JSON.stringify(e,null,2))}catch{s(JSON.stringify(e,null,2))}},[e,o]),r?e?(0,g.jsx)(`pre`,{className:(0,p.cn)(`text-xs bg-gray-50 p-2 rounded border border-gray-200 overflow-auto max-h-40`,i.className),children:JSON.stringify(e,null,2)}):(0,g.jsx)(p.EmptyValue,{}):(0,g.jsxs)(`div`,{className:`space-y-1`,children:[(0,g.jsx)(p.Textarea,{value:o,onChange:e=>{let n=e.target.value;if(s(n),l(null),!n.trim()){t(null);return}try{t(JSON.parse(n))}catch{l(`Invalid JSON`)}},placeholder:a?.placeholder||`{
|
|
7
7
|
"key": "value"
|
|
8
8
|
}`,disabled:r||i.disabled,className:(0,p.cn)(`font-mono text-xs`,c?`border-red-500 focus-visible:ring-red-500`:``,i.className),rows:6}),c&&(0,g.jsx)(`p`,{className:`text-xs text-red-500`,children:c})]})}var wt=o((()=>{})),Tt=s({VectorField:()=>Et});function Et({value:e,field:t,...n}){let r=(t||n.schema)?.dimensions||(Array.isArray(e)?e.length:0);if(!e||!Array.isArray(e))return(0,g.jsx)(p.EmptyValue,{});let i=e.slice(0,3).map(e=>{let t=Number(e);return isNaN(t)?`0`:t.toFixed(4)}).join(`, `);return(0,g.jsxs)(`div`,{className:`text-sm ${n.className||``}`,children:[(0,g.jsxs)(`span`,{className:`font-mono text-gray-700`,children:[`[`,i,`...]`]}),(0,g.jsxs)(`span`,{className:`text-gray-500 ml-2`,children:[`(`,r,`D)`]})]})}var Dt=o((()=>{})),Ot=s({GridField:()=>Rt,LineItemsField:()=>Ht,computeRow:()=>Pt,evalArith:()=>Mt,lookupAutofillPatch:()=>Nt,sumColumn:()=>Lt});function kt(e){if(e.width)return{width:e.width,minWidth:e.width};if((e.type??`text`)===`text`)return{minWidth:180};let t=Bt[e.type??`text`]??132;return{width:t,minWidth:t}}function At(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===` `||r===`
|
|
9
|
-
`){n++;continue}if(r>=`0`&&r<=`9`||r===`.`){let r=n+1;for(;r<e.length&&(e[r]>=`0`&&e[r]<=`9`||e[r]===`.`);)r++;t.push({t:`num`,v:e.slice(n,r)}),n=r;continue}if(/[a-zA-Z_]/.test(r)){let r=n+1;for(;r<e.length&&/[a-zA-Z0-9_.]/.test(e[r]);)r++;t.push({t:`id`,v:e.slice(n,r)}),n=r;continue}if(r===`+`||r===`-`||r===`*`||r===`/`||r===`%`){t.push({t:`op`,v:r}),n++;continue}if(r===`(`){t.push({t:`lp`,v:r}),n++;continue}if(r===`)`){t.push({t:`rp`,v:r}),n++;continue}return null}return t}function jt(e,t){let n=e.startsWith(`record.`)?e.slice(7):e,r=t?.[n];if(r==null||r===``)return null;let i=Number(r);return Number.isFinite(i)?i:null}function Mt(e,t){let n=At(e);if(!n||n.length===0)return null;let r=0,i=!1,a=()=>n[r],o=()=>n[r++];function s(){let e=a();if(!e)return i=!0,NaN;if(e.t===`op`&&e.v===`-`)return o(),-s();if(e.t===`op`&&e.v===`+`)return o(),s();if(e.t===`num`)return o(),Number(e.v);if(e.t===`id`){o();let n=jt(e.v,t);return n===null?(i=!0,NaN):n}if(e.t===`lp`){o();let e=l(),t=o();return(!t||t.t!==`rp`)&&(i=!0),e}return i=!0,NaN}function c(){let e=s();for(;a()&&a().t===`op`&&(a().v===`*`||a().v===`/`||a().v===`%`);){let t=o().v,n=s();e=t===`*`?e*n:t===`/`?e/n:e%n}return e}function l(){let e=c();for(;a()&&a().t===`op`&&(a().v===`+`||a().v===`-`);){let t=o().v,n=c();e=t===`+`?e+n:e-n}return e}let u=l();return i||r!==n.length||!Number.isFinite(u)?null:u}function Nt(e,t,n){let r={[t.field]:n?.value??n?.id??n?._id};if(t.autofill!==!1&&n&&typeof n==`object`)for(let i of e){if(i.field===t.field||i.computed||i.type===`lookup`)continue;let e=n[i.field];e!=null&&e!==``&&(r[i.field]=e)}return r}function Pt(e,t){let n=e.filter(e=>e.computed&&e.expr);if(n.length===0)return t;let r={...t};for(let e of n){let t=Mt(e.expr,r);if(t===null){r[e.field]=null;continue}let n=e.scale??(e.type===`currency`?2:void 0);r[e.field]=n==null?t:Number(t.toFixed(n))}return r}function Ft(e,t){if(t==null||t===``)return`—`;if(e.type===`select`&&Array.isArray(e.options)){let n=e.options.find(e=>String(e.value)===String(t));return n?n.label:String(t)}if(zt(e.type)){let n=Number(t);if(Number.isFinite(n))return e.type===`currency`?`${e.prefix||`¥`}${n.toLocaleString()}`:n.toLocaleString()}return Array.isArray(t)?t.join(`, `):String(t)}function It(e,t){if(zt(e)){if(t===``||t==null)return null;let e=Number(t);return Number.isNaN(e)?t:e}return t}function Lt(e,t){return Array.isArray(e)?e.reduce((e,n)=>{let r=Number(n?.[t]);return e+(Number.isFinite(r)?r:0)},0):0}function Rt({value:e,onChange:t,field:n,readonly:r,disabled:i,className:a,onRowExpand:o,displayMode:s,onAdd:c,...l}){let f=n||l.schema||{},h=f.columns||[],_=Array.isArray(e)?e:[],v=l.contextRecord,y=(0,u.useCallback)((e,t)=>{if(!e.readonlyWhen&&!e.requiredWhen)return{readonly:!1,required:!!e.required};let n=(0,d.resolveFieldRuleState)({readonlyWhen:e.readonlyWhen,requiredWhen:e.requiredWhen},t||{},{required:!!e.required,readonly:!1},void 0,v?{parent:v}:void 0);return{readonly:n.readonly,required:n.required}},[v]),b=s===`list`&&!r,[x,S]=u.default.useState(()=>new Set),C=h.filter(e=>e.defaultHidden&&!e.required),w=h.filter(e=>!e.defaultHidden||e.required||x.has(e.field)),T=(0,u.useCallback)(e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),E=f.allow_add!==!1&&!r&&!i,D=f.allow_delete!==!1&&!r&&!i,O=f.allow_duplicate!==!1&&E,k=typeof o==`function`&&!r,A=f.show_line_numbers!==!1,ee=f.min_rows??0,j=f.max_rows,M=f.total_field||f.amount_field||f.amountField,N=f.sort_field,P=f.reorderable!==!1&&!r&&!i,F=(0,u.useCallback)(e=>{t?.(N?e.map((e,t)=>({...e,[N]:t})):e)},[t,N]),I=(0,u.useCallback)(()=>{let e={};for(let t of w)e[t.field]=null;return e},[w]),L=(0,u.useCallback)((e,t)=>{if(e>=_.length){if(j!=null&&_.length>=j)return;F([..._,Pt(w,{...I(),...t})]);return}F(_.map((n,r)=>r===e?Pt(w,{...n,...t}):n))},[_,w,j,I,F]),te=(0,u.useCallback)((e,t,n)=>L(e,{[t]:n}),[L]),R=(0,u.useCallback)((e,t,n)=>{L(e,Nt(w,t,n))},[w,L]),ne=(0,u.useCallback)((e,t,n)=>te(e,t,n),[te]),z=(0,u.useCallback)((e,t,n)=>{te(e,t.field,It(t.type,n))},[te]),B=(0,u.useCallback)(()=>{j!=null&&_.length>=j||F([..._,I()])},[_,I,j,F]),V=(0,u.useRef)(null),H=(0,u.useCallback)((e,t)=>{let n=V.current?.querySelector(`[data-cell="${e}-${t}"]`);n&&(n.focus(),n instanceof HTMLInputElement&&n.select())},[]),re=(0,u.useCallback)((e,t,n)=>{e.key===`ArrowDown`||e.key===`Enter`?(e.preventDefault(),H(t+1,n)):e.key===`ArrowUp`&&(e.preventDefault(),t>0&&H(t-1,n))},[H]),U=(0,u.useCallback)(e=>{_.length<=ee||F(_.filter((t,n)=>n!==e))},[_,ee,F]),ie=(0,u.useCallback)(e=>{if(j!=null&&_.length>=j)return;let t=_[e];if(!t)return;let{id:n,_id:r,recordId:i,...a}=t,o=[..._];o.splice(e+1,0,{...a}),F(o)},[_,j,F]),ae=(0,u.useCallback)((e,t)=>{if(e===t||e<0||t<0||e>=_.length||t>=_.length)return;let n=[..._],[r]=n.splice(e,1);n.splice(t,0,r),F(n)},[_,F]),W=(0,u.useRef)(null),G=k||D||O,oe=(+!!k+ +!!O+ +!!D)*34+12,K=!!M,q=K?Lt(_,M):0,J=K?Math.max(0,w.findIndex(e=>e.field===M)):-1,se=C.length>0?(0,g.jsxs)(p.Popover,{children:[(0,g.jsx)(p.PopoverTrigger,{asChild:!0,children:(0,g.jsxs)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 gap-1.5 text-xs text-muted-foreground`,"data-testid":`line-items-columns`,children:[(0,g.jsx)(m.SlidersHorizontal,{className:`h-3.5 w-3.5`}),`Columns`,x.size>0&&(0,g.jsxs)(`span`,{className:`rounded-full bg-primary/10 px-1.5 text-[10px] font-medium text-primary`,children:[`+`,x.size]})]})}),(0,g.jsxs)(p.PopoverContent,{align:`end`,className:`w-56 p-2`,children:[(0,g.jsx)(`div`,{className:`px-1 pb-1.5 text-xs font-medium text-muted-foreground`,children:`Optional columns`}),(0,g.jsx)(`div`,{className:`max-h-64 space-y-0.5 overflow-y-auto`,children:C.map(e=>{let t=`col-toggle-${e.field}`;return(0,g.jsxs)(p.Label,{htmlFor:t,className:`flex cursor-pointer items-center gap-2 rounded-md px-1.5 py-1.5 text-sm font-normal hover:bg-muted`,children:[(0,g.jsx)(p.Checkbox,{id:t,checked:x.has(e.field),onCheckedChange:()=>T(e.field)}),(0,g.jsx)(`span`,{className:`truncate`,children:e.label||e.field})]},e.field)})})]})]}):null;if(r)return(0,g.jsxs)(`div`,{className:(0,p.cn)(`space-y-2`,a),children:[se&&(0,g.jsx)(`div`,{className:`flex justify-end`,children:se}),(0,g.jsx)(`div`,{className:`border border-border rounded-lg overflow-x-auto`,"data-testid":`line-items-readonly`,children:(0,g.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,g.jsx)(`thead`,{className:`bg-muted border-b border-border`,children:(0,g.jsxs)(`tr`,{children:[A&&(0,g.jsx)(`th`,{className:`w-10 px-2 py-2 text-right text-xs font-medium text-muted-foreground`,children:`#`}),w.map(e=>(0,g.jsx)(`th`,{style:{minWidth:Vt(e)},className:(0,p.cn)(`px-3 py-2 text-xs font-medium text-muted-foreground whitespace-nowrap`,zt(e.type)?`text-right`:`text-left`),children:e.label||e.field},e.field))]})}),(0,g.jsx)(`tbody`,{className:`divide-y divide-border`,children:_.length===0?(0,g.jsx)(`tr`,{children:(0,g.jsx)(`td`,{colSpan:Math.max(w.length+ +!!A,1),className:`px-3 py-6 text-center text-muted-foreground`,children:`No items`})}):_.map((e,t)=>(0,g.jsxs)(`tr`,{children:[A&&(0,g.jsx)(`td`,{className:`px-2 py-2 text-right text-muted-foreground tabular-nums`,children:t+1}),w.map(t=>(0,g.jsx)(`td`,{className:(0,p.cn)(`px-3 py-2 text-foreground`,zt(t.type)&&`text-right tabular-nums`),children:t.type===`lookup`&&e[t.field]!=null&&e[t.field]!==``?(0,g.jsx)(Fe,{value:e[t.field],onChange:()=>{},readonly:!0,field:{reference:t.reference,display_field:t.displayField,id_field:t.idField}}):e[t.field]!=null&&e[t.field]!==``?String(e[t.field]):`—`},t.field))]},t))}),K&&(0,g.jsx)(`tfoot`,{className:`border-t border-border bg-muted/40`,children:(0,g.jsxs)(`tr`,{children:[(0,g.jsx)(`td`,{colSpan:Math.max(+!!A+J,1),className:`px-3 py-2 text-right text-xs font-medium text-muted-foreground`,children:`Total`}),(0,g.jsx)(`td`,{className:`px-3 py-2 text-right font-semibold text-foreground tabular-nums`,children:q.toLocaleString()}),w.length-J-1>0&&(0,g.jsx)(`td`,{colSpan:w.length-J-1})]})})]})})]});let Y=!b&&E&&(j==null||_.length<j),X=Y?[..._,I()]:_,ce=(e,t,n,r)=>{let a=r?.[e.field],o=i||y(e,r).readonly;return b?e.type===`lookup`&&a!=null&&a!==``?(0,g.jsx)(Fe,{value:a,onChange:()=>{},readonly:!0,field:{reference:e.reference,display_field:e.displayField,id_field:e.idField}}):(0,g.jsx)(`span`,{className:(0,p.cn)(`px-2 text-sm text-foreground`,zt(e.type)&&`tabular-nums`,(a==null||a===``)&&`text-muted-foreground`),children:Ft(e,a)}):e.computed?(0,g.jsx)(`span`,{className:(0,p.cn)(`block px-2 text-sm tabular-nums`,zt(e.type)?`text-right`:`text-left`,a==null||a===``?`text-muted-foreground`:`text-foreground`),title:`Computed`,"data-computed":e.field,children:Ft(e,a)}):e.type===`lookup`?(0,g.jsx)(Fe,{value:a,onChange:t=>ne(n,e.field,t),onSelectRecord:t=>R(n,e,t),compact:!0,field:{reference:e.reference,display_field:e.displayField,id_field:e.idField,multiple:e.multiple,options:e.options,placeholder:`—`},disabled:o}):e.type===`select`?(0,g.jsxs)(p.Select,{value:a==null?``:String(a),onValueChange:t=>z(n,e,t),disabled:o,children:[(0,g.jsx)(p.SelectTrigger,{className:`h-8 rounded-none border-0 bg-transparent px-2 shadow-none focus:ring-1 focus:ring-ring/60`,"aria-label":e.label||e.field,children:(0,g.jsx)(p.SelectValue,{placeholder:`—`})}),(0,g.jsx)(p.SelectContent,{children:(e.options||[]).map(e=>(0,g.jsx)(p.SelectItem,{value:e.value,children:e.label},e.value))})]}):(0,g.jsxs)(`div`,{className:`relative`,children:[e.type===`currency`&&(0,g.jsx)(`span`,{className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-xs text-muted-foreground`,children:e.prefix||`¥`}),(0,g.jsx)(p.Input,{"data-cell":`${n}-${t}`,onKeyDown:e=>re(e,n,t),className:(0,p.cn)(`h-8 rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:ring-1 focus-visible:ring-ring/60`,e.type===`currency`&&`pl-6`,zt(e.type)&&`text-right tabular-nums`),type:e.type===`date`?`date`:zt(e.type)?`number`:`text`,step:zt(e.type)?e.step??`any`:void 0,"aria-label":e.label||e.field,value:a==null?``:String(a),onChange:t=>z(n,e,t.target.value),disabled:o})]})};return(0,g.jsxs)(`div`,{className:(0,p.cn)(`space-y-2`,a),"data-testid":`line-items`,children:[se&&(0,g.jsx)(`div`,{className:`flex justify-end`,children:se}),(0,g.jsx)(`div`,{className:`border border-border rounded-lg overflow-x-auto`,children:(0,g.jsxs)(`table`,{ref:V,className:`w-full text-sm`,children:[(0,g.jsx)(`thead`,{className:`bg-muted/60 border-b border-border`,children:(0,g.jsxs)(`tr`,{children:[A&&(0,g.jsx)(`th`,{className:(0,p.cn)(`px-2 py-2 text-right text-xs font-medium text-muted-foreground`,P?`w-14`:`w-10`),children:`#`}),w.map(e=>(0,g.jsxs)(`th`,{className:(0,p.cn)(`px-2 py-2 text-xs font-medium text-muted-foreground whitespace-nowrap`,zt(e.type)?`text-right`:`text-left`),style:kt(e),children:[e.label||e.field,e.required&&!e.computed&&(0,g.jsx)(`span`,{className:`text-destructive`,children:` *`})]},e.field)),G&&(0,g.jsx)(`th`,{style:{width:oe}})]})}),(0,g.jsx)(`tbody`,{className:`divide-y divide-border`,children:b&&_.length===0?(0,g.jsx)(`tr`,{children:(0,g.jsxs)(`td`,{colSpan:w.length+ +!!G+ +!!A,className:`px-3 py-6 text-center text-muted-foreground`,children:[`No items yet — click “`,f.add_label||`Add`,`” to begin.`]})}):X.map((e,t)=>{let n=Y&&t===_.length,r=P&&!n&&!b;return(0,g.jsxs)(`tr`,{className:(0,p.cn)(`group`,!n&&`hover:bg-muted/30`),...P&&!n?{onDragOver:e=>{W.current!=null&&e.preventDefault()},onDrop:e=>{e.preventDefault(),W.current!=null&&(ae(W.current,t),W.current=null)}}:{},children:[A&&(0,g.jsx)(`td`,{className:`px-1 py-1 text-right align-middle text-xs text-muted-foreground tabular-nums`,children:(0,g.jsxs)(`span`,{className:`inline-flex items-center justify-end gap-0.5`,children:[r&&(0,g.jsx)(`span`,{draggable:!0,onDragStart:()=>{W.current=t},onDragEnd:()=>{W.current=null},className:`cursor-grab text-muted-foreground/40 opacity-0 transition-opacity group-hover:opacity-100`,title:`Drag to reorder`,"aria-label":`Drag to reorder`,"data-testid":`line-items-drag-${t}`,children:(0,g.jsx)(m.GripVertical,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(`span`,{className:(0,p.cn)(n&&`opacity-30`),children:t+1})]})}),w.map((r,i)=>{let a=y(r,e).required,o=!n&&!b&&a&&!r.computed&&(e[r.field]==null||e[r.field]===``);return(0,g.jsx)(`td`,{"aria-invalid":o||void 0,title:o?`${r.label||r.field} is required`:void 0,"data-testid":o?`line-items-invalid-${t}-${r.field}`:void 0,className:(0,p.cn)(`border-r border-border/40 px-1 py-0.5 align-middle last:border-r-0`,b&&`px-2 py-1.5`,o&&`bg-destructive/5 ring-1 ring-inset ring-destructive/50`),children:ce(r,i,t,e)},r.field)}),G&&(0,g.jsx)(`td`,{className:`px-1 py-0.5 align-middle whitespace-nowrap`,children:(0,g.jsxs)(`div`,{className:`flex items-center justify-center gap-0.5`,children:[!n&&k&&(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground hover:text-foreground`,"aria-label":`Open row`,title:`Open full form`,"data-testid":`line-items-expand-${t}`,onClick:()=>o(t),children:(0,g.jsx)(m.Maximize2,{className:`h-3.5 w-3.5`})}),!n&&O&&(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`icon`,className:(0,p.cn)(`h-8 w-8 text-muted-foreground hover:text-foreground`,!b&&`opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100`),"aria-label":`Duplicate row`,title:`Duplicate line`,"data-testid":`line-items-duplicate-${t}`,onClick:()=>ie(t),disabled:i||j!=null&&_.length>=j,children:(0,g.jsx)(m.Copy,{className:`h-3.5 w-3.5`})}),!n&&D&&(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`icon`,className:(0,p.cn)(`h-8 w-8 text-muted-foreground hover:text-destructive`,!b&&`opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100`),"aria-label":`Remove row`,"data-testid":`line-items-remove-${t}`,onClick:()=>U(t),disabled:i||_.length<=ee,children:(0,g.jsx)(m.Trash2,{className:`h-4 w-4`})})]})})]},t)})}),K&&(0,g.jsx)(`tfoot`,{className:`border-t border-border bg-muted/40`,children:(0,g.jsxs)(`tr`,{children:[(0,g.jsx)(`td`,{colSpan:Math.max(+!!A+J,1),className:`px-3 py-2 text-right text-xs font-medium text-muted-foreground`,children:`Total`}),(0,g.jsx)(`td`,{className:`px-3 py-2 text-right font-semibold text-foreground tabular-nums`,"data-testid":`line-items-total`,children:q.toLocaleString()}),w.length-J-1+ +!!G>0&&(0,g.jsx)(`td`,{colSpan:w.length-J-1+ +!!G})]})})]})}),E&&(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:b&&c?c:B,disabled:j!=null&&_.length>=j,"data-testid":`line-items-add`,children:[(0,g.jsx)(m.Plus,{className:`mr-1.5 h-4 w-4`}),f.add_label||`Add line`]})]})}var zt,Bt,Vt,Ht,Ut=o((()=>{Re(),zt=e=>e===`number`||e===`currency`,Bt={text:160,select:132,lookup:168,number:104,currency:116,date:150},Vt=e=>e.width??Bt[e.type??`text`]??132,Ht=Rt})),Wt=s({ColorField:()=>Gt});function Gt({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema;return r?(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`div`,{className:`w-6 h-6 rounded border border-input`,style:{backgroundColor:e||`#000000`}}),(0,g.jsx)(`span`,{className:`text-sm`,children:e||(0,g.jsx)(p.EmptyValue,{})})]}):(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`input`,{type:`color`,value:e||`#000000`,onChange:e=>t(e.target.value),disabled:r||i.disabled,className:`w-10 h-10 rounded border border-input cursor-pointer`}),(0,g.jsx)(p.Input,{type:`text`,value:e||``,onChange:e=>t(e.target.value),placeholder:a?.placeholder||`#000000`,disabled:r||i.disabled,className:i.className,pattern:`^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$`})]})}var Kt=o((()=>{})),qt=s({SliderField:()=>Jt});function Jt({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=a?.min??0,s=a?.max??100,c=a?.step??1;return r?(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`span`,{className:`text-sm font-medium`,children:e??o}),(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,s]})]}):(0,g.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,g.jsx)(p.Slider,{value:[e??o],onValueChange:e=>t(e[0]),min:o,max:s,step:c,disabled:r||i.disabled,className:i.className}),(0,g.jsx)(`span`,{className:`text-sm font-medium w-12 text-right`,children:e??o})]})}var Yt=o((()=>{})),Xt=s({RatingField:()=>Zt});function Zt({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=(n||a.schema)?.max??5,s=e??0,[c,l]=u.default.useState(null),d=c===null?s:c;return r?(0,g.jsxs)(`div`,{className:(0,p.cn)(`flex items-center gap-1`,i),children:[Array.from({length:o},(e,t)=>(0,g.jsx)(m.Star,{className:`w-5 h-5 ${t<s?`fill-yellow-400 text-yellow-400`:`text-muted-foreground`}`},t)),(0,g.jsxs)(`span`,{className:`ml-2 text-sm text-muted-foreground`,children:[s,` / `,o]})]}):(0,g.jsxs)(`div`,{className:(0,p.cn)(`flex items-center gap-1`,i),children:[Array.from({length:o},(e,n)=>(0,g.jsx)(`button`,{type:`button`,onClick:()=>t(n+1),onMouseEnter:()=>l(n+1),onMouseLeave:()=>l(null),className:`focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 rounded`,disabled:r||a.disabled,children:(0,g.jsx)(m.Star,{className:`w-5 h-5 transition-colors ${n<d?`fill-yellow-400 text-yellow-400 hover:fill-yellow-500 hover:text-yellow-500`:`text-muted-foreground hover:text-yellow-400`}`})},n)),(0,g.jsxs)(`span`,{className:`ml-2 text-sm text-muted-foreground`,children:[s,` / `,o]})]})}var Qt=o((()=>{})),$t=s({CodeField:()=>en});function en({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=a?.language??`javascript`;return r?(0,g.jsx)(`pre`,{className:(0,p.cn)(`text-sm bg-muted p-2 rounded overflow-x-auto border`,i.className),children:(0,g.jsx)(`code`,{children:e||(0,g.jsx)(p.EmptyValue,{})})}):(0,g.jsx)(p.Textarea,{value:e||``,onChange:e=>t(e.target.value),placeholder:a?.placeholder||`// Write ${o} code here...`,disabled:r||i.disabled,className:(0,p.cn)(`font-mono text-sm`,i.className),rows:12,spellCheck:!1})}var tn=o((()=>{})),nn=s({AvatarField:()=>rn});function rn({value:e,onChange:t,field:n,readonly:r,...i}){let[a,o]=u.default.useState(!1),s=u.default.useRef(null),c=n||i.schema,l=e=>{let n=e.target.files?.[0];if(!n)return;if(!n.type.startsWith(`image/`)){console.error(`Please select an image file`);return}if(n.size>5*1024*1024){console.error(`File size must be less than 5MB`);return}let r=new FileReader;r.onloadend=()=>{t(r.result)},r.readAsDataURL(n)},d=()=>{t(``)},f=()=>(c?.defaultName||c?.label||`User`).split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return r?(0,g.jsxs)(p.Avatar,{className:`w-16 h-16`,children:[e&&(0,g.jsx)(p.AvatarImage,{src:e,alt:c?.label}),(0,g.jsx)(p.AvatarFallback,{children:f()})]}):(0,g.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,g.jsxs)(`div`,{className:`relative`,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[(0,g.jsxs)(p.Avatar,{className:`w-16 h-16`,children:[e&&(0,g.jsx)(p.AvatarImage,{src:e,alt:c?.label}),(0,g.jsx)(p.AvatarFallback,{children:f()})]}),!r&&a&&e&&(0,g.jsx)(`button`,{type:`button`,onClick:d,className:`absolute -top-1 -right-1 bg-destructive text-destructive-foreground rounded-full p-1 hover:bg-destructive/90`,children:(0,g.jsx)(m.X,{className:`w-3 h-3`})})]}),(0,g.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,g.jsx)(`input`,{ref:s,type:`file`,accept:`image/*`,onChange:l,className:`hidden`}),(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s.current?.click(),disabled:r||i.disabled,children:[(0,g.jsx)(m.Upload,{className:`w-4 h-4 mr-2`}),e?`Change`:`Upload`,` Avatar`]}),(0,g.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`PNG, JPG up to 5MB`})]})]})}var an=o((()=>{})),on=s({AddressField:()=>sn});function sn({value:e,onChange:t,field:n,readonly:r,...i}){let a=e||{},o=(e,n)=>{t({...a,[e]:n})},s=e=>[e.street,e.city,[e.state,e.zipCode].filter(Boolean).join(` `),e.country].filter(Boolean).join(`, `);if(r){let e=s(a);return e?(0,g.jsx)(`span`,{className:`text-sm`,children:e}):(0,g.jsx)(p.EmptyValue,{})}return(0,g.jsxs)(`div`,{className:`space-y-3`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`street`,className:`text-xs`,children:`Street Address`}),(0,g.jsx)(p.Input,{id:`street`,type:`text`,value:a.street||``,onChange:e=>o(`street`,e.target.value),placeholder:`123 Main St`,disabled:r||i.disabled,className:i.className})]}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`city`,className:`text-xs`,children:`City`}),(0,g.jsx)(p.Input,{id:`city`,type:`text`,value:a.city||``,onChange:e=>o(`city`,e.target.value),placeholder:`San Francisco`,disabled:r||i.disabled})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`state`,className:`text-xs`,children:`State / Province`}),(0,g.jsx)(p.Input,{id:`state`,type:`text`,value:a.state||``,onChange:e=>o(`state`,e.target.value),placeholder:`CA`,disabled:r||i.disabled})]})]}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`zipCode`,className:`text-xs`,children:`ZIP / Postal Code`}),(0,g.jsx)(p.Input,{id:`zipCode`,type:`text`,value:a.zipCode||``,onChange:e=>o(`zipCode`,e.target.value),placeholder:`94102`,disabled:r||i.disabled})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`country`,className:`text-xs`,children:`Country`}),(0,g.jsx)(p.Input,{id:`country`,type:`text`,value:a.country||``,onChange:e=>o(`country`,e.target.value),placeholder:`United States`,disabled:r||i.disabled})]})]})]})}var cn=o((()=>{})),ln=s({GeolocationField:()=>un});function un({value:e,onChange:t,field:n,readonly:r,...i}){let[a,o]=u.default.useState(!1),s=e||{},c=(e,n)=>{t({...s,[e]:n?Number(n):void 0})},l=()=>{if(!navigator.geolocation){console.error(`Geolocation is not supported by this browser`);return}o(!0),navigator.geolocation.getCurrentPosition(e=>{t({latitude:e.coords.latitude,longitude:e.coords.longitude,accuracy:e.coords.accuracy}),o(!1)},e=>{console.error(`Error getting location:`,e.message),o(!1)},{enableHighAccuracy:!0,timeout:5e3,maximumAge:0})},d=e=>!e.latitude||!e.longitude?``:`${e.latitude.toFixed(6)}, ${e.longitude.toFixed(6)}`,f=()=>{if(!s.latitude||!s.longitude)return;let e=`https://www.google.com/maps?q=${s.latitude},${s.longitude}`;window.open(e,`_blank`)};if(r){let e=d(s);return(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(m.MapPin,{className:`w-4 h-4 text-muted-foreground`}),e?(0,g.jsx)(`span`,{className:`text-sm`,children:e}):(0,g.jsx)(p.EmptyValue,{}),s.latitude&&s.longitude&&(0,g.jsx)(p.Button,{type:`button`,variant:`link`,size:`sm`,onClick:f,className:`p-0 h-auto`,children:`View on map`})]})}return(0,g.jsxs)(`div`,{className:`space-y-3`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:l,disabled:r||a,children:[(0,g.jsx)(m.Crosshair,{className:`w-4 h-4 mr-2`}),a?`Getting location...`:`Use Current Location`]}),s.latitude&&s.longitude&&(0,g.jsxs)(p.Button,{type:`button`,variant:`link`,size:`sm`,onClick:f,children:[(0,g.jsx)(m.MapPin,{className:`w-4 h-4 mr-2`}),`View on map`]})]}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`latitude`,className:`text-xs`,children:`Latitude`}),(0,g.jsx)(p.Input,{id:`latitude`,type:`number`,value:s.latitude??``,onChange:e=>c(`latitude`,e.target.value),placeholder:`37.7749`,disabled:r||i.disabled,step:`any`,className:i.className})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`longitude`,className:`text-xs`,children:`Longitude`}),(0,g.jsx)(p.Input,{id:`longitude`,type:`number`,value:s.longitude??``,onChange:e=>c(`longitude`,e.target.value),placeholder:`-122.4194`,disabled:r||i.disabled,step:`any`})]})]}),s.accuracy&&(0,g.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Accuracy: ±`,s.accuracy.toFixed(0),`m`]})]})}var dn=o((()=>{})),fn=s({SignatureField:()=>pn});function pn({value:e,onChange:t,readonly:n}){let r=(0,u.useRef)(null),[i,a]=u.default.useState(!1),[o,s]=u.default.useState(!e);(0,u.useEffect)(()=>{if(e&&r.current){let t=r.current.getContext(`2d`);if(t){let n=new Image;n.onload=()=>{t.drawImage(n,0,0),s(!1)},n.src=e}}},[e]);let c=e=>{if(n)return;a(!0),s(!1);let t=r.current;if(!t)return;let i=t.getContext(`2d`);if(!i)return;let o=t.getBoundingClientRect(),c=`touches`in e?e.touches[0].clientX-o.left:e.clientX-o.left,l=`touches`in e?e.touches[0].clientY-o.top:e.clientY-o.top;i.beginPath(),i.moveTo(c,l)},l=e=>{if(!i||n)return;let t=r.current;if(!t)return;let a=t.getContext(`2d`);if(!a)return;let o=t.getBoundingClientRect(),s=`touches`in e?e.touches[0].clientX-o.left:e.clientX-o.left,c=`touches`in e?e.touches[0].clientY-o.top:e.clientY-o.top;a.lineTo(s,c),a.strokeStyle=`#000`,a.lineWidth=2,a.lineCap=`round`,a.lineJoin=`round`,a.stroke()},d=()=>{if(!i)return;a(!1);let e=r.current;e&&t(e.toDataURL(`image/png`))};return n&&e?(0,g.jsx)(`div`,{className:`border rounded p-2 bg-white`,children:(0,g.jsx)(`img`,{src:e,alt:`Signature`,loading:`lazy`,className:`max-w-full h-auto`})}):n&&!e?(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`No signature`}):(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(`div`,{className:`border rounded bg-white`,children:(0,g.jsx)(`canvas`,{ref:r,width:400,height:200,className:`w-full touch-none cursor-crosshair`,onMouseDown:c,onMouseMove:l,onMouseUp:d,onMouseLeave:d,onTouchStart:c,onTouchMove:l,onTouchEnd:d})}),(0,g.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,g.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o?`Sign above`:`Signature captured`}),(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{let e=r.current;if(!e)return;let n=e.getContext(`2d`);n&&(n.clearRect(0,0,e.width,e.height),s(!0),t(``))},disabled:n||o,children:[(0,g.jsx)(m.Eraser,{className:`w-4 h-4 mr-2`}),`Clear`]})]})]})}var mn=o((()=>{})),hn=s({QRCodeField:()=>gn});function gn({value:e,onChange:t,field:n,readonly:r,...i}){let[a,o]=u.default.useState(!1),s=n||i.schema;return r?(0,g.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,g.jsx)(`span`,{className:`text-sm flex-1 truncate`,children:e||(0,g.jsx)(p.EmptyValue,{})}),e&&(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>o(!a),children:[(0,g.jsx)(m.QrCode,{className:`w-4 h-4 mr-2`}),a?`Hide`:`Show`,` QR`]})]}):(0,g.jsxs)(`div`,{className:`space-y-3`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(p.Input,{type:`text`,value:e||``,onChange:e=>t(e.target.value),placeholder:s?.placeholder||`Enter text for QR code`,disabled:r||i.disabled,className:i.className}),e&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{e&&navigator.clipboard.writeText(e)},children:(0,g.jsx)(m.Copy,{className:`w-4 h-4`})}),(0,g.jsx)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>o(!a),children:(0,g.jsx)(m.QrCode,{className:`w-4 h-4`})})]})]}),a&&e&&(0,g.jsx)(`div`,{className:`border rounded p-4 bg-white flex justify-center`,children:(0,g.jsx)(`img`,{src:(e=>`https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(e)}`)(e),alt:`QR Code`,className:`w-48 h-48`})}),e&&(0,g.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`QR code contains: `,e.length,` characters`]})]})}var _n=o((()=>{}));C(),E(),k(),P(),L(),ne(),V(),U(),oe(),J(),X(),Ve(),We(),qe(),Xe(),$e(),ot(),lt(),ft(),ht(),vt(),xt(),wt(),Dt(),Ut(),Kt(),Yt(),Qt(),tn(),an(),cn(),dn(),mn(),_n(),nt();function vn({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=e||[],s=n||a.schema,c=()=>{let e={id:`new-${Date.now()}`,label:`New Related Record`};t([...o,e])},l=e=>{t(o.filter(t=>t.id!==e))},u=e=>{console.log(`View detail:`,e)};return r?(0,g.jsxs)(`div`,{className:(0,p.cn)(`space-y-2`,i),children:[o.length===0?(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`No related records`}):o.map(e=>(0,g.jsxs)(`div`,{className:`flex items-center justify-between p-2 border rounded hover:bg-muted/50`,children:[(0,g.jsx)(`span`,{className:`text-sm`,children:e.label}),(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>u(e),children:(0,g.jsx)(m.ExternalLink,{className:`w-4 h-4`})})]},e.id)),(0,g.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[o.length,` `,o.length===1?`record`:`records`]})]}):(0,g.jsxs)(`div`,{className:(0,p.cn)(`space-y-3`,i),children:[(0,g.jsxs)(`div`,{className:`space-y-2`,children:[o.map(e=>(0,g.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-2 border rounded hover:bg-muted/50`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,g.jsx)(p.Badge,{variant:`outline`,children:e.id}),(0,g.jsx)(`span`,{className:`text-sm flex-1`,children:e.label})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>u(e),children:(0,g.jsx)(m.ExternalLink,{className:`w-4 h-4`})}),(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>l(e.id),disabled:a.disabled,children:(0,g.jsx)(m.X,{className:`w-4 h-4`})})]})]},e.id)),o.length===0&&(0,g.jsx)(`div`,{className:`text-sm text-muted-foreground text-center py-4 border border-dashed rounded bg-muted/20`,children:`No related records`})]}),(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,className:`w-full`,onClick:c,disabled:a.disabled,children:[(0,g.jsx)(m.Plus,{className:`w-4 h-4 mr-2`}),`Add `,s?.label||`Record`]})]})}var yn=s({MultiSelectField:()=>bn});function bn({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=(n||a.schema)?.options||[],s=Array.isArray(e)?e:e==null?[]:[e];if(r)return s.length===0?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>(0,g.jsx)(p.Badge,{variant:`outline`,children:o.find(t=>t.value===e)?.label||e},e))});let c=e=>{t(s.includes(e)?s.filter(t=>t!==e):[...s,e])};return(0,g.jsx)(`div`,{className:(0,p.cn)(`flex flex-wrap gap-1.5`,i),children:o.map(e=>{let t=s.includes(e.value);return(0,g.jsx)(`button`,{type:`button`,onClick:()=>c(e.value),disabled:a.disabled,"aria-pressed":t,className:(0,p.cn)(`rounded-full border px-3 py-1 text-sm transition-colors`,t?`border-primary bg-primary text-primary-foreground`:`border-input bg-background text-foreground hover:bg-accent`),children:e.label},e.value)})})}var xn=o((()=>{})),Sn=s({RadioField:()=>Cn});function Cn({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=(n||a.schema)?.options||[],s=(0,u.useId)();return r?e==null||e===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`text-sm`,children:o.find(t=>t.value===e)?.label||String(e)}):(0,g.jsx)(p.RadioGroup,{value:e??``,onValueChange:t,disabled:a.disabled,className:i,children:o.map(e=>{let t=`${s}-${e.value}`;return(0,g.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,g.jsx)(p.RadioGroupItem,{value:e.value,id:t}),(0,g.jsx)(p.Label,{htmlFor:t,className:`font-normal`,children:e.label})]},e.value)})})}var wn=o((()=>{})),Tn=s({CheckboxesField:()=>En});function En({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=(n||a.schema)?.options||[],s=Array.isArray(e)?e:e==null?[]:[e],c=(0,u.useId)();if(r)return s.length===0?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>(0,g.jsx)(p.Badge,{variant:`outline`,children:o.find(t=>t.value===e)?.label||e},e))});let l=(e,n)=>{t(n?[...s.filter(t=>t!==e),e]:s.filter(t=>t!==e))};return(0,g.jsx)(`div`,{className:i,children:o.map(e=>{let t=`${c}-${e.value}`;return(0,g.jsxs)(`div`,{className:`flex items-center space-x-2 py-0.5`,children:[(0,g.jsx)(p.Checkbox,{id:t,checked:s.includes(e.value),onCheckedChange:t=>l(e.value,!!t),disabled:a.disabled}),(0,g.jsx)(p.Label,{htmlFor:t,className:`font-normal`,children:e.label})]},e.value)})})}var Dn=o((()=>{})),On=s({TagsField:()=>kn});function kn({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=Array.isArray(e)?e:e==null?[]:[e],[s,c]=u.default.useState(``);if(r)return o.length===0?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>(0,g.jsx)(p.Badge,{variant:`secondary`,children:e},e))});let l=e=>{let n=e.trim();!n||o.includes(n)||(t([...o,n]),c(``))},d=e=>t(o.filter(t=>t!==e));return(0,g.jsxs)(`div`,{className:(0,p.cn)(`flex flex-wrap items-center gap-1.5 rounded-md border border-input bg-background p-1.5`,i),children:[o.map(e=>(0,g.jsxs)(p.Badge,{variant:`secondary`,className:`gap-1`,children:[e,(0,g.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`ml-0.5 rounded-full text-muted-foreground hover:text-foreground`,"aria-label":`Remove ${e}`,children:`×`})]},e)),(0,g.jsx)(p.Input,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),l(s)):e.key===`Backspace`&&s===``&&o.length>0&&d(o[o.length-1])},onBlur:()=>l(s),disabled:a.disabled,placeholder:o.length===0?`输入后回车添加…`:``,className:`h-7 flex-1 border-0 bg-transparent p-0 px-1 shadow-none focus-visible:ring-0 min-w-[8ch]`})]})}var An=o((()=>{})),jn=s({default:()=>Mn});function Mn({value:e}){return(0,g.jsx)(`div`,{className:`prose prose-sm max-w-none dark:prose-invert break-words`,children:(0,g.jsx)(v.default,{remarkPlugins:[y.default],rehypePlugins:[b.default],children:e})})}var Nn=o((()=>{}));Re(),ie(),Ae(),C(),E(),k(),P(),L(),Ve(),We(),ne(),V(),U(),oe(),qe(),Xe(),J(),X(),Re(),Z(),$e(),ot(),lt(),ft(),ht(),vt(),xt(),wt(),Dt(),Ut(),Kt(),Yt(),Qt(),tn(),an(),cn(),dn(),mn(),_n(),xn(),wn(),Dn(),An();var Pn=new Map;function Fn(e,t){if(!e||typeof e!=`object`)return;if(t){let n=e[t];if(typeof n==`string`&&n.trim())return n.trim();if(typeof n==`number`)return String(n)}for(let t of[`name`,`full_name`,`display_name`,`label`,`title`,`subject`,`username`]){let n=e[t];if(typeof n==`string`&&n.trim())return n.trim();if(typeof n==`number`)return String(n)}let n=e.first_name,r=e.last_name,i=[e.salutation,n,r].filter(e=>typeof e==`string`&&e.trim()).map(e=>e.trim()).join(` `);if(i)return i;let a=e.email;if(typeof a==`string`&&a.trim())return a.trim();let o=new Set([`id`,`_id`,`organization_id`,`created_by`,`updated_by`,`created_at`,`updated_at`,`tenant_id`]),s=[`_name`,`_title`,`_number`,`_code`,`_label`];for(let[t,n]of Object.entries(e))if(!o.has(t)&&!t.endsWith(`_id`)&&s.some(e=>t.endsWith(e))){if(typeof n==`string`&&n.trim())return n.trim();if(typeof n==`number`)return String(n)}}function In(e){if(typeof e!=`string`||!/^[A-Za-z0-9_-]{12,32}$/.test(e))return!1;let t=/[A-Z]/.test(e),n=/[a-z]/.test(e),r=/[0-9_-]/.test(e);return t&&n||t&&r||n&&r}function Ln(e,t){let n=u.default.useContext(h.SchemaRendererContext)?.dataSource,[,r]=u.default.useState(0),i=!!e&&!!n&&typeof n.find==`function`&&(typeof t==`string`||typeof t==`number`)&&t!==``,a=i?`${e}:${String(t)}`:``;if(u.default.useEffect(()=>{if(!i)return;let o=Pn.get(a);if(o&&o.state!==`pending`&&o.promise==null||o?.state===`pending`)return;let s=(async()=>{try{let r;if(typeof n.findOne==`function`)r=await n.findOne(e,t);else{let i=await n.find(e,{$filter:{id:t},options:{$top:1}});r=(Array.isArray(i)?i:i?.value||i?.data||[])[0]}let i=Fn(r);Pn.set(a,{state:`ok`,name:i})}catch{Pn.set(a,{state:`err`})}r(e=>e+1)})();Pn.set(a,{state:`pending`,promise:s})},[a,i,e,t,n]),!i)return;let o=Pn.get(a);return o?.state===`ok`?o.name:void 0}function Rn(){try{let{t:e}=(0,h.useObjectTranslation)();return(t,n)=>{let r=e(t);return!r||r===t?n:r}}catch{return(e,t)=>t}}function Q(e){if(e==null||typeof e==`number`||typeof e==`boolean`)return e;if(typeof e==`string`){let t=e.trim();if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return Q(JSON.parse(t))}catch{}return e}if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(e=>{if(typeof e==`object`&&e){let t=e;return String(t.name||t.label||t.externalId||t.id||t._id||`[Object]`)}return String(e)}).join(`, `);if(typeof e==`object`){let t=e;return`$numberDecimal`in t?Number(t.$numberDecimal):`$oid`in t?String(t.$oid):`$date`in t?String(t.$date):String(t.name||t.label||t.externalId||t.id||t._id||`[Object]`)}return String(e)}function zn(e,t){let n=Number.isFinite(e)&&e===Math.trunc(e)?0:2;if(!t)return Vn(e,n);try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,minimumFractionDigits:0,maximumFractionDigits:n}).format(e)}catch{return`${t} ${e.toFixed(n)}`}}function Bn(e,t){if(!t)try{return new Intl.NumberFormat(`en-US`,{notation:`compact`,maximumFractionDigits:1}).format(e).replace(/\.0(?=[KMBT])/,``)}catch{return String(e)}try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,notation:`compact`,maximumFractionDigits:1}).format(e).replace(/\.0(?=[KMBT])/,``)}catch{return`${t} ${e}`}}function Vn(e,t=2){try{return new Intl.NumberFormat(`en-US`,{minimumFractionDigits:t,maximumFractionDigits:t}).format(e)}catch{return e.toFixed(t)}}function Hn(e,t=0){return`${(0,d.percentDisplayValue)(e).toFixed(t)}%`}function Un(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Wn(e){if(e==null||e===``)return`—`;let t=e instanceof Date?e:new Date(e);if(!(t instanceof Date)||isNaN(t.getTime()))return`—`;let n=new Date,r=new Date(n.getFullYear(),n.getMonth(),n.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()-r.getTime(),a=Math.round(i/(1e3*60*60*24));if(a===0)return`Today`;if(a===1)return`Tomorrow`;if(a===-1)return`Yesterday`;if(a<-1){let e=Math.abs(a);return e<=7?`Overdue ${e}d`:Gn(t)}return a>1&&a<=7?`In ${a} days`:Gn(t)}function Gn(e,t){if(e==null||e===``)return`—`;let n=e instanceof Date?e:new Date(e);if(!(n instanceof Date)||isNaN(n.getTime()))return`—`;if(t===`short`)return`${n.toLocaleDateString(`en-US`,{month:`short`})} ${n.getDate()}, '${String(n.getFullYear()).slice(-2)}`;if(t===`relative`)return Wn(n);let r=n.getFullYear()===new Date().getFullYear();return n.toLocaleDateString(void 0,{year:r?void 0:`numeric`,month:`short`,day:`numeric`})}function Kn(e){if(e==null||e===``)return`—`;let t=e instanceof Date?e:new Date(e);return!(t instanceof Date)||isNaN(t.getTime())?`—`:t.toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function qn({value:e}){let t=Q(e);return t==null||t===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`truncate`,children:String(t)})}function Jn({value:e,field:t}){if(e==null)return(0,g.jsx)(p.EmptyValue,{});let n=Q(e),r=t.precision??0,i=Number(n);return(0,g.jsx)(`span`,{className:`tabular-nums`,children:isNaN(i)?String(n):new Intl.NumberFormat(`en-US`,{minimumFractionDigits:r,maximumFractionDigits:r}).format(i)})}function Yn({value:e,field:t}){if(e==null)return(0,g.jsx)(p.EmptyValue,{});let n=Q(e),{currency:r}=(0,f.useLocalization)(),i=(0,f.resolveFieldCurrency)(t,r),a=Number(n);return(0,g.jsx)(`span`,{className:`tabular-nums font-medium whitespace-nowrap`,children:isNaN(a)?String(n):zn(a,i)})}var Xn=/progress|completion/;function Zn({value:e,field:t}){if(e==null)return(0,g.jsx)(p.EmptyValue,{});let n=Q(e),r=t.precision??0,i=Number(n);if(isNaN(i))return(0,g.jsx)(`span`,{className:`tabular-nums whitespace-nowrap`,children:String(n)});let a=Xn.test(t?.name?.toLowerCase()||``),o=a?i:i>-1&&i<1?i*100:i,s=a?`${i.toFixed(r)}%`:Hn(i,r),c=Math.max(0,Math.min(100,o));return(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`div`,{className:`h-1.5 w-16 rounded-full bg-muted ring-1 ring-inset ring-border/60 overflow-hidden shrink-0`,role:`progressbar`,"aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100,children:(0,g.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-all`,style:{width:`${c}%`}})}),(0,g.jsx)(`span`,{className:`tabular-nums whitespace-nowrap`,children:s})]})}var Qn=new Set([`active`,`is_active`,`enabled`,`is_enabled`,`verified`,`is_verified`]);function $n({value:e,field:t}){if(e==null)return(0,g.jsx)(`span`,{className:`flex items-center justify-center`,children:(0,g.jsx)(p.EmptyValue,{})});let n=t?.name?.toLowerCase()||``;return n===`completed`||n===`is_completed`||n===`done`||n===`is_done`?(0,g.jsx)(`div`,{className:`flex items-center justify-center`,children:e?(0,g.jsx)(`div`,{className:`size-5 rounded-full bg-green-500 flex items-center justify-center`,role:`img`,"aria-label":`Completed`,"data-testid":`completion-indicator`,children:(0,g.jsx)(m.Check,{className:`size-3 text-white`})}):(0,g.jsx)(`div`,{className:`size-5 rounded-full border-2 border-muted-foreground/30`,role:`img`,"aria-label":`Not completed`,"data-testid":`completion-indicator`})}):Qn.has(n)&&!e?(0,g.jsxs)(p.Badge,{variant:`destructive`,className:`text-xs`,"data-testid":`boolean-warning-badge`,children:[t?.label||Un(n),` — Off`]}):(0,g.jsx)(`div`,{className:`flex items-center justify-start`,children:(0,g.jsx)(p.Checkbox,{checked:!!e,disabled:!0,className:`pointer-events-none`})})}function er({value:e,field:t}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let n=Q(e),r=t,i=Gn(n,r.format||`relative`),a=n==null?null:new Date(n),o=a!==null&&!isNaN(a.getTime()),s=new Date;s.setHours(0,0,0,0);let c=String(r?.name||r?.accessorKey||r?.key||``).toLowerCase(),l=(r?.dueLike===!0||/(^|_)(due|deadline|expires?|expiry|expiration|expected_close|target_close|sla|return_by|renewal|next_action)(_|$)/.test(c))&&o&&a<s,u=o?a.toISOString():String(n);return(0,g.jsx)(`span`,{className:`tabular-nums${l?` text-red-600`:``}`,title:u,children:i})}function tr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=Q(e),n=t==null?null:new Date(t);if(n===null||isNaN(n.getTime()))return(0,g.jsx)(p.EmptyValue,{});let r=n.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`,year:`numeric`}),i=n.toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`,hour12:!0}).toLowerCase();return(0,g.jsxs)(`span`,{className:`tabular-nums text-sm whitespace-nowrap`,children:[(0,g.jsx)(`span`,{children:r}),(0,g.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:i})]})}var nr={critical:`red`,urgent:`red`,high:`orange`,medium:`yellow`,normal:`blue`,low:`gray`,none:`gray`,paid:`green`,completed:`green`,done:`green`,active:`green`,approved:`green`,resolved:`green`,pending:`yellow`,waiting:`yellow`,on_hold:`yellow`,shipped:`blue`,in_progress:`blue`,open:`blue`,processing:`blue`,draft:`gray`,new:`gray`,inactive:`gray`,closed:`gray`,cancelled:`red`,canceled:`red`,rejected:`red`,failed:`red`,overdue:`red`,delivered:`purple`,archived:`indigo`,contacted:`blue`,qualified:`purple`,converted:`green`,won:`green`,lost:`red`,紧急:`red`,严重:`red`,高:`orange`,中:`yellow`,普通:`blue`,低:`gray`,无:`gray`,新建:`gray`,草稿:`gray`,待处理:`yellow`,待审核:`yellow`,待联系:`yellow`,挂起:`yellow`,进行中:`blue`,处理中:`blue`,已联系:`blue`,跟进中:`blue`,已发货:`blue`,打开:`blue`,已确认:`green`,已审核:`green`,已通过:`green`,已完成:`green`,已支付:`green`,已签收:`green`,已转化:`green`,成单:`green`,赢得:`green`,已签约:`green`,已交付:`purple`,已归档:`indigo`,已关闭:`gray`,已取消:`red`,已拒绝:`red`,失败:`red`,逾期:`red`,流失:`red`,丢失:`red`},rr={gray:`bg-gray-50 text-gray-700 border-gray-200 dark:bg-gray-800/50 dark:text-gray-200 dark:border-gray-700/60`,red:`bg-red-50 text-red-700 border-red-200 dark:bg-red-950/40 dark:text-red-300 dark:border-red-900/60`,orange:`bg-orange-50 text-orange-700 border-orange-200 dark:bg-orange-950/40 dark:text-orange-300 dark:border-orange-900/60`,yellow:`bg-yellow-50 text-yellow-800 border-yellow-200 dark:bg-yellow-950/40 dark:text-yellow-300 dark:border-yellow-900/60`,green:`bg-green-50 text-green-700 border-green-200 dark:bg-green-950/40 dark:text-green-300 dark:border-green-900/60`,blue:`bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-950/40 dark:text-blue-300 dark:border-blue-900/60`,indigo:`bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-950/40 dark:text-indigo-300 dark:border-indigo-900/60`,purple:`bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-950/40 dark:text-purple-300 dark:border-purple-900/60`,pink:`bg-pink-50 text-pink-700 border-pink-200 dark:bg-pink-950/40 dark:text-pink-300 dark:border-pink-900/60`},ir={gray:`bg-gray-400 dark:bg-gray-500`,red:`bg-red-500`,orange:`bg-orange-500`,yellow:`bg-yellow-500`,green:`bg-green-500`,blue:`bg-blue-500`,indigo:`bg-indigo-500`,purple:`bg-purple-500`,pink:`bg-pink-500`},ar=[`blue`,`green`,`purple`,`orange`,`pink`,`indigo`,`yellow`,`red`];function or(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return ar[Math.abs(t)%ar.length]}function sr(e){let t=/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.exec(e.trim());if(!t)return;let n=t[1];n.length===3&&(n=n.split(``).map(e=>e+e).join(``));let r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=Math.max(r,i,a),s=Math.min(r,i,a),c=o-s,l=(o+s)/2;if((c===0?0:c/(1-Math.abs(2*l-1)))<.22)return`gray`;let u;return u=o===r?((i-a)/c%6+6)%6:o===i?(a-r)/c+2:(r-i)/c+4,u*=60,u>=345||u<15?`red`:u<30?`orange`:u<60?`yellow`:u<170?`green`:u<238?`blue`:u<250?`indigo`:u<295?`purple`:`pink`}function cr(e){if(e){if(rr[e])return e;if(e.charAt(0)===`#`)return sr(e)}}function lr(e,t){let n=cr(e);if(n&&rr[n])return rr[n];if(t==null||t===``)return`bg-muted text-muted-foreground border-border`;let r=String(t).toLowerCase().replace(/[\s-]/g,`_`),i=nr[r];return i&&rr[i]?rr[i]:rr[or(r)]}function ur(e,t){let n=cr(e);if(n&&rr[n])return n;if(t==null||t===``)return;let r=String(t).toLowerCase().replace(/[\s-]/g,`_`);return nr[r]||or(r)}var dr={gray:`#6b7280`,red:`#ef4444`,orange:`#f97316`,yellow:`#eab308`,green:`#22c55e`,blue:`#3b82f6`,indigo:`#6366f1`,purple:`#a855f7`,pink:`#ec4899`};function fr(e,t=`#3b82f6`){return e?dr[e]??t:t}function pr({value:e,field:t}){let n=t,r=n.options||[],i=n.appearance===`dot`?`dot`:`badge`;if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});let a=e=>{let t=r.find(t=>t.value===e);if(t)return t;let n=String(e).toLowerCase();return r.find(e=>String(e.value).toLowerCase()===n)},o=(e,t)=>{let n=a(e),r=n?.label||Un(String(e));return i===`dot`?(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,g.jsx)(`span`,{className:(0,p.cn)(`h-1.5 w-1.5 rounded-full shrink-0`,ir[cr(n?.color)||nr[String(e).toLowerCase().replace(/[\s-]/g,`_`)]||or(String(e).toLowerCase().replace(/[\s-]/g,`_`))]||ir.gray),"aria-hidden":`true`}),(0,g.jsx)(`span`,{className:`truncate`,children:r})]},t):(0,g.jsx)(p.Badge,{variant:`outline`,className:lr(n?.color,e),children:r},t)};return Array.isArray(e)?(0,g.jsx)(`div`,{className:(0,p.cn)(`flex flex-wrap`,i===`dot`?`gap-x-3 gap-y-1`:`gap-1`),children:e.map((e,t)=>o(e,t))}):o(e)}function mr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=Rn(),n=String(Q(e)??``),[r,i]=u.default.useState(!1);return(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1 group/email`,children:[(0,g.jsx)(p.Button,{variant:`link`,className:`p-0 h-auto font-normal text-blue-600 hover:text-blue-800`,asChild:!0,children:(0,g.jsx)(`a`,{href:`mailto:${n}`,onClick:e=>e.stopPropagation(),children:n})}),(0,g.jsx)(`button`,{type:`button`,className:`opacity-0 group-hover/email:opacity-100 transition-opacity p-0.5 rounded hover:bg-muted`,onClick:e=>{e.stopPropagation(),e.preventDefault(),navigator.clipboard.writeText(n).then(()=>{i(!0),setTimeout(()=>i(!1),2e3)}).catch(()=>{})},"aria-label":t(`detail.copyEmail`,`Copy email`),children:r?(0,g.jsx)(m.Check,{className:`h-3 w-3 text-green-600`}):(0,g.jsx)(m.Copy,{className:`h-3 w-3 text-muted-foreground`})})]})}function hr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=String(Q(e)??``);return(0,g.jsx)(p.Button,{variant:`link`,className:`p-0 h-auto font-normal text-blue-600 hover:text-blue-800`,asChild:!0,children:(0,g.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:t})})}function gr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=Rn(),n=String(Q(e)??``),[r,i]=u.default.useState(!1);return(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1 group/phone`,children:[(0,g.jsxs)(`a`,{href:`tel:${n}`,className:`inline-flex items-center gap-1 text-blue-600 hover:text-blue-800`,onClick:e=>e.stopPropagation(),children:[(0,g.jsx)(m.Phone,{className:`h-3 w-3`}),n]}),(0,g.jsx)(`button`,{type:`button`,className:`opacity-0 group-hover/phone:opacity-100 transition-opacity p-0.5 rounded hover:bg-muted`,onClick:e=>{e.stopPropagation(),e.preventDefault(),navigator.clipboard.writeText(n).then(()=>{i(!0),setTimeout(()=>i(!1),2e3)}).catch(()=>{})},"aria-label":t(`detail.copyPhone`,`Copy phone number`),children:r?(0,g.jsx)(m.Check,{className:`h-3 w-3 text-green-600`}):(0,g.jsx)(m.Copy,{className:`h-3 w-3 text-muted-foreground`})})]})}function _r({value:e,field:t}){if(!e)return(0,g.jsx)(p.EmptyValue,{});if(t.multiple,Array.isArray(e)){let t=e.length;return(0,g.jsxs)(`span`,{className:`text-sm text-gray-600`,children:[t,` `,t===1?`file`:`files`]})}return(0,g.jsx)(`span`,{className:`text-sm truncate`,children:e.name||e.original_name||`File`})}function vr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=e=>typeof e==`string`?e:e?.url||e?.src||e?.href||e?.thumbnailUrl||``,n=(e,t)=>e&&typeof e==`object`&&(e.name||e.original_name)||t;if(Array.isArray(e)){let r=e.map(e=>({url:t(e),name:n(e,`Image`)})).filter(e=>e.url);return r.length===0?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsxs)(`div`,{className:`flex -space-x-2`,children:[r.slice(0,3).map((e,t)=>(0,g.jsx)(`img`,{src:e.url,alt:e.name||`Image ${t+1}`,className:`size-8 rounded-md border-2 border-white object-cover`},t)),r.length>3&&(0,g.jsxs)(`div`,{className:`size-8 rounded-md border-2 border-white bg-gray-100 flex items-center justify-center text-xs font-medium text-gray-600`,children:[`+`,r.length-3]})]})}let r=t(e);return r?(0,g.jsx)(`img`,{src:r,alt:n(e,`Image`),className:`size-10 rounded-md object-cover`}):(0,g.jsx)(p.EmptyValue,{})}function yr({value:e,field:t}){let n=t.reference_to,r=(()=>{if(Array.isArray(e))return e.find(e=>e!=null&&(typeof e==`string`||typeof e==`number`)&&e!==``);if(e!=null&&e!==``&&(typeof e==`string`||typeof e==`number`)&&typeof e!=`object`)return e})(),i=Ln(n,r);if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});if(typeof e==`string`){let t=e.trim();if(t.startsWith(`{`)&&t.endsWith(`}`))try{let e=JSON.parse(t);if(e&&typeof e==`object`){let t=Fn(e)||String(e.externalId??e.id??e._id??``);if(t)return(0,g.jsx)(`span`,{className:`truncate`,children:t})}}catch{}}if(!Array.isArray(e)&&typeof e==`object`){let t=e,n=Fn(t)||String(t.id||t._id||``);if(n)return(0,g.jsx)(`span`,{className:`truncate`,children:n})}let a=t.options||[],o=e=>{if(a.length>0){let t=a.find(t=>String(t.value)===String(e));if(t)return{text:t.label,muted:!1}}return e===r&&i?{text:i,muted:!1}:In(e)?{text:`—`,muted:!0}:{text:String(e),muted:!1}};if(Array.isArray(e))return(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>{let n,r=!1;if(typeof e==`object`&&e)n=Fn(e)||String(e.id||e._id||`[Object]`);else{let t=o(e);n=t.text,r=t.muted}return(0,g.jsx)(`span`,{className:(0,p.cn)(`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium`,r?`bg-muted/40 text-muted-foreground`:`bg-gray-50 text-gray-700 dark:bg-gray-800/50 dark:text-gray-200`),children:n},t)})});if(typeof e==`object`&&e)return(0,g.jsx)(`span`,{className:`truncate`,children:Fn(e)||String(e.id||e._id||`[Object]`)});let{text:s,muted:c}=o(e);return(0,g.jsx)(`span`,{className:(0,p.cn)(`truncate`,c&&`text-muted-foreground`),children:s})}function br({value:e}){let t=Q(e);return t==null||t===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`text-gray-700 font-mono text-sm`,children:String(t)})}function xr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});if(typeof e!=`object`)return(0,g.jsx)(`span`,{className:`truncate`,children:String(e)});if(Array.isArray(e))return(0,g.jsxs)(`div`,{className:`flex -space-x-2`,children:[e.slice(0,3).map((e,t)=>{if(typeof e!=`object`||!e)return(0,g.jsx)(`span`,{className:`truncate text-sm`,children:String(e)},t);let n=e.name||e.username||`User`;return(0,g.jsx)(p.Avatar,{className:`size-8 border-2 border-white`,title:n,children:(0,g.jsx)(p.AvatarFallback,{className:`bg-blue-500 text-white text-xs`,children:n.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)})},t)}),e.length>3&&(0,g.jsx)(p.Avatar,{className:`size-8 border-2 border-white`,children:(0,g.jsxs)(p.AvatarFallback,{className:`bg-gray-200 text-gray-600 text-xs`,children:[`+`,e.length-3]})})]});let t=e.name||e.username||`User`;return(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(p.Avatar,{className:`size-8`,children:(0,g.jsx)(p.AvatarFallback,{className:`bg-blue-500 text-white text-xs`,children:t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)})}),(0,g.jsx)(`span`,{className:`truncate`,children:t})]})}var Sr=new Map;function Cr(e,t){Sr.set(e,t)}var wr={phone:`phone`,tel:`phone`,telephone:`phone`,email:`email`,url:`url`,uri:`url`,link:`url`,currency:`currency`,money:`currency`,percent:`percent`,percentage:`percent`},Tr=new Set([`text`,`textarea`,`string`,`longtext`,``]);function Er(e){if(!e)return`text`;if(typeof e==`string`)return e;let t=(e.type||``).toLowerCase(),n=e.format,r=typeof n==`string`?n.toLowerCase():``;return r&&wr[r]&&Tr.has(t)?wr[r]:e.type||`text`}function Dr({value:e}){if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});let t;if(typeof e==`object`)try{t=JSON.stringify(e)}catch{t=String(e)}else t=String(e);return(0,g.jsx)(`span`,{className:`font-mono text-xs text-gray-600 truncate`,title:t,children:t})}function Or({value:e}){if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});let t=String(e);return(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,g.jsx)(`span`,{className:`h-3.5 w-3.5 rounded border border-black/10 shrink-0`,style:{backgroundColor:t},"aria-hidden":`true`}),(0,g.jsx)(`span`,{className:`font-mono text-xs`,children:t})]})}var kr=u.default.lazy(()=>Promise.resolve().then(()=>(Nn(),jn)));function Ar({value:e}){return e==null||e===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(u.default.Suspense,{fallback:(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:String(e).slice(0,80)}),children:(0,g.jsx)(kr,{value:String(e)})})}function jr(e){return e.replace(/<\s*(script|style|iframe|object|embed)[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi,``).replace(/\son\w+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi,``).replace(/(href|src)\s*=\s*("javascript:[^"]*"|'javascript:[^']*')/gi,`$1="#"`)}function Mr({value:e}){return e==null||e===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`div`,{className:`prose prose-sm max-w-none dark:prose-invert break-words`,dangerouslySetInnerHTML:{__html:jr(String(e))}})}function Nr({value:e}){if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});let t,n;if(typeof e==`object`&&!Array.isArray(e)){let r=e;t=typeof r.lat==`number`?r.lat:typeof r.latitude==`number`?r.latitude:void 0,n=typeof r.lng==`number`?r.lng:typeof r.lon==`number`?r.lon:typeof r.longitude==`number`?r.longitude:void 0}else if(Array.isArray(e)&&e.length===2)t=Number(e[0]),n=Number(e[1]);else if(typeof e==`string`){let r=e.split(`,`).map(e=>parseFloat(e.trim()));r.length===2&&!isNaN(r[0])&&!isNaN(r[1])&&([t,n]=r)}return typeof t==`number`&&typeof n==`number`&&!isNaN(t)&&!isNaN(n)?(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-sm tabular-nums`,children:[(0,g.jsx)(m.MapPin,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),t.toFixed(4),`, `,n.toFixed(4)]}):(0,g.jsx)(Dr,{value:e,field:{}})}function Pr(e){return Sr.has(e)?Sr.get(e):{text:qn,textarea:qn,markdown:Ar,html:Mr,richtext:Ar,code:qn,qrcode:qn,number:Jn,currency:Yn,percent:Zn,progress:Zn,slider:Jn,rating:Jn,boolean:$n,toggle:$n,date:er,datetime:tr,time:qn,select:pr,status:pr,multiselect:pr,radio:pr,checkboxes:pr,tags:pr,lookup:yr,master_detail:yr,tree:yr,email:mr,url:hr,phone:gr,file:_r,video:_r,audio:_r,image:vr,avatar:vr,signature:vr,formula:br,summary:br,auto_number:qn,user:xr,owner:xr,password:()=>(0,g.jsx)(`span`,{children:`••••••`}),secret:()=>(0,g.jsx)(`span`,{children:`••••••`}),location:Nr,geolocation:Nr,address:Dr,color:Or,json:Dr,object:Dr,composite:Dr,record:Dr,repeater:({value:e})=>{let t=Array.isArray(e)?e.length:0;return t>0?(0,g.jsxs)(`span`,{className:`text-gray-500 italic`,children:[t,` 项`]}):(0,g.jsx)(p.EmptyValue,{})},vector:()=>(0,g.jsx)(`span`,{className:`text-gray-500 italic`,children:`[Vector]`}),grid:()=>(0,g.jsx)(`span`,{className:`text-gray-500 italic`,children:`[Grid]`})}[e]||qn}Cr(`lookup`,yr),Cr(`master_detail`,yr),Cr(`select`,pr),Cr(`status`,pr),Cr(`user`,xr),Cr(`owner`,xr),De(Pr);function Fr(e){return{text:`field:text`,textarea:`field:textarea`,markdown:`field:markdown`,html:`field:html`,richtext:`field:richtext`,secret:`field:password`,number:`field:number`,currency:`field:currency`,percent:`field:percent`,slider:`field:slider`,progress:`field:slider`,rating:`field:rating`,date:`field:date`,datetime:`field:datetime`,time:`field:time`,boolean:`field:boolean`,toggle:`field:boolean`,select:`field:select`,multiselect:`field:multiselect`,radio:`field:radio`,checkboxes:`field:checkboxes`,tags:`field:tags`,lookup:`field:lookup`,master_detail:`field:master_detail`,tree:`field:lookup`,email:`field:email`,phone:`field:phone`,url:`field:url`,file:`field:file`,image:`field:image`,avatar:`field:avatar`,video:`field:file`,audio:`field:file`,signature:`field:signature`,password:`field:password`,location:`field:location`,geolocation:`field:geolocation`,address:`field:address`,color:`field:color`,code:`field:code`,json:`field:code`,qrcode:`field:qrcode`,vector:`field:vector`,object:`field:object`,composite:`field:object`,record:`field:object`,repeater:`field:grid`,formula:`field:formula`,summary:`field:summary`,auto_number:`field:auto_number`}[e]||`field:text`}function Ir(e){if(e<0||!Number.isFinite(e)||e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n.toFixed(+(r>0))} ${t[r]}`}function Lr(e){let t={};return e.required&&(t.required=typeof e.required_message==`string`?e.required_message:`${e.label||e.name} is required`),e.min_length&&(t.minLength={value:e.min_length,message:e.min_length_message||`Minimum length is ${e.min_length} characters`}),e.max_length&&(t.maxLength={value:e.max_length,message:e.max_length_message||`Maximum length is ${e.max_length} characters`}),e.min!==void 0&&(t.min={value:e.min,message:e.min_message||`Minimum value is ${e.min}`}),e.max!==void 0&&(t.max={value:e.max,message:e.max_message||`Maximum value is ${e.max}`}),e.pattern&&(t.pattern={value:typeof e.pattern==`string`?new RegExp(e.pattern):e.pattern,message:e.pattern_message||`Invalid format`}),e.type===`email`&&(t.pattern={value:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,message:`Please enter a valid email address`}),e.type===`url`&&(t.pattern={value:/^https?:\/\/.+/,message:`Please enter a valid URL`}),e.validate&&(t.validate=e.validate),Object.keys(t).length>0?t:void 0}function Rr(e,t){if(!e)return!0;if(e.field&&e.value!==void 0){let n=t[e.field];if(e.operator===`=`||e.operator===`==`)return n===e.value;if(e.operator===`!=`)return n!==e.value;if(e.operator===`>`)return n>e.value;if(e.operator===`>=`)return n>=e.value;if(e.operator===`<`)return n<e.value;if(e.operator===`<=`)return n<=e.value;if(e.operator===`in`)return Array.isArray(e.value)&&e.value.includes(n)}return e.and&&Array.isArray(e.and)?e.and.every(e=>Rr(e,t)):e.or&&Array.isArray(e.or)?e.or.some(e=>Rr(e,t)):!0}function $(e){let t=({schema:t,className:n,value:r,...i})=>{let[a,o]=u.default.useState(r??t?.value??``),s={name:t?.name||`field`,label:t?.label,type:t?.type,placeholder:t?.placeholder,required:t?.required,readonly:t?.readonly||t?.readOnly,help:t?.help,description:t?.description,defaultValue:t?.defaultValue||t?.value,...t},c=u.default.useCallback(e=>{o(e),i.onChange&&i.onChange(e)},[i]),l=t?.readonly||t?.readOnly||!1;return(0,g.jsxs)(`div`,{className:`grid w-full items-center gap-1.5`,"data-obj-id":t?.id,"data-obj-type":t?.type,children:[t?.label&&(0,g.jsx)(`label`,{htmlFor:t.id,className:t.required?`after:content-['*'] after:ml-0.5 after:text-red-500`:``,children:t.label}),(0,g.jsx)(e,{value:a,onChange:c,field:s,readonly:l,className:n}),t?.description&&(0,g.jsx)(`p`,{className:`text-sm text-gray-500`,children:t.description})]})};return t.displayName=`FieldRenderer(${e.displayName||e.name||`Component`})`,t}var zr={text:()=>Promise.resolve().then(()=>(C(),x)).then(e=>({default:e.TextField})),textarea:()=>Promise.resolve().then(()=>(J(),K)).then(e=>({default:e.TextAreaField})),number:()=>Promise.resolve().then(()=>(E(),w)).then(e=>({default:e.NumberField})),boolean:()=>Promise.resolve().then(()=>(k(),D)).then(e=>({default:e.BooleanField})),select:()=>Promise.resolve().then(()=>(P(),M)).then(e=>({default:e.SelectField})),date:()=>Promise.resolve().then(()=>(L(),F)).then(e=>({default:e.DateField})),datetime:()=>Promise.resolve().then(()=>(Ve(),ze)).then(e=>({default:e.DateTimeField})),time:()=>Promise.resolve().then(()=>(We(),He)).then(e=>({default:e.TimeField})),email:()=>Promise.resolve().then(()=>(ne(),te)).then(e=>({default:e.EmailField})),phone:()=>Promise.resolve().then(()=>(V(),z)).then(e=>({default:e.PhoneField})),url:()=>Promise.resolve().then(()=>(U(),H)).then(e=>({default:e.UrlField})),multiselect:()=>Promise.resolve().then(()=>(xn(),yn)).then(e=>({default:e.MultiSelectField})),radio:()=>Promise.resolve().then(()=>(wn(),Sn)).then(e=>({default:e.RadioField})),checkboxes:()=>Promise.resolve().then(()=>(Dn(),Tn)).then(e=>({default:e.CheckboxesField})),tags:()=>Promise.resolve().then(()=>(An(),On)).then(e=>({default:e.TagsField})),currency:()=>Promise.resolve().then(()=>(oe(),ae)).then(e=>({default:e.CurrencyField})),percent:()=>Promise.resolve().then(()=>(qe(),Ge)).then(e=>({default:e.PercentField})),password:()=>Promise.resolve().then(()=>(Xe(),Je)).then(e=>({default:e.PasswordField})),markdown:()=>Promise.resolve().then(()=>(X(),se)).then(e=>({default:e.RichTextField})),html:()=>Promise.resolve().then(()=>(X(),se)).then(e=>({default:e.RichTextField})),richtext:()=>Promise.resolve().then(()=>(X(),se)).then(e=>({default:e.RichTextField})),lookup:()=>Promise.resolve().then(()=>(Re(),je)).then(e=>({default:e.LookupField})),master_detail:()=>Promise.resolve().then(()=>(Re(),je)).then(e=>({default:e.LookupField})),file:()=>Promise.resolve().then(()=>($e(),Ze)).then(e=>({default:e.FileField})),image:()=>Promise.resolve().then(()=>(ot(),rt)).then(e=>({default:e.ImageField})),location:()=>Promise.resolve().then(()=>(lt(),st)).then(e=>({default:e.LocationField})),formula:()=>Promise.resolve().then(()=>(ft(),ut)).then(e=>({default:e.FormulaField})),summary:()=>Promise.resolve().then(()=>(ht(),pt)).then(e=>({default:e.SummaryField})),auto_number:()=>Promise.resolve().then(()=>(vt(),gt)).then(e=>({default:e.AutoNumberField})),user:()=>Promise.resolve().then(()=>(xt(),yt)).then(e=>({default:e.UserField})),owner:()=>Promise.resolve().then(()=>(xt(),yt)).then(e=>({default:e.UserField})),object:()=>Promise.resolve().then(()=>(wt(),St)).then(e=>({default:e.ObjectField})),vector:()=>Promise.resolve().then(()=>(Dt(),Tt)).then(e=>({default:e.VectorField})),grid:()=>Promise.resolve().then(()=>(Ut(),Ot)).then(e=>({default:e.GridField})),color:()=>Promise.resolve().then(()=>(Kt(),Wt)).then(e=>({default:e.ColorField})),slider:()=>Promise.resolve().then(()=>(Yt(),qt)).then(e=>({default:e.SliderField})),rating:()=>Promise.resolve().then(()=>(Qt(),Xt)).then(e=>({default:e.RatingField})),code:()=>Promise.resolve().then(()=>(tn(),$t)).then(e=>({default:e.CodeField})),avatar:()=>Promise.resolve().then(()=>(an(),nn)).then(e=>({default:e.AvatarField})),address:()=>Promise.resolve().then(()=>(cn(),on)).then(e=>({default:e.AddressField})),geolocation:()=>Promise.resolve().then(()=>(dn(),ln)).then(e=>({default:e.GeolocationField})),signature:()=>Promise.resolve().then(()=>(mn(),fn)).then(e=>({default:e.SignatureField})),qrcode:()=>Promise.resolve().then(()=>(_n(),hn)).then(e=>({default:e.QRCodeField}))},Br=new Set([`text`,`html`,`image`,`avatar`,`grid`,`textarea`,`select`,`email`,`password`,`slider`,`markdown`]);function Vr(e){let t=zr[e];if(!t){console.warn(`Unknown field type: ${e}`);return}let n=u.default.lazy(t);d.ComponentRegistry.register(e,n,{namespace:`field`,skipFallback:Br.has(e)})}function Hr(){Object.keys(zr).forEach(e=>{Vr(e)})}function Ur(){d.ComponentRegistry.register(`text`,$(S),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`textarea`,$(q),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`number`,$(T),{namespace:`field`}),d.ComponentRegistry.register(`boolean`,$(O),{namespace:`field`}),d.ComponentRegistry.register(`select`,$(N),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`date`,$(I),{namespace:`field`}),d.ComponentRegistry.register(`datetime`,$(Be),{namespace:`field`}),d.ComponentRegistry.register(`time`,$(Ue),{namespace:`field`}),d.ComponentRegistry.register(`email`,$(R),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`phone`,$(B),{namespace:`field`}),d.ComponentRegistry.register(`url`,$(re),{namespace:`field`}),d.ComponentRegistry.register(`currency`,$(G),{namespace:`field`}),d.ComponentRegistry.register(`percent`,$(Ke),{namespace:`field`}),d.ComponentRegistry.register(`password`,$(Ye),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`markdown`,$(Y),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`html`,$(Y),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`lookup`,$(Fe),{namespace:`field`}),d.ComponentRegistry.register(`master_detail`,$(Fe),{namespace:`field`}),d.ComponentRegistry.register(`file`,$(Qe),{namespace:`field`}),d.ComponentRegistry.register(`image`,$(it),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`location`,$(ct),{namespace:`field`}),d.ComponentRegistry.register(`formula`,$(dt),{namespace:`field`}),d.ComponentRegistry.register(`summary`,$(mt),{namespace:`field`}),d.ComponentRegistry.register(`auto_number`,$(_t),{namespace:`field`}),d.ComponentRegistry.register(`user`,$(bt),{namespace:`field`}),d.ComponentRegistry.register(`owner`,$(bt),{namespace:`field`}),d.ComponentRegistry.register(`object`,$(Ct),{namespace:`field`}),d.ComponentRegistry.register(`vector`,$(Et),{namespace:`field`}),d.ComponentRegistry.register(`grid`,$(Rt),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`color`,$(Gt),{namespace:`field`}),d.ComponentRegistry.register(`slider`,$(Jt),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`rating`,$(Zt),{namespace:`field`}),d.ComponentRegistry.register(`code`,$(en),{namespace:`field`}),d.ComponentRegistry.register(`avatar`,$(rn),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`address`,$(sn),{namespace:`field`}),d.ComponentRegistry.register(`geolocation`,$(un),{namespace:`field`}),d.ComponentRegistry.register(`signature`,$(pn),{namespace:`field`}),d.ComponentRegistry.register(`qrcode`,$(gn),{namespace:`field`})}Hr(),exports.AddressField=sn,exports.AutoNumberField=_t,exports.AvatarField=rn,exports.BooleanCellRenderer=$n,exports.BooleanField=O,exports.CheckboxesField=En,exports.CodeField=en,exports.ColorField=Gt,exports.ColorSwatchCellRenderer=Or,exports.CurrencyCellRenderer=Yn,exports.CurrencyField=G,exports.DateCellRenderer=er,exports.DateField=I,exports.DateTimeCellRenderer=tr,exports.DateTimeField=Be,exports.EmailCellRenderer=mr,exports.EmailField=R,exports.FileCellRenderer=_r,exports.FileField=Qe,exports.FormulaCellRenderer=br,exports.FormulaField=dt,exports.GeolocationField=un,exports.GridField=Rt,exports.HtmlCellRenderer=Mr,exports.ImageCellRenderer=vr,exports.ImageCropperDialog=tt,exports.ImageField=it,exports.JsonCellRenderer=Dr,exports.LineItemsField=Ht,exports.LocationCellRenderer=Nr,exports.LocationField=ct,exports.LookupCellRenderer=yr,exports.LookupField=Fe,exports.MarkdownCellRenderer=Ar,exports.MasterDetailField=vn,exports.MultiSelectField=bn,exports.NumberCellRenderer=Jn,exports.NumberField=T,exports.ObjectField=Ct,exports.PasswordField=Ye,exports.PercentCellRenderer=Zn,exports.PercentField=Ke,exports.PhoneCellRenderer=gr,exports.PhoneField=B,exports.QRCodeField=gn,exports.RadioField=Cn,exports.RatingField=Zt,exports.RecordPickerDialog=fe,exports.RichTextField=Y,exports.SelectCellRenderer=pr,exports.SelectField=N,exports.SignatureField=pn,exports.SliderField=Jt,exports.SummaryField=mt,exports.TagsField=kn,exports.TextAreaField=q,exports.TextCellRenderer=qn,exports.TextField=S,exports.TimeField=Ue,exports.UrlCellRenderer=hr,exports.UrlField=re,exports.UserCellRenderer=xr,exports.UserField=bt,exports.VectorField=Et,exports.buildValidationRules=Lr,exports.coerceToSafeValue=Q,exports.computeRow=Pt,exports.evalArith=Mt,exports.evaluateCondition=Rr,exports.formatCompactCurrency=Bn,exports.formatCurrency=zn,exports.formatDate=Gn,exports.formatDateTime=Kn,exports.formatFileSize=Ir,exports.formatNumber=Vn,exports.formatPercent=Hn,exports.formatRelativeDate=Wn,exports.getBadgeColorClasses=lr,exports.getCellRenderer=Pr,exports.getSemanticColorName=ur,exports.getSemanticHex=fr,exports.humanizeLabel=Un,exports.isLikelyOpaqueId=In,exports.lookupAutofillPatch=Nt,exports.lookupFiltersToRecord=ue,exports.mapFieldTypeToFormType=Fr,exports.registerAllFields=Hr,exports.registerField=Vr,exports.registerFieldRenderer=Cr,exports.registerFields=Ur,exports.resolveCellRendererType=Er,Object.defineProperty(exports,"resolveFieldCurrency",{enumerable:!0,get:function(){return f.resolveFieldCurrency}}),exports.sumColumn=Lt;
|
|
9
|
+
`){n++;continue}if(r>=`0`&&r<=`9`||r===`.`){let r=n+1;for(;r<e.length&&(e[r]>=`0`&&e[r]<=`9`||e[r]===`.`);)r++;t.push({t:`num`,v:e.slice(n,r)}),n=r;continue}if(/[a-zA-Z_]/.test(r)){let r=n+1;for(;r<e.length&&/[a-zA-Z0-9_.]/.test(e[r]);)r++;t.push({t:`id`,v:e.slice(n,r)}),n=r;continue}if(r===`+`||r===`-`||r===`*`||r===`/`||r===`%`){t.push({t:`op`,v:r}),n++;continue}if(r===`(`){t.push({t:`lp`,v:r}),n++;continue}if(r===`)`){t.push({t:`rp`,v:r}),n++;continue}return null}return t}function jt(e,t){let n=e.startsWith(`record.`)?e.slice(7):e,r=t?.[n];if(r==null||r===``)return null;let i=Number(r);return Number.isFinite(i)?i:null}function Mt(e,t){let n=At(e);if(!n||n.length===0)return null;let r=0,i=!1,a=()=>n[r],o=()=>n[r++];function s(){let e=a();if(!e)return i=!0,NaN;if(e.t===`op`&&e.v===`-`)return o(),-s();if(e.t===`op`&&e.v===`+`)return o(),s();if(e.t===`num`)return o(),Number(e.v);if(e.t===`id`){o();let n=jt(e.v,t);return n===null?(i=!0,NaN):n}if(e.t===`lp`){o();let e=l(),t=o();return(!t||t.t!==`rp`)&&(i=!0),e}return i=!0,NaN}function c(){let e=s();for(;a()&&a().t===`op`&&(a().v===`*`||a().v===`/`||a().v===`%`);){let t=o().v,n=s();e=t===`*`?e*n:t===`/`?e/n:e%n}return e}function l(){let e=c();for(;a()&&a().t===`op`&&(a().v===`+`||a().v===`-`);){let t=o().v,n=c();e=t===`+`?e+n:e-n}return e}let u=l();return i||r!==n.length||!Number.isFinite(u)?null:u}function Nt(e,t,n){let r={[t.field]:n?.value??n?.id??n?._id};if(t.autofill!==!1&&n&&typeof n==`object`)for(let i of e){if(i.field===t.field||i.computed||i.type===`lookup`)continue;let e=n[i.field];e!=null&&e!==``&&(r[i.field]=e)}return r}function Pt(e,t){let n=e.filter(e=>e.computed&&e.expr);if(n.length===0)return t;let r={...t};for(let e of n){let t=Mt(e.expr,r);if(t===null){r[e.field]=null;continue}let n=e.scale??(e.type===`currency`?2:void 0);r[e.field]=n==null?t:Number(t.toFixed(n))}return r}function Ft(e,t){if(t==null||t===``)return`—`;if(e.type===`select`&&Array.isArray(e.options)){let n=e.options.find(e=>String(e.value)===String(t));return n?n.label:String(t)}if(zt(e.type)){let n=Number(t);if(Number.isFinite(n))return e.type===`currency`?`${e.prefix||`¥`}${n.toLocaleString()}`:n.toLocaleString()}return Array.isArray(t)?t.join(`, `):String(t)}function It(e,t){if(zt(e)){if(t===``||t==null)return null;let e=Number(t);return Number.isNaN(e)?t:e}return t}function Lt(e,t){return Array.isArray(e)?e.reduce((e,n)=>{let r=Number(n?.[t]);return e+(Number.isFinite(r)?r:0)},0):0}function Rt({value:e,onChange:t,field:n,readonly:r,disabled:i,className:a,onRowExpand:o,displayMode:s,onAdd:c,...l}){let f=n||l.schema||{},h=f.columns||[],_=Array.isArray(e)?e:[],v=l.contextRecord,y=(0,u.useCallback)((e,t)=>{if(!e.readonlyWhen&&!e.requiredWhen)return{readonly:!1,required:!!e.required};let n=(0,d.resolveFieldRuleState)({readonlyWhen:e.readonlyWhen,requiredWhen:e.requiredWhen},t||{},{required:!!e.required,readonly:!1},void 0,v?{parent:v}:void 0);return{readonly:n.readonly,required:n.required}},[v]),b=s===`list`&&!r,[x,S]=u.default.useState(()=>new Set),C=h.filter(e=>e.defaultHidden&&!e.required),w=h.filter(e=>!e.defaultHidden||e.required||x.has(e.field)),T=(0,u.useCallback)(e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),E=f.allow_add!==!1&&!r&&!i,D=f.allow_delete!==!1&&!r&&!i,O=f.allow_duplicate!==!1&&E,k=typeof o==`function`&&!r,A=f.show_line_numbers!==!1,ee=f.min_rows??0,j=f.max_rows,te=f.total_field||f.amount_field||f.amountField,M=f.sort_field,N=f.reorderable!==!1&&!r&&!i,P=(0,u.useCallback)(e=>{t?.(M?e.map((e,t)=>({...e,[M]:t})):e)},[t,M]),F=(0,u.useCallback)(()=>{let e={};for(let t of w)e[t.field]=null;return e},[w]),I=(0,u.useCallback)((e,t)=>{if(e>=_.length){if(j!=null&&_.length>=j)return;P([..._,Pt(w,{...F(),...t})]);return}P(_.map((n,r)=>r===e?Pt(w,{...n,...t}):n))},[_,w,j,F,P]),ne=(0,u.useCallback)((e,t,n)=>I(e,{[t]:n}),[I]),L=(0,u.useCallback)((e,t,n)=>{I(e,Nt(w,t,n))},[w,I]),re=(0,u.useCallback)((e,t,n)=>ne(e,t,n),[ne]),R=(0,u.useCallback)((e,t,n)=>{ne(e,t.field,It(t.type,n))},[ne]),z=(0,u.useCallback)(()=>{j!=null&&_.length>=j||P([..._,F()])},[_,F,j,P]),B=(0,u.useRef)(null),V=(0,u.useCallback)((e,t)=>{let n=B.current?.querySelector(`[data-cell="${e}-${t}"]`);n&&(n.focus(),n instanceof HTMLInputElement&&n.select())},[]),ie=(0,u.useCallback)((e,t,n)=>{e.key===`ArrowDown`||e.key===`Enter`?(e.preventDefault(),V(t+1,n)):e.key===`ArrowUp`&&(e.preventDefault(),t>0&&V(t-1,n))},[V]),H=(0,u.useCallback)(e=>{_.length<=ee||P(_.filter((t,n)=>n!==e))},[_,ee,P]),ae=(0,u.useCallback)(e=>{if(j!=null&&_.length>=j)return;let t=_[e];if(!t)return;let{id:n,_id:r,recordId:i,...a}=t,o=[..._];o.splice(e+1,0,{...a}),P(o)},[_,j,P]),oe=(0,u.useCallback)((e,t)=>{if(e===t||e<0||t<0||e>=_.length||t>=_.length)return;let n=[..._],[r]=n.splice(e,1);n.splice(t,0,r),P(n)},[_,P]),U=(0,u.useRef)(null),W=k||D||O,se=(+!!k+ +!!O+ +!!D)*34+12,G=!!te,K=G?Lt(_,te):0,q=G?Math.max(0,w.findIndex(e=>e.field===te)):-1,ce=C.length>0?(0,g.jsxs)(p.Popover,{children:[(0,g.jsx)(p.PopoverTrigger,{asChild:!0,children:(0,g.jsxs)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 gap-1.5 text-xs text-muted-foreground`,"data-testid":`line-items-columns`,children:[(0,g.jsx)(m.SlidersHorizontal,{className:`h-3.5 w-3.5`}),`Columns`,x.size>0&&(0,g.jsxs)(`span`,{className:`rounded-full bg-primary/10 px-1.5 text-[10px] font-medium text-primary`,children:[`+`,x.size]})]})}),(0,g.jsxs)(p.PopoverContent,{align:`end`,className:`w-56 p-2`,children:[(0,g.jsx)(`div`,{className:`px-1 pb-1.5 text-xs font-medium text-muted-foreground`,children:`Optional columns`}),(0,g.jsx)(`div`,{className:`max-h-64 space-y-0.5 overflow-y-auto`,children:C.map(e=>{let t=`col-toggle-${e.field}`;return(0,g.jsxs)(p.Label,{htmlFor:t,className:`flex cursor-pointer items-center gap-2 rounded-md px-1.5 py-1.5 text-sm font-normal hover:bg-muted`,children:[(0,g.jsx)(p.Checkbox,{id:t,checked:x.has(e.field),onCheckedChange:()=>T(e.field)}),(0,g.jsx)(`span`,{className:`truncate`,children:e.label||e.field})]},e.field)})})]})]}):null;if(r)return(0,g.jsxs)(`div`,{className:(0,p.cn)(`space-y-2`,a),children:[ce&&(0,g.jsx)(`div`,{className:`flex justify-end`,children:ce}),(0,g.jsx)(`div`,{className:`border border-border rounded-lg overflow-x-auto`,"data-testid":`line-items-readonly`,children:(0,g.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,g.jsx)(`thead`,{className:`bg-muted border-b border-border`,children:(0,g.jsxs)(`tr`,{children:[A&&(0,g.jsx)(`th`,{className:`w-10 px-2 py-2 text-right text-xs font-medium text-muted-foreground`,children:`#`}),w.map(e=>(0,g.jsx)(`th`,{style:{minWidth:Vt(e)},className:(0,p.cn)(`px-3 py-2 text-xs font-medium text-muted-foreground whitespace-nowrap`,zt(e.type)?`text-right`:`text-left`),children:e.label||e.field},e.field))]})}),(0,g.jsx)(`tbody`,{className:`divide-y divide-border`,children:_.length===0?(0,g.jsx)(`tr`,{children:(0,g.jsx)(`td`,{colSpan:Math.max(w.length+ +!!A,1),className:`px-3 py-6 text-center text-muted-foreground`,children:`No items`})}):_.map((e,t)=>(0,g.jsxs)(`tr`,{children:[A&&(0,g.jsx)(`td`,{className:`px-2 py-2 text-right text-muted-foreground tabular-nums`,children:t+1}),w.map(t=>(0,g.jsx)(`td`,{className:(0,p.cn)(`px-3 py-2 text-foreground`,zt(t.type)&&`text-right tabular-nums`),children:t.type===`lookup`&&e[t.field]!=null&&e[t.field]!==``?(0,g.jsx)(Ie,{value:e[t.field],onChange:()=>{},readonly:!0,field:{reference:t.reference,display_field:t.displayField,id_field:t.idField}}):e[t.field]!=null&&e[t.field]!==``?String(e[t.field]):`—`},t.field))]},t))}),G&&(0,g.jsx)(`tfoot`,{className:`border-t border-border bg-muted/40`,children:(0,g.jsxs)(`tr`,{children:[(0,g.jsx)(`td`,{colSpan:Math.max(+!!A+q,1),className:`px-3 py-2 text-right text-xs font-medium text-muted-foreground`,children:`Total`}),(0,g.jsx)(`td`,{className:`px-3 py-2 text-right font-semibold text-foreground tabular-nums`,children:K.toLocaleString()}),w.length-q-1>0&&(0,g.jsx)(`td`,{colSpan:w.length-q-1})]})})]})})]});let J=!b&&E&&(j==null||_.length<j),Y=J?[..._,F()]:_,le=(e,t,n,r)=>{let a=r?.[e.field],o=i||y(e,r).readonly;return b?e.type===`lookup`&&a!=null&&a!==``?(0,g.jsx)(Ie,{value:a,onChange:()=>{},readonly:!0,field:{reference:e.reference,display_field:e.displayField,id_field:e.idField}}):(0,g.jsx)(`span`,{className:(0,p.cn)(`px-2 text-sm text-foreground`,zt(e.type)&&`tabular-nums`,(a==null||a===``)&&`text-muted-foreground`),children:Ft(e,a)}):e.computed?(0,g.jsx)(`span`,{className:(0,p.cn)(`block px-2 text-sm tabular-nums`,zt(e.type)?`text-right`:`text-left`,a==null||a===``?`text-muted-foreground`:`text-foreground`),title:`Computed`,"data-computed":e.field,children:Ft(e,a)}):e.type===`lookup`?(0,g.jsx)(Ie,{value:a,onChange:t=>re(n,e.field,t),onSelectRecord:t=>L(n,e,t),compact:!0,field:{reference:e.reference,display_field:e.displayField,id_field:e.idField,multiple:e.multiple,options:e.options,placeholder:`—`},disabled:o}):e.type===`select`?(0,g.jsxs)(p.Select,{value:a==null?``:String(a),onValueChange:t=>R(n,e,t),disabled:o,children:[(0,g.jsx)(p.SelectTrigger,{className:`h-8 rounded-none border-0 bg-transparent px-2 shadow-none focus:ring-1 focus:ring-ring/60`,"aria-label":e.label||e.field,children:(0,g.jsx)(p.SelectValue,{placeholder:`—`})}),(0,g.jsx)(p.SelectContent,{children:(e.options||[]).map(e=>(0,g.jsx)(p.SelectItem,{value:e.value,children:e.label},e.value))})]}):(0,g.jsxs)(`div`,{className:`relative`,children:[e.type===`currency`&&(0,g.jsx)(`span`,{className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-xs text-muted-foreground`,children:e.prefix||`¥`}),(0,g.jsx)(p.Input,{"data-cell":`${n}-${t}`,onKeyDown:e=>ie(e,n,t),className:(0,p.cn)(`h-8 rounded-none border-0 bg-transparent px-2 shadow-none focus-visible:ring-1 focus-visible:ring-ring/60`,e.type===`currency`&&`pl-6`,zt(e.type)&&`text-right tabular-nums`),type:e.type===`date`?`date`:zt(e.type)?`number`:`text`,step:zt(e.type)?e.step??`any`:void 0,"aria-label":e.label||e.field,value:a==null?``:String(a),onChange:t=>R(n,e,t.target.value),disabled:o})]})};return(0,g.jsxs)(`div`,{className:(0,p.cn)(`space-y-2`,a),"data-testid":`line-items`,children:[ce&&(0,g.jsx)(`div`,{className:`flex justify-end`,children:ce}),(0,g.jsx)(`div`,{className:`border border-border rounded-lg overflow-x-auto`,children:(0,g.jsxs)(`table`,{ref:B,className:`w-full text-sm`,children:[(0,g.jsx)(`thead`,{className:`bg-muted/60 border-b border-border`,children:(0,g.jsxs)(`tr`,{children:[A&&(0,g.jsx)(`th`,{className:(0,p.cn)(`px-2 py-2 text-right text-xs font-medium text-muted-foreground`,N?`w-14`:`w-10`),children:`#`}),w.map(e=>(0,g.jsxs)(`th`,{className:(0,p.cn)(`px-2 py-2 text-xs font-medium text-muted-foreground whitespace-nowrap`,zt(e.type)?`text-right`:`text-left`),style:kt(e),children:[e.label||e.field,e.required&&!e.computed&&(0,g.jsx)(`span`,{className:`text-destructive`,children:` *`})]},e.field)),W&&(0,g.jsx)(`th`,{style:{width:se}})]})}),(0,g.jsx)(`tbody`,{className:`divide-y divide-border`,children:b&&_.length===0?(0,g.jsx)(`tr`,{children:(0,g.jsxs)(`td`,{colSpan:w.length+ +!!W+ +!!A,className:`px-3 py-6 text-center text-muted-foreground`,children:[`No items yet — click “`,f.add_label||`Add`,`” to begin.`]})}):Y.map((e,t)=>{let n=J&&t===_.length,r=N&&!n&&!b;return(0,g.jsxs)(`tr`,{className:(0,p.cn)(`group`,!n&&`hover:bg-muted/30`),...N&&!n?{onDragOver:e=>{U.current!=null&&e.preventDefault()},onDrop:e=>{e.preventDefault(),U.current!=null&&(oe(U.current,t),U.current=null)}}:{},children:[A&&(0,g.jsx)(`td`,{className:`px-1 py-1 text-right align-middle text-xs text-muted-foreground tabular-nums`,children:(0,g.jsxs)(`span`,{className:`inline-flex items-center justify-end gap-0.5`,children:[r&&(0,g.jsx)(`span`,{draggable:!0,onDragStart:()=>{U.current=t},onDragEnd:()=>{U.current=null},className:`cursor-grab text-muted-foreground/40 opacity-0 transition-opacity group-hover:opacity-100`,title:`Drag to reorder`,"aria-label":`Drag to reorder`,"data-testid":`line-items-drag-${t}`,children:(0,g.jsx)(m.GripVertical,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(`span`,{className:(0,p.cn)(n&&`opacity-30`),children:t+1})]})}),w.map((r,i)=>{let a=y(r,e).required,o=!n&&!b&&a&&!r.computed&&(e[r.field]==null||e[r.field]===``);return(0,g.jsx)(`td`,{"aria-invalid":o||void 0,title:o?`${r.label||r.field} is required`:void 0,"data-testid":o?`line-items-invalid-${t}-${r.field}`:void 0,className:(0,p.cn)(`border-r border-border/40 px-1 py-0.5 align-middle last:border-r-0`,b&&`px-2 py-1.5`,o&&`bg-destructive/5 ring-1 ring-inset ring-destructive/50`),children:le(r,i,t,e)},r.field)}),W&&(0,g.jsx)(`td`,{className:`px-1 py-0.5 align-middle whitespace-nowrap`,children:(0,g.jsxs)(`div`,{className:`flex items-center justify-center gap-0.5`,children:[!n&&k&&(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground hover:text-foreground`,"aria-label":`Open row`,title:`Open full form`,"data-testid":`line-items-expand-${t}`,onClick:()=>o(t),children:(0,g.jsx)(m.Maximize2,{className:`h-3.5 w-3.5`})}),!n&&O&&(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`icon`,className:(0,p.cn)(`h-8 w-8 text-muted-foreground hover:text-foreground`,!b&&`opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100`),"aria-label":`Duplicate row`,title:`Duplicate line`,"data-testid":`line-items-duplicate-${t}`,onClick:()=>ae(t),disabled:i||j!=null&&_.length>=j,children:(0,g.jsx)(m.Copy,{className:`h-3.5 w-3.5`})}),!n&&D&&(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`icon`,className:(0,p.cn)(`h-8 w-8 text-muted-foreground hover:text-destructive`,!b&&`opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100`),"aria-label":`Remove row`,"data-testid":`line-items-remove-${t}`,onClick:()=>H(t),disabled:i||_.length<=ee,children:(0,g.jsx)(m.Trash2,{className:`h-4 w-4`})})]})})]},t)})}),G&&(0,g.jsx)(`tfoot`,{className:`border-t border-border bg-muted/40`,children:(0,g.jsxs)(`tr`,{children:[(0,g.jsx)(`td`,{colSpan:Math.max(+!!A+q,1),className:`px-3 py-2 text-right text-xs font-medium text-muted-foreground`,children:`Total`}),(0,g.jsx)(`td`,{className:`px-3 py-2 text-right font-semibold text-foreground tabular-nums`,"data-testid":`line-items-total`,children:K.toLocaleString()}),w.length-q-1+ +!!W>0&&(0,g.jsx)(`td`,{colSpan:w.length-q-1+ +!!W})]})})]})}),E&&(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:b&&c?c:z,disabled:j!=null&&_.length>=j,"data-testid":`line-items-add`,children:[(0,g.jsx)(m.Plus,{className:`mr-1.5 h-4 w-4`}),f.add_label||`Add line`]})]})}var zt,Bt,Vt,Ht,Ut=o((()=>{Z(),zt=e=>e===`number`||e===`currency`,Bt={text:160,select:132,lookup:168,number:104,currency:116,date:150},Vt=e=>e.width??Bt[e.type??`text`]??132,Ht=Rt})),Wt=s({ColorField:()=>Gt});function Gt({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema;return r?(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`div`,{className:`w-6 h-6 rounded border border-input`,style:{backgroundColor:e||`#000000`}}),(0,g.jsx)(`span`,{className:`text-sm`,children:e||(0,g.jsx)(p.EmptyValue,{})})]}):(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`input`,{type:`color`,value:e||`#000000`,onChange:e=>t(e.target.value),disabled:r||i.disabled,className:`w-10 h-10 rounded border border-input cursor-pointer`}),(0,g.jsx)(p.Input,{type:`text`,value:e||``,onChange:e=>t(e.target.value),placeholder:a?.placeholder||`#000000`,disabled:r||i.disabled,className:i.className,pattern:`^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$`})]})}var Kt=o((()=>{})),qt=s({SliderField:()=>Jt});function Jt({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=a?.min??0,s=a?.max??100,c=a?.step??1;return r?(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`span`,{className:`text-sm font-medium`,children:e??o}),(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,s]})]}):(0,g.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,g.jsx)(p.Slider,{value:[e??o],onValueChange:e=>t(e[0]),min:o,max:s,step:c,disabled:r||i.disabled,className:i.className}),(0,g.jsx)(`span`,{className:`text-sm font-medium w-12 text-right`,children:e??o})]})}var Yt=o((()=>{})),Xt=s({RatingField:()=>Zt});function Zt({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=(n||a.schema)?.max??5,s=e??0,[c,l]=u.default.useState(null),d=c===null?s:c;return r?(0,g.jsxs)(`div`,{className:(0,p.cn)(`flex items-center gap-1`,i),children:[Array.from({length:o},(e,t)=>(0,g.jsx)(m.Star,{className:`w-5 h-5 ${t<s?`fill-yellow-400 text-yellow-400`:`text-muted-foreground`}`},t)),(0,g.jsxs)(`span`,{className:`ml-2 text-sm text-muted-foreground`,children:[s,` / `,o]})]}):(0,g.jsxs)(`div`,{className:(0,p.cn)(`flex items-center gap-1`,i),children:[Array.from({length:o},(e,n)=>(0,g.jsx)(`button`,{type:`button`,onClick:()=>t(n+1),onMouseEnter:()=>l(n+1),onMouseLeave:()=>l(null),className:`focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 rounded`,disabled:r||a.disabled,children:(0,g.jsx)(m.Star,{className:`w-5 h-5 transition-colors ${n<d?`fill-yellow-400 text-yellow-400 hover:fill-yellow-500 hover:text-yellow-500`:`text-muted-foreground hover:text-yellow-400`}`})},n)),(0,g.jsxs)(`span`,{className:`ml-2 text-sm text-muted-foreground`,children:[s,` / `,o]})]})}var Qt=o((()=>{})),$t=s({CodeField:()=>en});function en({value:e,onChange:t,field:n,readonly:r,...i}){let a=n||i.schema,o=a?.language??`javascript`;return r?(0,g.jsx)(`pre`,{className:(0,p.cn)(`text-sm bg-muted p-2 rounded overflow-x-auto border`,i.className),children:(0,g.jsx)(`code`,{children:e||(0,g.jsx)(p.EmptyValue,{})})}):(0,g.jsx)(p.Textarea,{value:e||``,onChange:e=>t(e.target.value),placeholder:a?.placeholder||`// Write ${o} code here...`,disabled:r||i.disabled,className:(0,p.cn)(`font-mono text-sm`,i.className),rows:12,spellCheck:!1})}var tn=o((()=>{})),nn=s({AvatarField:()=>rn});function rn({value:e,onChange:t,field:n,readonly:r,...i}){let[a,o]=u.default.useState(!1),s=u.default.useRef(null),c=n||i.schema,l=e=>{let n=e.target.files?.[0];if(!n)return;if(!n.type.startsWith(`image/`)){console.error(`Please select an image file`);return}if(n.size>5*1024*1024){console.error(`File size must be less than 5MB`);return}let r=new FileReader;r.onloadend=()=>{t(r.result)},r.readAsDataURL(n)},d=()=>{t(``)},f=()=>(c?.defaultName||c?.label||`User`).split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return r?(0,g.jsxs)(p.Avatar,{className:`w-16 h-16`,children:[e&&(0,g.jsx)(p.AvatarImage,{src:e,alt:c?.label}),(0,g.jsx)(p.AvatarFallback,{children:f()})]}):(0,g.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,g.jsxs)(`div`,{className:`relative`,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[(0,g.jsxs)(p.Avatar,{className:`w-16 h-16`,children:[e&&(0,g.jsx)(p.AvatarImage,{src:e,alt:c?.label}),(0,g.jsx)(p.AvatarFallback,{children:f()})]}),!r&&a&&e&&(0,g.jsx)(`button`,{type:`button`,onClick:d,className:`absolute -top-1 -right-1 bg-destructive text-destructive-foreground rounded-full p-1 hover:bg-destructive/90`,children:(0,g.jsx)(m.X,{className:`w-3 h-3`})})]}),(0,g.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,g.jsx)(`input`,{ref:s,type:`file`,accept:`image/*`,onChange:l,className:`hidden`}),(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s.current?.click(),disabled:r||i.disabled,children:[(0,g.jsx)(m.Upload,{className:`w-4 h-4 mr-2`}),e?`Change`:`Upload`,` Avatar`]}),(0,g.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`PNG, JPG up to 5MB`})]})]})}var an=o((()=>{})),on=s({AddressField:()=>sn});function sn({value:e,onChange:t,field:n,readonly:r,...i}){let a=e||{},o=(e,n)=>{t({...a,[e]:n})},s=e=>[e.street,e.city,[e.state,e.zipCode].filter(Boolean).join(` `),e.country].filter(Boolean).join(`, `);if(r){let e=s(a);return e?(0,g.jsx)(`span`,{className:`text-sm`,children:e}):(0,g.jsx)(p.EmptyValue,{})}return(0,g.jsxs)(`div`,{className:`space-y-3`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`street`,className:`text-xs`,children:`Street Address`}),(0,g.jsx)(p.Input,{id:`street`,type:`text`,value:a.street||``,onChange:e=>o(`street`,e.target.value),placeholder:`123 Main St`,disabled:r||i.disabled,className:i.className})]}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`city`,className:`text-xs`,children:`City`}),(0,g.jsx)(p.Input,{id:`city`,type:`text`,value:a.city||``,onChange:e=>o(`city`,e.target.value),placeholder:`San Francisco`,disabled:r||i.disabled})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`state`,className:`text-xs`,children:`State / Province`}),(0,g.jsx)(p.Input,{id:`state`,type:`text`,value:a.state||``,onChange:e=>o(`state`,e.target.value),placeholder:`CA`,disabled:r||i.disabled})]})]}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`zipCode`,className:`text-xs`,children:`ZIP / Postal Code`}),(0,g.jsx)(p.Input,{id:`zipCode`,type:`text`,value:a.zipCode||``,onChange:e=>o(`zipCode`,e.target.value),placeholder:`94102`,disabled:r||i.disabled})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`country`,className:`text-xs`,children:`Country`}),(0,g.jsx)(p.Input,{id:`country`,type:`text`,value:a.country||``,onChange:e=>o(`country`,e.target.value),placeholder:`United States`,disabled:r||i.disabled})]})]})]})}var cn=o((()=>{})),ln=s({GeolocationField:()=>un});function un({value:e,onChange:t,field:n,readonly:r,...i}){let[a,o]=u.default.useState(!1),s=e||{},c=(e,n)=>{t({...s,[e]:n?Number(n):void 0})},l=()=>{if(!navigator.geolocation){console.error(`Geolocation is not supported by this browser`);return}o(!0),navigator.geolocation.getCurrentPosition(e=>{t({latitude:e.coords.latitude,longitude:e.coords.longitude,accuracy:e.coords.accuracy}),o(!1)},e=>{console.error(`Error getting location:`,e.message),o(!1)},{enableHighAccuracy:!0,timeout:5e3,maximumAge:0})},d=e=>!e.latitude||!e.longitude?``:`${e.latitude.toFixed(6)}, ${e.longitude.toFixed(6)}`,f=()=>{if(!s.latitude||!s.longitude)return;let e=`https://www.google.com/maps?q=${s.latitude},${s.longitude}`;window.open(e,`_blank`)};if(r){let e=d(s);return(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(m.MapPin,{className:`w-4 h-4 text-muted-foreground`}),e?(0,g.jsx)(`span`,{className:`text-sm`,children:e}):(0,g.jsx)(p.EmptyValue,{}),s.latitude&&s.longitude&&(0,g.jsx)(p.Button,{type:`button`,variant:`link`,size:`sm`,onClick:f,className:`p-0 h-auto`,children:`View on map`})]})}return(0,g.jsxs)(`div`,{className:`space-y-3`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:l,disabled:r||a,children:[(0,g.jsx)(m.Crosshair,{className:`w-4 h-4 mr-2`}),a?`Getting location...`:`Use Current Location`]}),s.latitude&&s.longitude&&(0,g.jsxs)(p.Button,{type:`button`,variant:`link`,size:`sm`,onClick:f,children:[(0,g.jsx)(m.MapPin,{className:`w-4 h-4 mr-2`}),`View on map`]})]}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`latitude`,className:`text-xs`,children:`Latitude`}),(0,g.jsx)(p.Input,{id:`latitude`,type:`number`,value:s.latitude??``,onChange:e=>c(`latitude`,e.target.value),placeholder:`37.7749`,disabled:r||i.disabled,step:`any`,className:i.className})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(p.Label,{htmlFor:`longitude`,className:`text-xs`,children:`Longitude`}),(0,g.jsx)(p.Input,{id:`longitude`,type:`number`,value:s.longitude??``,onChange:e=>c(`longitude`,e.target.value),placeholder:`-122.4194`,disabled:r||i.disabled,step:`any`})]})]}),s.accuracy&&(0,g.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Accuracy: ±`,s.accuracy.toFixed(0),`m`]})]})}var dn=o((()=>{})),fn=s({SignatureField:()=>pn});function pn({value:e,onChange:t,readonly:n}){let r=(0,u.useRef)(null),[i,a]=u.default.useState(!1),[o,s]=u.default.useState(!e);(0,u.useEffect)(()=>{if(e&&r.current){let t=r.current.getContext(`2d`);if(t){let n=new Image;n.onload=()=>{t.drawImage(n,0,0),s(!1)},n.src=e}}},[e]);let c=e=>{if(n)return;a(!0),s(!1);let t=r.current;if(!t)return;let i=t.getContext(`2d`);if(!i)return;let o=t.getBoundingClientRect(),c=`touches`in e?e.touches[0].clientX-o.left:e.clientX-o.left,l=`touches`in e?e.touches[0].clientY-o.top:e.clientY-o.top;i.beginPath(),i.moveTo(c,l)},l=e=>{if(!i||n)return;let t=r.current;if(!t)return;let a=t.getContext(`2d`);if(!a)return;let o=t.getBoundingClientRect(),s=`touches`in e?e.touches[0].clientX-o.left:e.clientX-o.left,c=`touches`in e?e.touches[0].clientY-o.top:e.clientY-o.top;a.lineTo(s,c),a.strokeStyle=`#000`,a.lineWidth=2,a.lineCap=`round`,a.lineJoin=`round`,a.stroke()},d=()=>{if(!i)return;a(!1);let e=r.current;e&&t(e.toDataURL(`image/png`))};return n&&e?(0,g.jsx)(`div`,{className:`border rounded p-2 bg-white`,children:(0,g.jsx)(`img`,{src:e,alt:`Signature`,loading:`lazy`,className:`max-w-full h-auto`})}):n&&!e?(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`No signature`}):(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(`div`,{className:`border rounded bg-white`,children:(0,g.jsx)(`canvas`,{ref:r,width:400,height:200,className:`w-full touch-none cursor-crosshair`,onMouseDown:c,onMouseMove:l,onMouseUp:d,onMouseLeave:d,onTouchStart:c,onTouchMove:l,onTouchEnd:d})}),(0,g.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,g.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o?`Sign above`:`Signature captured`}),(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{let e=r.current;if(!e)return;let n=e.getContext(`2d`);n&&(n.clearRect(0,0,e.width,e.height),s(!0),t(``))},disabled:n||o,children:[(0,g.jsx)(m.Eraser,{className:`w-4 h-4 mr-2`}),`Clear`]})]})]})}var mn=o((()=>{})),hn=s({QRCodeField:()=>gn});function gn({value:e,onChange:t,field:n,readonly:r,...i}){let[a,o]=u.default.useState(!1),s=n||i.schema;return r?(0,g.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,g.jsx)(`span`,{className:`text-sm flex-1 truncate`,children:e||(0,g.jsx)(p.EmptyValue,{})}),e&&(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>o(!a),children:[(0,g.jsx)(m.QrCode,{className:`w-4 h-4 mr-2`}),a?`Hide`:`Show`,` QR`]})]}):(0,g.jsxs)(`div`,{className:`space-y-3`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(p.Input,{type:`text`,value:e||``,onChange:e=>t(e.target.value),placeholder:s?.placeholder||`Enter text for QR code`,disabled:r||i.disabled,className:i.className}),e&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{e&&navigator.clipboard.writeText(e)},children:(0,g.jsx)(m.Copy,{className:`w-4 h-4`})}),(0,g.jsx)(p.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>o(!a),children:(0,g.jsx)(m.QrCode,{className:`w-4 h-4`})})]})]}),a&&e&&(0,g.jsx)(`div`,{className:`border rounded p-4 bg-white flex justify-center`,children:(0,g.jsx)(`img`,{src:(e=>`https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(e)}`)(e),alt:`QR Code`,className:`w-48 h-48`})}),e&&(0,g.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`QR code contains: `,e.length,` characters`]})]})}var _n=o((()=>{}));C(),E(),k(),N(),I(),re(),B(),H(),se(),q(),Y(),Ve(),We(),qe(),Xe(),$e(),ot(),lt(),ft(),ht(),vt(),xt(),wt(),Dt(),Ut(),Kt(),Yt(),Qt(),tn(),an(),cn(),dn(),mn(),_n(),nt();function vn({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=e||[],s=n||a.schema,c=()=>{let e={id:`new-${Date.now()}`,label:`New Related Record`};t([...o,e])},l=e=>{t(o.filter(t=>t.id!==e))},u=e=>{console.log(`View detail:`,e)};return r?(0,g.jsxs)(`div`,{className:(0,p.cn)(`space-y-2`,i),children:[o.length===0?(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`No related records`}):o.map(e=>(0,g.jsxs)(`div`,{className:`flex items-center justify-between p-2 border rounded hover:bg-muted/50`,children:[(0,g.jsx)(`span`,{className:`text-sm`,children:e.label}),(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>u(e),children:(0,g.jsx)(m.ExternalLink,{className:`w-4 h-4`})})]},e.id)),(0,g.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[o.length,` `,o.length===1?`record`:`records`]})]}):(0,g.jsxs)(`div`,{className:(0,p.cn)(`space-y-3`,i),children:[(0,g.jsxs)(`div`,{className:`space-y-2`,children:[o.map(e=>(0,g.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-2 border rounded hover:bg-muted/50`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,g.jsx)(p.Badge,{variant:`outline`,children:e.id}),(0,g.jsx)(`span`,{className:`text-sm flex-1`,children:e.label})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>u(e),children:(0,g.jsx)(m.ExternalLink,{className:`w-4 h-4`})}),(0,g.jsx)(p.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>l(e.id),disabled:a.disabled,children:(0,g.jsx)(m.X,{className:`w-4 h-4`})})]})]},e.id)),o.length===0&&(0,g.jsx)(`div`,{className:`text-sm text-muted-foreground text-center py-4 border border-dashed rounded bg-muted/20`,children:`No related records`})]}),(0,g.jsxs)(p.Button,{type:`button`,variant:`outline`,className:`w-full`,onClick:c,disabled:a.disabled,children:[(0,g.jsx)(m.Plus,{className:`w-4 h-4 mr-2`}),`Add `,s?.label||`Record`]})]})}var yn=s({MultiSelectField:()=>bn});function bn({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=(n||a.schema)?.options||[],s=Array.isArray(e)?e:e==null?[]:[e];if(r)return s.length===0?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>(0,g.jsx)(p.Badge,{variant:`outline`,children:o.find(t=>t.value===e)?.label||e},e))});let c=e=>{t(s.includes(e)?s.filter(t=>t!==e):[...s,e])};return(0,g.jsx)(`div`,{className:(0,p.cn)(`flex flex-wrap gap-1.5`,i),children:o.map(e=>{let t=s.includes(e.value);return(0,g.jsx)(`button`,{type:`button`,onClick:()=>c(e.value),disabled:a.disabled,"aria-pressed":t,className:(0,p.cn)(`rounded-full border px-3 py-1 text-sm transition-colors`,t?`border-primary bg-primary text-primary-foreground`:`border-input bg-background text-foreground hover:bg-accent`),children:e.label},e.value)})})}var xn=o((()=>{})),Sn=s({RadioField:()=>Cn});function Cn({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=(n||a.schema)?.options||[],s=(0,u.useId)();return r?e==null||e===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`text-sm`,children:o.find(t=>t.value===e)?.label||String(e)}):(0,g.jsx)(p.RadioGroup,{value:e??``,onValueChange:t,disabled:a.disabled,className:i,children:o.map(e=>{let t=`${s}-${e.value}`;return(0,g.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,g.jsx)(p.RadioGroupItem,{value:e.value,id:t}),(0,g.jsx)(p.Label,{htmlFor:t,className:`font-normal`,children:e.label})]},e.value)})})}var wn=o((()=>{})),Tn=s({CheckboxesField:()=>En});function En({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=(n||a.schema)?.options||[],s=Array.isArray(e)?e:e==null?[]:[e],c=(0,u.useId)();if(r)return s.length===0?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>(0,g.jsx)(p.Badge,{variant:`outline`,children:o.find(t=>t.value===e)?.label||e},e))});let l=(e,n)=>{t(n?[...s.filter(t=>t!==e),e]:s.filter(t=>t!==e))};return(0,g.jsx)(`div`,{className:i,children:o.map(e=>{let t=`${c}-${e.value}`;return(0,g.jsxs)(`div`,{className:`flex items-center space-x-2 py-0.5`,children:[(0,g.jsx)(p.Checkbox,{id:t,checked:s.includes(e.value),onCheckedChange:t=>l(e.value,!!t),disabled:a.disabled}),(0,g.jsx)(p.Label,{htmlFor:t,className:`font-normal`,children:e.label})]},e.value)})})}var Dn=o((()=>{})),On=s({TagsField:()=>kn});function kn({value:e,onChange:t,field:n,readonly:r,className:i,...a}){let o=Array.isArray(e)?e:e==null?[]:[e],[s,c]=u.default.useState(``);if(r)return o.length===0?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>(0,g.jsx)(p.Badge,{variant:`secondary`,children:e},e))});let l=e=>{let n=e.trim();!n||o.includes(n)||(t([...o,n]),c(``))},d=e=>t(o.filter(t=>t!==e));return(0,g.jsxs)(`div`,{className:(0,p.cn)(`flex flex-wrap items-center gap-1.5 rounded-md border border-input bg-background p-1.5`,i),children:[o.map(e=>(0,g.jsxs)(p.Badge,{variant:`secondary`,className:`gap-1`,children:[e,(0,g.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`ml-0.5 rounded-full text-muted-foreground hover:text-foreground`,"aria-label":`Remove ${e}`,children:`×`})]},e)),(0,g.jsx)(p.Input,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`||e.key===`,`?(e.preventDefault(),l(s)):e.key===`Backspace`&&s===``&&o.length>0&&d(o[o.length-1])},onBlur:()=>l(s),disabled:a.disabled,placeholder:o.length===0?`输入后回车添加…`:``,className:`h-7 flex-1 border-0 bg-transparent p-0 px-1 shadow-none focus-visible:ring-0 min-w-[8ch]`})]})}var An=o((()=>{})),jn=s({default:()=>Mn});function Mn({value:e}){return(0,g.jsx)(`div`,{className:`prose prose-sm max-w-none dark:prose-invert break-words`,children:(0,g.jsx)(v.default,{remarkPlugins:[y.default],rehypePlugins:[b.default],children:e})})}var Nn=o((()=>{}));Z(),ae(),je(),C(),E(),k(),N(),I(),Ve(),We(),re(),B(),H(),se(),qe(),Xe(),q(),Y(),Z(),X(),$e(),ot(),lt(),ft(),ht(),vt(),xt(),wt(),Dt(),Ut(),Kt(),Yt(),Qt(),tn(),an(),cn(),dn(),mn(),_n(),xn(),wn(),Dn(),An();var Pn=new Map;function Fn(e,t){if(!e||typeof e!=`object`)return;if(t){let n=e[t];if(typeof n==`string`&&n.trim())return n.trim();if(typeof n==`number`)return String(n)}for(let t of[`name`,`full_name`,`display_name`,`label`,`title`,`subject`,`username`]){let n=e[t];if(typeof n==`string`&&n.trim())return n.trim();if(typeof n==`number`)return String(n)}let n=e.first_name,r=e.last_name,i=[e.salutation,n,r].filter(e=>typeof e==`string`&&e.trim()).map(e=>e.trim()).join(` `);if(i)return i;let a=e.email;if(typeof a==`string`&&a.trim())return a.trim();let o=new Set([`id`,`_id`,`organization_id`,`created_by`,`updated_by`,`created_at`,`updated_at`,`tenant_id`]),s=[`_name`,`_title`,`_number`,`_code`,`_label`];for(let[t,n]of Object.entries(e))if(!o.has(t)&&!t.endsWith(`_id`)&&s.some(e=>t.endsWith(e))){if(typeof n==`string`&&n.trim())return n.trim();if(typeof n==`number`)return String(n)}}function In(e){if(typeof e!=`string`||!/^[A-Za-z0-9_-]{12,32}$/.test(e))return!1;let t=/[A-Z]/.test(e),n=/[a-z]/.test(e),r=/[0-9_-]/.test(e);return t&&n||t&&r||n&&r}function Ln(e,t){let n=u.default.useContext(h.SchemaRendererContext)?.dataSource,[,r]=u.default.useState(0),i=!!e&&!!n&&typeof n.find==`function`&&(typeof t==`string`||typeof t==`number`)&&t!==``,a=i?`${e}:${String(t)}`:``;if(u.default.useEffect(()=>{if(!i)return;let o=Pn.get(a);if(o&&o.state!==`pending`&&o.promise==null||o?.state===`pending`)return;let s=(async()=>{try{let r;if(typeof n.findOne==`function`)r=await n.findOne(e,t);else{let i=await n.find(e,{$filter:{id:t},options:{$top:1}});r=(Array.isArray(i)?i:i?.value||i?.data||[])[0]}let i=Fn(r);Pn.set(a,{state:`ok`,name:i})}catch{Pn.set(a,{state:`err`})}r(e=>e+1)})();Pn.set(a,{state:`pending`,promise:s})},[a,i,e,t,n]),!i)return;let o=Pn.get(a);return o?.state===`ok`?o.name:void 0}function Rn(){try{let{t:e}=(0,h.useObjectTranslation)();return(t,n)=>{let r=e(t);return!r||r===t?n:r}}catch{return(e,t)=>t}}function Q(e){if(e==null||typeof e==`number`||typeof e==`boolean`)return e;if(typeof e==`string`){let t=e.trim();if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return Q(JSON.parse(t))}catch{}return e}if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(e=>{if(typeof e==`object`&&e){let t=e;return String(t.name||t.label||t.externalId||t.id||t._id||`[Object]`)}return String(e)}).join(`, `);if(typeof e==`object`){let t=e;return`$numberDecimal`in t?Number(t.$numberDecimal):`$oid`in t?String(t.$oid):`$date`in t?String(t.$date):String(t.name||t.label||t.externalId||t.id||t._id||`[Object]`)}return String(e)}function zn(e,t){let n=Number.isFinite(e)&&e===Math.trunc(e)?0:2;if(!t)return Vn(e,n);try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,minimumFractionDigits:0,maximumFractionDigits:n}).format(e)}catch{return`${t} ${e.toFixed(n)}`}}function Bn(e,t){if(!t)try{return new Intl.NumberFormat(`en-US`,{notation:`compact`,maximumFractionDigits:1}).format(e).replace(/\.0(?=[KMBT])/,``)}catch{return String(e)}try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,notation:`compact`,maximumFractionDigits:1}).format(e).replace(/\.0(?=[KMBT])/,``)}catch{return`${t} ${e}`}}function Vn(e,t=2){try{return new Intl.NumberFormat(`en-US`,{minimumFractionDigits:t,maximumFractionDigits:t}).format(e)}catch{return e.toFixed(t)}}function Hn(e,t=0){return`${(0,d.percentDisplayValue)(e).toFixed(t)}%`}function Un(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Wn(e){if(e==null||e===``)return`—`;let t=e instanceof Date?e:new Date(e);if(!(t instanceof Date)||isNaN(t.getTime()))return`—`;let n=new Date,r=new Date(n.getFullYear(),n.getMonth(),n.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()-r.getTime(),a=Math.round(i/(1e3*60*60*24));if(a===0)return`Today`;if(a===1)return`Tomorrow`;if(a===-1)return`Yesterday`;if(a<-1){let e=Math.abs(a);return e<=7?`Overdue ${e}d`:Gn(t)}return a>1&&a<=7?`In ${a} days`:Gn(t)}function Gn(e,t){if(e==null||e===``)return`—`;let n=e instanceof Date?e:new Date(e);if(!(n instanceof Date)||isNaN(n.getTime()))return`—`;if(t===`short`)return`${n.toLocaleDateString(`en-US`,{month:`short`})} ${n.getDate()}, '${String(n.getFullYear()).slice(-2)}`;if(t===`relative`)return Wn(n);let r=n.getFullYear()===new Date().getFullYear();return n.toLocaleDateString(void 0,{year:r?void 0:`numeric`,month:`short`,day:`numeric`})}function Kn(e){if(e==null||e===``)return`—`;let t=e instanceof Date?e:new Date(e);return!(t instanceof Date)||isNaN(t.getTime())?`—`:t.toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function qn({value:e}){let t=Q(e);return t==null||t===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`truncate`,children:String(t)})}function Jn({value:e,field:t}){if(e==null)return(0,g.jsx)(p.EmptyValue,{});let n=Q(e),r=t.precision??0,i=Number(n);return(0,g.jsx)(`span`,{className:`tabular-nums`,children:isNaN(i)?String(n):new Intl.NumberFormat(`en-US`,{minimumFractionDigits:r,maximumFractionDigits:r}).format(i)})}function Yn({value:e,field:t}){if(e==null)return(0,g.jsx)(p.EmptyValue,{});let n=Q(e),{currency:r}=(0,f.useLocalization)(),i=(0,f.resolveFieldCurrency)(t,r),a=Number(n);return(0,g.jsx)(`span`,{className:`tabular-nums font-medium whitespace-nowrap`,children:isNaN(a)?String(n):zn(a,i)})}var Xn=/progress|completion/;function Zn({value:e,field:t}){if(e==null)return(0,g.jsx)(p.EmptyValue,{});let n=Q(e),r=t.precision??0,i=Number(n);if(isNaN(i))return(0,g.jsx)(`span`,{className:`tabular-nums whitespace-nowrap`,children:String(n)});let a=Xn.test(t?.name?.toLowerCase()||``),o=a?i:i>-1&&i<1?i*100:i,s=a?`${i.toFixed(r)}%`:Hn(i,r),c=Math.max(0,Math.min(100,o));return(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`div`,{className:`h-1.5 w-16 rounded-full bg-muted ring-1 ring-inset ring-border/60 overflow-hidden shrink-0`,role:`progressbar`,"aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100,children:(0,g.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-all`,style:{width:`${c}%`}})}),(0,g.jsx)(`span`,{className:`tabular-nums whitespace-nowrap`,children:s})]})}var Qn=new Set([`active`,`is_active`,`enabled`,`is_enabled`,`verified`,`is_verified`]);function $n({value:e,field:t}){if(e==null)return(0,g.jsx)(`span`,{className:`flex items-center justify-center`,children:(0,g.jsx)(p.EmptyValue,{})});let n=t?.name?.toLowerCase()||``;return n===`completed`||n===`is_completed`||n===`done`||n===`is_done`?(0,g.jsx)(`div`,{className:`flex items-center justify-center`,children:e?(0,g.jsx)(`div`,{className:`size-5 rounded-full bg-green-500 flex items-center justify-center`,role:`img`,"aria-label":`Completed`,"data-testid":`completion-indicator`,children:(0,g.jsx)(m.Check,{className:`size-3 text-white`})}):(0,g.jsx)(`div`,{className:`size-5 rounded-full border-2 border-muted-foreground/30`,role:`img`,"aria-label":`Not completed`,"data-testid":`completion-indicator`})}):Qn.has(n)&&!e?(0,g.jsxs)(p.Badge,{variant:`destructive`,className:`text-xs`,"data-testid":`boolean-warning-badge`,children:[t?.label||Un(n),` — Off`]}):(0,g.jsx)(`div`,{className:`flex items-center justify-start`,children:(0,g.jsx)(p.Checkbox,{checked:!!e,disabled:!0,className:`pointer-events-none`})})}function er({value:e,field:t}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let n=Q(e),r=t,i=Gn(n,r.format||`relative`),a=n==null?null:new Date(n),o=a!==null&&!isNaN(a.getTime()),s=new Date;s.setHours(0,0,0,0);let c=String(r?.name||r?.accessorKey||r?.key||``).toLowerCase(),l=(r?.dueLike===!0||/(^|_)(due|deadline|expires?|expiry|expiration|expected_close|target_close|sla|return_by|renewal|next_action)(_|$)/.test(c))&&o&&a<s,u=o?a.toISOString():String(n);return(0,g.jsx)(`span`,{className:`tabular-nums${l?` text-red-600`:``}`,title:u,children:i})}function tr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=Q(e),n=t==null?null:new Date(t);if(n===null||isNaN(n.getTime()))return(0,g.jsx)(p.EmptyValue,{});let r=n.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`,year:`numeric`}),i=n.toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`,hour12:!0}).toLowerCase();return(0,g.jsxs)(`span`,{className:`tabular-nums text-sm whitespace-nowrap`,children:[(0,g.jsx)(`span`,{children:r}),(0,g.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:i})]})}var nr={critical:`red`,urgent:`red`,high:`orange`,medium:`yellow`,normal:`blue`,low:`gray`,none:`gray`,paid:`green`,completed:`green`,done:`green`,active:`green`,approved:`green`,resolved:`green`,pending:`yellow`,waiting:`yellow`,on_hold:`yellow`,shipped:`blue`,in_progress:`blue`,open:`blue`,processing:`blue`,draft:`gray`,new:`gray`,inactive:`gray`,closed:`gray`,cancelled:`red`,canceled:`red`,rejected:`red`,failed:`red`,overdue:`red`,delivered:`purple`,archived:`indigo`,contacted:`blue`,qualified:`purple`,converted:`green`,won:`green`,lost:`red`,紧急:`red`,严重:`red`,高:`orange`,中:`yellow`,普通:`blue`,低:`gray`,无:`gray`,新建:`gray`,草稿:`gray`,待处理:`yellow`,待审核:`yellow`,待联系:`yellow`,挂起:`yellow`,进行中:`blue`,处理中:`blue`,已联系:`blue`,跟进中:`blue`,已发货:`blue`,打开:`blue`,已确认:`green`,已审核:`green`,已通过:`green`,已完成:`green`,已支付:`green`,已签收:`green`,已转化:`green`,成单:`green`,赢得:`green`,已签约:`green`,已交付:`purple`,已归档:`indigo`,已关闭:`gray`,已取消:`red`,已拒绝:`red`,失败:`red`,逾期:`red`,流失:`red`,丢失:`red`},rr={gray:`bg-gray-50 text-gray-700 border-gray-200 dark:bg-gray-800/50 dark:text-gray-200 dark:border-gray-700/60`,red:`bg-red-50 text-red-700 border-red-200 dark:bg-red-950/40 dark:text-red-300 dark:border-red-900/60`,orange:`bg-orange-50 text-orange-700 border-orange-200 dark:bg-orange-950/40 dark:text-orange-300 dark:border-orange-900/60`,yellow:`bg-yellow-50 text-yellow-800 border-yellow-200 dark:bg-yellow-950/40 dark:text-yellow-300 dark:border-yellow-900/60`,green:`bg-green-50 text-green-700 border-green-200 dark:bg-green-950/40 dark:text-green-300 dark:border-green-900/60`,blue:`bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-950/40 dark:text-blue-300 dark:border-blue-900/60`,indigo:`bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-950/40 dark:text-indigo-300 dark:border-indigo-900/60`,purple:`bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-950/40 dark:text-purple-300 dark:border-purple-900/60`,pink:`bg-pink-50 text-pink-700 border-pink-200 dark:bg-pink-950/40 dark:text-pink-300 dark:border-pink-900/60`},ir={gray:`bg-gray-400 dark:bg-gray-500`,red:`bg-red-500`,orange:`bg-orange-500`,yellow:`bg-yellow-500`,green:`bg-green-500`,blue:`bg-blue-500`,indigo:`bg-indigo-500`,purple:`bg-purple-500`,pink:`bg-pink-500`},ar=[`blue`,`green`,`purple`,`orange`,`pink`,`indigo`,`yellow`,`red`];function or(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return ar[Math.abs(t)%ar.length]}function sr(e){let t=/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.exec(e.trim());if(!t)return;let n=t[1];n.length===3&&(n=n.split(``).map(e=>e+e).join(``));let r=parseInt(n.slice(0,2),16)/255,i=parseInt(n.slice(2,4),16)/255,a=parseInt(n.slice(4,6),16)/255,o=Math.max(r,i,a),s=Math.min(r,i,a),c=o-s,l=(o+s)/2;if((c===0?0:c/(1-Math.abs(2*l-1)))<.22)return`gray`;let u;return u=o===r?((i-a)/c%6+6)%6:o===i?(a-r)/c+2:(r-i)/c+4,u*=60,u>=345||u<15?`red`:u<30?`orange`:u<60?`yellow`:u<170?`green`:u<238?`blue`:u<250?`indigo`:u<295?`purple`:`pink`}function cr(e){if(e){if(rr[e])return e;if(e.charAt(0)===`#`)return sr(e)}}function lr(e,t){let n=cr(e);if(n&&rr[n])return rr[n];if(t==null||t===``)return`bg-muted text-muted-foreground border-border`;let r=String(t).toLowerCase().replace(/[\s-]/g,`_`),i=nr[r];return i&&rr[i]?rr[i]:rr[or(r)]}function ur(e,t){let n=cr(e);if(n&&rr[n])return n;if(t==null||t===``)return;let r=String(t).toLowerCase().replace(/[\s-]/g,`_`);return nr[r]||or(r)}var dr={gray:`#6b7280`,red:`#ef4444`,orange:`#f97316`,yellow:`#eab308`,green:`#22c55e`,blue:`#3b82f6`,indigo:`#6366f1`,purple:`#a855f7`,pink:`#ec4899`};function fr(e,t=`#3b82f6`){return e?dr[e]??t:t}function pr({value:e,field:t}){let n=t,r=n.options||[],i=n.appearance===`dot`?`dot`:`badge`;if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});let a=e=>{let t=r.find(t=>t.value===e);if(t)return t;let n=String(e).toLowerCase();return r.find(e=>String(e.value).toLowerCase()===n)},o=(e,t)=>{let n=a(e),r=n?.label||Un(String(e));return i===`dot`?(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,g.jsx)(`span`,{className:(0,p.cn)(`h-1.5 w-1.5 rounded-full shrink-0`,ir[cr(n?.color)||nr[String(e).toLowerCase().replace(/[\s-]/g,`_`)]||or(String(e).toLowerCase().replace(/[\s-]/g,`_`))]||ir.gray),"aria-hidden":`true`}),(0,g.jsx)(`span`,{className:`truncate`,children:r})]},t):(0,g.jsx)(p.Badge,{variant:`outline`,className:lr(n?.color,e),children:r},t)};return Array.isArray(e)?(0,g.jsx)(`div`,{className:(0,p.cn)(`flex flex-wrap`,i===`dot`?`gap-x-3 gap-y-1`:`gap-1`),children:e.map((e,t)=>o(e,t))}):o(e)}function mr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=Rn(),n=String(Q(e)??``),[r,i]=u.default.useState(!1);return(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1 group/email`,children:[(0,g.jsx)(p.Button,{variant:`link`,className:`p-0 h-auto font-normal text-blue-600 hover:text-blue-800`,asChild:!0,children:(0,g.jsx)(`a`,{href:`mailto:${n}`,onClick:e=>e.stopPropagation(),children:n})}),(0,g.jsx)(`button`,{type:`button`,className:`opacity-0 group-hover/email:opacity-100 transition-opacity p-0.5 rounded hover:bg-muted`,onClick:e=>{e.stopPropagation(),e.preventDefault(),navigator.clipboard.writeText(n).then(()=>{i(!0),setTimeout(()=>i(!1),2e3)}).catch(()=>{})},"aria-label":t(`detail.copyEmail`,`Copy email`),children:r?(0,g.jsx)(m.Check,{className:`h-3 w-3 text-green-600`}):(0,g.jsx)(m.Copy,{className:`h-3 w-3 text-muted-foreground`})})]})}function hr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=String(Q(e)??``);return(0,g.jsx)(p.Button,{variant:`link`,className:`p-0 h-auto font-normal text-blue-600 hover:text-blue-800`,asChild:!0,children:(0,g.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:t})})}function gr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=Rn(),n=String(Q(e)??``),[r,i]=u.default.useState(!1);return(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1 group/phone`,children:[(0,g.jsxs)(`a`,{href:`tel:${n}`,className:`inline-flex items-center gap-1 text-blue-600 hover:text-blue-800`,onClick:e=>e.stopPropagation(),children:[(0,g.jsx)(m.Phone,{className:`h-3 w-3`}),n]}),(0,g.jsx)(`button`,{type:`button`,className:`opacity-0 group-hover/phone:opacity-100 transition-opacity p-0.5 rounded hover:bg-muted`,onClick:e=>{e.stopPropagation(),e.preventDefault(),navigator.clipboard.writeText(n).then(()=>{i(!0),setTimeout(()=>i(!1),2e3)}).catch(()=>{})},"aria-label":t(`detail.copyPhone`,`Copy phone number`),children:r?(0,g.jsx)(m.Check,{className:`h-3 w-3 text-green-600`}):(0,g.jsx)(m.Copy,{className:`h-3 w-3 text-muted-foreground`})})]})}function _r({value:e,field:t}){if(!e)return(0,g.jsx)(p.EmptyValue,{});if(t.multiple,Array.isArray(e)){let t=e.length;return(0,g.jsxs)(`span`,{className:`text-sm text-gray-600`,children:[t,` `,t===1?`file`:`files`]})}return(0,g.jsx)(`span`,{className:`text-sm truncate`,children:e.name||e.original_name||`File`})}function vr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});let t=e=>typeof e==`string`?e:e?.url||e?.src||e?.href||e?.thumbnailUrl||``,n=(e,t)=>e&&typeof e==`object`&&(e.name||e.original_name)||t;if(Array.isArray(e)){let r=e.map(e=>({url:t(e),name:n(e,`Image`)})).filter(e=>e.url);return r.length===0?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsxs)(`div`,{className:`flex -space-x-2`,children:[r.slice(0,3).map((e,t)=>(0,g.jsx)(`img`,{src:e.url,alt:e.name||`Image ${t+1}`,className:`size-8 rounded-md border-2 border-white object-cover`},t)),r.length>3&&(0,g.jsxs)(`div`,{className:`size-8 rounded-md border-2 border-white bg-gray-100 flex items-center justify-center text-xs font-medium text-gray-600`,children:[`+`,r.length-3]})]})}let r=t(e);return r?(0,g.jsx)(`img`,{src:r,alt:n(e,`Image`),className:`size-10 rounded-md object-cover`}):(0,g.jsx)(p.EmptyValue,{})}function yr({value:e,field:t}){let n=t.reference_to,r=(()=>{if(Array.isArray(e))return e.find(e=>e!=null&&(typeof e==`string`||typeof e==`number`)&&e!==``);if(e!=null&&e!==``&&(typeof e==`string`||typeof e==`number`)&&typeof e!=`object`)return e})(),i=Ln(n,r);if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});if(typeof e==`string`){let t=e.trim();if(t.startsWith(`{`)&&t.endsWith(`}`))try{let e=JSON.parse(t);if(e&&typeof e==`object`){let t=Fn(e)||String(e.externalId??e.id??e._id??``);if(t)return(0,g.jsx)(`span`,{className:`truncate`,children:t})}}catch{}}if(!Array.isArray(e)&&typeof e==`object`){let t=e,n=Fn(t)||String(t.id||t._id||``);if(n)return(0,g.jsx)(`span`,{className:`truncate`,children:n})}let a=t.options||[],o=e=>{if(a.length>0){let t=a.find(t=>String(t.value)===String(e));if(t)return{text:t.label,muted:!1}}return e===r&&i?{text:i,muted:!1}:In(e)?{text:`—`,muted:!0}:{text:String(e),muted:!1}};if(Array.isArray(e))return(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>{let n,r=!1;if(typeof e==`object`&&e)n=Fn(e)||String(e.id||e._id||`[Object]`);else{let t=o(e);n=t.text,r=t.muted}return(0,g.jsx)(`span`,{className:(0,p.cn)(`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium`,r?`bg-muted/40 text-muted-foreground`:`bg-gray-50 text-gray-700 dark:bg-gray-800/50 dark:text-gray-200`),children:n},t)})});if(typeof e==`object`&&e)return(0,g.jsx)(`span`,{className:`truncate`,children:Fn(e)||String(e.id||e._id||`[Object]`)});let{text:s,muted:c}=o(e);return(0,g.jsx)(`span`,{className:(0,p.cn)(`truncate`,c&&`text-muted-foreground`),children:s})}function br({value:e}){let t=Q(e);return t==null||t===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`span`,{className:`text-gray-700 font-mono text-sm`,children:String(t)})}function xr({value:e}){if(!e)return(0,g.jsx)(p.EmptyValue,{});if(typeof e!=`object`)return(0,g.jsx)(`span`,{className:`truncate`,children:String(e)});if(Array.isArray(e))return(0,g.jsxs)(`div`,{className:`flex -space-x-2`,children:[e.slice(0,3).map((e,t)=>{if(typeof e!=`object`||!e)return(0,g.jsx)(`span`,{className:`truncate text-sm`,children:String(e)},t);let n=e.name||e.username||`User`;return(0,g.jsx)(p.Avatar,{className:`size-8 border-2 border-white`,title:n,children:(0,g.jsx)(p.AvatarFallback,{className:`bg-blue-500 text-white text-xs`,children:n.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)})},t)}),e.length>3&&(0,g.jsx)(p.Avatar,{className:`size-8 border-2 border-white`,children:(0,g.jsxs)(p.AvatarFallback,{className:`bg-gray-200 text-gray-600 text-xs`,children:[`+`,e.length-3]})})]});let t=e.name||e.username||`User`;return(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(p.Avatar,{className:`size-8`,children:(0,g.jsx)(p.AvatarFallback,{className:`bg-blue-500 text-white text-xs`,children:t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)})}),(0,g.jsx)(`span`,{className:`truncate`,children:t})]})}var Sr=new Map;function Cr(e,t){Sr.set(e,t)}var wr={phone:`phone`,tel:`phone`,telephone:`phone`,email:`email`,url:`url`,uri:`url`,link:`url`,currency:`currency`,money:`currency`,percent:`percent`,percentage:`percent`},Tr=new Set([`text`,`textarea`,`string`,`longtext`,``]);function Er(e){if(!e)return`text`;if(typeof e==`string`)return e;let t=(e.type||``).toLowerCase(),n=e.format,r=typeof n==`string`?n.toLowerCase():``;return r&&wr[r]&&Tr.has(t)?wr[r]:e.type||`text`}function Dr({value:e}){if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});let t;if(typeof e==`object`)try{t=JSON.stringify(e)}catch{t=String(e)}else t=String(e);return(0,g.jsx)(`span`,{className:`font-mono text-xs text-gray-600 truncate`,title:t,children:t})}function Or({value:e}){if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});let t=String(e);return(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,g.jsx)(`span`,{className:`h-3.5 w-3.5 rounded border border-black/10 shrink-0`,style:{backgroundColor:t},"aria-hidden":`true`}),(0,g.jsx)(`span`,{className:`font-mono text-xs`,children:t})]})}var kr=u.default.lazy(()=>Promise.resolve().then(()=>(Nn(),jn)));function Ar({value:e}){return e==null||e===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(u.default.Suspense,{fallback:(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:String(e).slice(0,80)}),children:(0,g.jsx)(kr,{value:String(e)})})}function jr(e){return e.replace(/<\s*(script|style|iframe|object|embed)[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi,``).replace(/\son\w+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi,``).replace(/(href|src)\s*=\s*("javascript:[^"]*"|'javascript:[^']*')/gi,`$1="#"`)}function Mr({value:e}){return e==null||e===``?(0,g.jsx)(p.EmptyValue,{}):(0,g.jsx)(`div`,{className:`prose prose-sm max-w-none dark:prose-invert break-words`,dangerouslySetInnerHTML:{__html:jr(String(e))}})}function Nr({value:e}){if(e==null||e===``)return(0,g.jsx)(p.EmptyValue,{});let t,n;if(typeof e==`object`&&!Array.isArray(e)){let r=e;t=typeof r.lat==`number`?r.lat:typeof r.latitude==`number`?r.latitude:void 0,n=typeof r.lng==`number`?r.lng:typeof r.lon==`number`?r.lon:typeof r.longitude==`number`?r.longitude:void 0}else if(Array.isArray(e)&&e.length===2)t=Number(e[0]),n=Number(e[1]);else if(typeof e==`string`){let r=e.split(`,`).map(e=>parseFloat(e.trim()));r.length===2&&!isNaN(r[0])&&!isNaN(r[1])&&([t,n]=r)}return typeof t==`number`&&typeof n==`number`&&!isNaN(t)&&!isNaN(n)?(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-sm tabular-nums`,children:[(0,g.jsx)(m.MapPin,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),t.toFixed(4),`, `,n.toFixed(4)]}):(0,g.jsx)(Dr,{value:e,field:{}})}function Pr(e){return Sr.has(e)?Sr.get(e):{text:qn,textarea:qn,markdown:Ar,html:Mr,richtext:Ar,code:qn,qrcode:qn,number:Jn,currency:Yn,percent:Zn,progress:Zn,slider:Jn,rating:Jn,boolean:$n,toggle:$n,date:er,datetime:tr,time:qn,select:pr,status:pr,multiselect:pr,radio:pr,checkboxes:pr,tags:pr,lookup:yr,master_detail:yr,tree:yr,email:mr,url:hr,phone:gr,file:_r,video:_r,audio:_r,image:vr,avatar:vr,signature:vr,formula:br,summary:br,auto_number:qn,user:xr,owner:xr,password:()=>(0,g.jsx)(`span`,{children:`••••••`}),secret:()=>(0,g.jsx)(`span`,{children:`••••••`}),location:Nr,geolocation:Nr,address:Dr,color:Or,json:Dr,object:Dr,composite:Dr,record:Dr,repeater:({value:e})=>{let t=Array.isArray(e)?e.length:0;return t>0?(0,g.jsxs)(`span`,{className:`text-gray-500 italic`,children:[t,` 项`]}):(0,g.jsx)(p.EmptyValue,{})},vector:()=>(0,g.jsx)(`span`,{className:`text-gray-500 italic`,children:`[Vector]`}),grid:()=>(0,g.jsx)(`span`,{className:`text-gray-500 italic`,children:`[Grid]`})}[e]||qn}Cr(`lookup`,yr),Cr(`master_detail`,yr),Cr(`select`,pr),Cr(`status`,pr),Cr(`user`,xr),Cr(`owner`,xr),Oe(Pr);function Fr(e){return{text:`field:text`,textarea:`field:textarea`,markdown:`field:markdown`,html:`field:html`,richtext:`field:richtext`,secret:`field:password`,number:`field:number`,currency:`field:currency`,percent:`field:percent`,slider:`field:slider`,progress:`field:slider`,rating:`field:rating`,date:`field:date`,datetime:`field:datetime`,time:`field:time`,boolean:`field:boolean`,toggle:`field:boolean`,select:`field:select`,multiselect:`field:multiselect`,radio:`field:radio`,checkboxes:`field:checkboxes`,tags:`field:tags`,lookup:`field:lookup`,master_detail:`field:master_detail`,tree:`field:lookup`,user:`field:user`,owner:`field:owner`,email:`field:email`,phone:`field:phone`,url:`field:url`,file:`field:file`,image:`field:image`,avatar:`field:avatar`,video:`field:file`,audio:`field:file`,signature:`field:signature`,password:`field:password`,location:`field:location`,geolocation:`field:geolocation`,address:`field:address`,color:`field:color`,code:`field:code`,json:`field:code`,qrcode:`field:qrcode`,vector:`field:vector`,object:`field:object`,composite:`field:object`,record:`field:object`,repeater:`field:grid`,formula:`field:formula`,summary:`field:summary`,auto_number:`field:auto_number`}[e]||`field:text`}function Ir(e){if(e<0||!Number.isFinite(e)||e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n.toFixed(+(r>0))} ${t[r]}`}function Lr(e){let t={};return e.required&&(t.required=typeof e.required_message==`string`?e.required_message:`${e.label||e.name} is required`),e.min_length&&(t.minLength={value:e.min_length,message:e.min_length_message||`Minimum length is ${e.min_length} characters`}),e.max_length&&(t.maxLength={value:e.max_length,message:e.max_length_message||`Maximum length is ${e.max_length} characters`}),e.min!==void 0&&(t.min={value:e.min,message:e.min_message||`Minimum value is ${e.min}`}),e.max!==void 0&&(t.max={value:e.max,message:e.max_message||`Maximum value is ${e.max}`}),e.pattern&&(t.pattern={value:typeof e.pattern==`string`?new RegExp(e.pattern):e.pattern,message:e.pattern_message||`Invalid format`}),e.type===`email`&&(t.pattern={value:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,message:`Please enter a valid email address`}),e.type===`url`&&(t.pattern={value:/^https?:\/\/.+/,message:`Please enter a valid URL`}),e.validate&&(t.validate=e.validate),Object.keys(t).length>0?t:void 0}function Rr(e,t){if(!e)return!0;if(e.field&&e.value!==void 0){let n=t[e.field];if(e.operator===`=`||e.operator===`==`)return n===e.value;if(e.operator===`!=`)return n!==e.value;if(e.operator===`>`)return n>e.value;if(e.operator===`>=`)return n>=e.value;if(e.operator===`<`)return n<e.value;if(e.operator===`<=`)return n<=e.value;if(e.operator===`in`)return Array.isArray(e.value)&&e.value.includes(n)}return e.and&&Array.isArray(e.and)?e.and.every(e=>Rr(e,t)):e.or&&Array.isArray(e.or)?e.or.some(e=>Rr(e,t)):!0}function $(e){let t=({schema:t,className:n,value:r,...i})=>{let[a,o]=u.default.useState(r??t?.value??``),s={name:t?.name||`field`,label:t?.label,type:t?.type,placeholder:t?.placeholder,required:t?.required,readonly:t?.readonly||t?.readOnly,help:t?.help,description:t?.description,defaultValue:t?.defaultValue||t?.value,...t},c=u.default.useCallback(e=>{o(e),i.onChange&&i.onChange(e)},[i]),l=t?.readonly||t?.readOnly||!1;return(0,g.jsxs)(`div`,{className:`grid w-full items-center gap-1.5`,"data-obj-id":t?.id,"data-obj-type":t?.type,children:[t?.label&&(0,g.jsx)(`label`,{htmlFor:t.id,className:t.required?`after:content-['*'] after:ml-0.5 after:text-red-500`:``,children:t.label}),(0,g.jsx)(e,{value:a,onChange:c,field:s,readonly:l,className:n}),t?.description&&(0,g.jsx)(`p`,{className:`text-sm text-gray-500`,children:t.description})]})};return t.displayName=`FieldRenderer(${e.displayName||e.name||`Component`})`,t}var zr={text:()=>Promise.resolve().then(()=>(C(),x)).then(e=>({default:e.TextField})),textarea:()=>Promise.resolve().then(()=>(q(),G)).then(e=>({default:e.TextAreaField})),number:()=>Promise.resolve().then(()=>(E(),w)).then(e=>({default:e.NumberField})),boolean:()=>Promise.resolve().then(()=>(k(),D)).then(e=>({default:e.BooleanField})),select:()=>Promise.resolve().then(()=>(N(),te)).then(e=>({default:e.SelectField})),date:()=>Promise.resolve().then(()=>(I(),P)).then(e=>({default:e.DateField})),datetime:()=>Promise.resolve().then(()=>(Ve(),ze)).then(e=>({default:e.DateTimeField})),time:()=>Promise.resolve().then(()=>(We(),He)).then(e=>({default:e.TimeField})),email:()=>Promise.resolve().then(()=>(re(),ne)).then(e=>({default:e.EmailField})),phone:()=>Promise.resolve().then(()=>(B(),R)).then(e=>({default:e.PhoneField})),url:()=>Promise.resolve().then(()=>(H(),V)).then(e=>({default:e.UrlField})),multiselect:()=>Promise.resolve().then(()=>(xn(),yn)).then(e=>({default:e.MultiSelectField})),radio:()=>Promise.resolve().then(()=>(wn(),Sn)).then(e=>({default:e.RadioField})),checkboxes:()=>Promise.resolve().then(()=>(Dn(),Tn)).then(e=>({default:e.CheckboxesField})),tags:()=>Promise.resolve().then(()=>(An(),On)).then(e=>({default:e.TagsField})),currency:()=>Promise.resolve().then(()=>(se(),oe)).then(e=>({default:e.CurrencyField})),percent:()=>Promise.resolve().then(()=>(qe(),Ge)).then(e=>({default:e.PercentField})),password:()=>Promise.resolve().then(()=>(Xe(),Je)).then(e=>({default:e.PasswordField})),markdown:()=>Promise.resolve().then(()=>(Y(),ce)).then(e=>({default:e.RichTextField})),html:()=>Promise.resolve().then(()=>(Y(),ce)).then(e=>({default:e.RichTextField})),richtext:()=>Promise.resolve().then(()=>(Y(),ce)).then(e=>({default:e.RichTextField})),lookup:()=>Promise.resolve().then(()=>(Z(),Me)).then(e=>({default:e.LookupField})),master_detail:()=>Promise.resolve().then(()=>(Z(),Me)).then(e=>({default:e.LookupField})),file:()=>Promise.resolve().then(()=>($e(),Ze)).then(e=>({default:e.FileField})),image:()=>Promise.resolve().then(()=>(ot(),rt)).then(e=>({default:e.ImageField})),location:()=>Promise.resolve().then(()=>(lt(),st)).then(e=>({default:e.LocationField})),formula:()=>Promise.resolve().then(()=>(ft(),ut)).then(e=>({default:e.FormulaField})),summary:()=>Promise.resolve().then(()=>(ht(),pt)).then(e=>({default:e.SummaryField})),auto_number:()=>Promise.resolve().then(()=>(vt(),gt)).then(e=>({default:e.AutoNumberField})),user:()=>Promise.resolve().then(()=>(xt(),yt)).then(e=>({default:e.UserField})),owner:()=>Promise.resolve().then(()=>(xt(),yt)).then(e=>({default:e.UserField})),object:()=>Promise.resolve().then(()=>(wt(),St)).then(e=>({default:e.ObjectField})),vector:()=>Promise.resolve().then(()=>(Dt(),Tt)).then(e=>({default:e.VectorField})),grid:()=>Promise.resolve().then(()=>(Ut(),Ot)).then(e=>({default:e.GridField})),color:()=>Promise.resolve().then(()=>(Kt(),Wt)).then(e=>({default:e.ColorField})),slider:()=>Promise.resolve().then(()=>(Yt(),qt)).then(e=>({default:e.SliderField})),rating:()=>Promise.resolve().then(()=>(Qt(),Xt)).then(e=>({default:e.RatingField})),code:()=>Promise.resolve().then(()=>(tn(),$t)).then(e=>({default:e.CodeField})),avatar:()=>Promise.resolve().then(()=>(an(),nn)).then(e=>({default:e.AvatarField})),address:()=>Promise.resolve().then(()=>(cn(),on)).then(e=>({default:e.AddressField})),geolocation:()=>Promise.resolve().then(()=>(dn(),ln)).then(e=>({default:e.GeolocationField})),signature:()=>Promise.resolve().then(()=>(mn(),fn)).then(e=>({default:e.SignatureField})),qrcode:()=>Promise.resolve().then(()=>(_n(),hn)).then(e=>({default:e.QRCodeField}))},Br=new Set([`text`,`html`,`image`,`avatar`,`grid`,`textarea`,`select`,`email`,`password`,`slider`,`markdown`]);function Vr(e){let t=zr[e];if(!t){console.warn(`Unknown field type: ${e}`);return}let n=u.default.lazy(t);d.ComponentRegistry.register(e,n,{namespace:`field`,skipFallback:Br.has(e)})}function Hr(){Object.keys(zr).forEach(e=>{Vr(e)})}function Ur(){d.ComponentRegistry.register(`text`,$(S),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`textarea`,$(K),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`number`,$(T),{namespace:`field`}),d.ComponentRegistry.register(`boolean`,$(O),{namespace:`field`}),d.ComponentRegistry.register(`select`,$(M),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`date`,$(F),{namespace:`field`}),d.ComponentRegistry.register(`datetime`,$(Be),{namespace:`field`}),d.ComponentRegistry.register(`time`,$(Ue),{namespace:`field`}),d.ComponentRegistry.register(`email`,$(L),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`phone`,$(z),{namespace:`field`}),d.ComponentRegistry.register(`url`,$(ie),{namespace:`field`}),d.ComponentRegistry.register(`currency`,$(W),{namespace:`field`}),d.ComponentRegistry.register(`percent`,$(Ke),{namespace:`field`}),d.ComponentRegistry.register(`password`,$(Ye),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`markdown`,$(J),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`html`,$(J),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`lookup`,$(Ie),{namespace:`field`}),d.ComponentRegistry.register(`master_detail`,$(Ie),{namespace:`field`}),d.ComponentRegistry.register(`file`,$(Qe),{namespace:`field`}),d.ComponentRegistry.register(`image`,$(it),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`location`,$(ct),{namespace:`field`}),d.ComponentRegistry.register(`formula`,$(dt),{namespace:`field`}),d.ComponentRegistry.register(`summary`,$(mt),{namespace:`field`}),d.ComponentRegistry.register(`auto_number`,$(_t),{namespace:`field`}),d.ComponentRegistry.register(`user`,$(bt),{namespace:`field`}),d.ComponentRegistry.register(`owner`,$(bt),{namespace:`field`}),d.ComponentRegistry.register(`object`,$(Ct),{namespace:`field`}),d.ComponentRegistry.register(`vector`,$(Et),{namespace:`field`}),d.ComponentRegistry.register(`grid`,$(Rt),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`color`,$(Gt),{namespace:`field`}),d.ComponentRegistry.register(`slider`,$(Jt),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`rating`,$(Zt),{namespace:`field`}),d.ComponentRegistry.register(`code`,$(en),{namespace:`field`}),d.ComponentRegistry.register(`avatar`,$(rn),{namespace:`field`,skipFallback:!0}),d.ComponentRegistry.register(`address`,$(sn),{namespace:`field`}),d.ComponentRegistry.register(`geolocation`,$(un),{namespace:`field`}),d.ComponentRegistry.register(`signature`,$(pn),{namespace:`field`}),d.ComponentRegistry.register(`qrcode`,$(gn),{namespace:`field`})}Hr(),exports.AddressField=sn,exports.AutoNumberField=_t,exports.AvatarField=rn,exports.BooleanCellRenderer=$n,exports.BooleanField=O,exports.CheckboxesField=En,exports.CodeField=en,exports.ColorField=Gt,exports.ColorSwatchCellRenderer=Or,exports.CurrencyCellRenderer=Yn,exports.CurrencyField=W,exports.DateCellRenderer=er,exports.DateField=F,exports.DateTimeCellRenderer=tr,exports.DateTimeField=Be,exports.EmailCellRenderer=mr,exports.EmailField=L,exports.FileCellRenderer=_r,exports.FileField=Qe,exports.FormulaCellRenderer=br,exports.FormulaField=dt,exports.GeolocationField=un,exports.GridField=Rt,exports.HtmlCellRenderer=Mr,exports.ImageCellRenderer=vr,exports.ImageCropperDialog=tt,exports.ImageField=it,exports.JsonCellRenderer=Dr,exports.LineItemsField=Ht,exports.LocationCellRenderer=Nr,exports.LocationField=ct,exports.LookupCellRenderer=yr,exports.LookupField=Ie,exports.MarkdownCellRenderer=Ar,exports.MasterDetailField=vn,exports.MultiSelectField=bn,exports.NumberCellRenderer=Jn,exports.NumberField=T,exports.ObjectField=Ct,exports.PasswordField=Ye,exports.PercentCellRenderer=Zn,exports.PercentField=Ke,exports.PhoneCellRenderer=gr,exports.PhoneField=z,exports.QRCodeField=gn,exports.RadioField=Cn,exports.RatingField=Zt,exports.RecordPickerDialog=pe,exports.RichTextField=J,exports.SelectCellRenderer=pr,exports.SelectField=M,exports.SignatureField=pn,exports.SliderField=Jt,exports.SummaryField=mt,exports.TagsField=kn,exports.TextAreaField=K,exports.TextCellRenderer=qn,exports.TextField=S,exports.TimeField=Ue,exports.UrlCellRenderer=hr,exports.UrlField=ie,exports.UserCellRenderer=xr,exports.UserField=bt,exports.VectorField=Et,exports.buildValidationRules=Lr,exports.coerceToSafeValue=Q,exports.computeRow=Pt,exports.evalArith=Mt,exports.evaluateCondition=Rr,exports.formatCompactCurrency=Bn,exports.formatCurrency=zn,exports.formatDate=Gn,exports.formatDateTime=Kn,exports.formatFileSize=Ir,exports.formatNumber=Vn,exports.formatPercent=Hn,exports.formatRelativeDate=Wn,exports.getBadgeColorClasses=lr,exports.getCellRenderer=Pr,exports.getSemanticColorName=ur,exports.getSemanticHex=fr,exports.humanizeLabel=Un,exports.isLikelyOpaqueId=In,exports.lookupAutofillPatch=Nt,exports.lookupFiltersToRecord=de,exports.mapFieldTypeToFormType=Fr,exports.registerAllFields=Hr,exports.registerField=Vr,exports.registerFieldRenderer=Cr,exports.registerFields=Ur,exports.resolveCellRendererType=Er,Object.defineProperty(exports,"resolveFieldCurrency",{enumerable:!0,get:function(){return f.resolveFieldCurrency}}),exports.sumColumn=Lt;
|
package/dist/index.js
CHANGED
|
@@ -2305,75 +2305,23 @@ function zn({ value: e, field: t, ...n }) {
|
|
|
2305
2305
|
});
|
|
2306
2306
|
}
|
|
2307
2307
|
var Bn = Z((() => {})), Vn = /* @__PURE__ */ Q({ UserField: () => Hn });
|
|
2308
|
-
function Hn(
|
|
2309
|
-
let
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
children: /* @__PURE__ */ Y(_, {
|
|
2321
|
-
className: "bg-blue-500 text-white text-xs",
|
|
2322
|
-
children: n.split(" ").map((e) => e[0]).join("").toUpperCase().slice(0, 2)
|
|
2323
|
-
})
|
|
2324
|
-
}, t);
|
|
2325
|
-
}), t.length > 3 && /* @__PURE__ */ Y(g, {
|
|
2326
|
-
className: "size-8 border-2 border-white",
|
|
2327
|
-
children: /* @__PURE__ */ X(_, {
|
|
2328
|
-
className: "bg-gray-200 text-gray-600 text-xs",
|
|
2329
|
-
children: ["+", t.length - 3]
|
|
2330
|
-
})
|
|
2331
|
-
})]
|
|
2332
|
-
});
|
|
2333
|
-
}
|
|
2334
|
-
let o = e ? Array.isArray(e) ? e : [e] : [], s = (e) => {
|
|
2335
|
-
if (a) {
|
|
2336
|
-
let n = o.filter((t, n) => n !== e);
|
|
2337
|
-
t(n.length > 0 ? n : null);
|
|
2338
|
-
} else t(null);
|
|
2339
|
-
};
|
|
2340
|
-
return /* @__PURE__ */ X("div", {
|
|
2341
|
-
className: i.className,
|
|
2342
|
-
children: [o.length > 0 && /* @__PURE__ */ Y("div", {
|
|
2343
|
-
className: "flex flex-wrap gap-2 mb-2",
|
|
2344
|
-
children: o.map((e, t) => {
|
|
2345
|
-
let n = e.name || e.username || "User";
|
|
2346
|
-
return /* @__PURE__ */ X(y, {
|
|
2347
|
-
variant: "outline",
|
|
2348
|
-
className: "gap-2 pr-1",
|
|
2349
|
-
children: [
|
|
2350
|
-
/* @__PURE__ */ Y(g, {
|
|
2351
|
-
className: "size-5",
|
|
2352
|
-
children: /* @__PURE__ */ Y(_, {
|
|
2353
|
-
className: "bg-blue-500 text-white text-xs",
|
|
2354
|
-
children: n.split(" ").map((e) => e[0]).join("").toUpperCase().slice(0, 2)
|
|
2355
|
-
})
|
|
2356
|
-
}),
|
|
2357
|
-
/* @__PURE__ */ Y("span", {
|
|
2358
|
-
className: "text-sm",
|
|
2359
|
-
children: n
|
|
2360
|
-
}),
|
|
2361
|
-
/* @__PURE__ */ Y("button", {
|
|
2362
|
-
type: "button",
|
|
2363
|
-
onClick: () => s(t),
|
|
2364
|
-
className: "ml-1 rounded-full hover:bg-gray-200 p-0.5",
|
|
2365
|
-
children: /* @__PURE__ */ Y(Fe, { className: "size-3" })
|
|
2366
|
-
})
|
|
2367
|
-
]
|
|
2368
|
-
}, t);
|
|
2369
|
-
})
|
|
2370
|
-
}), /* @__PURE__ */ Y("div", {
|
|
2371
|
-
className: "text-sm text-gray-500 italic",
|
|
2372
|
-
children: "User selection component requires integration with user management system"
|
|
2373
|
-
})]
|
|
2308
|
+
function Hn(e) {
|
|
2309
|
+
let t = e.field || e.schema, n = t?.field && typeof t.field == "object" && ("reference" in t.field || "reference_to" in t.field || "type" in t.field), r = n ? t.field : t, i = {
|
|
2310
|
+
...r || {},
|
|
2311
|
+
reference: r?.reference || r?.reference_to || "sys_user",
|
|
2312
|
+
display_field: r?.display_field || r?.displayField || r?.reference_field || "name"
|
|
2313
|
+
}, a = n ? {
|
|
2314
|
+
...t,
|
|
2315
|
+
field: i
|
|
2316
|
+
} : i;
|
|
2317
|
+
return /* @__PURE__ */ Y(nn, {
|
|
2318
|
+
...e,
|
|
2319
|
+
field: a
|
|
2374
2320
|
});
|
|
2375
2321
|
}
|
|
2376
|
-
var Un = Z((() => {
|
|
2322
|
+
var Un = Z((() => {
|
|
2323
|
+
on();
|
|
2324
|
+
})), Wn = /* @__PURE__ */ Q({ ObjectField: () => Gn });
|
|
2377
2325
|
function Gn({ value: e, onChange: t, field: n, readonly: r, ...i }) {
|
|
2378
2326
|
let o = n || i.schema, [s, c] = l(() => e == null ? "" : JSON.stringify(e, null, 2)), [u, d] = l(null);
|
|
2379
2327
|
return a(() => {
|
|
@@ -4774,6 +4722,8 @@ function ra(e) {
|
|
|
4774
4722
|
lookup: "field:lookup",
|
|
4775
4723
|
master_detail: "field:master_detail",
|
|
4776
4724
|
tree: "field:lookup",
|
|
4725
|
+
user: "field:user",
|
|
4726
|
+
owner: "field:owner",
|
|
4777
4727
|
email: "field:email",
|
|
4778
4728
|
phone: "field:phone",
|
|
4779
4729
|
url: "field:url",
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { FieldWidgetProps } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* UserField
|
|
5
|
-
*
|
|
4
|
+
* UserField — person picker for the `user` field type.
|
|
5
|
+
*
|
|
6
|
+
* `user` is a lookup specialized to the `sys_user` system object (see framework
|
|
7
|
+
* "lookup → sys_user" specialization). Rather than re-implement candidate search,
|
|
8
|
+
* the searchable picker, the record-picker dialog and id resolution, this widget
|
|
9
|
+
* **delegates to the shared {@link LookupField}** with the reference fixed to
|
|
10
|
+
* `sys_user`. The author writes `Field.user({ multiple })`; we normalise the field
|
|
11
|
+
* metadata so the lookup machinery targets users with a sensible display field.
|
|
12
|
+
*
|
|
13
|
+
* Table-cell display (avatars / initials) is handled separately by
|
|
14
|
+
* `UserCellRenderer`; this is the form/editor widget.
|
|
6
15
|
*/
|
|
7
|
-
export declare function UserField(
|
|
16
|
+
export declare function UserField(props: FieldWidgetProps<any>): React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/fields",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "Field renderers and registry for Object UI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"rehype-sanitize": "^6.0.0",
|
|
31
31
|
"remark-gfm": "^4.0.1",
|
|
32
32
|
"tailwind-merge": "^3.6.0",
|
|
33
|
-
"@object-ui/components": "
|
|
34
|
-
"@object-ui/core": "
|
|
35
|
-
"@object-ui/i18n": "
|
|
36
|
-
"@object-ui/providers": "
|
|
37
|
-
"@object-ui/react": "
|
|
38
|
-
"@object-ui/types": "
|
|
33
|
+
"@object-ui/components": "11.0.0",
|
|
34
|
+
"@object-ui/core": "11.0.0",
|
|
35
|
+
"@object-ui/i18n": "11.0.0",
|
|
36
|
+
"@object-ui/providers": "11.0.0",
|
|
37
|
+
"@object-ui/react": "11.0.0",
|
|
38
|
+
"@object-ui/types": "11.0.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "^18.0.0 || ^19.0.0",
|
package/src/index.tsx
CHANGED
|
@@ -1656,6 +1656,11 @@ export function mapFieldTypeToFormType(fieldType: string): string {
|
|
|
1656
1656
|
lookup: 'field:lookup',
|
|
1657
1657
|
master_detail: 'field:master_detail',
|
|
1658
1658
|
tree: 'field:lookup', // hierarchical reference — pick the parent via a lookup
|
|
1659
|
+
// `user` is a lookup specialized to sys_user; `owner` mirrors it (record
|
|
1660
|
+
// ownership). Both render via the UserField person-picker (delegates to the
|
|
1661
|
+
// lookup picker). Without these they would fall through to `field:text`.
|
|
1662
|
+
user: 'field:user',
|
|
1663
|
+
owner: 'field:owner',
|
|
1659
1664
|
|
|
1660
1665
|
// Contact fields
|
|
1661
1666
|
email: 'field:email',
|
|
@@ -1,88 +1,39 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Avatar, AvatarFallback, Badge, EmptyValue } from '@object-ui/components';
|
|
3
|
-
import { X } from 'lucide-react';
|
|
4
2
|
import { FieldWidgetProps } from './types';
|
|
3
|
+
import { LookupField } from './LookupField';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
|
-
* UserField
|
|
8
|
-
*
|
|
6
|
+
* UserField — person picker for the `user` field type.
|
|
7
|
+
*
|
|
8
|
+
* `user` is a lookup specialized to the `sys_user` system object (see framework
|
|
9
|
+
* "lookup → sys_user" specialization). Rather than re-implement candidate search,
|
|
10
|
+
* the searchable picker, the record-picker dialog and id resolution, this widget
|
|
11
|
+
* **delegates to the shared {@link LookupField}** with the reference fixed to
|
|
12
|
+
* `sys_user`. The author writes `Field.user({ multiple })`; we normalise the field
|
|
13
|
+
* metadata so the lookup machinery targets users with a sensible display field.
|
|
14
|
+
*
|
|
15
|
+
* Table-cell display (avatars / initials) is handled separately by
|
|
16
|
+
* `UserCellRenderer`; this is the form/editor widget.
|
|
9
17
|
*/
|
|
10
|
-
export function UserField(
|
|
11
|
-
const
|
|
12
|
-
const multiple = userField?.multiple || false;
|
|
18
|
+
export function UserField(props: FieldWidgetProps<any>) {
|
|
19
|
+
const raw = (props.field || (props as any).schema) as any;
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{users.slice(0, 3).map((user: any, idx: number) => {
|
|
21
|
-
const name = user.name || user.username || 'User';
|
|
22
|
-
const initials = name.split(' ').map((n: string) => n[0]).join('').toUpperCase().slice(0, 2);
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Avatar key={idx} className="size-8 border-2 border-white" title={name}>
|
|
26
|
-
<AvatarFallback className="bg-blue-500 text-white text-xs">
|
|
27
|
-
{initials}
|
|
28
|
-
</AvatarFallback>
|
|
29
|
-
</Avatar>
|
|
30
|
-
);
|
|
31
|
-
})}
|
|
32
|
-
{users.length > 3 && (
|
|
33
|
-
<Avatar className="size-8 border-2 border-white">
|
|
34
|
-
<AvatarFallback className="bg-gray-200 text-gray-600 text-xs">
|
|
35
|
-
+{users.length - 3}
|
|
36
|
-
</AvatarFallback>
|
|
37
|
-
</Avatar>
|
|
38
|
-
)}
|
|
39
|
-
</div>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
21
|
+
// The objectSchema field metadata may live directly on `field`, or nested at
|
|
22
|
+
// `field.field` when rendered via the createFieldRenderer wrapper — mirror the
|
|
23
|
+
// unwrap LookupField itself performs.
|
|
24
|
+
const metaIsNested = raw?.field && typeof raw.field === 'object'
|
|
25
|
+
&& ('reference' in raw.field || 'reference_to' in raw.field || 'type' in raw.field);
|
|
26
|
+
const meta = metaIsNested ? raw.field : raw;
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} else {
|
|
50
|
-
onChange(null);
|
|
51
|
-
}
|
|
28
|
+
// Ensure the picker always targets sys_user (even if the author omitted an
|
|
29
|
+
// explicit reference) and presents user names by default.
|
|
30
|
+
const normalized = {
|
|
31
|
+
...(meta || {}),
|
|
32
|
+
reference: meta?.reference || meta?.reference_to || 'sys_user',
|
|
33
|
+
display_field: meta?.display_field || meta?.displayField || meta?.reference_field || 'name',
|
|
52
34
|
};
|
|
53
35
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
<div className="flex flex-wrap gap-2 mb-2">
|
|
58
|
-
{users.map((user: any, idx: number) => {
|
|
59
|
-
const name = user.name || user.username || 'User';
|
|
60
|
-
const initials = name.split(' ').map((n: string) => n[0]).join('').toUpperCase().slice(0, 2);
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<Badge key={idx} variant="outline" className="gap-2 pr-1">
|
|
64
|
-
<Avatar className="size-5">
|
|
65
|
-
<AvatarFallback className="bg-blue-500 text-white text-xs">
|
|
66
|
-
{initials}
|
|
67
|
-
</AvatarFallback>
|
|
68
|
-
</Avatar>
|
|
69
|
-
<span className="text-sm">{name}</span>
|
|
70
|
-
<button
|
|
71
|
-
type="button"
|
|
72
|
-
onClick={() => handleRemove(idx)}
|
|
73
|
-
className="ml-1 rounded-full hover:bg-gray-200 p-0.5"
|
|
74
|
-
>
|
|
75
|
-
<X className="size-3" />
|
|
76
|
-
</button>
|
|
77
|
-
</Badge>
|
|
78
|
-
);
|
|
79
|
-
})}
|
|
80
|
-
</div>
|
|
81
|
-
)}
|
|
82
|
-
|
|
83
|
-
<div className="text-sm text-gray-500 italic">
|
|
84
|
-
User selection component requires integration with user management system
|
|
85
|
-
</div>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
36
|
+
const fieldProp = metaIsNested ? { ...raw, field: normalized } : normalized;
|
|
37
|
+
|
|
38
|
+
return <LookupField {...(props as any)} field={fieldProp} />;
|
|
88
39
|
}
|