@gisce/react-ooui 1.5.8 → 1.5.9

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.
@@ -36,7 +36,7 @@
36
36
  .ant-input {
37
37
  background-color: ${vn.colorPrimaryBg};
38
38
  }
39
- `,Cn=Ke.default.createContext(null),qa=({children:t,initialView:r})=>{const[n,s]=l.useState(r),[o,i]=l.useState(0),[a,c]=l.useState(!1);return e.jsx(Cn.Provider,{value:{currentView:n,setCurrentView:s,itemIndex:o,setItemIndex:i,manualTriggerChange:a,setManualTriggerChange:c},children:t})},{getValueForOperator:bn}=se.graphProcessor,It=.7,At=30,xn=t=>{const{model:r,domain:n,context:s,colorCondition:o,totalDomain:i,showPercent:a=!1,icon:c,suffix:h,field:d,operator:u,manualIds:f}=t,[g,w]=l.useState(!1),[y,m]=l.useState(),[v,S]=l.useState(),[T,E]=l.useState(),[b,V]=l.useState(0),[F,L]=l.useState(0),[x,O]=l.useState(),[_,C]=l.useState(),[P,I]=l.useState();l.useEffect(()=>{A()},[r,o]);async function D({domain:M,isTotal:N}){if(N)return await $({domain:M});if(d&&u){const k=f||await K.getHandler().searchAllIds({params:M,model:r,context:s}),Y=await K.getHandler().readObjects({model:r,ids:k,fieldsToRetrieve:[d],context:s});return bn({values:Y.map(z=>z[d]),operator:u})}else return f?f.length:await K.getHandler().searchCount({model:r,params:M,context:s})}async function $({domain:M}){if(d&&u){const N=await K.getHandler().searchAllIds({params:M,model:r,context:s}),k=await K.getHandler().readObjects({model:r,ids:N,fieldsToRetrieve:[d],context:s});return bn({values:k.map(Y=>Y[d]),operator:u})}else return await K.getHandler().searchCount({model:r,params:M,context:s})}async function A(){w(!0);let M,N;try{const k=await D({domain:n,isTotal:!1});if(m(k),i){const Y=await K.getHandler().evalDomain({domain:i,values:{},context:s});M=await D({domain:Y,isTotal:!0}),E(M)}if(M?(N=Math.round(k/M*100*100)/100,S(N)):S(0),o){const Y=await K.getHandler().parseCondition({condition:o,values:{value:k,percent:N},context:s});O(Y)}if(c)if(c.indexOf(":")!==-1){const Y=await K.getHandler().parseCondition({condition:c,values:{value:k,percent:N},context:s});C(Y)}else C(c)}catch(k){I(JSON.stringify(k))}w(!1)}return P?e.jsx(p.Alert,{className:"mt-10",message:P,type:"error",banner:!0}):g?e.jsx("div",{style:{padding:"1rem"},children:e.jsx(H.LoadingOutlined,{style:{height:"12px"}})}):e.jsx(Yt.default,{bounds:!0,onResize:M=>{var N,k;V((N=M.bounds)==null?void 0:N.height),L((k=M.bounds)==null?void 0:k.width)},children:({measureRef:M})=>a?e.jsx(Ga,{value:y,total:T,percent:v,measureRef:M,height:b,width:F,color:x,icon:_,suffix:h}):e.jsx(Ua,{value:y,total:T,measureRef:M,height:b,width:F,color:x,icon:_,suffix:h})})};function Tn(t,r){const s=document.createElement("canvas").getContext("2d");return s.font=r||getComputedStyle(document.body).font,s.measureText(t).width}function Ua({measureRef:t,width:r,height:n,total:s,value:o,color:i,icon:a,suffix:c}){let h=n*It<At?At:n*It;const d=o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0});let u=s?`${d}/${s}`:`${d}`;c&&(u+=" "+c);let f=Tn(u,`bold ${Math.floor(h*1.03)}px sans-serif`);a&&(f=f*2),f>=r*.85&&(h=r*.85/f*h);const g=a&&Je(a,{style:{fontSize:h*.7}});return e.jsx("div",{ref:t,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden"},children:e.jsxs(qt.default,{style:{fontSize:h,margin:0,color:i},children:[g&&e.jsx(g,{style:{fontSize:h*.7}}),g?` ${u}`:u]})})}function Ga({measureRef:t,height:r,width:n,percent:s,total:o,value:i,color:a,icon:c,suffix:h}){const d=r*.65;let u=d*It<At?At:d*It;const f=i==null?void 0:i.toLocaleString("es-ES",{useGrouping:!0});let g=o?`${f}/${o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0})}`:`${f}`;h&&(g+=" "+h);const w=`${s==null?void 0:s.toLocaleString("es-ES",{useGrouping:!0})}%`;let y=Tn(w,`bold ${Math.floor(u*1.03)}px sans-serif`);c&&(y=y*1.5),(y>=n*.85||u*2<d)&&(u=n*.85/y*u);const m=c&&Je(c,{style:{fontSize:u}});return e.jsx("div",{ref:t,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexDirection:"column",padding:"0.2rem"},children:e.jsxs(p.Row,{align:"middle",children:[m&&e.jsx(p.Col,{style:{fontSize:u*1,color:a,paddingRight:"10px"},children:e.jsx(m,{})}),e.jsxs(p.Col,{children:[e.jsx(qt.default,{style:{fontSize:u*.8,margin:0,color:a},children:m?` ${s}%`:`${s}%`}),e.jsx(qt.default,{style:{fontSize:u*.4,margin:0,color:a,textAlign:"center"},children:g})]})]})})}const nr=t=>r=>{const n=r.value.toLocaleString("es-ES",{useGrouping:!0});return{name:t==="pie"?r.x:r.type,value:n}},$t=t=>{if(typeof t=="string"&&ja(t))return parseFloat(t).toLocaleString("es-ES",{useGrouping:!0});if(za(t))return t.toLocaleString("es-ES",{useGrouping:!0});if(Ja(t)){const r=Za(t);return r===null?t:Ze(t,Lt.input[r]).format(Lt.output[r])}else return t},ja=t=>/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(t),za=t=>typeof t=="number"&&!isNaN(t),Fn={default:{padding:"auto",xAxis:{tickCount:5,label:{formatter:$t}},yAxis:{label:{formatter:$t}},legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:nr("default")}},pie:{appendPadding:10,radius:.9,label:{type:"inner",offset:"-30%",content:({percent:t})=>`${(t*100).toFixed(0)}%`,style:{fontSize:14,textAlign:"center"}},legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:nr("pie")},interactions:[{type:"element-active"}]},barGrouped:{isGroup:!0,legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:nr("barGrouped")},xAxis:{label:{formatter:$t}},yAxis:{label:{formatter:$t}},label:{position:"middle",layout:[{type:"interval-adjust-position"},{type:"interval-hide-overlap"},{type:"adjust-color"}]}}};function Ja(t){return typeof t!="string"||t===void 0?!1:new Date(t).toString()!=="Invalid Date"}const Lt={input:{hours:"YYYY-MM-DD HH:mm",days:"YYYY-MM-DD",weeks:"YYYY-[W]WW",months:"YYYY-MM",years:"YYYY"},output:{hours:"DD/MM/YYYY HH:mm",days:"DD/MM/YYYY",weeks:"[W]WW/YYYY",months:"MM/YYYY",years:"YYYY"}};function Za(t){for(const r in Lt.input)if(Ze(t,Lt.input[r],!0).isValid())return r;return null}const{processGraphData:Xa}=se.graphProcessor,{getFieldsToRetrieve:Qa}=se.graphFieldUtils,Ra=t=>{const{model:r,domain:n=[],context:s={},xml:o,limit:i,uninformedString:a,manualIds:c}=t,[h,d]=l.useState(!1),[u,f]=l.useState(),[g,w]=l.useState(),[y,m]=l.useState(),[v,S]=l.useState("line");return tt.default(()=>{(async()=>{d(!0),f(void 0);const T=se.parseGraph(o);S(T.type||"line");const E=Qa({ooui:T});let b,V;try{({values:b,fields:V}=await tl({model:r,domain:n,context:s,limit:i,order:T.timerange?T.x.name:null,fields:E,manualIds:c}))}catch(F){f("Error fetching graph data values: "+JSON.stringify(F)),d(!1);return}try{if(!b||!V){f("No values or fields returned"),d(!1);return}m(b);const F=Xa({ooui:T,values:b,fields:V,options:{uninformedString:a}});w(F)}catch(F){f("Error processing graph data: "+F),d(!1);return}d(!1)})()},[o,r,i,s,n]),{loading:h,error:u,type:v,values:g,evaluatedEntries:y}};async function el({model:t,context:r,fields:n}){return await K.getHandler().getFields({model:t,context:r,fields:n})}async function tl({fields:t,model:r,domain:n,context:s,order:o,limit:i,manualIds:a}){const c=await el({model:r,context:s,fields:t});if(a){let d=await K.getHandler().readObjects({model:r,ids:a,fieldsToRetrieve:t,context:s});return o&&(d=[...d].sort((u,f)=>u[o]-f[o])),{values:d,fields:c}}return{values:await K.getHandler().search({model:r,params:n,fields:t,context:s,limit:i,order:o}),fields:c}}const rl={line:Wt.Line,bar:Wt.Column,pie:Wt.Pie},nl=t=>{var S;const{model:r,domain:n,context:s,xml:o,limit:i,manualIds:a}=t,{t:c}=l.useContext(he),{error:h,loading:d,values:u,type:f,evaluatedEntries:g}=Ra({model:r,xml:o,limit:i,domain:n,context:s,uninformedString:c("uninformed"),manualIds:a});if(h)return e.jsx(p.Alert,{message:h,type:"error",banner:!0});if(d)return e.jsx(p.Spin,{});if(!u)return e.jsx(p.Alert,{message:"No data to display",type:"info"});const{data:w,isGroup:y,isStack:m}=u,v=rl[f];return v?e.jsxs("div",{style:{padding:"1rem"},children:[e.jsx("p",{style:{textAlign:"right"},children:`${c("totalRegisters")} ${(S=g==null?void 0:g.length)==null?void 0:S.toLocaleString("es-ES",{useGrouping:!0})}`}),e.jsx(v,{...ol({type:f,data:w,isGroup:y,isStack:m})})]}):e.jsx(e.Fragment,{children:`Unknown graph type: ${f}`})};function ol(t){const{type:r,data:n,isGroup:s,isStack:o}=t;let i=Fn[r];return i||(i=Fn.default),i.data=n,r==="pie"?(i.colorField="x",i.angleField="value"):(i.xField="x",i.yField="value",i.seriesField="type",i.isGroup=s,o&&(i.isStack=!0,i.groupField="stacked")),i}const sl=(t,r)=>{const{view_id:n,model:s,context:o,domain:i,limit:a,manualIds:c}=t,[h,d]=l.useState(!1),[u,f]=l.useState(),[g,w]=l.useState(),y=l.useContext(Ge),{setGraphIsLoading:m=void 0}=y||{};l.useImperativeHandle(r,()=>({refresh:()=>{v()}})),l.useEffect(()=>{v()},[n]);async function v(){d(!0),m==null||m(!0);try{const S=await K.getHandler().getView({model:s,id:n,type:"graph",context:o});w(S.arch);const T=se.parseGraph(S.arch);f(T)}catch(S){return console.error(S),e.jsx(e.Fragment,{children:JSON.stringify(S)})}d(!1),m==null||m(!1)}if(h)return e.jsx("div",{style:{width:"100%",display:"flex",height:"20%",justifyContent:"center",alignContent:"center",padding:"1rem"},children:e.jsx(H.LoadingOutlined,{style:{height:"12px"}})});if(!u)return null;switch(u.type){case"indicatorField":case"indicator":{const S=u,T=S.type==="indicatorField"?{field:S.field,operator:S.operator}:{};return e.jsx(xn,{showPercent:S.showPercent,totalDomain:S.totalDomain,colorCondition:S.color,model:s,context:o,domain:i,icon:S.icon,suffix:S.suffix,manualIds:c,...T})}case"line":case"bar":case"pie":return e.jsx(nl,{model:s,context:o,domain:i,xml:g,limit:a,manualIds:c});default:return e.jsx(e.Fragment,{children:`Graph ${u.type} not implemented`})}},Nt=l.forwardRef(sl),{confirm:il}=p.Modal,al=({onOk:t,lang:r})=>{il({title:xe("removeItems",r),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:xe("confirmRemove",r),okText:xe("yesConfirmRemove",r),onOk:t,cancelText:xe("cancel",r)})},{confirm:ll}=p.Modal,cl=({onOk:t,lang:r})=>{ll({title:xe("unlinkItems",r),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:xe("confirmUnlink",r),okText:xe("yesConfirmUnlink",r),onOk:t,cancelText:xe("cancel",r)})},{useToken:dl}=p.theme,ul=t=>{const{title:r,readOnly:n,onCreateItem:s,onToggleViewMode:o,mode:i,onDelete:a,totalItems:c,currentItemIndex:h,onPreviousItem:d,onNextItem:u,isMany2Many:f,onSearchItem:g,selectedRowKeys:w,showCreateButton:y,showToggleButton:m}=t,{token:v}=dl();function S(){return e.jsx("div",{className:"inline-block w-3"})}function T(){return e.jsx("div",{className:"flex flex-grow h-8 text-white",style:{borderRadius:v.borderRadius,backgroundColor:v.colorPrimaryActive},children:e.jsx("div",{className:"flex flex-col items-center justify-center h-full",children:e.jsx("span",{className:"pl-2 font-bold",children:r})})})}function E(){return e.jsx(We,{tooltip:f?"Unlink":"Delete",icon:f?e.jsx(H.ApiOutlined,{}):e.jsx(H.DeleteOutlined,{}),onClick:a,disabled:c===0||n||i!=="form"&&w.length===0})}function b(){let F="_";return c===0?F="_":F=(h+1).toString(),e.jsxs("span",{className:"pl-1 pr-1",children:["(",F,"/",c,")"]})}function V(){return e.jsxs(e.Fragment,{children:[S(),e.jsx(We,{tooltip:"Previous item",icon:e.jsx(H.LeftOutlined,{}),onClick:d}),b(),e.jsx(We,{tooltip:"Next item",icon:e.jsx(H.RightOutlined,{}),onClick:u})]})}return e.jsxs("div",{className:"flex mb-2",children:[T(),e.jsxs("div",{className:"flex-none h-8 pl-2",children:[i!=="graph"&&y&&e.jsx(We,{tooltip:"Create new item",icon:e.jsx(H.FileAddOutlined,{}),disabled:n,onClick:s}),f&&y&&e.jsx(We,{tooltip:"Search existing item",icon:e.jsx(H.SearchOutlined,{}),disabled:n,onClick:g}),i!=="graph"&&S(),i!=="graph"&&E(),i==="form"&&V(),S(),m&&e.jsx(We,{tooltip:"Toggle view mode",icon:e.jsx(H.AlignLeftOutlined,{}),onClick:o})]})]})},fl={form:se.Form,tree:se.Tree,graph:Nt};function hl(t){const r=t.map(s=>s.id);return t.filter((s,o)=>{const{id:i}=s;return!r.includes(i,o+1)})}const pl=t=>{var Le;const{value:r,onChange:n,ooui:s,views:o}=t,{items:i=[]}=r||{},{currentView:a,setCurrentView:c,itemIndex:h,setItemIndex:d}=l.useContext(Cn),u=l.useContext(De),{activeId:f,getFields:g,getValues:w,getContext:y,domain:m}=u||{},{lang:v,t:S}=l.useContext(he),[T,E]=l.useState(!1),[b,V]=l.useState(!1),[F,L]=l.useState(),[x,O]=l.useState(!1),[_,C]=l.useState(!1),[P,I]=l.useState(),[D,$]=l.useState([]),[A,M]=l.useState(!1),N=l.useRef([]),[k,Y]=l.useState(),z=l.useRef(),[j,U]=l.useState(void 0),{readOnly:Z,relation:B,context:W,domain:R}=s,re=s.type==="many2many",{id:ce}=s,X=i.filter(ee=>(ee.values||ee.treeValues)&&ee.operation!=="pendingRemove"),Q=l.useRef();l.useEffect(()=>{if(Q.current!==a){Q.current=a,ue();return}ue()},[i,a]);const ue=l.useCallback(()=>{(a==="form"&&i.some(ee=>!ee.values)||a==="tree"&&i.some(ee=>!ee.treeValues))&&ke()},[i,a]);l.useEffect(()=>{Ee()},[m]);const pe=ee=>{var le,Ce;n==null||n({fields:((le=o.get("form"))==null?void 0:le.fields)||((Ce=o.get("tree"))==null?void 0:Ce.fields),items:hl(ee)})},ke=async()=>{await Fe(),h>X.length-1&&h!==0&&d(0)},Fe=async ee=>{var le,Ce,ye;V(!0),E(!1),L(void 0);try{const[be,Te]=await Jt({treeView:{arch:(le=o.get("tree"))==null?void 0:le.arch,fields:(Ce=o.get("tree"))==null?void 0:Ce.fields},formView:{fields:((ye=o.get("form"))==null?void 0:ye.fields)||{}},model:B,items:i,context:{...y==null?void 0:y(),...W},currentView:ee||a});return z.current||(z.current=be.map(je=>je.id)),(a||ee)==="tree"&&Te&&U(Te),pe(be),be}catch(be){L(be)}finally{V(!1)}};async function Ee(){R&&(N.current=await K.getHandler().evalDomain({domain:R,values:dt({fields:g(),values:w()}),fields:g(),context:y()})),m&&m.length>0&&(N.current=N.current.concat(se.transformDomainForChildWidget({domain:m,widgetFieldName:ce})))}const Be=()=>{const ee=Array.from(o.keys()),le=ee[(ee.indexOf(a)+1)%ee.length];a==="form"?ve(()=>{c(le)}):c(le)},Se=()=>{h>0&&(a==="form"?ve(()=>{d(h-1)}):d(h-1))},ie=()=>{const ee=X.length;h<ee-1&&(a==="form"?ve(()=>{d(h+1)}):d(h+1))},Me=async()=>{const ee=X[h].id,le=(await K.getHandler().readObjects({model:B,ids:[ee],fields:o.get("form").fields,context:{...y==null?void 0:y(),...W}}))[0],Ce=(await K.getHandler().readObjects({model:B,ids:[ee],fields:o.get("tree").fields,context:{...y==null?void 0:y(),...W}}))[0],ye=i.map(be=>be.id===ee?{...be,operation:"original",values:le,treeValues:Ce}:be);pe(ye)},ve=ee=>{T?St({lang:v,onOk:()=>{Me(),ee(),E(!1)}}):ee()},Ve=()=>{if(re){cl({lang:v,onOk:()=>{a==="form"?we():_e()}});return}al({lang:v,onOk:()=>{a==="form"?we():_e()}})},$e=async()=>{const{inv_field:ee}=s;let le;ee&&f&&(le={[ee]:f}),a==="form"?ve(()=>{M(!0),I({defaultValues:le}),O(!0)}):(M(!0),I({defaultValues:le}),O(!0))},te=async()=>{a==="form"?ve(()=>{C(!0)}):C(!0)},we=async()=>{V(!0),E(!1),L(void 0);try{if(X[h].id>0){const ee=i.map(le=>le.id===X[h].id?{...le,operation:"pendingRemove"}:le);pe(ee)}else pe(i.filter(ee=>ee.id!==X[h].id))}catch(ee){L(ee)}d(0),V(!1)},_e=async()=>{const ee=X.filter(le=>D.includes(le.id));V(!0),E(!1),L(void 0);try{const le=ee.map(ye=>ye.id),Ce=i.filter(ye=>!(le.includes(ye.id)&&ye.id<0)).map(ye=>le.includes(ye.id)?{...ye,operation:"pendingRemove"}:ye);pe(Ce)}catch(le){L(le)}d(0),V(!1)},Ie=(ee,le,Ce,ye=!1)=>{let be;if(ye)be=i.concat({id:ee,operation:"pendingLink",values:{...Ce,id:ee},treeValues:{...Ce,id:ee}});else if(ee)be=i.map(Te=>Te.id===ee?{id:ee,operation:ee>0?"pendingUpdate":"pendingCreate",values:{...Ce,id:ee},treeValues:{...Ce,id:ee}}:Te);else{const Te=ui(i);be=i.concat({id:Te,operation:"pendingCreate",values:{...Ce,id:Te},treeValues:{...Ce,id:Te}})}pe(be),A||O(!1)},ae=async ee=>{const{id:le}=ee;let Ce=i;const ye=i.find(be=>be.id===le);(ye==null?void 0:ye.values)===void 0&&(Ce=await Fe("form")),I(Ce.find(be=>be.id===le)),M(!1),O(!0)},fe=async ee=>{V(!0);let le=i;const Ce=ee.filter(ye=>!i.find(be=>be.id===ye));try{for(const ye of Ce){const be=(await K.getHandler().readObjects({model:B,ids:[ye],fields:o.get("form").fields,context:{...y==null?void 0:y(),...W}}))[0],Te=(await K.getHandler().readObjects({model:B,ids:[ye],fields:o.get("tree").fields,context:{...y==null?void 0:y(),...W}}))[0];le.push({id:ye,operation:"pendingLink",values:be,treeValues:Te})}pe(le)}catch(ye){L(ye)}finally{V(!1)}};function Ae(){const ee=fl[a];if(a==="graph")return se.parseGraph(o.get("graph").arch).string;{const le=new ee(o.get(a).fields);return le.parse(o.get(a).arch),le.string}}const de=()=>{var le,Ce,ye,be;if(a==="form")return X.length===0?S("noCurrentEntries"):a!==Q.current&&i.some(Te=>!Te.values)?e.jsx(p.Spin,{}):e.jsx(ft,{formView:o.get("form"),values:(le=X[h])==null?void 0:le.values,parentContext:{...y==null?void 0:y(),...W},model:B,id:(Ce=X[h])==null?void 0:Ce.id,submitMode:"values",onFieldsChange:Te=>{var Oe;const je=(Oe=X[h])==null?void 0:Oe.id,He=i.map(Ne=>Ne.id===je?{...Ne,operation:Ne.operation==="original"?"pendingUpdate":Ne.operation,values:{...Te,id:je},treeValues:{...Te,id:je}}:Ne);pe(He),E(!0)},readOnly:Z});let ee=[];if(X.some(Te=>Te.treeValues)&&(ee=k?lt({resultsToSort:X.map(Te=>Te.treeValues),sorter:k,fields:{...o.get("tree").fields,...((ye=o.get("form"))==null?void 0:ye.fields)||{}}}):X.map(Te=>Te.treeValues)),a==="tree")return e.jsx(Tt,{total:X.length,limit:X.length,treeView:o.get("tree"),results:ee,loading:b,onRowClicked:((be=o.get("form"))==null?void 0:be.fields)!==void 0?ae:void 0,showPagination:!1,rowSelection:{selectedRowKeys:D,onChange:$},sorter:k,onChangeSort:Y,context:{...y==null?void 0:y(),...W},colorsForResults:j,readonly:Z});if(a==="graph"){const Te=[[`${s.inv_field}`,"=",f]];return e.jsx(Nt,{view_id:o.get("graph").view_id,model:s.relation,domain:Te,context:{...y==null?void 0:y(),...W},limit:0})}};if(F)return e.jsx(p.Alert,{className:"mt-10",message:F,type:"error",banner:!0});const qe=A;return b?e.jsx(p.Spin,{}):e.jsxs(e.Fragment,{children:[e.jsx(ul,{mode:a,title:Ae(),readOnly:Z,isMany2Many:re,formHasChanges:T,totalItems:X.length,currentItemIndex:h,onDelete:Ve,onCreateItem:$e,onToggleViewMode:Be,onPreviousItem:Se,onNextItem:ie,onSearchItem:te,selectedRowKeys:D,showCreateButton:((Le=o.get("form"))==null?void 0:Le.fields)!==void 0,showToggleButton:o.size>1}),de(),e.jsx(ht,{formView:o.get("form"),model:B,id:P==null?void 0:P.id,submitMode:"2many",values:P==null?void 0:P.values,defaultValues:P==null?void 0:P.defaultValues,visible:x,onSubmitSucceed:Ie,parentContext:{...y==null?void 0:y(),...W},onCancel:()=>{M(!1),O(!1)},readOnly:Z,mustClearAfterSave:qe}),e.jsx(rr,{domain:N.current,model:B,context:{...y==null?void 0:y(),...W},visible:_,onSelectValues:async ee=>{C(!1),fe(ee)},onCloseModal:()=>{C(!1)}})]})},On=t=>{const{ooui:r}=t,{mode:n,relation:s,views:o,required:i,context:a}=r;let c;const[h,d]=l.useState(!0),[u,f]=l.useState(),[g,w]=l.useState(new Map),y=l.useContext(De),{getContext:m}=y||{};tt.default(()=>{S()},[r]);const v=async E=>o&&o[E]?o[E]:await K.getHandler().getView({model:s,type:E,context:{...m==null?void 0:m(),...a}}),S=async()=>{d(!0),f(void 0);try{if(n&&n.length>0){for(const E of n){const b=await v(E);g.set(E,b)}w(g)}else{const E=await v("form"),b=await v("tree");g.set("form",E),g.set("tree",b),w(g)}}catch(E){f(JSON.stringify(E))}finally{d(!1)}};if(n&&n.length>0?c=n[0]:c="tree",h)return e.jsx(p.Spin,{});if(u)return e.jsx(p.Alert,{className:"mt-10",message:u,type:"error",banner:!0});const T=async(E,b)=>{if(!b)throw new Error;if(!b.items)throw new Error;if(!Array.isArray(b.items))throw new Error;if(b.items.length===0)throw new Error};return e.jsx(qa,{initialView:c,children:e.jsx(me,{required:i,type:"array",validator:T,...t,children:e.jsx(pl,{ooui:r,views:g})})})},{useToken:gl}=p.theme,_n=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"number",...t,children:e.jsx(ml,{ooui:r})})},ml=t=>{const{ooui:r,value:n,onChange:s}=t,{id:o,readOnly:i,required:a}=r,{token:c}=gl(),h=a&&!i?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useRef(),[u,f]=l.useState(),g=l.useContext(De),{elementHasLostFocus:w}=g||{};l.useEffect(()=>{f(ln(n))},[n]);const y=S=>{s==null||s(S)};function m(S){d.current=S.target.value,f(S.target.value)}async function v(){y(ma(u)),await new Promise(S=>setTimeout(S,300)),w==null||w()}return e.jsx(p.Input,{value:u,disabled:i,className:"w-full",style:h,id:o,placeholder:"00:00",onChange:m,onBlur:v})};function or(t){const{ooui:r,showLabel:n=!0,responsiveBehaviour:s}=t,o=Je(r.icon||"");return e.jsx(e.Fragment,{children:(r.label||o)&&n?e.jsx(yr.FieldSet,{label:r.label,icon:o,children:e.jsx(Xt,{container:r.container,responsiveBehaviour:s})}):e.jsx(Xt,{container:r.container,responsiveBehaviour:s})})}const{TabPane:yl}=p.Tabs;function Dn(t){const{ooui:r,responsiveBehaviour:n}=t,s=r.pages;function o(i){if(i){const a=Je(i);return a&&e.jsx(a,{})}}return e.jsx(p.Tabs,{defaultActiveKey:"1",tabPosition:r.tabPosition,children:s.filter(i=>!i.invisible).map(i=>e.jsx(yl,{tab:e.jsxs(e.Fragment,{children:[o(i.icon)," ",i.label]}),children:e.jsx(or,{ooui:i,showLabel:!1,responsiveBehaviour:n})},i.label))})}const{useToken:vl}=p.theme,{TextArea:sr}=p.Input,kn=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o,height:i,translatable:a}=r,{token:c}=vl(),h=o&&!s?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useContext(De),{elementHasLostFocus:u}=d||{};return e.jsx(me,{required:o,...t,children:a?e.jsx(wl,{field:n,height:i,requiredStyle:h}):e.jsx(sr,{disabled:s||a,style:{minHeight:i?i+"px":"100%",...h},rows:4,onBlur:u})})},wl=({value:t,field:r,requiredStyle:n,onChange:s,height:o})=>{const i=l.useContext(De),{activeId:a,activeModel:c,fetchValues:h,formHasChanges:d,elementHasLostFocus:u}=i||{},[f,g]=l.useState(!1),{t:w}=l.useContext(he);return a?e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>{if(d!=null&&d()){Qe(w("saveBeforeTranslate"));return}f||g(!0)},children:e.jsx(sr,{value:t,onChange:y=>{s==null||s(y.target.value)},style:{height:o?o+"px":"100%",cursor:"pointer",pointerEvents:"none",...n},id:r,disabled:!0,rows:4,onBlur:u})}),e.jsx(kr,{id:a,model:c,field:r,visible:f,onCloseModal:()=>{g(!1)},onSubmitSucceed:()=>{g(!1),h==null||h()}})]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Row,{gutter:8,wrap:!1,children:e.jsx(sr,{value:t,onChange:y=>{s==null||s(y.target.value)},style:{height:o?o+"px":"100%",...n},id:r,rows:4,onBlur:u})}),e.jsx(p.Row,{justify:"end",style:{paddingTop:5},children:e.jsx(We,{tooltip:w("translate"),icon:e.jsx(H.TranslationOutlined,{}),onClick:async()=>{d!=null&&d()?Qe(w("saveBeforeTranslate")):Qe(w("enterTextBeforeTranslate"))},children:w("translate")})})]})},Mn=t=>{const{ooui:r}=t,{label:n,icon:s}=r,o=Je(s||"");return e.jsx(p.Divider,{orientation:"left",className:"text-sm",children:(o||n)&&e.jsxs(p.Space,{children:[o?e.jsx(o,{}):null,n]})})},Sl=({model:t,context:r,locale:n,selectedRegistersToExport:s,domain:o,limit:i,onClose:a})=>{const c=l.useRef({}),h=l.useRef(new Map),d=l.useCallback(async v=>{if(v.selectedKeys===void 0||v.selectedKeys.length===0){Qe(xe("selectAtLeastOneField",n));return}let S=o;v.registersAmount==="selected"&&(s==null?void 0:s.length)!==0&&(S=[["id","in",s==null?void 0:s.map(b=>b.id)]]);const{datas:T}=await K.getHandler().exportData({model:t,fields:Ol({keys:v.selectedKeys,fields:c.current}),domain:S,limit:v.registersAmount==="all"?0:i,context:r,format:v.exportType});a(),await new Promise(b=>setTimeout(b,200));const E=await it(T);kt(T,E.mime)},[n,t,o,i,r,a]),u=l.useCallback(async()=>{const v=await K.getHandler().getFields({model:t,context:r,fields:[]});return c.current["/"]=v,Vn({fields:v})},[t,r,c]),f=l.useCallback(async v=>{const T=ar(v,c.current)[ir(v)],E=T.relation,b=await K.getHandler().getFields({model:E,context:r,fields:[]});for(const[V,F]of Object.entries(b))b[V].string=bl({parentTitle:T.string,title:F.string});return c.current[v]=b,Vn({fields:b,parentKey:v})},[c.current,t,r]),g=l.useCallback(async()=>{const v=await xl({model:t,context:r}),S=await Fl({predefinedExports:v,fields:c.current,onGetFieldChilds:f});return{predefinedExports:v.map(E=>({...E,fields:E.fields.map(b=>{const V=ir(b.key),L=ar(b.key,c.current)[V];return{key:b.key,title:L.string}})})),keysWithChilds:S}},[c.current]),w=l.useCallback(async v=>{const S=await m("ir.exports"),T=await m("ir.exports.line"),E=await K.getHandler().create({model:"ir.exports",values:{name:v.name,resource:t},fields:S,context:r});return await Promise.all(v.fields.map(async b=>await K.getHandler().create({model:"ir.exports.line",values:{name:b.key,export_id:E},fields:T,context:r}))),{...v,id:E}},[]),y=l.useCallback(async v=>{await K.getHandler().delete({model:"ir.exports",ids:[v.id]})},[]),m=l.useCallback(async v=>{if(h.current.has(v))return h.current.get(v);const S=K.getHandler().getFields({model:v,context:r,fields:[]});h.current.set(v,S)},[h,r]);return{onGetFields:u,onGetFieldChilds:f,onExport:d,onGetPredefinedExports:g,onSavePredefinedExport:w,onRemovePredefinedExport:y}},Vn=({fields:t,parentKey:r})=>{const n=[];for(const s of Object.keys(t)){const o=t[s];if(o.relation&&o.is_function===!0)continue;const i=En(o);n.push({key:Cl({key:s,parentKey:r}),title:o.string,tooltip:o.help,required:o.required,isLeaf:!i})}return n},En=t=>t.type==="many2one"||t.type==="one2many"||t.type==="many2many",Cl=({parentKey:t,key:r})=>`${t?t+"/":""}${r}`,Ft=t=>t.indexOf("/")===-1?t:t.split("/").slice(0,-1).join("/"),ir=t=>{if(t.indexOf("/")===-1)return t;const r=t.split("/");return r[r.length-1]},ar=(t,r)=>t.indexOf("/")===-1?r["/"]:r[Ft(t)],bl=({title:t,parentTitle:r})=>`${r?r+" \u2192 ":""}${t}`,xl=async({model:t,context:r})=>{const n=await K.getHandler().search({model:"ir.exports",params:[["resource","=",t]],context:r}),s=n.flatMap(i=>i.export_fields),o=await K.getHandler().readObjects({model:"ir.exports.line",ids:s,context:r});return n.map(i=>({id:i.id,name:i.name,fields:i.export_fields.map(a=>({key:o.find(h=>h.id===a).name}))}))},Tl=({fields:t,keys:r})=>_l([...new Set(r.filter(n=>{var s,o,i;if(n.indexOf("/")===-1)return!((s=t["/"])!=null&&s[n]);{const a=Ft(n);console.log({key:n,parentKey:a,fields:t});const c=(o=t==null?void 0:t[Ft(n)])==null?void 0:o[n];return console.log({exists:c}),!((i=t==null?void 0:t[Ft(n)])!=null&&i[n])}}).map(n=>Ft(n)))]),Fl=async({predefinedExports:t,fields:r,onGetFieldChilds:n})=>{const s=t.flatMap(a=>a.fields.map(c=>c.key)),o=Tl({fields:r,keys:s}),i=[];for(const a of o)i.push({key:a,childs:await n(a)});return i},Ol=({keys:t,fields:r})=>t.map(n=>{const s=ir(n),i=ar(n,r)[s];return En(i)?`${n}/id`:n}),_l=t=>{const r=new Map,n=[];for(const s of t){const o=s.split("/");let i="";for(const a of o){const c=i?`${i}/${a}`:a;r.has(c)||(n.push(c),r.set(c,!0)),i=c}}return n.sort((s,o)=>{const i=s.split("/").length,a=o.split("/").length;return i-a}),n},In=t=>{const{visible:r,locale:n,onClose:s,model:o,context:i,selectedRegistersToExport:a,totalRegisters:c,domain:h,limit:d,visibleRegisters:u}=t,{onExport:f,onGetFieldChilds:g,onGetFields:w,onGetPredefinedExports:y,onSavePredefinedExport:m,onRemovePredefinedExport:v}=Sl({model:o,context:i,domain:h,limit:d,selectedRegistersToExport:a,onClose:s,locale:n});return e.jsx(yr.ExportModal,{visible:r,locale:n,onSucceed:f,onCancel:s,selectedRegistersToExport:a&&a.length&&a.length>0?a.length:void 0,totalRegisters:c,onGetFieldChilds:g,onGetFields:w,visibleRegisters:u,onGetPredefinedExports:y,onSavePredefinedExport:m,onRemovePredefinedExport:v})},An=t=>{const{ooui:r}=t;return e.jsx(gn,{ooui:r})},$n=t=>{const{ooui:r}=t;return e.jsx(gn,{ooui:r,showTime:!0})};var Ln={exports:{}};(function(t,r){(function(n,s){t.exports=s()})(Re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},s=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,o=/\d\d/,i=/\d\d?/,a=/\d*[^-_:/,()\s\d]+/,c={},h=function(m){return(m=+m)+(m>68?1900:2e3)},d=function(m){return function(v){this[m]=+v}},u=[/[+-]\d\d:?(\d\d)?|Z/,function(m){(this.zone||(this.zone={})).offset=function(v){if(!v||v==="Z")return 0;var S=v.match(/([+-]|\d\d)/g),T=60*S[1]+(+S[2]||0);return T===0?0:S[0]==="+"?-T:T}(m)}],f=function(m){var v=c[m];return v&&(v.indexOf?v:v.s.concat(v.f))},g=function(m,v){var S,T=c.meridiem;if(T){for(var E=1;E<=24;E+=1)if(m.indexOf(T(E,0,v))>-1){S=E>12;break}}else S=m===(v?"pm":"PM");return S},w={A:[a,function(m){this.afternoon=g(m,!1)}],a:[a,function(m){this.afternoon=g(m,!0)}],S:[/\d/,function(m){this.milliseconds=100*+m}],SS:[o,function(m){this.milliseconds=10*+m}],SSS:[/\d{3}/,function(m){this.milliseconds=+m}],s:[i,d("seconds")],ss:[i,d("seconds")],m:[i,d("minutes")],mm:[i,d("minutes")],H:[i,d("hours")],h:[i,d("hours")],HH:[i,d("hours")],hh:[i,d("hours")],D:[i,d("day")],DD:[o,d("day")],Do:[a,function(m){var v=c.ordinal,S=m.match(/\d+/);if(this.day=S[0],v)for(var T=1;T<=31;T+=1)v(T).replace(/\[|\]/g,"")===m&&(this.day=T)}],M:[i,d("month")],MM:[o,d("month")],MMM:[a,function(m){var v=f("months"),S=(f("monthsShort")||v.map(function(T){return T.slice(0,3)})).indexOf(m)+1;if(S<1)throw new Error;this.month=S%12||S}],MMMM:[a,function(m){var v=f("months").indexOf(m)+1;if(v<1)throw new Error;this.month=v%12||v}],Y:[/[+-]?\d+/,d("year")],YY:[o,function(m){this.year=h(m)}],YYYY:[/\d{4}/,d("year")],Z:u,ZZ:u};function y(m){var v,S;v=m,S=c&&c.formats;for(var T=(m=v.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(O,_,C){var P=C&&C.toUpperCase();return _||S[C]||n[C]||S[P].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,D,$){return D||$.slice(1)})})).match(s),E=T.length,b=0;b<E;b+=1){var V=T[b],F=w[V],L=F&&F[0],x=F&&F[1];T[b]=x?{regex:L,parser:x}:V.replace(/^\[|\]$/g,"")}return function(O){for(var _={},C=0,P=0;C<E;C+=1){var I=T[C];if(typeof I=="string")P+=I.length;else{var D=I.regex,$=I.parser,A=O.slice(P),M=D.exec(A)[0];$.call(_,M),O=O.replace(M,"")}}return function(N){var k=N.afternoon;if(k!==void 0){var Y=N.hours;k?Y<12&&(N.hours+=12):Y===12&&(N.hours=0),delete N.afternoon}}(_),_}}return function(m,v,S){S.p.customParseFormat=!0,m&&m.parseTwoDigitYear&&(h=m.parseTwoDigitYear);var T=v.prototype,E=T.parse;T.parse=function(b){var V=b.date,F=b.utc,L=b.args;this.$u=F;var x=L[1];if(typeof x=="string"){var O=L[2]===!0,_=L[3]===!0,C=O||_,P=L[2];_&&(P=L[2]),c=this.$locale(),!O&&P&&(c=S.Ls[P]),this.$d=function(A,M,N){try{if(["x","X"].indexOf(M)>-1)return new Date((M==="X"?1e3:1)*A);var k=y(M)(A),Y=k.year,z=k.month,j=k.day,U=k.hours,Z=k.minutes,B=k.seconds,W=k.milliseconds,R=k.zone,re=new Date,ce=j||(Y||z?1:re.getDate()),X=Y||re.getFullYear(),Q=0;Y&&!z||(Q=z>0?z-1:re.getMonth());var ue=U||0,pe=Z||0,ke=B||0,Fe=W||0;return R?new Date(Date.UTC(X,Q,ce,ue,pe,ke,Fe+60*R.offset*1e3)):N?new Date(Date.UTC(X,Q,ce,ue,pe,ke,Fe)):new Date(X,Q,ce,ue,pe,ke,Fe)}catch{return new Date("")}}(V,x,F),this.init(),P&&P!==!0&&(this.$L=this.locale(P).$L),C&&V!=this.format(x)&&(this.$d=new Date("")),c={}}else if(x instanceof Array)for(var I=x.length,D=1;D<=I;D+=1){L[1]=x[D-1];var $=S.apply(this,L);if($.isValid()){this.$d=$.$d,this.$L=$.$L,this.init();break}D===I&&(this.$d=new Date(""))}else E.call(this,b)}}})})(Ln);const Dl=Ln.exports;Ze.extend(Dl);const Nn=t=>{const{ooui:r}=t;return e.jsx(me,{...t,children:e.jsx(kl,{ooui:r})})},kl=t=>{const r=(n,s)=>{t.onChange&&t.onChange(s)};return e.jsx(p.TimePicker,{onChange:r,value:t.value?Ze(t.value,"HH:mm:ss"):void 0})},Pn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(Ml,{ooui:r})})},Ml=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,selectionValues:i,readOnly:a}=s,c=r==null?void 0:r.split(","),[h,d]=l.useState([]),[u,f]=l.useState();return l.useEffect(()=>{if(!r){f(void 0),d([]);return}const g=r&&c&&c[0],w=r&&c&&c[1]&&parseInt(c[1]);d([w,void 0]),f(g)},[r]),e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"1",children:e.jsx(Mr,{ooui:new se.Selection({name:"model_selection",selection:i,readonly:a,required:o}),onChange:g=>{f(g);let w=h[0]||0;g!==u&&(d([]),w=0);const y=`${g},${w}`;y!==r&&(n==null||n(y))},value:u})}),e.jsx(p.Col,{flex:"3",children:e.jsx(Sn,{ooui:new se.Many2one({name:"object_value",relation:u,readonly:a,required:o}),value:h,onChange:g=>{d(g);const w=`${u},${g[0]||0}`;w!==r&&(n==null||n(w))}})})]})},{useToken:Vl}=p.theme,Bn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(El,{ooui:r})})},El=t=>{const{ooui:r,value:n,onChange:s}=t,{readOnly:o,required:i,filenameField:a}=r,{token:c}=Vl(),h=i&&!o?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useRef(null),{setFieldValue:u,getFieldValue:f}=l.useContext(De)||{},{t:g}=l.useContext(he),w=n?si(n):"",y=E=>{s==null||s(E)};async function m(){const E=await it(n),b=`data:${E==null?void 0:E.mime};base64,${n}`,V=document.createElement("a"),F=f(a),L=f("name");V.href=b,V.download=F||L,V.click()}async function v(){const E=await it(n);kt(n,E.mime)}async function S(E){E.stopPropagation(),E.preventDefault();const b=E.target.files[0],V=await Yr(b);y(V),a&&u(a,b.name)}function T(){u(a,void 0),y(void 0)}return e.jsxs(p.Row,{gutter:8,children:[e.jsxs(p.Col,{style:{paddingBottom:5},children:[e.jsx("input",{type:"file",id:"file",ref:d,style:{display:"none"},onChange:S}),e.jsx(p.Input,{type:"text",disabled:!0,style:h,value:w})]}),e.jsx(p.Col,{children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.FolderOpenOutlined,{}),disabled:o,onClick:()=>{d.current.click()},children:"Select"}),e.jsx(p.Button,{icon:e.jsx(H.EyeOutlined,{}),disabled:!n,onClick:v,children:g("open")}),e.jsx(We,{tooltip:g("download"),disabled:!n,onClick:m,icon:e.jsx(H.DownloadOutlined,{})}),e.jsx(We,{tooltip:g("clear"),disabled:o||!n,onClick:T,icon:e.jsx(H.ClearOutlined,{})})]})})]})},lr={tree:e.jsx(H.TableOutlined,{}),form:e.jsx(H.FormOutlined,{}),graph:e.jsx(H.AreaChartOutlined,{}),calendar:e.jsx(H.CalendarOutlined,{})};function Hn(t){return t?(lr==null?void 0:lr[t.type])||e.jsx(H.FormOutlined,{}):e.jsx(H.FormOutlined,{})}function cr(t){const{currentView:r,availableViews:n,onChangeView:s,disabled:o=!1,formHasChanges:i=!1,previousView:a}=t,{t:c,lang:h}=l.useContext(he);function d(){const g=n.map((w,y)=>e.jsx(p.Menu.Item,{children:e.jsxs(p.Row,{wrap:!1,children:[e.jsx(p.Col,{flex:"none",style:{paddingRight:20},children:Hn(w)}),e.jsx(p.Col,{flex:"auto",style:{paddingRight:20},children:w.type.charAt(0).toUpperCase()+w.type.slice(1)}),e.jsx(p.Col,{flex:"none",children:e.jsx(H.CheckOutlined,{style:{opacity:r.view_id===w.view_id?1:0}})})]})},w.view_id||y));return e.jsx(p.Menu,{onClick:f,children:e.jsx(p.Menu.ItemGroup,{title:c("viewAs"),children:g})})}function u(g){if(i){St({lang:h,onOk:()=>{g()}});return}g()}function f(g){u(()=>{const w=n.find(y=>y.view_id===parseInt(g.key));s(w)})}return e.jsxs("div",{style:{display:"flex"},children:[e.jsx(We,{tooltip:a?c("viewAs")+" "+c(a.type):"",icon:Hn(a),style:{width:50,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:()=>{f({key:a==null?void 0:a.view_id})},disabled:o||n.length===1}),e.jsx(p.Dropdown,{overlay:d(),disabled:o||n.length===1,children:e.jsx(p.Button,{style:{width:25,borderTopLeftRadius:0,borderBottomLeftRadius:0},icon:e.jsx(H.DownOutlined,{style:{fontSize:"0.5em"}}),onClick:g=>g.preventDefault()})})]})}const{Search:Il}=p.Input;function pt(t){const{icon:r,tooltip:n,items:s=[],onItemClick:o,label:i,disabled:a=!1,searchable:c="auto"}=t,[h,d]=l.useState(),u=w=>{if(!w){d(void 0);return}const y=w.trim();if(y.length===0){d(void 0);return}d(y)};function f(){let w=[];h?w=s.filter(v=>v.name.toLowerCase().includes(h.toLowerCase())):w=s;const y=w.map((v,S)=>v.name==="divider"?e.jsx(p.Menu.Divider,{},"divider"+S):e.jsx(p.Menu.Item,{children:v.name},v.id)),m=c===!0||c==="auto"&&s.length>3;return e.jsxs(p.Menu,{onClick:g,children:[m&&e.jsx(Il,{onChange:v=>u(v.target.value),onSearch:u,allowClear:!0,style:{padding:5}}),e.jsx(p.Menu.ItemGroup,{title:n,children:y})]})}function g(w){const y=s.find(m=>isNaN(w.key)?m.id===w.key:m.id===parseInt(w.key));o(y)}return e.jsx(p.Dropdown,{overlay:f(),disabled:a||!s||s.length===0,children:e.jsxs(p.Button,{children:[r," ",i," ",e.jsx(H.DownOutlined,{})]})})}function Ye(t){const{onClick:r,disabled:n=!1,loading:s=!1,tooltip:o,icon:i,label:a,type:c="default"}=t,h=s?e.jsx(H.LoadingOutlined,{}):i;return e.jsxs(We,{type:c,tooltip:o,onClick:r,disabled:n,children:[h,a]})}function Kn(t){const{disabled:r=!1}=t,{formHasChanges:n,onNewClicked:s}=l.useContext(Ge),{t:o,lang:i}=l.useContext(he),a=()=>{if(n){St({lang:i,onOk:()=>{s()}});return}s()};return e.jsx(Ye,{icon:e.jsx(H.FileAddOutlined,{}),tooltip:o("new"),onClick:a,disabled:r})}const{confirm:Al}=p.Modal,$l=({onOk:t,onCancel:r,lang:n})=>{Al({title:xe("unsavedChanges",n),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:xe("confirmRefreshWithoutSave",n),okText:xe("discardAndRefresh",n),cancelText:xe("cancel",n),onOk:t,onCancel:r})};async function Wn(t,r,n){const s=(await K.getHandler().getLogInfo({model:t,ids:[r]}))[0],{create_date:o,create_uid:i,id:a,write_date:c,write_uid:h}=s;Qe(e.jsxs("div",{children:["ID: "+a," ",e.jsx("br",{}),n("createdBy")+": "+i[1]," ",e.jsx("br",{}),n("creationDate")+": "+o," ",e.jsx("br",{}),n("lastUpdatedBy")+": "+h[1]," ",e.jsx("br",{}),n("lastUpdatedDate")+": "+c]}))}const Ll=t=>{const{numberOfAttachments:r,disabled:n}=t,{t:s,lang:o}=l.useContext(he),[i,a]=l.useState(!1),c=e.jsxs(p.Button,{disabled:n,children:[e.jsx(H.LinkOutlined,{}),`(${r})`,e.jsx(H.DownOutlined,{style:{fontSize:12}})]});return n?c:e.jsx(p.Popover,{onVisibleChange:h=>a(h),visible:i,placement:"bottom",content:Nl(t,a,o),title:s("attachments"),arrowContent:null,children:c})},Nl=(t,r,n)=>{const{attachments:s=[],loading:o,onAddNewAttachment:i,onopenAttachmentLink:a,onOpenAttachmentDetail:c,onListAllAttachments:h}=t;return o?e.jsx(p.Spin,{style:{padding:20}}):e.jsxs(e.Fragment,{children:[e.jsxs("a",{style:{display:"block",paddingBottom:5},href:"#",onClick:()=>{r(!1),h()},children:[e.jsx(H.TableOutlined,{})," ",xe("listAllAttachments",n)]}),e.jsxs("a",{style:{display:"block"},href:"#",onClick:()=>{r(!1),i()},children:[e.jsx(H.FileAddOutlined,{})," ",xe("addNewAttachment",n)]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("li",{className:"ant-dropdown-menu-item-divider"}),s.map(d=>{const u=d.link?H.LinkOutlined:H.DownloadOutlined;return e.jsxs(p.Row,{style:{paddingTop:4,paddingBottom:4},wrap:!1,align:"middle",children:[e.jsx(p.Col,{flex:"auto",children:d.name}),e.jsx(p.Col,{flex:"25px",style:{textAlign:"center"},children:(d.datas_fname||d.link)&&e.jsx(p.Tooltip,{title:d.link?xe("openAttachmentLink",n):xe("download",n),children:e.jsx(u,{style:{cursor:"pointer"},onClick:()=>{r(!1),a(d)}})})}),e.jsx(p.Col,{flex:"25px",style:{textAlign:"center"},children:e.jsx(p.Tooltip,{title:xe("openAttachment",n),children:e.jsx(H.FormOutlined,{style:{cursor:"pointer"},onClick:()=>{r(!1),c(d)}})})})]},d.id)})]})]})};function Pl(t){const{attachments:r,disabled:n=!1,onAddNewAttachment:s,onListAllAttachments:o,onViewAttachmentDetails:i}=t,{formRef:a}=l.useContext(Ge),[c,h]=l.useState(!1),[d,u]=l.useState([]),[f,g]=l.useState(!1),{t:w}=l.useContext(he),y=l.useCallback(async()=>{h(!0);try{const S=await K.getHandler().readObjects({model:"ir.attachment",ids:r.map(T=>T.id),fieldsToRetrieve:["name","datas_fname","link"],context:a.current.getContext()});u(S.map(T=>({id:T.id,name:T.name,datas_fname:T.datas_fname,link:T.link})))}catch(S){Pe(S)}h(!1)},r),m=l.useCallback(async S=>{if(S.link){window.open(S.link);return}g(!0);let T;try{T=(await K.getHandler().readObjects({model:"ir.attachment",ids:[S.id],context:a.current.getContext()}))[0]}catch(E){Pe(E)}if(g(!1),!!T)if(T.datas){const E=await it(T.datas);kt(T.datas,E.mime)}else i(T)},[]),v=l.useCallback(async S=>{i(S)},[]);return l.useEffect(()=>{y()},[y]),e.jsxs(e.Fragment,{children:[e.jsx(Ll,{numberOfAttachments:r.length,attachments:d,disabled:n,loading:c,onAddNewAttachment:s,onListAllAttachments:o,onopenAttachmentLink:m,onOpenAttachmentDetail:v}),e.jsx(p.Modal,{title:w("downloadingAttachment"),open:f,footer:null,closable:!1,centered:!0,maskClosable:!1,children:e.jsx(p.Spin,{})})]})}function Yn({toolbar:t}){const{availableViews:r,currentView:n,setCurrentView:s,onFormSave:o,formHasChanges:i,formIsSaving:a,currentId:c,results:h,setCurrentItemIndex:d,currentItemIndex:u,setCurrentId:f,currentModel:g,setRemovingItem:w,removingItem:y,duplicatingItem:m,setDuplicatingItem:v,setResults:S,formIsLoading:T,attachments:E,formRef:b,setFormHasChanges:V,previousView:F,setPreviousView:L,goToResourceId:x}=l.useContext(Ge),{t:O,lang:_}=l.useContext(he),C=l.useContext(ut),{processAction:P}=C||{},I=l.useContext(Xe),{openRelate:D,openDefaultActionForModel:$}=I||{};function A(B){if(i){$l({lang:_,onOk:()=>{B()}});return}B()}function M(B){if(i){St({lang:_,onOk:()=>{B()}});return}B()}function N(){h&&h.length>u+1?(d==null||d(u+1),f==null||f(h[u+1].id)):h&&u+1===h.length&&(d==null||d(0),f==null||f(h[0].id))}function k(){h&&u>0?(d==null||d(u-1),f==null||f(h[u-1].id)):h&&u===0&&(d==null||d(h.length-1),f==null||f(h[h.length-1].id))}function Y(){st({confirmMessage:O("confirmRemoveItem"),lang:_,onOk:()=>{z()}})}async function z(){try{w==null||w(!0),await K.getHandler().delete({model:g,ids:[c]});const B=h==null?void 0:h.filter(R=>R.id!==c);S==null||S(B);let W=0;u>0&&u<=h.length-1&&(W=u-1),B!=null&&B[W]?(f==null||f(B==null?void 0:B[W].id),d==null||d(W)):(f==null||f(void 0),d==null||d(void 0))}catch(B){Et(JSON.stringify(B))}finally{w==null||w(!1)}}async function j(){try{v==null||v(!0);const B=await K.getHandler().duplicate({id:c,model:g,context:b.current.getContext()});B&&await(x==null?void 0:x([B]))}catch(B){Et(JSON.stringify(B))}finally{v==null||v(!1)}}const U=a||y||T||m;function Z(B){P==null||P({actionData:B,values:b.current.getValues(),fields:b.current.getFields(),context:b.current.getContext(),onRefreshParentValues:()=>{b.current.fetchValues()}})}return n?e.jsxs(p.Space,{wrap:!0,children:[T&&e.jsxs(e.Fragment,{children:[e.jsx(p.Spin,{}),gt(),gt()]}),e.jsx(Kn,{disabled:a||T||y||m}),e.jsx(Ye,{icon:e.jsx(H.SaveOutlined,{}),tooltip:O("save"),disabled:!i||U,loading:a,onClick:o}),e.jsx(Ye,{icon:e.jsx(H.CopyOutlined,{}),tooltip:O("duplicate"),disabled:i||a||c===void 0||m||T,loading:m,onClick:j}),e.jsx(Ye,{icon:e.jsx(H.DeleteOutlined,{}),tooltip:O("delete"),disabled:a||c===void 0||y||m||T,loading:y,onClick:Y}),gt(),e.jsx(Ye,{icon:e.jsx(H.InfoCircleOutlined,{}),tooltip:O("showLogs"),disabled:a||c===void 0||y||m||T,loading:!1,onClick:()=>{Wn(g,c,O)}}),e.jsx(Ye,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:O("refresh"),disabled:a||c===void 0||y||m||T,loading:!1,onClick:()=>{A(()=>{b.current.fetchValues()})}}),gt(),e.jsx(cr,{currentView:n,previousView:F,availableViews:r,onChangeView:B=>{L==null||L(n),V==null||V(!1),s==null||s(B)},disabled:U,formHasChanges:i}),gt(),e.jsxs(p.Space,{children:[e.jsx(Ye,{icon:e.jsx(H.LeftOutlined,{}),tooltip:O("previous"),disabled:U,loading:!1,onClick:()=>{M(k)}}),e.jsx(Ye,{icon:e.jsx(H.RightOutlined,{}),tooltip:O("next"),disabled:U,loading:!1,onClick:()=>{M(N)}})]}),gt(),e.jsx(pt,{icon:e.jsx(H.ThunderboltOutlined,{}),disabled:U,tooltip:O("actions"),items:t==null?void 0:t.action,onItemClick:async B=>{!B||!(await mt({onFormSave:o})).succeed||Z(B)}}),e.jsx(pt,{icon:e.jsx(H.PrinterOutlined,{}),disabled:U,tooltip:O("reports"),items:t==null?void 0:t.print,onItemClick:async B=>{if(!B)return;const W=await mt({onFormSave:o});!W.succeed||Z({...B,datas:{...B.datas||{},ids:[W.currentId]}})}}),e.jsx(pt,{icon:e.jsx(H.EnterOutlined,{}),disabled:U,tooltip:O("related"),items:t==null?void 0:t.relate,onItemClick:async B=>{!B||!(await mt({onFormSave:o})).succeed||D({relateData:B,values:b.current.getValues(),fields:b.current.getFields(),action_id:B.id,action_type:B.type})}}),e.jsx(Pl,{disabled:U,attachments:E,onAddNewAttachment:async()=>{const B=await mt({onFormSave:o});if(!B.succeed)return;const W=B.currentId,R=g;$({model:"ir.attachment",values:{selection_associated_object:`${R},${W}`},forced_values:{res_model:R,res_id:W},initialViewType:"form"})},onListAllAttachments:async()=>{const B=await mt({onFormSave:o});if(!B.succeed)return;const W=B.currentId;$({model:"ir.attachment",domain:[["res_model","=",`${g}`],["res_id","=",`${W}`]],initialViewType:"tree"})},onViewAttachmentDetails:async B=>{!(await mt({onFormSave:o})).succeed||$({model:"ir.attachment",res_id:B.id,initialViewType:"form"})}})]}):null}function gt(){return e.jsx("div",{className:"inline-block w-2"})}async function mt({onFormSave:t}){const r=await(t==null?void 0:t());return r!=null&&r.succeed?{succeed:!0,currentId:r.id}:{succeed:!1,currentId:void 0}}const{useToken:Bl}=p.theme,qn=t=>{const{ooui:r,value:n,onChange:s,valueValidator:o,linkPrefix:i=""}=t,{id:a,readOnly:c,required:h}=r,{token:d}=Bl(),u=h&&!c?{backgroundColor:d.colorPrimaryBg}:void 0,f=l.useContext(De),{elementHasLostFocus:g}=f||{},[w,y]=l.useState(!1),[m,v]=l.useState(!1);l.useEffect(()=>{c&&!w&&v(!1),!n&&!c&&(y(!0),v(!0))},[w,c]);const S=T=>{s==null||s(T.target.value)};return e.jsxs(p.Row,{gutter:8,wrap:!1,align:"middle",children:[c?null:e.jsx(p.Col,{flex:"32px",children:w?e.jsx(p.Button,{icon:e.jsx(H.CheckOutlined,{}),onClick:()=>{o(n)&&(y(!1),v(!1))},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1}):e.jsx(p.Button,{icon:e.jsx(H.EditOutlined,{}),onClick:()=>{y(!0),v(!0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1})}),e.jsx(p.Col,{flex:"auto",children:m?e.jsx(p.Input,{style:{borderTopLeftRadius:0,borderBottomLeftRadius:0,...u},id:a,onChange:S,value:n,onBlur:()=>{o(n)&&(y(!1),v(!1),g==null||g())}}):e.jsx("a",{href:`${i}${n}`,style:{color:d.colorPrimary,paddingRight:15},target:"_blank",children:n})})]})},Un=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(qn,{ooui:r,valueValidator:s=>s?Mo.default(s):!1})})},Gn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(qn,{ooui:r,linkPrefix:"mailto:",valueValidator:s=>s?Vo.default(s):!1})})},Hl=t=>{const{visible:r,onIdSubmitted:n,onCancel:s,isSearching:o}=t,{t:i}=l.useContext(he),a=l.useRef();function c(h){const d=h.id.split(",").map(u=>parseInt(u.trim()));n(d)}return e.jsx(p.Modal,{title:i("goToResourceId"),centered:!0,open:r,footer:null,destroyOnClose:!0,onCancel:s,maskClosable:!1,afterOpenChange:h=>{var d;return h&&((d=a.current)==null?void 0:d.focus())},children:e.jsxs(p.Form,{layout:"vertical",onFinish:c,autoComplete:"off",children:[e.jsx(p.Form.Item,{name:"id",label:i("searchId"),rules:[{required:!0}],help:i("searchIdHelp"),children:e.jsx(p.Input,{style:{width:"100%"},autoFocus:!0,ref:a})}),e.jsx(p.Row,{align:"middle",justify:"end",children:e.jsx(p.Col,{children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.CloseOutlined,{}),htmlType:"button",onClick:s,disabled:o,children:i("cancel")}),e.jsx(p.Button,{loading:o,style:{marginLeft:15},icon:e.jsx(H.CheckOutlined,{}),htmlType:"submit",type:"primary",disabled:o,children:i("ok")})]})})})]})})},{useToken:Kl}=p.theme;function jn(t){const{badgeNumber:r=0,...n}=t,{token:s}=Kl();return e.jsxs("div",{style:{position:"relative"},children:[r>0&&e.jsx("div",{style:{position:"absolute",left:-10,top:-10,zIndex:2},children:e.jsx("span",{style:{display:"inline-block",minWidth:"22px",padding:"2px",borderRadius:"50%",fontSize:"12px",textAlign:"center",background:s.colorPrimaryHover,color:s.colorPrimaryBg},children:r})}),e.jsx(We,{...n,style:{width:46,zIndex:0}})]})}function Wl({refreshGraph:t}){const{t:r}=l.useContext(he),{availableViews:n,currentView:s,setCurrentView:o,searchParams:i,searchVisible:a,setSearchVisible:c,graphIsLoading:h,previousView:d,setPreviousView:u}=l.useContext(Ge);return e.jsxs(p.Space,{wrap:!0,children:[e.jsx(jn,{icon:e.jsx(H.FilterOutlined,{style:{color:a?"white":void 0}}),tooltip:r("advanced_search"),type:a?"primary":"default",onClick:()=>{c==null||c(!a)},disabled:h,badgeNumber:i==null?void 0:i.length}),e.jsx(Ye,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:r("refresh"),disabled:h,loading:!1,onClick:()=>{t()}}),e.jsx(cr,{currentView:s,availableViews:n,onChangeView:f=>{u==null||u(s),o==null||o(f)},disabled:!1,previousView:d})]})}const{useToken:Yl}=p.theme,{Title:ql,Text:Pt}=p.Typography;function Bt(t){const{title:r,children:n}=t,{title:s,currentView:o,currentId:i,currentItemIndex:a,results:c,totalItems:h,selectedRowItems:d}=l.useContext(Ge),{t:u}=l.useContext(he),{token:f}=Yl();function g(){if((o==null?void 0:o.type)==="form")return i?h===0?e.jsxs(e.Fragment,{children:[u("editingDocument")," (id:"," ",e.jsx(Pt,{copyable:{icon:e.jsx(H.CopyOutlined,{style:{color:"red"}})},children:i}),")"]}):e.jsxs(e.Fragment,{children:[u("register")," ",a===void 0?1:a+1," /"," ",c.length," ",u("of")," ",h," - ",u("editingDocument")," (id:"," ",e.jsx(Pt,{copyable:!0,children:i}),")"]}):"";if((o==null?void 0:o.type)==="tree"&&d){if(d.length===1)return e.jsxs(e.Fragment,{children:["1 ",u("selectedRegisters")," - (id:"," ",e.jsx(Pt,{copyable:!0,children:d[0].id}),")"]});if(d.length>1)return e.jsxs(e.Fragment,{children:[d.length," ",u("selectedRegisters"),e.jsx(Pt,{copyable:{text:d.map(w=>w.id).join(", ")}})]})}return null}return e.jsxs("div",{style:{position:"sticky",top:80,zIndex:3},children:[e.jsxs(p.Row,{className:"shadow-md",style:{padding:"1em",borderRadius:f.borderRadius,backgroundColor:f.colorPrimaryBg},align:"middle",children:[e.jsxs(p.Col,{flex:2,children:[e.jsx(ql,{level:3,style:{marginBottom:0},children:r||s}),g()]}),e.jsx(p.Col,{flex:3,children:e.jsx(p.Row,{justify:"end",children:n})})]}),e.jsx("div",{className:"pb-5"})]})}const Ul=t=>{const{viewData:r,visible:n,model:s,context:o,domain:i,formView:a,treeView:c}=t,h=l.useRef(),d=l.useContext(Ge),{setResults:u=void 0,setCurrentItemIndex:f=void 0,currentId:g=void 0,results:w=void 0,setSelectedRowItems:y=void 0,setSearchParams:m=void 0,searchVisible:v=!0,setSearchVisible:S=void 0,sorter:T=void 0,setSorter:E=void 0,setTotalItems:b=void 0,setSearchTreeNameSearch:V=void 0,setTreeIsLoading:F=void 0,limit:L,setLimit:x,searchParams:O,searchValues:_,setSearchValues:C,currentView:P}=d||{},[I,D]=l.useState(!0);l.useEffect(()=>{var Y;(Y=h.current)==null||Y.refresh()},[O]),l.useEffect(()=>{r.view_id!==P.view_id&&D(!0)},[P]);const{clear:$,searchFilterLoading:A,searchError:M,offset:N,tableRefreshing:k}=nn({model:s,setSearchTreeNameSearch:V,setSelectedRowItems:y,searchParams:O,setSearchValues:C,setSearchParams:m,setSearchVisible:S,setTreeIsLoading:F,context:o,formView:a,treeView:c,sorter:T,setSorter:E,setCurrentItemIndex:f,setResultsActionView:u,resultsActionView:w,domain:i,currentId:g,setActionViewTotalItems:b,limit:L,setLimit:x});return!n||!r?null:e.jsxs(e.Fragment,{children:[e.jsx(Bt,{title:r.name,children:e.jsx(Wl,{refreshGraph:()=>{h.current.refresh()}})}),e.jsx(Rt,{fields:{...c.fields,...a.fields},searchFields:zr([a.search_fields,c.search_fields]),limit:L,onClear:$,offset:N,isSearching:A,onSubmit:Y=>{D(!1),m==null||m(Y.params),S==null||S(!1)},searchError:M,searchVisible:v,searchValues:_,showLimitOptions:!1}),k?e.jsx(p.Spin,{}):e.jsx(Nt,{ref:h,view_id:r.view_id,model:s,context:o,domain:Ct(O||[],i),limit:I?L:void 0,manualIds:I?w==null?void 0:w.map(Y=>Y.id):void 0})]})},Gl=t=>{const{visible:r,formRef:n,model:s,currentId:o,domain:i,formView:a,context:c,defaultValues:h,forcedValues:d,results:u,setResults:f,setCurrentItemIndex:g}=t;return r?e.jsxs(e.Fragment,{children:[e.jsx(Bt,{children:e.jsx(Yn,{toolbar:a==null?void 0:a.toolbar})}),e.jsx(ft,{rootForm:!0,ref:n,model:s,defaultValues:h,forcedValues:d,formView:a,actionDomain:i,id:o,parentContext:c,onSubmitSucceed:(w,y)=>{u.findIndex(v=>v.id===w)===-1&&(u.push(y),f(u),g(u.length-1))}})]}):null};function jl(t){const{onSearch:r,disabled:n=!1,searchText:s}=t,{t:o}=l.useContext(he),[i]=p.Form.useForm(),[a,c]=l.useState(!1);function h(u){r(u.search)}l.useEffect(()=>{i.setFieldsValue({search:s})},[s]);function d(){c(!1),i.setFieldsValue({search:void 0}),r(void 0)}return e.jsx(p.Form,{form:i,onFinish:h,autoComplete:"off",children:e.jsxs(p.Row,{align:"middle",justify:"end",children:[e.jsx(p.Col,{children:e.jsx(p.Form.Item,{name:"search",noStyle:!0,children:e.jsx(p.Input,{autoFocus:!0,disabled:n,onChange:u=>{c(u.target.value.length>0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},suffix:(a||s&&s.length>0)&&e.jsx(p.Tooltip,{title:o("clear"),children:e.jsx(H.CloseCircleFilled,{style:{color:"rgba(0,0,0,.45)"},onClick:d})})})})}),e.jsx(p.Col,{children:e.jsx(p.Button,{htmlType:"submit",disabled:n,style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},children:o("search")})})]})})}const zn=Ke.default.createContext({previewFeatures:!1});function zl(t){var j;const{availableViews:r,currentView:n,setCurrentView:s,selectedRowItems:o,setRemovingItem:i,removingItem:a,duplicatingItem:c,setDuplicatingItem:h,currentModel:d,searchTreeRef:u,setCurrentId:f,setCurrentItemIndex:g,searchParams:w,searchVisible:y,setSearchVisible:m,setSearchTreeNameSearch:v,searchTreeNameSearch:S,treeIsLoading:T,setPreviousView:E,previousView:b,results:V,limit:F,totalItems:L}=l.useContext(Ge),{parentContext:x={},treeExpandable:O,toolbar:_}=t;l.useContext(zn);const{t:C,lang:P}=l.useContext(he),I=l.useContext(ut),{processAction:D}=I||{},[$,A]=l.useState(!1),M=S!==void 0&&S.trim().length>0;function N(){st({confirmMessage:C("confirmRemove"),lang:P,onOk:()=>{k()}})}async function k(){var U;try{i==null||i(!0),await K.getHandler().delete({model:d,ids:o.map(Z=>Z.id)}),f==null||f(void 0),g==null||g(void 0),(U=u==null?void 0:u.current)==null||U.refreshResults()}catch(Z){Pe(Z)}finally{i==null||i(!1)}}async function Y(){var U;try{h==null||h(!0);const Z=o[0].id;await K.getHandler().duplicate({id:Z,model:d,context:{...x}})&&((U=u==null?void 0:u.current)==null||U.refreshResults())}catch(Z){Pe(Z)}finally{h==null||h(!1)}}function z(U){D==null||D({actionData:U,values:{active_id:o==null?void 0:o.map(Z=>Z.id)[0],active_ids:o==null?void 0:o.map(Z=>Z.id)},fields:{},context:{...x,active_id:o==null?void 0:o.map(Z=>Z.id)[0],active_ids:o==null?void 0:o.map(Z=>Z.id)},onRefreshParentValues:()=>{var Z;(Z=u==null?void 0:u.current)==null||Z.refreshResults()}})}return e.jsxs(p.Space,{wrap:!0,children:[T&&e.jsxs(e.Fragment,{children:[e.jsx(p.Spin,{}),rt(),rt()]}),O?null:e.jsxs(e.Fragment,{children:[e.jsx(jl,{disabled:c||a||T,searchText:S,onSearch:U=>{U&&U.trim().length>0?v==null||v(U):v==null||v(void 0)}}),!O&&e.jsx(jn,{icon:e.jsx(H.FilterOutlined,{style:{color:y?"white":void 0}}),tooltip:C("advanced_search"),type:y?"primary":"default",onClick:()=>{m==null||m(!y)},disabled:c||a||T,badgeNumber:w==null?void 0:w.length}),rt(),e.jsx(Kn,{disabled:T}),e.jsx(Ye,{icon:e.jsx(H.CopyOutlined,{}),tooltip:C("duplicate"),disabled:!o||(o==null?void 0:o.length)!==1||c||T,loading:c,onClick:Y}),e.jsx(Ye,{icon:e.jsx(H.DeleteOutlined,{}),tooltip:C("delete"),disabled:!(o&&(o==null?void 0:o.length)>0)||T,loading:a,onClick:N}),rt()]}),e.jsx(Ye,{icon:e.jsx(H.InfoCircleOutlined,{}),tooltip:C("showLogs"),disabled:!(o&&(o==null?void 0:o.length)>0)||T,loading:!1,onClick:()=>{Wn(d,o[0].id,C)}}),e.jsx(Ye,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:C("refresh"),disabled:c||a||T,loading:!1,onClick:()=>{var U;(U=u==null?void 0:u.current)==null||U.refreshResults()}}),!O&&e.jsxs(e.Fragment,{children:[rt(),e.jsx(cr,{currentView:n,availableViews:r,onChangeView:U=>{E==null||E(n),s==null||s(U)},previousView:b,disabled:T})]}),rt(),e.jsx(pt,{icon:e.jsx(H.ThunderboltOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||T,tooltip:C("actions"),items:_==null?void 0:_.action,onItemClick:U=>{!U||z(U)}}),e.jsx(pt,{icon:e.jsx(H.PrinterOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||T,tooltip:C("reports"),items:_==null?void 0:_.print,onItemClick:U=>{!U||z({...U,datas:{...U.datas||{},ids:o.map(Z=>Z.id)}})}}),rt(),e.jsx(pt,{icon:e.jsx(br.default,{component:()=>e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-database-export",width:"1em",height:"1em",viewBox:"0 0 24 24",strokeWidth:"1.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),e.jsx("ellipse",{cx:"12",cy:"6",rx:"8",ry:"3"}),e.jsx("path",{d:"M4 6v6c0 1.657 3.582 3 8 3a19.84 19.84 0 0 0 3.302 -.267m4.698 -2.733v-6"}),e.jsx("path",{d:"M4 12v6c0 1.599 3.335 2.905 7.538 2.995m8.462 -6.995v-2m-6 7h7m-3 -3l3 3l-3 3"})]})}),tooltip:C("export"),items:[{id:"print_screen",name:C("printScreen")},{id:"export",name:C("advancedExport")}],onItemClick:U=>{if(U.id==="print_screen"){let Z=(o==null?void 0:o.map(B=>B.id))||[];Z.length===0&&(Z=(V==null?void 0:V.map(B=>B.id))||[]),z({id:-1,model:d,report_name:"printscreen.list",type:"ir.actions.report.xml",datas:{model:d,ids:Z}});return}A(!0)},disabled:c||a||T||M}),e.jsx(In,{visible:$,locale:P,onClose:()=>A(!1),model:d,domain:Ct(((j=u==null?void 0:u.current)==null?void 0:j.getDomain())||[],w||[]),limit:F,totalRegisters:L||0,selectedRegistersToExport:o,visibleRegisters:(V==null?void 0:V.length)||0,context:x})]})}function rt(){return e.jsx("div",{className:"inline-block w-2"})}const Jl=t=>{const{visible:r,searchTreeRef:n,model:s,context:o,formView:i,treeView:a,domain:c,setCurrentItemIndex:h,results:d,setCurrentId:u,setCurrentView:f,availableViews:g,searchTreeNameSearch:w}=t,{currentView:y,setPreviousView:m}=l.useContext(Ge);return r?e.jsxs(e.Fragment,{children:[e.jsx(Bt,{children:e.jsx(zl,{toolbar:a==null?void 0:a.toolbar,parentContext:o,treeExpandable:(a==null?void 0:a.isExpandable)||!1})}),e.jsx(tr,{ref:n,rootTree:!0,model:s,parentContext:o,nameSearch:w,formView:i,treeView:a,domain:c,onRowClicked:v=>{const{id:S}=v;u(S);const T=d.findIndex(b=>b.id===S);m==null||m(y),h(T);const E=g.find(b=>b.type==="form");f(E)}})]}):null},dr=Ke.default.createContext(null),Zl=t=>{const[r,n]=l.useState(!1),[s,o]=l.useState(!1),{children:i,dashboardRef:a,openAction:c}=t;return e.jsx(dr.Provider,{value:{isLoading:r,setIsLoading:n,dashboardRef:a,openAction:c,moveItemsEnabled:s,setMoveItemsEnabled:o},children:i})};function Xl(){const{isLoading:t,dashboardRef:r,moveItemsEnabled:n,setMoveItemsEnabled:s}=l.useContext(dr),{t:o}=l.useContext(he);return e.jsxs(p.Space,{wrap:!0,children:[e.jsx(Ye,{icon:e.jsx(H.BorderOuterOutlined,{style:{color:n?"white":void 0}}),type:n?"primary":"default",tooltip:o("moveDashboard"),disabled:t,loading:!1,onClick:()=>{s(!n)}}),Ql(),e.jsx(Ye,{icon:e.jsx(H.SettingOutlined,{}),tooltip:o("configDashboard"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.configDashboard()}}),e.jsx(Ye,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:o("refresh"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.refresh()}})]})}function Ql(){return e.jsx("div",{className:"inline-block w-2"})}const Rl=t=>{const{dashboardData:r}=t,n=l.useRef(),s=l.useContext(Xe),{openShortcut:o}=s||{};return r?e.jsxs(Zl,{dashboardRef:n,openAction:i=>{o(i)},children:[e.jsx(Bt,{children:e.jsx(Xl,{})}),e.jsx(Qn,{ref:n,model:r.model,id:r.id,context:r==null?void 0:r.context,configAction:r==null?void 0:r.configAction})]}):null};async function ec(t){const r=await Promise.all(t.map(async s=>{try{return await s.promise}catch(o){return console.error(`Error for ${s.viewTuple}:`,o),null}}));return t.map((s,o)=>({...s,info:r[o]})).filter(s=>s.info!==null)}function tc(t,r){const{domain:n,model:s,context:o,views:i,title:a,setCanWeClose:c,tabKey:h,initialView:d,formDefaultValues:u,formForcedValues:f={},res_id:g=!1,action_id:w,action_type:y,treeExpandable:m=!1,limit:v}=t,[S,T]=l.useState(),[E,b]=l.useState([]),[V,F]=l.useState(!0),L=g||void 0,[x,O]=l.useState(L),[_,C]=l.useState([]),[P,I]=l.useState(),[D,$]=l.useState([]),[A,M]=l.useState(),[N,k]=l.useState(0),[Y,z]=l.useState(!1),[j,U]=l.useState(!1),[Z,B]=l.useState(),{t:W}=l.useContext(he),R=l.useRef(),re=l.useRef(),ce=l.useContext(Xe),{setCurrentView:X,setCurrentId:Q,tabs:ue,activeKey:pe,openAction:ke,onRemoveTab:Fe}=ce||{};To.useHotkeys("ctrl+g,command+g",te=>{te.preventDefault(),Me()},[pe,ue,S,P,D]);function Ee(te){O(te),Q==null||Q(te)}function Be(te){T(te),X==null||X(te)}l.useImperativeHandle(r,()=>({canWeClose:ie}));const Se=async()=>{F(!0);const te=[],we=[];for(const ae of i){const[fe,Ae]=ae;Ae!=="dashboard"?we.push({viewTuple:ae,promise:K.getHandler().getView({model:s,type:Ae,id:fe,context:o})}):we.push({viewTuple:ae})}const _e=await ec(we);for(const ae of _e){if(!ae)continue;const[,fe]=ae.viewTuple;let Ae=ae.info;switch(fe){case"dashboard":{const de=i.find(Le=>{const[,ee]=Le;return ee==="form"});let qe;de&&(qe={action_id:w,action_type:y,name:a,res_id:o.active_id,res_model:s,view_id:de[0],view_type:de[1]}),te.push({type:"dashboard",id:o.active_id,model:s,context:o,configAction:qe});break}case"form":{te.push({...Ae,type:fe});break}case"tree":{te.push({...Ae,isExpandable:m,type:fe});break}case"graph":{te.push({...Ae,type:fe});break}}}let Ie;!d&&te.find(ae=>ae.type==="tree")?Ie=te.find(fe=>fe.type==="tree"):d?Ie=te.find(fe=>d.id?fe.type===d.type&&fe.view_id===d.id:fe.type===d.type):Ie=te.find(fe=>fe.type==="form"),Ie||(Pe(`Error determining the first view to show for model ${s}.
39
+ `,Cn=Ke.default.createContext(null),qa=({children:t,initialView:r})=>{const[n,s]=l.useState(r),[o,i]=l.useState(0),[a,c]=l.useState(!1);return e.jsx(Cn.Provider,{value:{currentView:n,setCurrentView:s,itemIndex:o,setItemIndex:i,manualTriggerChange:a,setManualTriggerChange:c},children:t})},{getValueForOperator:bn}=se.graphProcessor,It=.7,At=30,xn=t=>{const{model:r,domain:n,context:s,colorCondition:o,totalDomain:i,showPercent:a=!1,icon:c,suffix:h,field:d,operator:u,manualIds:f}=t,[g,w]=l.useState(!1),[y,m]=l.useState(),[v,S]=l.useState(),[T,E]=l.useState(),[b,V]=l.useState(0),[F,L]=l.useState(0),[x,O]=l.useState(),[_,C]=l.useState(),[P,I]=l.useState();l.useEffect(()=>{A()},[r,o]);async function D({domain:M,isTotal:N}){if(N)return await $({domain:M});if(d&&u){const k=f||await K.getHandler().searchAllIds({params:M,model:r,context:s}),Y=await K.getHandler().readObjects({model:r,ids:k,fieldsToRetrieve:[d],context:s});return bn({values:Y.map(z=>z[d]),operator:u})}else return f?f.length:await K.getHandler().searchCount({model:r,params:M,context:s})}async function $({domain:M}){if(d&&u){const N=await K.getHandler().searchAllIds({params:M,model:r,context:s}),k=await K.getHandler().readObjects({model:r,ids:N,fieldsToRetrieve:[d],context:s});return bn({values:k.map(Y=>Y[d]),operator:u})}else return await K.getHandler().searchCount({model:r,params:M,context:s})}async function A(){w(!0);let M,N;try{const k=await D({domain:n,isTotal:!1});if(m(k),i){const Y=await K.getHandler().evalDomain({domain:i,values:{},context:s});M=await D({domain:Y,isTotal:!0}),E(M)}if(M?(N=Math.round(k/M*100*100)/100,S(N)):S(0),o){const Y=await K.getHandler().parseCondition({condition:o,values:{value:k,percent:N},context:s});O(Y)}if(c)if(c.indexOf(":")!==-1){const Y=await K.getHandler().parseCondition({condition:c,values:{value:k,percent:N},context:s});C(Y)}else C(c)}catch(k){I(JSON.stringify(k))}w(!1)}return P?e.jsx(p.Alert,{className:"mt-10",message:P,type:"error",banner:!0}):g?e.jsx("div",{style:{padding:"1rem"},children:e.jsx(H.LoadingOutlined,{style:{height:"12px"}})}):e.jsx(Yt.default,{bounds:!0,onResize:M=>{var N,k;V((N=M.bounds)==null?void 0:N.height),L((k=M.bounds)==null?void 0:k.width)},children:({measureRef:M})=>a?e.jsx(Ga,{value:y,total:T,percent:v,measureRef:M,height:b,width:F,color:x,icon:_,suffix:h}):e.jsx(Ua,{value:y,total:T,measureRef:M,height:b,width:F,color:x,icon:_,suffix:h})})};function Tn(t,r){const s=document.createElement("canvas").getContext("2d");return s.font=r||getComputedStyle(document.body).font,s.measureText(t).width}function Ua({measureRef:t,width:r,height:n,total:s,value:o,color:i,icon:a,suffix:c}){let h=n*It<At?At:n*It;const d=o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0});let u=s?`${d}/${s}`:`${d}`;c&&(u+=" "+c);let f=Tn(u,`bold ${Math.floor(h*1.03)}px sans-serif`);a&&(f=f*2),f>=r*.85&&(h=r*.85/f*h);const g=a&&Je(a,{style:{fontSize:h*.7}});return e.jsx("div",{ref:t,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden"},children:e.jsxs(qt.default,{style:{fontSize:h,margin:0,color:i},children:[g&&e.jsx(g,{style:{fontSize:h*.7}}),g?` ${u}`:u]})})}function Ga({measureRef:t,height:r,width:n,percent:s,total:o,value:i,color:a,icon:c,suffix:h}){const d=r*.65;let u=d*It<At?At:d*It;const f=i==null?void 0:i.toLocaleString("es-ES",{useGrouping:!0});let g=o?`${f}/${o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0})}`:`${f}`;h&&(g+=" "+h);const w=`${s==null?void 0:s.toLocaleString("es-ES",{useGrouping:!0})}%`;let y=Tn(w,`bold ${Math.floor(u*1.03)}px sans-serif`);c&&(y=y*1.5),(y>=n*.85||u*2<d)&&(u=n*.85/y*u);const m=c&&Je(c,{style:{fontSize:u}});return e.jsx("div",{ref:t,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexDirection:"column",padding:"0.2rem"},children:e.jsxs(p.Row,{align:"middle",children:[m&&e.jsx(p.Col,{style:{fontSize:u*1,color:a,paddingRight:"10px"},children:e.jsx(m,{})}),e.jsxs(p.Col,{children:[e.jsx(qt.default,{style:{fontSize:u*.8,margin:0,color:a},children:m?` ${s}%`:`${s}%`}),e.jsx(qt.default,{style:{fontSize:u*.4,margin:0,color:a,textAlign:"center"},children:g})]})]})})}const nr=t=>r=>{const n=r.value.toLocaleString("es-ES",{useGrouping:!0});return{name:t==="pie"?r.x:r.type,value:n}},$t=t=>{if(typeof t=="string"&&ja(t))return parseFloat(t).toLocaleString("es-ES",{useGrouping:!0});if(za(t))return t.toLocaleString("es-ES",{useGrouping:!0});if(Ja(t)){const r=Za(t);return r===null?t:Ze(t,Lt.input[r]).format(Lt.output[r])}else return t},ja=t=>/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(t),za=t=>typeof t=="number"&&!isNaN(t),Fn={default:{padding:"auto",xAxis:{tickCount:5,label:{formatter:$t}},yAxis:{label:{formatter:$t}},legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:nr("default")}},pie:{appendPadding:10,radius:.9,label:{type:"inner",offset:"-30%",content:({percent:t})=>`${(t*100).toFixed(0)}%`,style:{fontSize:14,textAlign:"center"}},legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:nr("pie")},interactions:[{type:"element-active"}]},barGrouped:{isGroup:!0,legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:nr("barGrouped")},xAxis:{label:{formatter:$t}},yAxis:{label:{formatter:$t}},label:{position:"middle",layout:[{type:"interval-adjust-position"},{type:"interval-hide-overlap"},{type:"adjust-color"}]}}};function Ja(t){return typeof t!="string"||t===void 0?!1:new Date(t).toString()!=="Invalid Date"}const Lt={input:{hours:"YYYY-MM-DD HH:mm",days:"YYYY-MM-DD",weeks:"YYYY-[W]WW",months:"YYYY-MM",years:"YYYY"},output:{hours:"DD/MM/YYYY HH:mm",days:"DD/MM/YYYY",weeks:"[W]WW/YYYY",months:"MM/YYYY",years:"YYYY"}};function Za(t){for(const r in Lt.input)if(Ze(t,Lt.input[r],!0).isValid())return r;return null}const{processGraphData:Xa}=se.graphProcessor,{getFieldsToRetrieve:Qa}=se.graphFieldUtils,Ra=t=>{const{model:r,domain:n=[],context:s={},xml:o,limit:i,uninformedString:a,manualIds:c}=t,[h,d]=l.useState(!1),[u,f]=l.useState(),[g,w]=l.useState(),[y,m]=l.useState(),[v,S]=l.useState("line");return tt.default(()=>{(async()=>{d(!0),f(void 0);const T=se.parseGraph(o);S(T.type||"line");const E=Qa({ooui:T});let b,V;try{({values:b,fields:V}=await tl({model:r,domain:n,context:s,limit:i,order:T.timerange?T.x.name:null,fields:E,manualIds:c}))}catch(F){f("Error fetching graph data values: "+JSON.stringify(F)),d(!1);return}try{if(!b||!V){f("No values or fields returned"),d(!1);return}m(b);const F=Xa({ooui:T,values:b,fields:V,options:{uninformedString:a}});w(F)}catch(F){f("Error processing graph data: "+F),d(!1);return}d(!1)})()},[o,r,i,s,n]),{loading:h,error:u,type:v,values:g,evaluatedEntries:y}};async function el({model:t,context:r,fields:n}){return await K.getHandler().getFields({model:t,context:r,fields:n})}async function tl({fields:t,model:r,domain:n,context:s,order:o,limit:i,manualIds:a}){const c=await el({model:r,context:s,fields:t});if(a){let d=await K.getHandler().readObjects({model:r,ids:a,fieldsToRetrieve:t,context:s});return o&&(d=[...d].sort((u,f)=>u[o]-f[o])),{values:d,fields:c}}return{values:await K.getHandler().search({model:r,params:n,fields:t,context:s,limit:i,order:o}),fields:c}}const rl={line:Wt.Line,bar:Wt.Column,pie:Wt.Pie},nl=t=>{var S;const{model:r,domain:n,context:s,xml:o,limit:i,manualIds:a}=t,{t:c}=l.useContext(he),{error:h,loading:d,values:u,type:f,evaluatedEntries:g}=Ra({model:r,xml:o,limit:i,domain:n,context:s,uninformedString:c("uninformed"),manualIds:a});if(h)return e.jsx(p.Alert,{message:h,type:"error",banner:!0});if(d)return e.jsx(p.Spin,{});if(!u)return e.jsx(p.Alert,{message:"No data to display",type:"info"});const{data:w,isGroup:y,isStack:m}=u,v=rl[f];return v?e.jsxs("div",{style:{padding:"1rem"},children:[e.jsx("p",{style:{textAlign:"right"},children:`${c("totalRegisters")} ${(S=g==null?void 0:g.length)==null?void 0:S.toLocaleString("es-ES",{useGrouping:!0})}`}),e.jsx(v,{...ol({type:f,data:w,isGroup:y,isStack:m})})]}):e.jsx(e.Fragment,{children:`Unknown graph type: ${f}`})};function ol(t){const{type:r,data:n,isGroup:s,isStack:o}=t;let i=Fn[r];return i||(i=Fn.default),i.data=n,r==="pie"?(i.colorField="x",i.angleField="value"):(i.xField="x",i.yField="value",i.seriesField="type",i.isGroup=s,o&&(i.isStack=!0,i.groupField="stacked")),i}const sl=(t,r)=>{const{view_id:n,model:s,context:o,domain:i,limit:a,manualIds:c}=t,[h,d]=l.useState(!1),[u,f]=l.useState(),[g,w]=l.useState(),y=l.useContext(Ge),{setGraphIsLoading:m=void 0}=y||{};l.useImperativeHandle(r,()=>({refresh:()=>{v()}})),l.useEffect(()=>{v()},[n]);async function v(){d(!0),m==null||m(!0);try{const S=await K.getHandler().getView({model:s,id:n,type:"graph",context:o});w(S.arch);const T=se.parseGraph(S.arch);f(T)}catch(S){return console.error(S),e.jsx(e.Fragment,{children:JSON.stringify(S)})}d(!1),m==null||m(!1)}if(h)return e.jsx("div",{style:{width:"100%",display:"flex",height:"20%",justifyContent:"center",alignContent:"center",padding:"1rem"},children:e.jsx(H.LoadingOutlined,{style:{height:"12px"}})});if(!u)return null;switch(u.type){case"indicatorField":case"indicator":{const S=u,T=S.type==="indicatorField"?{field:S.field,operator:S.operator}:{};return e.jsx(xn,{showPercent:S.showPercent,totalDomain:S.totalDomain,colorCondition:S.color,model:s,context:o,domain:i,icon:S.icon,suffix:S.suffix,manualIds:c,...T})}case"line":case"bar":case"pie":return e.jsx(nl,{model:s,context:o,domain:i,xml:g,limit:a,manualIds:c});default:return e.jsx(e.Fragment,{children:`Graph ${u.type} not implemented`})}},Nt=l.forwardRef(sl),{confirm:il}=p.Modal,al=({onOk:t,lang:r})=>{il({title:xe("removeItems",r),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:xe("confirmRemove",r),okText:xe("yesConfirmRemove",r),onOk:t,cancelText:xe("cancel",r)})},{confirm:ll}=p.Modal,cl=({onOk:t,lang:r})=>{ll({title:xe("unlinkItems",r),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:xe("confirmUnlink",r),okText:xe("yesConfirmUnlink",r),onOk:t,cancelText:xe("cancel",r)})},{useToken:dl}=p.theme,ul=t=>{const{title:r,readOnly:n,onCreateItem:s,onToggleViewMode:o,mode:i,onDelete:a,totalItems:c,currentItemIndex:h,onPreviousItem:d,onNextItem:u,isMany2Many:f,onSearchItem:g,selectedRowKeys:w,showCreateButton:y,showToggleButton:m}=t,{token:v}=dl();function S(){return e.jsx("div",{className:"inline-block w-3"})}function T(){return e.jsx("div",{className:"flex flex-grow h-8 text-white",style:{borderRadius:v.borderRadius,backgroundColor:v.colorPrimaryActive},children:e.jsx("div",{className:"flex flex-col items-center justify-center h-full",children:e.jsx("span",{className:"pl-2 font-bold",children:r})})})}function E(){return e.jsx(We,{tooltip:f?"Unlink":"Delete",icon:f?e.jsx(H.ApiOutlined,{}):e.jsx(H.DeleteOutlined,{}),onClick:a,disabled:c===0||n||i!=="form"&&w.length===0})}function b(){let F="_";return c===0?F="_":F=(h+1).toString(),e.jsxs("span",{className:"pl-1 pr-1",children:["(",F,"/",c,")"]})}function V(){return e.jsxs(e.Fragment,{children:[S(),e.jsx(We,{tooltip:"Previous item",icon:e.jsx(H.LeftOutlined,{}),onClick:d}),b(),e.jsx(We,{tooltip:"Next item",icon:e.jsx(H.RightOutlined,{}),onClick:u})]})}return e.jsxs("div",{className:"flex mb-2",children:[T(),e.jsxs("div",{className:"flex-none h-8 pl-2",children:[i!=="graph"&&y&&e.jsx(We,{tooltip:"Create new item",icon:e.jsx(H.FileAddOutlined,{}),disabled:n,onClick:s}),f&&y&&e.jsx(We,{tooltip:"Search existing item",icon:e.jsx(H.SearchOutlined,{}),disabled:n,onClick:g}),i!=="graph"&&S(),i!=="graph"&&E(),i==="form"&&V(),S(),m&&e.jsx(We,{tooltip:"Toggle view mode",icon:e.jsx(H.AlignLeftOutlined,{}),onClick:o})]})]})},fl={form:se.Form,tree:se.Tree,graph:Nt};function hl(t){const r=t.map(s=>s.id);return t.filter((s,o)=>{const{id:i}=s;return!r.includes(i,o+1)})}const pl=t=>{var Le;const{value:r,onChange:n,ooui:s,views:o}=t,{items:i=[]}=r||{},{currentView:a,setCurrentView:c,itemIndex:h,setItemIndex:d}=l.useContext(Cn),u=l.useContext(De),{activeId:f,getFields:g,getValues:w,getContext:y,domain:m}=u||{},{lang:v,t:S}=l.useContext(he),[T,E]=l.useState(!1),[b,V]=l.useState(!1),[F,L]=l.useState(),[x,O]=l.useState(!1),[_,C]=l.useState(!1),[P,I]=l.useState(),[D,$]=l.useState([]),[A,M]=l.useState(!1),N=l.useRef([]),[k,Y]=l.useState(),z=l.useRef(),[j,U]=l.useState(void 0),{readOnly:Z,relation:B,context:W,domain:R}=s,re=s.type==="many2many",{id:ce}=s,X=i.filter(ee=>(ee.values||ee.treeValues)&&ee.operation!=="pendingRemove"),Q=l.useRef();l.useEffect(()=>{if(Q.current!==a){Q.current=a,ue();return}ue()},[i,a]);const ue=l.useCallback(()=>{(a==="form"&&i.some(ee=>!ee.values)||a==="tree"&&i.some(ee=>!ee.treeValues))&&ke()},[i,a]);l.useEffect(()=>{Ee()},[m]);const pe=ee=>{var le,Ce;n==null||n({fields:((le=o.get("form"))==null?void 0:le.fields)||((Ce=o.get("tree"))==null?void 0:Ce.fields),items:hl(ee)})},ke=async()=>{await Fe(),h>X.length-1&&h!==0&&d(0)},Fe=async ee=>{var le,Ce,ye;V(!0),E(!1),L(void 0);try{const[be,Te]=await Jt({treeView:{arch:(le=o.get("tree"))==null?void 0:le.arch,fields:(Ce=o.get("tree"))==null?void 0:Ce.fields},formView:{fields:((ye=o.get("form"))==null?void 0:ye.fields)||{}},model:B,items:i,context:{...y==null?void 0:y(),...W},currentView:ee||a});return z.current||(z.current=be.map(je=>je.id)),(a||ee)==="tree"&&Te&&U(Te),pe(be),be}catch(be){L(be)}finally{V(!1)}};async function Ee(){R&&(N.current=await K.getHandler().evalDomain({domain:R,values:dt({fields:g(),values:w()}),fields:g(),context:y()})),m&&m.length>0&&(N.current=N.current.concat(se.transformDomainForChildWidget({domain:m,widgetFieldName:ce})))}const Be=()=>{const ee=Array.from(o.keys()),le=ee[(ee.indexOf(a)+1)%ee.length];a==="form"?ve(()=>{c(le)}):c(le)},Se=()=>{h>0&&(a==="form"?ve(()=>{d(h-1)}):d(h-1))},ie=()=>{const ee=X.length;h<ee-1&&(a==="form"?ve(()=>{d(h+1)}):d(h+1))},Me=async()=>{const ee=X[h].id,le=(await K.getHandler().readObjects({model:B,ids:[ee],fields:o.get("form").fields,context:{...y==null?void 0:y(),...W}}))[0],Ce=(await K.getHandler().readObjects({model:B,ids:[ee],fields:o.get("tree").fields,context:{...y==null?void 0:y(),...W}}))[0],ye=i.map(be=>be.id===ee?{...be,operation:"original",values:le,treeValues:Ce}:be);pe(ye)},ve=ee=>{T?St({lang:v,onOk:()=>{Me(),ee(),E(!1)}}):ee()},Ve=()=>{if(re){cl({lang:v,onOk:()=>{a==="form"?we():_e()}});return}al({lang:v,onOk:()=>{a==="form"?we():_e()}})},$e=async()=>{const{inv_field:ee}=s;let le;ee&&f&&(le={[ee]:f}),a==="form"?ve(()=>{M(!0),I({defaultValues:le}),O(!0)}):(M(!0),I({defaultValues:le}),O(!0))},te=async()=>{a==="form"?ve(()=>{C(!0)}):C(!0)},we=async()=>{V(!0),E(!1),L(void 0);try{if(X[h].id>0){const ee=i.map(le=>le.id===X[h].id?{...le,operation:"pendingRemove"}:le);pe(ee)}else pe(i.filter(ee=>ee.id!==X[h].id))}catch(ee){L(ee)}d(0),V(!1)},_e=async()=>{const ee=X.filter(le=>D.includes(le.id));V(!0),E(!1),L(void 0);try{const le=ee.map(ye=>ye.id),Ce=i.filter(ye=>!(le.includes(ye.id)&&ye.id<0)).map(ye=>le.includes(ye.id)?{...ye,operation:"pendingRemove"}:ye);pe(Ce)}catch(le){L(le)}d(0),V(!1)},Ie=(ee,le,Ce,ye=!1)=>{let be;if(ye)be=i.concat({id:ee,operation:"pendingLink",values:{...Ce,id:ee},treeValues:{...Ce,id:ee}});else if(ee)be=i.map(Te=>Te.id===ee?{id:ee,operation:ee>0?"pendingUpdate":"pendingCreate",values:{...Ce,id:ee},treeValues:{...Ce,id:ee}}:Te);else{const Te=ui(i);be=i.concat({id:Te,operation:"pendingCreate",values:{...Ce,id:Te},treeValues:{...Ce,id:Te}})}pe(be),A||O(!1)},ae=async ee=>{const{id:le}=ee;let Ce=i;const ye=i.find(be=>be.id===le);(ye==null?void 0:ye.values)===void 0&&(Ce=await Fe("form")),I(Ce.find(be=>be.id===le)),M(!1),O(!0)},fe=async ee=>{V(!0);let le=i;const Ce=ee.filter(ye=>!i.find(be=>be.id===ye));try{for(const ye of Ce){const be=(await K.getHandler().readObjects({model:B,ids:[ye],fields:o.get("form").fields,context:{...y==null?void 0:y(),...W}}))[0],Te=(await K.getHandler().readObjects({model:B,ids:[ye],fields:o.get("tree").fields,context:{...y==null?void 0:y(),...W}}))[0];le.push({id:ye,operation:"pendingLink",values:be,treeValues:Te})}pe(le)}catch(ye){L(ye)}finally{V(!1)}};function Ae(){const ee=fl[a];if(a==="graph")return se.parseGraph(o.get("graph").arch).string;{const le=new ee(o.get(a).fields);return le.parse(o.get(a).arch),le.string}}const de=()=>{var le,Ce,ye,be;if(a==="form")return X.length===0?S("noCurrentEntries"):a!==Q.current&&i.some(Te=>!Te.values)?e.jsx(p.Spin,{}):e.jsx(ft,{formView:o.get("form"),values:(le=X[h])==null?void 0:le.values,parentContext:{...y==null?void 0:y(),...W},model:B,id:(Ce=X[h])==null?void 0:Ce.id,submitMode:"values",onFieldsChange:Te=>{var Oe;const je=(Oe=X[h])==null?void 0:Oe.id,He=i.map(Ne=>Ne.id===je?{...Ne,operation:Ne.operation==="original"?"pendingUpdate":Ne.operation,values:{...Te,id:je},treeValues:{...Te,id:je}}:Ne);pe(He),E(!0)},readOnly:Z});let ee=[];if(X.some(Te=>Te.treeValues)&&(ee=k?lt({resultsToSort:X.map(Te=>Te.treeValues),sorter:k,fields:{...o.get("tree").fields,...((ye=o.get("form"))==null?void 0:ye.fields)||{}}}):X.map(Te=>Te.treeValues)),a==="tree")return e.jsx(Tt,{total:X.length,limit:X.length,treeView:o.get("tree"),results:ee,loading:b,onRowClicked:((be=o.get("form"))==null?void 0:be.fields)!==void 0?ae:void 0,showPagination:!1,rowSelection:{selectedRowKeys:D,onChange:$},sorter:k,onChangeSort:Y,context:{...y==null?void 0:y(),...W},colorsForResults:j,readonly:Z});if(a==="graph"){const Te=[[`${s.inv_field}`,"=",f]];return e.jsx(Nt,{view_id:o.get("graph").view_id,model:s.relation,domain:Te,context:{...y==null?void 0:y(),...W},limit:0})}};if(F)return e.jsx(p.Alert,{className:"mt-10",message:F,type:"error",banner:!0});const qe=A;return b?e.jsx(p.Spin,{}):e.jsxs(e.Fragment,{children:[e.jsx(ul,{mode:a,title:Ae(),readOnly:Z,isMany2Many:re,formHasChanges:T,totalItems:X.length,currentItemIndex:h,onDelete:Ve,onCreateItem:$e,onToggleViewMode:Be,onPreviousItem:Se,onNextItem:ie,onSearchItem:te,selectedRowKeys:D,showCreateButton:((Le=o.get("form"))==null?void 0:Le.fields)!==void 0,showToggleButton:o.size>1}),de(),e.jsx(ht,{formView:o.get("form"),model:B,id:P==null?void 0:P.id,submitMode:"2many",values:P==null?void 0:P.values,defaultValues:P==null?void 0:P.defaultValues,visible:x,onSubmitSucceed:Ie,parentContext:{...y==null?void 0:y(),...W},onCancel:()=>{M(!1),O(!1)},readOnly:Z,mustClearAfterSave:qe}),e.jsx(rr,{domain:N.current,model:B,context:{...y==null?void 0:y(),...W},visible:_,onSelectValues:async ee=>{C(!1),fe(ee)},onCloseModal:()=>{C(!1)}})]})},On=t=>{const{ooui:r}=t,{mode:n,relation:s,views:o,required:i,context:a}=r;let c;const[h,d]=l.useState(!0),[u,f]=l.useState(),[g,w]=l.useState(new Map),y=l.useContext(De),{getContext:m}=y||{};tt.default(()=>{S()},[r]);const v=async E=>o&&o[E]?o[E]:await K.getHandler().getView({model:s,type:E,context:{...m==null?void 0:m(),...a}}),S=async()=>{d(!0),f(void 0);try{if(n&&n.length>0){for(const E of n){const b=await v(E);g.set(E,b)}w(g)}else{const E=await v("form"),b=await v("tree");g.set("form",E),g.set("tree",b),w(g)}}catch(E){f(JSON.stringify(E))}finally{d(!1)}};if(n&&n.length>0?c=n[0]:c="tree",h)return e.jsx(p.Spin,{});if(u)return e.jsx(p.Alert,{className:"mt-10",message:u,type:"error",banner:!0});const T=async(E,b)=>{if(!b)throw new Error;if(!b.items)throw new Error;if(!Array.isArray(b.items))throw new Error;if(b.items.length===0)throw new Error};return e.jsx(qa,{initialView:c,children:e.jsx(me,{required:i,type:"array",validator:T,...t,children:e.jsx(pl,{ooui:r,views:g})})})},{useToken:gl}=p.theme,_n=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"number",...t,children:e.jsx(ml,{ooui:r})})},ml=t=>{const{ooui:r,value:n,onChange:s}=t,{id:o,readOnly:i,required:a}=r,{token:c}=gl(),h=a&&!i?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useRef(),[u,f]=l.useState(),g=l.useContext(De),{elementHasLostFocus:w}=g||{};l.useEffect(()=>{f(ln(n))},[n]);const y=S=>{s==null||s(S)};function m(S){d.current=S.target.value,f(S.target.value)}async function v(){y(ma(u)),await new Promise(S=>setTimeout(S,300)),w==null||w()}return e.jsx(p.Input,{value:u,disabled:i,className:"w-full",style:h,id:o,placeholder:"00:00",onChange:m,onBlur:v})};function or(t){const{ooui:r,showLabel:n=!0,responsiveBehaviour:s}=t,o=Je(r.icon||"");return e.jsx(e.Fragment,{children:(r.label||o)&&n?e.jsx(yr.FieldSet,{label:r.label,icon:o,children:e.jsx(Xt,{container:r.container,responsiveBehaviour:s})}):e.jsx(Xt,{container:r.container,responsiveBehaviour:s})})}const{TabPane:yl}=p.Tabs;function Dn(t){const{ooui:r,responsiveBehaviour:n}=t,s=r.pages;function o(i){if(i){const a=Je(i);return a&&e.jsx(a,{})}}return e.jsx(p.Tabs,{defaultActiveKey:"1",tabPosition:r.tabPosition,children:s.filter(i=>!i.invisible).map(i=>e.jsx(yl,{tab:e.jsxs(e.Fragment,{children:[o(i.icon)," ",i.label]}),children:e.jsx(or,{ooui:i,showLabel:!1,responsiveBehaviour:n})},i.label))})}const{useToken:vl}=p.theme,{TextArea:sr}=p.Input,kn=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o,height:i,translatable:a}=r,{token:c}=vl(),h=o&&!s?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useContext(De),{elementHasLostFocus:u}=d||{};return e.jsx(me,{required:o,...t,children:a?e.jsx(wl,{field:n,height:i,requiredStyle:h}):e.jsx(sr,{disabled:s||a,style:{minHeight:i?i+"px":"100%",...h},rows:4,onBlur:u})})},wl=({value:t,field:r,requiredStyle:n,onChange:s,height:o})=>{const i=l.useContext(De),{activeId:a,activeModel:c,fetchValues:h,formHasChanges:d,elementHasLostFocus:u}=i||{},[f,g]=l.useState(!1),{t:w}=l.useContext(he);return a?e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>{if(d!=null&&d()){Qe(w("saveBeforeTranslate"));return}f||g(!0)},children:e.jsx(sr,{value:t,onChange:y=>{s==null||s(y.target.value)},style:{height:o?o+"px":"100%",cursor:"pointer",pointerEvents:"none",...n},id:r,disabled:!0,rows:4,onBlur:u})}),e.jsx(kr,{id:a,model:c,field:r,visible:f,onCloseModal:()=>{g(!1)},onSubmitSucceed:()=>{g(!1),h==null||h()}})]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Row,{gutter:8,wrap:!1,children:e.jsx(sr,{value:t,onChange:y=>{s==null||s(y.target.value)},style:{height:o?o+"px":"100%",...n},id:r,rows:4,onBlur:u})}),e.jsx(p.Row,{justify:"end",style:{paddingTop:5},children:e.jsx(We,{tooltip:w("translate"),icon:e.jsx(H.TranslationOutlined,{}),onClick:async()=>{d!=null&&d()?Qe(w("saveBeforeTranslate")):Qe(w("enterTextBeforeTranslate"))},children:w("translate")})})]})},Mn=t=>{const{ooui:r}=t,{label:n,icon:s}=r,o=Je(s||"");return e.jsx(p.Divider,{orientation:"left",className:"text-sm",children:(o||n)&&e.jsxs(p.Space,{children:[o?e.jsx(o,{}):null,n]})})},Sl=({model:t,context:r,locale:n,selectedRegistersToExport:s,domain:o,limit:i,onClose:a})=>{const c=l.useRef({}),h=l.useRef(new Map),d=l.useCallback(async v=>{if(v.selectedKeys===void 0||v.selectedKeys.length===0){Qe(xe("selectAtLeastOneField",n));return}let S=o;v.registersAmount==="selected"&&(s==null?void 0:s.length)!==0&&(S=[["id","in",s==null?void 0:s.map(b=>b.id)]]);const{datas:T}=await K.getHandler().exportData({model:t,fields:Ol({keys:v.selectedKeys,fields:c.current}),domain:S,limit:v.registersAmount==="all"?0:i,context:r,format:v.exportType});a(),await new Promise(b=>setTimeout(b,200));const E=await it(T);kt(T,E.mime)},[n,t,o,i,r,a]),u=l.useCallback(async()=>{const v=await K.getHandler().getFields({model:t,context:r,fields:[]});return c.current["/"]=v,Vn({fields:v})},[t,r,c]),f=l.useCallback(async v=>{const T=ar(v,c.current)[ir(v)],E=T.relation,b=await K.getHandler().getFields({model:E,context:r,fields:[]});for(const[V,F]of Object.entries(b))b[V].string=bl({parentTitle:T.string,title:F.string});return c.current[v]=b,Vn({fields:b,parentKey:v})},[c.current,t,r]),g=l.useCallback(async()=>{const v=await xl({model:t,context:r}),S=await Fl({predefinedExports:v,fields:c.current,onGetFieldChilds:f});return{predefinedExports:v.map(E=>({...E,fields:E.fields.map(b=>{const V=ir(b.key),L=ar(b.key,c.current)[V];return{key:b.key,title:L.string}})})),keysWithChilds:S}},[c.current]),w=l.useCallback(async v=>{const S=await m("ir.exports"),T=await m("ir.exports.line"),E=await K.getHandler().create({model:"ir.exports",values:{name:v.name,resource:t},fields:S,context:r});return await Promise.all(v.fields.map(async b=>await K.getHandler().create({model:"ir.exports.line",values:{name:b.key,export_id:E},fields:T,context:r}))),{...v,id:E}},[]),y=l.useCallback(async v=>{await K.getHandler().delete({model:"ir.exports",ids:[v.id],context:r})},[]),m=l.useCallback(async v=>{if(h.current.has(v))return h.current.get(v);const S=K.getHandler().getFields({model:v,context:r,fields:[]});h.current.set(v,S)},[h,r]);return{onGetFields:u,onGetFieldChilds:f,onExport:d,onGetPredefinedExports:g,onSavePredefinedExport:w,onRemovePredefinedExport:y}},Vn=({fields:t,parentKey:r})=>{const n=[];for(const s of Object.keys(t)){const o=t[s];if(o.relation&&o.is_function===!0)continue;const i=En(o);n.push({key:Cl({key:s,parentKey:r}),title:o.string,tooltip:o.help,required:o.required,isLeaf:!i})}return n},En=t=>t.type==="many2one"||t.type==="one2many"||t.type==="many2many",Cl=({parentKey:t,key:r})=>`${t?t+"/":""}${r}`,Ft=t=>t.indexOf("/")===-1?t:t.split("/").slice(0,-1).join("/"),ir=t=>{if(t.indexOf("/")===-1)return t;const r=t.split("/");return r[r.length-1]},ar=(t,r)=>t.indexOf("/")===-1?r["/"]:r[Ft(t)],bl=({title:t,parentTitle:r})=>`${r?r+" \u2192 ":""}${t}`,xl=async({model:t,context:r})=>{const n=await K.getHandler().search({model:"ir.exports",params:[["resource","=",t]],context:r}),s=n.flatMap(i=>i.export_fields),o=await K.getHandler().readObjects({model:"ir.exports.line",ids:s,context:r});return n.map(i=>({id:i.id,name:i.name,fields:i.export_fields.map(a=>({key:o.find(h=>h.id===a).name}))}))},Tl=({fields:t,keys:r})=>_l([...new Set(r.filter(n=>{var s,o,i;if(n.indexOf("/")===-1)return!((s=t["/"])!=null&&s[n]);{const a=Ft(n);console.log({key:n,parentKey:a,fields:t});const c=(o=t==null?void 0:t[Ft(n)])==null?void 0:o[n];return console.log({exists:c}),!((i=t==null?void 0:t[Ft(n)])!=null&&i[n])}}).map(n=>Ft(n)))]),Fl=async({predefinedExports:t,fields:r,onGetFieldChilds:n})=>{const s=t.flatMap(a=>a.fields.map(c=>c.key)),o=Tl({fields:r,keys:s}),i=[];for(const a of o)i.push({key:a,childs:await n(a)});return i},Ol=({keys:t,fields:r})=>t.map(n=>{const s=ir(n),i=ar(n,r)[s];return En(i)?`${n}/id`:n}),_l=t=>{const r=new Map,n=[];for(const s of t){const o=s.split("/");let i="";for(const a of o){const c=i?`${i}/${a}`:a;r.has(c)||(n.push(c),r.set(c,!0)),i=c}}return n.sort((s,o)=>{const i=s.split("/").length,a=o.split("/").length;return i-a}),n},In=t=>{const{visible:r,locale:n,onClose:s,model:o,context:i,selectedRegistersToExport:a,totalRegisters:c,domain:h,limit:d,visibleRegisters:u}=t,{onExport:f,onGetFieldChilds:g,onGetFields:w,onGetPredefinedExports:y,onSavePredefinedExport:m,onRemovePredefinedExport:v}=Sl({model:o,context:i,domain:h,limit:d,selectedRegistersToExport:a,onClose:s,locale:n});return e.jsx(yr.ExportModal,{visible:r,locale:n,onSucceed:f,onCancel:s,selectedRegistersToExport:a&&a.length&&a.length>0?a.length:void 0,totalRegisters:c,onGetFieldChilds:g,onGetFields:w,visibleRegisters:u,onGetPredefinedExports:y,onSavePredefinedExport:m,onRemovePredefinedExport:v})},An=t=>{const{ooui:r}=t;return e.jsx(gn,{ooui:r})},$n=t=>{const{ooui:r}=t;return e.jsx(gn,{ooui:r,showTime:!0})};var Ln={exports:{}};(function(t,r){(function(n,s){t.exports=s()})(Re,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},s=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,o=/\d\d/,i=/\d\d?/,a=/\d*[^-_:/,()\s\d]+/,c={},h=function(m){return(m=+m)+(m>68?1900:2e3)},d=function(m){return function(v){this[m]=+v}},u=[/[+-]\d\d:?(\d\d)?|Z/,function(m){(this.zone||(this.zone={})).offset=function(v){if(!v||v==="Z")return 0;var S=v.match(/([+-]|\d\d)/g),T=60*S[1]+(+S[2]||0);return T===0?0:S[0]==="+"?-T:T}(m)}],f=function(m){var v=c[m];return v&&(v.indexOf?v:v.s.concat(v.f))},g=function(m,v){var S,T=c.meridiem;if(T){for(var E=1;E<=24;E+=1)if(m.indexOf(T(E,0,v))>-1){S=E>12;break}}else S=m===(v?"pm":"PM");return S},w={A:[a,function(m){this.afternoon=g(m,!1)}],a:[a,function(m){this.afternoon=g(m,!0)}],S:[/\d/,function(m){this.milliseconds=100*+m}],SS:[o,function(m){this.milliseconds=10*+m}],SSS:[/\d{3}/,function(m){this.milliseconds=+m}],s:[i,d("seconds")],ss:[i,d("seconds")],m:[i,d("minutes")],mm:[i,d("minutes")],H:[i,d("hours")],h:[i,d("hours")],HH:[i,d("hours")],hh:[i,d("hours")],D:[i,d("day")],DD:[o,d("day")],Do:[a,function(m){var v=c.ordinal,S=m.match(/\d+/);if(this.day=S[0],v)for(var T=1;T<=31;T+=1)v(T).replace(/\[|\]/g,"")===m&&(this.day=T)}],M:[i,d("month")],MM:[o,d("month")],MMM:[a,function(m){var v=f("months"),S=(f("monthsShort")||v.map(function(T){return T.slice(0,3)})).indexOf(m)+1;if(S<1)throw new Error;this.month=S%12||S}],MMMM:[a,function(m){var v=f("months").indexOf(m)+1;if(v<1)throw new Error;this.month=v%12||v}],Y:[/[+-]?\d+/,d("year")],YY:[o,function(m){this.year=h(m)}],YYYY:[/\d{4}/,d("year")],Z:u,ZZ:u};function y(m){var v,S;v=m,S=c&&c.formats;for(var T=(m=v.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(O,_,C){var P=C&&C.toUpperCase();return _||S[C]||n[C]||S[P].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,D,$){return D||$.slice(1)})})).match(s),E=T.length,b=0;b<E;b+=1){var V=T[b],F=w[V],L=F&&F[0],x=F&&F[1];T[b]=x?{regex:L,parser:x}:V.replace(/^\[|\]$/g,"")}return function(O){for(var _={},C=0,P=0;C<E;C+=1){var I=T[C];if(typeof I=="string")P+=I.length;else{var D=I.regex,$=I.parser,A=O.slice(P),M=D.exec(A)[0];$.call(_,M),O=O.replace(M,"")}}return function(N){var k=N.afternoon;if(k!==void 0){var Y=N.hours;k?Y<12&&(N.hours+=12):Y===12&&(N.hours=0),delete N.afternoon}}(_),_}}return function(m,v,S){S.p.customParseFormat=!0,m&&m.parseTwoDigitYear&&(h=m.parseTwoDigitYear);var T=v.prototype,E=T.parse;T.parse=function(b){var V=b.date,F=b.utc,L=b.args;this.$u=F;var x=L[1];if(typeof x=="string"){var O=L[2]===!0,_=L[3]===!0,C=O||_,P=L[2];_&&(P=L[2]),c=this.$locale(),!O&&P&&(c=S.Ls[P]),this.$d=function(A,M,N){try{if(["x","X"].indexOf(M)>-1)return new Date((M==="X"?1e3:1)*A);var k=y(M)(A),Y=k.year,z=k.month,j=k.day,U=k.hours,Z=k.minutes,B=k.seconds,W=k.milliseconds,R=k.zone,re=new Date,ce=j||(Y||z?1:re.getDate()),X=Y||re.getFullYear(),Q=0;Y&&!z||(Q=z>0?z-1:re.getMonth());var ue=U||0,pe=Z||0,ke=B||0,Fe=W||0;return R?new Date(Date.UTC(X,Q,ce,ue,pe,ke,Fe+60*R.offset*1e3)):N?new Date(Date.UTC(X,Q,ce,ue,pe,ke,Fe)):new Date(X,Q,ce,ue,pe,ke,Fe)}catch{return new Date("")}}(V,x,F),this.init(),P&&P!==!0&&(this.$L=this.locale(P).$L),C&&V!=this.format(x)&&(this.$d=new Date("")),c={}}else if(x instanceof Array)for(var I=x.length,D=1;D<=I;D+=1){L[1]=x[D-1];var $=S.apply(this,L);if($.isValid()){this.$d=$.$d,this.$L=$.$L,this.init();break}D===I&&(this.$d=new Date(""))}else E.call(this,b)}}})})(Ln);const Dl=Ln.exports;Ze.extend(Dl);const Nn=t=>{const{ooui:r}=t;return e.jsx(me,{...t,children:e.jsx(kl,{ooui:r})})},kl=t=>{const r=(n,s)=>{t.onChange&&t.onChange(s)};return e.jsx(p.TimePicker,{onChange:r,value:t.value?Ze(t.value,"HH:mm:ss"):void 0})},Pn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(Ml,{ooui:r})})},Ml=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,selectionValues:i,readOnly:a}=s,c=r==null?void 0:r.split(","),[h,d]=l.useState([]),[u,f]=l.useState();return l.useEffect(()=>{if(!r){f(void 0),d([]);return}const g=r&&c&&c[0],w=r&&c&&c[1]&&parseInt(c[1]);d([w,void 0]),f(g)},[r]),e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"1",children:e.jsx(Mr,{ooui:new se.Selection({name:"model_selection",selection:i,readonly:a,required:o}),onChange:g=>{f(g);let w=h[0]||0;g!==u&&(d([]),w=0);const y=`${g},${w}`;y!==r&&(n==null||n(y))},value:u})}),e.jsx(p.Col,{flex:"3",children:e.jsx(Sn,{ooui:new se.Many2one({name:"object_value",relation:u,readonly:a,required:o}),value:h,onChange:g=>{d(g);const w=`${u},${g[0]||0}`;w!==r&&(n==null||n(w))}})})]})},{useToken:Vl}=p.theme,Bn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(El,{ooui:r})})},El=t=>{const{ooui:r,value:n,onChange:s}=t,{readOnly:o,required:i,filenameField:a}=r,{token:c}=Vl(),h=i&&!o?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useRef(null),{setFieldValue:u,getFieldValue:f}=l.useContext(De)||{},{t:g}=l.useContext(he),w=n?si(n):"",y=E=>{s==null||s(E)};async function m(){const E=await it(n),b=`data:${E==null?void 0:E.mime};base64,${n}`,V=document.createElement("a"),F=f(a),L=f("name");V.href=b,V.download=F||L,V.click()}async function v(){const E=await it(n);kt(n,E.mime)}async function S(E){E.stopPropagation(),E.preventDefault();const b=E.target.files[0],V=await Yr(b);y(V),a&&u(a,b.name)}function T(){u(a,void 0),y(void 0)}return e.jsxs(p.Row,{gutter:8,children:[e.jsxs(p.Col,{style:{paddingBottom:5},children:[e.jsx("input",{type:"file",id:"file",ref:d,style:{display:"none"},onChange:S}),e.jsx(p.Input,{type:"text",disabled:!0,style:h,value:w})]}),e.jsx(p.Col,{children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.FolderOpenOutlined,{}),disabled:o,onClick:()=>{d.current.click()},children:"Select"}),e.jsx(p.Button,{icon:e.jsx(H.EyeOutlined,{}),disabled:!n,onClick:v,children:g("open")}),e.jsx(We,{tooltip:g("download"),disabled:!n,onClick:m,icon:e.jsx(H.DownloadOutlined,{})}),e.jsx(We,{tooltip:g("clear"),disabled:o||!n,onClick:T,icon:e.jsx(H.ClearOutlined,{})})]})})]})},lr={tree:e.jsx(H.TableOutlined,{}),form:e.jsx(H.FormOutlined,{}),graph:e.jsx(H.AreaChartOutlined,{}),calendar:e.jsx(H.CalendarOutlined,{})};function Hn(t){return t?(lr==null?void 0:lr[t.type])||e.jsx(H.FormOutlined,{}):e.jsx(H.FormOutlined,{})}function cr(t){const{currentView:r,availableViews:n,onChangeView:s,disabled:o=!1,formHasChanges:i=!1,previousView:a}=t,{t:c,lang:h}=l.useContext(he);function d(){const g=n.map((w,y)=>e.jsx(p.Menu.Item,{children:e.jsxs(p.Row,{wrap:!1,children:[e.jsx(p.Col,{flex:"none",style:{paddingRight:20},children:Hn(w)}),e.jsx(p.Col,{flex:"auto",style:{paddingRight:20},children:w.type.charAt(0).toUpperCase()+w.type.slice(1)}),e.jsx(p.Col,{flex:"none",children:e.jsx(H.CheckOutlined,{style:{opacity:r.view_id===w.view_id?1:0}})})]})},w.view_id||y));return e.jsx(p.Menu,{onClick:f,children:e.jsx(p.Menu.ItemGroup,{title:c("viewAs"),children:g})})}function u(g){if(i){St({lang:h,onOk:()=>{g()}});return}g()}function f(g){u(()=>{const w=n.find(y=>y.view_id===parseInt(g.key));s(w)})}return e.jsxs("div",{style:{display:"flex"},children:[e.jsx(We,{tooltip:a?c("viewAs")+" "+c(a.type):"",icon:Hn(a),style:{width:50,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:()=>{f({key:a==null?void 0:a.view_id})},disabled:o||n.length===1}),e.jsx(p.Dropdown,{overlay:d(),disabled:o||n.length===1,children:e.jsx(p.Button,{style:{width:25,borderTopLeftRadius:0,borderBottomLeftRadius:0},icon:e.jsx(H.DownOutlined,{style:{fontSize:"0.5em"}}),onClick:g=>g.preventDefault()})})]})}const{Search:Il}=p.Input;function pt(t){const{icon:r,tooltip:n,items:s=[],onItemClick:o,label:i,disabled:a=!1,searchable:c="auto"}=t,[h,d]=l.useState(),u=w=>{if(!w){d(void 0);return}const y=w.trim();if(y.length===0){d(void 0);return}d(y)};function f(){let w=[];h?w=s.filter(v=>v.name.toLowerCase().includes(h.toLowerCase())):w=s;const y=w.map((v,S)=>v.name==="divider"?e.jsx(p.Menu.Divider,{},"divider"+S):e.jsx(p.Menu.Item,{children:v.name},v.id)),m=c===!0||c==="auto"&&s.length>3;return e.jsxs(p.Menu,{onClick:g,children:[m&&e.jsx(Il,{onChange:v=>u(v.target.value),onSearch:u,allowClear:!0,style:{padding:5}}),e.jsx(p.Menu.ItemGroup,{title:n,children:y})]})}function g(w){const y=s.find(m=>isNaN(w.key)?m.id===w.key:m.id===parseInt(w.key));o(y)}return e.jsx(p.Dropdown,{overlay:f(),disabled:a||!s||s.length===0,children:e.jsxs(p.Button,{children:[r," ",i," ",e.jsx(H.DownOutlined,{})]})})}function Ye(t){const{onClick:r,disabled:n=!1,loading:s=!1,tooltip:o,icon:i,label:a,type:c="default"}=t,h=s?e.jsx(H.LoadingOutlined,{}):i;return e.jsxs(We,{type:c,tooltip:o,onClick:r,disabled:n,children:[h,a]})}function Kn(t){const{disabled:r=!1}=t,{formHasChanges:n,onNewClicked:s}=l.useContext(Ge),{t:o,lang:i}=l.useContext(he),a=()=>{if(n){St({lang:i,onOk:()=>{s()}});return}s()};return e.jsx(Ye,{icon:e.jsx(H.FileAddOutlined,{}),tooltip:o("new"),onClick:a,disabled:r})}const{confirm:Al}=p.Modal,$l=({onOk:t,onCancel:r,lang:n})=>{Al({title:xe("unsavedChanges",n),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:xe("confirmRefreshWithoutSave",n),okText:xe("discardAndRefresh",n),cancelText:xe("cancel",n),onOk:t,onCancel:r})};async function Wn(t,r,n){const s=(await K.getHandler().getLogInfo({model:t,ids:[r]}))[0],{create_date:o,create_uid:i,id:a,write_date:c,write_uid:h}=s;Qe(e.jsxs("div",{children:["ID: "+a," ",e.jsx("br",{}),n("createdBy")+": "+i[1]," ",e.jsx("br",{}),n("creationDate")+": "+o," ",e.jsx("br",{}),n("lastUpdatedBy")+": "+h[1]," ",e.jsx("br",{}),n("lastUpdatedDate")+": "+c]}))}const Ll=t=>{const{numberOfAttachments:r,disabled:n}=t,{t:s,lang:o}=l.useContext(he),[i,a]=l.useState(!1),c=e.jsxs(p.Button,{disabled:n,children:[e.jsx(H.LinkOutlined,{}),`(${r})`,e.jsx(H.DownOutlined,{style:{fontSize:12}})]});return n?c:e.jsx(p.Popover,{onVisibleChange:h=>a(h),visible:i,placement:"bottom",content:Nl(t,a,o),title:s("attachments"),arrowContent:null,children:c})},Nl=(t,r,n)=>{const{attachments:s=[],loading:o,onAddNewAttachment:i,onopenAttachmentLink:a,onOpenAttachmentDetail:c,onListAllAttachments:h}=t;return o?e.jsx(p.Spin,{style:{padding:20}}):e.jsxs(e.Fragment,{children:[e.jsxs("a",{style:{display:"block",paddingBottom:5},href:"#",onClick:()=>{r(!1),h()},children:[e.jsx(H.TableOutlined,{})," ",xe("listAllAttachments",n)]}),e.jsxs("a",{style:{display:"block"},href:"#",onClick:()=>{r(!1),i()},children:[e.jsx(H.FileAddOutlined,{})," ",xe("addNewAttachment",n)]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("li",{className:"ant-dropdown-menu-item-divider"}),s.map(d=>{const u=d.link?H.LinkOutlined:H.DownloadOutlined;return e.jsxs(p.Row,{style:{paddingTop:4,paddingBottom:4},wrap:!1,align:"middle",children:[e.jsx(p.Col,{flex:"auto",children:d.name}),e.jsx(p.Col,{flex:"25px",style:{textAlign:"center"},children:(d.datas_fname||d.link)&&e.jsx(p.Tooltip,{title:d.link?xe("openAttachmentLink",n):xe("download",n),children:e.jsx(u,{style:{cursor:"pointer"},onClick:()=>{r(!1),a(d)}})})}),e.jsx(p.Col,{flex:"25px",style:{textAlign:"center"},children:e.jsx(p.Tooltip,{title:xe("openAttachment",n),children:e.jsx(H.FormOutlined,{style:{cursor:"pointer"},onClick:()=>{r(!1),c(d)}})})})]},d.id)})]})]})};function Pl(t){const{attachments:r,disabled:n=!1,onAddNewAttachment:s,onListAllAttachments:o,onViewAttachmentDetails:i}=t,{formRef:a}=l.useContext(Ge),[c,h]=l.useState(!1),[d,u]=l.useState([]),[f,g]=l.useState(!1),{t:w}=l.useContext(he),y=l.useCallback(async()=>{h(!0);try{const S=await K.getHandler().readObjects({model:"ir.attachment",ids:r.map(T=>T.id),fieldsToRetrieve:["name","datas_fname","link"],context:a.current.getContext()});u(S.map(T=>({id:T.id,name:T.name,datas_fname:T.datas_fname,link:T.link})))}catch(S){Pe(S)}h(!1)},r),m=l.useCallback(async S=>{if(S.link){window.open(S.link);return}g(!0);let T;try{T=(await K.getHandler().readObjects({model:"ir.attachment",ids:[S.id],context:a.current.getContext()}))[0]}catch(E){Pe(E)}if(g(!1),!!T)if(T.datas){const E=await it(T.datas);kt(T.datas,E.mime)}else i(T)},[]),v=l.useCallback(async S=>{i(S)},[]);return l.useEffect(()=>{y()},[y]),e.jsxs(e.Fragment,{children:[e.jsx(Ll,{numberOfAttachments:r.length,attachments:d,disabled:n,loading:c,onAddNewAttachment:s,onListAllAttachments:o,onopenAttachmentLink:m,onOpenAttachmentDetail:v}),e.jsx(p.Modal,{title:w("downloadingAttachment"),open:f,footer:null,closable:!1,centered:!0,maskClosable:!1,children:e.jsx(p.Spin,{})})]})}function Yn({toolbar:t}){const{availableViews:r,currentView:n,setCurrentView:s,onFormSave:o,formHasChanges:i,formIsSaving:a,currentId:c,results:h,setCurrentItemIndex:d,currentItemIndex:u,setCurrentId:f,currentModel:g,setRemovingItem:w,removingItem:y,duplicatingItem:m,setDuplicatingItem:v,setResults:S,formIsLoading:T,attachments:E,formRef:b,setFormHasChanges:V,previousView:F,setPreviousView:L,goToResourceId:x}=l.useContext(Ge),{t:O,lang:_}=l.useContext(he),C=l.useContext(ut),{processAction:P}=C||{},I=l.useContext(Xe),{openRelate:D,openDefaultActionForModel:$}=I||{};function A(B){if(i){$l({lang:_,onOk:()=>{B()}});return}B()}function M(B){if(i){St({lang:_,onOk:()=>{B()}});return}B()}function N(){h&&h.length>u+1?(d==null||d(u+1),f==null||f(h[u+1].id)):h&&u+1===h.length&&(d==null||d(0),f==null||f(h[0].id))}function k(){h&&u>0?(d==null||d(u-1),f==null||f(h[u-1].id)):h&&u===0&&(d==null||d(h.length-1),f==null||f(h[h.length-1].id))}function Y(){st({confirmMessage:O("confirmRemoveItem"),lang:_,onOk:()=>{z()}})}async function z(){try{w==null||w(!0),await K.getHandler().delete({model:g,ids:[c],context:b.current.getContext()});const B=h==null?void 0:h.filter(R=>R.id!==c);S==null||S(B);let W=0;u>0&&u<=h.length-1&&(W=u-1),B!=null&&B[W]?(f==null||f(B==null?void 0:B[W].id),d==null||d(W)):(f==null||f(void 0),d==null||d(void 0))}catch(B){Et(JSON.stringify(B))}finally{w==null||w(!1)}}async function j(){try{v==null||v(!0);const B=await K.getHandler().duplicate({id:c,model:g,context:b.current.getContext()});B&&await(x==null?void 0:x([B]))}catch(B){Et(JSON.stringify(B))}finally{v==null||v(!1)}}const U=a||y||T||m;function Z(B){P==null||P({actionData:B,values:b.current.getValues(),fields:b.current.getFields(),context:b.current.getContext(),onRefreshParentValues:()=>{b.current.fetchValues()}})}return n?e.jsxs(p.Space,{wrap:!0,children:[T&&e.jsxs(e.Fragment,{children:[e.jsx(p.Spin,{}),gt(),gt()]}),e.jsx(Kn,{disabled:a||T||y||m}),e.jsx(Ye,{icon:e.jsx(H.SaveOutlined,{}),tooltip:O("save"),disabled:!i||U,loading:a,onClick:o}),e.jsx(Ye,{icon:e.jsx(H.CopyOutlined,{}),tooltip:O("duplicate"),disabled:i||a||c===void 0||m||T,loading:m,onClick:j}),e.jsx(Ye,{icon:e.jsx(H.DeleteOutlined,{}),tooltip:O("delete"),disabled:a||c===void 0||y||m||T,loading:y,onClick:Y}),gt(),e.jsx(Ye,{icon:e.jsx(H.InfoCircleOutlined,{}),tooltip:O("showLogs"),disabled:a||c===void 0||y||m||T,loading:!1,onClick:()=>{Wn(g,c,O)}}),e.jsx(Ye,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:O("refresh"),disabled:a||c===void 0||y||m||T,loading:!1,onClick:()=>{A(()=>{b.current.fetchValues()})}}),gt(),e.jsx(cr,{currentView:n,previousView:F,availableViews:r,onChangeView:B=>{L==null||L(n),V==null||V(!1),s==null||s(B)},disabled:U,formHasChanges:i}),gt(),e.jsxs(p.Space,{children:[e.jsx(Ye,{icon:e.jsx(H.LeftOutlined,{}),tooltip:O("previous"),disabled:U,loading:!1,onClick:()=>{M(k)}}),e.jsx(Ye,{icon:e.jsx(H.RightOutlined,{}),tooltip:O("next"),disabled:U,loading:!1,onClick:()=>{M(N)}})]}),gt(),e.jsx(pt,{icon:e.jsx(H.ThunderboltOutlined,{}),disabled:U,tooltip:O("actions"),items:t==null?void 0:t.action,onItemClick:async B=>{!B||!(await mt({onFormSave:o})).succeed||Z(B)}}),e.jsx(pt,{icon:e.jsx(H.PrinterOutlined,{}),disabled:U,tooltip:O("reports"),items:t==null?void 0:t.print,onItemClick:async B=>{if(!B)return;const W=await mt({onFormSave:o});!W.succeed||Z({...B,datas:{...B.datas||{},ids:[W.currentId]}})}}),e.jsx(pt,{icon:e.jsx(H.EnterOutlined,{}),disabled:U,tooltip:O("related"),items:t==null?void 0:t.relate,onItemClick:async B=>{!B||!(await mt({onFormSave:o})).succeed||D({relateData:B,values:b.current.getValues(),fields:b.current.getFields(),action_id:B.id,action_type:B.type})}}),e.jsx(Pl,{disabled:U,attachments:E,onAddNewAttachment:async()=>{const B=await mt({onFormSave:o});if(!B.succeed)return;const W=B.currentId,R=g;$({model:"ir.attachment",values:{selection_associated_object:`${R},${W}`},forced_values:{res_model:R,res_id:W},initialViewType:"form"})},onListAllAttachments:async()=>{const B=await mt({onFormSave:o});if(!B.succeed)return;const W=B.currentId;$({model:"ir.attachment",domain:[["res_model","=",`${g}`],["res_id","=",`${W}`]],initialViewType:"tree"})},onViewAttachmentDetails:async B=>{!(await mt({onFormSave:o})).succeed||$({model:"ir.attachment",res_id:B.id,initialViewType:"form"})}})]}):null}function gt(){return e.jsx("div",{className:"inline-block w-2"})}async function mt({onFormSave:t}){const r=await(t==null?void 0:t());return r!=null&&r.succeed?{succeed:!0,currentId:r.id}:{succeed:!1,currentId:void 0}}const{useToken:Bl}=p.theme,qn=t=>{const{ooui:r,value:n,onChange:s,valueValidator:o,linkPrefix:i=""}=t,{id:a,readOnly:c,required:h}=r,{token:d}=Bl(),u=h&&!c?{backgroundColor:d.colorPrimaryBg}:void 0,f=l.useContext(De),{elementHasLostFocus:g}=f||{},[w,y]=l.useState(!1),[m,v]=l.useState(!1);l.useEffect(()=>{c&&!w&&v(!1),!n&&!c&&(y(!0),v(!0))},[w,c]);const S=T=>{s==null||s(T.target.value)};return e.jsxs(p.Row,{gutter:8,wrap:!1,align:"middle",children:[c?null:e.jsx(p.Col,{flex:"32px",children:w?e.jsx(p.Button,{icon:e.jsx(H.CheckOutlined,{}),onClick:()=>{o(n)&&(y(!1),v(!1))},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1}):e.jsx(p.Button,{icon:e.jsx(H.EditOutlined,{}),onClick:()=>{y(!0),v(!0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1})}),e.jsx(p.Col,{flex:"auto",children:m?e.jsx(p.Input,{style:{borderTopLeftRadius:0,borderBottomLeftRadius:0,...u},id:a,onChange:S,value:n,onBlur:()=>{o(n)&&(y(!1),v(!1),g==null||g())}}):e.jsx("a",{href:`${i}${n}`,style:{color:d.colorPrimary,paddingRight:15},target:"_blank",children:n})})]})},Un=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(qn,{ooui:r,valueValidator:s=>s?Mo.default(s):!1})})},Gn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(qn,{ooui:r,linkPrefix:"mailto:",valueValidator:s=>s?Vo.default(s):!1})})},Hl=t=>{const{visible:r,onIdSubmitted:n,onCancel:s,isSearching:o}=t,{t:i}=l.useContext(he),a=l.useRef();function c(h){const d=h.id.split(",").map(u=>parseInt(u.trim()));n(d)}return e.jsx(p.Modal,{title:i("goToResourceId"),centered:!0,open:r,footer:null,destroyOnClose:!0,onCancel:s,maskClosable:!1,afterOpenChange:h=>{var d;return h&&((d=a.current)==null?void 0:d.focus())},children:e.jsxs(p.Form,{layout:"vertical",onFinish:c,autoComplete:"off",children:[e.jsx(p.Form.Item,{name:"id",label:i("searchId"),rules:[{required:!0}],help:i("searchIdHelp"),children:e.jsx(p.Input,{style:{width:"100%"},autoFocus:!0,ref:a})}),e.jsx(p.Row,{align:"middle",justify:"end",children:e.jsx(p.Col,{children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.CloseOutlined,{}),htmlType:"button",onClick:s,disabled:o,children:i("cancel")}),e.jsx(p.Button,{loading:o,style:{marginLeft:15},icon:e.jsx(H.CheckOutlined,{}),htmlType:"submit",type:"primary",disabled:o,children:i("ok")})]})})})]})})},{useToken:Kl}=p.theme;function jn(t){const{badgeNumber:r=0,...n}=t,{token:s}=Kl();return e.jsxs("div",{style:{position:"relative"},children:[r>0&&e.jsx("div",{style:{position:"absolute",left:-10,top:-10,zIndex:2},children:e.jsx("span",{style:{display:"inline-block",minWidth:"22px",padding:"2px",borderRadius:"50%",fontSize:"12px",textAlign:"center",background:s.colorPrimaryHover,color:s.colorPrimaryBg},children:r})}),e.jsx(We,{...n,style:{width:46,zIndex:0}})]})}function Wl({refreshGraph:t}){const{t:r}=l.useContext(he),{availableViews:n,currentView:s,setCurrentView:o,searchParams:i,searchVisible:a,setSearchVisible:c,graphIsLoading:h,previousView:d,setPreviousView:u}=l.useContext(Ge);return e.jsxs(p.Space,{wrap:!0,children:[e.jsx(jn,{icon:e.jsx(H.FilterOutlined,{style:{color:a?"white":void 0}}),tooltip:r("advanced_search"),type:a?"primary":"default",onClick:()=>{c==null||c(!a)},disabled:h,badgeNumber:i==null?void 0:i.length}),e.jsx(Ye,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:r("refresh"),disabled:h,loading:!1,onClick:()=>{t()}}),e.jsx(cr,{currentView:s,availableViews:n,onChangeView:f=>{u==null||u(s),o==null||o(f)},disabled:!1,previousView:d})]})}const{useToken:Yl}=p.theme,{Title:ql,Text:Pt}=p.Typography;function Bt(t){const{title:r,children:n}=t,{title:s,currentView:o,currentId:i,currentItemIndex:a,results:c,totalItems:h,selectedRowItems:d}=l.useContext(Ge),{t:u}=l.useContext(he),{token:f}=Yl();function g(){if((o==null?void 0:o.type)==="form")return i?h===0?e.jsxs(e.Fragment,{children:[u("editingDocument")," (id:"," ",e.jsx(Pt,{copyable:{icon:e.jsx(H.CopyOutlined,{style:{color:"red"}})},children:i}),")"]}):e.jsxs(e.Fragment,{children:[u("register")," ",a===void 0?1:a+1," /"," ",c.length," ",u("of")," ",h," - ",u("editingDocument")," (id:"," ",e.jsx(Pt,{copyable:!0,children:i}),")"]}):"";if((o==null?void 0:o.type)==="tree"&&d){if(d.length===1)return e.jsxs(e.Fragment,{children:["1 ",u("selectedRegisters")," - (id:"," ",e.jsx(Pt,{copyable:!0,children:d[0].id}),")"]});if(d.length>1)return e.jsxs(e.Fragment,{children:[d.length," ",u("selectedRegisters"),e.jsx(Pt,{copyable:{text:d.map(w=>w.id).join(", ")}})]})}return null}return e.jsxs("div",{style:{position:"sticky",top:80,zIndex:3},children:[e.jsxs(p.Row,{className:"shadow-md",style:{padding:"1em",borderRadius:f.borderRadius,backgroundColor:f.colorPrimaryBg},align:"middle",children:[e.jsxs(p.Col,{flex:2,children:[e.jsx(ql,{level:3,style:{marginBottom:0},children:r||s}),g()]}),e.jsx(p.Col,{flex:3,children:e.jsx(p.Row,{justify:"end",children:n})})]}),e.jsx("div",{className:"pb-5"})]})}const Ul=t=>{const{viewData:r,visible:n,model:s,context:o,domain:i,formView:a,treeView:c}=t,h=l.useRef(),d=l.useContext(Ge),{setResults:u=void 0,setCurrentItemIndex:f=void 0,currentId:g=void 0,results:w=void 0,setSelectedRowItems:y=void 0,setSearchParams:m=void 0,searchVisible:v=!0,setSearchVisible:S=void 0,sorter:T=void 0,setSorter:E=void 0,setTotalItems:b=void 0,setSearchTreeNameSearch:V=void 0,setTreeIsLoading:F=void 0,limit:L,setLimit:x,searchParams:O,searchValues:_,setSearchValues:C,currentView:P}=d||{},[I,D]=l.useState(!0);l.useEffect(()=>{var Y;(Y=h.current)==null||Y.refresh()},[O]),l.useEffect(()=>{r.view_id!==P.view_id&&D(!0)},[P]);const{clear:$,searchFilterLoading:A,searchError:M,offset:N,tableRefreshing:k}=nn({model:s,setSearchTreeNameSearch:V,setSelectedRowItems:y,searchParams:O,setSearchValues:C,setSearchParams:m,setSearchVisible:S,setTreeIsLoading:F,context:o,formView:a,treeView:c,sorter:T,setSorter:E,setCurrentItemIndex:f,setResultsActionView:u,resultsActionView:w,domain:i,currentId:g,setActionViewTotalItems:b,limit:L,setLimit:x});return!n||!r?null:e.jsxs(e.Fragment,{children:[e.jsx(Bt,{title:r.name,children:e.jsx(Wl,{refreshGraph:()=>{h.current.refresh()}})}),e.jsx(Rt,{fields:{...c.fields,...a.fields},searchFields:zr([a.search_fields,c.search_fields]),limit:L,onClear:$,offset:N,isSearching:A,onSubmit:Y=>{D(!1),m==null||m(Y.params),S==null||S(!1)},searchError:M,searchVisible:v,searchValues:_,showLimitOptions:!1}),k?e.jsx(p.Spin,{}):e.jsx(Nt,{ref:h,view_id:r.view_id,model:s,context:o,domain:Ct(O||[],i),limit:I?L:void 0,manualIds:I?w==null?void 0:w.map(Y=>Y.id):void 0})]})},Gl=t=>{const{visible:r,formRef:n,model:s,currentId:o,domain:i,formView:a,context:c,defaultValues:h,forcedValues:d,results:u,setResults:f,setCurrentItemIndex:g}=t;return r?e.jsxs(e.Fragment,{children:[e.jsx(Bt,{children:e.jsx(Yn,{toolbar:a==null?void 0:a.toolbar})}),e.jsx(ft,{rootForm:!0,ref:n,model:s,defaultValues:h,forcedValues:d,formView:a,actionDomain:i,id:o,parentContext:c,onSubmitSucceed:(w,y)=>{u.findIndex(v=>v.id===w)===-1&&(u.push(y),f(u),g(u.length-1))}})]}):null};function jl(t){const{onSearch:r,disabled:n=!1,searchText:s}=t,{t:o}=l.useContext(he),[i]=p.Form.useForm(),[a,c]=l.useState(!1);function h(u){r(u.search)}l.useEffect(()=>{i.setFieldsValue({search:s})},[s]);function d(){c(!1),i.setFieldsValue({search:void 0}),r(void 0)}return e.jsx(p.Form,{form:i,onFinish:h,autoComplete:"off",children:e.jsxs(p.Row,{align:"middle",justify:"end",children:[e.jsx(p.Col,{children:e.jsx(p.Form.Item,{name:"search",noStyle:!0,children:e.jsx(p.Input,{autoFocus:!0,disabled:n,onChange:u=>{c(u.target.value.length>0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},suffix:(a||s&&s.length>0)&&e.jsx(p.Tooltip,{title:o("clear"),children:e.jsx(H.CloseCircleFilled,{style:{color:"rgba(0,0,0,.45)"},onClick:d})})})})}),e.jsx(p.Col,{children:e.jsx(p.Button,{htmlType:"submit",disabled:n,style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},children:o("search")})})]})})}const zn=Ke.default.createContext({previewFeatures:!1});function zl(t){var j;const{availableViews:r,currentView:n,setCurrentView:s,selectedRowItems:o,setRemovingItem:i,removingItem:a,duplicatingItem:c,setDuplicatingItem:h,currentModel:d,searchTreeRef:u,setCurrentId:f,setCurrentItemIndex:g,searchParams:w,searchVisible:y,setSearchVisible:m,setSearchTreeNameSearch:v,searchTreeNameSearch:S,treeIsLoading:T,setPreviousView:E,previousView:b,results:V,limit:F,totalItems:L}=l.useContext(Ge),{parentContext:x={},treeExpandable:O,toolbar:_}=t;l.useContext(zn);const{t:C,lang:P}=l.useContext(he),I=l.useContext(ut),{processAction:D}=I||{},[$,A]=l.useState(!1),M=S!==void 0&&S.trim().length>0;function N(){st({confirmMessage:C("confirmRemove"),lang:P,onOk:()=>{k()}})}async function k(){var U;try{i==null||i(!0),await K.getHandler().delete({model:d,ids:o.map(Z=>Z.id),context:{...x}}),f==null||f(void 0),g==null||g(void 0),(U=u==null?void 0:u.current)==null||U.refreshResults()}catch(Z){Pe(Z)}finally{i==null||i(!1)}}async function Y(){var U;try{h==null||h(!0);const Z=o[0].id;await K.getHandler().duplicate({id:Z,model:d,context:{...x}})&&((U=u==null?void 0:u.current)==null||U.refreshResults())}catch(Z){Pe(Z)}finally{h==null||h(!1)}}function z(U){D==null||D({actionData:U,values:{active_id:o==null?void 0:o.map(Z=>Z.id)[0],active_ids:o==null?void 0:o.map(Z=>Z.id)},fields:{},context:{...x,active_id:o==null?void 0:o.map(Z=>Z.id)[0],active_ids:o==null?void 0:o.map(Z=>Z.id)},onRefreshParentValues:()=>{var Z;(Z=u==null?void 0:u.current)==null||Z.refreshResults()}})}return e.jsxs(p.Space,{wrap:!0,children:[T&&e.jsxs(e.Fragment,{children:[e.jsx(p.Spin,{}),rt(),rt()]}),O?null:e.jsxs(e.Fragment,{children:[e.jsx(jl,{disabled:c||a||T,searchText:S,onSearch:U=>{U&&U.trim().length>0?v==null||v(U):v==null||v(void 0)}}),!O&&e.jsx(jn,{icon:e.jsx(H.FilterOutlined,{style:{color:y?"white":void 0}}),tooltip:C("advanced_search"),type:y?"primary":"default",onClick:()=>{m==null||m(!y)},disabled:c||a||T,badgeNumber:w==null?void 0:w.length}),rt(),e.jsx(Kn,{disabled:T}),e.jsx(Ye,{icon:e.jsx(H.CopyOutlined,{}),tooltip:C("duplicate"),disabled:!o||(o==null?void 0:o.length)!==1||c||T,loading:c,onClick:Y}),e.jsx(Ye,{icon:e.jsx(H.DeleteOutlined,{}),tooltip:C("delete"),disabled:!(o&&(o==null?void 0:o.length)>0)||T,loading:a,onClick:N}),rt()]}),e.jsx(Ye,{icon:e.jsx(H.InfoCircleOutlined,{}),tooltip:C("showLogs"),disabled:!(o&&(o==null?void 0:o.length)>0)||T,loading:!1,onClick:()=>{Wn(d,o[0].id,C)}}),e.jsx(Ye,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:C("refresh"),disabled:c||a||T,loading:!1,onClick:()=>{var U;(U=u==null?void 0:u.current)==null||U.refreshResults()}}),!O&&e.jsxs(e.Fragment,{children:[rt(),e.jsx(cr,{currentView:n,availableViews:r,onChangeView:U=>{E==null||E(n),s==null||s(U)},previousView:b,disabled:T})]}),rt(),e.jsx(pt,{icon:e.jsx(H.ThunderboltOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||T,tooltip:C("actions"),items:_==null?void 0:_.action,onItemClick:U=>{!U||z(U)}}),e.jsx(pt,{icon:e.jsx(H.PrinterOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||T,tooltip:C("reports"),items:_==null?void 0:_.print,onItemClick:U=>{!U||z({...U,datas:{...U.datas||{},ids:o.map(Z=>Z.id)}})}}),rt(),e.jsx(pt,{icon:e.jsx(br.default,{component:()=>e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-database-export",width:"1em",height:"1em",viewBox:"0 0 24 24",strokeWidth:"1.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),e.jsx("ellipse",{cx:"12",cy:"6",rx:"8",ry:"3"}),e.jsx("path",{d:"M4 6v6c0 1.657 3.582 3 8 3a19.84 19.84 0 0 0 3.302 -.267m4.698 -2.733v-6"}),e.jsx("path",{d:"M4 12v6c0 1.599 3.335 2.905 7.538 2.995m8.462 -6.995v-2m-6 7h7m-3 -3l3 3l-3 3"})]})}),tooltip:C("export"),items:[{id:"print_screen",name:C("printScreen")},{id:"export",name:C("advancedExport")}],onItemClick:U=>{if(U.id==="print_screen"){let Z=(o==null?void 0:o.map(B=>B.id))||[];Z.length===0&&(Z=(V==null?void 0:V.map(B=>B.id))||[]),z({id:-1,model:d,report_name:"printscreen.list",type:"ir.actions.report.xml",datas:{model:d,ids:Z}});return}A(!0)},disabled:c||a||T||M}),e.jsx(In,{visible:$,locale:P,onClose:()=>A(!1),model:d,domain:Ct(((j=u==null?void 0:u.current)==null?void 0:j.getDomain())||[],w||[]),limit:F,totalRegisters:L||0,selectedRegistersToExport:o,visibleRegisters:(V==null?void 0:V.length)||0,context:x})]})}function rt(){return e.jsx("div",{className:"inline-block w-2"})}const Jl=t=>{const{visible:r,searchTreeRef:n,model:s,context:o,formView:i,treeView:a,domain:c,setCurrentItemIndex:h,results:d,setCurrentId:u,setCurrentView:f,availableViews:g,searchTreeNameSearch:w}=t,{currentView:y,setPreviousView:m}=l.useContext(Ge);return r?e.jsxs(e.Fragment,{children:[e.jsx(Bt,{children:e.jsx(zl,{toolbar:a==null?void 0:a.toolbar,parentContext:o,treeExpandable:(a==null?void 0:a.isExpandable)||!1})}),e.jsx(tr,{ref:n,rootTree:!0,model:s,parentContext:o,nameSearch:w,formView:i,treeView:a,domain:c,onRowClicked:v=>{const{id:S}=v;u(S);const T=d.findIndex(b=>b.id===S);m==null||m(y),h(T);const E=g.find(b=>b.type==="form");f(E)}})]}):null},dr=Ke.default.createContext(null),Zl=t=>{const[r,n]=l.useState(!1),[s,o]=l.useState(!1),{children:i,dashboardRef:a,openAction:c}=t;return e.jsx(dr.Provider,{value:{isLoading:r,setIsLoading:n,dashboardRef:a,openAction:c,moveItemsEnabled:s,setMoveItemsEnabled:o},children:i})};function Xl(){const{isLoading:t,dashboardRef:r,moveItemsEnabled:n,setMoveItemsEnabled:s}=l.useContext(dr),{t:o}=l.useContext(he);return e.jsxs(p.Space,{wrap:!0,children:[e.jsx(Ye,{icon:e.jsx(H.BorderOuterOutlined,{style:{color:n?"white":void 0}}),type:n?"primary":"default",tooltip:o("moveDashboard"),disabled:t,loading:!1,onClick:()=>{s(!n)}}),Ql(),e.jsx(Ye,{icon:e.jsx(H.SettingOutlined,{}),tooltip:o("configDashboard"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.configDashboard()}}),e.jsx(Ye,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:o("refresh"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.refresh()}})]})}function Ql(){return e.jsx("div",{className:"inline-block w-2"})}const Rl=t=>{const{dashboardData:r}=t,n=l.useRef(),s=l.useContext(Xe),{openShortcut:o}=s||{};return r?e.jsxs(Zl,{dashboardRef:n,openAction:i=>{o(i)},children:[e.jsx(Bt,{children:e.jsx(Xl,{})}),e.jsx(Qn,{ref:n,model:r.model,id:r.id,context:r==null?void 0:r.context,configAction:r==null?void 0:r.configAction})]}):null};async function ec(t){const r=await Promise.all(t.map(async s=>{try{return await s.promise}catch(o){return console.error(`Error for ${s.viewTuple}:`,o),null}}));return t.map((s,o)=>({...s,info:r[o]})).filter(s=>s.info!==null)}function tc(t,r){const{domain:n,model:s,context:o,views:i,title:a,setCanWeClose:c,tabKey:h,initialView:d,formDefaultValues:u,formForcedValues:f={},res_id:g=!1,action_id:w,action_type:y,treeExpandable:m=!1,limit:v}=t,[S,T]=l.useState(),[E,b]=l.useState([]),[V,F]=l.useState(!0),L=g||void 0,[x,O]=l.useState(L),[_,C]=l.useState([]),[P,I]=l.useState(),[D,$]=l.useState([]),[A,M]=l.useState(),[N,k]=l.useState(0),[Y,z]=l.useState(!1),[j,U]=l.useState(!1),[Z,B]=l.useState(),{t:W}=l.useContext(he),R=l.useRef(),re=l.useRef(),ce=l.useContext(Xe),{setCurrentView:X,setCurrentId:Q,tabs:ue,activeKey:pe,openAction:ke,onRemoveTab:Fe}=ce||{};To.useHotkeys("ctrl+g,command+g",te=>{te.preventDefault(),Me()},[pe,ue,S,P,D]);function Ee(te){O(te),Q==null||Q(te)}function Be(te){T(te),X==null||X(te)}l.useImperativeHandle(r,()=>({canWeClose:ie}));const Se=async()=>{F(!0);const te=[],we=[];for(const ae of i){const[fe,Ae]=ae;Ae!=="dashboard"?we.push({viewTuple:ae,promise:K.getHandler().getView({model:s,type:Ae,id:fe,context:o})}):we.push({viewTuple:ae})}const _e=await ec(we);for(const ae of _e){if(!ae)continue;const[,fe]=ae.viewTuple;let Ae=ae.info;switch(fe){case"dashboard":{const de=i.find(Le=>{const[,ee]=Le;return ee==="form"});let qe;de&&(qe={action_id:w,action_type:y,name:a,res_id:o.active_id,res_model:s,view_id:de[0],view_type:de[1]}),te.push({type:"dashboard",id:o.active_id,model:s,context:o,configAction:qe});break}case"form":{te.push({...Ae,type:fe});break}case"tree":{te.push({...Ae,isExpandable:m,type:fe});break}case"graph":{te.push({...Ae,type:fe});break}}}let Ie;!d&&te.find(ae=>ae.type==="tree")?Ie=te.find(fe=>fe.type==="tree"):d?Ie=te.find(fe=>d.id?fe.type===d.type&&fe.view_id===d.id:fe.type===d.type):Ie=te.find(fe=>fe.type==="form"),Ie||(Pe(`Error determining the first view to show for model ${s}.
40
40
  Please, make sure the view ids on the fields_view_get responses are the same as the ones defined in the action`),Fe==null||Fe(h)),Be(Ie),b(te),F(!1)};c({tabKey:h,canWeClose:ie}),l.useEffect(()=>{const te=E.find(_e=>_e.type==="tree"),we=E.find(_e=>d.id?_e.type===d.type&&_e.view_id===d.id:_e.type===d.type);Be(we||te),g?Q==null||Q(L):(Ee(void 0),I(void 0)),Se()},[s,i,g]),l.useEffect(()=>{pe===h&&(Q==null||Q(x),X==null||X(S))},[ue,pe]);async function ie(){return S&&S.type==="form"?await R.current.cancelUnsavedChanges():!0}async function Me(){pe===h&&(S.type==="form"&&!await R.current.cancelUnsavedChanges()||z(!0))}async function ve(te){var ae;U(!0);let we,_e;if(te.length===1){we="form",_e=[];const fe=te[0],Ae=D.findIndex(qe=>qe.id===fe);let de;if(Ae===-1){try{de=(ae=await K.getHandler().readObjects({model:s,ids:[fe],context:o}))==null?void 0:ae[0]}catch{}if(!de){U(!1),z(!1),Qe(W("idNotFound"));return}}else de=D[Ae]}else we="tree",_e=[["id","in",te]];U(!1),z(!1);const Ie=i.find(fe=>fe[1]===we);ke({domain:_e,context:o,model:s,views:i,title:a,target:"current",initialView:{id:Ie==null?void 0:Ie[0],type:we},action_id:w,action_type:y,res_id:te[0]})}function Ve(){return E.map(te=>{switch(te.type){case"form":return e.jsx(Gl,{formRef:R,currentId:x,visible:S.type===te.type&&S.view_id===te.view_id,formView:te,model:s,context:o,domain:n,defaultValues:u,forcedValues:f,results:D,setResults:$,setCurrentItemIndex:I},`${te.type}-${te.view_id}`);case"tree":return e.jsx(Jl,{visible:S.type===te.type&&S.view_id===te.view_id,limit:v,model:s,context:o,domain:n,formView:E.find(we=>we.type==="form"),treeView:te,searchTreeRef:re,searchTreeNameSearch:Z,availableViews:E,results:D,setCurrentItemIndex:I,setCurrentId:Ee,setCurrentView:Be},`${te.type}-${te.view_id}`);case"graph":return e.jsx(Ul,{visible:S.type===te.type&&S.view_id===te.view_id,viewData:te,model:s,context:o,domain:n,treeView:E.find(we=>we.type==="tree"),formView:E.find(we=>we.type==="form")},`${te.type}-${te.view_id}`);case"dashboard":return e.jsx(Rl,{dashboardData:te},`${te.type}-${te.view_id}`)}})}function $e(){if(x===void 0&&S.type==="form")R.current.clearAndReload();else{Ee(void 0);const te=E.find(we=>we.type==="form");Be(te)}}return V?e.jsx(p.Spin,{}):S?e.jsxs(Gi,{title:a,currentView:S,setCurrentView:Be,availableViews:E,formRef:R,searchTreeRef:re,onNewClicked:$e,currentId:x,setCurrentId:Ee,setCurrentItemIndex:I,currentItemIndex:P,results:D,setResults:$,currentModel:s,sorter:A,setSorter:M,totalItems:N,setTotalItems:k,selectedRowItems:_,setSelectedRowItems:C,setSearchTreeNameSearch:B,searchTreeNameSearch:Z,goToResourceId:ve,limit:v,children:[Ve(),e.jsx(Hl,{visible:Y,onIdSubmitted:ve,isSearching:j,onCancel:()=>{z(!1)}})]}):null}const Jn=l.forwardRef(tc);async function rc({actionId:t,rootContext:r={},globalValues:n={}}){const s="ir.actions.act_window",o=`${s},${t}`,i=await K.getHandler().getActionData({action:o,context:r}),a=se.parseContext({context:i.context,values:n,fields:{}}),c=i.domain?await K.getHandler().evalDomain({domain:i.domain,values:n,context:{...r,...a}}):[],{res_model:h,views:d,name:u,limit:f,view_type:g}=i,w=g==="tree",y=[];for(const T of d){const[E,b]=T;if(E)y.push(T);else{const{view_id:V}=await K.getHandler().getView({model:h,type:b,id:E,context:{...r,...a}});y.push([V,b])}}const[m,v]=y[0],S={id:m,type:v};return{title:u,actionId:t,actionType:s,key:wr.v4(),views:d,model:h,context:{...r,...a},domain:c,initialView:S,limit:f,treeExpandable:w}}const ed="",nc=vr.WidthProvider(vr.Responsive),Zn=t=>{const{children:r=[],onPositionItemsChanged:n}=t,s=Ke.default.Children.map(r,o=>{const{parms:i,id:a}=o.props;return e.jsx("div",{"data-grid":i,children:o},a)});return e.jsx(nc,{className:"layout",cols:{lg:12,md:10,sm:6,xs:4,xxs:2},draggableHandle:".draggable-head",rowHeight:30,onLayoutChange:o=>{n==null||n(o.map(i=>({id:parseInt(i.i.replace(".$",""),10),x:i.x,y:i.y,w:i.w,h:i.h})))},children:s})},{useToken:oc}=p.theme,{Text:sc}=p.Typography,Xn=t=>{const{title:r,children:n,action:s,openAction:o}=t,{token:i}=oc();return e.jsxs("div",{className:"shadow-md",style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden",border:"1px solid #eee",backgroundColor:"white",borderRadius:i.borderRadius},children:[e.jsxs(p.Row,{align:"middle",style:{borderBottom:"1px solid #ddd",backgroundColor:i.colorPrimaryBg},wrap:!1,children:[e.jsx(p.Col,{flex:"auto",className:"draggable-head",style:{fontWeight:"bold",padding:"0.5rem",cursor:"grab",overflow:"hidden"},children:e.jsx(sc,{ellipsis:!0,children:r})}),s&&e.jsx(p.Col,{flex:"25px",style:{padding:"0.5rem"},children:e.jsx(p.Row,{justify:"end",align:"middle",children:e.jsx(H.ExportOutlined,{style:{cursor:"pointer"},onClick:()=>{o==null||o(s)}})})})]}),n]})},ic=80;function ac(t){const{action:r,model:n,view_id:s,onRowClicked:o,domain:i=[],visible:a=!0,parentContext:c={}}=t,[h,d]=l.useState(!1),[u,f]=l.useState(!1),[g,w]=l.useState(),[y,m]=l.useState(),[v,S]=l.useState(),[T,E]=l.useState(1),[b,V]=l.useState(0),F=l.useRef(ic),L=l.useRef([]),[x,O]=l.useState(0),[_,C]=l.useState([]),[P,I]=l.useState(void 0),[D,$]=l.useState(),[A,M]=l.useState(),[N,k]=l.useState(),[Y,z]=l.useState(!1),j=l.useRef([]),U=Q=>{z(!0),E(Q),V((Q-1)*F.current)},Z=async()=>{const Q=j.current.length>0?j.current:i,ue=Ct(L.current,Q),{colors:pe}=at(y),{totalItems:ke,results:Fe,attrsEvaluated:Ee}=await K.getHandler().searchForTree({params:ue,limit:F.current,offset:b,model:g,fields:y.fields,context:c,attrs:pe&&{colors:pe}});I(Mt(Ee));const Be=lt({resultsToSort:Fe,sorter:D,fields:{...y.fields,...v.fields}});z(!1),C(Be);const Se=await ke;O(Se)},B=async()=>{try{z(!0),await Z()}catch(Q){M(JSON.stringify(Q))}};l.useEffect(()=>{!u||a&&B()},[T,b,u,a]);const W=async Q=>{f(!1),d(!0),k(void 0);try{Q==="action"?await R():await re(),f(!0)}catch(ue){k(ue)}finally{d(!1)}},R=async()=>{const Q=await K.getHandler().getViewsForAction({action:r,context:c});j.current=Q.domain,S(Q.views.get("form")),m(Q.views.get("tree")),w(Q.model),F.current=Q.limit},re=async()=>{w(n);const Q=await K.getHandler().getView({model:n,type:"form",context:c});S(Q);const ue=await K.getHandler().getView({model:n,type:"tree",id:s,context:c});m(ue)};l.useEffect(()=>{r?W("action"):n&&W("model")},[r,n]);const ce=Q=>{const{id:ue}=Q;o({id:ue,model:g,treeView:y})},X=()=>!y||!v?null:e.jsxs("div",{style:{overflowY:"scroll"},children:[A&&e.jsx(p.Alert,{className:"mt-10",message:A,type:"error",banner:!0}),e.jsx(Tt,{showPagination:!1,total:x,limit:F.current,page:T,treeView:y,results:_,onRequestPageChange:U,loading:Y,onRowClicked:ce,colorsForResults:P,sorter:D,onChangeSort:Q=>{$==null||$(Q);const ue=lt({resultsToSort:_,sorter:Q,fields:{...y.fields,...v.fields}});C(ue)},context:c})]});return N?e.jsx(p.Alert,{className:"mt-10",message:N,type:"error",banner:!0}):h?e.jsx(p.Spin,{style:{padding:"2rem"}}):X()}const lc=t=>{const{model:r}=t,[n,s]=l.useState();l.useEffect(()=>{o()},[r]);async function o(){const i=await K.getHandler().search({params:[],model:r,limit:1});i.length>0&&s(i[0].id)}return e.jsx("div",{style:{padding:"0.5rem",overflowY:"scroll"},children:e.jsx(ft,{...t,model:r,id:n,readOnly:!0})})},ur="line_ids";function cc(t,r){const{model:n,context:s={},id:o,configAction:i}=t,[a,c]=l.useState([]),[h,d]=l.useState(!1),[u,f]=l.useState(),{setIsLoading:g,openAction:w,moveItemsEnabled:y}=l.useContext(dr),m=l.useRef(),v=l.useRef();l.useEffect(()=>{S()},[n,o,s]),l.useImperativeHandle(r,()=>({refresh:()=>{S()},configDashboard:L}));async function S(){d(!0),g(!0),f(void 0);try{const x=await T(),O=await b(x),_=x.fields[ur].relation,C=O[ur].items;v.current=x.fields;const P=await E({items:C,model:_,context:s}),I=await V(P);c(I),d(!1),g(!1)}catch(x){f(JSON.stringify(x))}}async function T(){return await K.getHandler().getView({model:n,type:"form",context:s})}async function E({items:x,model:O,context:_}){m.current=(await K.getHandler().getView({model:O,type:"form",context:_})).fields;const[C]=await Jt({treeView:{fields:m.current},formView:{fields:m.current},model:O,items:x,context:_,currentView:"form"});return C}async function b(x){return(await K.getHandler().readObjects({model:n,ids:[o],fields:x.fields,context:s}))[0]}async function V(x){const O=[];for(const _ of x){const{values:C}=_;if(C.action_id&&C.action_id.length>0){const P=parseInt(C.action_id[0],10),I=await rc({actionId:P,rootContext:s});O.push({..._,actionData:I})}}return O}async function F(x){if(!y)return;const O=x.filter(I=>{const D=a.find(A=>A.id===I.id);if(!D)return!1;if(!D.position)return!0;const $={...JSON.parse(D.position.replace(/'/g,'"')),id:D.id};return JSON.stringify(I)!==JSON.stringify($)});if(O.length===0)return;const C=a.filter(I=>O.map(D=>D.id).includes(I.id)).map(I=>{const D={...O.find($=>$.id===I.id)};return delete D.id,{...I},{...I,operation:"pendingUpdate",values:{...I.values,position:JSON.stringify(D).replace(/"/g,"'")}}}),P={fields:m.current,items:C};await K.getHandler().update({model:n,id:o,values:{[ur]:P},fields:v.current,context:s})}async function L(){w(i)}return u?(console.log(u),e.jsx(p.Alert,{className:"mt-10 mb-20",message:u,type:"error",banner:!0})):h?e.jsx(H.LoadingOutlined,{}):e.jsx(Zn,{onPositionItemsChanged:F,children:a.map((x,O)=>{const{actionData:_,values:C}=x,{position:P,id:I}=C,{actionId:D,actionType:$,key:A,title:M,views:N,model:k,context:Y,domain:z,initialView:j,limit:U}=_;let Z={};try{Z=JSON.parse(P.replace(/'/g,'"'))}catch{Z={x:O*2,y:0,w:2,h:3}}let B=null;if((j==null?void 0:j.type)==="graph")B=e.jsx(Nt,{view_id:N.filter(re=>re[1]==="graph")[0][0],model:k,context:Y,domain:z,limit:U});else if((j==null?void 0:j.type)==="form")B=e.jsx(lc,{model:k,actionDomain:z});else if((j==null?void 0:j.type)==="tree")B=e.jsx(ac,{model:k,domain:z,view_id:N.filter(re=>re[1]==="tree")[0][0],onRowClicked:re=>{const ce=N.find(X=>{const[,Q]=X;return Q==="form"});if(ce){const[X,Q]=ce,{actionId:ue,actionType:pe,title:ke,model:Fe}=_,Ee={action_id:ue,action_type:pe,name:ke,res_id:re.id,res_model:Fe,view_id:X,view_type:Q};w(Ee)}}});else if(j!==void 0){const re=j&&Array.isArray(j.id)?{...j,id:j.id[0]}:j;B=e.jsx(Jn,{action_id:D,action_type:$,tabKey:A,title:M,views:N,model:k,context:Y,domain:z,setCanWeClose:()=>{},initialView:re,limit:U})}let W;const R=N.find(re=>{const[,ce]=re;return ce==="tree"});if(R){const[re,ce]=R,{actionId:X,actionType:Q,title:ue,model:pe}=_;W={action_id:X,action_type:Q,name:ue,res_id:!1,res_model:pe,view_id:re,view_type:ce}}return e.jsx(Xn,{id:I,title:M,parms:Z,action:W,openAction:w,children:B},I)})})}const Qn=l.forwardRef(cc),Rn=t=>{const{ooui:r}=t;return e.jsx(me,{type:"array",...t,children:e.jsx(dc,{ooui:r})})},dc=t=>{const{value:r,ooui:n,onChange:s}=t,{items:o=[]}=r||{},i=o.filter(x=>x.operation!=="pendingRemove").map(x=>x.id),[a,c]=l.useState([]),[h,d]=l.useState(),[u,f]=l.useState(!1),{relation:g,context:w,readOnly:y,field:m,columns:v}=n,S=l.useContext(De),{getContext:T}=S||{};tt.default(()=>{b()},[o]);const E=x=>{s==null||s({items:x})};async function b(){f(!0);let x=[];if(n.domain){const O=await K.getHandler().evalDomain({domain:n.domain,values:dt({fields:S==null?void 0:S.getFields(),values:S.getPlainValues()}),fields:S==null?void 0:S.getFields(),context:S.getContext()});x=[...x,...O]}try{const _=(await K.getHandler().search({model:g,params:x,fields:[m],context:{...T==null?void 0:T(),...w}})).map(C=>{const P=C[m];let I=P;return Array.isArray(P)&&(I=P[1]),{label:I,value:C.id}});c(_)}catch(O){d(O)}finally{f(!1)}if(h)return e.jsx(p.Alert,{className:"mt-10",message:h,type:"error",banner:!0})}const V=()=>{L(a.map(x=>x.value))},F=()=>{L([])},L=x=>{const O=o.map(C=>x.includes(C.id)?C.operation=="pendingRemove"?{...C,operation:"original"}:C:{id:C.id,operation:"pendingRemove"}),_=O.map(C=>C.id);x.filter(C=>!_.includes(C)).map(C=>{O.push({id:C,operation:"pendingLink"})}),E(O)};return u&&a.length===0?e.jsx(p.Spin,{}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(p.Checkbox.Group,{value:a.length?i:[],disabled:y,onChange:L,style:{width:"100%"},children:e.jsx(p.Row,{children:a.map(x=>e.jsx(p.Col,{span:Math.floor(24/v),children:e.jsx(p.Checkbox,{value:x.value,children:x.label})}))})}),!y&&e.jsxs(p.Space,{children:[e.jsx(p.Button,{onClick:V,disabled:i.length==a.length,children:"Check all"}),e.jsx(p.Button,{onClick:F,disabled:i.length===0,children:"Uncheck all"})]})]})})},eo=t=>e.jsx(me,{...t,children:e.jsx(uc,{...t})}),uc=t=>{const{value:r,ooui:n}=t;return e.jsx("div",{style:{height:n!=null&&n.height?n.height+"px":"100%",overflow:"auto"},children:e.jsx(Eo.default,{className:"markdown-typography",children:r})})},to=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(fc,{...t})})},fc=t=>{const{ooui:r,onChange:n,value:s}=t,{selectionValues:o,readOnly:i,direction:a}=r,c=Array.from(o.entries()),h=c&&c.length&&c.map(d=>{const[u,f]=d;return e.jsx(p.Radio,{value:u,children:f},u)});return e.jsx(p.Radio.Group,{disabled:i,onChange:n,value:s,children:e.jsx(p.Space,{direction:a,children:h})})},ro=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o}=r;return e.jsx(me,{...t,valuePropName:"checked",children:e.jsx(hc,{id:n,readOnly:s,required:o})})},hc=t=>{const{required:r,readOnly:n,...s}=t;return e.jsx("div",{className:"flex flex-row",children:e.jsx(p.Switch,{disabled:n,...s})})},no=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(pc,{...t})})},pc=t=>{const{ooui:r,value:n}=t,{selectionValues:s,errorField:o}=r,i=l.useContext(De),a=Array.from(s.entries()),c=a.map(u=>u[0]).indexOf(n);let h="process",d="";return o&&(d=i.getFieldValue(o),d&&(h="error")),e.jsx(p.Steps,{current:c,status:h,children:a.map((u,f)=>e.jsx(p.Steps.Step,{title:u[1],description:f===c&&h==="error"?d:null}))})},oo=t=>{const{ooui:r}=t,{lang:n,height:s}=r,o=l.useContext(De),{elementHasLostFocus:i}=o||{},a=c=>{c.onDidBlurEditorWidget(i)};return e.jsx(me,{...t,children:e.jsx(Io.default,{defaultLanguage:n||"",height:s||300,onMount:a})})};var so={exports:{}};(function(t,r){(function(n,s){t.exports=s()})(Re,function(){return function(n,s,o){n=n||{};var i=s.prototype,a={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function c(d,u,f,g){return i.fromToBase(d,u,f,g)}o.en.relativeTime=a,i.fromToBase=function(d,u,f,g,w){for(var y,m,v,S=f.$locale().relativeTime||a,T=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],E=T.length,b=0;b<E;b+=1){var V=T[b];V.d&&(y=g?o(d).diff(f,V.d,!0):f.diff(d,V.d,!0));var F=(n.rounding||Math.round)(Math.abs(y));if(v=y>0,F<=V.r||!V.r){F<=1&&b>0&&(V=T[b-1]);var L=S[V.l];w&&(F=w(""+F)),m=typeof L=="string"?L.replace("%d",F):L(F,u,V.l,v);break}}if(u)return m;var x=v?S.future:S.past;return typeof x=="function"?x(m):x.replace("%s",m)},i.to=function(d,u){return c(d,u,this,!0)},i.from=function(d,u){return c(d,u,this)};var h=function(d){return d.$u?o.utc():o()};i.toNow=function(d){return this.to(h(this),d)},i.fromNow=function(d){return this.from(h(this),d)}}})})(so);const gc=so.exports,{Meta:mc}=p.Card,{Text:yc}=p.Typography;Ze.extend(gc);const vc=({email:t,size:r=40,theme:n=""})=>{const s=`https://www.gravatar.com/avatar/${Ao.default(t)}?s=${r}&d=${n}`;return e.jsx(p.Avatar,{src:s,size:r})};function wc({text:t}){const r=t.split(`
