@gisce/react-ooui 1.2.11 → 1.2.12

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  `)!==-1){const o=t.split(`
4
4
 
5
- `);r=o[1].replace(/\n/g,"<br />");const i=o[0].split(" -- ");n=i[0],s=i[1]}else r=t,n="error",s="Error";return{type:n,message:r,title:s}},{error:$o,warning:Ao}=p.Modal,Ae=t=>{const{message:r,type:n,title:s}=Fr(t),o=n==="error"?e.jsx(H.ExclamationCircleOutlined,{}):e.jsx(H.WarningOutlined,{});(n==="error"?$o:Ao)({title:s,icon:o,centered:!0,content:r})},Or=t=>{const{visible:r,onCloseModal:n,model:s,id:o,field:i,onSubmitSucceed:a}=t,{modalWidth:c}=Tt(),{t:f}=l.useContext(ge),[d,h]=l.useState([]),[u,g]=l.useState(!1),[C,y]=l.useState(!1),[m,w]=l.useState({}),v=l.useRef();l.useEffect(()=>{r?O():w({})},[r]);async function O(){g(!0);try{const x=await D();await S(x)}catch(x){Ae(x)}g(!1)}async function D(){const b=(await Y.getHandler().search({params:[["translatable","=","1"]],fields:["code","name"],model:"res.lang"})).map(_=>({code:_.code,name:_.name}));return h==null||h(b),b}async function S(x){const b={};for(const _ of x){const T=(await Y.getHandler().readObjects({model:s,ids:[o],fieldsToRetrieve:[i],context:{lang:_.code}}))[0];b[_.code]=T[i]||""}v.current=b,w(b)}function V(){return d.map((x,b)=>e.jsxs(p.Row,{style:{paddingBottom:20},children:[e.jsx(p.Col,{flex:"8rem",style:{paddingRight:10},children:x.name}),e.jsx(p.Col,{flex:"auto",children:e.jsx(wo.default,{rows:4,value:m[x.code]||"",onChange:_=>{w({...m,[x.code]:_.target.value})},disabled:C})})]},b))}async function k(){y(!0);try{for(const x of Object.keys(m))m[x]!==v.current[x]&&await Y.getHandler().update({model:s,id:o,values:{[i]:m[x]},context:{lang:x},fields:{}})}catch(x){Ae(x)}y(!1),a()}function L(){return u?e.jsx(p.Spin,{}):e.jsxs(e.Fragment,{children:[V(),e.jsx(p.Divider,{}),e.jsx(p.Row,{justify:"end",children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.CloseOutlined,{}),onClick:n,disabled:C,children:f("cancel")}),e.jsx(p.Button,{icon:C?e.jsx(H.LoadingOutlined,{}):e.jsx(H.CheckOutlined,{}),disabled:C,onClick:k,style:{marginLeft:15},type:"primary",children:f("ok")})]})})]})}return e.jsx(p.Modal,{title:f("translate"),centered:!0,width:c,open:r,closable:!0,onCancel:n,footer:null,destroyOnClose:!0,maskClosable:!1,children:L()})};function Le(t){const{tooltip:r,...n}=t;return e.jsx(p.Tooltip,{title:r,children:e.jsx(p.Button,{...n})})}const{info:Lo}=p.Modal,Ue=t=>{Lo({title:"",centered:!0,content:t})},{useToken:No}=p.theme,Gt=t=>{const{ooui:r,isSearchField:n=!1}=t,{id:s,readOnly:o,isPassword:i,required:a,translatable:c}=r,{token:f}=No(),d=a&&!o?{backgroundColor:f.colorPrimaryBg}:void 0,h=l.useContext(ke),{elementHasLostFocus:u}=h||{};let g=e.jsx(p.Input,{disabled:o||c&&!n,id:s,style:d,maxLength:r.size,onBlur:u});return i&&(g=e.jsx(p.Input.Password,{disabled:o,id:s,onBlur:u})),c&&!o&&!n&&(g=e.jsx(Po,{field:s,requiredStyle:d})),e.jsx(me,{required:a,...t,children:g})},Po=({value:t,field:r,requiredStyle:n,onChange:s})=>{const o=l.useContext(ke),{activeId:i,activeModel:a,fetchValues:c,formHasChanges:f,elementHasLostFocus:d}=o||{},[h,u]=l.useState(!1),{t:g}=l.useContext(ge);return i?e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>{if(f!=null&&f()){Ue(g("saveBeforeTranslate"));return}h||u(!0)},children:e.jsx(p.Input,{value:t,disabled:!0,id:r,onChange:C=>{s==null||s(C.target.value)},onBlur:d,style:{cursor:"pointer",...n}})}),e.jsx(Or,{id:i,model:a,field:r,visible:h,onCloseModal:()=>{u(!1)},onSubmitSucceed:()=>{u(!1),c==null||c()}})]}):e.jsx(e.Fragment,{children:e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"auto",children:e.jsx(p.Input,{value:t,id:r,style:n,onChange:C=>{s==null||s(C.target.value)},onBlur:d})}),e.jsx(p.Col,{flex:"32px",children:e.jsx(Le,{tooltip:g("translate"),icon:e.jsx(H.TranslationOutlined,{}),onClick:async()=>{f!=null&&f()?Ue(g("saveBeforeTranslate")):Ue(g("enterTextBeforeTranslate"))},children:g("translate")})})]})})},{defaultAlgorithm:Bo,defaultSeed:Ho}=p.theme,Ko=Bo(Ho),{Option:Yo}=p.Select,Ut=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(_r,{...t})})},_r=t=>{const{ooui:r,onChange:n,value:s}=t,{selectionValues:o,readOnly:i,required:a}=r,c=Array.from(o.entries()),f=c&&c.length&&c.map(h=>{const[u,g]=h;return e.jsx(Yo,{value:u,children:g},u)}),d=a&&!i?Wo:p.Select;return e.jsx(d,{disabled:i,onChange:n,value:s,optionFilterProp:"children",filterOption:(h,u)=>u.children.toLowerCase().indexOf(h.toLowerCase())>=0,showSearch:!0,children:f})},Wo=pt.default(p.Select)`
5
+ `);r=o[1].replace(/\n/g,"<br />");const i=o[0].split(" -- ");n=i[0],s=i[1]}else r=t,n="error",s="Error";return{type:n,message:r,title:s}},{error:$o,warning:Ao}=p.Modal,Ae=t=>{const{message:r,type:n,title:s}=Fr(t),o=n==="error"?e.jsx(H.ExclamationCircleOutlined,{}):e.jsx(H.WarningOutlined,{});(n==="error"?$o:Ao)({title:s,icon:o,centered:!0,content:r})},Or=t=>{const{visible:r,onCloseModal:n,model:s,id:o,field:i,onSubmitSucceed:a}=t,{modalWidth:c}=Tt(),{t:f}=l.useContext(ge),[d,h]=l.useState([]),[u,g]=l.useState(!1),[C,y]=l.useState(!1),[m,w]=l.useState({}),v=l.useRef();l.useEffect(()=>{r?O():w({})},[r]);async function O(){g(!0);try{const x=await D();await S(x)}catch(x){Ae(x)}g(!1)}async function D(){const b=(await Y.getHandler().search({params:[["translatable","=","1"]],fields:["code","name"],model:"res.lang"})).map(_=>({code:_.code,name:_.name}));return h==null||h(b),b}async function S(x){const b={};for(const _ of x){const T=(await Y.getHandler().readObjects({model:s,ids:[o],fieldsToRetrieve:[i],context:{lang:_.code}}))[0];b[_.code]=T[i]||""}v.current=b,w(b)}function V(){return d.map((x,b)=>e.jsxs(p.Row,{style:{paddingBottom:20},children:[e.jsx(p.Col,{flex:"8rem",style:{paddingRight:10},children:x.name}),e.jsx(p.Col,{flex:"auto",children:e.jsx(wo.default,{rows:4,value:m[x.code]||"",onChange:_=>{w({...m,[x.code]:_.target.value})},disabled:C})})]},b))}async function k(){y(!0);try{for(const x of Object.keys(m))m[x]!==v.current[x]&&await Y.getHandler().update({model:s,id:o,values:{[i]:m[x]},context:{lang:x},fields:{}})}catch(x){Ae(x)}y(!1),a()}function L(){return u?e.jsx(p.Spin,{}):e.jsxs(e.Fragment,{children:[V(),e.jsx(p.Divider,{}),e.jsx(p.Row,{justify:"end",children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.CloseOutlined,{}),onClick:n,disabled:C,children:f("cancel")}),e.jsx(p.Button,{icon:C?e.jsx(H.LoadingOutlined,{}):e.jsx(H.CheckOutlined,{}),disabled:C,onClick:k,style:{marginLeft:15},type:"primary",children:f("ok")})]})})]})}return e.jsx(p.Modal,{title:f("translate"),centered:!0,width:c,open:r,closable:!0,onCancel:n,footer:null,destroyOnClose:!0,maskClosable:!1,children:L()})};function Le(t){const{tooltip:r,...n}=t;return e.jsx(p.Tooltip,{title:r,children:e.jsx(p.Button,{...n})})}const{info:Lo}=p.Modal,Ue=t=>{Lo({title:"",centered:!0,content:t})},{useToken:No}=p.theme,Gt=t=>{const{ooui:r,isSearchField:n=!1}=t,{id:s,readOnly:o,isPassword:i,required:a,translatable:c}=r,{token:f}=No(),d=a&&!o?{backgroundColor:f.colorPrimaryBg}:void 0,h=l.useContext(ke),{elementHasLostFocus:u}=h||{};let g=e.jsx(p.Input,{disabled:o||c&&!n,id:s,style:d,maxLength:r.size,onBlur:u});return i&&(g=e.jsx(p.Input.Password,{disabled:o,id:s,onBlur:u})),c&&!o&&!n&&(g=e.jsx(Po,{field:s,requiredStyle:d})),e.jsx(me,{required:a,...t,children:g})},Po=({value:t,field:r,requiredStyle:n,onChange:s})=>{const o=l.useContext(ke),{activeId:i,activeModel:a,fetchValues:c,formHasChanges:f,elementHasLostFocus:d}=o||{},[h,u]=l.useState(!1),{t:g}=l.useContext(ge);return i?e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>{if(f!=null&&f()){Ue(g("saveBeforeTranslate"));return}h||u(!0)},children:e.jsx(p.Input,{value:t,disabled:!0,id:r,onChange:C=>{s==null||s(C.target.value)},onBlur:d,style:{cursor:"pointer",pointerEvents:"none",...n}})}),e.jsx(Or,{id:i,model:a,field:r,visible:h,onCloseModal:()=>{u(!1)},onSubmitSucceed:()=>{u(!1),c==null||c()}})]}):e.jsx(e.Fragment,{children:e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"auto",children:e.jsx(p.Input,{value:t,id:r,style:n,onChange:C=>{s==null||s(C.target.value)},onBlur:d})}),e.jsx(p.Col,{flex:"32px",children:e.jsx(Le,{tooltip:g("translate"),icon:e.jsx(H.TranslationOutlined,{}),onClick:async()=>{f!=null&&f()?Ue(g("saveBeforeTranslate")):Ue(g("enterTextBeforeTranslate"))},children:g("translate")})})]})})},{defaultAlgorithm:Bo,defaultSeed:Ho}=p.theme,Ko=Bo(Ho),{Option:Yo}=p.Select,Ut=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(_r,{...t})})},_r=t=>{const{ooui:r,onChange:n,value:s}=t,{selectionValues:o,readOnly:i,required:a}=r,c=Array.from(o.entries()),f=c&&c.length&&c.map(h=>{const[u,g]=h;return e.jsx(Yo,{value:u,children:g},u)}),d=a&&!i?Wo:p.Select;return e.jsx(d,{disabled:i,onChange:n,value:s,optionFilterProp:"children",filterOption:(h,u)=>u.children.toLowerCase().indexOf(h.toLowerCase())>=0,showSearch:!0,children:f})},Wo=pt.default(p.Select)`
6
6
  &.ant-select:not(.ant-select-customize-input) .ant-select-selector {
7
7
  background-color: ${Ko.colorPrimaryBg};
8
8
  }
@@ -32,6 +32,6 @@
32
32
  .ant-input {
33
33
  background-color: ${hn.colorPrimaryBg};
34
34
  }
