@xras/ui 0.26.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/xras-ui.cjs +1 -1
- package/dist/xras-ui.js +1 -1
- package/package.json +1 -1
package/dist/xras-ui.cjs
CHANGED
|
@@ -49,7 +49,7 @@ Error generating stack: `+s.message+`
|
|
|
49
49
|
The error may be correlated with this previous error:
|
|
50
50
|
${Q.current.stack}
|
|
51
51
|
|
|
52
|
-
`),me}Ga(()=>{Q.current=void 0,X.current=void 0,H.current=Ce});const De=ie.useMemo(()=>ie.createElement(v,{...Ce,ref:N}),[N,v,Ce]);return ie.useMemo(()=>x?ie.createElement(O.Provider,{value:A},De):De,[O,De,A])}const C=ie.memo(S);if(C.WrappedComponent=v,C.displayName=S.displayName=g,c){const _=ie.forwardRef(function(R,O){return ie.createElement(C,{...R,reactReduxForwardedRef:O})});return _.displayName=g,_.WrappedComponent=v,ed(_,v)}return ed(C,v)}}var T_=O_;function P_({store:e,context:t,children:n,serverState:r,stabilityCheck:o="once",identityFunctionCheck:s="once"}){const i=ie.useMemo(()=>{const u=vx(e);return{store:e,subscription:u,getServerState:r?()=>r:void 0,stabilityCheck:o,identityFunctionCheck:s}},[e,r,o,s]),l=ie.useMemo(()=>e.getState(),[e]);Ga(()=>{const{subscription:u}=i;return u.onStateChange=u.notifyNestedSubs,u.trySubscribe(),l!==e.getState()&&u.notifyNestedSubs(),()=>{u.tryUnsubscribe(),u.onStateChange=void 0}},[i,l]);const c=t||Fn;return ie.createElement(c.Provider,{value:i},n)}var Bn=P_;function bx(e=Fn){const t=e===Fn?px:Mf(e),n=()=>{const{store:r}=t();return r};return Object.assign(n,{withTypes:()=>n}),n}var I_=bx();function $_(e=Fn){const t=e===Fn?I_:bx(e),n=()=>t().dispatch;return Object.assign(n,{withTypes:()=>n}),n}var ge=$_();VC(LC.useSyncExternalStoreWithSelector);C_(w.useSyncExternalStore);const nn="https://allocations.access-ci.org",ne={creditAlertThreshold:1e3,resourceTypeIcons:{credit:"cash-coin",compute:"cpu-fill",storage:"hdd-fill",program:"person-square"},routes:{edit_request_action_path:(e,t)=>`/requests/${e}/actions/${t}/edit`,edit_request_path:e=>`/requests/${e}/edit`,how_to_path:()=>"/how-to",get_your_first_project_path:()=>`${nn}/get-your-first-project`,profile_path:()=>`${nn}/profile`,project_types_path:()=>`${nn}/project-types`,projects_path:()=>`${nn}/projects`,projects_save_users_path:()=>"/projects/save_users",renew_request_path:e=>`${nn}/requests/${e}/renew`,request_action_path:(e,t)=>`${nn}/requests/${e}/actions/${t}`,request_actions_path:e=>`${nn}/requests/${e}/actions`,request_path:e=>`${nn}/requests/${e}`,resources_path:()=>`${nn}/resources`,search_people_path:()=>`${nn}/search/people`,usage_detail_path:(e,t)=>`/usage/${e}/${t}`},roleIcons:{PI:"person-fill-check","Co-PI":"person-fill-add","Allocation Manager":"person-fill-gear",User:"people-fill"}},mo=(e,t,n="round")=>{const r=Math.pow(10,t||0);return Math[n](e*r)/r},M_=e=>new Date(`${e}T00:00:00`),A_={year:"numeric",month:"short",day:"numeric"},go=(e,t)=>M_(e).toLocaleString("en-us",t||A_),it=(e,{abbreviate:t=!1,decimalPlaces:n=void 0}={})=>{if(t){let r=0;for(;Math.abs(e)/Math.pow(1e3,r)>=1e3;)r+=1;const o=["","K","M","B","T","Q"][r];return`${(e/Math.pow(1e3,r)).toLocaleString("en-US",{maximumSignificantDigits:3})}${o}`}return e.toLocaleString("en-US",{maximumFractionDigits:n,minimumFractionDigits:n})},Ff=(e,t)=>{if(e.startDate&&e.endDate){const o=go(e.startDate,t),s=go(e.endDate,t);return`${e.allocationType}: ${o} to ${s}`}const n=go(e.entryDate,t),r=e.status=="Incomplete"?"Started":"Submitted";return`${e.allocationType}: ${r} ${n}`},Tn=e=>a.jsx("i",{className:`bi bi-${e}`}),ii=e=>{const t=e.match(/^([^\(\)]+) (\(([^\)]+)\))?$/);return{full:e,short:t&&t[3]||null}},cm=e=>{const t=ii(e.name);return t.short||t.full},Qa=(e,t)=>e.isCredit>t.isCredit||e.isActive>t.isActive||cm(e)<cm(t)?-1:1,um=(...e)=>{for(let t of e)if(t!=null)return t;return null},wx=(e,t="and",n=", ")=>e.reduce((r,o,s)=>a.jsxs(a.Fragment,{children:[r,e.length-1>s?n:` ${t} `,o]})),Lf=e=>e?a.jsxs(a.Fragment,{children:[Tn("check-circle")," Yes"]}):a.jsxs(a.Fragment,{children:[Tn("x-circle")," No"]}),Uf=e=>wx(e.users.filter(({role:t})=>["pi","co_pi","allocation_manager"].includes(t)).map(t=>`${t.firstName} ${t.lastName}`),"or"),dm=(e,t)=>t==1&&e.endsWith("s")?e.slice(0,-1):e,D_=(e,t,n)=>`${it(t)} ${dm(n,t)} / ${dm(e,1)}`,Sx=e=>{let t=0,n=0;for(let r of e.resources){if(r.isBoolean)continue;let{unitCost:o}=r.exchangeRates.base;t+=r.allocated*o,n+=Math.min(r.used,r.allocated)*o}return t>0?n/t:0},$l=[{role:"pi",name:"PI",xrasRole:"PI"},{role:"co_pi",name:"Co-PI",xrasRole:"CoPI"},{role:"allocation_manager",name:"Allocation Manager",xrasRole:"Allocation Manager"},{role:"user",name:"User",xrasRole:"User"}],jx={};for(let e of $l)jx[e.role]=e;const td={};for(let{role:e,xrasRole:t}of $l)td[e]=t;const nd=["info","success","secondary","warning","danger"];function rd(e,t="total"){const n=e.exchangeRates[e.requested<=e.allocated?"base":"current"].unitCost;let r=(e.requested-e.allocated)*n;return t!="total"?r:r+e.allocated*e.exchangeRates.base.unitCost}function ai(e){e&&(ne.routes={...ne.routes,...e})}const od={user:{colors:["#ffc42d","#fea92c","#f98f30","#f07537"]},rp:{colors:["#48c0b9","#2e9da4","#207b8b","#1a5b6e"]}},Ac={};function Cx(e,t=3){let n=0;for(;e/Math.pow(1e3,n)>1e3;)n+=1;const r=e.toString().length,o=Math.pow(10,r-t);return(Math.round(e/o)*o/Math.pow(1e3,n)).toString()+["","K","M","B","T"][n]}async function F_(){return await(await fetch("https://basemaps-api.arcgis.com/arcgis/rest/services/styles/ArcGIS:Community?type=style&token=AAPK220079f462f24fda89c27fa210c3f887EJPCECuukKD8PnCIBqktgGTKZWPlVXWjRoSsZYGkOJ12QemGItZ4liRZkcUzYyme")).json()}async function L_(e){if(Ac[e])return Ac[e];const t=document.location,n=`${t.protocol}//${t.host}${t.pathname}`,o=await(await fetch(`${n}/${e}`)).json();return Ac[e]=o,o}function U_(e){const t=[...e.creditLines.features.map(r=>r.properties.credits)],n=[...e.rpPoints.features.map(r=>r.properties.rpCredits),...e.userPoints.features.map(r=>r.properties.userCredits)];return{lines:pm(t),points:pm(n)}}function fm({activeOrg:e,basemapStyle:t,creditLevels:n,creditType:r,geoJSON:o,organizationType:s}){const i={},l=[];if(o&&n){const u=s==="user"?"rp":"user",d=o[`${s}Points`],f=o[`${u}Points`],p=`${s}Credits`,m=`${u}Credits`;i.organizations={type:"geojson",data:d};const x={user:[],rp:[]},y=[];n.points.forEach((h,g)=>{Object.keys(od).forEach(b=>{x[b].push(h[1],od[b].colors[g])}),y.push(h[1],5*(g+1))});const v=[];if(n.lines.forEach((h,g)=>{v.push(h[1],1*(g+1))}),l.push({id:"organizations",type:"circle",source:"organizations",paint:{"circle-radius":["interpolate",["linear"],["get",p],...y],"circle-color":["interpolate",["linear"],["get",p],...x[s]],"circle-opacity":e?["match",["id"],e.id,1,.3]:1,"circle-stroke-color":"#ffffff","circle-stroke-width":1}}),e&&r!=="allocated"){i.opp={type:"geojson",data:f};const h=["get",e.id.toString(),["get",`${m}Map`]];l.push({id:"opp",type:"circle",source:"opp",filter:["has",e.id.toString(),["get",`${m}Map`]],paint:{"circle-radius":["interpolate",["linear"],h,...y],"circle-color":["interpolate",["linear"],h,...x[u]],"circle-stroke-color":"#ffffff","circle-stroke-width":1}}),i.credits={type:"geojson",data:o.creditLines},l.push({id:"credits",type:"line",source:"credits",filter:["==",["get",`${s}_organization_id`],e.id],paint:{"line-color":"#444444","line-opacity":.4,"line-width":["interpolate",["linear"],["get","credits"],...v]}})}}const c=t||{version:8,sources:{},layers:[]};return{...c,sources:{...c.sources,...i},layers:[...c.layers.filter(u=>u.id!=="Marine waterbody/label/2x large"),...l]}}function V_(e,t,n,r,o=20){return[...Array(o+1).keys()].map(s=>s/o).map(s=>{let i=s*(n-e)+e,l=s*(r-t)+t+Math.abs(Math.sin(s*Math.PI)*(n-e)*.1);return[i,l]})}function z_(e,t,n){const r={};return e.features.forEach(s=>r[s.id]={type:s.type,geometry:s.geometry,id:s.id,properties:{name:s.properties.name,abbr:s.properties.abbr,userCredits:0,userCreditsMap:{},rpCredits:0,rpCreditsMap:{}}},{}),{creditLines:{type:"FeatureCollection",features:t.result.filter(s=>r[s.user_organization_id]!==void 0&&(n==="allocated"||r[s.rp_organization_id]!==void 0)).map(s=>{const i=r[s.user_organization_id],l=r[s.rp_organization_id];if(i.properties.userCredits+=s.credits,l&&(l.properties.rpCredits+=s.credits),i.properties.userCreditsMap[s.rp_organization_id]=(i.properties.userCreditsMap[s.rp_organization_id]||0)+s.credits,l&&(l.properties.rpCreditsMap[s.user_organization_id]=(l.properties.rpCreditsMap[s.user_organization_id]||0)+s.credits),n!=="allocated")return{type:"Feature",geometry:{type:"LineString",coordinates:V_(...r[s.user_organization_id].geometry.coordinates,...r[s.rp_organization_id].geometry.coordinates)},properties:s}}).filter(s=>s!==void 0)},userPoints:{type:"FeatureCollection",features:Object.values(r).filter(s=>s.properties.userCredits>0).sort((s,i)=>s.properties.userCredits>i.properties.userCredits?-1:1)},rpPoints:{type:"FeatureCollection",features:Object.values(r).filter(s=>s.properties.rpCredits>0).sort((s,i)=>s.properties.rpCredits>i.properties.rpCredits?-1:1)}}}function pm(e,t=[0,.3,.6,.9]){return t.map((n,r)=>{const o=B_(e,n),s=r===t.length-1?"+":"";return[`${Cx(Math.round(o))}${s}`,o]})}function B_(e,t){e.sort((s,i)=>s-i);const n=(e.length-1)*t,r=Math.floor(n),o=n-r;return e[r+1]!==void 0?e[r]+o*(e[r+1]-e[r]):e[r]}const q_="_fullscreen_1iid9_6",H_="_map_1iid9_14",$i={"allocations-map":"_allocations-map_1iid9_1",fullscreen:q_,map:H_},W_="_group_11k83_1",K_="_button_11k83_6",Y_="_icon_11k83_16",Dc={group:W_,button:K_,icon:Y_};function hm({choices:e,disabledValues:t=[],label:n,value:r,setValue:o}){const s=[];return e.forEach(([i,l])=>s.push(a.jsx("input",{type:"radio",className:"btn-check",name:i,id:i,autoComplete:"off",checked:r===i,onChange:()=>o(i),disabled:t.includes(i)},i),a.jsxs("label",{className:`btn btn-outline-primary ${Dc.button}`,htmlFor:i,disabled:t.includes(i),children:[r===i?a.jsx("i",{className:`bi bi-check ${Dc.icon}`}):null," ",l]},`${i}-label`))),a.jsx("div",{className:"mb-2",children:a.jsx("div",{className:`btn-group ${Dc.group}`,role:"group","aria-label":n,children:s})})}const G_="_controls_1be4t_1",Q_={controls:G_};function X_({creditType:e,organizationType:t,setCreditType:n,setOrganizationType:r}){return a.jsxs("div",{className:Q_.controls,children:[a.jsx("h2",{children:"ACCESS Allocations"}),a.jsx(hm,{choices:[["allocated","Allocations"],["exchanged","Exchanges"],["used","Usage"]],label:"Credit Type",value:e,setValue:n}),a.jsx(hm,{choices:[["user","By Research Institution"],["rp","By Resource Provider"]],disabledValues:e==="allocated"?["rp"]:[],label:"Organization Type",value:t,setValue:r})]})}const Z_="_legend_odgg9_1",J_="_symbols_odgg9_17",eE="_symbol_odgg9_17",ra={legend:Z_,symbols:J_,symbol:eE};function tE(e,t){const n=2*e+2;return a.jsx("svg",{viewBox:`0 0 ${n} ${n}`,xmlns:"http://www.w3.org/2000/svg",stroke:"white",strokeWidth:"1",height:n,width:n,children:a.jsx("circle",{fill:t,cx:e+1,cy:e+1,r:e})})}function nE({activeOrg:e,creditLevels:t,organizationType:n}){if(e||!t)return;const r=t.points.map((o,s)=>a.jsxs("div",{className:ra.symbol,children:[tE(5*(s+1),od[n].colors[s]),a.jsx("br",{}),a.jsx("span",{className:"label",children:o[0]})]},o[0]));return a.jsxs("div",{className:ra.legend,children:[a.jsxs("h2",{className:"fs-6 mt-0 mb-0",children:["ACCESS Credits ",a.jsx("small",{children:"or credit equivalents"})]}),a.jsx("div",{className:ra.symbols,children:r})]})}const rE="_info_oxxoh_1",oE="_user_oxxoh_7",sE="_rp_oxxoh_10",iE="_credits_oxxoh_15",oa={info:rE,user:oE,rp:sE,credits:iE};function mm(e,t,n){e.sort((o,s)=>s[1]-o[1]);const r=e.slice(0,3).map(o=>o[0]);return e.length>3&&(r[2]=`${e.length-2} other ${n}s`),r.reduce((o,s,i,l)=>[o,a.jsx("span",{className:`name ${oa[t]}`,children:s},s),[""," and ",", "][l.length-i-1]],[])}function aE({activeOrg:e,creditType:t,organizationMap:n,organizationType:r}){if(!e||!n)return;const o=e.properties,s=o[`${r}Credits`],i=r==="rp"?"user":"rp",l=JSON.parse(o[`${r}CreditsMap`]),c={user:[],rp:[]};return c[r].push([o.name,s]),Object.keys(l).forEach(u=>c[i].push([n[u],l[u]])),a.jsx("div",{className:`${ra.legend} ${oa.info}`,children:a.jsxs("p",{className:oa[r],children:["Researchers at ",mm(c.user,"user","research institution")," ",t==="allocated"?"were ":"",t," ",a.jsxs("span",{className:oa.credits,children:[Cx(s)," ACCESS Credits"]}),t!=="allocated"?a.jsxs(a.Fragment,{children:[" ",t==="exchanged"?"for":"on"," resources at"," ",mm(c.rp,"rp","resource provider")]}):"","."]})})}function lE(){const e=w.useRef(null),t=w.useRef(null),[n,r]=w.useState(null),[o,s]=w.useState(null),[i,l]=w.useState(null),[c,u]=w.useState(!1),[d,f]=w.useState(null),[p,m]=w.useState(null),[x,y]=w.useState(null),[v,h]=w.useState("user"),[g,b]=w.useState("exchanged");return w.useEffect(()=>{(async()=>s(await F_()))()},[]),w.useEffect(()=>{(async S=>{const[j,C]=await Promise.all(["organizations",`credits_${S}`].map(L_));if(!x){const _={};j.features.forEach(N=>_[N.id.toString()]=N.properties.name),y(_)}const E=z_(j,C,g);f(E),S==="exchanged"&&!i&&l(U_(E))})(g)},[g]),w.useEffect(()=>{p&&p.setStyle(fm({activeOrg:n,basemapStyle:o,creditLevels:i,creditType:g,geoJSON:d,organizationType:v}))},[n,d,p,v]),w.useEffect(()=>{p&&(p.on("mousemove","organizations",S=>r(S.features.length?S.features[0]:null)),p.on("mouseleave","organizations",()=>r(null)))},[p]),w.useEffect(()=>{p&&p.resize()},[c]),w.useEffect(()=>{g==="allocated"&&h("user")},[g]),w.useLayoutEffect(()=>m(new maplibregl.Map({container:t.current,style:fm({activeOrg:n,basemapStyle:o,creditLevels:i,creditType:g,geoJSON:d,organizationType:v}),center:[-111.01,38.88],zoom:3.4,hash:!0})),[]),w.useLayoutEffect(()=>e.current.addEventListener("keydown",S=>{S.key==="Escape"&&u(!1)}),[]),a.jsxs("section",{className:`${$i["allocations-map"]} ${c?$i.fullscreen:"border border-3 border-primary"}`,ref:e,children:[a.jsx("div",{className:$i.map,ref:t}),a.jsx(X_,{creditType:g,fullscreen:c,organizationType:v,setCreditType:b,setFullscreen:u,setOrganizationType:h}),a.jsx(nE,{activeOrg:n,creditLevels:i,organizationType:v}),a.jsx(aE,{activeOrg:n,creditType:g,organizationMap:x,organizationType:v}),a.jsx("button",{title:`${c?"Exit":"Enter"} Fullscreen`,className:$i.fullscreen,onClick:()=>u(!c),children:a.jsx("i",{className:`bi ${c?"bi-fullscreen-exit":"bi-arrows-fullscreen"}`,"aria-label":"Fullscreen"})})]})}const cE=async(e,t)=>{try{const n=await fetch(`${e}/resources`,{method:"PATCH",headers:{"Content-Type":"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:JSON.stringify({resources:t.map((o,s)=>({resource_id:o.resource_id,relative_order:s+1}))})});if(!n.ok){const o=await n.json();throw new Error(o.error||"Failed to update resource order")}const r=await n.json();console.log(r.message)}catch(n){console.error("Error updating resource order:",n)}},gm=e=>[...e].sort((t,n)=>t.relative_order===null&&n.relative_order===null?t.display_resource_name.localeCompare(n.display_resource_name):t.relative_order===null?1:n.relative_order===null?-1:t.relative_order-n.relative_order),vm=(e,t)=>{t.current||(t.current=setInterval(()=>{window.scrollBy(0,e*10)},16))},Fc=e=>{e.current&&(clearInterval(e.current),e.current=null)},uE="_dragging_1vb1t_45",Wt={"resources-container":"_resources-container_1vb1t_1","drag-instruction":"_drag-instruction_1vb1t_6","resources-list":"_resources-list_1vb1t_12","resources-header":"_resources-header_1vb1t_18","resources-item":"_resources-item_1vb1t_28",dragging:uE,"drag-handle":"_drag-handle_1vb1t_52","resource-name":"_resource-name_1vb1t_61","resource-repo":"_resource-repo_1vb1t_65","resource-link":"_resource-link_1vb1t_71"};var _x={exports:{}},dE="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",fE=dE,pE=fE;function Ex(){}function Rx(){}Rx.resetWarningCache=Ex;var hE=function(){function e(r,o,s,i,l,c){if(c!==pE){var u=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw u.name="Invariant Violation",u}}e.isRequired=e;function t(){return e}var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:Rx,resetWarningCache:Ex};return n.PropTypes=n,n};_x.exports=hE();var mE=_x.exports;const q=Js(mE),gE=(e,t)=>{switch(t.type){case"SET_RESOURCE_DATA":return{...e,resourceData:t.payload,loading:!1};case"SET_LOADING":return{...e,loading:t.payload};case"SET_SUCCESS_MESSAGE":return{...e,successMessage:t.payload};case"SET_ERRORS":return{...e,errors:Array.isArray(t.payload)?t.payload:[t.payload],loading:!1};case"UPDATE_RESOURCE_FIELD":return{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,[t.field]:t.value}}};case"UPDATE_ALLOCATION":return{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,allocation_types:e.resourceData.resource_details.allocation_types.map(n=>n.allocation_type_id===t.payload.allocationTypeId?{...n,...t.payload.updates}:n)}}};case"UPDATE_BASE_RATE":return console.log("Reducer: Updating base rate to:",t.payload),{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,exchange_rates:{...e.resourceData.resource_details.exchange_rates,base_rate:t.payload}}}};case"UPDATE_EXCHANGE_RATE":return{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,exchange_rates:{...e.resourceData.resource_details.exchange_rates,discount_rates:e.resourceData.resource_details.exchange_rates.discount_rates.map(n=>n.id===t.payload.rateId?{...n,...t.payload.changes}:n)}}}};case"ADD_EXCHANGE_RATE":return console.log("Reducer: Adding new discount rate:",t.payload),{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,exchange_rates:{...e.resourceData.resource_details.exchange_rates,discount_rates:[...e.resourceData.resource_details.exchange_rates.discount_rates||[],t.payload]}}}};case"DELETE_EXCHANGE_RATE":return{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,exchange_rates:{...e.resourceData.resource_details.exchange_rates,discount_rates:e.resourceData.resource_details.exchange_rates.discount_rates.filter(n=>n.id!==t.payload)}}}};default:return e}},sd=e=>({type:"SET_RESOURCE_DATA",payload:e}),vE=e=>({type:"SET_LOADING",payload:e}),ym=(e,t)=>({type:"SET_SUCCESS_MESSAGE",payload:{message:e,color:t}}),Br=(e,t)=>({type:"UPDATE_RESOURCE_FIELD",field:e,value:t}),Lc=(e,t)=>({type:"UPDATE_ALLOCATION",payload:{allocationTypeId:e,updates:t}}),yE=async(e,t)=>await(await fetch(`${t}/resources/${e}.json`)).json(),xE=async(e,t,n,r)=>(console.log("update resource",n),await fetch(`${t}/resources/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:JSON.stringify({resource:n,required_resources:r})})),bE=(e,t)=>{const[n,r]=w.useReducer(gE,{resourceData:null,loading:!0,errors:[],successMessage:{message:"",color:""}}),o=w.useCallback(async(i,l)=>{let c=[l];try{const u=await i.json();u.errors?c=u.errors:u.message&&(c=[u.message])}catch(u){console.error("Error parsing error response:",u)}r({type:"SET_ERRORS",payload:c})},[]),s=w.useCallback(async()=>{r(vE(!0));try{const i=await yE(e,t);r(sd(i))}catch(i){console.error("Failed to fetch resource data:",i),r({type:"SET_ERRORS",payload:"Failed to fetch resource data. Please try again later."})}},[e,t]);return w.useEffect(()=>{s()},[s]),{state:n,dispatch:r,handleError:o,fetchData:s}},Vf=e=>{var t,n,r;return{allowedActionsOptions:((t=e==null?void 0:e.resource_state_types_available)==null?void 0:t.map(o=>({value:o.resource_state_type_id,label:o.display_resource_state_type,additionalInfo:o.action_types.map(s=>s.display_action_type).join(", ")})))||[],resourceTypesOptions:((n=e==null?void 0:e.resource_types_available)==null?void 0:n.map(o=>({value:o.resource_type_id,label:o.display_resource_type})))||[],unitTypesOptions:((r=e==null?void 0:e.unit_types_available)==null?void 0:r.map(o=>({value:o.unit_type_id,label:o.display_unit_type})))||[],availableResources:(e==null?void 0:e.required_resources_available)||[],availableAllocationTypes:(e==null?void 0:e.unassigned_allocation_types)||[]}},wE=(e,t,n,r,o,s,i)=>{const c=(()=>{var p;if(!e)return[];const f=new Set;return(p=e.allocation_types)==null||p.forEach(m=>{var x;(x=m.required_resources)==null||x.forEach(y=>{f.add(y.resource_name)})}),Array.from(f).sort((m,x)=>m.localeCompare(x)).map(m=>({key:m,name:`Require ${m}`,width:150,type:"checkbox"}))})();return{allocationColumns:[{key:"display_name",name:"Allocation Type",width:200},{key:"allowed_actions",name:"Allowed Actions",width:200,type:"select"},{key:"comment",name:"Descriptive Text",width:200,type:"input",tooltip:"Appears below the resource name and allocations description in the form when making a new request"},...c],allocationRows:e!=null&&e.allocation_types?e.allocation_types.map(f=>{var p;return{display_name:f.display_name,allocation_type_id:f.allocation_type_id,allowed_actions:{options:r,value:((p=f.allowed_action)==null?void 0:p.resource_state_type_id)||"",onChange:m=>o(f.allocation_type_id,m)},comment:{value:f.comment||"",onChange:m=>s(f.allocation_type_id,m)},...Object.fromEntries(c.map(m=>{var x;return[m.key,{checked:((x=f.required_resources)==null?void 0:x.some(y=>y.resource_name===m.key))||!1,onChange:y=>i(f.allocation_type_id,m.key,y,f)}]}))}}):[],requiredResourcesColumns:c}},SE=(e,t,n)=>{const{availableResources:r,availableAllocationTypes:o,allowedActionsOptions:s}=Vf(e),[i,l]=w.useState(!1),[c,u]=w.useState(!1),[d,f]=w.useState([]),[p,m]=w.useState(""),x=w.useCallback((j,C)=>{n(Lc(j,{allowed_action:{resource_state_type_id:C}}))},[n]),y=w.useCallback((j,C)=>{n(Lc(j,{comment:C}))},[n]),v=w.useCallback((j,C,E,_)=>{const N=E?[..._.required_resources||[],{resource_name:C,required_resource_id:e.required_resources_available.find(R=>R.resource_name===C).resource_id}]:(_.required_resources||[]).filter(R=>R.resource_name!==C);n(Lc(j,{required_resources:N}))},[e,n]);w.useEffect(()=>{if(i&&t){const j=t.allocation_types.flatMap(C=>C.required_resources||[]).map(C=>C.required_resource_id);f(j)}},[i,t]);const h=w.useCallback((j,C)=>{f(E=>C?[...E,j]:E.filter(_=>_!==j))},[]),g=w.useCallback(()=>{const j=t.allocation_types.flatMap(N=>N.required_resources||[]).map(N=>N.required_resource_id),C=d.filter(N=>!j.includes(N)),E=j.filter(N=>!d.includes(N)),_=t.allocation_types.map(N=>{const R=N.required_resources||[],O=C.map(P=>{const U=r.find(F=>F.resource_id===P);return{resource_name:U.resource_name,required_resource_id:U.resource_id}}),k=R.filter(P=>!E.includes(P.required_resource_id)).concat(O.filter(P=>!R.some(U=>U.required_resource_id===P.required_resource_id)));return{...N,required_resources:k}});n(sd({...e,resource_details:{...t,allocation_types:_}})),f([]),l(!1)},[d,r,t,e,n]),b=w.useCallback(j=>{const C=j.target.value;m(C)},[]),S=w.useCallback(()=>{var E,_;if(!p)return;const j=o.find(N=>N.allocation_type_id.toString()===p),C=(E=t.allocation_types)==null?void 0:E.some(N=>N.allocation_type_id===j.allocation_type_id);if(j&&!C){const N=(_=s[0])==null?void 0:_.value,R=[...t.allocation_types||[],{allocation_type_id:j.allocation_type_id,display_name:j.display_name,allowed_action:{resource_state_type_id:N},comment:"",required_resources:[]}];n(sd({...e,resource_details:{...t,allocation_types:R}})),u(!1)}},[p,o,t,e,n,s]);return{showAddResourceModal:i,setShowAddResourceModal:l,showAddAllocationTypeModal:c,setShowAddAllocationTypeModal:u,selectedNewResource:d,handleSelectNewResource:h,handleSaveResources:g,selectedNewAllocationType:p,handleSelectNewAllocationType:b,handleSaveAllocationType:S,handleAllowedActionChange:x,handleCommentChange:y,handleRequiredResourceChange:v}},jE=(e,t,n,r,o,s)=>w.useCallback(async()=>{var c,u,d;if(!e)return;const i={resource_name:e.resource_name,description:e.description,resource_type_id:e.resource_type_id,unit_type_id:e.unit_type_id,min_exchange:e.min_exchange,dollar_value:e.dollar_value,allocation_types:e.allocation_types.map(f=>{var p;return{allocation_type_id:f.allocation_type_id,allowed_action:{resource_state_type_id:(p=f.allowed_action)==null?void 0:p.resource_state_type_id},comment:f.comment||""}}),exchange_rates:{base_rate:(c=e.exchange_rates)==null?void 0:c.base_rate,discount_rates:(d=(u=e.exchange_rates)==null?void 0:u.discount_rates)==null?void 0:d.map(f=>({id:f.id,exchange_rate:f.exchange_rate,begin_date:f.begin_date,end_date:f.end_date}))}},l={};e.allocation_types.forEach(f=>{f.required_resources.forEach(p=>{l[p.required_resource_id]||(l[p.required_resource_id]=[]),l[p.required_resource_id].push(f.allocation_type_id)})});try{const f=await xE(t,n,i,l);if(f.ok){const p=await f.json();return s(ym(p.message||"Resource updated successfully!","success")),await r(),!0}else return await o(f,"Failed to update resource"),!1}catch{return s(ym("Error updating resource. Please try again later.","danger")),!1}},[e,t,n,r,o]),CE=(e=!1)=>{const[t,n]=w.useState(e);return{isEditing:t,handleEditingChange:o=>{n(o)}}},_E={"form-wrapper":"_form-wrapper_mu0yh_1"},Xa=({show:e,onClose:t,title:n,children:r,onSave:o,buttonText:s,cancelText:i="Cancel",canSave:l=!0})=>e?a.jsx("div",{style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.8)",display:"flex",alignItems:"center",zIndex:1050},children:a.jsx("div",{className:"modal fade in",tabIndex:"-1",role:"dialog","aria-hidden":"true",style:{width:"90%",maxWidth:"600px",maxHeight:"90%",overflow:"auto",backgroundColor:"white",position:"relative"},children:a.jsx("div",{className:"modal-dialog",role:"document",children:a.jsxs("div",{className:"modal-content",children:[a.jsxs("div",{className:"modal-header",children:[a.jsx("button",{type:"button",className:"close","data-dismiss":"modal",onClick:t,"aria-label":"Close",children:a.jsx("h3",{"aria-hidden":"true",className:"text-danger",children:"×"})}),a.jsx("h3",{className:"modal-title",children:n})]}),a.jsx("div",{className:"modal-body",children:r}),a.jsxs("div",{className:"modal-footer",style:{padding:"15px",textAlign:"right",borderTop:"1px solid #e5e5e5",backgroundColor:"#f8f9fa"},children:[a.jsx("button",{className:"btn btn-danger",onClick:t,children:i}),a.jsx("button",{className:"btn btn-success",onClick:o,disabled:!l,children:s})]})]})})})}):null;Xa.propTypes={show:q.bool.isRequired,onClose:q.func.isRequired,title:q.string.isRequired,children:q.node.isRequired,onSave:q.func.isRequired,buttonText:q.string,cancelText:q.string,canSave:q.bool};const Se=({children:e,color:t,dismissable:n=!1})=>a.jsxs("div",{className:`alert alert-${t} mt-3 alert-dismissible show`,role:"alert",children:[e,n&&a.jsx("button",{type:"button",className:"close","data-dismiss":"alert","aria-label":"Close",children:a.jsx("span",{"aria-hidden":"true",children:"×"})})]}),Ro=({label:e,options:t,value:n,onChange:r,...o})=>a.jsxs("div",{className:"form-group",children:[e&&a.jsx("label",{children:e}),a.jsx("select",{className:"form-control",value:n,onChange:r,...o,children:t.map(s=>a.jsxs("option",{value:s.value,children:[s.label,s.additionalInfo&&` - ${s.additionalInfo}`]},s.value))})]});Ro.propTypes={label:q.string,options:q.arrayOf(q.shape({value:q.oneOfType([q.string,q.number]).isRequired,label:q.string.isRequired,additionalInfo:q.string})).isRequired,value:q.oneOfType([q.string,q.number]),onChange:q.func.isRequired};function Yr({label:e,type:t="text",value:n,onChange:r,disabled:o=!1,infoText:s="",style:i,inputClassName:l,inputAddon:c}){return a.jsxs(a.Fragment,{children:[e&&a.jsx("label",{children:e}),s&&a.jsx("small",{className:"form-text help-block",children:s}),t==="textarea"?a.jsx("textarea",{className:`form-control ${l||""}`,value:n,onChange:r,disabled:o,rows:"6"}):c?a.jsxs("div",{className:"input-prepend",children:[a.jsx("span",{className:"add-on",children:c}),a.jsx("input",{type:t,className:`form-control ${l||""}`,style:i,value:n,onChange:r,disabled:o})]}):a.jsx("input",{type:t,className:`form-control ${l||""}`,style:i,value:n,onChange:r,disabled:o})]})}const EE="_blurred_16xcy_16",xn={"advanced-settings":"_advanced-settings_16xcy_1","header-wrapper":"_header-wrapper_16xcy_5","content-container":"_content-container_16xcy_11",blurred:EE,"warning-banner":"_warning-banner_16xcy_21","alt-warning-banner":"_alt-warning-banner_16xcy_40 _warning-banner_16xcy_21"},zf=({headerText:e,header:t,children:n,isEditing:r=!1,onEditingChange:o,warningMessage:s=""})=>{const i=e&&e.type==="label";return a.jsxs("div",{className:xn["advanced-settings"],children:[(e||t)&&a.jsxs("div",{className:xn["header-wrapper"],children:[e,t&&a.jsx("div",{className:`${xn["header-buttons-container"]} ${r?"":xn.blurred}`,children:t})]}),a.jsxs("div",{style:{width:"100%"},children:[!r&&a.jsxs("div",{className:i?`${xn["alt-warning-banner"]}`:xn["warning-banner"],children:[a.jsxs("span",{className:xn["warning-text"],children:[a.jsx("strong",{children:"CAUTION! "})," ",s]}),a.jsx("button",{className:"btn btn-danger",onClick:()=>o(!0),children:"I understand the risks"})]}),a.jsx("div",{className:`${xn["content-container"]} ${r?"":xn.blurred}`,children:n})]})]})};zf.propTypes={headerText:q.node,header:q.node,children:q.node.isRequired,isEditing:q.bool,onEditingChange:q.func.isRequired,warningMessage:q.string};const Bf=Re.memo(function({resourceDetails:t,resourceTypesOptions:n,unitTypesOptions:r,dispatch:o,isDollarValueEditing:s,onDollarValueEditingChange:i,showDollarValue:l=!0,showResourceId:c=!0,useAdvancedSettings:u=!0}){var p;const d="Dollar Value per SUs",f=l?a.jsx(Yr,{label:u?null:d,value:t.dollar_value,onChange:m=>o(Br("dollar_value",m.target.value)),type:"number",inputAddon:"$",inputClassName:"span4"}):null;return a.jsxs(a.Fragment,{children:[a.jsx(Yr,{label:"Resource Name",value:t.resource_name,onChange:m=>o(Br("resource_name",m.target.value)),inputClassName:"span8"}),c&&a.jsx(Yr,{label:"Resource Repository Key",value:t.resource_repository_key,disabled:!0,inputClassName:"span8"}),u&&l?a.jsx(zf,{headerText:a.jsx("label",{children:d}),isEditing:s,onEditingChange:i,warningMessage:"Dollar value is for reporting and should only be modified if the SU rate changes.",children:f}):f,a.jsx(Yr,{label:"Allocations Description",type:"textarea",value:t.description,infoText:"Appears below the resource name in the form when making a new request, as well as under the header Allocations Description in resource catalogs",onChange:m=>o(Br("description",m.target.value)),inputClassName:"span8"}),a.jsx(Ro,{label:"Resource Type",options:n,value:t.resource_type_id,onChange:m=>o(Br("resource_type_id",m.target.value)),className:"span8"}),a.jsx(Ro,{label:"Unit Type",options:r,value:t.unit_type_id,onChange:m=>o(Br("unit_type_id",m.target.value)),className:"span8"}),a.jsx(Yr,{label:`Minimum exchange amount, in ${(p=r.find(m=>m.value.toString()===t.unit_type_id))==null?void 0:p.label}`,value:t.min_exchange,onChange:m=>o(Br("min_exchange",m.target.value)),inputClassName:"span8"})]})});Bf.propTypes={resourceDetails:q.object.isRequired,resourceTypesOptions:q.array.isRequired,unitTypesOptions:q.array.isRequired,dispatch:q.func.isRequired,isDollarValueEditing:q.bool,onDollarValueEditingChange:q.func,showDollarValue:q.bool,showResourceId:q.bool,useAdvancedSettings:q.bool};function Nx({onClose:e}){const[t,n]=w.useState(!0),[r,o]=w.useState([]),[s,i]=w.useState(null),[l,c]=w.useState(-1),[u,d]=w.useState(null),f=Vf(u);f.resourceTypesOptions.unshift({value:0,label:"Select a resource type..."}),f.unitTypesOptions.unshift({value:0,label:"Select a unit type..."}),w.useEffect(()=>{(async()=>{const g=await fetch("/resources/addable.json");n(!1),g.status==200?o(await g.json()):i("Error retrieving resource list.")})()},[]),w.useEffect(()=>{if(l===-1)return d(null);(async()=>{const g=await fetch(`/resources/addable/${l}.json`);g.status==200?d(await g.json()):i("Error retrieving resource details.")})()},[l]);let p=null;t?p=a.jsx("p",{children:"Loading…"}):s!==null?p=a.jsx(Se,{color:"danger",children:s}):r.length==0&&(p=a.jsx(Se,{children:"There are currently no resources available to add."}));const m=[{value:-1,label:"Select a resource..."}].concat(r.map(g=>({value:g.xras_cider_resource_id,label:g.resource_descriptive_name}))),x=u?u.resource_details:null,y=!s&&x&&x.resource_name.length>0&&x.resource_type_id>0&&x.unit_type_id>0,v=g=>{g.type=="UPDATE_RESOURCE_FIELD"&&d({...u,resource_details:{...u.resource_details,[g.field]:g.value}})},h=()=>{(async()=>{const g=await fetch("/resources",{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:JSON.stringify({...x,resource_repository_key:l})});if(g.status==200){const b=await g.json();window.location=`/resources/${b.resource_id}`}else i("Error saving resource.")})()};return p===null&&(p=a.jsxs(a.Fragment,{children:[a.jsx("h2",{children:"Select a Resource to Add"}),a.jsx(Ro,{options:m,onChange:g=>c(parseInt(g.target.value))}),!u&&l!==-1?a.jsx("p",{children:"Loading…"}):null,u&&a.jsxs(a.Fragment,{children:[a.jsx("h2",{children:"Resource Properties"}),a.jsx("p",{style:{fontStyle:"italic",fontWeight:"bold"},children:"Any modifications to these resource properties will be applied globally and impact resources on other all allocations process"}),a.jsx("div",{className:_E["form-wrapper"],children:a.jsx(Bf,{resourceDetails:x,resourceTypesOptions:f.resourceTypesOptions,unitTypesOptions:f.unitTypesOptions,showResourceId:!1,showDollarValue:!1,dispatch:v})})]})]})),a.jsx(Xa,{show:!0,onClose:e,title:"Add a Resource from CIDeR",onSave:h,buttonText:"Save",canSave:y,children:p})}Nx.propTypes={onClose:q.func.isRequired};function RE({availableResources:e,unavailableResources:t=[],canAdd:n=!1,relativeUrlRoot:r}){const o=w.useMemo(()=>gm(e),[e]),s=w.useMemo(()=>gm(t),[t]),[i,l]=w.useState(o),[c,u]=w.useState(!1),d=w.useRef(null),f=w.useRef(null),p="Active",m="Inactive",[x,y]=w.useState(p),v=j=>{y(j),console.log(j),j==p?l(o):l(s)};function h(j,C){C.preventDefault(),y(j),v(j)}w.useEffect(()=>{l(o)},[o]);const g=(j,C)=>{d.current=C},b=(j,C)=>{if(j.preventDefault(),d.current===C)return;const E=[...i],_=E[d.current];E.splice(d.current,1),E.splice(C,0,_),d.current=C,l(E);const{clientY:N}=j,R=130;N<R?vm(-1,f):window.innerHeight-N<R?vm(1,f):Fc(f)},S=()=>{d.current=null,Fc(f),cE(r,i)};return w.useEffect(()=>()=>Fc(f),[]),a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:Wt["resources-container"],children:[n&&a.jsx("button",{className:"btn btn-primary pull-right",onClick:()=>u(!0),children:"Add a Resource from CIDeR"}),a.jsx("h2",{children:"Select a resource from the list to modify"}),a.jsx("p",{className:Wt["drag-instruction"],children:"Drag items to reorder the list."}),a.jsxs("div",{className:"w-full max-w-md mx-auto p-4",children:[a.jsxs("ul",{className:"nav nav-tabs",children:[a.jsx("li",{className:"nav-item",children:a.jsx("a",{className:`nav-link ${x===p?"active":""}`,"data-toggle":x===p?"tab":void 0,style:{cursor:"default",...x===p?{border:"1px solid #ddd",borderBottomColor:"transparent",color:"#555",backgroundColor:"#fff"}:{}},onClick:j=>h(p,j),children:p})}),a.jsx("li",{className:"nav-item",children:a.jsx("a",{className:`nav-link ${x===m?"active":""}`,"data-toggle":x===m?"tab":void 0,style:{cursor:"default"},onClick:j=>h(m,j),children:m})})]}),a.jsxs("div",{className:Wt["resources-list"],children:[a.jsxs("div",{className:Wt["resources-header"],children:[a.jsx("span",{className:Wt["header-name"],children:"Resource Name"}),a.jsx("span",{className:Wt["header-repo"],children:"Repository Key"})]}),i.map((j,C)=>a.jsxs("div",{className:`${Wt["resources-item"]}`,draggable:!0,onDragStart:E=>g(E,C),onDragOver:E=>b(E,C),onDrop:S,children:[a.jsx("span",{className:Wt["drag-handle"]}),a.jsx("span",{className:Wt["resource-name"],children:a.jsx("a",{href:`${r}/resources/${j.resource_id}`,className:Wt["resource-link"],children:j.display_resource_name})}),a.jsx("span",{className:Wt["resource-repo"],children:j.resource_repository_key||"N/A"})]},j.resource_id))]})]})]}),c&&a.jsx(Nx,{onClose:()=>u(!1)})]})}function Ur(){return a.jsx("div",{className:"spinner-border",role:"status",children:a.jsx("span",{className:"visually-hidden",children:"Loading..."})})}const NE="_grid_afccc_1",kE="_important_afccc_30",OE="_input_afccc_34",TE="_edited_afccc_38",PE="_disabled_afccc_46",IE="_scroll_afccc_59",_r={grid:NE,important:kE,input:OE,edited:TE,disabled:PE,scroll:IE};function $E({column:e,row:t,style:n={}}){const r=e.format?e.format(t[e.key],t):t[e.key],o=["cell"];return e.class&&o.push(e.class),e.rowClass&&o.push(e.rowClass(t)),a.jsx("td",{className:o.join(" "),style:n,children:r})}const qf=({title:e,placement:t,children:n})=>(w.useEffect(()=>($('[data-toggle="tooltip"]').tooltip(),()=>{$('[data-toggle="tooltip"]').tooltip("destroy")}),[]),a.jsx("span",{"data-toggle":"tooltip","data-placement":t,title:e,style:{margin:"10px"},children:n}));qf.propTypes={title:q.string.isRequired,placement:q.oneOf(["top","bottom","left","right"]),children:q.node.isRequired};qf.defaultProps={placement:"top"};const ME="_datepicker_19wnv_1",AE="_error_19wnv_1",xm={datepicker:ME,error:AE},DE=({value:e,onChange:t,disabled:n=!1,style:r,className:o="",minDate:s="",maxDate:i="",error:l=""})=>{const c=l;return a.jsx("div",{className:`w-full ${o}`,children:a.jsx("input",{type:"date",style:r,className:`${xm.datepicker} ${c?xm.error:""}`,value:e||"",onChange:u=>t(u.target.value),disabled:n,min:s||"1900-01-01",max:i||"2100-12-31"})})},es=(e,t,n)=>{if(t.onChange){t.onChange(n,e);return}const r=e[t.key];r!=null&&r.onChange&&r.onChange(n)},FE={text:$E,select:({column:e,row:t,style:n})=>a.jsx("td",{style:n,children:a.jsx(Ro,{label:"",options:t[e.key].options,value:t[e.key].value,onChange:r=>es(t,e,r.target.value),style:{width:"100%",margin:0}})}),input:({column:e,row:t,style:n})=>a.jsx("td",{style:n,children:a.jsx(Yr,{label:"",type:"text",disabled:t[e.key].disabled,value:t[e.key].value,onChange:r=>es(t,e,r.target.value),style:{width:"92%",margin:0}})}),checkbox:({column:e,row:t,style:n})=>a.jsx("td",{style:n,children:a.jsx("input",{type:"checkbox",checked:t[e.key].checked,onChange:r=>es(t,e,r.target.checked)})}),date:({column:e,row:t,style:n})=>{const r=t[e.key];return!(r!=null&&r.value)&&typeof r!="object"?a.jsx("td",{style:n,children:r||""}):a.jsx("td",{style:n,children:a.jsx(DE,{value:r.value,onChange:o=>es(t,e,o),disabled:r.disabled,style:{width:"92%",margin:0},minDate:e.minDate,maxDate:e.maxDate,error:r.error})})},action:({column:e,row:t,style:n})=>a.jsx("td",{style:n,children:t.rate_type==="Discount"&&a.jsx("button",{className:"btn btn-link text-danger",onClick:()=>{var r;return es(t,e,(r=t[e.key])==null?void 0:r.id)},children:a.jsx("i",{className:"fa fa-trash"})})})};function mn({columns:e,rows:t,classes:n,frozenColumns:r=0,minWidth:o,rowClasses:s=[],scroll:i=!0,scrollBehavior:l="smooth",scrollRowIndex:c=0}){const u=w.useRef();w.useLayoutEffect(()=>{if(!i||!u.current)return;const y=u.current.querySelector(`tbody tr:nth-child(${c+1})`);y&&y.scrollIntoView({behavior:l,block:"nearest",inline:"nearest"})},[i,c,l]);const d=[0];for(let y=0;y<r;y++)d[y+1]=d[y]+(e[y].width||100);const f=(y,v)=>y<r?{position:"sticky",left:`${d[y]}px`,minWidth:`${e[y].width||100}px`,width:`${e[y].width||100}px`,zIndex:v||1}:{},p=e.map((y,v)=>a.jsxs("th",{className:y.headerClass||y.class||"",style:f(v,100),children:[y.formatHeader?y.formatHeader(y.name,y):y.name,y.tooltip&&a.jsx(qf,{title:y.tooltip,placement:"bottom",children:a.jsx("i",{className:"icon-info-sign"})})]},y.key)),m=t.map((y,v)=>{const h=e.map((g,b)=>{const S=FE[g.type||"text"];return a.jsx(S,{column:g,row:y,style:f(b)},g.key)});return a.jsx("tr",{className:s[v]||"",children:h},v)}),x={};return o&&(x.minWidth=o),a.jsx("div",{className:`${_r.grid} ${i?_r.scroll:""} ${n||""}`,ref:u,children:a.jsxs("table",{className:"table table-bordered",style:x,children:[a.jsx("thead",{children:a.jsx("tr",{children:p})}),a.jsx("tbody",{children:m})]})})}const id={"header-buttons":"_header-buttons_15oxx_1","allocation-types-grid":"_allocation-types-grid_15oxx_6","vertical-align-center":"_vertical-align-center_15oxx_10"},kx=({onAddAllocationType:e,onAddRequiredResource:t})=>a.jsxs("div",{className:id["header-buttons"],children:[a.jsxs("button",{className:"btn btn-primary",onClick:e,children:[a.jsx("i",{className:"fa fa-plus"})," Add Allocation Type"]}),a.jsxs("button",{className:"btn btn-primary",onClick:t,children:[a.jsx("i",{className:"fa fa-plus"})," Add Required Resource"]})]});kx.propTypes={headerText:q.node,onAddAllocationType:q.func.isRequired,onAddRequiredResource:q.func.isRequired};const Ox=Re.memo(function({columns:t,rows:n}){return a.jsxs("div",{className:id["allocation-types-grid"],children:[a.jsx(mn,{columns:t,rows:n,rowClasses:Array(n.length).fill(id["vertical-align-center"]),scroll:!1}),a.jsx("p",{style:{margin:"0",fontStyle:"italic",fontWeight:"bold"},children:"Note: You may need to contact your Allocations Coordinator if you have added this resource to an allocation type."})]})});Ox.propTypes={columns:q.array.isRequired,rows:q.array.isRequired};const qr={"exchange-rates-grid":"_exchange-rates-grid_5qkd5_1","header-container":"_header-container_5qkd5_5","header-buttons":"_header-buttons_5qkd5_11","vertical-align-center":"_vertical-align-center_5qkd5_18","error-summary":"_error-summary_5qkd5_35"},Tx=Re.memo(function({columns:t,rows:n,onAddDiscountRate:r,dateErrors:o=[]}){return a.jsxs("div",{className:qr["exchange-rates-grid"],children:[a.jsxs("div",{className:qr["header-container"],children:[a.jsx("h2",{className:qr["header-title"],children:"Exchange Rates"}),a.jsx("div",{className:qr["header-buttons"],children:a.jsxs("button",{className:"btn btn-primary",onClick:r,children:[a.jsx("i",{className:"fa fa-plus"})," Add Discount Rate"]})})]}),a.jsx(mn,{columns:t,rows:n,rowClasses:Array(n.length).fill(qr["vertical-align-center"]),scroll:!1}),o.length>0&&a.jsx("div",{className:qr["error-summary"],children:a.jsx("ul",{children:o.map((s,i)=>a.jsx("li",{children:s},i))})})]})});Tx.propTypes={columns:q.array.isRequired,rows:q.array.isRequired,onAddDiscountRate:q.func.isRequired,dateErrors:q.array};const LE=(e,t)=>{const n=w.useCallback(m=>{var y,v;t({type:"DELETE_EXCHANGE_RATE",payload:m}),(((v=(y=e==null?void 0:e.resource_details)==null?void 0:y.exchange_rates)==null?void 0:v.discount_rates.filter(h=>h.id!==m))||[]).forEach(h=>{h.begin_date&&h.end_date&&t({type:"UPDATE_EXCHANGE_RATE",payload:{rateId:h.id,changes:{start_date_error:"",end_date_error:""}}})})},[t,e]),r=[{key:"rate_type",name:"Rate Type",width:150},{key:"rate",name:"Exchange Rate",width:100,type:"input",tooltip:"Exchange rate is the cost in ACCESS Credits of one resource unit. ACCESS Credits / exchange rate = resource units"},{key:"conversion",name:"Resource Units per ACCESS Credit",width:150},{key:"start_date",name:"Start Date",width:150,type:"date",minDate:new Date().toISOString().split("T")[0]},{key:"end_date",name:"End Date",width:150,type:"date",minDate:new Date().toISOString().split("T")[0]},{key:"actions",name:"",width:80,type:"action",onChange:n}],o=m=>{t({type:"UPDATE_BASE_RATE",payload:m})},s=(m,x)=>{const y={exchange_rate:x},v={};x?v.rate_error="":v.rate_error="Exchange Rate cannot be empty",t({type:"UPDATE_EXCHANGE_RATE",payload:{rateId:m,changes:{...y,...v}}})},i=()=>{var y,v;const m=[];return(((v=(y=e==null?void 0:e.resource_details)==null?void 0:y.exchange_rates)==null?void 0:v.discount_rates)||[]).forEach(h=>{h.start_date_error&&m.push(h.start_date_error),h.end_date_error&&m.push(h.end_date_error),h.rate_error&&m.push(h.rate_error)}),m.filter((h,g)=>h&&h!==""&&(!h.includes("overlaps")||m.indexOf(h)===g))},l=m=>{const x=new Date(m);return new Intl.DateTimeFormat("en-US",{timeZone:"UTC",month:"numeric",day:"numeric",year:"numeric"}).format(x)},c=(m,x,y,v)=>{const h=new Date(m).getTime(),g=new Date(x).getTime(),b=new Date(y).getTime(),S=new Date(v).getTime();return h<=S&&b<=g},u=(m,x)=>{let y="";if(m.begin_date&&m.end_date){const v=x.filter(h=>h.id!==m.id);for(const h of v)if(h.begin_date&&h.end_date&&c(m.begin_date,m.end_date,h.begin_date,h.end_date)){y=`The selected date range (${l(m.begin_date)} to ${l(m.end_date)}) overlaps with an existing discount rate (${l(h.begin_date)} to ${l(h.end_date)})`;break}}return y},d=(m,x,y)=>{var R,O;const v={start_date:"begin_date",end_date:"end_date"},h=k=>{const P=new Date(k);return new Intl.DateTimeFormat("en-US",{timeZone:"UTC",month:"numeric",day:"numeric",year:"numeric"}).format(P)},g=((O=(R=e==null?void 0:e.resource_details)==null?void 0:R.exchange_rates)==null?void 0:O.discount_rates)||[],b=g.find(k=>k.id===m);if(!b)return;const S={[v[x]]:y},j={},C=x==="end_date",E=()=>{if(!y)return j[`${x}_error`]="Date cannot be empty or invalid",!1;const k=r.find(V=>V.key===x),P=(k==null?void 0:k.minDate)||"1900-01-01",U=(k==null?void 0:k.maxDate)||"2100-12-31",F=C&&b.begin_date?b.begin_date:P;return y<F?(j[`${x}_error`]=`${x.replace("_"," ")} ${h(y)} cannot be before ${h(F)}`,!1):y>U?(j[`${x}_error`]=`${x.replace("_"," ")} cannot be after ${h(U)}`,!1):(j[`${x}_error`]="",!0)},_=()=>{const k=x==="end_date"?y:b.end_date;if(x==="start_date"&&k){if(y>k)return j.end_date_error=`end date ${h(k)} cannot be before ${h(y)}`,!1;j.end_date_error=j.end_date_error||""}return!0},N=()=>{console.log("validating overlaps");const k=x==="start_date"?y:b.begin_date,P=x==="end_date"?y:b.end_date;if(k&&P){const U=u({...b,begin_date:k,end_date:P},g);return j.start_date_error=U,j.end_date_error=U,!U}return!0};if(!E()){t({type:"UPDATE_EXCHANGE_RATE",payload:{rateId:m,changes:{...S,...j}}});return}_(),N(),C&&!b.begin_date?j.start_date_error="Date cannot be empty or invalid":!C&&!b.end_date&&(j.end_date_error="Date cannot be empty or invalid"),t({type:"UPDATE_EXCHANGE_RATE",payload:{rateId:m,changes:{...S,...j}}})},f=()=>{var j,C;const m=((C=(j=e==null?void 0:e.resource_details)==null?void 0:j.exchange_rates)==null?void 0:C.discount_rates)||[];let y=new Date;m.forEach(E=>{if(E.end_date){const _=new Date(E.end_date);_>y&&(y=_)}});const v=new Date(y);v.setDate(v.getDate()+1);const h=v.toISOString().split("T")[0],g=new Date(v);g.setDate(g.getDate()+15);const b=g.toISOString().split("T")[0],S={id:Date.now(),exchange_rate:"1.0",begin_date:h,end_date:b,is_new:!0};t({type:"ADD_EXCHANGE_RATE",payload:S})};return{exchangeRateColumns:r,exchangeRateRows:(()=>{var b,S;const m=(b=e==null?void 0:e.resource_details)==null?void 0:b.exchange_rates,x=(m==null?void 0:m.base_rate)??"",y=(m==null?void 0:m.discount_rates)||[],v=new Date().toISOString().split("T")[0],h=((S=e==null?void 0:e.resource_details)==null?void 0:S.unit_type)||"Resource Units",g=j=>!j||Number(j)===0?"-":`${(1/Number(j)).toFixed(2)} ${h}`;return[{rate_type:"Base Rate",rate:{value:x.toString(),onChange:j=>o(j)},conversion:g(x)},...y.map(j=>{var N;const C=j.is_new||j.begin_date>v,E=C||j.begin_date==="",_=j.is_new||j.end_date>=v||j.end_date==="";return{rate_type:"Discount",rate:{value:((N=j.exchange_rate)==null?void 0:N.toString())||"",onChange:C?R=>s(j.id,R):null,disabled:!C},conversion:g(j.exchange_rate),start_date:{value:j.begin_date||"",onChange:R=>d(j.id,"start_date",R),error:j.start_date_error,disabled:!E},end_date:{value:j.end_date||"",onChange:R=>d(j.id,"end_date",R),error:j.end_date_error,disabled:!_},actions:{id:j.id}}})]})(),handleAddDiscountRate:f,handleDeleteRate:n,dateErrors:i()}};function Px({resourceId:e,relativeUrlRoot:t,setExternalSubmit:n}){const{state:r,dispatch:o,handleError:s,fetchData:i}=bE(e,t),{isEditing:l,handleEditingChange:c}=CE(),{resourceData:u,loading:d,errors:f,successMessage:p}=r,m=u==null?void 0:u.resource_details,x=u==null?void 0:u.uses_exchange_rates,{allowedActionsOptions:y,resourceTypesOptions:v,unitTypesOptions:h,availableResources:g,availableAllocationTypes:b}=Vf(u),{showAddResourceModal:S,setShowAddResourceModal:j,showAddAllocationTypeModal:C,setShowAddAllocationTypeModal:E,selectedNewResource:_,handleSelectNewResource:N,handleSaveResources:R,selectedNewAllocationType:O,handleSelectNewAllocationType:k,handleSaveAllocationType:P,handleAllowedActionChange:U,handleCommentChange:F,handleRequiredResourceChange:V}=SE(u,m,o),{exchangeRateColumns:Z,exchangeRateRows:T,handleAddDiscountRate:L,dateErrors:A}=LE(u,o),H=jE(m,e,t,i,s,o);w.useEffect(()=>{n&&A.length==0?n(H):n(null)},[H,n,A]);const{allocationColumns:B,allocationRows:X}=wE(m,g,_,y,U,F,V),[J,ee]=w.useState(!1);return d?a.jsx(Ur,{}):f.length>0?a.jsx("div",{children:f.map((Q,te)=>a.jsx(Se,{color:"danger",dismissable:!0,children:Q},te))}):u?a.jsxs("div",{className:"edit-resource",children:[p.message&&a.jsx(Se,{color:p.color,dismissable:!0,children:p.message}),a.jsxs("div",{children:[a.jsx("h2",{children:"Resource Properties"}),a.jsx("div",{style:{marginBottom:"0.75rem"},children:a.jsx("p",{style:{margin:"0",fontStyle:"italic",fontWeight:"bold"},children:"Any modifications to these resource properties will be applied globally and impact resources on other all allocations process"})}),a.jsx(Bf,{resourceDetails:m,resourceTypesOptions:v,unitTypesOptions:h,dispatch:o,isDollarValueEditing:J,onDollarValueEditingChange:ee})]}),x&&a.jsx(Tx,{columns:Z,rows:T,onAddDiscountRate:L,dateErrors:A}),a.jsx(zf,{headerText:a.jsx("h2",{children:"Allocation Types"}),header:a.jsx(kx,{onAddAllocationType:()=>l&&E(!0),onAddRequiredResource:()=>l&&j(!0)}),isEditing:l,onEditingChange:c,warningMessage:`Incorrect allocations
|
|
52
|
+
`),me}Ga(()=>{Q.current=void 0,X.current=void 0,H.current=Ce});const De=ie.useMemo(()=>ie.createElement(v,{...Ce,ref:N}),[N,v,Ce]);return ie.useMemo(()=>x?ie.createElement(O.Provider,{value:A},De):De,[O,De,A])}const C=ie.memo(S);if(C.WrappedComponent=v,C.displayName=S.displayName=g,c){const _=ie.forwardRef(function(R,O){return ie.createElement(C,{...R,reactReduxForwardedRef:O})});return _.displayName=g,_.WrappedComponent=v,ed(_,v)}return ed(C,v)}}var T_=O_;function P_({store:e,context:t,children:n,serverState:r,stabilityCheck:o="once",identityFunctionCheck:s="once"}){const i=ie.useMemo(()=>{const u=vx(e);return{store:e,subscription:u,getServerState:r?()=>r:void 0,stabilityCheck:o,identityFunctionCheck:s}},[e,r,o,s]),l=ie.useMemo(()=>e.getState(),[e]);Ga(()=>{const{subscription:u}=i;return u.onStateChange=u.notifyNestedSubs,u.trySubscribe(),l!==e.getState()&&u.notifyNestedSubs(),()=>{u.tryUnsubscribe(),u.onStateChange=void 0}},[i,l]);const c=t||Fn;return ie.createElement(c.Provider,{value:i},n)}var Bn=P_;function bx(e=Fn){const t=e===Fn?px:Mf(e),n=()=>{const{store:r}=t();return r};return Object.assign(n,{withTypes:()=>n}),n}var I_=bx();function $_(e=Fn){const t=e===Fn?I_:bx(e),n=()=>t().dispatch;return Object.assign(n,{withTypes:()=>n}),n}var ge=$_();VC(LC.useSyncExternalStoreWithSelector);C_(w.useSyncExternalStore);const nn="https://allocations.access-ci.org",ne={creditAlertThreshold:1e3,resourceTypeIcons:{credit:"cash-coin",compute:"cpu-fill",storage:"hdd-fill",program:"person-square"},routes:{edit_request_action_path:(e,t)=>`/requests/${e}/actions/${t}/edit`,edit_request_path:e=>`/requests/${e}/edit`,how_to_path:()=>"/how-to",get_your_first_project_path:()=>`${nn}/get-your-first-project`,profile_path:()=>`${nn}/profile`,project_types_path:()=>`${nn}/project-types`,projects_path:()=>`${nn}/projects`,projects_save_users_path:()=>"/projects/save_users",renew_request_path:e=>`${nn}/requests/${e}/renew`,request_action_path:(e,t)=>`${nn}/requests/${e}/actions/${t}`,request_actions_path:e=>`${nn}/requests/${e}/actions`,request_path:e=>`${nn}/requests/${e}`,resources_path:()=>`${nn}/resources`,search_people_path:()=>`${nn}/search/people`,usage_detail_path:(e,t)=>`/usage/${e}/${t}`},roleIcons:{PI:"person-fill-check","Co-PI":"person-fill-add","Allocation Manager":"person-fill-gear",User:"people-fill"}},mo=(e,t,n="round")=>{const r=Math.pow(10,t||0);return Math[n](e*r)/r},M_=e=>new Date(`${e}T00:00:00`),A_={year:"numeric",month:"short",day:"numeric"},go=(e,t)=>M_(e).toLocaleString("en-us",t||A_),it=(e,{abbreviate:t=!1,decimalPlaces:n=void 0}={})=>{if(t){let r=0;for(;Math.abs(e)/Math.pow(1e3,r)>=1e3;)r+=1;const o=["","K","M","B","T","Q"][r];return`${(e/Math.pow(1e3,r)).toLocaleString("en-US",{maximumSignificantDigits:3})}${o}`}return e.toLocaleString("en-US",{maximumFractionDigits:n,minimumFractionDigits:n})},Ff=(e,t)=>{if(e.startDate&&e.endDate){const o=go(e.startDate,t),s=go(e.endDate,t);return`${e.allocationType}: ${o} to ${s}`}const n=go(e.entryDate,t),r=e.status=="Incomplete"?"Started":"Submitted";return`${e.allocationType}: ${r} ${n}`},Tn=e=>a.jsx("i",{className:`bi bi-${e}`}),ii=e=>{const t=e.match(/^([^\(\)]+) (\(([^\)]+)\))?$/);return{full:e,short:t&&t[3]||null}},cm=e=>{const t=ii(e.name);return t.short||t.full},Qa=(e,t)=>e.isCredit>t.isCredit||e.isActive>t.isActive||cm(e)<cm(t)?-1:1,um=(...e)=>{for(let t of e)if(t!=null)return t;return null},wx=(e,t="and",n=", ")=>e.reduce((r,o,s)=>a.jsxs(a.Fragment,{children:[r,e.length-1>s?n:` ${t} `,o]})),Lf=e=>e?a.jsxs(a.Fragment,{children:[Tn("check-circle")," Yes"]}):a.jsxs(a.Fragment,{children:[Tn("x-circle")," No"]}),Uf=e=>wx(e.users.filter(({role:t})=>["pi","co_pi","allocation_manager"].includes(t)).map(t=>`${t.firstName} ${t.lastName}`),"or"),dm=(e,t)=>t==1&&e.endsWith("s")?e.slice(0,-1):e,D_=(e,t,n)=>`${it(t)} ${dm(n,t)} / ${dm(e,1)}`,Sx=e=>{let t=0,n=0;for(let r of e.resources){if(r.isBoolean)continue;let{unitCost:o}=r.exchangeRates.base;t+=r.allocated*o,n+=Math.min(r.used,r.allocated)*o}return t>0?n/t:0},$l=[{role:"pi",name:"PI",xrasRole:"PI"},{role:"co_pi",name:"Co-PI",xrasRole:"CoPI"},{role:"allocation_manager",name:"Allocation Manager",xrasRole:"Allocation Manager"},{role:"user",name:"User",xrasRole:"User"}],jx={};for(let e of $l)jx[e.role]=e;const td={};for(let{role:e,xrasRole:t}of $l)td[e]=t;const nd=["info","success","secondary","warning","danger"];function rd(e,t="total"){const n=e.exchangeRates[e.requested<=e.allocated?"base":"current"].unitCost;let r=(e.requested-e.allocated)*n;return t!="total"?r:r+e.allocated*e.exchangeRates.base.unitCost}function ai(e){e&&(ne.routes={...ne.routes,...e})}const od={user:{colors:["#ffc42d","#fea92c","#f98f30","#f07537"]},rp:{colors:["#48c0b9","#2e9da4","#207b8b","#1a5b6e"]}},Ac={};function Cx(e,t=3){let n=0;for(;e/Math.pow(1e3,n)>1e3;)n+=1;const r=e.toString().length,o=Math.pow(10,r-t);return(Math.round(e/o)*o/Math.pow(1e3,n)).toString()+["","K","M","B","T"][n]}async function F_(){return await(await fetch("https://basemaps-api.arcgis.com/arcgis/rest/services/styles/ArcGIS:Community?type=style&token=AAPK220079f462f24fda89c27fa210c3f887EJPCECuukKD8PnCIBqktgGTKZWPlVXWjRoSsZYGkOJ12QemGItZ4liRZkcUzYyme")).json()}async function L_(e){if(Ac[e])return Ac[e];const t=document.location,n=`${t.protocol}//${t.host}${t.pathname}`,o=await(await fetch(`${n}/${e}`)).json();return Ac[e]=o,o}function U_(e){const t=[...e.creditLines.features.map(r=>r.properties.credits)],n=[...e.rpPoints.features.map(r=>r.properties.rpCredits),...e.userPoints.features.map(r=>r.properties.userCredits)];return{lines:pm(t),points:pm(n)}}function fm({activeOrg:e,basemapStyle:t,creditLevels:n,creditType:r,geoJSON:o,organizationType:s}){const i={},l=[];if(o&&n){const u=s==="user"?"rp":"user",d=o[`${s}Points`],f=o[`${u}Points`],p=`${s}Credits`,m=`${u}Credits`;i.organizations={type:"geojson",data:d};const x={user:[],rp:[]},y=[];n.points.forEach((h,g)=>{Object.keys(od).forEach(b=>{x[b].push(h[1],od[b].colors[g])}),y.push(h[1],5*(g+1))});const v=[];if(n.lines.forEach((h,g)=>{v.push(h[1],1*(g+1))}),l.push({id:"organizations",type:"circle",source:"organizations",paint:{"circle-radius":["interpolate",["linear"],["get",p],...y],"circle-color":["interpolate",["linear"],["get",p],...x[s]],"circle-opacity":e?["match",["id"],e.id,1,.3]:1,"circle-stroke-color":"#ffffff","circle-stroke-width":1}}),e&&r!=="allocated"){i.opp={type:"geojson",data:f};const h=["get",e.id.toString(),["get",`${m}Map`]];l.push({id:"opp",type:"circle",source:"opp",filter:["has",e.id.toString(),["get",`${m}Map`]],paint:{"circle-radius":["interpolate",["linear"],h,...y],"circle-color":["interpolate",["linear"],h,...x[u]],"circle-stroke-color":"#ffffff","circle-stroke-width":1}}),i.credits={type:"geojson",data:o.creditLines},l.push({id:"credits",type:"line",source:"credits",filter:["==",["get",`${s}_organization_id`],e.id],paint:{"line-color":"#444444","line-opacity":.4,"line-width":["interpolate",["linear"],["get","credits"],...v]}})}}const c=t||{version:8,sources:{},layers:[]};return{...c,sources:{...c.sources,...i},layers:[...c.layers.filter(u=>u.id!=="Marine waterbody/label/2x large"),...l]}}function V_(e,t,n,r,o=20){return[...Array(o+1).keys()].map(s=>s/o).map(s=>{let i=s*(n-e)+e,l=s*(r-t)+t+Math.abs(Math.sin(s*Math.PI)*(n-e)*.1);return[i,l]})}function z_(e,t,n){const r={};return e.features.forEach(s=>r[s.id]={type:s.type,geometry:s.geometry,id:s.id,properties:{name:s.properties.name,abbr:s.properties.abbr,userCredits:0,userCreditsMap:{},rpCredits:0,rpCreditsMap:{}}},{}),{creditLines:{type:"FeatureCollection",features:t.result.filter(s=>r[s.user_organization_id]!==void 0&&(n==="allocated"||r[s.rp_organization_id]!==void 0)).map(s=>{const i=r[s.user_organization_id],l=r[s.rp_organization_id];if(i.properties.userCredits+=s.credits,l&&(l.properties.rpCredits+=s.credits),i.properties.userCreditsMap[s.rp_organization_id]=(i.properties.userCreditsMap[s.rp_organization_id]||0)+s.credits,l&&(l.properties.rpCreditsMap[s.user_organization_id]=(l.properties.rpCreditsMap[s.user_organization_id]||0)+s.credits),n!=="allocated")return{type:"Feature",geometry:{type:"LineString",coordinates:V_(...r[s.user_organization_id].geometry.coordinates,...r[s.rp_organization_id].geometry.coordinates)},properties:s}}).filter(s=>s!==void 0)},userPoints:{type:"FeatureCollection",features:Object.values(r).filter(s=>s.properties.userCredits>0).sort((s,i)=>s.properties.userCredits>i.properties.userCredits?-1:1)},rpPoints:{type:"FeatureCollection",features:Object.values(r).filter(s=>s.properties.rpCredits>0).sort((s,i)=>s.properties.rpCredits>i.properties.rpCredits?-1:1)}}}function pm(e,t=[0,.3,.6,.9]){return t.map((n,r)=>{const o=B_(e,n),s=r===t.length-1?"+":"";return[`${Cx(Math.round(o))}${s}`,o]})}function B_(e,t){e.sort((s,i)=>s-i);const n=(e.length-1)*t,r=Math.floor(n),o=n-r;return e[r+1]!==void 0?e[r]+o*(e[r+1]-e[r]):e[r]}const q_="_fullscreen_1iid9_6",H_="_map_1iid9_14",$i={"allocations-map":"_allocations-map_1iid9_1",fullscreen:q_,map:H_},W_="_group_11k83_1",K_="_button_11k83_6",Y_="_icon_11k83_16",Dc={group:W_,button:K_,icon:Y_};function hm({choices:e,disabledValues:t=[],label:n,value:r,setValue:o}){const s=[];return e.forEach(([i,l])=>s.push(a.jsx("input",{type:"radio",className:"btn-check",name:i,id:i,autoComplete:"off",checked:r===i,onChange:()=>o(i),disabled:t.includes(i)},i),a.jsxs("label",{className:`btn btn-outline-primary ${Dc.button}`,htmlFor:i,disabled:t.includes(i),children:[r===i?a.jsx("i",{className:`bi bi-check ${Dc.icon}`}):null," ",l]},`${i}-label`))),a.jsx("div",{className:"mb-2",children:a.jsx("div",{className:`btn-group ${Dc.group}`,role:"group","aria-label":n,children:s})})}const G_="_controls_1be4t_1",Q_={controls:G_};function X_({creditType:e,organizationType:t,setCreditType:n,setOrganizationType:r}){return a.jsxs("div",{className:Q_.controls,children:[a.jsx("h2",{children:"ACCESS Allocations"}),a.jsx(hm,{choices:[["allocated","Allocations"],["exchanged","Exchanges"],["used","Usage"]],label:"Credit Type",value:e,setValue:n}),a.jsx(hm,{choices:[["user","By Research Institution"],["rp","By Resource Provider"]],disabledValues:e==="allocated"?["rp"]:[],label:"Organization Type",value:t,setValue:r})]})}const Z_="_legend_odgg9_1",J_="_symbols_odgg9_17",eE="_symbol_odgg9_17",ra={legend:Z_,symbols:J_,symbol:eE};function tE(e,t){const n=2*e+2;return a.jsx("svg",{viewBox:`0 0 ${n} ${n}`,xmlns:"http://www.w3.org/2000/svg",stroke:"white",strokeWidth:"1",height:n,width:n,children:a.jsx("circle",{fill:t,cx:e+1,cy:e+1,r:e})})}function nE({activeOrg:e,creditLevels:t,organizationType:n}){if(e||!t)return;const r=t.points.map((o,s)=>a.jsxs("div",{className:ra.symbol,children:[tE(5*(s+1),od[n].colors[s]),a.jsx("br",{}),a.jsx("span",{className:"label",children:o[0]})]},o[0]));return a.jsxs("div",{className:ra.legend,children:[a.jsxs("h2",{className:"fs-6 mt-0 mb-0",children:["ACCESS Credits ",a.jsx("small",{children:"or credit equivalents"})]}),a.jsx("div",{className:ra.symbols,children:r})]})}const rE="_info_oxxoh_1",oE="_user_oxxoh_7",sE="_rp_oxxoh_10",iE="_credits_oxxoh_15",oa={info:rE,user:oE,rp:sE,credits:iE};function mm(e,t,n){e.sort((o,s)=>s[1]-o[1]);const r=e.slice(0,3).map(o=>o[0]);return e.length>3&&(r[2]=`${e.length-2} other ${n}s`),r.reduce((o,s,i,l)=>[o,a.jsx("span",{className:`name ${oa[t]}`,children:s},s),[""," and ",", "][l.length-i-1]],[])}function aE({activeOrg:e,creditType:t,organizationMap:n,organizationType:r}){if(!e||!n)return;const o=e.properties,s=o[`${r}Credits`],i=r==="rp"?"user":"rp",l=JSON.parse(o[`${r}CreditsMap`]),c={user:[],rp:[]};return c[r].push([o.name,s]),Object.keys(l).forEach(u=>c[i].push([n[u],l[u]])),a.jsx("div",{className:`${ra.legend} ${oa.info}`,children:a.jsxs("p",{className:oa[r],children:["Researchers at ",mm(c.user,"user","research institution")," ",t==="allocated"?"were ":"",t," ",a.jsxs("span",{className:oa.credits,children:[Cx(s)," ACCESS Credits"]}),t!=="allocated"?a.jsxs(a.Fragment,{children:[" ",t==="exchanged"?"for":"on"," resources at"," ",mm(c.rp,"rp","resource provider")]}):"","."]})})}function lE(){const e=w.useRef(null),t=w.useRef(null),[n,r]=w.useState(null),[o,s]=w.useState(null),[i,l]=w.useState(null),[c,u]=w.useState(!1),[d,f]=w.useState(null),[p,m]=w.useState(null),[x,y]=w.useState(null),[v,h]=w.useState("user"),[g,b]=w.useState("exchanged");return w.useEffect(()=>{(async()=>s(await F_()))()},[]),w.useEffect(()=>{(async S=>{const[j,C]=await Promise.all(["organizations",`credits_${S}`].map(L_));if(!x){const _={};j.features.forEach(N=>_[N.id.toString()]=N.properties.name),y(_)}const E=z_(j,C,g);f(E),S==="exchanged"&&!i&&l(U_(E))})(g)},[g]),w.useEffect(()=>{p&&p.setStyle(fm({activeOrg:n,basemapStyle:o,creditLevels:i,creditType:g,geoJSON:d,organizationType:v}))},[n,d,p,v]),w.useEffect(()=>{p&&(p.on("mousemove","organizations",S=>r(S.features.length?S.features[0]:null)),p.on("mouseleave","organizations",()=>r(null)))},[p]),w.useEffect(()=>{p&&p.resize()},[c]),w.useEffect(()=>{g==="allocated"&&h("user")},[g]),w.useLayoutEffect(()=>m(new maplibregl.Map({container:t.current,style:fm({activeOrg:n,basemapStyle:o,creditLevels:i,creditType:g,geoJSON:d,organizationType:v}),center:[-111.01,38.88],zoom:3.4,hash:!0})),[]),w.useLayoutEffect(()=>e.current.addEventListener("keydown",S=>{S.key==="Escape"&&u(!1)}),[]),a.jsxs("section",{className:`${$i["allocations-map"]} ${c?$i.fullscreen:"border border-3 border-primary"}`,ref:e,children:[a.jsx("div",{className:$i.map,ref:t}),a.jsx(X_,{creditType:g,fullscreen:c,organizationType:v,setCreditType:b,setFullscreen:u,setOrganizationType:h}),a.jsx(nE,{activeOrg:n,creditLevels:i,organizationType:v}),a.jsx(aE,{activeOrg:n,creditType:g,organizationMap:x,organizationType:v}),a.jsx("button",{title:`${c?"Exit":"Enter"} Fullscreen`,className:$i.fullscreen,onClick:()=>u(!c),children:a.jsx("i",{className:`bi ${c?"bi-fullscreen-exit":"bi-arrows-fullscreen"}`,"aria-label":"Fullscreen"})})]})}const cE=async(e,t)=>{try{const n=await fetch(`${e}/resources`,{method:"PATCH",headers:{"Content-Type":"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:JSON.stringify({resources:t.map((o,s)=>({resource_id:o.resource_id,relative_order:s+1}))})});if(!n.ok){const o=await n.json();throw new Error(o.error||"Failed to update resource order")}const r=await n.json();console.log(r.message)}catch(n){console.error("Error updating resource order:",n)}},gm=e=>[...e].sort((t,n)=>t.relative_order===null&&n.relative_order===null?t.display_resource_name.localeCompare(n.display_resource_name):t.relative_order===null?1:n.relative_order===null?-1:t.relative_order-n.relative_order),vm=(e,t)=>{t.current||(t.current=setInterval(()=>{window.scrollBy(0,e*10)},16))},Fc=e=>{e.current&&(clearInterval(e.current),e.current=null)},uE="_dragging_1vb1t_45",Wt={"resources-container":"_resources-container_1vb1t_1","drag-instruction":"_drag-instruction_1vb1t_6","resources-list":"_resources-list_1vb1t_12","resources-header":"_resources-header_1vb1t_18","resources-item":"_resources-item_1vb1t_28",dragging:uE,"drag-handle":"_drag-handle_1vb1t_52","resource-name":"_resource-name_1vb1t_61","resource-repo":"_resource-repo_1vb1t_65","resource-link":"_resource-link_1vb1t_71"};var _x={exports:{}},dE="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",fE=dE,pE=fE;function Ex(){}function Rx(){}Rx.resetWarningCache=Ex;var hE=function(){function e(r,o,s,i,l,c){if(c!==pE){var u=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw u.name="Invariant Violation",u}}e.isRequired=e;function t(){return e}var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:Rx,resetWarningCache:Ex};return n.PropTypes=n,n};_x.exports=hE();var mE=_x.exports;const q=Js(mE),gE=(e,t)=>{switch(t.type){case"SET_RESOURCE_DATA":return{...e,resourceData:t.payload,loading:!1};case"SET_LOADING":return{...e,loading:t.payload};case"SET_SUCCESS_MESSAGE":return{...e,successMessage:t.payload};case"SET_ERRORS":return{...e,errors:Array.isArray(t.payload)?t.payload:[t.payload],loading:!1};case"UPDATE_RESOURCE_FIELD":return{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,[t.field]:t.value}}};case"UPDATE_ALLOCATION":return{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,allocation_types:e.resourceData.resource_details.allocation_types.map(n=>n.allocation_type_id===t.payload.allocationTypeId?{...n,...t.payload.updates}:n)}}};case"UPDATE_BASE_RATE":return console.log("Reducer: Updating base rate to:",t.payload),{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,exchange_rates:{...e.resourceData.resource_details.exchange_rates,base_rate:t.payload}}}};case"UPDATE_EXCHANGE_RATE":return{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,exchange_rates:{...e.resourceData.resource_details.exchange_rates,discount_rates:e.resourceData.resource_details.exchange_rates.discount_rates.map(n=>n.id===t.payload.rateId?{...n,...t.payload.changes}:n)}}}};case"ADD_EXCHANGE_RATE":return console.log("Reducer: Adding new discount rate:",t.payload),{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,exchange_rates:{...e.resourceData.resource_details.exchange_rates,discount_rates:[...e.resourceData.resource_details.exchange_rates.discount_rates||[],t.payload]}}}};case"DELETE_EXCHANGE_RATE":return{...e,resourceData:{...e.resourceData,resource_details:{...e.resourceData.resource_details,exchange_rates:{...e.resourceData.resource_details.exchange_rates,discount_rates:e.resourceData.resource_details.exchange_rates.discount_rates.filter(n=>n.id!==t.payload)}}}};default:return e}},sd=e=>({type:"SET_RESOURCE_DATA",payload:e}),vE=e=>({type:"SET_LOADING",payload:e}),ym=(e,t)=>({type:"SET_SUCCESS_MESSAGE",payload:{message:e,color:t}}),Br=(e,t)=>({type:"UPDATE_RESOURCE_FIELD",field:e,value:t}),Lc=(e,t)=>({type:"UPDATE_ALLOCATION",payload:{allocationTypeId:e,updates:t}}),yE=async(e,t)=>await(await fetch(`${t}/resources/${e}.json`)).json(),xE=async(e,t,n,r)=>(console.log("update resource",n),await fetch(`${t}/resources/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:JSON.stringify({resource:n,required_resources:r})})),bE=(e,t)=>{const[n,r]=w.useReducer(gE,{resourceData:null,loading:!0,errors:[],successMessage:{message:"",color:""}}),o=w.useCallback(async(i,l)=>{let c=[l];try{const u=await i.json();u.errors?c=u.errors:u.message&&(c=[u.message])}catch(u){console.error("Error parsing error response:",u)}r({type:"SET_ERRORS",payload:c})},[]),s=w.useCallback(async()=>{r(vE(!0));try{const i=await yE(e,t);r(sd(i))}catch(i){console.error("Failed to fetch resource data:",i),r({type:"SET_ERRORS",payload:"Failed to fetch resource data. Please try again later."})}},[e,t]);return w.useEffect(()=>{s()},[s]),{state:n,dispatch:r,handleError:o,fetchData:s}},Vf=e=>{var t,n,r;return{allowedActionsOptions:((t=e==null?void 0:e.resource_state_types_available)==null?void 0:t.map(o=>({value:o.resource_state_type_id,label:o.display_resource_state_type,additionalInfo:o.action_types.map(s=>s.display_action_type).join(", ")})))||[],resourceTypesOptions:((n=e==null?void 0:e.resource_types_available)==null?void 0:n.map(o=>({value:o.resource_type_id,label:o.display_resource_type})))||[],unitTypesOptions:((r=e==null?void 0:e.unit_types_available)==null?void 0:r.map(o=>({value:o.unit_type_id,label:o.display_unit_type})))||[],availableResources:(e==null?void 0:e.required_resources_available)||[],availableAllocationTypes:(e==null?void 0:e.unassigned_allocation_types)||[]}},wE=(e,t,n,r,o,s,i)=>{const c=(()=>{var p;if(!e)return[];const f=new Set;return(p=e.allocation_types)==null||p.forEach(m=>{var x;(x=m.required_resources)==null||x.forEach(y=>{f.add(y.resource_name)})}),Array.from(f).sort((m,x)=>m.localeCompare(x)).map(m=>({key:m,name:`Require ${m}`,width:150,type:"checkbox"}))})();return{allocationColumns:[{key:"display_name",name:"Allocation Type",width:200},{key:"allowed_actions",name:"Allowed Actions",width:200,type:"select"},{key:"comment",name:"Descriptive Text",width:200,type:"input",tooltip:"Appears below the resource name and allocations description in the form when making a new request"},...c],allocationRows:e!=null&&e.allocation_types?e.allocation_types.map(f=>{var p;return{display_name:f.display_name,allocation_type_id:f.allocation_type_id,allowed_actions:{options:r,value:((p=f.allowed_action)==null?void 0:p.resource_state_type_id)||"",onChange:m=>o(f.allocation_type_id,m)},comment:{value:f.comment||"",onChange:m=>s(f.allocation_type_id,m)},...Object.fromEntries(c.map(m=>{var x;return[m.key,{checked:((x=f.required_resources)==null?void 0:x.some(y=>y.resource_name===m.key))||!1,onChange:y=>i(f.allocation_type_id,m.key,y,f)}]}))}}):[],requiredResourcesColumns:c}},SE=(e,t,n)=>{const{availableResources:r,availableAllocationTypes:o,allowedActionsOptions:s}=Vf(e),[i,l]=w.useState(!1),[c,u]=w.useState(!1),[d,f]=w.useState([]),[p,m]=w.useState(""),x=w.useCallback((j,C)=>{n(Lc(j,{allowed_action:{resource_state_type_id:C}}))},[n]),y=w.useCallback((j,C)=>{n(Lc(j,{comment:C}))},[n]),v=w.useCallback((j,C,E,_)=>{const N=E?[..._.required_resources||[],{resource_name:C,required_resource_id:e.required_resources_available.find(R=>R.resource_name===C).resource_id}]:(_.required_resources||[]).filter(R=>R.resource_name!==C);n(Lc(j,{required_resources:N}))},[e,n]);w.useEffect(()=>{if(i&&t){const j=t.allocation_types.flatMap(C=>C.required_resources||[]).map(C=>C.required_resource_id);f(j)}},[i,t]);const h=w.useCallback((j,C)=>{f(E=>C?[...E,j]:E.filter(_=>_!==j))},[]),g=w.useCallback(()=>{const j=t.allocation_types.flatMap(N=>N.required_resources||[]).map(N=>N.required_resource_id),C=d.filter(N=>!j.includes(N)),E=j.filter(N=>!d.includes(N)),_=t.allocation_types.map(N=>{const R=N.required_resources||[],O=C.map(P=>{const U=r.find(F=>F.resource_id===P);return{resource_name:U.resource_name,required_resource_id:U.resource_id}}),k=R.filter(P=>!E.includes(P.required_resource_id)).concat(O.filter(P=>!R.some(U=>U.required_resource_id===P.required_resource_id)));return{...N,required_resources:k}});n(sd({...e,resource_details:{...t,allocation_types:_}})),f([]),l(!1)},[d,r,t,e,n]),b=w.useCallback(j=>{const C=j.target.value;m(C)},[]),S=w.useCallback(()=>{var E,_;if(!p)return;const j=o.find(N=>N.allocation_type_id.toString()===p),C=(E=t.allocation_types)==null?void 0:E.some(N=>N.allocation_type_id===j.allocation_type_id);if(j&&!C){const N=(_=s[0])==null?void 0:_.value,R=[...t.allocation_types||[],{allocation_type_id:j.allocation_type_id,display_name:j.display_name,allowed_action:{resource_state_type_id:N},comment:"",required_resources:[]}];n(sd({...e,resource_details:{...t,allocation_types:R}})),u(!1)}},[p,o,t,e,n,s]);return{showAddResourceModal:i,setShowAddResourceModal:l,showAddAllocationTypeModal:c,setShowAddAllocationTypeModal:u,selectedNewResource:d,handleSelectNewResource:h,handleSaveResources:g,selectedNewAllocationType:p,handleSelectNewAllocationType:b,handleSaveAllocationType:S,handleAllowedActionChange:x,handleCommentChange:y,handleRequiredResourceChange:v}},jE=(e,t,n,r,o,s)=>w.useCallback(async()=>{var c,u,d;if(!e)return;const i={resource_name:e.resource_name,description:e.description,resource_type_id:e.resource_type_id,unit_type_id:e.unit_type_id,min_exchange:e.min_exchange,dollar_value:e.dollar_value,allocation_types:e.allocation_types.map(f=>{var p;return{allocation_type_id:f.allocation_type_id,allowed_action:{resource_state_type_id:(p=f.allowed_action)==null?void 0:p.resource_state_type_id},comment:f.comment||""}}),exchange_rates:{base_rate:(c=e.exchange_rates)==null?void 0:c.base_rate,discount_rates:(d=(u=e.exchange_rates)==null?void 0:u.discount_rates)==null?void 0:d.map(f=>({id:f.id,exchange_rate:f.exchange_rate,begin_date:f.begin_date,end_date:f.end_date}))}},l={};e.allocation_types.forEach(f=>{f.required_resources.forEach(p=>{l[p.required_resource_id]||(l[p.required_resource_id]=[]),l[p.required_resource_id].push(f.allocation_type_id)})});try{const f=await xE(t,n,i,l);if(f.ok){const p=await f.json();return s(ym(p.message||"Resource updated successfully!","success")),await r(),!0}else return await o(f,"Failed to update resource"),!1}catch{return s(ym("Error updating resource. Please try again later.","danger")),!1}},[e,t,n,r,o]),CE=(e=!1)=>{const[t,n]=w.useState(e);return{isEditing:t,handleEditingChange:o=>{n(o)}}},_E={"form-wrapper":"_form-wrapper_mu0yh_1"},Xa=({show:e,onClose:t,title:n,children:r,onSave:o,buttonText:s,cancelText:i="Cancel",canSave:l=!0})=>e?a.jsx("div",{style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.8)",display:"flex",alignItems:"center",zIndex:1050},children:a.jsx("div",{className:"modal fade in",tabIndex:"-1",role:"dialog","aria-hidden":"true",style:{width:"90%",maxWidth:"600px",maxHeight:"90%",overflow:"auto",backgroundColor:"white",position:"relative"},children:a.jsx("div",{className:"modal-dialog",role:"document",children:a.jsxs("div",{className:"modal-content",children:[a.jsxs("div",{className:"modal-header",children:[a.jsx("button",{type:"button",className:"close","data-dismiss":"modal",onClick:t,"aria-label":"Close",children:a.jsx("h3",{"aria-hidden":"true",className:"text-danger",children:"×"})}),a.jsx("h3",{className:"modal-title",children:n})]}),a.jsx("div",{className:"modal-body",children:r}),a.jsxs("div",{className:"modal-footer",style:{padding:"15px",textAlign:"right",borderTop:"1px solid #e5e5e5",backgroundColor:"#f8f9fa"},children:[a.jsx("button",{className:"btn btn-danger",onClick:t,children:i}),a.jsx("button",{className:"btn btn-success",onClick:o,disabled:!l,children:s})]})]})})})}):null;Xa.propTypes={show:q.bool.isRequired,onClose:q.func.isRequired,title:q.string.isRequired,children:q.node.isRequired,onSave:q.func.isRequired,buttonText:q.string,cancelText:q.string,canSave:q.bool};const Se=({children:e,color:t,dismissable:n=!1})=>a.jsxs("div",{className:`alert alert-${t} mt-3 alert-dismissible show`,role:"alert",children:[e,n&&a.jsx("button",{type:"button",className:"close","data-dismiss":"alert","aria-label":"Close",children:a.jsx("span",{"aria-hidden":"true",children:"×"})})]}),Ro=({label:e,options:t,value:n,onChange:r,...o})=>a.jsxs("div",{className:"form-group",children:[e&&a.jsx("label",{children:e}),a.jsx("select",{className:"form-control",value:n,onChange:r,...o,children:t.map(s=>a.jsxs("option",{value:s.value,children:[s.label,s.additionalInfo&&` - ${s.additionalInfo}`]},s.value))})]});Ro.propTypes={label:q.string,options:q.arrayOf(q.shape({value:q.oneOfType([q.string,q.number]).isRequired,label:q.string.isRequired,additionalInfo:q.string})).isRequired,value:q.oneOfType([q.string,q.number]),onChange:q.func.isRequired};function Yr({label:e,type:t="text",value:n,onChange:r,disabled:o=!1,infoText:s="",style:i,inputClassName:l,inputAddon:c}){return a.jsxs(a.Fragment,{children:[e&&a.jsx("label",{children:e}),s&&a.jsx("small",{className:"form-text help-block",children:s}),t==="textarea"?a.jsx("textarea",{className:`form-control ${l||""}`,value:n,onChange:r,disabled:o,rows:"6"}):c?a.jsxs("div",{className:"input-prepend",children:[a.jsx("span",{className:"add-on",children:c}),a.jsx("input",{type:t,className:`form-control ${l||""}`,style:i,value:n,onChange:r,disabled:o})]}):a.jsx("input",{type:t,className:`form-control ${l||""}`,style:i,value:n,onChange:r,disabled:o})]})}const EE="_blurred_16xcy_16",xn={"advanced-settings":"_advanced-settings_16xcy_1","header-wrapper":"_header-wrapper_16xcy_5","content-container":"_content-container_16xcy_11",blurred:EE,"warning-banner":"_warning-banner_16xcy_21","alt-warning-banner":"_alt-warning-banner_16xcy_40 _warning-banner_16xcy_21"},zf=({headerText:e,header:t,children:n,isEditing:r=!1,onEditingChange:o,warningMessage:s=""})=>{const i=e&&e.type==="label";return a.jsxs("div",{className:xn["advanced-settings"],children:[(e||t)&&a.jsxs("div",{className:xn["header-wrapper"],children:[e,t&&a.jsx("div",{className:`${xn["header-buttons-container"]} ${r?"":xn.blurred}`,children:t})]}),a.jsxs("div",{style:{width:"100%"},children:[!r&&a.jsxs("div",{className:i?`${xn["alt-warning-banner"]}`:xn["warning-banner"],children:[a.jsxs("span",{className:xn["warning-text"],children:[a.jsx("strong",{children:"CAUTION! "})," ",s]}),a.jsx("button",{className:"btn btn-danger",onClick:()=>o(!0),children:"I understand the risks"})]}),a.jsx("div",{className:`${xn["content-container"]} ${r?"":xn.blurred}`,children:n})]})]})};zf.propTypes={headerText:q.node,header:q.node,children:q.node.isRequired,isEditing:q.bool,onEditingChange:q.func.isRequired,warningMessage:q.string};const Bf=Re.memo(function({resourceDetails:t,resourceTypesOptions:n,unitTypesOptions:r,dispatch:o,isDollarValueEditing:s,onDollarValueEditingChange:i,showDollarValue:l=!0,showResourceId:c=!0,useAdvancedSettings:u=!0}){var p;const d="Dollar Value per SUs",f=l?a.jsx(Yr,{label:u?null:d,value:t.dollar_value,onChange:m=>o(Br("dollar_value",m.target.value)),type:"number",inputAddon:"$",inputClassName:"span4"}):null;return a.jsxs(a.Fragment,{children:[a.jsx(Yr,{label:"Resource Name",value:t.resource_name,onChange:m=>o(Br("resource_name",m.target.value)),inputClassName:"span8"}),c&&a.jsx(Yr,{label:"Resource Repository Key",value:t.resource_repository_key,disabled:!0,inputClassName:"span8"}),u&&l?a.jsx(zf,{headerText:a.jsx("label",{children:d}),isEditing:s,onEditingChange:i,warningMessage:"Dollar value is for reporting and should only be modified if the SU rate changes.",children:f}):f,a.jsx(Yr,{label:"Allocations Description",type:"textarea",value:t.description,infoText:"Appears below the resource name in the form when making a new request, as well as under the header Allocations Description in resource catalogs",onChange:m=>o(Br("description",m.target.value)),inputClassName:"span8"}),a.jsx(Ro,{label:"Resource Type",options:n,value:t.resource_type_id,onChange:m=>o(Br("resource_type_id",m.target.value)),className:"span8"}),a.jsx(Ro,{label:"Unit Type",options:r,value:t.unit_type_id,onChange:m=>o(Br("unit_type_id",m.target.value)),className:"span8"}),a.jsx(Yr,{label:`Minimum exchange amount, in ${(p=r.find(m=>m.value.toString()===t.unit_type_id.toString()))==null?void 0:p.label}`,value:t.min_exchange,onChange:m=>o(Br("min_exchange",m.target.value)),inputClassName:"span8"})]})});Bf.propTypes={resourceDetails:q.object.isRequired,resourceTypesOptions:q.array.isRequired,unitTypesOptions:q.array.isRequired,dispatch:q.func.isRequired,isDollarValueEditing:q.bool,onDollarValueEditingChange:q.func,showDollarValue:q.bool,showResourceId:q.bool,useAdvancedSettings:q.bool};function Nx({onClose:e}){const[t,n]=w.useState(!0),[r,o]=w.useState([]),[s,i]=w.useState(null),[l,c]=w.useState(-1),[u,d]=w.useState(null),f=Vf(u);f.resourceTypesOptions.unshift({value:0,label:"Select a resource type..."}),f.unitTypesOptions.unshift({value:0,label:"Select a unit type..."}),w.useEffect(()=>{(async()=>{const g=await fetch("/resources/addable.json");n(!1),g.status==200?o(await g.json()):i("Error retrieving resource list.")})()},[]),w.useEffect(()=>{if(l===-1)return d(null);(async()=>{const g=await fetch(`/resources/addable/${l}.json`);g.status==200?d(await g.json()):i("Error retrieving resource details.")})()},[l]);let p=null;t?p=a.jsx("p",{children:"Loading…"}):s!==null?p=a.jsx(Se,{color:"danger",children:s}):r.length==0&&(p=a.jsx(Se,{children:"There are currently no resources available to add."}));const m=[{value:-1,label:"Select a resource..."}].concat(r.map(g=>({value:g.xras_cider_resource_id,label:g.resource_descriptive_name}))),x=u?u.resource_details:null,y=!s&&x&&x.resource_name.length>0&&x.resource_type_id>0&&x.unit_type_id>0,v=g=>{g.type=="UPDATE_RESOURCE_FIELD"&&d({...u,resource_details:{...u.resource_details,[g.field]:g.value}})},h=()=>{(async()=>{const g=await fetch("/resources",{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:JSON.stringify({...x,resource_repository_key:l})});if(g.status==200){const b=await g.json();window.location=`/resources/${b.resource_id}`}else i("Error saving resource.")})()};return p===null&&(p=a.jsxs(a.Fragment,{children:[a.jsx("h2",{children:"Select a Resource to Add"}),a.jsx(Ro,{options:m,onChange:g=>c(parseInt(g.target.value))}),!u&&l!==-1?a.jsx("p",{children:"Loading…"}):null,u&&a.jsxs(a.Fragment,{children:[a.jsx("h2",{children:"Resource Properties"}),a.jsx("p",{style:{fontStyle:"italic",fontWeight:"bold"},children:"Any modifications to these resource properties will be applied globally and impact resources on other all allocations process"}),a.jsx("div",{className:_E["form-wrapper"],children:a.jsx(Bf,{resourceDetails:x,resourceTypesOptions:f.resourceTypesOptions,unitTypesOptions:f.unitTypesOptions,showResourceId:!1,showDollarValue:!1,dispatch:v})})]})]})),a.jsx(Xa,{show:!0,onClose:e,title:"Add a Resource from CIDeR",onSave:h,buttonText:"Save",canSave:y,children:p})}Nx.propTypes={onClose:q.func.isRequired};function RE({availableResources:e,unavailableResources:t=[],canAdd:n=!1,relativeUrlRoot:r}){const o=w.useMemo(()=>gm(e),[e]),s=w.useMemo(()=>gm(t),[t]),[i,l]=w.useState(o),[c,u]=w.useState(!1),d=w.useRef(null),f=w.useRef(null),p="Active",m="Inactive",[x,y]=w.useState(p),v=j=>{y(j),console.log(j),j==p?l(o):l(s)};function h(j,C){C.preventDefault(),y(j),v(j)}w.useEffect(()=>{l(o)},[o]);const g=(j,C)=>{d.current=C},b=(j,C)=>{if(j.preventDefault(),d.current===C)return;const E=[...i],_=E[d.current];E.splice(d.current,1),E.splice(C,0,_),d.current=C,l(E);const{clientY:N}=j,R=130;N<R?vm(-1,f):window.innerHeight-N<R?vm(1,f):Fc(f)},S=()=>{d.current=null,Fc(f),cE(r,i)};return w.useEffect(()=>()=>Fc(f),[]),a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:Wt["resources-container"],children:[n&&a.jsx("button",{className:"btn btn-primary pull-right",onClick:()=>u(!0),children:"Add a Resource from CIDeR"}),a.jsx("h2",{children:"Select a resource from the list to modify"}),a.jsx("p",{className:Wt["drag-instruction"],children:"Drag items to reorder the list."}),a.jsxs("div",{className:"w-full max-w-md mx-auto p-4",children:[a.jsxs("ul",{className:"nav nav-tabs",children:[a.jsx("li",{className:"nav-item",children:a.jsx("a",{className:`nav-link ${x===p?"active":""}`,"data-toggle":x===p?"tab":void 0,style:{cursor:"default",...x===p?{border:"1px solid #ddd",borderBottomColor:"transparent",color:"#555",backgroundColor:"#fff"}:{}},onClick:j=>h(p,j),children:p})}),a.jsx("li",{className:"nav-item",children:a.jsx("a",{className:`nav-link ${x===m?"active":""}`,"data-toggle":x===m?"tab":void 0,style:{cursor:"default"},onClick:j=>h(m,j),children:m})})]}),a.jsxs("div",{className:Wt["resources-list"],children:[a.jsxs("div",{className:Wt["resources-header"],children:[a.jsx("span",{className:Wt["header-name"],children:"Resource Name"}),a.jsx("span",{className:Wt["header-repo"],children:"Repository Key"})]}),i.map((j,C)=>a.jsxs("div",{className:`${Wt["resources-item"]}`,draggable:!0,onDragStart:E=>g(E,C),onDragOver:E=>b(E,C),onDrop:S,children:[a.jsx("span",{className:Wt["drag-handle"]}),a.jsx("span",{className:Wt["resource-name"],children:a.jsx("a",{href:`${r}/resources/${j.resource_id}`,className:Wt["resource-link"],children:j.display_resource_name})}),a.jsx("span",{className:Wt["resource-repo"],children:j.resource_repository_key||"N/A"})]},j.resource_id))]})]})]}),c&&a.jsx(Nx,{onClose:()=>u(!1)})]})}function Ur(){return a.jsx("div",{className:"spinner-border",role:"status",children:a.jsx("span",{className:"visually-hidden",children:"Loading..."})})}const NE="_grid_afccc_1",kE="_important_afccc_30",OE="_input_afccc_34",TE="_edited_afccc_38",PE="_disabled_afccc_46",IE="_scroll_afccc_59",_r={grid:NE,important:kE,input:OE,edited:TE,disabled:PE,scroll:IE};function $E({column:e,row:t,style:n={}}){const r=e.format?e.format(t[e.key],t):t[e.key],o=["cell"];return e.class&&o.push(e.class),e.rowClass&&o.push(e.rowClass(t)),a.jsx("td",{className:o.join(" "),style:n,children:r})}const qf=({title:e,placement:t,children:n})=>(w.useEffect(()=>($('[data-toggle="tooltip"]').tooltip(),()=>{$('[data-toggle="tooltip"]').tooltip("destroy")}),[]),a.jsx("span",{"data-toggle":"tooltip","data-placement":t,title:e,style:{margin:"10px"},children:n}));qf.propTypes={title:q.string.isRequired,placement:q.oneOf(["top","bottom","left","right"]),children:q.node.isRequired};qf.defaultProps={placement:"top"};const ME="_datepicker_19wnv_1",AE="_error_19wnv_1",xm={datepicker:ME,error:AE},DE=({value:e,onChange:t,disabled:n=!1,style:r,className:o="",minDate:s="",maxDate:i="",error:l=""})=>{const c=l;return a.jsx("div",{className:`w-full ${o}`,children:a.jsx("input",{type:"date",style:r,className:`${xm.datepicker} ${c?xm.error:""}`,value:e||"",onChange:u=>t(u.target.value),disabled:n,min:s||"1900-01-01",max:i||"2100-12-31"})})},es=(e,t,n)=>{if(t.onChange){t.onChange(n,e);return}const r=e[t.key];r!=null&&r.onChange&&r.onChange(n)},FE={text:$E,select:({column:e,row:t,style:n})=>a.jsx("td",{style:n,children:a.jsx(Ro,{label:"",options:t[e.key].options,value:t[e.key].value,onChange:r=>es(t,e,r.target.value),style:{width:"100%",margin:0}})}),input:({column:e,row:t,style:n})=>a.jsx("td",{style:n,children:a.jsx(Yr,{label:"",type:"text",disabled:t[e.key].disabled,value:t[e.key].value,onChange:r=>es(t,e,r.target.value),style:{width:"92%",margin:0}})}),checkbox:({column:e,row:t,style:n})=>a.jsx("td",{style:n,children:a.jsx("input",{type:"checkbox",checked:t[e.key].checked,onChange:r=>es(t,e,r.target.checked)})}),date:({column:e,row:t,style:n})=>{const r=t[e.key];return!(r!=null&&r.value)&&typeof r!="object"?a.jsx("td",{style:n,children:r||""}):a.jsx("td",{style:n,children:a.jsx(DE,{value:r.value,onChange:o=>es(t,e,o),disabled:r.disabled,style:{width:"92%",margin:0},minDate:e.minDate,maxDate:e.maxDate,error:r.error})})},action:({column:e,row:t,style:n})=>a.jsx("td",{style:n,children:t.rate_type==="Discount"&&a.jsx("button",{className:"btn btn-link text-danger",onClick:()=>{var r;return es(t,e,(r=t[e.key])==null?void 0:r.id)},children:a.jsx("i",{className:"fa fa-trash"})})})};function mn({columns:e,rows:t,classes:n,frozenColumns:r=0,minWidth:o,rowClasses:s=[],scroll:i=!0,scrollBehavior:l="smooth",scrollRowIndex:c=0}){const u=w.useRef();w.useLayoutEffect(()=>{if(!i||!u.current)return;const y=u.current.querySelector(`tbody tr:nth-child(${c+1})`);y&&y.scrollIntoView({behavior:l,block:"nearest",inline:"nearest"})},[i,c,l]);const d=[0];for(let y=0;y<r;y++)d[y+1]=d[y]+(e[y].width||100);const f=(y,v)=>y<r?{position:"sticky",left:`${d[y]}px`,minWidth:`${e[y].width||100}px`,width:`${e[y].width||100}px`,zIndex:v||1}:{},p=e.map((y,v)=>a.jsxs("th",{className:y.headerClass||y.class||"",style:f(v,100),children:[y.formatHeader?y.formatHeader(y.name,y):y.name,y.tooltip&&a.jsx(qf,{title:y.tooltip,placement:"bottom",children:a.jsx("i",{className:"icon-info-sign"})})]},y.key)),m=t.map((y,v)=>{const h=e.map((g,b)=>{const S=FE[g.type||"text"];return a.jsx(S,{column:g,row:y,style:f(b)},g.key)});return a.jsx("tr",{className:s[v]||"",children:h},v)}),x={};return o&&(x.minWidth=o),a.jsx("div",{className:`${_r.grid} ${i?_r.scroll:""} ${n||""}`,ref:u,children:a.jsxs("table",{className:"table table-bordered",style:x,children:[a.jsx("thead",{children:a.jsx("tr",{children:p})}),a.jsx("tbody",{children:m})]})})}const id={"header-buttons":"_header-buttons_15oxx_1","allocation-types-grid":"_allocation-types-grid_15oxx_6","vertical-align-center":"_vertical-align-center_15oxx_10"},kx=({onAddAllocationType:e,onAddRequiredResource:t})=>a.jsxs("div",{className:id["header-buttons"],children:[a.jsxs("button",{className:"btn btn-primary",onClick:e,children:[a.jsx("i",{className:"fa fa-plus"})," Add Allocation Type"]}),a.jsxs("button",{className:"btn btn-primary",onClick:t,children:[a.jsx("i",{className:"fa fa-plus"})," Add Required Resource"]})]});kx.propTypes={headerText:q.node,onAddAllocationType:q.func.isRequired,onAddRequiredResource:q.func.isRequired};const Ox=Re.memo(function({columns:t,rows:n}){return a.jsxs("div",{className:id["allocation-types-grid"],children:[a.jsx(mn,{columns:t,rows:n,rowClasses:Array(n.length).fill(id["vertical-align-center"]),scroll:!1}),a.jsx("p",{style:{margin:"0",fontStyle:"italic",fontWeight:"bold"},children:"Note: You may need to contact your Allocations Coordinator if you have added this resource to an allocation type."})]})});Ox.propTypes={columns:q.array.isRequired,rows:q.array.isRequired};const qr={"exchange-rates-grid":"_exchange-rates-grid_5qkd5_1","header-container":"_header-container_5qkd5_5","header-buttons":"_header-buttons_5qkd5_11","vertical-align-center":"_vertical-align-center_5qkd5_18","error-summary":"_error-summary_5qkd5_35"},Tx=Re.memo(function({columns:t,rows:n,onAddDiscountRate:r,dateErrors:o=[]}){return a.jsxs("div",{className:qr["exchange-rates-grid"],children:[a.jsxs("div",{className:qr["header-container"],children:[a.jsx("h2",{className:qr["header-title"],children:"Exchange Rates"}),a.jsx("div",{className:qr["header-buttons"],children:a.jsxs("button",{className:"btn btn-primary",onClick:r,children:[a.jsx("i",{className:"fa fa-plus"})," Add Discount Rate"]})})]}),a.jsx(mn,{columns:t,rows:n,rowClasses:Array(n.length).fill(qr["vertical-align-center"]),scroll:!1}),o.length>0&&a.jsx("div",{className:qr["error-summary"],children:a.jsx("ul",{children:o.map((s,i)=>a.jsx("li",{children:s},i))})})]})});Tx.propTypes={columns:q.array.isRequired,rows:q.array.isRequired,onAddDiscountRate:q.func.isRequired,dateErrors:q.array};const LE=(e,t)=>{const n=w.useCallback(m=>{var y,v;t({type:"DELETE_EXCHANGE_RATE",payload:m}),(((v=(y=e==null?void 0:e.resource_details)==null?void 0:y.exchange_rates)==null?void 0:v.discount_rates.filter(h=>h.id!==m))||[]).forEach(h=>{h.begin_date&&h.end_date&&t({type:"UPDATE_EXCHANGE_RATE",payload:{rateId:h.id,changes:{start_date_error:"",end_date_error:""}}})})},[t,e]),r=[{key:"rate_type",name:"Rate Type",width:150},{key:"rate",name:"Exchange Rate",width:100,type:"input",tooltip:"Exchange rate is the cost in ACCESS Credits of one resource unit. ACCESS Credits / exchange rate = resource units"},{key:"conversion",name:"Resource Units per ACCESS Credit",width:150},{key:"start_date",name:"Start Date",width:150,type:"date",minDate:new Date().toISOString().split("T")[0]},{key:"end_date",name:"End Date",width:150,type:"date",minDate:new Date().toISOString().split("T")[0]},{key:"actions",name:"",width:80,type:"action",onChange:n}],o=m=>{t({type:"UPDATE_BASE_RATE",payload:m})},s=(m,x)=>{const y={exchange_rate:x},v={};x?v.rate_error="":v.rate_error="Exchange Rate cannot be empty",t({type:"UPDATE_EXCHANGE_RATE",payload:{rateId:m,changes:{...y,...v}}})},i=()=>{var y,v;const m=[];return(((v=(y=e==null?void 0:e.resource_details)==null?void 0:y.exchange_rates)==null?void 0:v.discount_rates)||[]).forEach(h=>{h.start_date_error&&m.push(h.start_date_error),h.end_date_error&&m.push(h.end_date_error),h.rate_error&&m.push(h.rate_error)}),m.filter((h,g)=>h&&h!==""&&(!h.includes("overlaps")||m.indexOf(h)===g))},l=m=>{const x=new Date(m);return new Intl.DateTimeFormat("en-US",{timeZone:"UTC",month:"numeric",day:"numeric",year:"numeric"}).format(x)},c=(m,x,y,v)=>{const h=new Date(m).getTime(),g=new Date(x).getTime(),b=new Date(y).getTime(),S=new Date(v).getTime();return h<=S&&b<=g},u=(m,x)=>{let y="";if(m.begin_date&&m.end_date){const v=x.filter(h=>h.id!==m.id);for(const h of v)if(h.begin_date&&h.end_date&&c(m.begin_date,m.end_date,h.begin_date,h.end_date)){y=`The selected date range (${l(m.begin_date)} to ${l(m.end_date)}) overlaps with an existing discount rate (${l(h.begin_date)} to ${l(h.end_date)})`;break}}return y},d=(m,x,y)=>{var R,O;const v={start_date:"begin_date",end_date:"end_date"},h=k=>{const P=new Date(k);return new Intl.DateTimeFormat("en-US",{timeZone:"UTC",month:"numeric",day:"numeric",year:"numeric"}).format(P)},g=((O=(R=e==null?void 0:e.resource_details)==null?void 0:R.exchange_rates)==null?void 0:O.discount_rates)||[],b=g.find(k=>k.id===m);if(!b)return;const S={[v[x]]:y},j={},C=x==="end_date",E=()=>{if(!y)return j[`${x}_error`]="Date cannot be empty or invalid",!1;const k=r.find(V=>V.key===x),P=(k==null?void 0:k.minDate)||"1900-01-01",U=(k==null?void 0:k.maxDate)||"2100-12-31",F=C&&b.begin_date?b.begin_date:P;return y<F?(j[`${x}_error`]=`${x.replace("_"," ")} ${h(y)} cannot be before ${h(F)}`,!1):y>U?(j[`${x}_error`]=`${x.replace("_"," ")} cannot be after ${h(U)}`,!1):(j[`${x}_error`]="",!0)},_=()=>{const k=x==="end_date"?y:b.end_date;if(x==="start_date"&&k){if(y>k)return j.end_date_error=`end date ${h(k)} cannot be before ${h(y)}`,!1;j.end_date_error=j.end_date_error||""}return!0},N=()=>{console.log("validating overlaps");const k=x==="start_date"?y:b.begin_date,P=x==="end_date"?y:b.end_date;if(k&&P){const U=u({...b,begin_date:k,end_date:P},g);return j.start_date_error=U,j.end_date_error=U,!U}return!0};if(!E()){t({type:"UPDATE_EXCHANGE_RATE",payload:{rateId:m,changes:{...S,...j}}});return}_(),N(),C&&!b.begin_date?j.start_date_error="Date cannot be empty or invalid":!C&&!b.end_date&&(j.end_date_error="Date cannot be empty or invalid"),t({type:"UPDATE_EXCHANGE_RATE",payload:{rateId:m,changes:{...S,...j}}})},f=()=>{var j,C;const m=((C=(j=e==null?void 0:e.resource_details)==null?void 0:j.exchange_rates)==null?void 0:C.discount_rates)||[];let y=new Date;m.forEach(E=>{if(E.end_date){const _=new Date(E.end_date);_>y&&(y=_)}});const v=new Date(y);v.setDate(v.getDate()+1);const h=v.toISOString().split("T")[0],g=new Date(v);g.setDate(g.getDate()+15);const b=g.toISOString().split("T")[0],S={id:Date.now(),exchange_rate:"1.0",begin_date:h,end_date:b,is_new:!0};t({type:"ADD_EXCHANGE_RATE",payload:S})};return{exchangeRateColumns:r,exchangeRateRows:(()=>{var b,S;const m=(b=e==null?void 0:e.resource_details)==null?void 0:b.exchange_rates,x=(m==null?void 0:m.base_rate)??"",y=(m==null?void 0:m.discount_rates)||[],v=new Date().toISOString().split("T")[0],h=((S=e==null?void 0:e.resource_details)==null?void 0:S.unit_type)||"Resource Units",g=j=>!j||Number(j)===0?"-":`${(1/Number(j)).toFixed(2)} ${h}`;return[{rate_type:"Base Rate",rate:{value:x.toString(),onChange:j=>o(j)},conversion:g(x)},...y.map(j=>{var N;const C=j.is_new||j.begin_date>v,E=C||j.begin_date==="",_=j.is_new||j.end_date>=v||j.end_date==="";return{rate_type:"Discount",rate:{value:((N=j.exchange_rate)==null?void 0:N.toString())||"",onChange:C?R=>s(j.id,R):null,disabled:!C},conversion:g(j.exchange_rate),start_date:{value:j.begin_date||"",onChange:R=>d(j.id,"start_date",R),error:j.start_date_error,disabled:!E},end_date:{value:j.end_date||"",onChange:R=>d(j.id,"end_date",R),error:j.end_date_error,disabled:!_},actions:{id:j.id}}})]})(),handleAddDiscountRate:f,handleDeleteRate:n,dateErrors:i()}};function Px({resourceId:e,relativeUrlRoot:t,setExternalSubmit:n}){const{state:r,dispatch:o,handleError:s,fetchData:i}=bE(e,t),{isEditing:l,handleEditingChange:c}=CE(),{resourceData:u,loading:d,errors:f,successMessage:p}=r,m=u==null?void 0:u.resource_details,x=u==null?void 0:u.uses_exchange_rates,{allowedActionsOptions:y,resourceTypesOptions:v,unitTypesOptions:h,availableResources:g,availableAllocationTypes:b}=Vf(u),{showAddResourceModal:S,setShowAddResourceModal:j,showAddAllocationTypeModal:C,setShowAddAllocationTypeModal:E,selectedNewResource:_,handleSelectNewResource:N,handleSaveResources:R,selectedNewAllocationType:O,handleSelectNewAllocationType:k,handleSaveAllocationType:P,handleAllowedActionChange:U,handleCommentChange:F,handleRequiredResourceChange:V}=SE(u,m,o),{exchangeRateColumns:Z,exchangeRateRows:T,handleAddDiscountRate:L,dateErrors:A}=LE(u,o),H=jE(m,e,t,i,s,o);w.useEffect(()=>{n&&A.length==0?n(H):n(null)},[H,n,A]);const{allocationColumns:B,allocationRows:X}=wE(m,g,_,y,U,F,V),[J,ee]=w.useState(!1);return d?a.jsx(Ur,{}):f.length>0?a.jsx("div",{children:f.map((Q,te)=>a.jsx(Se,{color:"danger",dismissable:!0,children:Q},te))}):u?a.jsxs("div",{className:"edit-resource",children:[p.message&&a.jsx(Se,{color:p.color,dismissable:!0,children:p.message}),a.jsxs("div",{children:[a.jsx("h2",{children:"Resource Properties"}),a.jsx("div",{style:{marginBottom:"0.75rem"},children:a.jsx("p",{style:{margin:"0",fontStyle:"italic",fontWeight:"bold"},children:"Any modifications to these resource properties will be applied globally and impact resources on other all allocations process"})}),a.jsx(Bf,{resourceDetails:m,resourceTypesOptions:v,unitTypesOptions:h,dispatch:o,isDollarValueEditing:J,onDollarValueEditingChange:ee})]}),x&&a.jsx(Tx,{columns:Z,rows:T,onAddDiscountRate:L,dateErrors:A}),a.jsx(zf,{headerText:a.jsx("h2",{children:"Allocation Types"}),header:a.jsx(kx,{onAddAllocationType:()=>l&&E(!0),onAddRequiredResource:()=>l&&j(!0)}),isEditing:l,onEditingChange:c,warningMessage:`Incorrect allocations
|
|
53
53
|
process settings can make a resource unavailable for allocation.
|
|
54
54
|
Please proceed with caution.`,children:a.jsx(Ox,{columns:B,rows:X})}),a.jsx(Xa,{show:S,onClose:()=>j(!1),title:"Add Required Resource",onSave:R,buttonText:"Save",children:a.jsx("div",{children:g.map(Q=>a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[a.jsx("input",{type:"checkbox",style:{margin:0},checked:_.includes(Q.resource_id),onChange:te=>N(Q.resource_id,te.target.checked)}),Q.resource_name]},Q.resource_id))})}),a.jsx(Xa,{show:C,onClose:()=>E(!1),title:"Add Allocation Type",onSave:P,buttonText:"Save",children:a.jsx(Ro,{label:"Select Allocation Type",options:[{value:"",label:"Select an allocation type to add",disabled:!0},...b.map(Q=>({value:Q.allocation_type_id,label:Q.display_name}))],value:O,onChange:k})})]}):a.jsx("div",{children:"No resource data available."})}Px.propTypes={resourceId:q.number.isRequired,relativeUrlRoot:q.string.isRequired,setExternalSubmit:q.func};const Ve={error:"error",pending:"pending",success:"success"},Za=e=>e.endDate||e.startDate||(e.actions[0]||{}).entryDate,bm=e=>`${{pi:"01",co_pi:"02",allocation_manager:"03"}[e.role]||"04"} ${e.lastName}, ${e.firstName}`,UE=(e,{grantNumber:t,projectManager:n,requestMasterId:r,requests:o,title:s,users:i},l)=>{t=t||r,o.sort((d,f)=>Za(d)>Za(f)?-1:1);const c=o.find(d=>d.timeStatus=="current"),u=c?c.requestId:null;e.projects[t]={currentRequestId:u,grantNumber:t,isManager:n,requestsList:o.map(d=>{const{actions:f,allocationType:p,endDate:m,requestId:x,startDate:y,status:v}=d,h=f.map(({entryDate:g})=>g).sort()[0].split("T")[0];return VE(e,d,{entryDate:h,grantNumber:t}),{allocationType:p,endDate:m,entryDate:h,requestId:x,startDate:y,status:v}}),selectedRequestId:u||o[0].requestId,status:l,tab:"overview",title:s,users:i.map(({eligibleReason:d,email:f,firstName:p,isEligible:m,lastName:x,organization:y,resources:v,role:h,username:g})=>{const b=v.filter(_=>_.userAccountState=="active"&&_.unitType!="ACCESS Credits"),S=b.map(_=>_.xrasResourceId),j=b.filter(_=>_.resourceProviderState=="pending-active").map(_=>_.xrasResourceId),C=v.filter(_=>_.userAccountState!="active").map(_=>_.xrasResourceId),E={};for(let _ of b)E[_.xrasResourceId]=_.resourceUsername;return{eligibility:m,eligibilityReason:d,email:f,firstName:p,initialResourceIds:[...S],initialRole:h,lastName:x,organization:y,resourceAccountPendingIds:j,resourceAccountInactiveIds:C,resourceIds:S,resourceUsernames:E,role:h,username:g}}).sort((d,f)=>bm(d)<bm(f)?-1:1),usersNewRowIndex:0,usersStatus:null},e.projects[t].currentUser=e.projects[t].users.find(({username:d})=>d==e.username)},VE=(e,{actions:t,allocationType:n,allowedActions:r,endDate:o,requestId:s,requestType:i,resources:l,startDate:c,status:u,timeStatus:d},{entryDate:f,grantNumber:p})=>{l=l||[];const m={actions:t.map(({actionId:v,actionStatusType:h,actionType:g,allowedOperations:b,approvedStartDate:S,detailAvailable:j,entryDate:C,isRequest:E,requestedStartDate:_,resources:N})=>({actionId:v,allowedOperations:b,detailAvailable:j,date:(C||S||_).split("T")[0],deleteStatus:null,isRequest:E,resources:N.map(ad).sort(Qa),showDeleteModal:!1,status:h,type:g})),allocationType:n,allowedActions:zE(r),endDate:o,entryDate:f,exchangeActionId:null,exchangeActionEditable:!0,exchangeErrors:[],exchangeStatus:null,grantNumber:p,isMaximize:n=="Maximize",requestId:s,resources:l.map(ad).filter(v=>v.isCredit||v.allocated>0).sort(Qa),resourcesReason:"",returnedForCorrections:!!t.find(v=>v.returnedForCorrections),returnedForCorrectionsNotes:t.map(v=>v.adminComments).join(","),showActionsModal:!1,showConfirmModal:!1,showResourcesModal:!1,startDate:c,status:u,timeStatus:d,type:i,usageDetail:null,usageDetailStatus:null,usesCredits:["Explore","Discover","Accelerate"].includes(n)};let x={};for(let v of m.actions)if(["Exchange","Transfer"].includes(v.type)&&["Submitted","Under Review","Incomplete"].includes(v.status)){m.exchangeActionId=v.actionId,m.exchangeActionEditable=v.status==="Incomplete";for(let h of v.resources)x[h.resourceId]=h;for(let h of m.resources)h.resourceId in x&&(h.requested+=x[h.resourceId].requested,delete x[h.resourceId]);m.resources.push(...Object.values(x).map(h=>({...h,isNew:!0})));break}const y=m.allowedActions.Exchange||m.allowedActions.Transfer;if(y){x={};for(let v of y.resources)x[v.resourceId]=v;for(let v of m.resources)v.resourceId in x&&(v.questions=x[v.resourceId].questions||[],v.requires=x[v.resourceId].requires||[])}m.resources.length&&!m.resources.find(v=>v.isCredit)&&m.resources.push(y&&y.resources.find(v=>v.isCredit)||{allocated:0,decimalPlaces:0,exchangeRates:{base:{type:"base",unitCost:1},current:{type:"base",unitCost:1}},icon:"credit",isActive:!0,isBoolean:!1,isCredit:!0,isFake:!0,name:"Credit Equivalents",requested:0,requires:[],resourceId:0,unit:"Credit Equivalents",used:0}),e.requests[s]=m},zE=e=>{const t={};for(let{actionType:n,allowedResources:r,opportunityId:o,opportunityName:s}of e){let i={name:n,resources:r.map(ad).sort(Qa),opportunityId:o,opportunityName:s};n in t?(Array.isArray(t[n])||(t[n]=[t[n]]),t[n].push(i)):t[n]=i}return"Transfer"in t&&!("Exchange"in t)&&(t.Exchange=t.Transfer),t},wm=(e,t)=>e.relativeOrder<t.relativeOrder?-1:1,ad=({allocationState:e,amountAllocated:t,amountApproved:n,amountRequested:r,amountUsed:o,attributeSets:s,baseExchangeRate:i,currentExchangeRate:l,currentExchangeRateEndDate:c,currentExchangeRateType:u,dependentResourceXrasIds:d,displayResourceName:f,endDate:p,exchangeRate:m,minimumExchange:x,organizationId:y,organizationFaviconUrl:v,organizationName:h,resourceRepositoryKey:g,resourceType:b,startDate:S,unitType:j,userGuideUrl:C,xrasResourceId:E})=>{const _=j=="Yes / No",N=j=="ACCESS Credits";return{allocated:mo(um(t,n)||0,0,"floor"),decimalPlaces:0,endDate:p,exchangeRates:{base:{type:"base",unitCost:_?0:i||m},current:{endDate:c,type:(u||"base").toLowerCase(),unitCost:_?0:l||m}},icon:N?"credit":b.toLowerCase(),isActive:e=="active",isBoolean:_,isCredit:N,isFake:!1,isUnderReview:!1,isNew:!1,minimumExchange:x,name:f.trim(),questions:(s||[]).filter(({isActive:R})=>R).sort(wm).map(R=>({attributeSetId:R.attributeSetId,attributes:R.attributes.sort(wm).map(O=>({required:O.isRequired,resourceAttributeId:O.resourceAttributeId,label:O.attributeName})),fieldType:R.attributeSetRelationType,label:R.attributeSetName,resourceId:E,values:[]})),resourceProvider:{organizationId:y,name:h,favicon:v},requested:mo(um(r,t)||0,0,"floor"),requires:d||[],resourceId:E,resourceRepositoryKey:g,startDate:S,type:b,unit:j,used:mo(o||0,0,"ceil"),userGuideUrl:C}},Sm=(e,t)=>{const n=t.allowedActions.Exchange;if(!n)return;const r={};for(let c of n.resources)r[c.resourceId]=c;const o=t.resources.map(c=>c.resourceId),s=r[e].requires||[];let i=!s.some(c=>o.includes(c));const l=[e,...i?s:[]].filter(c=>c in r&&!o.includes(c));t.resources.push(...l.map(c=>({...r[c],allocated:0,isNew:!0,used:0,requested:0})))},Ix=(e,t)=>(e=[...e].sort(),t=[...t].sort(),e.length===t.length&&e.every((n,r)=>n===t[r])),Mi=(e,t)=>{const n=Ue(e,t);for(let r of n.actions)if(r.actionId==t.payload.actionId)return r},on=(e,t)=>e.projects[t.payload.grantNumber],Ue=(e,t)=>e.requests[t.payload.requestId],BE=(e,t)=>on(e,t).users.find(({username:n})=>n==t.payload.username),ld=({allocated:e,isActive:t,isCredit:n})=>e>0&&t&&!n,jm=e=>e.hasChanges=e.isNew||e.role!=e.initialRole||!Ix(e.resourceIds,e.initialResourceIds),$x=()=>document.querySelector("meta[name=csrf-token]").content,qE=async e=>{const t=new URLSearchParams({q:e});return(await(await fetch(`${ne.routes.search_people_path()}?${t}`)).json()).map(({eligible_reason:r,email:o,first_name:s,is_eligible:i,last_name:l,username:c,organization:u})=>({eligibility:i,eligibilityReason:r,email:o,firstName:s,lastName:l,username:c,organization:u}))},sa=rt("api/fetchProjectsList",async(e,{rejectWithValue:t})=>{const n=await fetch(`${ne.routes.projects_path()}.json`);return n.status==200?{username:e,projectsList:(await n.json()).result}:t({})}),Mx=rt("api/fetchProjectDetail",async({grantNumber:e},{rejectWithValue:t})=>t({grantNumber:e})),Ax=rt("api/fetchRequestDetail",async({grantNumber:e,requestId:t},{rejectWithValue:n})=>n({grantNumber:e,requestId:t})),ia=rt("api/fetchUsageDetail",async({grantNumber:e,requestId:t,resourceRepositoryKey:n},{rejectWithValue:r})=>{const o=await fetch(`${ne.routes.usage_detail_path(e,n)}.json`);return o.status==200?{grantNumber:e,requestId:t,resourceRepositoryKey:n,usageDetail:(await o.json()).usage}:r({grantNumber:e,requestId:t,resourceRepositoryKey:n})}),aa=rt("api/deleteAction",async({actionId:e,requestId:t},{getState:n,rejectWithValue:r})=>{const o=n().api.requests[t],s=o.actions.find(u=>u.actionId==e);if(!s||!s.allowedOperations||!s.allowedOperations.includes("Delete"))return r({actionId:e,requestId:t});const i=ne.routes.request_action_path(o.requestId,s.actionId),l={_method:"delete",authenticity_token:$x()};return(await fetch(i,{body:Object.keys(l).map(u=>`${encodeURIComponent(u)}=${encodeURIComponent(l[u])}`).join("&"),headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},method:"POST"})).status==200?{actionId:e,requestId:t}:r({actionId:e,requestId:t})}),la=rt("api/saveResources",async({requestId:e},{getState:t,rejectWithValue:n})=>{const r=t().api.requests[e],o={},s={};for(let{allocated:f,isFake:p,questions:m,requested:x,resourceId:y}of r.resources)if(x!=f&&!p){o[y]={resource_id:y,requested:1,amount:x-f};for(let{attributes:v,values:h,fieldType:g}of m)if(h.length){let b=v[0].resourceAttributeId,S=["drop_down","single_sel","multi_sel"].includes(g),C={resource_attribute_id:g=="multi_sel"?h:S?h[0]:b};S||(C.attribute_value=h[0]),s[b]=C}}const i={authenticity_token:$x(),request_action:{action_type:r.allowedActions.Exchange.name,user_comments:r.resourcesReason,resource_attributes:s},requested_resources:o},l=r.exchangeActionId?ne.routes.request_action_path(r.requestId,r.exchangeActionId):ne.routes.request_actions_path(r.requestId),c=await fetch(`${l}.json`,{body:JSON.stringify(i),headers:{"Content-Type":"application/json"},method:r.exchangeActionId?"PUT":"POST"});let u,d;try{const f=await c.json();u=f.errors,d=f.actionId}catch{u=["Unable to save exchange"],d=null}return c.status==200?{requestId:e,exchangeActionId:d}:n({requestId:e,exchangeActionId:d,errors:u})}),ca=rt("api/saveUsers",async({grantNumber:e},{getState:t,rejectWithValue:n})=>{const o=t().api.projects[e].users,s=o.filter(u=>!Ix(u.resourceIds,u.initialResourceIds)||u.isNew).length==0?[]:o.map(u=>({username:u.username,resources:u.resourceIds})),i=o.filter(u=>u.role!=u.initialRole).map(u=>({username:u.username,role:td[u.role],initialRole:td[u.initialRole]})),l={grantNumber:e,resourceChanges:s,roleChanges:i,authenticity_token:document.querySelector("meta[name=csrf-token]").content};return(await fetch(ne.routes.projects_save_users_path(),{method:"POST",body:JSON.stringify(l),headers:{"Content-Type":"application/json"}})).status==200?{grantNumber:e}:n({grantNumber:e})}),Dx=Lr({name:"api",initialState:{error:null,projectsList:[],projectListLoading:!1,projects:{},requests:{},username:null},reducers:{addResource:(e,t)=>{const{resourceId:n}=t.payload,r=Ue(e,t);Sm(n,r)},addUser:(e,t)=>{const n=on(e,t),r=e.requests[n.currentRequestId],{user:o}=t.payload;n.users.map(({username:s})=>s).includes(o.username)||(n.users.push({...o,resourceIds:r.resources.filter(ld).map(s=>s.resourceId),role:"user",initialResourceIds:[],initialRole:"user",hasChanges:!0,isNew:!0}),n.usersNewRowIndex=n.users.length-1)},closeUsageDetailModal:(e,t)=>{const n=Ue(e,t);n.usageDetail=null,n.usageDetailStatus=null},resetResources:(e,t)=>{const n=Ue(e,t);n.resourcesReason="",n.resources=n.resources.filter(r=>r.isCredit||r.allocated).map(r=>({...r,requested:r.allocated}))},resetUsers:(e,t)=>{const n=on(e,t);n.users=n.users.filter(({isNew:r})=>!r).map(r=>({...r,resourceIds:[...r.initialResourceIds],role:r.initialRole,hasChanges:!1}))},setRequest:(e,t)=>{const n=on(e,t);n&&(n.selectedRequestId=t.payload.requestId,n.tab=="users"&&n.currentRequestId!=n.selectedRequestId&&(n.tab="overview"))},setResourceQuestionValues:(e,t)=>{const{attributeSetId:n,resourceId:r,values:o}=t.payload,s=Ue(e,t);for(let i of s.resources)if(i.resourceId==r){for(let l of i.questions)if(l.attributeSetId==n){l.values=o;break}break}},setResourceRequest:(e,t)=>{const{resourceId:n,requested:r}=t.payload,o=Ue(e,t);let s,i=0;for(let l of o.resources)l.resourceId==n&&(l.requested=r,l.requested!=l.allocated&&Sm(l.resourceId,o)),l.isCredit?(s=l,i+=l.allocated*l.exchangeRates.base.unitCost):i-=rd(l,"difference");s&&(s.requested=mo(i,s.decimalPlaces,"floor"))},setResourcesReason:(e,t)=>{const n=Ue(e,t);n.resourcesReason=t.payload.reason},setTab:(e,t)=>{const n=on(e,t);n&&(n.tab=t.payload.tab)},setUserRole:(e,t)=>{const n=BE(e,t);n.role=t.payload.role,jm(n)},toggleActionsModal:(e,t)=>{const n=Ue(e,t);n.showActionsModal=!n.showActionsModal},toggleConfirmModal:(e,t)=>{const n=Ue(e,t);n.showConfirmModal=!n.showConfirmModal},toggleDeleteModal:(e,t)=>{const n=Mi(e,t);n.showDeleteModal=!n.showDeleteModal},toggleResourcesModal:(e,t)=>{const n=Ue(e,t);n.showResourcesModal=!n.showResourcesModal},toggleUsersResources:(e,t)=>{const n=on(e,t),r=e.requests[n.currentRequestId],{username:o,resourceId:s,checked:i}=t.payload,l=o?[n.users.find(c=>c.username==o)]:n.users;for(let c of l){if(s){let u=c.resourceIds.indexOf(s);i&&u==-1?c.resourceIds.push(s):!i&&u>=0&&c.resourceIds.splice(u,1)}else c.resourceIds=i?r.resources.filter(ld).map(({resourceId:u})=>u):[];jm(c)}}},extraReducers:e=>{e.addCase(sa.pending,t=>{t.projectListLoading=!0}).addCase(sa.fulfilled,(t,n)=>{n.payload.projectsList.sort((r,o)=>Za(r.requests[0])>Za(o.requests[0])?-1:1),t.username=n.payload.username,t.projectsList=n.payload.projectsList.map(r=>{const{grantNumber:o,requestMasterId:s,requests:i,status:l,title:c}=r,d=r.requests.filter(f=>f.actions.filter(p=>p.returnedForCorrections).length>0).length>0?"Returned for Corrections":l||i&&(i.find(({timeStatus:f})=>f=="current")?"Active":i[0].timeStatus=="past"?"Inactive":i[0].status);return i&&UE(t,r,d),{grantNumber:o||s,status:d,title:c}}),t.projectListLoading=!1}).addCase(sa.rejected,t=>{t.error="Failed to load project list.",t.projectListLoading=!1}).addCase(Mx.rejected,(t,n)=>{const{grantNumber:r}=n.payload;t.projects[r]={error:"Failed to load project data."}}).addCase(Ax.rejected,(t,n)=>{const{requestId:r}=n.payload;t.requests[r]={error:"Failed to load request data."}}).addCase(ia.pending,(t,n)=>{const r=Ue(t,{payload:n.meta.arg});r.usageDetailStatus=Ve.pending}).addCase(ia.fulfilled,(t,n)=>{const r=Ue(t,n);r.usageDetail=n.payload.usageDetail,r.usageDetailStatus=Ve.success}).addCase(ia.rejected,(t,n)=>{const r=Ue(t,n);r.usageDetailStatus=Ve.error}).addCase(aa.pending,(t,n)=>{const r=Mi(t,{payload:n.meta.arg});r.deleteStatus=Ve.pending}).addCase(aa.fulfilled,(t,n)=>{const r=Ue(t,n),o=Mi(t,n);o.isRequest?(r.error="This request has been deleted.",o.allowedOperations=[]):r.actions=r.actions.filter(s=>s.actionId!=o.actionId),o.deleteStatus=Ve.success,o.showDeleteModal=!1}).addCase(aa.rejected,(t,n)=>{const r=Mi(t,n);r.deleteStatus=Ve.error}).addCase(la.pending,(t,n)=>{const r=Ue(t,{payload:n.meta.arg});r.exchangeStatus=Ve.pending,r.showResourcesModal=!1}).addCase(la.fulfilled,(t,n)=>{const r=Ue(t,n);r.exchangeActionId=n.payload.exchangeActionId,r.exchangeActionEditable=!1,r.exchangeErrors=[],r.exchangeStatus=Ve.success}).addCase(la.rejected,(t,n)=>{const r=Ue(t,n);r.exchangeActionId=n.payload.exchangeActionId,r.exchangeActionEditable=!0,r.exchangeErrors=n.payload.errors,r.exchangeStatus=Ve.error}).addCase(ca.pending,(t,n)=>{const r=on(t,{payload:n.meta.arg});r.usersStatus=Ve.pending}).addCase(ca.fulfilled,(t,n)=>{const r=on(t,n);r.users=r.users.map(o=>({...o,initialResourceIds:[...o.resourceIds],initialRole:o.role,hasChanges:!1,isNew:!1})),r.usersStatus=Ve.success}).addCase(ca.rejected,(t,n)=>{const r=on(t,n);r.usersStatus=Ve.error})}}),HE=e=>e.api.error,WE=e=>e.api.projectsList,KE=e=>e.api.projectListLoading,YE=(e,t)=>on(e.api,{payload:{grantNumber:t}}),GE=(e,t)=>Ue(e.api,{payload:{requestId:t}}),QE=e=>e.api.username,{addResource:XE,addUser:ZE,closeUsageDetailModal:JE,hideAlert:eD,resetResources:eR,resetUsers:tR,setRequest:nR,setResourceQuestionValues:rR,setResourceRequest:oR,setResourcesReason:sR,setTab:iR,setUserRole:aR,toggleActionsModal:lR,toggleConfirmModal:cR,toggleDeleteModal:uR,toggleResourcesModal:dR,toggleUsersResources:fR}=Dx.actions,pR=Dx.reducer,hR=e=>{const t=Y(HE),n=Y(KE),r=Y(WE),o=ge();return w.useEffect(()=>{o(sa(e))},[]),{error:t,loading:n,projects:r}},kt=(e,t)=>{const n=Y(s=>YE(s,e)),r=Y(QE),o=ge();return w.useEffect(()=>{!n&&!t&&o(Mx({grantNumber:e}))},[t]),{project:n,addUser:s=>o(ZE({grantNumber:e,user:s})),resetUsers:()=>o(tR({grantNumber:e})),saveUsers:()=>o(ca({grantNumber:e})),setRequest:s=>o(nR({grantNumber:e,requestId:s})),setTab:s=>o(iR({grantNumber:e,tab:s})),setUserRole:(s,i)=>o(aR({grantNumber:e,username:s,role:i})),statuses:Ve,toggleUsersResources:(s,i,l)=>o(fR({grantNumber:e,username:i,resourceId:l,checked:s})),username:r}},ut=(e,t)=>{const n=Y(o=>GE(o,e)),r=ge();return w.useEffect(()=>{n||r(Ax({grantNumber:t,requestId:e}))},[t,e]),{request:n,addResource:o=>r(XE({requestId:e,resourceId:o})),closeUsageDetailModal:()=>r(JE({requestId:e})),deleteAction:o=>r(aa({actionId:o,requestId:e})),openUsageDetailModal:o=>r(ia({grantNumber:n.grantNumber,requestId:e,resourceRepositoryKey:o})),resetResources:()=>r(eR({requestId:e})),saveResources:()=>r(la({requestId:e})),setResourceQuestionValues:(o,s,i)=>r(rR({requestId:e,resourceId:o,attributeSetId:s,values:i})),setResourceRequest:(o,s)=>r(oR({requestId:e,resourceId:o,requested:s})),setResourcesReason:o=>r(sR({requestId:e,reason:o})),statuses:Ve,toggleActionsModal:()=>r(lR({requestId:e})),toggleConfirmModal:()=>r(cR({requestId:e})),toggleDeleteModal:o=>r(uR({requestId:e,actionId:o})),toggleResourcesModal:()=>r(dR({requestId:e}))}},mR="_project_qqnbz_1",gR="_expand_qqnbz_5",Cm={project:mR,expand:gR},vR="_returnedForCorrectionsNotes_jujbd_1",yR={returnedForCorrectionsNotes:vR};function Fx(e,t,n){const r=w.useRef(e!==void 0),[o,s]=w.useState(t),i=e!==void 0,l=r.current;return r.current=i,!i&&l&&o!==t&&s(t),[i?e:o,w.useCallback((...c)=>{const[u,...d]=c;let f=n==null?void 0:n(u,...d);return s(u),f},[n])]}const Ja={prefix:String(Math.round(Math.random()*1e10)),current:0},Lx=Re.createContext(Ja),xR=Re.createContext(!1);let bR=!!(typeof window<"u"&&window.document&&window.document.createElement),Uc=new WeakMap;function wR(e=!1){let t=w.useContext(Lx),n=w.useRef(null);if(n.current===null&&!e){var r,o;let s=(o=Re.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED)===null||o===void 0||(r=o.ReactCurrentOwner)===null||r===void 0?void 0:r.current;if(s){let i=Uc.get(s);i==null?Uc.set(s,{id:t.current,state:s.memoizedState}):s.memoizedState!==i.state&&(t.current=i.id,Uc.delete(s))}n.current=++t.current}return n.current}function SR(e){let t=w.useContext(Lx);t===Ja&&!bR&&console.warn("When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.");let n=wR(!!e),r=`react-aria${t.prefix}`;return e||`${r}-${n}`}function jR(e){let t=Re.useId(),[n]=w.useState(RR()),r=n?"react-aria":`react-aria${Ja.prefix}`;return e||`${r}-${t}`}const Ux=typeof Re.useId=="function"?jR:SR;function CR(){return!1}function _R(){return!0}function ER(e){return()=>{}}function RR(){return typeof Re.useSyncExternalStore=="function"?Re.useSyncExternalStore(ER,CR,_R):w.useContext(xR)}const NR=w.createContext(null),Uo=NR,kR=w.createContext(null),$r=(e,t=null)=>e!=null?String(e):t||null,Ln=kR;function OR(e){const t=w.useRef(e);return w.useEffect(()=>{t.current=e},[e]),t}function Te(e){const t=OR(e);return w.useCallback(function(...n){return t.current&&t.current(...n)},[t])}const _m=e=>!e||typeof e=="function"?e:t=>{e.current=t};function TR(e,t){const n=_m(e),r=_m(t);return o=>{n&&n(o),r&&r(o)}}function gn(e,t){return w.useMemo(()=>TR(e,t),[e,t])}function Hf({children:e,in:t,onExited:n,mountOnEnter:r,unmountOnExit:o}){const s=w.useRef(null),i=w.useRef(t),l=Te(n);w.useEffect(()=>{t?i.current=!0:l(s.current)},[t,l]);const c=gn(s,e.ref),u=w.cloneElement(e,{ref:c});return t?u:o||!i.current&&r?null:u}const PR=["active","eventKey","mountOnEnter","transition","unmountOnExit","role","onEnter","onEntering","onEntered","onExit","onExiting","onExited"],IR=["activeKey","getControlledId","getControllerId"],$R=["as"];function cd(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}function Vx(e){let{active:t,eventKey:n,mountOnEnter:r,transition:o,unmountOnExit:s,role:i="tabpanel",onEnter:l,onEntering:c,onEntered:u,onExit:d,onExiting:f,onExited:p}=e,m=cd(e,PR);const x=w.useContext(Uo);if(!x)return[Object.assign({},m,{role:i}),{eventKey:n,isActive:t,mountOnEnter:r,transition:o,unmountOnExit:s,onEnter:l,onEntering:c,onEntered:u,onExit:d,onExiting:f,onExited:p}];const{activeKey:y,getControlledId:v,getControllerId:h}=x,g=cd(x,IR),b=$r(n);return[Object.assign({},m,{role:i,id:v(n),"aria-labelledby":h(n)}),{eventKey:n,isActive:t==null&&b!=null?$r(y)===b:t,transition:o||g.transition,mountOnEnter:r??g.mountOnEnter,unmountOnExit:s??g.unmountOnExit,onEnter:l,onEntering:c,onEntered:u,onExit:d,onExiting:f,onExited:p}]}const zx=w.forwardRef((e,t)=>{let{as:n="div"}=e,r=cd(e,$R);const[o,{isActive:s,onEnter:i,onEntering:l,onEntered:c,onExit:u,onExiting:d,onExited:f,mountOnEnter:p,unmountOnExit:m,transition:x=Hf}]=Vx(r);return a.jsx(Uo.Provider,{value:null,children:a.jsx(Ln.Provider,{value:null,children:a.jsx(x,{in:s,onEnter:i,onEntering:l,onEntered:c,onExit:u,onExiting:d,onExited:f,mountOnEnter:p,unmountOnExit:m,children:a.jsx(n,Object.assign({},o,{ref:t,hidden:!s,"aria-hidden":!s}))})})})});zx.displayName="TabPanel";const Bx=e=>{const{id:t,generateChildId:n,onSelect:r,activeKey:o,defaultActiveKey:s,transition:i,mountOnEnter:l,unmountOnExit:c,children:u}=e,[d,f]=Fx(o,s,r),p=Ux(t),m=w.useMemo(()=>n||((y,v)=>p?`${p}-${v}-${y}`:null),[p,n]),x=w.useMemo(()=>({onSelect:f,activeKey:d,transition:i,mountOnEnter:l||!1,unmountOnExit:c||!1,getControlledId:y=>m(y,"tabpane"),getControllerId:y=>m(y,"tab")}),[f,d,i,l,c,m]);return a.jsx(Uo.Provider,{value:x,children:a.jsx(Ln.Provider,{value:f||null,children:u})})};Bx.Panel=zx;const qx=Bx;var Hx={exports:{}};/*!
|
|
55
55
|
Copyright (c) 2018 Jed Watson.
|
package/dist/xras-ui.js
CHANGED
|
@@ -9765,7 +9765,7 @@ const Bf = Re.memo(function({
|
|
|
9765
9765
|
/* @__PURE__ */ a.jsx(
|
|
9766
9766
|
Yr,
|
|
9767
9767
|
{
|
|
9768
|
-
label: `Minimum exchange amount, in ${(p = r.find((m) => m.value.toString() === t.unit_type_id)) == null ? void 0 : p.label}`,
|
|
9768
|
+
label: `Minimum exchange amount, in ${(p = r.find((m) => m.value.toString() === t.unit_type_id.toString())) == null ? void 0 : p.label}`,
|
|
9769
9769
|
value: t.min_exchange,
|
|
9770
9770
|
onChange: (m) => o(Br("min_exchange", m.target.value)),
|
|
9771
9771
|
inputClassName: "span8"
|