41
41
  `);return e.jsx("div",{children:r.map((n,s)=>e.jsxs(Ke.default.Fragment,{children:[n,s!==r.length-1&&e.jsx("br",{})]},s))})}const Sc=t=>{const{data:r,style:n}=t,{t:s}=l.useContext(he);return e.jsxs(p.Card,{style:{...n,textAlign:"start"},children:[e.jsx(mc,{avatar:e.jsx(vc,{email:r.email,theme:"mp"}),title:r.author,description:e.jsxs(p.Space,{direction:"horizontal",children:[e.jsx("span",{title:r.date,children:Ze(r.date).fromNow()}),r.isAuthor&&e.jsx(p.Tag,{color:"blue",children:s("author")})]}),style:{marginBottom:"5px"}}),e.jsx(yc,{children:e.jsx(wc,{text:r.text})})]},r.id)},Cc=t=>{const{value:r}=t,n=(r||[]).map(s=>{if(s.type==="action")return{children:`${s.event.date} - ${s.event.action}`};if(s.type==="comment")return{color:"gray",position:s.event.isSender?"left":"right",label:s.event.date,children:e.jsx(Sc,{data:s.event})}});return e.jsx(p.Timeline,{mode:"alternate",items:n})},io=t=>e.jsx(me,{...t,children:e.jsx(Cc,{})}),{Content:bc}=p.Layout,{Title:xc}=p.Typography;function Tc(){const{t}=l.useContext(he);return e.jsx(bc,{className:"m-5 select-none",children:e.jsx(xc,{level:5,children:t("welcome")})})}function Fc(t,r){const{children:n,globalValues:s={},rootContext:o={},lang:i}=t,[a,c]=l.useState("welcome"),[h,d]=l.useState([{title:xe("welcome",i),key:"welcome",closable:!0,content:e.jsx(Tc,{})}]),u=l.useRef(new Map),f=l.useRef();l.useImperativeHandle(r,()=>({retrieveAndOpenAction:y,openShortcut:S}));function g(b){if(b===a){const V=h.findIndex(F=>F.key===b);h[V-1]&&c(h[V-1].key),h[V+1]&&c(h[V+1].key)}d(h.filter(V=>V.key!==b)),u.current.delete(b)}function w({tabKey:b,canWeClose:V}){u.current.set(b,V)}async function y({action:b,values:V,forced_values:F,initialViewType:L,res_id:x,domain:O=[]}){const _=await K.getHandler().getActionData({action:b,context:o});if(_.type==="ir.actions.wizard"){Pe("Action type not supported");return}const[C,P]=b.split(","),I=parseInt(P),D=se.parseContext({context:_.context,values:s,fields:{}}),$=_.domain?await K.getHandler().evalDomain({domain:_.domain,values:s,context:{...o,...D}}):[],{res_model:A,views:M,name:N,target:k,view_type:Y,limit:z}=_,j=Y==="tree",U=[];for(const B of M){const[W,R]=B;if(W)U.push(B);else if(R==="dashboard")U.push([void 0,"dashboard"]);else{const{view_id:re}=await K.getHandler().getView({model:A,type:R,id:W,context:{...o,...D}});U.push([re,R])}}let Z;if(L){const[B,W]=U.find(([R,re])=>re===L);Z={id:B,type:W}}else{const[B,W]=U[0];Z={id:B,type:W}}E({domain:[...$,...O],context:{...o,...D},model:A,views:U,title:N,target:k,initialView:Z,action_type:C,action_id:I,values:V,forced_values:F,res_id:x,treeExpandable:j,limit:z})}function m({title:b,content:V,key:F,action:L}){let x=[...h];h.length===1&&h[0].key==="welcome"&&(x=[...h.filter(O=>O.key!=="welcome")]),d([...x,{title:b,key:F,closable:!0,content:V,action:L}]),c(F)}async function v({relateData:b,fields:V,values:F,action_id:L,action_type:x}){const{res_model:O,context:_,domain:C,views:P,target:I,string:D,limit:$}=b,[A,M]=P[0],N={id:A,type:M},k=se.parseContext({context:_,values:{...F,...s},fields:V}),Y=C?await K.getHandler().evalDomain({domain:C,values:dt({fields:V,values:{...F,...s}}),fields:V,context:{...o,...k}}):[];E({model:O,target:I,views:P,context:{...o,...k},domain:Y,title:D,initialView:N,action_id:L,action_type:x,limit:$})}async function S(b){const{action_id:V,action_type:F,res_id:L,view_id:x}=b,O=`${F},${V}`,_=await K.getHandler().getActionData({action:O,context:o}),C=se.parseContext({context:_.context,values:s,fields:{}}),P=_.domain?await K.getHandler().evalDomain({domain:_.domain,values:s,context:{...o,...C}}):[],{res_model:I,views:D,name:$,target:A,view_type:M,limit:N}=_,k=M==="tree",Y=[];for(const Z of D){const[B,W]=Z;if(B)Y.push(Z);else if(W==="dashboard")Y.push([void 0,"dashboard"]);else{const{view_id:R}=await K.getHandler().getView({model:I,type:W,id:B,context:{...o,...C}});Y.push([R,W])}}let z,j;if(x==null){const Z=Y.find(B=>B[0]===void 0);z=void 0,j=Z[1]}else[z,j]=Y.find(Z=>Z[0]===void 0?!1:Z[0]===x);const U={id:z,type:j};E({domain:P,context:{...o,...C},model:I,views:Y,title:$,target:A,initialView:U,action_id:V,action_type:F,res_id:L,treeExpandable:k,limit:N})}async function T({model:b,values:V,forced_values:F,initialViewType:L,res_id:x,domain:O}){const _=await K.getHandler().getActionStringForModel(b);await y({action:_,values:V,forced_values:F,initialViewType:L,res_id:x,domain:O})}async function E({domain:b,context:V,model:F,views:L,title:x,target:O,initialView:_,action_id:C,action_type:P,res_id:I,values:D,forced_values:$,treeExpandable:A=!1,limit:M}){const N=wr.v4();if(O!=="current"){const k=await K.getHandler().getView({model:F,type:"form",id:_.type==="form"?_.id:void 0,context:{...o,...V}});f.current.openActionModal({domain:b,model:F,formView:k,context:{...o,...V},actionData:{action_id:C,action_type:P,res_id:I,view_id:k.view_id}})}else{const k=_&&Array.isArray(_.id)?{..._,id:_.id[0]}:_;m({title:x,action:{id:C,type:P},content:e.jsx(Jn,{action_id:C,action_type:P,tabKey:N,title:x,views:L,model:F,context:{...o,...V},domain:b,setCanWeClose:w,initialView:k,res_id:I,formDefaultValues:D,formForcedValues:$,treeExpandable:A,limit:M}),key:N})}}return e.jsx(Ho,{lang:i,children:e.jsx(ji,{openShortcut:S,openAction:E,openRelate:v,openDefaultActionForModel:T,tabs:h,activeKey:a,onRemoveTab:async b=>{const V=u.current.get(b);(await(V==null?void 0:V())||a==="welcome")&&g(b)},onChangeTab:b=>{c(b)},children:e.jsx(sn,{ref:f,globalValues:s,children:n})})})}const Oc=l.forwardRef(Fc),{useToken:_c}=p.theme;function Dc(t){const{label:r,onClose:n,tabKey:s,isActive:o,onSelected:i}=t,{token:a}=_c(),c=o?a.colorBgContainer:a.colorPrimaryBg;return e.jsxs("div",{onClick:()=>{!o&&i(s)},style:{cursor:"pointer",height:40,paddingTop:7,paddingBottom:5,paddingLeft:10,paddingRight:10,backgroundColor:c,display:"inline-flex",flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center",borderTopLeftRadius:a.borderRadius,borderTopRightRadius:a.borderRadius,marginLeft:2},children:[e.jsx("div",{style:{color:a.colorPrimaryActive,userSelect:"none",height:40,display:"flex",justifyContent:"center",alignItems:"center",paddingLeft:5,paddingRight:5,marginBottom:2,fontWeight:o?500:"normal"},children:r}),e.jsx("div",{style:{paddingLeft:5,height:40,display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(H.CloseOutlined,{style:{color:a.colorPrimaryActive},onClick:h=>{h.stopPropagation(),n(s)}})})]})}function kc(){const t=l.useContext(Xe),{activeKey:r,tabs:n,onRemoveTab:s,onChangeTab:o}=t||{};return e.jsx(e.Fragment,{children:n.map(i=>e.jsx(Dc,{tabKey:i.key,label:i.title,onClose:s,isActive:r===i.key,onSelected:o},i.key))})}function Mc(t){const{tab:r}=t,n=l.useContext(Xe),{activeKey:s}=n||{},o={display:"none"};return e.jsx("div",{style:r.key!==s?o:void 0,children:r.content})}const Vc=Ke.default.memo(Mc,()=>!0);function Ec(){const t=l.useContext(Xe),{tabs:r}=t||{},n=(r==null?void 0:r.map(s=>e.jsx(Vc,{tab:s},s.key)))||null;return e.jsx(e.Fragment,{children:n})}const{useToken:Ic}=p.theme,Ac=t=>{const{onRetrieveShortcuts:r,onCheckIsFavourite:n,onAddFavourite:s,onRemoveFavourite:o}=t,[i,a]=l.useState(!1),[c,h]=l.useState(!1),[d,u]=l.useState([]),[f,g]=l.useState(!0),[w,y]=l.useState(),{t:m}=l.useContext(he)||{},{token:v}=Ic(),S=l.useContext(Xe),{openShortcut:T,tabs:E,activeKey:b,currentView:V,currentId:F,openDefaultActionForModel:L}=S||{};l.useEffect(()=>{x()},[]),l.useEffect(()=>{C()},[E,b,V,F]);async function x(){try{g(!0);const A=await r();u(A)}catch(A){Pe(A)}finally{g(!1)}}function O(A){const{key:M}=A,N=d.find(k=>k.id===Number(M));(N==null?void 0:N.action_type)!=="ir.actions.wizard"&&(N&&T(N),h(!1))}function _(A){A&&x(),h(A)}async function C(){if(!V)return;const A=E.find(j=>j.key===b),{id:M,type:N}=(A==null?void 0:A.action)||{};if(!M||!N){a(!1);return}const k=V.view_id;let Y=!1;V.type==="form"&&(Y=F||!1);const z=await n({action_id:M,action_type:N,view_id:k,res_id:Y});z!==!1&&y(z),a(z!==!1)}async function P(){h(!1),L==null||L({model:"ir.ui.view_sc"})}const I=e.jsxs(p.Menu,{onClick:O,children:[e.jsxs("div",{style:{width:300,padding:5,display:"flex"},children:[e.jsx("div",{style:{paddingLeft:15,color:"#ccc"},children:m==null?void 0:m("favorites").toUpperCase()}),e.jsx("div",{style:{flexGrow:1,paddingLeft:10},children:e.jsx(p.Tooltip,{title:m==null?void 0:m("edit_favorites"),children:e.jsx(H.EditOutlined,{style:{color:v.colorPrimary,cursor:"pointer"},onClick:P})})})]}),e.jsx(p.Menu.Divider,{}),f?e.jsx(p.Spin,{style:{padding:"1rem"}}):d.length>0?e.jsx(e.Fragment,{children:d.map(A=>e.jsx(p.Menu.Item,{children:e.jsx(D,{title:A.name,type:A.view_type})},A.id))}):e.jsx("div",{style:{width:300,padding:5,paddingLeft:15},children:m==null?void 0:m("no_favorites")})]});function D({title:A,type:M}){const N=M==="tree"?e.jsx(H.TableOutlined,{}):e.jsx(H.FormOutlined,{});return e.jsxs(p.Row,{wrap:!1,children:[e.jsx(p.Col,{flex:"none",style:{paddingRight:20},children:N}),e.jsx(p.Col,{flex:"auto",children:A})]})}async function $(){if(i&&w)await o(w);else{if(!V)return;const A=E.find(z=>z.key===b),{id:M,type:N}=(A==null?void 0:A.action)||{},k=V.view_id;let Y=!1;if(!M||!N){a(!1);return}V.type==="form"&&(Y=F||!1),await s({action_id:M,action_type:N,view_id:k,res_id:Y})}await x(),a(!i)}return e.jsxs(e.Fragment,{children:[e.jsx(p.Button,{type:i?"primary":"default",icon:i?e.jsx(H.StarFilled,{style:{color:"white"}}):e.jsx(H.StarOutlined,{}),style:{width:50,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:$}),e.jsx(p.Dropdown,{overlay:I,onVisibleChange:_,open:c,children:e.jsx(p.Button,{style:{width:25,borderTopLeftRadius:0,borderBottomLeftRadius:0},icon:e.jsx(H.DownOutlined,{style:{fontSize:"0.5em"}}),onClick:A=>A.preventDefault()})})]})};G.ActionBar=Yn,G.Binary=Bn,G.Boolean=Er,G.Button=Ut,G.ButtonGroup=Or,G.Char=Gt,G.CodeEditor=oo,G.CommentsTimelineField=io,G.ConfigContext=zn,G.ConnectionProvider=K,G.ContentRootProvider=sn,G.CurrentTabContent=Ec,G.Dashboard=Qn,G.DashboardGrid=Zn,G.DashboardGridItem=Xn,G.Date=An,G.DateTime=$n,G.Email=Gn,G.ExportModal=In,G.FavouriteButton=Ac,G.Float=Qt,G.FloatTime=_n,G.Form=ft,G.FormModal=ht,G.GraphIndicator=xn,G.Group=or,G.Image=qr,G.Integer=xt,G.Label=vt,G.Many2one=wn,G.Markdown=eo,G.MultiCheckbox=Rn,G.Notebook=Dn,G.One2many=On,G.ProgressBar=cn,G.Radio=to,G.Reference=Pn,G.RootView=Oc,G.SearchFilter=Rt,G.SearchModal=rr,G.SearchTree=tr,G.Selection=jt,G.Separator=Mn,G.Steps=no,G.Switch=ro,G.TabSelector=kc,G.Tag=Zr,G.Tags=Rr,G.Text=kn,G.Time=Nn,G.Tree=Tt,G.Url=Un,G.iconMapper=Je,G.showConfirmDialog=st,Object.defineProperties(G,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
42
42
  //# sourceMappingURL=react-ooui.umd.js.map