35
- `,mn=Be.default.createContext(null),ka=({children:t,initialView:r})=>{const[n,s]=l.useState(r),[o,i]=l.useState(0),[a,c]=l.useState(!1);return e.jsx(mn.Provider,{value:{currentView:n,setCurrentView:s,itemIndex:o,setItemIndex:i,manualTriggerChange:a,setManualTriggerChange:c},children:t})},{getValueForOperator:yn}=oe.graphProcessor,Mt=.7,Vt=30,wn=t=>{const{model:r,domain:n,context:s,colorCondition:o,totalDomain:i,showPercent:a=!1,icon:c,suffix:f,field:d,operator:h,manualIds:u}=t,[g,C]=l.useState(!1),[y,m]=l.useState(),[w,v]=l.useState(),[O,D]=l.useState(),[S,V]=l.useState(0),[k,L]=l.useState(0),[x,b]=l.useState(),[_,T]=l.useState(),[P,I]=l.useState();l.useEffect(()=>{A()},[r,o]);async function F({domain:M,isTotal:B}){if(B)return await E({domain:M});if(d&&h){const $=u||await Y.getHandler().searchAllIds({params:M,model:r,context:s}),W=await Y.getHandler().readObjects({model:r,ids:$,fieldsToRetrieve:[d],context:s});return yn({values:W.map(J=>J[d]),operator:h})}else return u?u.length:await Y.getHandler().searchCount({model:r,params:M,context:s})}async function E({domain:M}){if(d&&h){const B=await Y.getHandler().searchAllIds({params:M,model:r,context:s}),$=await Y.getHandler().readObjects({model:r,ids:B,fieldsToRetrieve:[d],context:s});return yn({values:$.map(W=>W[d]),operator:h})}else return await Y.getHandler().searchCount({model:r,params:M,context:s})}async function A(){C(!0);let M,B;try{const $=await F({domain:n,isTotal:!1});if(m($),i){const W=await Y.getHandler().evalDomain({domain:i,values:{},context:s});M=await F({domain:W,isTotal:!0}),D(M)}if(M?(B=Math.round($/M*100*100)/100,v(B)):v(0),o){const W=await Y.getHandler().parseCondition({condition:o,values:{value:$,percent:B},context:s});b(W)}if(c)if(c.indexOf(":")!==-1){const W=await Y.getHandler().parseCondition({condition:c,values:{value:$,percent:B},context:s});T(W)}else T(c)}catch($){I(JSON.stringify($))}C(!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 B,$;V((B=M.bounds)==null?void 0:B.height),L(($=M.bounds)==null?void 0:$.width)},children:({measureRef:M})=>a?e.jsx(Va,{value:y,total:O,percent:w,measureRef:M,height:S,width:k,color:x,icon:_,suffix:f}):e.jsx(Ma,{value:y,total:O,measureRef:M,height:S,width:k,color:x,icon:_,suffix:f})})};function vn(t,r){const s=document.createElement("canvas").getContext("2d");return s.font=r||getComputedStyle(document.body).font,s.measureText(t).width}function Ma({measureRef:t,width:r,height:n,total:s,value:o,color:i,icon:a,suffix:c}){let f=n*Mt<Vt?Vt:n*Mt;const d=o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0});let h=s?`${d}/${s}`:`${d}`;c&&(h+=" "+c);let u=vn(h,`bold ${Math.floor(f*1.03)}px sans-serif`);a&&(u=u*2),u>=r*.85&&(f=r*.85/u*f);const g=a&&We(a);return e.jsx("div",{ref:t,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden"},children:e.jsxs(Wt.default,{style:{fontSize:f,margin:0,color:i},children:[g&&e.jsx(g,{style:{fontSize:f*.7}}),g?` ${h}`:h]})})}function Va({measureRef:t,height:r,width:n,percent:s,total:o,value:i,color:a,icon:c,suffix:f}){const d=r*.65;let h=d*Mt<Vt?Vt:d*Mt;const u=i==null?void 0:i.toLocaleString("es-ES",{useGrouping:!0});let g=o?`${u}/${o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0})}`:`${u}`;f&&(g+=" "+f);const C=`${s==null?void 0:s.toLocaleString("es-ES",{useGrouping:!0})}%`;let y=vn(C,`bold ${Math.floor(h*1.03)}px sans-serif`);c&&(y=y*1.5);const m=c&&We(c);return(y>=n*.85||h*2<d)&&(h=n*.85/y*h),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:h*1,color:a,paddingRight:"10px"},children:e.jsx(m,{})}),e.jsxs(p.Col,{children:[e.jsx(Wt.default,{style:{fontSize:h*.8,margin:0,color:a},children:m?` ${s}%`:`${s}%`}),e.jsx(Wt.default,{style:{fontSize:h*.4,margin:0,color:a,textAlign:"center"},children:g})]})]})})}const rr=t=>r=>{const n=r.value.toLocaleString("es-ES",{useGrouping:!0});return{name:t==="pie"?r.x:r.type,value:n}},Et=t=>{if(typeof t=="string"&&Ea(t))return parseFloat(t).toLocaleString("es-ES",{useGrouping:!0});if(Ia(t))return t.toLocaleString("es-ES",{useGrouping:!0});if($a(t)){const r=Aa(t);return r===null?t:je(t,It.input[r]).format(It.output[r])}else return t},Ea=t=>/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(t),Ia=t=>typeof t=="number"&&!isNaN(t),Cn={default:{padding:"auto",xAxis:{tickCount:5,label:{formatter:Et}},yAxis:{label:{formatter:Et}},legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:rr("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:rr("pie")},interactions:[{type:"element-active"}]},barGrouped:{isGroup:!0,legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:rr("barGrouped")},xAxis:{label:{formatter:Et}},yAxis:{label:{formatter:Et}},label:{position:"middle",layout:[{type:"interval-adjust-position"},{type:"interval-hide-overlap"},{type:"adjust-color"}]}}};function $a(t){return typeof t!="string"||t===void 0?!1:new Date(t).toString()!=="Invalid Date"}const It={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 Aa(t){for(const r in It.input)if(je(t,It.input[r],!0).isValid())return r;return null}const{processGraphData:La}=oe.graphProcessor,{getFieldsToRetrieve:Na}=oe.graphFieldUtils,Pa=t=>{const{model:r,domain:n=[],context:s={},xml:o,limit:i,uninformedString:a,manualIds:c}=t,[f,d]=l.useState(!1),[h,u]=l.useState(),[g,C]=l.useState(),[y,m]=l.useState(),[w,v]=l.useState("line");return Re.default(()=>{(async()=>{d(!0),u(void 0);const O=oe.parseGraph(o);v(O.type||"line");const D=Na({ooui:O});let S,V;try{({values:S,fields:V}=await Ha({model:r,domain:n,context:s,limit:i,order:O.timerange?O.x.name:null,fields:D,manualIds:c}))}catch(k){u("Error fetching graph data values: "+JSON.stringify(k)),d(!1);return}try{if(!S||!V){u("No values or fields returned"),d(!1);return}m(S);const k=La({ooui:O,values:S,fields:V,options:{uninformedString:a}});C(k)}catch(k){u("Error processing graph data: "+k),d(!1);return}d(!1)})()},[o,r,i,s,n]),{loading:f,error:h,type:w,values:g,evaluatedEntries:y}};async function Ba({model:t,context:r,fields:n}){return await Y.getHandler().getFields({model:t,context:r,fields:n})}async function Ha({fields:t,model:r,domain:n,context:s,order:o,limit:i,manualIds:a}){const c=await Ba({model:r,context:s,fields:t});if(a){let d=await Y.getHandler().readObjects({model:r,ids:a,fieldsToRetrieve:t,context:s});return o&&(d=[...d].sort((h,u)=>h[o]-u[o])),{values:d,fields:c}}return{values:await Y.getHandler().search({model:r,params:n,fields:t,context:s,limit:i,order:o}),fields:c}}const Ka={line:Kt.Line,bar:Kt.Column,pie:Kt.Pie},Ya=t=>{var v;const{model:r,domain:n,context:s,xml:o,limit:i,manualIds:a}=t,{t:c}=l.useContext(ge),{error:f,loading:d,values:h,type:u,evaluatedEntries:g}=Pa({model:r,xml:o,limit:i,domain:n,context:s,uninformedString:c("uninformed"),manualIds:a});if(f)return e.jsx(p.Alert,{message:f,type:"error",banner:!0});if(d)return e.jsx(p.Spin,{});if(!h)return e.jsx(p.Alert,{message:"No data to display",type:"info"});const{data:C,isGroup:y,isStack:m}=h,w=Ka[u];return w?e.jsxs("div",{style:{padding:"1rem"},children:[e.jsx("p",{style:{textAlign:"right"},children:`${c("totalRegisters")} ${(v=g==null?void 0:g.length)==null?void 0:v.toLocaleString("es-ES",{useGrouping:!0})}`}),e.jsx(w,{...Wa({type:u,data:C,isGroup:y,isStack:m})})]}):e.jsx(e.Fragment,{children:`Unknown graph type: ${u}`})};function Wa(t){const{type:r,data:n,isGroup:s,isStack:o}=t;let i=Cn[r];return i||(i=Cn.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 qa=(t,r)=>{const{view_id:n,model:s,context:o,domain:i,limit:a,manualIds:c}=t,[f,d]=l.useState(!1),[h,u]=l.useState(),[g,C]=l.useState(),y=l.useContext(He),{setGraphIsLoading:m=void 0}=y||{};l.useImperativeHandle(r,()=>({refresh:()=>{w()}})),l.useEffect(()=>{w()},[n]);async function w(){d(!0),m==null||m(!0);try{const v=await Y.getHandler().getView({model:s,id:n,type:"graph",context:o});C(v.arch);const O=oe.parseGraph(v.arch);u(O)}catch(v){return console.error(v),e.jsx(e.Fragment,{children:JSON.stringify(v)})}d(!1),m==null||m(!1)}if(f)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(!h)return null;switch(h.type){case"indicatorField":case"indicator":{const v=h,O=v.type==="indicatorField"?{field:v.field,operator:v.operator}:{};return e.jsx(wn,{showPercent:v.showPercent,totalDomain:v.totalDomain,colorCondition:v.color,model:s,context:o,domain:i,icon:v.icon,suffix:v.suffix,manualIds:c,...O})}case"line":case"bar":case"pie":return e.jsx(Ya,{model:s,context:o,domain:i,xml:g,limit:a,manualIds:c});default:return e.jsx(e.Fragment,{children:`Graph ${h.type} not implemented`})}},$t=l.forwardRef(qa),{confirm:Ga}=p.Modal,Ua=({onOk:t,lang:r})=>{Ga({title:Se("removeItems",r),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmRemove",r),okText:Se("yesConfirmRemove",r),onOk:t,cancelText:Se("cancel",r)})},{confirm:ja}=p.Modal,za=({onOk:t,lang:r})=>{ja({title:Se("unlinkItems",r),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmUnlink",r),okText:Se("yesConfirmUnlink",r),onOk:t,cancelText:Se("cancel",r)})},{useToken:Ja}=p.theme,Za=t=>{const{title:r,readOnly:n,onCreateItem:s,onToggleViewMode:o,mode:i,onDelete:a,totalItems:c,currentItemIndex:f,onPreviousItem:d,onNextItem:h,isMany2Many:u,onSearchItem:g,selectedRowKeys:C,showCreateButton:y,showToggleButton:m}=t,{token:w}=Ja();function v(){return e.jsx("div",{className:"inline-block w-3"})}function O(){return e.jsx("div",{className:"flex flex-grow h-8 text-white",style:{borderRadius:w.borderRadius,backgroundColor:w.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 D(){return e.jsx(Le,{tooltip:u?"Unlink":"Delete",icon:u?e.jsx(H.ApiOutlined,{}):e.jsx(H.DeleteOutlined,{}),onClick:a,disabled:c===0||n||i!=="form"&&C.length===0})}function S(){let k="_";return c===0?k="_":k=(f+1).toString(),e.jsxs("span",{className:"pl-1 pr-1",children:["(",k,"/",c,")"]})}function V(){return e.jsxs(e.Fragment,{children:[v(),e.jsx(Le,{tooltip:"Previous item",icon:e.jsx(H.LeftOutlined,{}),onClick:d}),S(),e.jsx(Le,{tooltip:"Next item",icon:e.jsx(H.RightOutlined,{}),onClick:h})]})}return e.jsxs("div",{className:"flex mb-2",children:[O(),e.jsxs("div",{className:"flex-none h-8 pl-2",children:[i!=="graph"&&y&&e.jsx(Le,{tooltip:"Create new item",icon:e.jsx(H.FileAddOutlined,{}),disabled:n,onClick:s}),u&&y&&e.jsx(Le,{tooltip:"Search existing item",icon:e.jsx(H.SearchOutlined,{}),disabled:n,onClick:g}),i!=="graph"&&v(),i!=="graph"&&D(),i==="form"&&V(),v(),m&&e.jsx(Le,{tooltip:"Toggle view mode",icon:e.jsx(H.AlignLeftOutlined,{}),onClick:o})]})]})},Xa={form:oe.Form,tree:oe.Tree,graph:$t};function Qa(t){const r=t.map(s=>s.id);return t.filter((s,o)=>{const{id:i}=s;return!r.includes(i,o+1)})}const Ra=t=>{var Je;const{value:r,onChange:n,ooui:s,views:o}=t,{items:i=[]}=r||{},{currentView:a,setCurrentView:c,itemIndex:f,setItemIndex:d}=l.useContext(mn),h=l.useContext(ke),{activeId:u,getFields:g,getValues:C,getContext:y,domain:m}=h||{},{lang:w,t:v}=l.useContext(ge),[O,D]=l.useState(!1),[S,V]=l.useState(!1),[k,L]=l.useState(),[x,b]=l.useState(!1),[_,T]=l.useState(!1),[P,I]=l.useState(),[F,E]=l.useState([]),[A,M]=l.useState(!1),B=l.useRef([]),[$,W]=l.useState(),J=l.useRef(),[q,X]=l.useState(void 0),{readOnly:j,relation:N,context:K,domain:Z}=s,se=s.type==="many2many",{id:ce}=s,Q=i.filter(ee=>(ee.values||ee.treeValues)&&ee.operation!=="pendingRemove"),R=l.useRef();l.useEffect(()=>{if(R.current!==a){R.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))&&Me()},[i,a]);l.useEffect(()=>{de()},[m]);const ve=ee=>{var le,Oe;n==null||n({fields:((le=o.get("form"))==null?void 0:le.fields)||((Oe=o.get("tree"))==null?void 0:Oe.fields),items:Qa(ee)})},Me=async()=>{await xe(),f>Q.length-1&&f!==0&&d(0)},xe=async ee=>{var le,Oe,he;V(!0),D(!1),L(void 0);try{const[pe,ie]=await zt({treeView:{arch:(le=o.get("tree"))==null?void 0:le.arch,fields:(Oe=o.get("tree"))==null?void 0:Oe.fields},formView:{fields:((he=o.get("form"))==null?void 0:he.fields)||{}},model:N,items:i,context:{...y==null?void 0:y(),...K},currentView:ee||a});return J.current||(J.current=pe.map(Pe=>Pe.id)),(a||ee)==="tree"&&ie&&X(ie),ve(pe),pe}catch(pe){L(pe)}finally{V(!1)}};async function de(){Z&&(B.current=await Y.getHandler().evalDomain({domain:Z,values:at({fields:g(),values:C()}),fields:g(),context:y()})),m&&m.length>0&&(B.current=B.current.concat(oe.transformDomainForChildWidget({domain:m,widgetFieldName:ce})))}const ae=()=>{const ee=Array.from(o.keys()),le=ee[(ee.indexOf(a)+1)%ee.length];a==="form"?Ve(()=>{c(le)}):c(le)},we=()=>{f>0&&(a==="form"?Ve(()=>{d(f-1)}):d(f-1))},De=()=>{const ee=Q.length;f<ee-1&&(a==="form"?Ve(()=>{d(f+1)}):d(f+1))},be=async()=>{const ee=Q[f].id,le=(await Y.getHandler().readObjects({model:N,ids:[ee],fields:o.get("form").fields,context:{...y==null?void 0:y(),...K}}))[0],Oe=(await Y.getHandler().readObjects({model:N,ids:[ee],fields:o.get("tree").fields,context:{...y==null?void 0:y(),...K}}))[0],he=i.map(pe=>pe.id===ee?{...pe,operation:"original",values:le,treeValues:Oe}:pe);ve(he)},Ve=ee=>{O?yt({lang:w,onOk:()=>{be(),ee(),D(!1)}}):ee()},Ke=()=>{if(se){za({lang:w,onOk:()=>{a==="form"?Te():Ee()}});return}Ua({lang:w,onOk:()=>{a==="form"?Te():Ee()}})},Ie=async()=>{const{inv_field:ee}=s;let le;ee&&u&&(le={[ee]:u}),a==="form"?Ve(()=>{M(!0),I({defaultValues:le}),b(!0)}):(M(!0),I({defaultValues:le}),b(!0))},te=async()=>{a==="form"?Ve(()=>{T(!0)}):T(!0)},Te=async()=>{V(!0),D(!1),L(void 0);try{if(Q[f].id>0){const ee=i.map(le=>le.id===Q[f].id?{...le,operation:"pendingRemove"}:le);ve(ee)}else ve(i.filter(ee=>ee.id!==Q[f].id))}catch(ee){L(ee)}d(0),V(!1)},Ee=async()=>{const ee=Q.filter(le=>F.includes(le.id));V(!0),D(!1),L(void 0);try{const le=ee.map(he=>he.id),Oe=i.filter(he=>!(le.includes(he.id)&&he.id<0)).map(he=>le.includes(he.id)?{...he,operation:"pendingRemove"}:he);ve(Oe)}catch(le){L(le)}d(0),V(!1)},ye=(ee,le,Oe)=>{let he;if(ee)he=i.map(pe=>pe.id===ee?{id:ee,operation:ee>0?"pendingUpdate":"pendingCreate",values:{...Oe,id:ee},treeValues:{...Oe,id:ee}}:pe);else{const pe=Qs(i);he=i.concat({id:pe,operation:"pendingCreate",values:{...Oe,id:pe},treeValues:{...Oe,id:pe}})}ve(he),A||b(!1)},Ce=async ee=>{const{id:le}=ee;let Oe=i;const he=i.find(pe=>pe.id===le);(he==null?void 0:he.values)===void 0&&(Oe=await xe("form")),I(Oe.find(pe=>pe.id===le)),M(!1),b(!0)},Fe=async ee=>{V(!0);let le=i;const Oe=ee.filter(he=>!i.find(pe=>pe.id===he));try{for(const he of Oe){const pe=(await Y.getHandler().readObjects({model:N,ids:[he],fields:o.get("form").fields,context:{...y==null?void 0:y(),...K}}))[0],ie=(await Y.getHandler().readObjects({model:N,ids:[he],fields:o.get("tree").fields,context:{...y==null?void 0:y(),...K}}))[0];le.push({id:he,operation:"pendingLink",values:pe,treeValues:ie})}ve(le)}catch(he){L(he)}finally{V(!1)}};function fe(){const ee=Xa[a];if(a==="graph")return oe.parseGraph(o.get("graph").arch).string;{const le=new ee(o.get(a).fields);return le.parse(o.get(a).arch),le.string}}const qe=()=>{var le,Oe,he,pe;if(a==="form")return Q.length===0?v("noCurrentEntries"):a!==R.current&&i.some(ie=>!ie.values)?e.jsx(p.Spin,{}):e.jsx(ct,{formView:o.get("form"),values:(le=Q[f])==null?void 0:le.values,parentContext:{...y==null?void 0:y(),...K},model:N,id:(Oe=Q[f])==null?void 0:Oe.id,submitMode:"values",onFieldsChange:ie=>{var xt;const Pe=(xt=Q[f])==null?void 0:xt.id,Ze=i.map(Qe=>Qe.id===Pe?{...Qe,operation:Qe.operation==="original"?"pendingUpdate":Qe.operation,values:{...ie,id:Pe},treeValues:{...ie,id:Pe}}:Qe);ve(Ze),D(!0)},readOnly:j});let ee=[];if(Q.some(ie=>ie.treeValues)&&(ee=$?st({resultsToSort:Q.map(ie=>ie.treeValues),sorter:$,fields:{...o.get("tree").fields,...((he=o.get("form"))==null?void 0:he.fields)||{}}}):Q.map(ie=>ie.treeValues)),a==="tree")return e.jsx(Ct,{total:Q.length,limit:Q.length,treeView:o.get("tree"),results:ee,loading:S,onRowClicked:((pe=o.get("form"))==null?void 0:pe.fields)!==void 0?Ce:void 0,showPagination:!1,rowSelection:{selectedRowKeys:F,onChange:E},sorter:$,onChangeSort:W,context:{...y==null?void 0:y(),...K},colorsForResults:q,readonly:j});if(a==="graph"){const ie=[[`${s.inv_field}`,"=",u]];return e.jsx($t,{view_id:o.get("graph").view_id,model:s.relation,domain:ie,context:{...y==null?void 0:y(),...K},limit:0})}};if(k)return e.jsx(p.Alert,{className:"mt-10",message:k,type:"error",banner:!0});const $e=A;return S?e.jsx(p.Spin,{}):e.jsxs(e.Fragment,{children:[e.jsx(Za,{mode:a,title:fe(),readOnly:j,isMany2Many:se,formHasChanges:O,totalItems:Q.length,currentItemIndex:f,onDelete:Ke,onCreateItem:Ie,onToggleViewMode:ae,onPreviousItem:we,onNextItem:De,onSearchItem:te,selectedRowKeys:F,showCreateButton:((Je=o.get("form"))==null?void 0:Je.fields)!==void 0,showToggleButton:o.size>1}),qe(),e.jsx(dt,{formView:o.get("form"),model:N,id:P==null?void 0:P.id,submitMode:"values",values:P==null?void 0:P.values,defaultValues:P==null?void 0:P.defaultValues,visible:x,onSubmitSucceed:ye,parentContext:{...y==null?void 0:y(),...K},onCancel:()=>{M(!1),b(!1)},readOnly:j,mustClearAfterSave:$e}),e.jsx(tr,{domain:B.current,model:N,context:{...y==null?void 0:y(),...K},visible:_,onSelectValues:async ee=>{T(!1),Fe(ee)},onCloseModal:()=>{T(!1)}})]})},Sn=t=>{const{ooui:r}=t,{mode:n,relation:s,views:o,required:i,context:a}=r;let c;const[f,d]=l.useState(!0),[h,u]=l.useState(),[g,C]=l.useState(new Map),y=l.useContext(ke),{getContext:m}=y||{};Re.default(()=>{v()},[r]);const w=async D=>o&&o[D]?o[D]:await Y.getHandler().getView({model:s,type:D,context:{...m==null?void 0:m(),...a}}),v=async()=>{d(!0),u(void 0);try{if(n&&n.length>0){for(const D of n){const S=await w(D);g.set(D,S)}C(g)}else{const D=await w("form"),S=await w("tree");g.set("form",D),g.set("tree",S),C(g)}}catch(D){u(JSON.stringify(D))}finally{d(!1)}};if(n&&n.length>0?c=n[0]:c="tree",f)return e.jsx(p.Spin,{});if(h)return e.jsx(p.Alert,{className:"mt-10",message:h,type:"error",banner:!0});const O=async(D,S)=>{if(!S)throw new Error;if(!S.items)throw new Error;if(!Array.isArray(S.items))throw new Error;if(S.items.length===0)throw new Error};return e.jsx(ka,{initialView:c,children:e.jsx(me,{required:i,type:"array",validator:O,...t,children:e.jsx(Ra,{ooui:r,views:g})})})},{useToken:el}=p.theme,bn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"number",...t,children:e.jsx(tl,{ooui:r})})},tl=t=>{const{ooui:r,value:n,onChange:s}=t,{id:o,readOnly:i,required:a}=r,{token:c}=el(),f=a&&!i?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useRef(),[h,u]=l.useState(),g=l.useContext(ke),{elementHasLostFocus:C}=g||{};l.useEffect(()=>{u(en(n))},[n]);const y=v=>{s==null||s(v)};function m(v){d.current=v.target.value,u(v.target.value)}async function w(){y(na(h)),await new Promise(v=>setTimeout(v,300)),C==null||C()}return e.jsx(p.Input,{value:h,disabled:i,className:"w-full",style:f,id:o,placeholder:"00:00",onChange:m,onBlur:w})};function nr(t){const{ooui:r,showLabel:n=!0,responsiveBehaviour:s}=t,o=We(r.icon||"");return e.jsx(e.Fragment,{children:(r.label||o)&&n?e.jsx(pr.FieldSet,{label:r.label,icon:o,children:e.jsx(Zt,{container:r.container,responsiveBehaviour:s})}):e.jsx(Zt,{container:r.container,responsiveBehaviour:s})})}const{TabPane:rl}=p.Tabs;function xn(t){const{ooui:r,responsiveBehaviour:n}=t,s=r.pages;function o(i){if(i){const a=We(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(rl,{tab:e.jsxs(e.Fragment,{children:[o(i.icon)," ",i.label]}),children:e.jsx(nr,{ooui:i,showLabel:!1,responsiveBehaviour:n})},i.label))})}const{useToken:nl}=p.theme,{TextArea:or}=p.Input,Tn=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o,height:i,translatable:a}=r,{token:c}=nl(),f=o&&!s?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useContext(ke),{elementHasLostFocus:h}=d||{};return e.jsx(me,{required:o,...t,children:a?e.jsx(ol,{field:n,height:i,requiredStyle:f}):e.jsx(or,{disabled:s||a,style:{minHeight:i?i+"px":"100%",...f},rows:4,onBlur:h})})},ol=({value:t,field:r,requiredStyle:n,onChange:s,height:o})=>{const i=l.useContext(ke),{activeId:a,activeModel:c,fetchValues:f,formHasChanges:d,elementHasLostFocus:h}=i||{},[u,g]=l.useState(!1),{t:C}=l.useContext(ge);return a?e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>{if(d!=null&&d()){Ue(C("saveBeforeTranslate"));return}u||g(!0)},children:e.jsx(or,{value:t,onChange:y=>{s==null||s(y.target.value)},style:{height:o?o+"px":"100%",cursor:"pointer",...n},id:r,disabled:!0,rows:4,onBlur:h})}),e.jsx(Or,{id:a,model:c,field:r,visible:u,onCloseModal:()=>{g(!1)},onSubmitSucceed:()=>{g(!1),f==null||f()}})]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Row,{gutter:8,wrap:!1,children:e.jsx(or,{value:t,onChange:y=>{s==null||s(y.target.value)},style:{height:o?o+"px":"100%",...n},id:r,rows:4,onBlur:h})}),e.jsx(p.Row,{justify:"end",style:{paddingTop:5},children:e.jsx(Le,{tooltip:C("translate"),icon:e.jsx(H.TranslationOutlined,{}),onClick:async()=>{d!=null&&d()?Ue(C("saveBeforeTranslate")):Ue(C("enterTextBeforeTranslate"))},children:C("translate")})})]})},Fn=t=>{const{ooui:r}=t,{label:n,icon:s}=r,o=We(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({}),f=l.useRef(new Map),d=l.useCallback(async w=>{if(w.selectedKeys===void 0||w.selectedKeys.length===0){Ue(Se("selectAtLeastOneField",n));return}let v=o;w.registersAmount==="selected"&&(s==null?void 0:s.length)!==0&&(v=[["id","in",s==null?void 0:s.map(S=>S.id)]]);const{datas:O}=await Y.getHandler().exportData({model:t,fields:ul({keys:w.selectedKeys,fields:c.current}),domain:v,limit:w.registersAmount==="all"?0:i,context:r,format:w.exportType});a(),await new Promise(S=>setTimeout(S,200));const D=await nt(O);Ft(O,D.mime)},[n,t,o,i,r,a]),h=l.useCallback(async()=>{const w=await Y.getHandler().getFields({model:t,context:r,fields:[]});return c.current["/"]=w,On({fields:w})},[t,r,c]),u=l.useCallback(async w=>{const O=ir(w,c.current)[sr(w)],D=O.relation,S=await Y.getHandler().getFields({model:D,context:r,fields:[]});for(const[V,k]of Object.entries(S))S[V].string=al({parentTitle:O.string,title:k.string});return c.current[w]=S,On({fields:S,parentKey:w})},[c.current,t,r]),g=l.useCallback(async()=>{const w=await ll({model:t,context:r}),v=await dl({predefinedExports:w,fields:c.current,onGetFieldChilds:u});return{predefinedExports:w.map(D=>({...D,fields:D.fields.map(S=>{const V=sr(S.key),L=ir(S.key,c.current)[V];return{key:S.key,title:L.string}})})),keysWithChilds:v}},[c.current]),C=l.useCallback(async w=>{const v=await m("ir.exports"),O=await m("ir.exports.line"),D=await Y.getHandler().create({model:"ir.exports",values:{name:w.name,resource:t},fields:v,context:r});return await Promise.all(w.fields.map(async S=>await Y.getHandler().create({model:"ir.exports.line",values:{name:S.key,export_id:D},fields:O,context:r}))),{...w,id:D}},[]),y=l.useCallback(async w=>{await Y.getHandler().delete({model:"ir.exports",ids:[w.id]})},[]),m=l.useCallback(async w=>{if(f.current.has(w))return f.current.get(w);const v=Y.getHandler().getFields({model:w,context:r,fields:[]});f.current.set(w,v)},[f,r]);return{onGetFields:h,onGetFieldChilds:u,onExport:d,onGetPredefinedExports:g,onSavePredefinedExport:C,onRemovePredefinedExport:y}},On=({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=_n(o);n.push({key:il({key:s,parentKey:r}),title:o.string,tooltip:o.help,required:o.required,isLeaf:!i})}return n},_n=t=>t.type==="many2one"||t.type==="one2many"||t.type==="many2many",il=({parentKey:t,key:r})=>`${t?t+"/":""}${r}`,St=t=>t.indexOf("/")===-1?t:t.split("/").slice(0,-1).join("/"),sr=t=>{if(t.indexOf("/")===-1)return t;const r=t.split("/");return r[r.length-1]},ir=(t,r)=>t.indexOf("/")===-1?r["/"]:r[St(t)],al=({title:t,parentTitle:r})=>`${r?r+" \u2192 ":""}${t}`,ll=async({model:t,context:r})=>{const n=await Y.getHandler().search({model:"ir.exports",params:[["resource","=",t]],context:r}),s=n.flatMap(i=>i.export_fields),o=await Y.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(f=>f.id===a).name}))}))},cl=({fields:t,keys:r})=>fl([...new Set(r.filter(n=>{var s,o,i;if(n.indexOf("/")===-1)return!((s=t["/"])!=null&&s[n]);{const a=St(n);console.log({key:n,parentKey:a,fields:t});const c=(o=t==null?void 0:t[St(n)])==null?void 0:o[n];return console.log({exists:c}),!((i=t==null?void 0:t[St(n)])!=null&&i[n])}}).map(n=>St(n)))]),dl=async({predefinedExports:t,fields:r,onGetFieldChilds:n})=>{const s=t.flatMap(a=>a.fields.map(c=>c.key)),o=cl({fields:r,keys:s}),i=[];for(const a of o)i.push({key:a,childs:await n(a)});return i},ul=({keys:t,fields:r})=>t.map(n=>{const s=sr(n),i=ir(n,r)[s];return _n(i)?`${n}/id`:n}),fl=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},Dn=t=>{const{visible:r,locale:n,onClose:s,model:o,context:i,selectedRegistersToExport:a,totalRegisters:c,domain:f,limit:d,visibleRegisters:h}=t,{onExport:u,onGetFieldChilds:g,onGetFields:C,onGetPredefinedExports:y,onSavePredefinedExport:m,onRemovePredefinedExport:w}=sl({model:o,context:i,domain:f,limit:d,selectedRegistersToExport:a,onClose:s,locale:n});return e.jsx(pr.ExportModal,{visible:r,locale:n,onSucceed:u,onCancel:s,selectedRegistersToExport:a&&a.length&&a.length>0?a.length:void 0,totalRegisters:c,onGetFieldChilds:g,onGetFields:C,visibleRegisters:h,onGetPredefinedExports:y,onSavePredefinedExport:m,onRemovePredefinedExport:w})},kn=t=>{const{ooui:r}=t;return e.jsx(dn,{ooui:r})},Mn=t=>{const{ooui:r}=t;return e.jsx(dn,{ooui:r,showTime:!0})};var Vn={exports:{}};(function(t,r){(function(n,s){t.exports=s()})(Xe,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={},f=function(m){return(m=+m)+(m>68?1900:2e3)},d=function(m){return function(w){this[m]=+w}},h=[/[+-]\d\d:?(\d\d)?|Z/,function(m){(this.zone||(this.zone={})).offset=function(w){if(!w||w==="Z")return 0;var v=w.match(/([+-]|\d\d)/g),O=60*v[1]+(+v[2]||0);return O===0?0:v[0]==="+"?-O:O}(m)}],u=function(m){var w=c[m];return w&&(w.indexOf?w:w.s.concat(w.f))},g=function(m,w){var v,O=c.meridiem;if(O){for(var D=1;D<=24;D+=1)if(m.indexOf(O(D,0,w))>-1){v=D>12;break}}else v=m===(w?"pm":"PM");return v},C={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 w=c.ordinal,v=m.match(/\d+/);if(this.day=v[0],w)for(var O=1;O<=31;O+=1)w(O).replace(/\[|\]/g,"")===m&&(this.day=O)}],M:[i,d("month")],MM:[o,d("month")],MMM:[a,function(m){var w=u("months"),v=(u("monthsShort")||w.map(function(O){return O.slice(0,3)})).indexOf(m)+1;if(v<1)throw new Error;this.month=v%12||v}],MMMM:[a,function(m){var w=u("months").indexOf(m)+1;if(w<1)throw new Error;this.month=w%12||w}],Y:[/[+-]?\d+/,d("year")],YY:[o,function(m){this.year=f(m)}],YYYY:[/\d{4}/,d("year")],Z:h,ZZ:h};function y(m){var w,v;w=m,v=c&&c.formats;for(var O=(m=w.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(b,_,T){var P=T&&T.toUpperCase();return _||v[T]||n[T]||v[P].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,F,E){return F||E.slice(1)})})).match(s),D=O.length,S=0;S<D;S+=1){var V=O[S],k=C[V],L=k&&k[0],x=k&&k[1];O[S]=x?{regex:L,parser:x}:V.replace(/^\[|\]$/g,"")}return function(b){for(var _={},T=0,P=0;T<D;T+=1){var I=O[T];if(typeof I=="string")P+=I.length;else{var F=I.regex,E=I.parser,A=b.slice(P),M=F.exec(A)[0];E.call(_,M),b=b.replace(M,"")}}return function(B){var $=B.afternoon;if($!==void 0){var W=B.hours;$?W<12&&(B.hours+=12):W===12&&(B.hours=0),delete B.afternoon}}(_),_}}return function(m,w,v){v.p.customParseFormat=!0,m&&m.parseTwoDigitYear&&(f=m.parseTwoDigitYear);var O=w.prototype,D=O.parse;O.parse=function(S){var V=S.date,k=S.utc,L=S.args;this.$u=k;var x=L[1];if(typeof x=="string"){var b=L[2]===!0,_=L[3]===!0,T=b||_,P=L[2];_&&(P=L[2]),c=this.$locale(),!b&&P&&(c=v.Ls[P]),this.$d=function(A,M,B){try{if(["x","X"].indexOf(M)>-1)return new Date((M==="X"?1e3:1)*A);var $=y(M)(A),W=$.year,J=$.month,q=$.day,X=$.hours,j=$.minutes,N=$.seconds,K=$.milliseconds,Z=$.zone,se=new Date,ce=q||(W||J?1:se.getDate()),Q=W||se.getFullYear(),R=0;W&&!J||(R=J>0?J-1:se.getMonth());var ue=X||0,ve=j||0,Me=N||0,xe=K||0;return Z?new Date(Date.UTC(Q,R,ce,ue,ve,Me,xe+60*Z.offset*1e3)):B?new Date(Date.UTC(Q,R,ce,ue,ve,Me,xe)):new Date(Q,R,ce,ue,ve,Me,xe)}catch{return new Date("")}}(V,x,k),this.init(),P&&P!==!0&&(this.$L=this.locale(P).$L),T&&V!=this.format(x)&&(this.$d=new Date("")),c={}}else if(x instanceof Array)for(var I=x.length,F=1;F<=I;F+=1){L[1]=x[F-1];var E=v.apply(this,L);if(E.isValid()){this.$d=E.$d,this.$L=E.$L,this.init();break}F===I&&(this.$d=new Date(""))}else D.call(this,S)}}})})(Vn);const hl=Vn.exports;je.extend(hl);const En=t=>{const{ooui:r}=t;return e.jsx(me,{...t,children:e.jsx(pl,{ooui:r})})},pl=t=>{const r=(n,s)=>{t.onChange&&t.onChange(s)};return e.jsx(p.TimePicker,{onChange:r,value:t.value?je(t.value,"HH:mm:ss"):void 0})},In=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(gl,{ooui:r})})},gl=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,selectionValues:i,readOnly:a}=s,c=r==null?void 0:r.split(","),[f,d]=l.useState([]),[h,u]=l.useState();return l.useEffect(()=>{if(!r){u(void 0),d([]);return}const g=r&&c&&c[0],C=r&&c&&c[1]&&parseInt(c[1]);d([C,void 0]),u(g)},[r]),e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"1",children:e.jsx(_r,{ooui:new oe.Selection({name:"model_selection",selection:i,readonly:a,required:o}),onChange:g=>{u(g);let C=f[0]||0;g!==h&&(d([]),C=0);const y=`${g},${C}`;y!==r&&(n==null||n(y))},value:h})}),e.jsx(p.Col,{flex:"3",children:e.jsx(gn,{ooui:new oe.Many2one({name:"object_value",relation:h,readonly:a,required:o}),value:f,onChange:g=>{d(g);const C=`${h},${g[0]||0}`;C!==r&&(n==null||n(C))}})})]})},{useToken:ml}=p.theme,$n=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(yl,{ooui:r})})},yl=t=>{const{ooui:r,value:n,onChange:s}=t,{readOnly:o,required:i,filenameField:a}=r,{token:c}=ml(),f=i&&!o?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useRef(null),{setFieldValue:h,getFieldValue:u}=l.useContext(ke)||{},{t:g}=l.useContext(ge),C=n?js(n):"",y=D=>{s==null||s(D)};async function m(){const D=await nt(n),S=`data:${D==null?void 0:D.mime};base64,${n}`,V=document.createElement("a"),k=u(a),L=u("name");V.href=S,V.download=k||L,V.click()}async function w(){const D=await nt(n);Ft(n,D.mime)}async function v(D){D.stopPropagation(),D.preventDefault();const S=D.target.files[0],V=await Hr(S);y(V),a&&h(a,S.name)}function O(){h(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:v}),e.jsx(p.Input,{type:"text",disabled:!0,style:f,value:C})]}),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:w,children:g("open")}),e.jsx(Le,{tooltip:g("download"),disabled:!n,onClick:m,icon:e.jsx(H.DownloadOutlined,{})}),e.jsx(Le,{tooltip:g("clear"),disabled:o||!n,onClick:O,icon:e.jsx(H.ClearOutlined,{})})]})})]})},ar={tree:e.jsx(H.TableOutlined,{}),form:e.jsx(H.FormOutlined,{}),graph:e.jsx(H.AreaChartOutlined,{}),calendar:e.jsx(H.CalendarOutlined,{})};function An(t){return t?(ar==null?void 0:ar[t.type])||e.jsx(H.FormOutlined,{}):e.jsx(H.FormOutlined,{})}function lr(t){const{currentView:r,availableViews:n,onChangeView:s,disabled:o=!1,formHasChanges:i=!1,previousView:a}=t,{t:c,lang:f}=l.useContext(ge);function d(){const g=n.map((C,y)=>e.jsx(p.Menu.Item,{children:e.jsxs(p.Row,{wrap:!1,children:[e.jsx(p.Col,{flex:"none",style:{paddingRight:20},children:An(C)}),e.jsx(p.Col,{flex:"auto",style:{paddingRight:20},children:C.type.charAt(0).toUpperCase()+C.type.slice(1)}),e.jsx(p.Col,{flex:"none",children:e.jsx(H.CheckOutlined,{style:{opacity:r.view_id===C.view_id?1:0}})})]})},C.view_id||y));return e.jsx(p.Menu,{onClick:u,children:e.jsx(p.Menu.ItemGroup,{title:c("viewAs"),children:g})})}function h(g){if(i){yt({lang:f,onOk:()=>{g()}});return}g()}function u(g){h(()=>{const C=n.find(y=>y.view_id===parseInt(g.key));s(C)})}return e.jsxs("div",{style:{display:"flex"},children:[e.jsx(Le,{tooltip:a?c("viewAs")+" "+c(a.type):"",icon:An(a),style:{width:50,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:()=>{u({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()})})]})}function ut(t){const{icon:r,tooltip:n,items:s=[],onItemClick:o,label:i,disabled:a=!1}=t;function c(){const d=s==null?void 0:s.map((h,u)=>h.name==="divider"?e.jsx(p.Menu.Divider,{},"divider"+u):e.jsx(p.Menu.Item,{children:h.name},h.id));return e.jsx(p.Menu,{onClick:f,children:e.jsx(p.Menu.ItemGroup,{title:n,children:d})})}function f(d){const h=s.find(u=>isNaN(d.key)?u.id===d.key:u.id===parseInt(d.key));o(h)}return e.jsx(p.Dropdown,{overlay:c(),disabled:a||!s||s.length===0,children:e.jsxs(p.Button,{children:[r," ",i," ",e.jsx(H.DownOutlined,{})]})})}function Ne(t){const{onClick:r,disabled:n=!1,loading:s=!1,tooltip:o,icon:i,label:a,type:c="default"}=t,f=s?e.jsx(H.LoadingOutlined,{}):i;return e.jsxs(Le,{type:c,tooltip:o,onClick:r,disabled:n,children:[f,a]})}function Ln(t){const{disabled:r=!1}=t,{formHasChanges:n,onNewClicked:s}=l.useContext(He),{t:o,lang:i}=l.useContext(ge),a=()=>{if(n){yt({lang:i,onOk:()=>{s()}});return}s()};return e.jsx(Ne,{icon:e.jsx(H.FileAddOutlined,{}),tooltip:o("new"),onClick:a,disabled:r})}const{confirm:wl}=p.Modal,vl=({onOk:t,onCancel:r,lang:n})=>{wl({title:Se("unsavedChanges",n),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmRefreshWithoutSave",n),okText:Se("discardAndRefresh",n),cancelText:Se("cancel",n),onOk:t,onCancel:r})};async function Nn(t,r,n){const s=(await Y.getHandler().getLogInfo({model:t,ids:[r]}))[0],{create_date:o,create_uid:i,id:a,write_date:c,write_uid:f}=s;Ue(e.jsxs("div",{children:["ID: "+a," ",e.jsx("br",{}),n("createdBy")+": "+i[1]," ",e.jsx("br",{}),n("creationDate")+": "+o," ",e.jsx("br",{}),n("lastUpdatedBy")+": "+f[1]," ",e.jsx("br",{}),n("lastUpdatedDate")+": "+c]}))}const Cl=t=>{const{numberOfAttachments:r,disabled:n}=t,{t:s,lang:o}=l.useContext(ge),[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:f=>a(f),visible:i,placement:"bottom",content:Sl(t,a,o),title:s("attachments"),arrowContent:null,children:c})},Sl=(t,r,n)=>{const{attachments:s=[],loading:o,onAddNewAttachment:i,onopenAttachmentLink:a,onOpenAttachmentDetail:c,onListAllAttachments:f}=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),f()},children:[e.jsx(H.TableOutlined,{})," ",Se("listAllAttachments",n)]}),e.jsxs("a",{style:{display:"block"},href:"#",onClick:()=>{r(!1),i()},children:[e.jsx(H.FileAddOutlined,{})," ",Se("addNewAttachment",n)]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("li",{className:"ant-dropdown-menu-item-divider"}),s.map(d=>{const h=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?Se("openAttachmentLink",n):Se("download",n),children:e.jsx(h,{style:{cursor:"pointer"},onClick:()=>{r(!1),a(d)}})})}),e.jsx(p.Col,{flex:"25px",style:{textAlign:"center"},children:e.jsx(p.Tooltip,{title:Se("openAttachment",n),children:e.jsx(H.FormOutlined,{style:{cursor:"pointer"},onClick:()=>{r(!1),c(d)}})})})]},d.id)})]})]})};function bl(t){const{attachments:r,disabled:n=!1,onAddNewAttachment:s,onListAllAttachments:o,onViewAttachmentDetails:i}=t,{formRef:a}=l.useContext(He),[c,f]=l.useState(!1),[d,h]=l.useState([]),[u,g]=l.useState(!1),{t:C}=l.useContext(ge),y=l.useCallback(async()=>{f(!0);try{const v=await Y.getHandler().readObjects({model:"ir.attachment",ids:r.map(O=>O.id),fieldsToRetrieve:["name","datas_fname","link"],context:a.current.getContext()});h(v.map(O=>({id:O.id,name:O.name,datas_fname:O.datas_fname,link:O.link})))}catch(v){Ae(v)}f(!1)},r),m=l.useCallback(async v=>{if(v.link){window.open(v.link);return}g(!0);let O;try{O=(await Y.getHandler().readObjects({model:"ir.attachment",ids:[v.id],context:a.current.getContext()}))[0]}catch(D){Ae(D)}if(g(!1),!!O)if(O.datas){const D=await nt(O.datas);Ft(O.datas,D.mime)}else i(O)},[]),w=l.useCallback(async v=>{i(v)},[]);return l.useEffect(()=>{y()},[y]),e.jsxs(e.Fragment,{children:[e.jsx(Cl,{numberOfAttachments:r.length,attachments:d,disabled:n,loading:c,onAddNewAttachment:s,onListAllAttachments:o,onopenAttachmentLink:m,onOpenAttachmentDetail:w}),e.jsx(p.Modal,{title:C("downloadingAttachment"),open:u,footer:null,closable:!1,centered:!0,maskClosable:!1,children:e.jsx(p.Spin,{})})]})}function Pn({toolbar:t}){const{availableViews:r,currentView:n,setCurrentView:s,onFormSave:o,formHasChanges:i,formIsSaving:a,currentId:c,results:f,setCurrentItemIndex:d,currentItemIndex:h,setCurrentId:u,currentModel:g,setRemovingItem:C,removingItem:y,duplicatingItem:m,setDuplicatingItem:w,setResults:v,formIsLoading:O,attachments:D,formRef:S,setFormHasChanges:V,previousView:k,setPreviousView:L,goToResourceId:x}=l.useContext(He),{t:b,lang:_}=l.useContext(ge),T=l.useContext(lt),{processAction:P}=T||{},I=l.useContext(Ge),{openRelate:F,openDefaultActionForModel:E}=I||{};function A(N){if(i){vl({lang:_,onOk:()=>{N()}});return}N()}function M(N){if(i){yt({lang:_,onOk:()=>{N()}});return}N()}function B(){f&&f.length>h+1?(d==null||d(h+1),u==null||u(f[h+1].id)):f&&h+1===f.length&&(d==null||d(0),u==null||u(f[0].id))}function $(){f&&h>0?(d==null||d(h-1),u==null||u(f[h-1].id)):f&&h===0&&(d==null||d(f.length-1),u==null||u(f[f.length-1].id))}function W(){rt({confirmMessage:b("confirmRemoveItem"),lang:_,onOk:()=>{J()}})}async function J(){try{C==null||C(!0),await Y.getHandler().delete({model:g,ids:[c]});const N=f==null?void 0:f.filter(Z=>Z.id!==c);v==null||v(N);let K=0;h>0&&h<=f.length-1&&(K=h-1),N!=null&&N[K]?(u==null||u(N==null?void 0:N[K].id),d==null||d(K)):(u==null||u(void 0),d==null||d(void 0))}catch(N){kt(JSON.stringify(N))}finally{C==null||C(!1)}}async function q(){try{w==null||w(!0);const N=await Y.getHandler().duplicate({id:c,model:g,context:S.current.getContext()});N&&await(x==null?void 0:x(N))}catch(N){kt(JSON.stringify(N))}finally{w==null||w(!1)}}const X=a||y||O||m;function j(N){P==null||P({actionData:N,values:S.current.getValues(),fields:S.current.getFields(),context:S.current.getContext(),onRefreshParentValues:()=>{S.current.fetchValues()}})}return n?e.jsxs(p.Space,{wrap:!0,children:[O&&e.jsxs(e.Fragment,{children:[e.jsx(p.Spin,{}),ft(),ft()]}),e.jsx(Ln,{disabled:a||O||y||m}),e.jsx(Ne,{icon:e.jsx(H.SaveOutlined,{}),tooltip:b("save"),disabled:!i||X,loading:a,onClick:o}),e.jsx(Ne,{icon:e.jsx(H.CopyOutlined,{}),tooltip:b("duplicate"),disabled:i||a||c===void 0||m||O,loading:m,onClick:q}),e.jsx(Ne,{icon:e.jsx(H.DeleteOutlined,{}),tooltip:b("delete"),disabled:a||c===void 0||y||m||O,loading:y,onClick:W}),ft(),e.jsx(Ne,{icon:e.jsx(H.InfoCircleOutlined,{}),tooltip:b("showLogs"),disabled:a||c===void 0||y||m||O,loading:!1,onClick:()=>{Nn(g,c,b)}}),e.jsx(Ne,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:b("refresh"),disabled:a||c===void 0||y||m||O,loading:!1,onClick:()=>{A(()=>{S.current.fetchValues()})}}),ft(),e.jsx(lr,{currentView:n,previousView:k,availableViews:r,onChangeView:N=>{L==null||L(n),V==null||V(!1),s==null||s(N)},disabled:X,formHasChanges:i}),ft(),e.jsxs(p.Space,{children:[e.jsx(Ne,{icon:e.jsx(H.LeftOutlined,{}),tooltip:b("previous"),disabled:X,loading:!1,onClick:()=>{M($)}}),e.jsx(Ne,{icon:e.jsx(H.RightOutlined,{}),tooltip:b("next"),disabled:X,loading:!1,onClick:()=>{M(B)}})]}),ft(),e.jsx(ut,{icon:e.jsx(H.ThunderboltOutlined,{}),disabled:X,tooltip:b("actions"),items:t==null?void 0:t.action,onItemClick:async N=>{!N||!(await ht({onFormSave:o})).succeed||j(N)}}),e.jsx(ut,{icon:e.jsx(H.PrinterOutlined,{}),disabled:X,tooltip:b("reports"),items:t==null?void 0:t.print,onItemClick:async N=>{if(!N)return;const K=await ht({onFormSave:o});!K.succeed||j({...N,datas:{...N.datas||{},ids:[K.currentId]}})}}),e.jsx(ut,{icon:e.jsx(H.EnterOutlined,{}),disabled:X,tooltip:b("related"),items:t==null?void 0:t.relate,onItemClick:async N=>{!N||!(await ht({onFormSave:o})).succeed||F({relateData:N,values:S.current.getValues(),fields:S.current.getFields(),action_id:N.id,action_type:N.type})}}),e.jsx(bl,{disabled:X,attachments:D,onAddNewAttachment:async()=>{const N=await ht({onFormSave:o});if(!N.succeed)return;const K=N.currentId,Z=g;E({model:"ir.attachment",values:{selection_associated_object:`${Z},${K}`},forced_values:{res_model:Z,res_id:K},initialViewType:"form"})},onListAllAttachments:async()=>{const N=await ht({onFormSave:o});if(!N.succeed)return;const K=N.currentId;E({model:"ir.attachment",domain:[["res_model","=",`${g}`],["res_id","=",`${K}`]],initialViewType:"tree"})},onViewAttachmentDetails:async N=>{!(await ht({onFormSave:o})).succeed||E({model:"ir.attachment",res_id:N.id,initialViewType:"form"})}})]}):null}function ft(){return e.jsx("div",{className:"inline-block w-2"})}async function ht({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:xl}=p.theme,Bn=t=>{const{ooui:r,value:n,onChange:s,valueValidator:o,linkPrefix:i=""}=t,{id:a,readOnly:c,required:f}=r,{token:d}=xl(),h=f&&!c?{backgroundColor:d.colorPrimaryBg}:void 0,u=l.useContext(ke),{elementHasLostFocus:g}=u||{},[C,y]=l.useState(!1),[m,w]=l.useState(!1);l.useEffect(()=>{c&&!C&&w(!1),!n&&!c&&(y(!0),w(!0))},[C,c]);const v=O=>{s==null||s(O.target.value)};return e.jsxs(p.Row,{gutter:8,wrap:!1,align:"middle",children:[c?null:e.jsx(p.Col,{flex:"32px",children:C?e.jsx(p.Button,{icon:e.jsx(H.CheckOutlined,{}),onClick:()=>{o(n)&&(y(!1),w(!1))},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1}):e.jsx(p.Button,{icon:e.jsx(H.EditOutlined,{}),onClick:()=>{y(!0),w(!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,...h},id:a,onChange:v,value:n,onBlur:()=>{o(n)&&(y(!1),w(!1),g==null||g())}}):e.jsx("a",{href:`${i}${n}`,style:{color:d.colorPrimary,paddingRight:15},target:"_blank",children:n})})]})},Hn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(Bn,{ooui:r,valueValidator:s=>s?vo.default(s):!1})})},Kn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(Bn,{ooui:r,linkPrefix:"mailto:",valueValidator:s=>s?Co.default(s):!1})})},Tl=t=>{const{visible:r,onIdSubmitted:n,onCancel:s,isSearching:o}=t,{t:i}=l.useContext(ge);function a(c){n(c.id)}return e.jsx(p.Modal,{title:i("goToResourceId"),centered:!0,open:r,footer:null,destroyOnClose:!0,onCancel:s,maskClosable:!1,children:e.jsxs(p.Form,{layout:"vertical",onFinish:a,autoComplete:"off",children:[e.jsx(p.Form.Item,{name:"id",label:i("searchId"),rules:[{required:!0,type:"number"}],children:e.jsx(p.InputNumber,{style:{width:"100%"},autoFocus:!0})}),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:Fl}=p.theme;function Yn(t){const{badgeNumber:r=0,...n}=t,{token:s}=Fl();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(Le,{...n,style:{width:46,zIndex:0}})]})}function Ol({refreshGraph:t}){const{t:r}=l.useContext(ge),{availableViews:n,currentView:s,setCurrentView:o,searchParams:i,searchVisible:a,setSearchVisible:c,graphIsLoading:f,previousView:d,setPreviousView:h}=l.useContext(He);return e.jsxs(p.Space,{wrap:!0,children:[e.jsx(Yn,{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:f,badgeNumber:i==null?void 0:i.length}),e.jsx(Ne,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:r("refresh"),disabled:f,loading:!1,onClick:()=>{t()}}),e.jsx(lr,{currentView:s,availableViews:n,onChangeView:u=>{h==null||h(s),o==null||o(u)},disabled:!1,previousView:d})]})}const{useToken:_l}=p.theme,{Title:Dl,Text:At}=p.Typography;function Lt(t){const{title:r,children:n}=t,{title:s,currentView:o,currentId:i,currentItemIndex:a,results:c,totalItems:f,selectedRowItems:d}=l.useContext(He),{t:h}=l.useContext(ge),{token:u}=_l();function g(){if((o==null?void 0:o.type)==="form")return i?f===0?e.jsxs(e.Fragment,{children:[h("editingDocument")," (id:"," ",e.jsx(At,{copyable:{icon:e.jsx(H.CopyOutlined,{style:{color:"red"}})},children:i}),")"]}):e.jsxs(e.Fragment,{children:[h("register")," ",a===void 0?1:a+1," /"," ",c.length," ",h("of")," ",f," - ",h("editingDocument")," (id:"," ",e.jsx(At,{copyable:!0,children:i}),")"]}):"";if((o==null?void 0:o.type)==="tree"&&d){if(d.length===1)return e.jsxs(e.Fragment,{children:["1 ",h("selectedRegisters")," - (id:"," ",e.jsx(At,{copyable:!0,children:d[0].id}),")"]});if(d.length>1)return e.jsxs(e.Fragment,{children:[d.length," ",h("selectedRegisters"),e.jsx(At,{copyable:{text:d.map(C=>C.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:u.borderRadius,backgroundColor:u.colorPrimaryBg},align:"middle",children:[e.jsxs(p.Col,{flex:2,children:[e.jsx(Dl,{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 kl=t=>{const{viewData:r,visible:n,model:s,context:o,domain:i,formView:a,treeView:c}=t,f=l.useRef(),d=l.useContext(He),{setResults:h=void 0,setCurrentItemIndex:u=void 0,currentId:g=void 0,results:C=void 0,setSelectedRowItems:y=void 0,setSearchParams:m=void 0,searchVisible:w=!0,setSearchVisible:v=void 0,sorter:O=void 0,setSorter:D=void 0,setTotalItems:S=void 0,setSearchTreeNameSearch:V=void 0,setTreeIsLoading:k=void 0,limit:L,setLimit:x,searchParams:b,searchValues:_,setSearchValues:T,currentView:P}=d||{},[I,F]=l.useState(!0);l.useEffect(()=>{var W;(W=f.current)==null||W.refresh()},[b]),l.useEffect(()=>{r.view_id!==P.view_id&&F(!0)},[P]);const{clear:E,searchFilterLoading:A,searchError:M,offset:B,tableRefreshing:$}=Zr({model:s,setSearchTreeNameSearch:V,setSelectedRowItems:y,searchParams:b,setSearchValues:T,setSearchParams:m,setSearchVisible:v,setTreeIsLoading:k,context:o,formView:a,treeView:c,sorter:O,setSorter:D,setCurrentItemIndex:u,setResultsActionView:h,resultsActionView:C,domain:i,currentId:g,setActionViewTotalItems:S,limit:L,setLimit:x});return!n||!r?null:e.jsxs(e.Fragment,{children:[e.jsx(Lt,{title:r.name,children:e.jsx(Ol,{refreshGraph:()=>{f.current.refresh()}})}),e.jsx(Qt,{fields:{...c.fields,...a.fields},searchFields:Wr([a.search_fields,c.search_fields]),formXml:a.arch,limit:L,onClear:E,offset:B,isSearching:A,onSubmit:W=>{F(!1),m==null||m(W.params),v==null||v(!1)},searchError:M,searchVisible:w,searchValues:_,showLimitOptions:!1}),$?e.jsx(p.Spin,{}):e.jsx($t,{ref:f,view_id:r.view_id,model:s,context:o,domain:Dt(b||[],i),limit:I?L:void 0,manualIds:I?C==null?void 0:C.map(W=>W.id):void 0})]})},Ml=t=>{const{visible:r,formRef:n,model:s,currentId:o,domain:i,formView:a,context:c,defaultValues:f,forcedValues:d,results:h,setResults:u,setCurrentItemIndex:g}=t;return r?e.jsxs(e.Fragment,{children:[e.jsx(Lt,{children:e.jsx(Pn,{toolbar:a==null?void 0:a.toolbar})}),e.jsx(ct,{rootForm:!0,ref:n,model:s,defaultValues:f,forcedValues:d,formView:a,actionDomain:i,id:o,parentContext:c,onSubmitSucceed:(C,y)=>{h.findIndex(w=>w.id===C)===-1&&(h.push(y),u(h),g(h.length-1))}})]}):null};function Vl(t){const{onSearch:r,disabled:n=!1,searchText:s}=t,{t:o}=l.useContext(ge),[i]=p.Form.useForm(),[a,c]=l.useState(!1);function f(h){r(h.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:f,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:h=>{c(h.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 Wn=Be.default.createContext({previewFeatures:!1});function El(t){var X;const{availableViews:r,currentView:n,setCurrentView:s,selectedRowItems:o,setRemovingItem:i,removingItem:a,duplicatingItem:c,setDuplicatingItem:f,currentModel:d,searchTreeRef:h,setCurrentId:u,setCurrentItemIndex:g,searchParams:C,searchVisible:y,setSearchVisible:m,setSearchTreeNameSearch:w,searchTreeNameSearch:v,treeIsLoading:O,setPreviousView:D,previousView:S,results:V,limit:k,totalItems:L}=l.useContext(He),{parentContext:x={},treeExpandable:b,toolbar:_}=t,{previewFeatures:T}=l.useContext(Wn),{t:P,lang:I}=l.useContext(ge),F=l.useContext(lt),{processAction:E}=F||{},[A,M]=l.useState(!1),B=v!==void 0&&v.trim().length>0;function $(){rt({confirmMessage:P("confirmRemove"),lang:I,onOk:()=>{W()}})}async function W(){var j;try{i==null||i(!0),await Y.getHandler().delete({model:d,ids:o.map(N=>N.id)}),u==null||u(void 0),g==null||g(void 0),(j=h==null?void 0:h.current)==null||j.refreshResults()}catch(N){Ae(N)}finally{i==null||i(!1)}}async function J(){var j;try{f==null||f(!0);const N=o[0].id;await Y.getHandler().duplicate({id:N,model:d,context:{...x}})&&((j=h==null?void 0:h.current)==null||j.refreshResults())}catch(N){Ae(N)}finally{f==null||f(!1)}}function q(j){E==null||E({actionData:j,values:{active_id:o==null?void 0:o.map(N=>N.id)[0],active_ids:o==null?void 0:o.map(N=>N.id)},fields:{},context:{...x,active_id:o==null?void 0:o.map(N=>N.id)[0],active_ids:o==null?void 0:o.map(N=>N.id)},onRefreshParentValues:()=>{var N;(N=h==null?void 0:h.current)==null||N.refreshResults()}})}return e.jsxs(p.Space,{wrap:!0,children:[b?null:e.jsxs(e.Fragment,{children:[e.jsx(Vl,{disabled:c||a||O,searchText:v,onSearch:j=>{j&&j.trim().length>0?w==null||w(j):w==null||w(void 0)}}),!b&&e.jsx(Yn,{icon:e.jsx(H.FilterOutlined,{style:{color:y?"white":void 0}}),tooltip:P("advanced_search"),type:y?"primary":"default",onClick:()=>{m==null||m(!y)},disabled:c||a||O,badgeNumber:C==null?void 0:C.length}),bt(),e.jsx(Ln,{disabled:O}),e.jsx(Ne,{icon:e.jsx(H.CopyOutlined,{}),tooltip:P("duplicate"),disabled:!o||(o==null?void 0:o.length)!==1||c||O,loading:c,onClick:J}),e.jsx(Ne,{icon:e.jsx(H.DeleteOutlined,{}),tooltip:P("delete"),disabled:!(o&&(o==null?void 0:o.length)>0)||O,loading:a,onClick:$}),bt()]}),e.jsx(Ne,{icon:e.jsx(H.InfoCircleOutlined,{}),tooltip:P("showLogs"),disabled:!(o&&(o==null?void 0:o.length)>0)||O,loading:!1,onClick:()=>{Nn(d,o[0].id,P)}}),e.jsx(Ne,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:P("refresh"),disabled:c||a||O,loading:!1,onClick:()=>{var j;(j=h==null?void 0:h.current)==null||j.refreshResults()}}),!b&&e.jsxs(e.Fragment,{children:[bt(),e.jsx(lr,{currentView:n,availableViews:r,onChangeView:j=>{D==null||D(n),s==null||s(j)},previousView:S,disabled:O})]}),bt(),e.jsx(ut,{icon:e.jsx(H.ThunderboltOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||O,tooltip:P("actions"),items:_==null?void 0:_.action,onItemClick:j=>{!j||q(j)}}),e.jsx(ut,{icon:e.jsx(H.PrinterOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||O,tooltip:P("reports"),items:_==null?void 0:_.print,onItemClick:j=>{!j||q({...j,datas:{...j.datas||{},ids:o.map(N=>N.id)}})}}),T&&e.jsxs(e.Fragment,{children:[bt(),e.jsx(ut,{icon:e.jsx(vr.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:P("export"),items:[{id:"print_screen",name:P("printScreen")},{id:"export",name:P("advancedExport")}],onItemClick:j=>{if(j.id==="print_screen"){let N=(o==null?void 0:o.map(K=>K.id))||[];N.length===0&&(N=(V==null?void 0:V.map(K=>K.id))||[]),q({id:-1,model:d,report_name:"printscreen.list",type:"ir.actions.report.xml",datas:{model:d,ids:N}});return}M(!0)},disabled:c||a||O||B}),e.jsx(Dn,{visible:A,locale:I,onClose:()=>M(!1),model:d,domain:Dt(((X=h==null?void 0:h.current)==null?void 0:X.getDomain())||[],C||[]),limit:k,totalRegisters:L||0,selectedRegistersToExport:o,visibleRegisters:(V==null?void 0:V.length)||0,context:x})]})]})}function bt(){return e.jsx("div",{className:"inline-block w-2"})}const Il=t=>{const{visible:r,searchTreeRef:n,model:s,context:o,formView:i,treeView:a,domain:c,setCurrentItemIndex:f,results:d,setCurrentId:h,setCurrentView:u,availableViews:g,searchTreeNameSearch:C}=t,{currentView:y,setPreviousView:m}=l.useContext(He);return r?e.jsxs(e.Fragment,{children:[e.jsx(Lt,{children:e.jsx(El,{toolbar:a==null?void 0:a.toolbar,parentContext:o,treeExpandable:(a==null?void 0:a.isExpandable)||!1})}),e.jsx(er,{ref:n,rootTree:!0,model:s,parentContext:o,nameSearch:C,formView:i,treeView:a,domain:c,onRowClicked:w=>{const{id:v}=w;h(v);const O=d.findIndex(S=>S.id===v);m==null||m(y),f(O);const D=g.find(S=>S.type==="form");u(D)}})]}):null},cr=Be.default.createContext(null),$l=t=>{const[r,n]=l.useState(!1),[s,o]=l.useState(!1),{children:i,dashboardRef:a,openAction:c}=t;return e.jsx(cr.Provider,{value:{isLoading:r,setIsLoading:n,dashboardRef:a,openAction:c,moveItemsEnabled:s,setMoveItemsEnabled:o},children:i})};function Al(){const{isLoading:t,dashboardRef:r,moveItemsEnabled:n,setMoveItemsEnabled:s}=l.useContext(cr),{t:o}=l.useContext(ge);return e.jsxs(p.Space,{wrap:!0,children:[e.jsx(Ne,{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)}}),Ll(),e.jsx(Ne,{icon:e.jsx(H.SettingOutlined,{}),tooltip:o("configDashboard"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.configDashboard()}}),e.jsx(Ne,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:o("refresh"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.refresh()}})]})}function Ll(){return e.jsx("div",{className:"inline-block w-2"})}const Nl=t=>{const{dashboardData:r}=t,n=l.useRef(),s=l.useContext(Ge),{openShortcut:o}=s||{};return r?e.jsxs($l,{dashboardRef:n,openAction:i=>{o(i)},children:[e.jsx(Lt,{children:e.jsx(Al,{})}),e.jsx(jn,{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 Pl(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 Bl(t,r){const{domain:n,model:s,context:o,views:i,title:a,setCanWeClose:c,tabKey:f,initialView:d,formDefaultValues:h,formForcedValues:u={},res_id:g=!1,action_id:C,action_type:y,treeExpandable:m=!1,limit:w}=t,[v,O]=l.useState(),[D,S]=l.useState([]),[V,k]=l.useState(!0),L=g||void 0,[x,b]=l.useState(L),[_,T]=l.useState([]),[P,I]=l.useState(),[F,E]=l.useState([]),[A,M]=l.useState(),[B,$]=l.useState(0),[W,J]=l.useState(!1),[q,X]=l.useState(!1),[j,N]=l.useState(),{t:K}=l.useContext(ge),Z=l.useRef(),se=l.useRef(),ce=l.useContext(Ge),{setCurrentView:Q,setCurrentId:R,tabs:ue,activeKey:ve,openAction:Me,onRemoveTab:xe}=ce||{};go.useHotkeys("ctrl+g,command+g",te=>{te.preventDefault(),be()},[ve,ue,v,P,F]);function de(te){b(te),R==null||R(te)}function ae(te){O(te),Q==null||Q(te)}l.useImperativeHandle(r,()=>({canWeClose:De}));const we=async()=>{k(!0);const te=[],Te=[];for(const Ce of i){const[Fe,fe]=Ce;fe!=="dashboard"?Te.push({viewTuple:Ce,promise:Y.getHandler().getView({model:s,type:fe,id:Fe,context:o})}):Te.push({viewTuple:Ce})}const Ee=await Pl(Te);for(const Ce of Ee){if(!Ce)continue;const[,Fe]=Ce.viewTuple;let fe=Ce.info;switch(Fe){case"dashboard":{const qe=i.find(Je=>{const[,ee]=Je;return ee==="form"});let $e;qe&&($e={action_id:C,action_type:y,name:a,res_id:o.active_id,res_model:s,view_id:qe[0],view_type:qe[1]}),te.push({type:"dashboard",id:o.active_id,model:s,context:o,configAction:$e});break}case"form":{te.push({...fe,type:Fe});break}case"tree":{te.push({...fe,isExpandable:m,type:Fe});break}case"graph":{te.push({...fe,type:Fe});break}}}let ye;!d&&te.find(Ce=>Ce.type==="tree")?ye=te.find(Fe=>Fe.type==="tree"):d?ye=te.find(Fe=>d.id?Fe.type===d.type&&Fe.view_id===d.id:Fe.type===d.type):ye=te.find(Fe=>Fe.type==="form"),ye||(Ae(`Error determining the first view to show for model ${s}.
35
+ `,mn=Be.default.createContext(null),ka=({children:t,initialView:r})=>{const[n,s]=l.useState(r),[o,i]=l.useState(0),[a,c]=l.useState(!1);return e.jsx(mn.Provider,{value:{currentView:n,setCurrentView:s,itemIndex:o,setItemIndex:i,manualTriggerChange:a,setManualTriggerChange:c},children:t})},{getValueForOperator:yn}=oe.graphProcessor,Mt=.7,Vt=30,wn=t=>{const{model:r,domain:n,context:s,colorCondition:o,totalDomain:i,showPercent:a=!1,icon:c,suffix:f,field:d,operator:h,manualIds:u}=t,[g,C]=l.useState(!1),[y,m]=l.useState(),[w,v]=l.useState(),[O,D]=l.useState(),[S,V]=l.useState(0),[k,L]=l.useState(0),[x,b]=l.useState(),[_,T]=l.useState(),[P,I]=l.useState();l.useEffect(()=>{A()},[r,o]);async function F({domain:M,isTotal:B}){if(B)return await E({domain:M});if(d&&h){const $=u||await Y.getHandler().searchAllIds({params:M,model:r,context:s}),W=await Y.getHandler().readObjects({model:r,ids:$,fieldsToRetrieve:[d],context:s});return yn({values:W.map(J=>J[d]),operator:h})}else return u?u.length:await Y.getHandler().searchCount({model:r,params:M,context:s})}async function E({domain:M}){if(d&&h){const B=await Y.getHandler().searchAllIds({params:M,model:r,context:s}),$=await Y.getHandler().readObjects({model:r,ids:B,fieldsToRetrieve:[d],context:s});return yn({values:$.map(W=>W[d]),operator:h})}else return await Y.getHandler().searchCount({model:r,params:M,context:s})}async function A(){C(!0);let M,B;try{const $=await F({domain:n,isTotal:!1});if(m($),i){const W=await Y.getHandler().evalDomain({domain:i,values:{},context:s});M=await F({domain:W,isTotal:!0}),D(M)}if(M?(B=Math.round($/M*100*100)/100,v(B)):v(0),o){const W=await Y.getHandler().parseCondition({condition:o,values:{value:$,percent:B},context:s});b(W)}if(c)if(c.indexOf(":")!==-1){const W=await Y.getHandler().parseCondition({condition:c,values:{value:$,percent:B},context:s});T(W)}else T(c)}catch($){I(JSON.stringify($))}C(!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 B,$;V((B=M.bounds)==null?void 0:B.height),L(($=M.bounds)==null?void 0:$.width)},children:({measureRef:M})=>a?e.jsx(Va,{value:y,total:O,percent:w,measureRef:M,height:S,width:k,color:x,icon:_,suffix:f}):e.jsx(Ma,{value:y,total:O,measureRef:M,height:S,width:k,color:x,icon:_,suffix:f})})};function vn(t,r){const s=document.createElement("canvas").getContext("2d");return s.font=r||getComputedStyle(document.body).font,s.measureText(t).width}function Ma({measureRef:t,width:r,height:n,total:s,value:o,color:i,icon:a,suffix:c}){let f=n*Mt<Vt?Vt:n*Mt;const d=o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0});let h=s?`${d}/${s}`:`${d}`;c&&(h+=" "+c);let u=vn(h,`bold ${Math.floor(f*1.03)}px sans-serif`);a&&(u=u*2),u>=r*.85&&(f=r*.85/u*f);const g=a&&We(a);return e.jsx("div",{ref:t,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden"},children:e.jsxs(Wt.default,{style:{fontSize:f,margin:0,color:i},children:[g&&e.jsx(g,{style:{fontSize:f*.7}}),g?` ${h}`:h]})})}function Va({measureRef:t,height:r,width:n,percent:s,total:o,value:i,color:a,icon:c,suffix:f}){const d=r*.65;let h=d*Mt<Vt?Vt:d*Mt;const u=i==null?void 0:i.toLocaleString("es-ES",{useGrouping:!0});let g=o?`${u}/${o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0})}`:`${u}`;f&&(g+=" "+f);const C=`${s==null?void 0:s.toLocaleString("es-ES",{useGrouping:!0})}%`;let y=vn(C,`bold ${Math.floor(h*1.03)}px sans-serif`);c&&(y=y*1.5);const m=c&&We(c);return(y>=n*.85||h*2<d)&&(h=n*.85/y*h),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:h*1,color:a,paddingRight:"10px"},children:e.jsx(m,{})}),e.jsxs(p.Col,{children:[e.jsx(Wt.default,{style:{fontSize:h*.8,margin:0,color:a},children:m?` ${s}%`:`${s}%`}),e.jsx(Wt.default,{style:{fontSize:h*.4,margin:0,color:a,textAlign:"center"},children:g})]})]})})}const rr=t=>r=>{const n=r.value.toLocaleString("es-ES",{useGrouping:!0});return{name:t==="pie"?r.x:r.type,value:n}},Et=t=>{if(typeof t=="string"&&Ea(t))return parseFloat(t).toLocaleString("es-ES",{useGrouping:!0});if(Ia(t))return t.toLocaleString("es-ES",{useGrouping:!0});if($a(t)){const r=Aa(t);return r===null?t:je(t,It.input[r]).format(It.output[r])}else return t},Ea=t=>/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(t),Ia=t=>typeof t=="number"&&!isNaN(t),Cn={default:{padding:"auto",xAxis:{tickCount:5,label:{formatter:Et}},yAxis:{label:{formatter:Et}},legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:rr("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:rr("pie")},interactions:[{type:"element-active"}]},barGrouped:{isGroup:!0,legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:rr("barGrouped")},xAxis:{label:{formatter:Et}},yAxis:{label:{formatter:Et}},label:{position:"middle",layout:[{type:"interval-adjust-position"},{type:"interval-hide-overlap"},{type:"adjust-color"}]}}};function $a(t){return typeof t!="string"||t===void 0?!1:new Date(t).toString()!=="Invalid Date"}const It={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 Aa(t){for(const r in It.input)if(je(t,It.input[r],!0).isValid())return r;return null}const{processGraphData:La}=oe.graphProcessor,{getFieldsToRetrieve:Na}=oe.graphFieldUtils,Pa=t=>{const{model:r,domain:n=[],context:s={},xml:o,limit:i,uninformedString:a,manualIds:c}=t,[f,d]=l.useState(!1),[h,u]=l.useState(),[g,C]=l.useState(),[y,m]=l.useState(),[w,v]=l.useState("line");return Re.default(()=>{(async()=>{d(!0),u(void 0);const O=oe.parseGraph(o);v(O.type||"line");const D=Na({ooui:O});let S,V;try{({values:S,fields:V}=await Ha({model:r,domain:n,context:s,limit:i,order:O.timerange?O.x.name:null,fields:D,manualIds:c}))}catch(k){u("Error fetching graph data values: "+JSON.stringify(k)),d(!1);return}try{if(!S||!V){u("No values or fields returned"),d(!1);return}m(S);const k=La({ooui:O,values:S,fields:V,options:{uninformedString:a}});C(k)}catch(k){u("Error processing graph data: "+k),d(!1);return}d(!1)})()},[o,r,i,s,n]),{loading:f,error:h,type:w,values:g,evaluatedEntries:y}};async function Ba({model:t,context:r,fields:n}){return await Y.getHandler().getFields({model:t,context:r,fields:n})}async function Ha({fields:t,model:r,domain:n,context:s,order:o,limit:i,manualIds:a}){const c=await Ba({model:r,context:s,fields:t});if(a){let d=await Y.getHandler().readObjects({model:r,ids:a,fieldsToRetrieve:t,context:s});return o&&(d=[...d].sort((h,u)=>h[o]-u[o])),{values:d,fields:c}}return{values:await Y.getHandler().search({model:r,params:n,fields:t,context:s,limit:i,order:o}),fields:c}}const Ka={line:Kt.Line,bar:Kt.Column,pie:Kt.Pie},Ya=t=>{var v;const{model:r,domain:n,context:s,xml:o,limit:i,manualIds:a}=t,{t:c}=l.useContext(ge),{error:f,loading:d,values:h,type:u,evaluatedEntries:g}=Pa({model:r,xml:o,limit:i,domain:n,context:s,uninformedString:c("uninformed"),manualIds:a});if(f)return e.jsx(p.Alert,{message:f,type:"error",banner:!0});if(d)return e.jsx(p.Spin,{});if(!h)return e.jsx(p.Alert,{message:"No data to display",type:"info"});const{data:C,isGroup:y,isStack:m}=h,w=Ka[u];return w?e.jsxs("div",{style:{padding:"1rem"},children:[e.jsx("p",{style:{textAlign:"right"},children:`${c("totalRegisters")} ${(v=g==null?void 0:g.length)==null?void 0:v.toLocaleString("es-ES",{useGrouping:!0})}`}),e.jsx(w,{...Wa({type:u,data:C,isGroup:y,isStack:m})})]}):e.jsx(e.Fragment,{children:`Unknown graph type: ${u}`})};function Wa(t){const{type:r,data:n,isGroup:s,isStack:o}=t;let i=Cn[r];return i||(i=Cn.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 qa=(t,r)=>{const{view_id:n,model:s,context:o,domain:i,limit:a,manualIds:c}=t,[f,d]=l.useState(!1),[h,u]=l.useState(),[g,C]=l.useState(),y=l.useContext(He),{setGraphIsLoading:m=void 0}=y||{};l.useImperativeHandle(r,()=>({refresh:()=>{w()}})),l.useEffect(()=>{w()},[n]);async function w(){d(!0),m==null||m(!0);try{const v=await Y.getHandler().getView({model:s,id:n,type:"graph",context:o});C(v.arch);const O=oe.parseGraph(v.arch);u(O)}catch(v){return console.error(v),e.jsx(e.Fragment,{children:JSON.stringify(v)})}d(!1),m==null||m(!1)}if(f)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(!h)return null;switch(h.type){case"indicatorField":case"indicator":{const v=h,O=v.type==="indicatorField"?{field:v.field,operator:v.operator}:{};return e.jsx(wn,{showPercent:v.showPercent,totalDomain:v.totalDomain,colorCondition:v.color,model:s,context:o,domain:i,icon:v.icon,suffix:v.suffix,manualIds:c,...O})}case"line":case"bar":case"pie":return e.jsx(Ya,{model:s,context:o,domain:i,xml:g,limit:a,manualIds:c});default:return e.jsx(e.Fragment,{children:`Graph ${h.type} not implemented`})}},$t=l.forwardRef(qa),{confirm:Ga}=p.Modal,Ua=({onOk:t,lang:r})=>{Ga({title:Se("removeItems",r),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmRemove",r),okText:Se("yesConfirmRemove",r),onOk:t,cancelText:Se("cancel",r)})},{confirm:ja}=p.Modal,za=({onOk:t,lang:r})=>{ja({title:Se("unlinkItems",r),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmUnlink",r),okText:Se("yesConfirmUnlink",r),onOk:t,cancelText:Se("cancel",r)})},{useToken:Ja}=p.theme,Za=t=>{const{title:r,readOnly:n,onCreateItem:s,onToggleViewMode:o,mode:i,onDelete:a,totalItems:c,currentItemIndex:f,onPreviousItem:d,onNextItem:h,isMany2Many:u,onSearchItem:g,selectedRowKeys:C,showCreateButton:y,showToggleButton:m}=t,{token:w}=Ja();function v(){return e.jsx("div",{className:"inline-block w-3"})}function O(){return e.jsx("div",{className:"flex flex-grow h-8 text-white",style:{borderRadius:w.borderRadius,backgroundColor:w.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 D(){return e.jsx(Le,{tooltip:u?"Unlink":"Delete",icon:u?e.jsx(H.ApiOutlined,{}):e.jsx(H.DeleteOutlined,{}),onClick:a,disabled:c===0||n||i!=="form"&&C.length===0})}function S(){let k="_";return c===0?k="_":k=(f+1).toString(),e.jsxs("span",{className:"pl-1 pr-1",children:["(",k,"/",c,")"]})}function V(){return e.jsxs(e.Fragment,{children:[v(),e.jsx(Le,{tooltip:"Previous item",icon:e.jsx(H.LeftOutlined,{}),onClick:d}),S(),e.jsx(Le,{tooltip:"Next item",icon:e.jsx(H.RightOutlined,{}),onClick:h})]})}return e.jsxs("div",{className:"flex mb-2",children:[O(),e.jsxs("div",{className:"flex-none h-8 pl-2",children:[i!=="graph"&&y&&e.jsx(Le,{tooltip:"Create new item",icon:e.jsx(H.FileAddOutlined,{}),disabled:n,onClick:s}),u&&y&&e.jsx(Le,{tooltip:"Search existing item",icon:e.jsx(H.SearchOutlined,{}),disabled:n,onClick:g}),i!=="graph"&&v(),i!=="graph"&&D(),i==="form"&&V(),v(),m&&e.jsx(Le,{tooltip:"Toggle view mode",icon:e.jsx(H.AlignLeftOutlined,{}),onClick:o})]})]})},Xa={form:oe.Form,tree:oe.Tree,graph:$t};function Qa(t){const r=t.map(s=>s.id);return t.filter((s,o)=>{const{id:i}=s;return!r.includes(i,o+1)})}const Ra=t=>{var Je;const{value:r,onChange:n,ooui:s,views:o}=t,{items:i=[]}=r||{},{currentView:a,setCurrentView:c,itemIndex:f,setItemIndex:d}=l.useContext(mn),h=l.useContext(ke),{activeId:u,getFields:g,getValues:C,getContext:y,domain:m}=h||{},{lang:w,t:v}=l.useContext(ge),[O,D]=l.useState(!1),[S,V]=l.useState(!1),[k,L]=l.useState(),[x,b]=l.useState(!1),[_,T]=l.useState(!1),[P,I]=l.useState(),[F,E]=l.useState([]),[A,M]=l.useState(!1),B=l.useRef([]),[$,W]=l.useState(),J=l.useRef(),[q,X]=l.useState(void 0),{readOnly:j,relation:N,context:K,domain:Z}=s,se=s.type==="many2many",{id:ce}=s,Q=i.filter(ee=>(ee.values||ee.treeValues)&&ee.operation!=="pendingRemove"),R=l.useRef();l.useEffect(()=>{if(R.current!==a){R.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))&&Me()},[i,a]);l.useEffect(()=>{de()},[m]);const ve=ee=>{var le,Oe;n==null||n({fields:((le=o.get("form"))==null?void 0:le.fields)||((Oe=o.get("tree"))==null?void 0:Oe.fields),items:Qa(ee)})},Me=async()=>{await xe(),f>Q.length-1&&f!==0&&d(0)},xe=async ee=>{var le,Oe,he;V(!0),D(!1),L(void 0);try{const[pe,ie]=await zt({treeView:{arch:(le=o.get("tree"))==null?void 0:le.arch,fields:(Oe=o.get("tree"))==null?void 0:Oe.fields},formView:{fields:((he=o.get("form"))==null?void 0:he.fields)||{}},model:N,items:i,context:{...y==null?void 0:y(),...K},currentView:ee||a});return J.current||(J.current=pe.map(Pe=>Pe.id)),(a||ee)==="tree"&&ie&&X(ie),ve(pe),pe}catch(pe){L(pe)}finally{V(!1)}};async function de(){Z&&(B.current=await Y.getHandler().evalDomain({domain:Z,values:at({fields:g(),values:C()}),fields:g(),context:y()})),m&&m.length>0&&(B.current=B.current.concat(oe.transformDomainForChildWidget({domain:m,widgetFieldName:ce})))}const ae=()=>{const ee=Array.from(o.keys()),le=ee[(ee.indexOf(a)+1)%ee.length];a==="form"?Ve(()=>{c(le)}):c(le)},we=()=>{f>0&&(a==="form"?Ve(()=>{d(f-1)}):d(f-1))},De=()=>{const ee=Q.length;f<ee-1&&(a==="form"?Ve(()=>{d(f+1)}):d(f+1))},be=async()=>{const ee=Q[f].id,le=(await Y.getHandler().readObjects({model:N,ids:[ee],fields:o.get("form").fields,context:{...y==null?void 0:y(),...K}}))[0],Oe=(await Y.getHandler().readObjects({model:N,ids:[ee],fields:o.get("tree").fields,context:{...y==null?void 0:y(),...K}}))[0],he=i.map(pe=>pe.id===ee?{...pe,operation:"original",values:le,treeValues:Oe}:pe);ve(he)},Ve=ee=>{O?yt({lang:w,onOk:()=>{be(),ee(),D(!1)}}):ee()},Ke=()=>{if(se){za({lang:w,onOk:()=>{a==="form"?Te():Ee()}});return}Ua({lang:w,onOk:()=>{a==="form"?Te():Ee()}})},Ie=async()=>{const{inv_field:ee}=s;let le;ee&&u&&(le={[ee]:u}),a==="form"?Ve(()=>{M(!0),I({defaultValues:le}),b(!0)}):(M(!0),I({defaultValues:le}),b(!0))},te=async()=>{a==="form"?Ve(()=>{T(!0)}):T(!0)},Te=async()=>{V(!0),D(!1),L(void 0);try{if(Q[f].id>0){const ee=i.map(le=>le.id===Q[f].id?{...le,operation:"pendingRemove"}:le);ve(ee)}else ve(i.filter(ee=>ee.id!==Q[f].id))}catch(ee){L(ee)}d(0),V(!1)},Ee=async()=>{const ee=Q.filter(le=>F.includes(le.id));V(!0),D(!1),L(void 0);try{const le=ee.map(he=>he.id),Oe=i.filter(he=>!(le.includes(he.id)&&he.id<0)).map(he=>le.includes(he.id)?{...he,operation:"pendingRemove"}:he);ve(Oe)}catch(le){L(le)}d(0),V(!1)},ye=(ee,le,Oe)=>{let he;if(ee)he=i.map(pe=>pe.id===ee?{id:ee,operation:ee>0?"pendingUpdate":"pendingCreate",values:{...Oe,id:ee},treeValues:{...Oe,id:ee}}:pe);else{const pe=Qs(i);he=i.concat({id:pe,operation:"pendingCreate",values:{...Oe,id:pe},treeValues:{...Oe,id:pe}})}ve(he),A||b(!1)},Ce=async ee=>{const{id:le}=ee;let Oe=i;const he=i.find(pe=>pe.id===le);(he==null?void 0:he.values)===void 0&&(Oe=await xe("form")),I(Oe.find(pe=>pe.id===le)),M(!1),b(!0)},Fe=async ee=>{V(!0);let le=i;const Oe=ee.filter(he=>!i.find(pe=>pe.id===he));try{for(const he of Oe){const pe=(await Y.getHandler().readObjects({model:N,ids:[he],fields:o.get("form").fields,context:{...y==null?void 0:y(),...K}}))[0],ie=(await Y.getHandler().readObjects({model:N,ids:[he],fields:o.get("tree").fields,context:{...y==null?void 0:y(),...K}}))[0];le.push({id:he,operation:"pendingLink",values:pe,treeValues:ie})}ve(le)}catch(he){L(he)}finally{V(!1)}};function fe(){const ee=Xa[a];if(a==="graph")return oe.parseGraph(o.get("graph").arch).string;{const le=new ee(o.get(a).fields);return le.parse(o.get(a).arch),le.string}}const qe=()=>{var le,Oe,he,pe;if(a==="form")return Q.length===0?v("noCurrentEntries"):a!==R.current&&i.some(ie=>!ie.values)?e.jsx(p.Spin,{}):e.jsx(ct,{formView:o.get("form"),values:(le=Q[f])==null?void 0:le.values,parentContext:{...y==null?void 0:y(),...K},model:N,id:(Oe=Q[f])==null?void 0:Oe.id,submitMode:"values",onFieldsChange:ie=>{var xt;const Pe=(xt=Q[f])==null?void 0:xt.id,Ze=i.map(Qe=>Qe.id===Pe?{...Qe,operation:Qe.operation==="original"?"pendingUpdate":Qe.operation,values:{...ie,id:Pe},treeValues:{...ie,id:Pe}}:Qe);ve(Ze),D(!0)},readOnly:j});let ee=[];if(Q.some(ie=>ie.treeValues)&&(ee=$?st({resultsToSort:Q.map(ie=>ie.treeValues),sorter:$,fields:{...o.get("tree").fields,...((he=o.get("form"))==null?void 0:he.fields)||{}}}):Q.map(ie=>ie.treeValues)),a==="tree")return e.jsx(Ct,{total:Q.length,limit:Q.length,treeView:o.get("tree"),results:ee,loading:S,onRowClicked:((pe=o.get("form"))==null?void 0:pe.fields)!==void 0?Ce:void 0,showPagination:!1,rowSelection:{selectedRowKeys:F,onChange:E},sorter:$,onChangeSort:W,context:{...y==null?void 0:y(),...K},colorsForResults:q,readonly:j});if(a==="graph"){const ie=[[`${s.inv_field}`,"=",u]];return e.jsx($t,{view_id:o.get("graph").view_id,model:s.relation,domain:ie,context:{...y==null?void 0:y(),...K},limit:0})}};if(k)return e.jsx(p.Alert,{className:"mt-10",message:k,type:"error",banner:!0});const $e=A;return S?e.jsx(p.Spin,{}):e.jsxs(e.Fragment,{children:[e.jsx(Za,{mode:a,title:fe(),readOnly:j,isMany2Many:se,formHasChanges:O,totalItems:Q.length,currentItemIndex:f,onDelete:Ke,onCreateItem:Ie,onToggleViewMode:ae,onPreviousItem:we,onNextItem:De,onSearchItem:te,selectedRowKeys:F,showCreateButton:((Je=o.get("form"))==null?void 0:Je.fields)!==void 0,showToggleButton:o.size>1}),qe(),e.jsx(dt,{formView:o.get("form"),model:N,id:P==null?void 0:P.id,submitMode:"values",values:P==null?void 0:P.values,defaultValues:P==null?void 0:P.defaultValues,visible:x,onSubmitSucceed:ye,parentContext:{...y==null?void 0:y(),...K},onCancel:()=>{M(!1),b(!1)},readOnly:j,mustClearAfterSave:$e}),e.jsx(tr,{domain:B.current,model:N,context:{...y==null?void 0:y(),...K},visible:_,onSelectValues:async ee=>{T(!1),Fe(ee)},onCloseModal:()=>{T(!1)}})]})},Sn=t=>{const{ooui:r}=t,{mode:n,relation:s,views:o,required:i,context:a}=r;let c;const[f,d]=l.useState(!0),[h,u]=l.useState(),[g,C]=l.useState(new Map),y=l.useContext(ke),{getContext:m}=y||{};Re.default(()=>{v()},[r]);const w=async D=>o&&o[D]?o[D]:await Y.getHandler().getView({model:s,type:D,context:{...m==null?void 0:m(),...a}}),v=async()=>{d(!0),u(void 0);try{if(n&&n.length>0){for(const D of n){const S=await w(D);g.set(D,S)}C(g)}else{const D=await w("form"),S=await w("tree");g.set("form",D),g.set("tree",S),C(g)}}catch(D){u(JSON.stringify(D))}finally{d(!1)}};if(n&&n.length>0?c=n[0]:c="tree",f)return e.jsx(p.Spin,{});if(h)return e.jsx(p.Alert,{className:"mt-10",message:h,type:"error",banner:!0});const O=async(D,S)=>{if(!S)throw new Error;if(!S.items)throw new Error;if(!Array.isArray(S.items))throw new Error;if(S.items.length===0)throw new Error};return e.jsx(ka,{initialView:c,children:e.jsx(me,{required:i,type:"array",validator:O,...t,children:e.jsx(Ra,{ooui:r,views:g})})})},{useToken:el}=p.theme,bn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"number",...t,children:e.jsx(tl,{ooui:r})})},tl=t=>{const{ooui:r,value:n,onChange:s}=t,{id:o,readOnly:i,required:a}=r,{token:c}=el(),f=a&&!i?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useRef(),[h,u]=l.useState(),g=l.useContext(ke),{elementHasLostFocus:C}=g||{};l.useEffect(()=>{u(en(n))},[n]);const y=v=>{s==null||s(v)};function m(v){d.current=v.target.value,u(v.target.value)}async function w(){y(na(h)),await new Promise(v=>setTimeout(v,300)),C==null||C()}return e.jsx(p.Input,{value:h,disabled:i,className:"w-full",style:f,id:o,placeholder:"00:00",onChange:m,onBlur:w})};function nr(t){const{ooui:r,showLabel:n=!0,responsiveBehaviour:s}=t,o=We(r.icon||"");return e.jsx(e.Fragment,{children:(r.label||o)&&n?e.jsx(pr.FieldSet,{label:r.label,icon:o,children:e.jsx(Zt,{container:r.container,responsiveBehaviour:s})}):e.jsx(Zt,{container:r.container,responsiveBehaviour:s})})}const{TabPane:rl}=p.Tabs;function xn(t){const{ooui:r,responsiveBehaviour:n}=t,s=r.pages;function o(i){if(i){const a=We(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(rl,{tab:e.jsxs(e.Fragment,{children:[o(i.icon)," ",i.label]}),children:e.jsx(nr,{ooui:i,showLabel:!1,responsiveBehaviour:n})},i.label))})}const{useToken:nl}=p.theme,{TextArea:or}=p.Input,Tn=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o,height:i,translatable:a}=r,{token:c}=nl(),f=o&&!s?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useContext(ke),{elementHasLostFocus:h}=d||{};return e.jsx(me,{required:o,...t,children:a?e.jsx(ol,{field:n,height:i,requiredStyle:f}):e.jsx(or,{disabled:s||a,style:{minHeight:i?i+"px":"100%",...f},rows:4,onBlur:h})})},ol=({value:t,field:r,requiredStyle:n,onChange:s,height:o})=>{const i=l.useContext(ke),{activeId:a,activeModel:c,fetchValues:f,formHasChanges:d,elementHasLostFocus:h}=i||{},[u,g]=l.useState(!1),{t:C}=l.useContext(ge);return a?e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>{if(d!=null&&d()){Ue(C("saveBeforeTranslate"));return}u||g(!0)},children:e.jsx(or,{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:h})}),e.jsx(Or,{id:a,model:c,field:r,visible:u,onCloseModal:()=>{g(!1)},onSubmitSucceed:()=>{g(!1),f==null||f()}})]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Row,{gutter:8,wrap:!1,children:e.jsx(or,{value:t,onChange:y=>{s==null||s(y.target.value)},style:{height:o?o+"px":"100%",...n},id:r,rows:4,onBlur:h})}),e.jsx(p.Row,{justify:"end",style:{paddingTop:5},children:e.jsx(Le,{tooltip:C("translate"),icon:e.jsx(H.TranslationOutlined,{}),onClick:async()=>{d!=null&&d()?Ue(C("saveBeforeTranslate")):Ue(C("enterTextBeforeTranslate"))},children:C("translate")})})]})},Fn=t=>{const{ooui:r}=t,{label:n,icon:s}=r,o=We(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({}),f=l.useRef(new Map),d=l.useCallback(async w=>{if(w.selectedKeys===void 0||w.selectedKeys.length===0){Ue(Se("selectAtLeastOneField",n));return}let v=o;w.registersAmount==="selected"&&(s==null?void 0:s.length)!==0&&(v=[["id","in",s==null?void 0:s.map(S=>S.id)]]);const{datas:O}=await Y.getHandler().exportData({model:t,fields:ul({keys:w.selectedKeys,fields:c.current}),domain:v,limit:w.registersAmount==="all"?0:i,context:r,format:w.exportType});a(),await new Promise(S=>setTimeout(S,200));const D=await nt(O);Ft(O,D.mime)},[n,t,o,i,r,a]),h=l.useCallback(async()=>{const w=await Y.getHandler().getFields({model:t,context:r,fields:[]});return c.current["/"]=w,On({fields:w})},[t,r,c]),u=l.useCallback(async w=>{const O=ir(w,c.current)[sr(w)],D=O.relation,S=await Y.getHandler().getFields({model:D,context:r,fields:[]});for(const[V,k]of Object.entries(S))S[V].string=al({parentTitle:O.string,title:k.string});return c.current[w]=S,On({fields:S,parentKey:w})},[c.current,t,r]),g=l.useCallback(async()=>{const w=await ll({model:t,context:r}),v=await dl({predefinedExports:w,fields:c.current,onGetFieldChilds:u});return{predefinedExports:w.map(D=>({...D,fields:D.fields.map(S=>{const V=sr(S.key),L=ir(S.key,c.current)[V];return{key:S.key,title:L.string}})})),keysWithChilds:v}},[c.current]),C=l.useCallback(async w=>{const v=await m("ir.exports"),O=await m("ir.exports.line"),D=await Y.getHandler().create({model:"ir.exports",values:{name:w.name,resource:t},fields:v,context:r});return await Promise.all(w.fields.map(async S=>await Y.getHandler().create({model:"ir.exports.line",values:{name:S.key,export_id:D},fields:O,context:r}))),{...w,id:D}},[]),y=l.useCallback(async w=>{await Y.getHandler().delete({model:"ir.exports",ids:[w.id]})},[]),m=l.useCallback(async w=>{if(f.current.has(w))return f.current.get(w);const v=Y.getHandler().getFields({model:w,context:r,fields:[]});f.current.set(w,v)},[f,r]);return{onGetFields:h,onGetFieldChilds:u,onExport:d,onGetPredefinedExports:g,onSavePredefinedExport:C,onRemovePredefinedExport:y}},On=({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=_n(o);n.push({key:il({key:s,parentKey:r}),title:o.string,tooltip:o.help,required:o.required,isLeaf:!i})}return n},_n=t=>t.type==="many2one"||t.type==="one2many"||t.type==="many2many",il=({parentKey:t,key:r})=>`${t?t+"/":""}${r}`,St=t=>t.indexOf("/")===-1?t:t.split("/").slice(0,-1).join("/"),sr=t=>{if(t.indexOf("/")===-1)return t;const r=t.split("/");return r[r.length-1]},ir=(t,r)=>t.indexOf("/")===-1?r["/"]:r[St(t)],al=({title:t,parentTitle:r})=>`${r?r+" \u2192 ":""}${t}`,ll=async({model:t,context:r})=>{const n=await Y.getHandler().search({model:"ir.exports",params:[["resource","=",t]],context:r}),s=n.flatMap(i=>i.export_fields),o=await Y.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(f=>f.id===a).name}))}))},cl=({fields:t,keys:r})=>fl([...new Set(r.filter(n=>{var s,o,i;if(n.indexOf("/")===-1)return!((s=t["/"])!=null&&s[n]);{const a=St(n);console.log({key:n,parentKey:a,fields:t});const c=(o=t==null?void 0:t[St(n)])==null?void 0:o[n];return console.log({exists:c}),!((i=t==null?void 0:t[St(n)])!=null&&i[n])}}).map(n=>St(n)))]),dl=async({predefinedExports:t,fields:r,onGetFieldChilds:n})=>{const s=t.flatMap(a=>a.fields.map(c=>c.key)),o=cl({fields:r,keys:s}),i=[];for(const a of o)i.push({key:a,childs:await n(a)});return i},ul=({keys:t,fields:r})=>t.map(n=>{const s=sr(n),i=ir(n,r)[s];return _n(i)?`${n}/id`:n}),fl=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},Dn=t=>{const{visible:r,locale:n,onClose:s,model:o,context:i,selectedRegistersToExport:a,totalRegisters:c,domain:f,limit:d,visibleRegisters:h}=t,{onExport:u,onGetFieldChilds:g,onGetFields:C,onGetPredefinedExports:y,onSavePredefinedExport:m,onRemovePredefinedExport:w}=sl({model:o,context:i,domain:f,limit:d,selectedRegistersToExport:a,onClose:s,locale:n});return e.jsx(pr.ExportModal,{visible:r,locale:n,onSucceed:u,onCancel:s,selectedRegistersToExport:a&&a.length&&a.length>0?a.length:void 0,totalRegisters:c,onGetFieldChilds:g,onGetFields:C,visibleRegisters:h,onGetPredefinedExports:y,onSavePredefinedExport:m,onRemovePredefinedExport:w})},kn=t=>{const{ooui:r}=t;return e.jsx(dn,{ooui:r})},Mn=t=>{const{ooui:r}=t;return e.jsx(dn,{ooui:r,showTime:!0})};var Vn={exports:{}};(function(t,r){(function(n,s){t.exports=s()})(Xe,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={},f=function(m){return(m=+m)+(m>68?1900:2e3)},d=function(m){return function(w){this[m]=+w}},h=[/[+-]\d\d:?(\d\d)?|Z/,function(m){(this.zone||(this.zone={})).offset=function(w){if(!w||w==="Z")return 0;var v=w.match(/([+-]|\d\d)/g),O=60*v[1]+(+v[2]||0);return O===0?0:v[0]==="+"?-O:O}(m)}],u=function(m){var w=c[m];return w&&(w.indexOf?w:w.s.concat(w.f))},g=function(m,w){var v,O=c.meridiem;if(O){for(var D=1;D<=24;D+=1)if(m.indexOf(O(D,0,w))>-1){v=D>12;break}}else v=m===(w?"pm":"PM");return v},C={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 w=c.ordinal,v=m.match(/\d+/);if(this.day=v[0],w)for(var O=1;O<=31;O+=1)w(O).replace(/\[|\]/g,"")===m&&(this.day=O)}],M:[i,d("month")],MM:[o,d("month")],MMM:[a,function(m){var w=u("months"),v=(u("monthsShort")||w.map(function(O){return O.slice(0,3)})).indexOf(m)+1;if(v<1)throw new Error;this.month=v%12||v}],MMMM:[a,function(m){var w=u("months").indexOf(m)+1;if(w<1)throw new Error;this.month=w%12||w}],Y:[/[+-]?\d+/,d("year")],YY:[o,function(m){this.year=f(m)}],YYYY:[/\d{4}/,d("year")],Z:h,ZZ:h};function y(m){var w,v;w=m,v=c&&c.formats;for(var O=(m=w.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(b,_,T){var P=T&&T.toUpperCase();return _||v[T]||n[T]||v[P].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(I,F,E){return F||E.slice(1)})})).match(s),D=O.length,S=0;S<D;S+=1){var V=O[S],k=C[V],L=k&&k[0],x=k&&k[1];O[S]=x?{regex:L,parser:x}:V.replace(/^\[|\]$/g,"")}return function(b){for(var _={},T=0,P=0;T<D;T+=1){var I=O[T];if(typeof I=="string")P+=I.length;else{var F=I.regex,E=I.parser,A=b.slice(P),M=F.exec(A)[0];E.call(_,M),b=b.replace(M,"")}}return function(B){var $=B.afternoon;if($!==void 0){var W=B.hours;$?W<12&&(B.hours+=12):W===12&&(B.hours=0),delete B.afternoon}}(_),_}}return function(m,w,v){v.p.customParseFormat=!0,m&&m.parseTwoDigitYear&&(f=m.parseTwoDigitYear);var O=w.prototype,D=O.parse;O.parse=function(S){var V=S.date,k=S.utc,L=S.args;this.$u=k;var x=L[1];if(typeof x=="string"){var b=L[2]===!0,_=L[3]===!0,T=b||_,P=L[2];_&&(P=L[2]),c=this.$locale(),!b&&P&&(c=v.Ls[P]),this.$d=function(A,M,B){try{if(["x","X"].indexOf(M)>-1)return new Date((M==="X"?1e3:1)*A);var $=y(M)(A),W=$.year,J=$.month,q=$.day,X=$.hours,j=$.minutes,N=$.seconds,K=$.milliseconds,Z=$.zone,se=new Date,ce=q||(W||J?1:se.getDate()),Q=W||se.getFullYear(),R=0;W&&!J||(R=J>0?J-1:se.getMonth());var ue=X||0,ve=j||0,Me=N||0,xe=K||0;return Z?new Date(Date.UTC(Q,R,ce,ue,ve,Me,xe+60*Z.offset*1e3)):B?new Date(Date.UTC(Q,R,ce,ue,ve,Me,xe)):new Date(Q,R,ce,ue,ve,Me,xe)}catch{return new Date("")}}(V,x,k),this.init(),P&&P!==!0&&(this.$L=this.locale(P).$L),T&&V!=this.format(x)&&(this.$d=new Date("")),c={}}else if(x instanceof Array)for(var I=x.length,F=1;F<=I;F+=1){L[1]=x[F-1];var E=v.apply(this,L);if(E.isValid()){this.$d=E.$d,this.$L=E.$L,this.init();break}F===I&&(this.$d=new Date(""))}else D.call(this,S)}}})})(Vn);const hl=Vn.exports;je.extend(hl);const En=t=>{const{ooui:r}=t;return e.jsx(me,{...t,children:e.jsx(pl,{ooui:r})})},pl=t=>{const r=(n,s)=>{t.onChange&&t.onChange(s)};return e.jsx(p.TimePicker,{onChange:r,value:t.value?je(t.value,"HH:mm:ss"):void 0})},In=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(gl,{ooui:r})})},gl=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,selectionValues:i,readOnly:a}=s,c=r==null?void 0:r.split(","),[f,d]=l.useState([]),[h,u]=l.useState();return l.useEffect(()=>{if(!r){u(void 0),d([]);return}const g=r&&c&&c[0],C=r&&c&&c[1]&&parseInt(c[1]);d([C,void 0]),u(g)},[r]),e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"1",children:e.jsx(_r,{ooui:new oe.Selection({name:"model_selection",selection:i,readonly:a,required:o}),onChange:g=>{u(g);let C=f[0]||0;g!==h&&(d([]),C=0);const y=`${g},${C}`;y!==r&&(n==null||n(y))},value:h})}),e.jsx(p.Col,{flex:"3",children:e.jsx(gn,{ooui:new oe.Many2one({name:"object_value",relation:h,readonly:a,required:o}),value:f,onChange:g=>{d(g);const C=`${h},${g[0]||0}`;C!==r&&(n==null||n(C))}})})]})},{useToken:ml}=p.theme,$n=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(yl,{ooui:r})})},yl=t=>{const{ooui:r,value:n,onChange:s}=t,{readOnly:o,required:i,filenameField:a}=r,{token:c}=ml(),f=i&&!o?{backgroundColor:c.colorPrimaryBg}:void 0,d=l.useRef(null),{setFieldValue:h,getFieldValue:u}=l.useContext(ke)||{},{t:g}=l.useContext(ge),C=n?js(n):"",y=D=>{s==null||s(D)};async function m(){const D=await nt(n),S=`data:${D==null?void 0:D.mime};base64,${n}`,V=document.createElement("a"),k=u(a),L=u("name");V.href=S,V.download=k||L,V.click()}async function w(){const D=await nt(n);Ft(n,D.mime)}async function v(D){D.stopPropagation(),D.preventDefault();const S=D.target.files[0],V=await Hr(S);y(V),a&&h(a,S.name)}function O(){h(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:v}),e.jsx(p.Input,{type:"text",disabled:!0,style:f,value:C})]}),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:w,children:g("open")}),e.jsx(Le,{tooltip:g("download"),disabled:!n,onClick:m,icon:e.jsx(H.DownloadOutlined,{})}),e.jsx(Le,{tooltip:g("clear"),disabled:o||!n,onClick:O,icon:e.jsx(H.ClearOutlined,{})})]})})]})},ar={tree:e.jsx(H.TableOutlined,{}),form:e.jsx(H.FormOutlined,{}),graph:e.jsx(H.AreaChartOutlined,{}),calendar:e.jsx(H.CalendarOutlined,{})};function An(t){return t?(ar==null?void 0:ar[t.type])||e.jsx(H.FormOutlined,{}):e.jsx(H.FormOutlined,{})}function lr(t){const{currentView:r,availableViews:n,onChangeView:s,disabled:o=!1,formHasChanges:i=!1,previousView:a}=t,{t:c,lang:f}=l.useContext(ge);function d(){const g=n.map((C,y)=>e.jsx(p.Menu.Item,{children:e.jsxs(p.Row,{wrap:!1,children:[e.jsx(p.Col,{flex:"none",style:{paddingRight:20},children:An(C)}),e.jsx(p.Col,{flex:"auto",style:{paddingRight:20},children:C.type.charAt(0).toUpperCase()+C.type.slice(1)}),e.jsx(p.Col,{flex:"none",children:e.jsx(H.CheckOutlined,{style:{opacity:r.view_id===C.view_id?1:0}})})]})},C.view_id||y));return e.jsx(p.Menu,{onClick:u,children:e.jsx(p.Menu.ItemGroup,{title:c("viewAs"),children:g})})}function h(g){if(i){yt({lang:f,onOk:()=>{g()}});return}g()}function u(g){h(()=>{const C=n.find(y=>y.view_id===parseInt(g.key));s(C)})}return e.jsxs("div",{style:{display:"flex"},children:[e.jsx(Le,{tooltip:a?c("viewAs")+" "+c(a.type):"",icon:An(a),style:{width:50,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:()=>{u({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()})})]})}function ut(t){const{icon:r,tooltip:n,items:s=[],onItemClick:o,label:i,disabled:a=!1}=t;function c(){const d=s==null?void 0:s.map((h,u)=>h.name==="divider"?e.jsx(p.Menu.Divider,{},"divider"+u):e.jsx(p.Menu.Item,{children:h.name},h.id));return e.jsx(p.Menu,{onClick:f,children:e.jsx(p.Menu.ItemGroup,{title:n,children:d})})}function f(d){const h=s.find(u=>isNaN(d.key)?u.id===d.key:u.id===parseInt(d.key));o(h)}return e.jsx(p.Dropdown,{overlay:c(),disabled:a||!s||s.length===0,children:e.jsxs(p.Button,{children:[r," ",i," ",e.jsx(H.DownOutlined,{})]})})}function Ne(t){const{onClick:r,disabled:n=!1,loading:s=!1,tooltip:o,icon:i,label:a,type:c="default"}=t,f=s?e.jsx(H.LoadingOutlined,{}):i;return e.jsxs(Le,{type:c,tooltip:o,onClick:r,disabled:n,children:[f,a]})}function Ln(t){const{disabled:r=!1}=t,{formHasChanges:n,onNewClicked:s}=l.useContext(He),{t:o,lang:i}=l.useContext(ge),a=()=>{if(n){yt({lang:i,onOk:()=>{s()}});return}s()};return e.jsx(Ne,{icon:e.jsx(H.FileAddOutlined,{}),tooltip:o("new"),onClick:a,disabled:r})}const{confirm:wl}=p.Modal,vl=({onOk:t,onCancel:r,lang:n})=>{wl({title:Se("unsavedChanges",n),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmRefreshWithoutSave",n),okText:Se("discardAndRefresh",n),cancelText:Se("cancel",n),onOk:t,onCancel:r})};async function Nn(t,r,n){const s=(await Y.getHandler().getLogInfo({model:t,ids:[r]}))[0],{create_date:o,create_uid:i,id:a,write_date:c,write_uid:f}=s;Ue(e.jsxs("div",{children:["ID: "+a," ",e.jsx("br",{}),n("createdBy")+": "+i[1]," ",e.jsx("br",{}),n("creationDate")+": "+o," ",e.jsx("br",{}),n("lastUpdatedBy")+": "+f[1]," ",e.jsx("br",{}),n("lastUpdatedDate")+": "+c]}))}const Cl=t=>{const{numberOfAttachments:r,disabled:n}=t,{t:s,lang:o}=l.useContext(ge),[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:f=>a(f),visible:i,placement:"bottom",content:Sl(t,a,o),title:s("attachments"),arrowContent:null,children:c})},Sl=(t,r,n)=>{const{attachments:s=[],loading:o,onAddNewAttachment:i,onopenAttachmentLink:a,onOpenAttachmentDetail:c,onListAllAttachments:f}=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),f()},children:[e.jsx(H.TableOutlined,{})," ",Se("listAllAttachments",n)]}),e.jsxs("a",{style:{display:"block"},href:"#",onClick:()=>{r(!1),i()},children:[e.jsx(H.FileAddOutlined,{})," ",Se("addNewAttachment",n)]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("li",{className:"ant-dropdown-menu-item-divider"}),s.map(d=>{const h=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?Se("openAttachmentLink",n):Se("download",n),children:e.jsx(h,{style:{cursor:"pointer"},onClick:()=>{r(!1),a(d)}})})}),e.jsx(p.Col,{flex:"25px",style:{textAlign:"center"},children:e.jsx(p.Tooltip,{title:Se("openAttachment",n),children:e.jsx(H.FormOutlined,{style:{cursor:"pointer"},onClick:()=>{r(!1),c(d)}})})})]},d.id)})]})]})};function bl(t){const{attachments:r,disabled:n=!1,onAddNewAttachment:s,onListAllAttachments:o,onViewAttachmentDetails:i}=t,{formRef:a}=l.useContext(He),[c,f]=l.useState(!1),[d,h]=l.useState([]),[u,g]=l.useState(!1),{t:C}=l.useContext(ge),y=l.useCallback(async()=>{f(!0);try{const v=await Y.getHandler().readObjects({model:"ir.attachment",ids:r.map(O=>O.id),fieldsToRetrieve:["name","datas_fname","link"],context:a.current.getContext()});h(v.map(O=>({id:O.id,name:O.name,datas_fname:O.datas_fname,link:O.link})))}catch(v){Ae(v)}f(!1)},r),m=l.useCallback(async v=>{if(v.link){window.open(v.link);return}g(!0);let O;try{O=(await Y.getHandler().readObjects({model:"ir.attachment",ids:[v.id],context:a.current.getContext()}))[0]}catch(D){Ae(D)}if(g(!1),!!O)if(O.datas){const D=await nt(O.datas);Ft(O.datas,D.mime)}else i(O)},[]),w=l.useCallback(async v=>{i(v)},[]);return l.useEffect(()=>{y()},[y]),e.jsxs(e.Fragment,{children:[e.jsx(Cl,{numberOfAttachments:r.length,attachments:d,disabled:n,loading:c,onAddNewAttachment:s,onListAllAttachments:o,onopenAttachmentLink:m,onOpenAttachmentDetail:w}),e.jsx(p.Modal,{title:C("downloadingAttachment"),open:u,footer:null,closable:!1,centered:!0,maskClosable:!1,children:e.jsx(p.Spin,{})})]})}function Pn({toolbar:t}){const{availableViews:r,currentView:n,setCurrentView:s,onFormSave:o,formHasChanges:i,formIsSaving:a,currentId:c,results:f,setCurrentItemIndex:d,currentItemIndex:h,setCurrentId:u,currentModel:g,setRemovingItem:C,removingItem:y,duplicatingItem:m,setDuplicatingItem:w,setResults:v,formIsLoading:O,attachments:D,formRef:S,setFormHasChanges:V,previousView:k,setPreviousView:L,goToResourceId:x}=l.useContext(He),{t:b,lang:_}=l.useContext(ge),T=l.useContext(lt),{processAction:P}=T||{},I=l.useContext(Ge),{openRelate:F,openDefaultActionForModel:E}=I||{};function A(N){if(i){vl({lang:_,onOk:()=>{N()}});return}N()}function M(N){if(i){yt({lang:_,onOk:()=>{N()}});return}N()}function B(){f&&f.length>h+1?(d==null||d(h+1),u==null||u(f[h+1].id)):f&&h+1===f.length&&(d==null||d(0),u==null||u(f[0].id))}function $(){f&&h>0?(d==null||d(h-1),u==null||u(f[h-1].id)):f&&h===0&&(d==null||d(f.length-1),u==null||u(f[f.length-1].id))}function W(){rt({confirmMessage:b("confirmRemoveItem"),lang:_,onOk:()=>{J()}})}async function J(){try{C==null||C(!0),await Y.getHandler().delete({model:g,ids:[c]});const N=f==null?void 0:f.filter(Z=>Z.id!==c);v==null||v(N);let K=0;h>0&&h<=f.length-1&&(K=h-1),N!=null&&N[K]?(u==null||u(N==null?void 0:N[K].id),d==null||d(K)):(u==null||u(void 0),d==null||d(void 0))}catch(N){kt(JSON.stringify(N))}finally{C==null||C(!1)}}async function q(){try{w==null||w(!0);const N=await Y.getHandler().duplicate({id:c,model:g,context:S.current.getContext()});N&&await(x==null?void 0:x(N))}catch(N){kt(JSON.stringify(N))}finally{w==null||w(!1)}}const X=a||y||O||m;function j(N){P==null||P({actionData:N,values:S.current.getValues(),fields:S.current.getFields(),context:S.current.getContext(),onRefreshParentValues:()=>{S.current.fetchValues()}})}return n?e.jsxs(p.Space,{wrap:!0,children:[O&&e.jsxs(e.Fragment,{children:[e.jsx(p.Spin,{}),ft(),ft()]}),e.jsx(Ln,{disabled:a||O||y||m}),e.jsx(Ne,{icon:e.jsx(H.SaveOutlined,{}),tooltip:b("save"),disabled:!i||X,loading:a,onClick:o}),e.jsx(Ne,{icon:e.jsx(H.CopyOutlined,{}),tooltip:b("duplicate"),disabled:i||a||c===void 0||m||O,loading:m,onClick:q}),e.jsx(Ne,{icon:e.jsx(H.DeleteOutlined,{}),tooltip:b("delete"),disabled:a||c===void 0||y||m||O,loading:y,onClick:W}),ft(),e.jsx(Ne,{icon:e.jsx(H.InfoCircleOutlined,{}),tooltip:b("showLogs"),disabled:a||c===void 0||y||m||O,loading:!1,onClick:()=>{Nn(g,c,b)}}),e.jsx(Ne,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:b("refresh"),disabled:a||c===void 0||y||m||O,loading:!1,onClick:()=>{A(()=>{S.current.fetchValues()})}}),ft(),e.jsx(lr,{currentView:n,previousView:k,availableViews:r,onChangeView:N=>{L==null||L(n),V==null||V(!1),s==null||s(N)},disabled:X,formHasChanges:i}),ft(),e.jsxs(p.Space,{children:[e.jsx(Ne,{icon:e.jsx(H.LeftOutlined,{}),tooltip:b("previous"),disabled:X,loading:!1,onClick:()=>{M($)}}),e.jsx(Ne,{icon:e.jsx(H.RightOutlined,{}),tooltip:b("next"),disabled:X,loading:!1,onClick:()=>{M(B)}})]}),ft(),e.jsx(ut,{icon:e.jsx(H.ThunderboltOutlined,{}),disabled:X,tooltip:b("actions"),items:t==null?void 0:t.action,onItemClick:async N=>{!N||!(await ht({onFormSave:o})).succeed||j(N)}}),e.jsx(ut,{icon:e.jsx(H.PrinterOutlined,{}),disabled:X,tooltip:b("reports"),items:t==null?void 0:t.print,onItemClick:async N=>{if(!N)return;const K=await ht({onFormSave:o});!K.succeed||j({...N,datas:{...N.datas||{},ids:[K.currentId]}})}}),e.jsx(ut,{icon:e.jsx(H.EnterOutlined,{}),disabled:X,tooltip:b("related"),items:t==null?void 0:t.relate,onItemClick:async N=>{!N||!(await ht({onFormSave:o})).succeed||F({relateData:N,values:S.current.getValues(),fields:S.current.getFields(),action_id:N.id,action_type:N.type})}}),e.jsx(bl,{disabled:X,attachments:D,onAddNewAttachment:async()=>{const N=await ht({onFormSave:o});if(!N.succeed)return;const K=N.currentId,Z=g;E({model:"ir.attachment",values:{selection_associated_object:`${Z},${K}`},forced_values:{res_model:Z,res_id:K},initialViewType:"form"})},onListAllAttachments:async()=>{const N=await ht({onFormSave:o});if(!N.succeed)return;const K=N.currentId;E({model:"ir.attachment",domain:[["res_model","=",`${g}`],["res_id","=",`${K}`]],initialViewType:"tree"})},onViewAttachmentDetails:async N=>{!(await ht({onFormSave:o})).succeed||E({model:"ir.attachment",res_id:N.id,initialViewType:"form"})}})]}):null}function ft(){return e.jsx("div",{className:"inline-block w-2"})}async function ht({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:xl}=p.theme,Bn=t=>{const{ooui:r,value:n,onChange:s,valueValidator:o,linkPrefix:i=""}=t,{id:a,readOnly:c,required:f}=r,{token:d}=xl(),h=f&&!c?{backgroundColor:d.colorPrimaryBg}:void 0,u=l.useContext(ke),{elementHasLostFocus:g}=u||{},[C,y]=l.useState(!1),[m,w]=l.useState(!1);l.useEffect(()=>{c&&!C&&w(!1),!n&&!c&&(y(!0),w(!0))},[C,c]);const v=O=>{s==null||s(O.target.value)};return e.jsxs(p.Row,{gutter:8,wrap:!1,align:"middle",children:[c?null:e.jsx(p.Col,{flex:"32px",children:C?e.jsx(p.Button,{icon:e.jsx(H.CheckOutlined,{}),onClick:()=>{o(n)&&(y(!1),w(!1))},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1}):e.jsx(p.Button,{icon:e.jsx(H.EditOutlined,{}),onClick:()=>{y(!0),w(!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,...h},id:a,onChange:v,value:n,onBlur:()=>{o(n)&&(y(!1),w(!1),g==null||g())}}):e.jsx("a",{href:`${i}${n}`,style:{color:d.colorPrimary,paddingRight:15},target:"_blank",children:n})})]})},Hn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(Bn,{ooui:r,valueValidator:s=>s?vo.default(s):!1})})},Kn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(Bn,{ooui:r,linkPrefix:"mailto:",valueValidator:s=>s?Co.default(s):!1})})},Tl=t=>{const{visible:r,onIdSubmitted:n,onCancel:s,isSearching:o}=t,{t:i}=l.useContext(ge);function a(c){n(c.id)}return e.jsx(p.Modal,{title:i("goToResourceId"),centered:!0,open:r,footer:null,destroyOnClose:!0,onCancel:s,maskClosable:!1,children:e.jsxs(p.Form,{layout:"vertical",onFinish:a,autoComplete:"off",children:[e.jsx(p.Form.Item,{name:"id",label:i("searchId"),rules:[{required:!0,type:"number"}],children:e.jsx(p.InputNumber,{style:{width:"100%"},autoFocus:!0})}),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:Fl}=p.theme;function Yn(t){const{badgeNumber:r=0,...n}=t,{token:s}=Fl();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(Le,{...n,style:{width:46,zIndex:0}})]})}function Ol({refreshGraph:t}){const{t:r}=l.useContext(ge),{availableViews:n,currentView:s,setCurrentView:o,searchParams:i,searchVisible:a,setSearchVisible:c,graphIsLoading:f,previousView:d,setPreviousView:h}=l.useContext(He);return e.jsxs(p.Space,{wrap:!0,children:[e.jsx(Yn,{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:f,badgeNumber:i==null?void 0:i.length}),e.jsx(Ne,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:r("refresh"),disabled:f,loading:!1,onClick:()=>{t()}}),e.jsx(lr,{currentView:s,availableViews:n,onChangeView:u=>{h==null||h(s),o==null||o(u)},disabled:!1,previousView:d})]})}const{useToken:_l}=p.theme,{Title:Dl,Text:At}=p.Typography;function Lt(t){const{title:r,children:n}=t,{title:s,currentView:o,currentId:i,currentItemIndex:a,results:c,totalItems:f,selectedRowItems:d}=l.useContext(He),{t:h}=l.useContext(ge),{token:u}=_l();function g(){if((o==null?void 0:o.type)==="form")return i?f===0?e.jsxs(e.Fragment,{children:[h("editingDocument")," (id:"," ",e.jsx(At,{copyable:{icon:e.jsx(H.CopyOutlined,{style:{color:"red"}})},children:i}),")"]}):e.jsxs(e.Fragment,{children:[h("register")," ",a===void 0?1:a+1," /"," ",c.length," ",h("of")," ",f," - ",h("editingDocument")," (id:"," ",e.jsx(At,{copyable:!0,children:i}),")"]}):"";if((o==null?void 0:o.type)==="tree"&&d){if(d.length===1)return e.jsxs(e.Fragment,{children:["1 ",h("selectedRegisters")," - (id:"," ",e.jsx(At,{copyable:!0,children:d[0].id}),")"]});if(d.length>1)return e.jsxs(e.Fragment,{children:[d.length," ",h("selectedRegisters"),e.jsx(At,{copyable:{text:d.map(C=>C.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:u.borderRadius,backgroundColor:u.colorPrimaryBg},align:"middle",children:[e.jsxs(p.Col,{flex:2,children:[e.jsx(Dl,{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 kl=t=>{const{viewData:r,visible:n,model:s,context:o,domain:i,formView:a,treeView:c}=t,f=l.useRef(),d=l.useContext(He),{setResults:h=void 0,setCurrentItemIndex:u=void 0,currentId:g=void 0,results:C=void 0,setSelectedRowItems:y=void 0,setSearchParams:m=void 0,searchVisible:w=!0,setSearchVisible:v=void 0,sorter:O=void 0,setSorter:D=void 0,setTotalItems:S=void 0,setSearchTreeNameSearch:V=void 0,setTreeIsLoading:k=void 0,limit:L,setLimit:x,searchParams:b,searchValues:_,setSearchValues:T,currentView:P}=d||{},[I,F]=l.useState(!0);l.useEffect(()=>{var W;(W=f.current)==null||W.refresh()},[b]),l.useEffect(()=>{r.view_id!==P.view_id&&F(!0)},[P]);const{clear:E,searchFilterLoading:A,searchError:M,offset:B,tableRefreshing:$}=Zr({model:s,setSearchTreeNameSearch:V,setSelectedRowItems:y,searchParams:b,setSearchValues:T,setSearchParams:m,setSearchVisible:v,setTreeIsLoading:k,context:o,formView:a,treeView:c,sorter:O,setSorter:D,setCurrentItemIndex:u,setResultsActionView:h,resultsActionView:C,domain:i,currentId:g,setActionViewTotalItems:S,limit:L,setLimit:x});return!n||!r?null:e.jsxs(e.Fragment,{children:[e.jsx(Lt,{title:r.name,children:e.jsx(Ol,{refreshGraph:()=>{f.current.refresh()}})}),e.jsx(Qt,{fields:{...c.fields,...a.fields},searchFields:Wr([a.search_fields,c.search_fields]),formXml:a.arch,limit:L,onClear:E,offset:B,isSearching:A,onSubmit:W=>{F(!1),m==null||m(W.params),v==null||v(!1)},searchError:M,searchVisible:w,searchValues:_,showLimitOptions:!1}),$?e.jsx(p.Spin,{}):e.jsx($t,{ref:f,view_id:r.view_id,model:s,context:o,domain:Dt(b||[],i),limit:I?L:void 0,manualIds:I?C==null?void 0:C.map(W=>W.id):void 0})]})},Ml=t=>{const{visible:r,formRef:n,model:s,currentId:o,domain:i,formView:a,context:c,defaultValues:f,forcedValues:d,results:h,setResults:u,setCurrentItemIndex:g}=t;return r?e.jsxs(e.Fragment,{children:[e.jsx(Lt,{children:e.jsx(Pn,{toolbar:a==null?void 0:a.toolbar})}),e.jsx(ct,{rootForm:!0,ref:n,model:s,defaultValues:f,forcedValues:d,formView:a,actionDomain:i,id:o,parentContext:c,onSubmitSucceed:(C,y)=>{h.findIndex(w=>w.id===C)===-1&&(h.push(y),u(h),g(h.length-1))}})]}):null};function Vl(t){const{onSearch:r,disabled:n=!1,searchText:s}=t,{t:o}=l.useContext(ge),[i]=p.Form.useForm(),[a,c]=l.useState(!1);function f(h){r(h.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:f,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:h=>{c(h.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 Wn=Be.default.createContext({previewFeatures:!1});function El(t){var X;const{availableViews:r,currentView:n,setCurrentView:s,selectedRowItems:o,setRemovingItem:i,removingItem:a,duplicatingItem:c,setDuplicatingItem:f,currentModel:d,searchTreeRef:h,setCurrentId:u,setCurrentItemIndex:g,searchParams:C,searchVisible:y,setSearchVisible:m,setSearchTreeNameSearch:w,searchTreeNameSearch:v,treeIsLoading:O,setPreviousView:D,previousView:S,results:V,limit:k,totalItems:L}=l.useContext(He),{parentContext:x={},treeExpandable:b,toolbar:_}=t,{previewFeatures:T}=l.useContext(Wn),{t:P,lang:I}=l.useContext(ge),F=l.useContext(lt),{processAction:E}=F||{},[A,M]=l.useState(!1),B=v!==void 0&&v.trim().length>0;function $(){rt({confirmMessage:P("confirmRemove"),lang:I,onOk:()=>{W()}})}async function W(){var j;try{i==null||i(!0),await Y.getHandler().delete({model:d,ids:o.map(N=>N.id)}),u==null||u(void 0),g==null||g(void 0),(j=h==null?void 0:h.current)==null||j.refreshResults()}catch(N){Ae(N)}finally{i==null||i(!1)}}async function J(){var j;try{f==null||f(!0);const N=o[0].id;await Y.getHandler().duplicate({id:N,model:d,context:{...x}})&&((j=h==null?void 0:h.current)==null||j.refreshResults())}catch(N){Ae(N)}finally{f==null||f(!1)}}function q(j){E==null||E({actionData:j,values:{active_id:o==null?void 0:o.map(N=>N.id)[0],active_ids:o==null?void 0:o.map(N=>N.id)},fields:{},context:{...x,active_id:o==null?void 0:o.map(N=>N.id)[0],active_ids:o==null?void 0:o.map(N=>N.id)},onRefreshParentValues:()=>{var N;(N=h==null?void 0:h.current)==null||N.refreshResults()}})}return e.jsxs(p.Space,{wrap:!0,children:[b?null:e.jsxs(e.Fragment,{children:[e.jsx(Vl,{disabled:c||a||O,searchText:v,onSearch:j=>{j&&j.trim().length>0?w==null||w(j):w==null||w(void 0)}}),!b&&e.jsx(Yn,{icon:e.jsx(H.FilterOutlined,{style:{color:y?"white":void 0}}),tooltip:P("advanced_search"),type:y?"primary":"default",onClick:()=>{m==null||m(!y)},disabled:c||a||O,badgeNumber:C==null?void 0:C.length}),bt(),e.jsx(Ln,{disabled:O}),e.jsx(Ne,{icon:e.jsx(H.CopyOutlined,{}),tooltip:P("duplicate"),disabled:!o||(o==null?void 0:o.length)!==1||c||O,loading:c,onClick:J}),e.jsx(Ne,{icon:e.jsx(H.DeleteOutlined,{}),tooltip:P("delete"),disabled:!(o&&(o==null?void 0:o.length)>0)||O,loading:a,onClick:$}),bt()]}),e.jsx(Ne,{icon:e.jsx(H.InfoCircleOutlined,{}),tooltip:P("showLogs"),disabled:!(o&&(o==null?void 0:o.length)>0)||O,loading:!1,onClick:()=>{Nn(d,o[0].id,P)}}),e.jsx(Ne,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:P("refresh"),disabled:c||a||O,loading:!1,onClick:()=>{var j;(j=h==null?void 0:h.current)==null||j.refreshResults()}}),!b&&e.jsxs(e.Fragment,{children:[bt(),e.jsx(lr,{currentView:n,availableViews:r,onChangeView:j=>{D==null||D(n),s==null||s(j)},previousView:S,disabled:O})]}),bt(),e.jsx(ut,{icon:e.jsx(H.ThunderboltOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||O,tooltip:P("actions"),items:_==null?void 0:_.action,onItemClick:j=>{!j||q(j)}}),e.jsx(ut,{icon:e.jsx(H.PrinterOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||O,tooltip:P("reports"),items:_==null?void 0:_.print,onItemClick:j=>{!j||q({...j,datas:{...j.datas||{},ids:o.map(N=>N.id)}})}}),T&&e.jsxs(e.Fragment,{children:[bt(),e.jsx(ut,{icon:e.jsx(vr.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:P("export"),items:[{id:"print_screen",name:P("printScreen")},{id:"export",name:P("advancedExport")}],onItemClick:j=>{if(j.id==="print_screen"){let N=(o==null?void 0:o.map(K=>K.id))||[];N.length===0&&(N=(V==null?void 0:V.map(K=>K.id))||[]),q({id:-1,model:d,report_name:"printscreen.list",type:"ir.actions.report.xml",datas:{model:d,ids:N}});return}M(!0)},disabled:c||a||O||B}),e.jsx(Dn,{visible:A,locale:I,onClose:()=>M(!1),model:d,domain:Dt(((X=h==null?void 0:h.current)==null?void 0:X.getDomain())||[],C||[]),limit:k,totalRegisters:L||0,selectedRegistersToExport:o,visibleRegisters:(V==null?void 0:V.length)||0,context:x})]})]})}function bt(){return e.jsx("div",{className:"inline-block w-2"})}const Il=t=>{const{visible:r,searchTreeRef:n,model:s,context:o,formView:i,treeView:a,domain:c,setCurrentItemIndex:f,results:d,setCurrentId:h,setCurrentView:u,availableViews:g,searchTreeNameSearch:C}=t,{currentView:y,setPreviousView:m}=l.useContext(He);return r?e.jsxs(e.Fragment,{children:[e.jsx(Lt,{children:e.jsx(El,{toolbar:a==null?void 0:a.toolbar,parentContext:o,treeExpandable:(a==null?void 0:a.isExpandable)||!1})}),e.jsx(er,{ref:n,rootTree:!0,model:s,parentContext:o,nameSearch:C,formView:i,treeView:a,domain:c,onRowClicked:w=>{const{id:v}=w;h(v);const O=d.findIndex(S=>S.id===v);m==null||m(y),f(O);const D=g.find(S=>S.type==="form");u(D)}})]}):null},cr=Be.default.createContext(null),$l=t=>{const[r,n]=l.useState(!1),[s,o]=l.useState(!1),{children:i,dashboardRef:a,openAction:c}=t;return e.jsx(cr.Provider,{value:{isLoading:r,setIsLoading:n,dashboardRef:a,openAction:c,moveItemsEnabled:s,setMoveItemsEnabled:o},children:i})};function Al(){const{isLoading:t,dashboardRef:r,moveItemsEnabled:n,setMoveItemsEnabled:s}=l.useContext(cr),{t:o}=l.useContext(ge);return e.jsxs(p.Space,{wrap:!0,children:[e.jsx(Ne,{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)}}),Ll(),e.jsx(Ne,{icon:e.jsx(H.SettingOutlined,{}),tooltip:o("configDashboard"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.configDashboard()}}),e.jsx(Ne,{icon:e.jsx(H.ReloadOutlined,{}),tooltip:o("refresh"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.refresh()}})]})}function Ll(){return e.jsx("div",{className:"inline-block w-2"})}const Nl=t=>{const{dashboardData:r}=t,n=l.useRef(),s=l.useContext(Ge),{openShortcut:o}=s||{};return r?e.jsxs($l,{dashboardRef:n,openAction:i=>{o(i)},children:[e.jsx(Lt,{children:e.jsx(Al,{})}),e.jsx(jn,{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 Pl(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 Bl(t,r){const{domain:n,model:s,context:o,views:i,title:a,setCanWeClose:c,tabKey:f,initialView:d,formDefaultValues:h,formForcedValues:u={},res_id:g=!1,action_id:C,action_type:y,treeExpandable:m=!1,limit:w}=t,[v,O]=l.useState(),[D,S]=l.useState([]),[V,k]=l.useState(!0),L=g||void 0,[x,b]=l.useState(L),[_,T]=l.useState([]),[P,I]=l.useState(),[F,E]=l.useState([]),[A,M]=l.useState(),[B,$]=l.useState(0),[W,J]=l.useState(!1),[q,X]=l.useState(!1),[j,N]=l.useState(),{t:K}=l.useContext(ge),Z=l.useRef(),se=l.useRef(),ce=l.useContext(Ge),{setCurrentView:Q,setCurrentId:R,tabs:ue,activeKey:ve,openAction:Me,onRemoveTab:xe}=ce||{};go.useHotkeys("ctrl+g,command+g",te=>{te.preventDefault(),be()},[ve,ue,v,P,F]);function de(te){b(te),R==null||R(te)}function ae(te){O(te),Q==null||Q(te)}l.useImperativeHandle(r,()=>({canWeClose:De}));const we=async()=>{k(!0);const te=[],Te=[];for(const Ce of i){const[Fe,fe]=Ce;fe!=="dashboard"?Te.push({viewTuple:Ce,promise:Y.getHandler().getView({model:s,type:fe,id:Fe,context:o})}):Te.push({viewTuple:Ce})}const Ee=await Pl(Te);for(const Ce of Ee){if(!Ce)continue;const[,Fe]=Ce.viewTuple;let fe=Ce.info;switch(Fe){case"dashboard":{const qe=i.find(Je=>{const[,ee]=Je;return ee==="form"});let $e;qe&&($e={action_id:C,action_type:y,name:a,res_id:o.active_id,res_model:s,view_id:qe[0],view_type:qe[1]}),te.push({type:"dashboard",id:o.active_id,model:s,context:o,configAction:$e});break}case"form":{te.push({...fe,type:Fe});break}case"tree":{te.push({...fe,isExpandable:m,type:Fe});break}case"graph":{te.push({...fe,type:Fe});break}}}let ye;!d&&te.find(Ce=>Ce.type==="tree")?ye=te.find(Fe=>Fe.type==="tree"):d?ye=te.find(Fe=>d.id?Fe.type===d.type&&Fe.view_id===d.id:Fe.type===d.type):ye=te.find(Fe=>Fe.type==="form"),ye||(Ae(`Error determining the first view to show for model ${s}.
36
36
  Please, make sure the view ids on the fields_view_get responses are the same as the ones defined in the action`),xe==null||xe(f)),ae(ye),S(te),k(!1)};c({tabKey:f,canWeClose:De}),l.useEffect(()=>{const te=D.find(Ee=>Ee.type==="tree"),Te=D.find(Ee=>d.id?Ee.type===d.type&&Ee.view_id===d.id:Ee.type===d.type);ae(Te||te),g?R==null||R(L):(de(void 0),I(void 0)),we()},[s,i,g]),l.useEffect(()=>{ve===f&&(R==null||R(x),Q==null||Q(v))},[ue,ve]);async function De(){return v&&v.type==="form"?await Z.current.cancelUnsavedChanges():!0}async function be(){ve===f&&(v.type==="form"&&!await Z.current.cancelUnsavedChanges()||J(!0))}async function Ve(te){var Ce;X(!0);const Te=F.findIndex(Fe=>Fe.id===te);let Ee;if(Te===-1){try{Ee=(Ce=await Y.getHandler().readObjects({model:s,ids:[te],context:o}))==null?void 0:Ce[0]}catch{}if(!Ee){X(!1),J(!1),Ue(K("idNotFound"));return}}else Ee=F[Te];X(!1),J(!1);const ye=i.find(Fe=>Fe[1]==="form");Me({domain:[],context:o,model:s,views:i,title:a,target:"current",initialView:{id:ye==null?void 0:ye[0],type:"form"},action_id:C,action_type:y,res_id:te})}function Ke(){return D.map(te=>{switch(te.type){case"form":return e.jsx(Ml,{formRef:Z,currentId:x,visible:v.type===te.type&&v.view_id===te.view_id,formView:te,model:s,context:o,domain:n,defaultValues:h,forcedValues:u,results:F,setResults:E,setCurrentItemIndex:I},`${te.type}-${te.view_id}`);case"tree":return e.jsx(Il,{visible:v.type===te.type&&v.view_id===te.view_id,limit:w,model:s,context:o,domain:n,formView:D.find(Te=>Te.type==="form"),treeView:te,searchTreeRef:se,searchTreeNameSearch:j,availableViews:D,results:F,setCurrentItemIndex:I,setCurrentId:de,setCurrentView:ae},`${te.type}-${te.view_id}`);case"graph":return e.jsx(kl,{visible:v.type===te.type&&v.view_id===te.view_id,viewData:te,model:s,context:o,domain:n,treeView:D.find(Te=>Te.type==="tree"),formView:D.find(Te=>Te.type==="form")},`${te.type}-${te.view_id}`);case"dashboard":return e.jsx(Nl,{dashboardData:te},`${te.type}-${te.view_id}`)}})}function Ie(){if(x===void 0&&v.type==="form")Z.current.clearAndReload();else{de(void 0);const te=D.find(Te=>Te.type==="form");ae(te)}}return V?e.jsx(p.Spin,{}):v?e.jsxs(Ii,{title:a,currentView:v,setCurrentView:ae,availableViews:D,formRef:Z,searchTreeRef:se,onNewClicked:Ie,currentId:x,setCurrentId:de,setCurrentItemIndex:I,currentItemIndex:P,results:F,setResults:E,currentModel:s,sorter:A,setSorter:M,totalItems:B,setTotalItems:$,selectedRowItems:_,setSelectedRowItems:T,setSearchTreeNameSearch:N,searchTreeNameSearch:j,goToResourceId:Ve,limit:w,children:[Ke(),e.jsx(Tl,{visible:W,onIdSubmitted:Ve,isSearching:q,onCancel:()=>{J(!1)}})]}):null}const qn=l.forwardRef(Bl);async function Hl({actionId:t,rootContext:r={},globalValues:n={}}){const s="ir.actions.act_window",o=`${s},${t}`,i=await Y.getHandler().getActionData({action:o,context:r}),a=oe.parseContext({context:i.context,values:n,fields:{}}),c=i.domain?await Y.getHandler().evalDomain({domain:i.domain,values:n,context:{...r,...a}}):[],{res_model:f,views:d,name:h,limit:u,view_type:g}=i,C=g==="tree",y=[];for(const O of d){const[D,S]=O;if(D)y.push(O);else{const{view_id:V}=await Y.getHandler().getView({model:f,type:S,id:D,context:{...r,...a}});y.push([V,S])}}const[m,w]=y[0],v={id:m,type:w};return{title:h,actionId:t,actionType:s,key:mr.v4(),views:d,model:f,context:{...r,...a},domain:c,initialView:v,limit:u,treeExpandable:C}}const Ec="",Kl=gr.WidthProvider(gr.Responsive),Gn=t=>{const{children:r=[],onPositionItemsChanged:n}=t,s=Be.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(Kl,{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:Yl}=p.theme,{Text:Wl}=p.Typography,Un=t=>{const{title:r,children:n,action:s,openAction:o}=t,{token:i}=Yl();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(Wl,{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]})},ql=80;function Gl(t){const{action:r,model:n,view_id:s,onRowClicked:o,domain:i=[],visible:a=!0,parentContext:c={}}=t,[f,d]=l.useState(!1),[h,u]=l.useState(!1),[g,C]=l.useState(),[y,m]=l.useState(),[w,v]=l.useState(),[O,D]=l.useState(1),[S,V]=l.useState(0),k=l.useRef(ql),L=l.useRef([]),[x,b]=l.useState(0),[_,T]=l.useState([]),[P,I]=l.useState(void 0),[F,E]=l.useState(),[A,M]=l.useState(),[B,$]=l.useState(),[W,J]=l.useState(!1),q=l.useRef([]),X=R=>{J(!0),D(R),V((R-1)*k.current)},j=async()=>{const R=q.current.length>0?q.current:i,ue=Dt(L.current,R),{colors:ve}=ot(y),{totalItems:Me,results:xe,attrsEvaluated:de}=await Y.getHandler().searchForTree({params:ue,limit:k.current,offset:S,model:g,fields:y.fields,context:c,attrs:ve&&{colors:ve}});I(Ot(de));const ae=st({resultsToSort:xe,sorter:F,fields:{...y.fields,...w.fields}});J(!1),T(ae);const we=await Me;b(we)},N=async()=>{try{J(!0),await j()}catch(R){M(JSON.stringify(R))}};l.useEffect(()=>{!h||a&&N()},[O,S,h,a]);const K=async R=>{u(!1),d(!0),$(void 0);try{R==="action"?await Z():await se(),u(!0)}catch(ue){$(ue)}finally{d(!1)}},Z=async()=>{const R=await Y.getHandler().getViewsForAction({action:r,context:c});q.current=R.domain,v(R.views.get("form")),m(R.views.get("tree")),C(R.model),k.current=R.limit},se=async()=>{C(n);const R=await Y.getHandler().getView({model:n,type:"form",context:c});v(R);const ue=await Y.getHandler().getView({model:n,type:"tree",id:s,context:c});m(ue)};l.useEffect(()=>{r?K("action"):n&&K("model")},[r,n]);const ce=R=>{const{id:ue}=R;o({id:ue,model:g,treeView:y})},Q=()=>!y||!w?null:e.jsxs("div",{style:{overflowY:"scroll"},children:[A&&e.jsx(p.Alert,{className:"mt-10",message:A,type:"error",banner:!0}),e.jsx(Ct,{showPagination:!1,total:x,limit:k.current,page:O,treeView:y,results:_,onRequestPageChange:X,loading:W,onRowClicked:ce,colorsForResults:P,sorter:F,onChangeSort:R=>{E==null||E(R);const ue=st({resultsToSort:_,sorter:R,fields:{...y.fields,...w.fields}});T(ue)},context:c})]});return B?e.jsx(p.Alert,{className:"mt-10",message:B,type:"error",banner:!0}):f?e.jsx(p.Spin,{style:{padding:"2rem"}}):Q()}const Ul=t=>{const{model:r}=t,[n,s]=l.useState();l.useEffect(()=>{o()},[r]);async function o(){const i=await Y.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(ct,{...t,model:r,id:n,readOnly:!0})})},dr="line_ids";function jl(t,r){const{model:n,context:s={},id:o,configAction:i}=t,[a,c]=l.useState([]),[f,d]=l.useState(!1),[h,u]=l.useState(),{setIsLoading:g,openAction:C,moveItemsEnabled:y}=l.useContext(cr),m=l.useRef(),w=l.useRef();l.useEffect(()=>{v()},[n,o,s]),l.useImperativeHandle(r,()=>({refresh:()=>{v()},configDashboard:L}));async function v(){d(!0),g(!0),u(void 0);try{const x=await O(),b=await S(x),_=x.fields[dr].relation,T=b[dr].items;w.current=x.fields;const P=await D({items:T,model:_,context:s}),I=await V(P);c(I),d(!1),g(!1)}catch(x){u(JSON.stringify(x))}}async function O(){return await Y.getHandler().getView({model:n,type:"form",context:s})}async function D({items:x,model:b,context:_}){m.current=(await Y.getHandler().getView({model:b,type:"form",context:_})).fields;const[T]=await zt({treeView:{fields:m.current},formView:{fields:m.current},model:b,items:x,context:_,currentView:"form"});return T}async function S(x){return(await Y.getHandler().readObjects({model:n,ids:[o],fields:x.fields,context:s}))[0]}async function V(x){const b=[];for(const _ of x){const{values:T}=_;if(T.action_id&&T.action_id.length>0){const P=parseInt(T.action_id[0],10),I=await Hl({actionId:P,rootContext:s});b.push({..._,actionData:I})}}return b}async function k(x){if(!y)return;const b=x.filter(I=>{const F=a.find(A=>A.id===I.id);if(!F)return!1;if(!F.position)return!0;const E={...JSON.parse(F.position.replace(/'/g,'"')),id:F.id};return JSON.stringify(I)!==JSON.stringify(E)});if(b.length===0)return;const T=a.filter(I=>b.map(F=>F.id).includes(I.id)).map(I=>{const F={...b.find(E=>E.id===I.id)};return delete F.id,{...I},{...I,operation:"pendingUpdate",values:{...I.values,position:JSON.stringify(F).replace(/"/g,"'")}}}),P={fields:m.current,items:T};await Y.getHandler().update({model:n,id:o,values:{[dr]:P},fields:w.current,context:s})}async function L(){C(i)}return h?(console.log(h),e.jsx(p.Alert,{className:"mt-10 mb-20",message:h,type:"error",banner:!0})):f?e.jsx(H.LoadingOutlined,{}):e.jsx(Gn,{onPositionItemsChanged:k,children:a.map((x,b)=>{const{actionData:_,values:T}=x,{position:P,id:I}=T,{actionId:F,actionType:E,key:A,title:M,views:B,model:$,context:W,domain:J,initialView:q,limit:X}=_;let j={};try{j=JSON.parse(P.replace(/'/g,'"'))}catch{j={x:b*2,y:0,w:2,h:3}}let N=null;if((q==null?void 0:q.type)==="graph")N=e.jsx($t,{view_id:B.filter(se=>se[1]==="graph")[0][0],model:$,context:W,domain:J,limit:X});else if((q==null?void 0:q.type)==="form")N=e.jsx(Ul,{model:$,actionDomain:J});else if((q==null?void 0:q.type)==="tree")N=e.jsx(Gl,{model:$,domain:J,view_id:B.filter(se=>se[1]==="tree")[0][0],onRowClicked:se=>{const ce=B.find(Q=>{const[,R]=Q;return R==="form"});if(ce){const[Q,R]=ce,{actionId:ue,actionType:ve,title:Me,model:xe}=_,de={action_id:ue,action_type:ve,name:Me,res_id:se.id,res_model:xe,view_id:Q,view_type:R};C(de)}}});else if(q!==void 0){const se=q&&Array.isArray(q.id)?{...q,id:q.id[0]}:q;N=e.jsx(qn,{action_id:F,action_type:E,tabKey:A,title:M,views:B,model:$,context:W,domain:J,setCanWeClose:()=>{},initialView:se,limit:X})}let K;const Z=B.find(se=>{const[,ce]=se;return ce==="tree"});if(Z){const[se,ce]=Z,{actionId:Q,actionType:R,title:ue,model:ve}=_;K={action_id:Q,action_type:R,name:ue,res_id:!1,res_model:ve,view_id:se,view_type:ce}}return e.jsx(Un,{id:I,title:M,parms:j,action:K,openAction:C,children:N},I)})})}const jn=l.forwardRef(jl),zn=t=>{const{ooui:r}=t;return e.jsx(me,{type:"array",...t,children:e.jsx(zl,{ooui:r})})},zl=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([]),[f,d]=l.useState(),[h,u]=l.useState(!1),{relation:g,context:C,readOnly:y,field:m,columns:w}=n,v=l.useContext(ke),{getContext:O}=v||{};Re.default(()=>{S()},[o]);const D=x=>{s==null||s({items:x})};async function S(){u(!0);let x=[];if(n.domain){const b=await Y.getHandler().evalDomain({domain:n.domain,values:at({fields:v==null?void 0:v.getFields(),values:v.getPlainValues()}),fields:v==null?void 0:v.getFields(),context:v.getContext()});x=[...x,...b]}try{const _=(await Y.getHandler().search({model:g,params:x,fields:[m],context:{...O==null?void 0:O(),...C}})).map(T=>{const P=T[m];let I=P;return Array.isArray(P)&&(I=P[1]),{label:I,value:T.id}});c(_)}catch(b){d(b)}finally{u(!1)}if(f)return e.jsx(p.Alert,{className:"mt-10",message:f,type:"error",banner:!0})}const V=()=>{L(a.map(x=>x.value))},k=()=>{L([])},L=x=>{const b=o.map(T=>x.includes(T.id)?T.operation=="pendingRemove"?{...T,operation:"original"}:T:{id:T.id,operation:"pendingRemove"}),_=b.map(T=>T.id);x.filter(T=>!_.includes(T)).map(T=>{b.push({id:T,operation:"pendingLink"})}),D(b)};return h&&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/w),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:k,disabled:i.length===0,children:"Uncheck all"})]})]})})},Jn=t=>e.jsx(me,{...t,children:e.jsx(Jl,{...t})}),Jl=t=>{const{value:r,ooui:n}=t;return e.jsx("div",{style:{height:n.height?n.height+"px":"100%",overflow:"auto"},children:e.jsx(So.default,{children:r,className:"ant-typography"})})},Zn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(Zl,{...t})})},Zl=t=>{const{ooui:r,onChange:n,value:s}=t,{selectionValues:o,readOnly:i,direction:a}=r,c=Array.from(o.entries()),f=c&&c.length&&c.map(d=>{const[h,u]=d;return e.jsx(p.Radio,{value:h,children:u},h)});return e.jsx(p.Radio.Group,{disabled:i,onChange:n,value:s,children:e.jsx(p.Space,{direction:a,children:f})})},Xn=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o}=r;return e.jsx(me,{...t,valuePropName:"checked",children:e.jsx(Xl,{id:n,readOnly:s,required:o})})},Xl=t=>{const{required:r,readOnly:n,...s}=t;return e.jsx("div",{className:"flex flex-row",children:e.jsx(p.Switch,{disabled:n,...s})})},Qn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(Ql,{...t})})},Ql=t=>{const{ooui:r,value:n}=t,{selectionValues:s,errorField:o}=r,i=l.useContext(ke),a=Array.from(s.entries()),c=a.map(h=>h[0]).indexOf(n);let f="process",d="";return o&&(d=i.getFieldValue(o),d&&(f="error")),e.jsx(p.Steps,{current:c,status:f,children:a.map((h,u)=>e.jsx(p.Steps.Step,{title:h[1],description:u===c&&f==="error"?d:null}))})},Rn=t=>{const{ooui:r}=t,{lang:n,height:s}=r,o=l.useContext(ke),{elementHasLostFocus:i}=o||{},a=c=>{c.onDidBlurEditorWidget(i)};return e.jsx(me,{...t,children:e.jsx(bo.default,{defaultLanguage:n||"",height:s||300,onMount:a})})},{Content:Rl}=p.Layout,{Title:ec}=p.Typography;function tc(){const{t}=l.useContext(ge);return e.jsx(Rl,{className:"m-5 select-none",children:e.jsx(ec,{level:5,children:t("welcome")})})}function rc(t,r){const{children:n,globalValues:s={},rootContext:o={},lang:i}=t,[a,c]=l.useState("welcome"),[f,d]=l.useState([{title:Se("welcome",i),key:"welcome",closable:!0,content:e.jsx(tc,{})}]),h=l.useRef(new Map),u=l.useRef();l.useImperativeHandle(r,()=>({retrieveAndOpenAction:y,openShortcut:v}));function g(S){if(S===a){const V=f.findIndex(k=>k.key===S);f[V-1]&&c(f[V-1].key),f[V+1]&&c(f[V+1].key)}d(f.filter(V=>V.key!==S)),h.current.delete(S)}function C({tabKey:S,canWeClose:V}){h.current.set(S,V)}async function y({action:S,values:V,forced_values:k,initialViewType:L,res_id:x,domain:b=[]}){const _=await Y.getHandler().getActionData({action:S,context:o});if(_.type==="ir.actions.wizard"){Ae("Action type not supported");return}const[T,P]=S.split(","),I=parseInt(P),F=oe.parseContext({context:_.context,values:s,fields:{}}),E=_.domain?await Y.getHandler().evalDomain({domain:_.domain,values:s,context:{...o,...F}}):[],{res_model:A,views:M,name:B,target:$,view_type:W,limit:J}=_,q=W==="tree",X=[];for(const N of M){const[K,Z]=N;if(K)X.push(N);else if(Z==="dashboard")X.push([void 0,"dashboard"]);else{const{view_id:se}=await Y.getHandler().getView({model:A,type:Z,id:K,context:{...o,...F}});X.push([se,Z])}}let j;if(L){const[N,K]=X.find(([Z,se])=>se===L);j={id:N,type:K}}else{const[N,K]=X[0];j={id:N,type:K}}D({domain:[...E,...b],context:{...o,...F},model:A,views:X,title:B,target:$,initialView:j,action_type:T,action_id:I,values:V,forced_values:k,res_id:x,treeExpandable:q,limit:J})}function m({title:S,content:V,key:k,action:L}){let x=[...f];f.length===1&&f[0].key==="welcome"&&(x=[...f.filter(b=>b.key!=="welcome")]),d([...x,{title:S,key:k,closable:!0,content:V,action:L}]),c(k)}async function w({relateData:S,fields:V,values:k,action_id:L,action_type:x}){const{res_model:b,context:_,domain:T,views:P,target:I,string:F,limit:E}=S,[A,M]=P[0],B={id:A,type:M},$=oe.parseContext({context:_,values:{...k,...s},fields:V}),W=T?await Y.getHandler().evalDomain({domain:T,values:at({fields:V,values:{...k,...s}}),fields:V,context:{...o,...$}}):[];D({model:b,target:I,views:P,context:{...o,...$},domain:W,title:F,initialView:B,action_id:L,action_type:x,limit:E})}async function v(S){const{action_id:V,action_type:k,res_id:L,view_id:x}=S,b=`${k},${V}`,_=await Y.getHandler().getActionData({action:b,context:o}),T=oe.parseContext({context:_.context,values:s,fields:{}}),P=_.domain?await Y.getHandler().evalDomain({domain:_.domain,values:s,context:{...o,...T}}):[],{res_model:I,views:F,name:E,target:A,view_type:M,limit:B}=_,$=M==="tree",W=[];for(const j of F){const[N,K]=j;if(N)W.push(j);else if(K==="dashboard")W.push([void 0,"dashboard"]);else{const{view_id:Z}=await Y.getHandler().getView({model:I,type:K,id:N,context:{...o,...T}});W.push([Z,K])}}let J,q;if(x==null){const j=W.find(N=>N[0]===void 0);J=void 0,q=j[1]}else[J,q]=W.find(j=>j[0]===void 0?!1:j[0]===x);const X={id:J,type:q};D({domain:P,context:{...o,...T},model:I,views:W,title:E,target:A,initialView:X,action_id:V,action_type:k,res_id:L,treeExpandable:$,limit:B})}async function O({model:S,values:V,forced_values:k,initialViewType:L,res_id:x,domain:b}){const _=await Y.getHandler().getActionStringForModel(S);await y({action:_,values:V,forced_values:k,initialViewType:L,res_id:x,domain:b})}async function D({domain:S,context:V,model:k,views:L,title:x,target:b,initialView:_,action_id:T,action_type:P,res_id:I,values:F,forced_values:E,treeExpandable:A=!1,limit:M}){const B=mr.v4();if(b!=="current"){const $=await Y.getHandler().getView({model:k,type:"form",id:_.type==="form"?_.id:void 0,context:{...o,...V}});u.current.openActionModal({domain:S,model:k,formView:$,context:{...o,...V},actionData:{action_id:T,action_type:P,res_id:I,view_id:$.view_id}})}else{const $=_&&Array.isArray(_.id)?{..._,id:_.id[0]}:_;m({title:x,action:{id:T,type:P},content:e.jsx(qn,{action_id:T,action_type:P,tabKey:B,title:x,views:L,model:k,context:{...o,...V},domain:S,setCanWeClose:C,initialView:$,res_id:I,formDefaultValues:F,formForcedValues:E,treeExpandable:A,limit:M}),key:B})}}return e.jsx(Do,{lang:i,children:e.jsx($i,{openShortcut:v,openAction:D,openRelate:w,openDefaultActionForModel:O,tabs:f,activeKey:a,onRemoveTab:async S=>{const V=h.current.get(S);(await(V==null?void 0:V())||a==="welcome")&&g(S)},onChangeTab:S=>{c(S)},children:e.jsx(Qr,{ref:u,globalValues:s,children:n})})})}const nc=l.forwardRef(rc),{useToken:oc}=p.theme;function sc(t){const{label:r,onClose:n,tabKey:s,isActive:o,onSelected:i}=t,{token:a}=oc(),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:f=>{f.stopPropagation(),n(s)}})})]})}function ic(){const t=l.useContext(Ge),{activeKey:r,tabs:n,onRemoveTab:s,onChangeTab:o}=t||{};return e.jsx(e.Fragment,{children:n.map(i=>e.jsx(sc,{tabKey:i.key,label:i.title,onClose:s,isActive:r===i.key,onSelected:o},i.key))})}function ac(t){const{tab:r}=t,n=l.useContext(Ge),{activeKey:s}=n||{},o={display:"none"};return e.jsx("div",{style:r.key!==s?o:void 0,children:r.content})}const lc=Be.default.memo(ac,()=>!0);function cc(){const t=l.useContext(Ge),{tabs:r}=t||{},n=(r==null?void 0:r.map(s=>e.jsx(lc,{tab:s},s.key)))||null;return e.jsx(e.Fragment,{children:n})}const{useToken:dc}=p.theme,uc=t=>{const{onRetrieveShortcuts:r,onCheckIsFavourite:n,onAddFavourite:s,onRemoveFavourite:o}=t,[i,a]=l.useState(!1),[c,f]=l.useState(!1),[d,h]=l.useState([]),[u,g]=l.useState(!0),[C,y]=l.useState(),{t:m}=l.useContext(ge)||{},{token:w}=dc(),v=l.useContext(Ge),{openShortcut:O,tabs:D,activeKey:S,currentView:V,currentId:k,openDefaultActionForModel:L}=v||{};l.useEffect(()=>{x()},[]),l.useEffect(()=>{T()},[D,S,V,k]);async function x(){try{g(!0);const A=await r();h(A)}catch(A){Ae(A)}finally{g(!1)}}function b(A){const{key:M}=A,B=d.find($=>$.id===Number(M));(B==null?void 0:B.action_type)!=="ir.actions.wizard"&&(B&&O(B),f(!1))}function _(A){A&&x(),f(A)}async function T(){if(!V)return;const A=D.find(q=>q.key===S),{id:M,type:B}=(A==null?void 0:A.action)||{};if(!M||!B){a(!1);return}const $=V.view_id;let W=!1;V.type==="form"&&(W=k||!1);const J=await n({action_id:M,action_type:B,view_id:$,res_id:W});J!==!1&&y(J),a(J!==!1)}async function P(){f(!1),L==null||L({model:"ir.ui.view_sc"})}const I=e.jsxs(p.Menu,{onClick:b,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:w.colorPrimary,cursor:"pointer"},onClick:P})})})]}),e.jsx(p.Menu.Divider,{}),u?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(F,{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 F({title:A,type:M}){const B=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:B}),e.jsx(p.Col,{flex:"auto",children:A})]})}async function E(){if(i&&C)await o(C);else{if(!V)return;const A=D.find(J=>J.key===S),{id:M,type:B}=(A==null?void 0:A.action)||{},$=V.view_id;let W=!1;if(!M||!B){a(!1);return}V.type==="form"&&(W=k||!1),await s({action_id:M,action_type:B,view_id:$,res_id:W})}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}),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()})})]})};U.ActionBar=Pn,U.Binary=$n,U.Boolean=kr,U.Button=qt,U.ButtonGroup=xr,U.Char=Gt,U.CodeEditor=Rn,U.ConfigContext=Wn,U.ConnectionProvider=Y,U.ContentRootProvider=Qr,U.CurrentTabContent=cc,U.Dashboard=jn,U.DashboardGrid=Gn,U.DashboardGridItem=Un,U.Date=kn,U.DateTime=Mn,U.Email=Kn,U.ExportModal=Dn,U.FavouriteButton=uc,U.Float=Xt,U.FloatTime=bn,U.Form=ct,U.FormModal=dt,U.GraphIndicator=wn,U.Group=nr,U.Image=Kr,U.Integer=vt,U.Label=gt,U.Many2one=pn,U.Markdown=Jn,U.MultiCheckbox=zn,U.Notebook=xn,U.One2many=Sn,U.ProgressBar=tn,U.Radio=Zn,U.Reference=In,U.RootView=nc,U.SearchFilter=Qt,U.SearchModal=tr,U.SearchTree=er,U.Selection=Ut,U.Separator=Fn,U.Steps=Qn,U.Switch=Xn,U.TabSelector=ic,U.Tag=sn,U.Tags=Ur,U.Text=Tn,U.Time=En,U.Tree=Ct,U.Url=Hn,U.iconMapper=We,U.showConfirmDialog=rt,Object.defineProperties(U,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
37
37
  //# sourceMappingURL=react-ooui.umd.js.map