1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8677,11157,11379,23688,25650,31058,62989,90666,92537],{1975:(e,t,a)=>{"use strict";a.d(t,{U:()=>c});var s=a(83815),i=a(27149),n=a(96985),l=a(99888),r=a(137),o=a(98839),d=a(95001);a(15721);let c=e=>{var t;let{disabledDates:a,_selectedStartDate:c,_selectedEndDate:m,classNames:u={},onSelect:x,defaultMonth:h,...g}=e,{selected:p,day:b,button_previous:v,button_next:f,day_button:j,weekday:y,chevron:w,root:N,range_start:k,range_middle:_,range_end:C,today:S,...I}=u,{locale:A="it"}=(0,l.useRouter)(),z=(0,o.h)();return(0,s.jsx)(r.h,{className:"text-md",locale:(0,i.no)(A),mode:"range",selected:{from:c,to:m},defaultMonth:null!=(t=null!=h?h:c)?t:(0,n.A)(new Date,1),onSelect:x,disabled:a,numberOfMonths:["xs","sm"].includes(z)?1:2,showOutsideDays:!0,fixedWeeks:!0,classNames:{root:(0,d.cn)("rdp-root !text-white",N),outside:(0,d.cn)("rdp-outside pointer-events-none invisible"),selected:(0,d.cn)("rdp-selected bg-dark-mode-blue-500",p),day_button:(0,d.cn)("rdp-day_button !border-none hover:bg-dark-mode-blue-500",j),button_previous:(0,d.cn)("rdp-button_previous hover:!bg-dark-mode-blue-500",v),button_next:(0,d.cn)("rdp-button_next hover:!bg-dark-mode-blue-500",f),chevron:(0,d.cn)("rdp-chevron !fill-white",w),weekday:(0,d.cn)("rdp-weekday",y),day:(0,d.cn)("rdp-day border-none",b),range_start:(0,d.cn)("bg-gradient-to-r from-transparent from-50% to-dark-mode-blue-500 to-50% [&>button]:!bg-dark-mode-blue-500",k),...I,range_middle:(0,d.cn)("bg-dark-mode-blue-500",_),range_end:(0,d.cn)("bg-gradient-to-l from-transparent from-50% to-dark-mode-blue-500 to-50% [&>button]:!bg-dark-mode-blue-500",C),today:(0,d.cn)("rdp-today !text-white",S)},...g})}},3539:(e,t,a)=>{"use strict";a.d(t,{ES:()=>d,On:()=>n,Px:()=>l,Vx:()=>o,e_:()=>s,xz:()=>i});let s=["cardinal_n","cardinal_e","cardinal_s","cardinal_w"],i=["ground","panorama"],n=[...s,...i];function l(e){return"pinNotes.types.".concat(e)}let r={cardinal_n:"N",cardinal_e:"E",cardinal_s:"S",cardinal_w:"O",ground:"â£",panorama:"â±"};function o(e){return!!e&&n.includes(e)}function d(e){var t;return e?null!=(t=r[e])?t:"â¢":null}},4141:(e,t,a)=>{"use strict";function s(e){var t,a;let s=null==e||null==(t=e.field_image_url)?void 0:t.trim();return s?{url:s,isFieldPhoto:!0}:{url:(null==e||null==(a=e.image_url)?void 0:a.trim())||null,isFieldPhoto:!1}}a.d(t,{B:()=>s})},8677:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>s});let s=a(11157).default},11157:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>N});var s=a(83815),i=a(52656),n=a(53325),l=a(11379),r=a(52375),o=a(84723),d=a.n(o),c=a(99888),m=a(70679),u=a(3324),x=a(19021),h=a(42708),g=a(26874),p=a(95001),b=a(17171),v=a.n(b);let f=[50,50],j={topLeft:f,bottomRight:f},y=e=>{let{bounds:t,maxZoom:a,fitPadding:s}=e,i=(0,m.useRef)(t),n=(0,u.ko)();return(0,m.useEffect)(()=>{let e=i.current,l=t.length!==e.length||t.some((t,a)=>{var s,i;return t[0]!==(null==(s=e[a])?void 0:s[0])||t[1]!==(null==(i=e[a])?void 0:i[1])});if(0!==t.length&&l){try{n.fitBounds(t,{animate:!1,maxZoom:a,paddingTopLeft:s.topLeft,paddingBottomRight:s.bottomRight}),i.current=t}catch(e){}return()=>{try{n.stop()}catch(e){}}}},[t,n,a,s]),null},w=e=>{let{clearActiveMarkerOnMapClick:t}=e;return(0,u.Po)({click:e=>{t&&(0,l.IC)(e.target)}}),null},N=(0,m.memo)(e=>{var t;let{id:a,bounds:l,height:o="800px",width:u="100%",children:b,className:f,variant:N="orange",center:k,zoom:_=9,maxZoom:C=r.gl,minZoom:S,refreshBoundsZoom:I=!0,maxZoomRefreshBounds:A=7.5,zoomControls:z=!1,mapExtraOptions:R,classNames:D,clearActiveMarkerOnMapClick:M=!0,zoomControlsPosition:T="bottomleft",fitPadding:E=j}=e,L=(0,m.useRef)(null),{locale:F="it"}=(0,c.useRouter)();return(0,s.jsx)("div",{id:a,ref:L,className:(0,p.cn)(v().map,"hiveMap",f,null==D?void 0:D.container,{[v()["map--".concat(N)]]:N}),children:(0,s.jsxs)(x.W,{center:null!=k?k:(0,g.I)(F,l),zoom:l.length>1?void 0:_,style:{height:o,width:u},dragging:!d().Browser.mobile,scrollWheelZoom:d().Browser.mobile,zoomControl:z,maxZoom:C,minZoom:S,tap:!d().Browser.mobile,bounds:l||[],boundsOptions:{paddingTopLeft:E.topLeft,paddingBottomRight:E.bottomRight},attributionControl:!1,className:null==D?void 0:D.mapContainer,...R,children:[(0,s.jsx)(i.G,{}),(0,s.jsx)(w,{clearActiveMarkerOnMapClick:M}),(0,s.jsx)(n.Q,{maxZoom:r.gl}),b,l&&I&&(0,s.jsx)(y,{bounds:l,maxZoom:A,fitPadding:E}),!d().Browser.mobile&&(null==(t=null==R?void 0:R.zoomControl)||t)&&(0,s.jsx)(h.p,{position:T})]})})})},11379:(e,t,a)=>{"use strict";a.d(t,{IC:()=>u,xb:()=>v,jj:()=>p,No:()=>x,yw:()=>h,FL:()=>c,_f:()=>d,An:()=>g,zu:()=>f,zk:()=>b,Wb:()=>o,i_:()=>m});var s=a(56771);a(44689),a(41013),a(19025);var i=a(99093);a(28571),a(73857);var n=a(84723),l=a.n(n),r=a(12259);let o=e=>
1Array.isArray(e)?e:[[e.getSouthWest().lat,e.getSouthWest().lng],[e.getNorthEast().lat,e.getNorthEast().lng]],d=e=>{let{center:t,distance:a}=e,[n,r]=(0,s.A)((0,i.zx)([t.lng,t.lat]),a,0,{units:"meters"}).geometry.coordinates.reverse(),[o,d]=(0,s.A)((0,i.zx)([t.lng,t.lat]),a,90,{units:"meters"}).geometry.coordinates.reverse(),[c,m]=(0,s.A)((0,i.zx)([t.lng,t.lat]),a,180,{units:"meters"}).geometry.coordinates.reverse(),[u,x]=(0,s.A)((0,i.zx)([t.lng,t.lat]),a,270,{units:"meters"}).geometry.coordinates.reverse();return l().latLngBounds([[n,r],[o,d],[c,m],[u,x]])},c=e=>{let{bbox:t,distance:a,fromCenter:n}=e;return n?d({center:t.getCenter(),distance:a}):(e=>{let{vertices:t,distance:a}=e,[n,r]=(0,s.A)((0,i.zx)([t.northEast.lng,t.northEast.lat]),a,45,{units:"meters"}).geometry.coordinates.reverse(),[o,d]=(0,s.A)((0,i.zx)([t.northWest.lng,t.northWest.lat]),a,-45,{units:"meters"}).geometry.coordinates.reverse(),[c,m]=(0,s.A)((0,i.zx)([t.southEast.lng,t.southEast.lat]),a,135,{units:"meters"}).geometry.coordinates.reverse(),[u,x]=(0,s.A)((0,i.zx)([t.southWest.lng,t.southWest.lat]),a,-135,{units:"meters"}).geometry.coordinates.reverse();return l().latLngBounds([[n,r],[o,d],[c,m],[u,x]])})({vertices:(e=>({northEast:e.getNorthEast(),northWest:e.getNorthWest(),southEast:e.getSouthEast(),southWest:e.getSouthWest
1()}))(t),distance:a})},m=(e,t)=>{try{if(!e||!t)return[...e||[],...t||[]];let a=l().latLngBounds([[e[0][0],e[0][1]],[e[1][0],e[1][1]]]),s=l().latLngBounds([[t[0][0],t[0][1]],[t[1][0],t[1][1]]]);return a.contains(s)?a.extend(s):s.contains(a)?s.extend(a):a.extend(s),[[a.getNorthEast().lat,a.getNorthEast().lng],[a.getSouthWest().lat,a.getSouthWest().lng]]}catch(a){return[...e||[],...t||[]]}},u=e=>{e.eachLayer(e=>{e instanceof l().Marker&&e.options["icon-default"]&&e.setIcon(e.options["icon-default"])})},x=e=>{let t=l().geoJSON(e).getBounds();return t.isValid()?[[t.getNorthEast().lat,t.getNorthEast().lng],[t.getSouthWest().lat,t.getSouthWest().lng]]:[]};function h(e){let{e:t,image:a,canvas:s,overlay:i}=e;if(!s||!a||!i)return null;let n=s.getContext("2d",{willReadFrequently:!0});if(s.width=i._image.width,s.height=i._image.height,!n)return null;n.drawImage(a,0,0,s.width,s.height);let l=t.originalEvent.offsetX,o=t.originalEvent.offsetY,[d,c,m,u]=n.getImageData(l,o,1,1).data;return{r:d,g:c,b:m,a:u,hex:(0,r.Ob)(d,c,m)}}function g(e,t){var a;let s=e.split("/").slice(0,-1).join("/"),i=null==(a=e.split("/").pop())?void 0:a.split(".").slice(0,-1).join("."),n="".concat(i,".").concat(t.replace("#",""),".png");return"".concat(s,"/").concat(n)}function p(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:50,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:20,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:25,n=a/2,l=a/2,r=Object.values(e).reduce((e,t)=>e+t,0),o=-Math.PI/2,d=[],c=Object.keys(e);if(1===c.length){let e=c[0],t=e.startsWith("#")?e:"#".concat(e);d.push('<circle cx="'.concat(n,'" cy="').concat(l,'" r="').concat(i,'" fill="').concat(t,'" />')),d.push('<circle cx="'.concat(n,'" cy="').concat(l,'" r="').concat(s,'" fill="#fff" />'))}else for(let[t,a]of Object.entries(e)){let e=a/r*2*Math.PI,c=o,m=c+e,u=n+i*Math.cos(c),x=l+i*Math.sin(c),h=n+i*Math.cos(m),g=l+i*Math.sin(m),p=n+s*Math.cos(m),b=l+s*Math.sin(m),v=n+s*Math.cos(c),f=l+s*Math.sin(c),j=+(e>Math.PI),y=t.startsWith("#")?t:"#".concat(t),w=["M ".concat(u.toFixed(2)," ").concat(x.toFixed(2)),"A ".concat(i," ").concat(i," 0 ").concat(j," 1 ").concat(h.toFixed(2)," ").concat(g.toFixed(2)),"L ".concat(p.toFixed(2)," ").concat(b.toFixed(2)),"A ".concat(s," ").concat(s," 0 ").concat(j," 0 ").concat(v.toFixed(2)," ").concat(f.toFixed(2)),"Z"].join(" ");d.push('<path d="'.concat(w,'" fill="').concat(y,'" />')),o=m}return'\n<svg width="'.concat(a,'" height="').concat(a,'" viewBox="0 0 ').concat(a," ").concat(a,'" xmlns="http://www.w3.org/2000/svg">\n ').concat(d.join("\n "),'\n\n \x3c!-- full inner circle to cover the center --\x3e\n <circle cx="').concat(n,'" cy="').concat(l,'" r="').concat(s,'" fill="#fff" />\n\n \x3c!-- childCount text in the center --\x3e\n <text\n x="').concat(n,'"\n y="').concat(l,'"\n text-anchor="middle"\n dominant-baseline="central"\n font-size="').concat(s,'px"\n fill="#333"\n>').concat(t,"</text>\n</svg>\n").trim()}function b(e,t){let{lat:a,lng:s}=e.getLatLng();return t.some(e=>!!e.getBounds().contains({lat:a,lng:s})&&function(e,t){let[a,s]=e,i=!1;for(let e=0,n=t.length-1;e<t.length;n=e++){let l=t[e][0],r=t[e][1],o=t[n][0],d=t[n][1];r>s!=d>s&&a<(o-l)*(s-r)/(d-r)+l&&(i=!i)}return i}([s,a],e.getLatLngs()[0].map(e=>{let{lat:t,lng:a}=e;return[a,t]})))}let v=e=>{if(!e||0===e.length)return null;try{let t=e.map(e=>e.map(e=>{let[t,a]=e;return[a,t]})),a=l().geoJSON({type:"Polygon",coordinates:t}
1).getBounds(),s=a.getSouthWest().lat,i=a.getSouthWest().lng,n=a.getNorthEast().lat,r=a.getNorthEast().lng;return[[s,i],[n,r]]}catch(e){return null}},f=(e,t)=>{let a=h(e);if(!a)return{id:null,hex:null};let{r:s,g:i,b:n,hex:l}=a,r="".concat(t,"-rgb(").concat(s,", ").concat(i,", ").concat(n,")"),o=document.getElementById(r);return o?(o.scrollIntoView({block:"nearest",inline:"center",behavior:"smooth"}),{id:r,hex:l}):{id:null,hex:null}}},11549:(e,t,a)=>{"use strict";a.d(t,{X:()=>o});var s=a(83815),i=a(60938),n=a(54002),l=a(95001);let r=[{key:"images",icon:"material-symbols:photo-camera-outline",color:"text-dark-mode-monitoring-600(base)",labelKey:"transectsOverview.chips.photos"},{key:"videos",icon:"material-symbols:videocam-outline",color:"text-dark-mode-blue-1100",labelKey:"transectsOverview.chips.videos"},{key:"notes",icon:"material-symbols:sticky-note-2-outline",color:"text-dark-mode-blue-1100",labelKey:"transectsOverview.chips.notes"},{key:"pins",icon:"material-symbols:location-on-outline",color:"text-dark-mode-blue-1100",labelKey:"transectsOverview.chips.pins"}],o=e=>{let{counts:t,size:a="md"}=e,{t:o}=(0,n.A)("monitoring"),d=r.filter(e=>t[e.key]>0);return 0===d.length?(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-800",children:o("monitoring-observations:transectsOverview.chips.empty")}):(0,s.jsx)("div",{className:"flex flex-wrap items-center gap-1.5",children:d.map(e=>(0,s.jsxs)("span",{className:(0,l.cn)("inline-flex items-center gap-1 rounded-full border border-dark-mode-blue-600(base) font-medium text-white","sm"===a?"px-2 py-0.5 text-[11px]":"px-2.5 py-1 text-xs"),children:[(0,s.jsx)(i.In,{icon:e.icon,width:"sm"===a?12:14,height:"sm"===a?12:14,className:e.color}),o("monitoring-observations:".concat(e.labelKey),{count:t[e.key]})]},e.key))})}},12166:(e,t,a)=>{"use strict";a.d(t,{E:()=>n});var s=a(83815),i=a(95001);function n(e){let{className:t,...a}=e;return(0,s.jsx)("div",{"data-slot":"skeleton",className:(0,i.cn)("bg-muted animate-pulse rounded-md",t),...a})}},17171:e=>{e.exports={map:"InteractiveMap_map__dJGhL"}},21490:(e,t,a)=>{"use strict";a.d(t,{$i:()=>n,Wj:()=>r,Y:()=>s,mt:()=>l,y:()=>i});let s="https://3bee-assets.s3.eu-south-1.amazonaws.com/oasi/insert_sites_csv_template.csv",i={"Cat 115hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5807/burst_20240514_103622.wav","Cat 122hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/6007/burst_20240514_104153.wav","Cat 130hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5823/burst_20240509_112750.wav","Cat 137hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5773/burst_20240511_101503.wav","Cat 145hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5990/burst_20240419_113517.wav","Cat 152hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5855/burst_20240504_161051.wav","Cat 160hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5866/burst_20240505_092710.wav","Cat 167hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5802/burst_20240515_134846.wav","Cat 175hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5493/burst_20240501_053710.wav","Cat 182hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5855/burst_20240511_073839.wav","Cat 190hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5822/burst_20240514_081933.wav","Cat 197hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5887/burst_20240504_074739.wav","Cat 205hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5753/burst_20240508_083417.wav","Cat 212hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5827/burst_20240512_051421.wav","Cat 220hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5855/burst_20240511_103652.wav","Cat 227hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/6017/burst_20240509_122037.wav","Cat 235hz":"https://spectrum-bursts-upload.s3.eu-central-1.amazonaws.com/5855/burst_20240504_102603.wav"},n={encore:"encore-section",highlights:"highlights-section",kpis:"monitoring-kpis-section",tabs:"tabs-sections",sounds:"sounds-section"},l=["A","B","C","D","E","F"],r="N/A"},22038:(e,t,a)=>{"use strict";a.d(t,{m:()=>n});var s=a(70679),i=a(28229);let n=()=>{let{filterSpecies:e,filterClass:t,filterOrder:a,filterFamily:n,filterGenre:l}=(0,i._R)(),r=(0,s.useMemo)(()=>({exclude_taxa:i.Wg}),[]),o=(0,s.useMemo)(()=>({...e.size>0&&{iconic_taxa:Array.from(e.keys()).join(",")},exclude_taxa:i.Wg}),[e]),d=(0,s.useMemo)(()=>({...e.size>0&&{iconic_taxa:Array.from(e.keys()).join(",")},...t.size>0&&{class_taxa:Array.from(t.keys()).join(",")},exclude_taxa:i.Wg}),[e,t]),c=(0,s.useMemo)(()=>({...e.size>0&&{iconic_taxa:Array.from(e.keys()).join(",")},...t.size>0&&{class_taxa:Array.from(t.keys()).join(",")},...a.size>0&&{order_taxa:Array.from(a.keys()).join(",")},exclude_taxa:i.Wg}),[e,t,a]);return{iconicTaxaCascadeParams:r,classCascadeParams:o,orderCascadeParams:d,familyCascadeParams:c,genusCascadeParams:(0,s.useMemo)(()=>({...e.size>0&&{iconic_taxa:Array.from(e.keys()).join(",")},...t.size>0&&{class_taxa:Array.from(t.keys()).join(",")},...a.size>0&&{order_taxa:Array.from(a.keys()).join(",")},...n.size>0&&{family_taxa:Array.from(n.keys()).join(",")},exclude_taxa:i.Wg}),[e,t,a,n]),taxaCascadeParams:(0,s.useMemo)(()=>({...e.size>0&&{iconic_taxa:Array.from(e.keys()).join(",")},...t.size>0&&{class_taxa:Array.from(t.keys()).join(",")},...a.size>0&&{order_taxa:Array.from(a.keys()).join(",")},...n.size>0&&{family_taxa:Array.from(n.keys()).join(",")},...l.size>0&&{genus_taxa:Array.from(l.keys()).join(",")},exclude_taxa:i.Wg}),[e,t,a,n,l])}}},26874:(e,t,a)=>{"use strict";a.d(t,{I:()=>i});let s={it:[42,13],es:[40,-4]},i=(e,t)=>{var a,i;if(!(null==t?void 0:t.length)||t.reduce((e,t)=>
1e&&null===t[0]&&null===t[1],!0))return null!=(a=s[e])?a:s.it;let n=t.filter(e=>null!==e[0]&&null!==e[1]);if(!n.length)return null!=(i=s[e])?i:s.it;let l=Math.min(...n.map(e=>e[0])),r=Math.max(...n.map(e=>e[0]));return[(l+r)/2,(Math.min(...n.map(e=>e[1]))+Math.max(...n.map(e=>e[1])))/2]}},27942:(e,t,a)=>{"use strict";a.d(t,{HL:()=>j,H0:()=>g,yd:()=>b,rd:()=>h,bL:()=>u,cw:()=>v,Id:()=>f,TZ:()=>p});var s=a(83815);a(60938);var i=a(21547),n=a(86666),l=a.n(n),r=a(70679),o=a(54066),d=a(95001);let c=(0,r.createContext)({media:[],mediaOnViewIndex:0,setMediaOnViewIndex:()=>{},mode:null}),m=()=>{let e=(0,r.useContext)(c);if(!e)throw Error("You are using this hook outside GalleryWithPreview context");return e},u=e=>{let{children:t,media:a,mode:i=null}=e,[n,l]=(0,r.useState)(0);return(0,s.jsx)(c.Provider,{value:{media:a,mediaOnViewIndex:n,setMediaOnViewIndex:l,mode:i},children:(0,s.jsx)("div",{className:(0,d.cn)("vertical"===i?"flex flex-col gap-y-5":"grid grid-cols-1 gap-x-8 gap-y-5 lg:grid-cols-12"),children:t})})},x=e=>{let{src:t,alt:a="gallery image",className:i,onLoad:n,...c}=e,[m,u]=(0,r.useState)(!1);return(0,s.jsxs)(s.Fragment,{children:[!m&&(0,s.jsx)(o.A,{width:"100%",height:"100%",containerClassName:"h-full w-full"}),(0,s.jsx)(l(),{src:t,alt:a,className:(0,d.cn)("object-cover",i,!m&&"!opacity-0"),...c,onLoad:e=>{u(!0),null==n||n(e)}})]})},h=e=>{let{children:t,className:a,...i}=e,{mediaOnViewIndex:n,mode:l}=m();return(0,s.jsx)("div",{className:(0,d.cn)("relative flex min-h-[400px] flex-col gap-5","vertical"!==l&&"col-span-1 lg:col-span-7",a),...i,children:t(n)},n)},g=e=>{let{src:t,alt:a="gallery image",className:i,...n}=e;return(0,s.jsx)("div",{className:(0,d.cn)("relative h-[50vh] w-full",i),children:(0,s.jsx)(x,{src:t,alt:a,fill:!0,className:"!object-contain",...n})})},p=e=>{let{src:t,poster:a,className:n,title:l}=e;return(0,s.jsxs)(i.bL,{className:(0,d.cn)("relative h-[50vh] w-full",n),children:[(0,s.jsx)(i.uN,{}),(0,s.jsx)(i.ai,{src:t,title:l,className:"h-full w-full object-contain",poster:a,preload:"metadata"}),(0,s.jsxs)(i.bX,{children:[(0,s.jsx)(i.nU,{}),(0,s.jsx)(i.G4,{}),(0,s.jsx)(i.z2,{})]})]})},b=e=>{let{children:t,className:a,...i}=e,{media:n,mode:l,mediaOnViewIndex:o}=m(),c=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!c.current)return;let e=document.getElementById("gallery-with-preview-".concat(o));if(!e)return;let t=c.current.offsetWidth,a=e.offsetWidth,s=e.offsetLeft-t/2+a/2;c.current.scroll({left:s,behavior:"smooth"})},[o]),(0,s.jsx)("div",{ref:c,className:(0,d.cn)("flex max-h-[450px] gap-5 overflow-y-auto scrollbar-hide","vertical"===l?"flex-row overflow-x-auto pb-5":"col-span-1 max-lg:pb-5 lg:col-span-5 lg:flex-col lg:pr-5",a),...i,children:t(n)})},v=e=>{let{children:t,className:a,mediaIndex:i,...n}=e,{mode:l}=m();return(0,s.jsx)("div",{id:"gallery-with-preview-".concat(i),className:(0,d.cn)("relative h-32 min-w-[150px] flex-none cursor-pointer","vertical"!==l&&"lg:w-full",a),...n,children:t})},f=e=>{let{imageIndex:t,src:a,alt:i="gallery image",className:n,...l}=e,{mediaOnViewIndex:r,setMediaOnViewIndex:o}=m();return(0,s.jsx)(x,{src:a,alt:i,fill:!0,className:(0,d.cn)("rounded-2xl object-cover opacity-[0.6] hover:!opacity-100",r===t&&"border-2 border-dark-mode-regeneration-600(base) !opacity-100",n),onClick:()=>o(t),...l})},j=e=>{let{children:t,className:a,...i}=e;return(0,s.jsx)("div",{className:(0,d.cn)("max-w-80% absolute bottom-14 left-1/2 -translate-x-1/2 rounded-xl p-3 text-sm text-white sm:max-w-[500px]","line-clamp-2 hover:line-clamp-none",a),style:{background:"rgba(9, 32, 43, 0.8)"},...i,children:t})}},28781:(e,t,a)=>{"use strict";a.d(t,{Af:()=>s,ZR:()=>l,rp:()=>n,ts:()=>i,w3:()=>o,yY:()=>r});let s=50,i=10,n="cavanna",l="/api/parks/public-oases",r={MAMMALIA:40151,AVES:3,PLANTAE:47126},o=["Human","Umano","Homo sapiens","Domestic Cat","Gatto domestico","Felis catus","Domestic Cattle","Bovino domestico","Bos taurus","Loxodonta africana","Elefante africano","Elephant","Elefante","Noise","Rumore"]},33423:(e,t,a)=>{"use strict";a.d(t,{m:()=>s});var s=function(e){return e.NE="#66CCFF",e.EX="#000000",e.ER="#9B4F96",e.RE="#542344",e.EW="#D9D9D9",e["CR (PE)"]="#D81E04",e.CR="#CD4639",e.EN="#CF6D36",e.VU="#D7AA38",e.NT="#6BA762",e.LC="#277862",e.DD="#669999",e}({})},36159:(e,t,a)=>{"use strict";a.d(t,{T:()=>y});var s=a(83815),i=a(28229),n=a(27492),l=a(24999),r=a(60938),o=a(45027),d=a(33635),c=a(52885),m=a(24552),u=a(54002),x=a(99888),h=a(70679),g=a(10307),p=a(94819),b=a(33098),v=a(8110),f=a(43052);let j=(0,g.tv)({slots:{chipsContainer:"flex min-h-[48px] flex-wrap items-center gap-2 rounded-[10px] border p-2",emptyChips:"flex min-h-[40px] items-center justify-center rounded-[10px] border border-dashed p-2.5",emptyText:"text-xs italic",chip:"inline-flex items-center gap-1.5 rounded-lg border-2 px-2 py-1",chipName:"whitespace-nowrap text-xs font-medium",primaryBadge:"rounded text-[9px] font-bold uppercase leading-snug tracking-wide",removeButton:"flex items-center opacity-60 hover:opacity-100",makePrimaryButton:"flex items-center opacity-60 hover:opacity-100",helper:"m-0 text-[11px] leading-relaxed"},variants:{variant:{dark:{chipsContainer:"border-dark-mode-blue-600(base) bg-dark-mode-blue-400",emptyChips:"border-dark-mode-blue-600(base)",emptyText:"text-dark-mode-blue-900",chip:"border-dark-mode-blue-600(base) bg-dark-mode-blue-400",chipName:"text-dark-mode-blue-1100",removeButton:"text-dark-mode-blue-1000",makePrimaryButton:"text-dark-mode-blue-1000",helper:"text-dark-mode-blue-900"},light:{chipsContainer:"border-light-mode-black-200 bg-light-mode-black-100",emptyChips:"border-light-mode-black-200",emptyText:"text-light-mode-black-400",chip:"border-light-mode-black-200 bg-light-mode-black-100",chipName:"text-light-mode-black-600(base)",removeButton:"text-light-mode-black-500",makePrimaryButton:"text-light-mode-black-500",helper:"text-light-mode-black-400"}},isPrimary:{true:{primaryBadge:"px-1.5 py-px"},false:{}}},compoundVariants:[{variant:"dark",isPrimary:!0,class:{chip:"border-dark-mode-regeneration-600(base)",primaryBadge:"bg-dark-mode-regeneration-600(base) text-dark-mode-blue-300"}},{variant:"light",isPrimary:!0,class:{chip:"border-light-mode-regeneration-600(base)",primaryBadge:"bg-light-mode-regeneration-600(base) text-light-mode-black-100"}}],defaultVariants:{variant:"dark",isPrimary:!1}}),y=e=>{var t,a;let{initialValue:g,predictionSelected:y}=e,{t:w}=(0,u.A)("monitoring"),{query:N,locale:k="it"}=(0,x.useRouter)(),_=N.slug,C=Number(N.id),S=(0,n.r)(),{viewMode:I,selectedObservation:A,selectedMultiObservations:z,setSelectedMultiObservations:R,generateQueryKey:D,setEvent:M}=(0,i._R)(),{toast:T}=p.dj(),E=(0,m.useSession)(),{canEditSite:L}=(0,l.A)(),F=(0,o.jE)(),[O,B]=(0,h.useState)(!1),[P,U]=(0,h.useState)(null),[H,q]=(0,h.useState)([]),[V,W]=(0,h.useState)(null!=g?g:""),[$,Q]=(0,h.useState)(null!=g?g:""),G=(0,h.useMemo)(()=>(0,c.debounce)(e=>Q(e),500),[]);(0,h.useEffect)(()=>G.cancel,[G]),(0,h.useEffect)(()=>{y&&(B(!0),W(y),Q(y))},[y]);let K=(null==A?void 0:A.type)==="video"?"video":"image",{data:Z=[]}=(0,d.wpJ)(_,C,null!=(a=null==A?void 0:A.obs_id)?a:0,{type:K},(null==E||null==(t=E.data)?void 0:t.accessToken)?{authorization:"Bearer ".concat(E.data.accessToken),"accept-language":k}
1:void 0,{query:{enabled:"list"===I&&!!(null==A?void 0:A.obs_id),retry:!1}});(0,h.useEffect)(()=>{var e;if("list"!==I||!A)return;let t=Z.filter(e=>"number"==typeof e.taxon_id).reduce((e,t)=>{var a,s;return e.some(e=>e.taxon_id===t.taxon_id)||e.push({taxon_id:t.taxon_id,name:null!=(s=null!=(a=t.latin_taxa)?a:t.taxa)?s:String(t.taxon_id)}),e},[]),a=null==(e=A.taxa)?void 0:e.taxon_id;q(void 0!==a?[...t].sort((e,t)=>Number(t.taxon_id===a)-Number(e.taxon_id===a)):t)},[Z,A,I]);let{data:J=[],isFetching:Y}=(0,d.o7h)({query:$,locale:k,page_size:15},{query:{enabled:$.length>3,onSettled:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(g&&null===P){let t=e.find(e=>e.name.toLowerCase()===g.toLowerCase());t&&U(t)}}}}),{mutateAsync:X,isLoading:ee}=(0,d.nvD)({mutation:{onError:()=>T({variant:"error",description:w("monitoring-observations:censuses.updateSpeciesName.error")}),onSuccess:()=>{T({variant:"success",description:w("monitoring-observations:censuses.updateSpeciesName.success")}),F.invalidateQueries(D(_,C,"observations_censuses")),F.invalidateQueries(D(_,C,"observations_statistics_charts")),F.invalidateQueries(D(_,C,"observations_statistics_charts_species")),F.invalidateQueries(D(_,C,"observations_statistics_charts_date")),F.invalidateQueries(D(_,C,"observations_statistics_grid")),F.invalidateQueries({predicate:e=>{var t,a,s;return null!=(s=null==(a=e.queryKey)||null==(t=a[0])?void 0:t.toString().includes("/annotations"))&&s}})}}}),{mutateAsync:et,isLoading:ea}=(0,d.GHV)({mutation:{onError:()=>T({variant:"error",description:w("monitoring-observations:censuses.updateSpeciesName.error")}),onSuccess:()=>{T({variant:"success",description:w("monitoring-observations:censuses.updateSpeciesName.success")}),R([]),F.invalidateQueries(D(_,C,"observations_censuses")),F.invalidateQueries(D(_,C,"observations_statistics_charts")),F.invalidateQueries(D(_,C,"observations_statistics_charts_species")),F.invalidateQueries(D(_,C,"observations_statistics_charts_date")),F.invalidateQueries(D(_,C,"observations_statistics_grid")),F.invalidateQueries({predicate:e=>{var t,a,s;return null!=(s=null==(a=e.queryKey)||null==(t=a[0])?void 0:t.toString().includes("/annotations"))&&s}})}}});if(!L||"list"===I&&!A)return null;let es=j({variant:S}),ei=async()=>{if("list"===I){var e;A&&0!==H.length&&(M({type:"tagging",observations:[A]}),X({userSlug:_,siteId:C,id:A.obs_id,data:{taxon_ids:H.map(e=>e.taxon_id),obs_type:A.type,user_upload:null!=(e=A.user_upload)&&e},headers:{authorization:"Bearer ".concat(E.data.accessToken)}}))}else{if(!P)return;M({type:"tagging",observations:z}),et({userSlug:_,siteId:C,data:z.map(e=>{var t;return{obs_id:e.obs_id,taxon_id:P.taxon_id,obs_type:e.type,user_upload:null!=(t=e.user_upload)&&t}}),headers:{authorization:"Bearer ".concat(E.data.accessToken)}})}},en=ee||ea||("list"===I?0===H.length:!P||!z.length);return(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)("span",{className:"text-base",children:w("monitoring-observations:censuses.updateSpeciesName.title")}),"list"===I&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:es.helper(),children:w("monitoring-observations:censuses.updateSpeciesName.multiHelper")}),0===H.length?(0,s.jsx)("div",{className:es.emptyChips(),children:(0,s.jsx)("span",{className:es.emptyText(),children:w("monitoring-observations:censuses.updateSpeciesName.noSpecies")})}):(0,s.jsx)("div",{className:es.chipsContainer(),children:H.map((e,t)=>{let a=0===t,i=j({variant:S,isPrimary:a});return(0,s.jsxs)("div",{className:i.chip(),children:[a?(0,s.jsx)("span",{className:i.primaryBadge(),children:w("monitoring-observations:censuses.updateSpeciesName.primaryBadge")}):(0,s.jsx)("button",{type:"button",className:i.makePrimaryButton(),title:w("monitoring-observations:censuses.updateSpeciesName.makePrimary"),"aria-label":w("monitoring-observations:censuses.updateSpeciesName.makePrimary"),onClick:()=>(e=>q(t=>{let a=t.find(t=>t.taxon_id===e);return a?[a,...t.filter(t=>t.taxon_id!==e)]:t}))(e.taxon_id),children:(0,s.jsx)(r.In,{icon:"material-symbols:star-outline",width:14,height:14})}),(0,s.jsx)("span",{className:i.chipName(),children:e.name}),(0,s.jsx)("button",{type:"button",className:i.removeButton(),"aria-label":w("monitoring-observations:censuses.updateSpeciesName.removeSpecies"),onClick:()=>{let t;return t=e.taxon_id,q(e=>e.filter(e=>e.taxon_id!==t))},children:(0,s.jsx)(r.In,{icon:"material-symbols:close",width:14,height:14})})]},e.taxon_id)})})]}),(0,s.jsxs)(b.bL,{open:O,onOpenChange:e=>{B(e),e||(W(""),Q(""))},children:[(0,s.jsxs)(b.Wv,{className:"flex h-fit w-full min-w-52 items-center gap-2 rounded-lg border-none bg-transparent p-2 ring-2 hover:opacity-70 ".concat("light"===S?"ring-light-mode-black-200":"ring-dark-mode-blue-600(base)"),children:[(0,s.jsx)(r.In,{icon:"ci:search-magnifying-glass",width:20,height:20,className:"shrink-0"}),(0,s.jsx)("span",{className:"text-sm",children:"list"===I?w("monitoring-observations:censuses.updateSpeciesName.addSpecies"):P?P.name:w("monitoring-observations:censuses.updateSpeciesName.placeholder")})]}),(0,s.jsx)(b.hl,{variant:"outline-blue-600(base)",align:"start",side:"top",className:"shadow ".concat("light"===S?"shadow-light-mode-black-200":"shadow-dark-mode-blue-1100"),children:(0,s.jsxs)(v.bL,{shouldFilter:!1,children:[(0,s.jsx)(v.pd,{variant:"blue-600(base)",placeholder:w("monitoring-observations:filters.values.species.search"),className:"h-9",value:V,onValueChange:e=>{W(e),G(e)}}),Y&&(0,s.jsx)(r.In,{icon:"eos-icons:loading",width:40,height:40,className:"mx-auto mt-3 ".concat("light"===S?"text-black":"text-white")}),!Y&&0===J.length&&(0,s.jsx)("span",{className:"mt-3 text-center text-sm",children:w("monitoring-observations:filters.values.species.noResults")}),(0,s.jsx)(v.B8,{className:"overflow-hidden",children:(0,s.jsx)(v.YJ,{variant:"blue-600(base)",className:"pb-0",children:(0,s.jsx)("ul",{className:"flex max-h-96 flex-col gap-5 overflow-auto ".concat("light"===S?"custom-scrollbar-light-mode-blue":"custom-scrollbar-dark-mode-blue-300"),children:null==J?void 0:J.map(e=>(0,s.jsx)(v.q7,{variant:"blue-600(base)",value:e.taxon_id.toString(),selected:"list"===I?H.some(t=>t.taxon_id===e.taxon_id):(null==P?void 0:P.taxon_id)===e.taxon_id,onSelect:()=>{"list"===I?(e=>{q(t=>t.some(t=>t.taxon_id===e.taxon_id)?t:[...t,e]),B(!1),W(""),Q("")})(e):(U(e),B(!1))},className:"p-1",children:e.name},e.taxon_id))})})})]})})]})]}),(0,s.jsxs)("div",{className:"mt-3 flex items-center gap-2 self
1-end",children:[(0,s.jsx)(f.$,{variant:"outline-monitoring-600(base)",onClick:()=>{U(null),W(""),Q(""),B(!1)},children:w("common:cancel")}),(0,s.jsx)(f.$,{variant:"monitoring-600(base)",disabled:en,onClick:ei,children:w("common:confirm")})]})]})}},36202:(e,t,a)=>{"use strict";a.d(t,{R0:()=>n,Ws:()=>i,dh:()=>l,me:()=>s});let s=e=>"trancept_".concat(e),i=(e,t)=>{let a=s(t);return(null!=e?e:[]).filter(e=>e.layer_type===a)},n=(e,t,a,s)=>{let i=[];return(null!=e?e:[]).forEach(e=>{i.push({type:"image",date:e.created_at,key:"image-".concat(e.id),raw:e})}),(null!=t?t:[]).forEach(e=>{i.push({type:"video",date:e.created_at,key:"video-".concat(e.id),raw:e})}),(null!=a?a:[]).forEach(e=>{i.push({type:"note",date:e.created_at,key:"note-".concat(e.id),raw:e})}),s.forEach(e=>{var t;i.push({type:"pin",date:null!=(t=e.last_activity_at)?t:e.created_at,key:"pin-".concat(e.id),raw:e})}),i.sort((e,t)=>{let a=new Date(e.date).getTime(),s=new Date(t.date).getTime();return Number.isNaN(s)?-1:Number.isNaN(a)?1:s-a})},l=e=>{let t={all:e.length,image:0,video:0,note:0,pin:0};return e.forEach(e=>{t[e.type]+=1}),t}},37482:(e,t,a)=>{"use strict";a.d(t,{h:()=>_});var s=a(83815),i=a(60938),n=a(54002),l=a(62476),r=a(28229),o=a(98572),d=a(45027),c=a(33635),m=a(24552),u=a(99888),x=a(87317),h=a(94819),g=a(99402),p=a(43052),b=a(54569);let v=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>"";return b.z.object({email:b.z.string().email({message:e("common:form.invalidEmail")})})},f=e=>{let{tranceptId:t}=e,{t:a}=(0,n.A)("monitoring"),{query:l}=(0,u.useRouter)(),b=l.slug,f=parseInt(l.id,10),{polygonVersion:j}=(0,r._R)(),{toast:y}=h.dj(),w=(0,m.useSession)(),N=(0,d.jE)(),k=v(a),{formState:{errors:_},handleSubmit:C,register:S,reset:I}=(0,x.mN)({resolver:(0,o.u)(k),defaultValues:{},reValidateMode:"onChange"}),{mutate:A,isLoading:z}=(0,c.RZd)({mutation:{onError:e=>{let t=a("monitoring-observations:map.biodiversaUsers.invite.error");try{if(e instanceof Error){let s=JSON.parse(e.message);if(!(null==s?void 0:s.detail))return;s.detail.toLowerCase().includes("already associated with")&&(t=a("monitoring-observations:map.biodiversaUsers.invite.errorAlreadyAssociated"))}}catch(e){}y({variant:"error",description:t})},onSuccess:()=>{N.invalidateQueries((0,c.x58)(b,f,j.id,t)),y({variant:"success",description:a("monitoring-observations:map.biodiversaUsers.invite.success")}),I()}}});return(0,s.jsxs)("form",{onSubmit:C(e=>{j&&w.data&&A({userSlug:b,siteId:f,plantationsPolygonsId:j.id,tranceptId:t,params:{user_email:e.email},headers:{authorization:"Bearer ".concat(w.data.accessToken)}})}),className:"flex flex-col gap-2",children:[(0,s.jsx)("label",{htmlFor:"email",className:"text-base text-white",children:a("monitoring-observations:map.biodiversaUsers.invite.title")}),(0,s.jsxs)("div",{className:"flex gap-1",children:[(0,s.jsx)(g.bL,{id:"email",type:"email",placeholder:a("monitoring-observations:map.biodiversaUsers.invite.emailPlaceholder"),variant:"dark-mode",className:"h-full flex-1 rounded-md text-white",withoutParent:!0,disabled:z,...S("email")}),(0,s.jsxs)(p.$,{type:"submit",size:"xs",variant:"monitoring-600(base)",className:"!rounded-md",disabled:z,children:[z&&(0,s.jsx)(i.In,{icon:"eos-icons:three-dots-loading",width:20,height:20,color:"black",className:"mr-2"}),a("monitoring-observations:map.biodiversaUsers.invite.submit")]})]}),_.email&&(0,s.jsx)("p",{className:"text-sm text-red-300",children:_.email.message})]})};var j=a(54066),y=a(24999),w=a(70679);let N=e=>{let{tranceptId:t,userId:a}=e,{t:o}=(0,n.A)("monitoring"),{query:x}=(0,u.useRouter)(),g=x.slug,b=Number(x.id),{polygonVersion:v}=(0,r._R)(),{toast:f}=h.dj(),j=(0,m.useSession)(),{isAdmin:N}=(0,y.A)(),k=(0,d.jE)(),[_,C]=(0,w.useState)(!1),{mutate:S,isLoading:I}=(0,c.xgW)({mutation:{onError:()=>{f({variant:"error",description:o("monitoring-observations:map.biodiversaUsers.usersList.delete.error")}),C(!1)},onSuccess:()=>{k.invalidateQueries((0,c.x58)(g,b,v.id,t)),f({variant:"success",description:o("monitoring-observations:map.biodiversaUsers.usersList.delete.success")}),C(!1)}}});return N?(0,s.jsxs)(l.Root,{open:_,onOpenChange:C,children:[(0,s.jsx)(l.DialogTrigger,{asChild:!0,children:(0,s.jsx)(p.$,{variant:"text-only-error-600(base)",className:"!ml-auto !bg-transparent hover:!bg-transparent hover:!text-state-colors-error-300",children:(0,s.jsx)(i.In,{icon:"ph:trash",width:24,height:24})})}),(0,s.jsxs)(l.DialogContent,{variant:"dark-mode-blue-1000",children:[(0,s.jsxs)(l.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(l.DialogTitle,{className:"!text-md font-bold text-white",children:o("monitoring-observations:map.biodiversaUsers.usersList.delete.title")}),(0,s.jsx)(l.DialogClose,{className:"self-start",children:(0,s.jsx)(i.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]}),(0,s.jsx)(l.DialogDescription,{className:"!text-sm font-normal text-white",children:o("monitoring-observations:map.biodiversaUsers.usersList.delete.description")}),(0,s.jsxs)(l.DialogFooter,{children:[(0,s.jsx)(l.DialogTrigger,{asChild:!0,children:(0,s.jsx)(p.$,{variant:"outline-error-600(base)",size:"xs",children:o("common:cancel")})}),(0,s.jsx)(p.$,{variant:"error-600(base)",size:"xs",disabled:I,onClick:()=>{v&&j.data&&S({userSlug:g,siteId:b,plantationsPolygonsId:v.id,tranceptId:t,params:{user_id:a},headers:{authorization:"Bearer ".concat(j.data.accessToken)}})},children:o("monitoring-observations:map.biodiversaUsers.usersList.delete.submit")})]})]})]}):null},k=e=>{var t,a;let{tranceptId:l}=e,{t:o}=(0,n.A)("monitoring"),d=(0,m.useSession)(),{query:x}=(0,u.useRouter)(),h=x.slug,g=parseInt(x.id,10),{polygonVersion:p}=(0,r._R)(),{isLoading:b,data:v}=(0,c.xzS)(h,g,null!=(a=null==p?void 0:p.id)?a:0,l,{authorization:"Bearer ".concat(null==d||null==(t=d.data)?void 0:t.accessToken)},{query:{enabled:!!p}});return b||v?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-base font-bold text-white",children:o("monitoring-observations:map.biodiversaUsers.usersList.title")}),(0,s.jsx)("ul",{className:"custom-scrollbar-dark-mode-blue flex max-h-75 flex-col gap-5 overflow-y-auto text-white",children:b?Array.from({length:3}).map((e,t)=>(0,s.jsx)("li",{children:(0,s.jsx)(j.A,{height:40,width:"100%"})},t)):v.map(e=>(0,s.jsxs)("li",{className:"flex items-center gap-2",children:[(0,s.jsx)(i.In,{icon:"mdi:people",width:24,height:24}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[e.full_name,(0,s.jsx)("span",{className:"text-xs",children:e.email})]}),(0,s.jsx)(N,{tranceptId:l,userId:e.id})]},e.id))})]}):null},_=e=>{let{open:t,onOpenChange:a,trancept:r}=e,{t:o}=(0,n.A)("monitoring");return(0,s.jsx)(l.Root,{open:t,onOpenChange:a,children:(0,s.jsxs)(l.DialogContent,{variant:"dark-mode-blue-1000",className:"!gap-5 sm:min-w-96",onOpenAutoFocus:e=>e.preventDefault(),children:[(0,s.jsxs)(l.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)(l.DialogTitle,{children:o("monitoring-observations:map.biodiversaUsers.title")}),(0,s.jsx)(l.DialogDescription,{className:"text-sm text-dark-mode-blue-1000",children:r.tranceptName})]}),(0,s.jsx)(l.DialogClose,{asChild:!0,children:(0,s.jsx)(i.In,{icon:"material-symbols:close",width:24,height:24,className:"cursor-pointer"})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsx)(f,{tranceptId:r.tranceptId}),(0,s.jsx)("hr",{className:"h-px w-full border-none bg-dark-mode-blue-1000"}),(0,s.jsx)(k,{tranceptId:r.tranceptId})]})]})})}},44359:(e,t,a)=>{"use strict";a.d(t,{h:()=>o});var s=a(83815),i=a(27149),n=a(99888),l=a(137),r=a(95001);a(15721);let o=e=>{let{_selectedDate:t,_setSelectedDate:a,classNames:o={},disabledDates:d,...c}=e,{selected:m,day_button:u,button_previous:x,button_next:h,weekday:g,day:p,chevron:b,today:v,root:f,month_caption:j,...y}=o,{locale:w="it"}=(0,n.useRouter)();return(0,s.jsx)(l.h,{locale:(0,i.no)(w),mode:"single",selected:t,onSelect:e=>{if(e){let t=new Date(e);t.setHours(9),a(t)}else a(void 0)},classNames:{root:(0,r.cn)("rdp-root !text-white",f),selected:(0,r.cn)("rdp-selected bg-dark-mode-blue-500",m),day_button:(0,r.cn)("rdp-day_button !border-none hover:bg-dark-mode-blue-500",u),button_previous:(0,r.cn)("rdp-button_previous hover:!bg-dark-mode-blue-500",x),button_next:(0,r.cn)("rdp-button_next hover:!bg-dark-mode-blue-500",h),chevron:(0,r.cn)("rdp-chevron !fill-white",b),weekday:(0,r.cn)("rdp-weekday",g),day:(0,r.cn)("rdp-day border-none",p),...y,today:(0,r.cn)("rdp-today !text-white",v),month_caption:(0,r.cn)("rdp-month_caption",j),...y},disabled:d,...c})}},50994:(e,t,a)=>{"use strict";a.d(t,{x:()=>d});var s=a(28229),i=a(80163),n=a(90336),l=a(24552),r=a(99888),o=a(58810);let d=()=>{var e;let{query:t,locale:a="it"}=(0,r.useRouter)(),d=t.slug,c=Number(t.id),m=(0,l.useSession)(),{polygonVersion:u,area:x,polygons:h,device:g,filterDate:p,filterSpecies:b,filterSubSpecies:v,filterFamily:f,filterGenre:j,filterOrder:y,filterIndex:w,minimumConfidenceValue:N,statisticsEndemicFilter:k,geoProbabilityFilter:_,classificationFilter:C,selectedObservation:S,setSelectedObservation:I,generateQueryKey:A,event:z,setEvent:R,viewMode:D}=(0,s._R)();return(0,i.i)({slug:d,siteId:c,locale:a,accessToken:null==m||null==(e=m.data)?void 0:e.accessToken,enabled:!!d&&!Number.isNaN(c)&&!!u,queryKey:A(d,c,"observations_censuses"),filters:{...u&&{polygon_id:u.id},...h.length>0&&{subpolygon_idx:h.map(e=>e.id).join(",")},...x&&{trancept_ids:x.id.toString()}
1,...g&&{hive_ids:g.id.toString()},...p.from&&{date_from:(0,n.default)(p.from,"yyyy-MM-dd")},...p.to&&{date_to:(0,n.default)(p.to,"yyyy-MM-dd")},...b.size>0&&{iconic_taxa:Array.from(b.keys()).join(",")},...v.size>0&&{taxa:Array.from(v.keys()).join(",")},...f.size>0&&{family_taxa:Array.from(f.keys()).join(",")},...j.size>0&&{genus_taxa:Array.from(j.keys()).join(",")},...y.size>0&&{order_taxa:Array.from(y.keys()).join(",")},...w&&{index_id:w.id},...N&&{min_confidence:N},..."all"!==k&&{endemic_filter:k},...(0,o.z)(_),..."all"!==C&&{classification_filter:C}},onSettled:e=>{var t,a;if(!e||"hierarchy"===D)return;let{obs:s}=e||{pages:[],pageParams:[],obs:[]};return z?(R(null),s&&0!==s.length)?void(S&&!s.find(e=>e.id===S.id)&&I(null!=(t=s[0])?t:null)):void I(null):s&&0!==s.length?void(s.find(e=>e.id===(null==S?void 0:S.id))||I(null!=(a=s[0])?a:null)):void I(null)}})}},51806:(e,t,a)=>{"use strict";a.d(t,{P:()=>m});var s=a(70679),i=a(3324);let n=new Map,l=(e,t,a,s)=>e.replace("{z}",String(t)).replace("{x}",String(a)).replace("{y}",String(s)).replace("{s}","a"),r=e=>new Promise(t=>{let a=new Image;a.crossOrigin="anonymous";let s=!1,i=e=>{s||(s=!0,clearTimeout(n),t(e))},n=setTimeout(()=>i(null),8e3);a.onload=()=>i(a),a.onerror=()=>i(null),a.src=e}),o=e=>{let t=document.createElement("canvas");t.width=16,t.height=16;let a=t.getContext("2d",{willReadFrequently:!0});if(!a)return null;try{return a.drawImage(e,0,0,16,16),a.getImageData(0,0,16,16).data}catch(e){return null}},d=async(e,t,a,s)=>{let i=2**s,n=Math.floor((a+180)/360*2**s),d=((e,t)=>{let a=e*Math.PI/180;return Math.floor((1-Math.log(Math.tan(a)+1/Math.cos(a))/Math.PI)/2*2**t)})(t,s),c=n+1<i?n+1:n-1;if(c<0||c===n)return null;let[m,u]=await Promise.all([r(l(e,s,n,d)),r(l(e,s,c,d))]);if(!m||!u)return null;let x=o(m),h=o(u);return x&&h?!((e,t)=>{if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0})(x,h):null},c=async(e,t,a,s)=>{let i=Math.max(s-6,16);for(let n=s;n>=i;n--){let i=await d(e,t,a,n);if(null===i)return s;if(i)return n}return i},m=(e,t,a)=>
1{let l=(0,i.ko)(),[r,o]=(0,s.useState)(t);return(0,s.useEffect)(()=>{let s;if(!a||!l)return void o(t);let i=!1,r=()=>{let a,s,r=l.getCenter(),d=(a=r.lat,s=r.lng,"".concat(e,"|").concat(t,"|").concat(a.toFixed(1),"|").concat(s.toFixed(1))),m=n.get(d);if(void 0!==m){i||o(m);return}c(e,r.lat,r.lng,t).then(e=>{n.set(d,e),i||o(e)})};r();let d=()=>{l.getZoom()>=t-2&&(s&&clearTimeout(s),s=setTimeout(r,400))};return l.on("zoomend",d),()=>{i=!0,s&&clearTimeout(s),l.off("zoomend",d)}},[l,e,t,a]),r}},52283:(e,t,a)=>{"use strict";a.d(t,{t:()=>n});var s=a(92682),i=a(7924);let n=e=>{if(e.length<=1)return 0;let t=(0,s.A)(e[0]),a=(0,s.A)(e[e.length-1]);return(0,i.A)(a,t)}},52656:(e,t,a)=>{"use strict";a.d(t,{G:()=>r});var s=a(84723),i=a.n(s),n=a(70679),l=a(3324);function r(){let e=(0,l.ko)();return(0,n.useEffect)(()=>{let t=(t,a,s)=>{e.flyTo([t,a],null!=s?s:e.getZoom(),{animate:!0,duration:1.5})},a=(t,a,s,n)=>{let l=i().latLngBounds([a,n],[t,s]);e.flyToBounds(l,{animate:!0,duration:1.5,padding:[50,50]})};return window.__mapFlyTo=t,window.__mapFlyToBounds=a,()=>{window.__mapFlyTo===t&&delete window.__mapFlyTo,window.__mapFlyToBounds===a&&delete window.__mapFlyToBounds}},[e]),null}},53325:(e,t,a)=>{"use strict";a.d(t,{Q:()=>d});var s=a(83815),i=a(51806),n=a(79139),l=a(52375),r=a(70679),o=a(92165);let d=e=>{let{maxZoom:t=l.gl,...a}=e,d=(0,i.P)(l.zn,l.AP,!0),c=(0,r.useRef)(null);return(0,n.i)(c,d),(0,s.jsx)(o.e,{ref:c,...a,url:l.zn,maxNativeZoom:d,maxZoom:t})}},56199:(e,t,a)=>{"use strict";a.d(t,{O:()=>o});var s=a(83815),i=a(60938),n=a(18508),l=a(54002),r=a(43052);let o=e=>{let{tablePagination:t,setTablePagination:a}=e,{t:o}=(0,l.A)("common");return(0,s.jsx)("tfoot",{children:(0,s.jsx)("tr",{children:(0,s.jsx)("td",{className:"bg-transparent pt-10",colSpan:6,children:(0,s.jsxs)("div",{className:"flex items-center justify-center gap-5 text-light-mode-black-500",children:[(0,s.jsx)(r.$,{variant:"unstyled",size:"xs",className:"h-auto !text-white disabled:!pointer-events-auto disabled:!opacity-70",onClick:()=>a(e=>({...e,page:e.page-1})),disabled:1===t.page,children:(0,s.jsx)(i.In,{icon:"radix-icons:chevron-left",width:20,height:20})}),(0,s.jsx)("p",{children:(0,s.jsx)(n.A,{text:o("paginatedTable.footer.page",{page:t.page,pages:t.pages}),components:{page:(0,s.jsx)("span",{className:"text-white"})}})}),(0,s.jsx)(r.$,{variant:"unstyled",size:"xs",className:"h-auto !text-white disabled:!pointer-events-auto disabled:!opacity-70",onClick:()=>a(e=>({...e,page:e.page+1})),disabled:t.page===t.pages,children:(0,s.jsx)(i.In,{icon:"radix-icons:chevron-right",width:20,height:20})})]})})})})}},58575:(e,t,a)=>{"use strict";a.d(t,{C:()=>el});var s=a(83815),i=a(17439),n=a(78646),l=a(28229),r=a(66337),o=a(63506),d=a(90452),c=a(90336),m=a(24552),u=a(99888),x=a(58810),h=a(27492),g=a(24999),p=a(44568),b=a(60938),v=a(75761),f=a(21547),j=a(54002),y=a(75258),w=a.n(y),N=a(86666),k=a.n(N),_=a(70679),C=a(95001),S=a(45954),I=a(13212),A=a(11832),z=a(71152),R=a(62214),D=a(54066),M=a(10307),T=a(43052);let E=(0,M.tv)({slots:{container:"flex flex-col gap-3 rounded-xl border p-4",header:"flex items-center justify-between gap-3",title:"text-sm font-bold",row:"flex items-center gap-3 rounded-lg border px-3 py-2 transition-colors",rowSelected:"",timestamp:"text-xs",probability:"bg-gradient-yellow-pink-cyan-green bg-clip-text text-xs font-bold text-transparent"},variants:{variant:{dark:{container:"border-dark-mode-blue-1000 bg-dark-mode-blue-300",title:"text-white",row:"border-dark-mode-blue-1000 text-white hover:bg-dark-mode-blue-1000/30",rowSelected:"border-dark-mode-monitoring-600(base) bg-dark-mode-blue-1000/40",timestamp:"text-dark-mode-blue-1000"},light:{container:"border-light-mode-black-200 bg-light-mode-black-100",title:"text-black",row:"border-light-mode-black-200 text-black hover:bg-light-mode-black-200/40",rowSelected:"border-dark-mode-monitoring-600(base) bg-light-mode-black-200/60",timestamp:"text-light-mode-black-500"}}},defaultVariants:{variant:"dark"}}),L=e=>{let{clips:t,isLoading:a,variant:i}=e,{t:n}=(0,j.A)("monitoring"),{selectedObservation:r,setSelectedObservation:o,timezone:d}=(0,l._R)(),[c,m]=(0,_.useState)(null),u=(0,_.useRef)(null),x=(0,_.useMemo)(()=>E({variant:i}),[i]),h=(0,_.useMemo)(()=>t.filter(e=>"sound"===e.type&&e.url),[t]);(0,_.useEffect)(()=>{let e=u.current;if(!e||null===c)return;let t=()=>{m(e=>{if(null===e)return null;let t=e+1;return t<h.length?t:null})};return e.addEventListener("ended",t),()=>e.removeEventListener("ended",t)},[c,h.length]),(0,_.useEffect)(()=>{let e=u.current;if(!e)return;if(null===c)return void e.pause();let t=h[c];(null==t?void 0:t.url)&&(e.src=t.url,e.play().catch(()=>m(null)))},[c,h]),(0,_.useEffect)(()=>()=>{var e;return null==(e=u.current)?void 0:e.pause()},[]);let g=(0,_.useCallback)(()=>{0!==h.length&&m(e=>null===e?0:null)},[h.length]);return a?(0,s.jsxs)("div",{className:x.container(),children:[(0,s.jsx)(D.A,{height:28}),(0,s.jsx)(D.A,{height:44,count:3})]}):0===t.length?null:(0,s.jsxs)("div",{className:x.container(),children:[(0,s.jsxs)("div",{className:x.header(),children:[(0,s.jsx)("span",{className:x.title(),children:n("monitoring-observations:censuses.grouping.clips",{count:t.length})}),h.length>0&&(0,s.jsxs)(T.$,{variant:"outline-monitoring-600(base)",size:"xs",onClick:g,children:[(0,s.jsx)(b.In,{icon:null!==c?"material-symbols:pause-circle-rounded":"material-symbols:play-circle-outline-rounded",width:18,height:18,className:"mr-1"}),n("monitoring-observations:censuses.grouping.playAll")]})]}),(0,s.jsx)("audio",{ref:u,className:"hidden"}),(0,s.jsx)("div",{className:"flex max-h-72 flex-col gap-2 overflow-y-auto",children:t.map(e=>{var t;let a=(null==r?void 0:r.id)===e.id;return(0,s.jsxs)("button",{type:"button",onClick:()=>o(e),className:(0,C.cn)(x.row(),a&&x.rowSelected()),children:["sound"===e.type&&e.url?(0,s.jsx)(b.In,{icon:"material-symbols:graphic-eq",width:18,height:18,className:"shrink-0"}):(0,s.jsx)(b.In,{icon:"material-symbols:image-outline",width:18,height:18,className:"shrink-0"}),(0,s.jsx)("span",{className:x.timestamp(),children:(0,R.format)(new Date(e.record_date),"dd.MM.yy HH:mm:ss",{timeZone:null!=d?d:"UTC"})}),(null==(t=e.taxa)?void 0:t.probability)!==void 0&&e.taxa.probability<100&&(0,s.jsx)("span",{className:(0,C.cn)(x.probability(),"ml-auto"),children:n("monitoring-observations:censuses.probability",{probability:e.taxa.probability})})]},e.id)})})]})};var F=a(33635),O=a(86921),B=a(45717),P=a(81314),U=a(88971),H=a(57548);let q=(0,M.tv)({slots:{container:"relative flex gap-4 pb-6 last:pb-0",timelineDot:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full",timelineLine:"mt-2 h-full w-px",taxa:"text-sm font-medium",currentBadge:"rounded-full px-2 py-0.5 text-xs font-medium",latinTaxa:"text-sm italic",metaText:"flex flex-wrap items-center gap-3 text-xs"},variants:{variant:{dark:{timelineDot:"bg-dark-mode-blue-600(base) text-white",timelineLine:"bg-dark-mode-blue-600(base)",taxa:"text-white",currentBadge:"bg-aqua/20 text-aqua",latinTaxa:"text-dark-mode-blue-1000",metaText:"text-dark-mode-blue-1000"},light:{timelineDot:"bg-light-mode-black-200 text-black",timelineLine:"bg-light-mode-black-200",taxa:"text-black",currentBadge:"bg-green-100 text-green-700",latinTaxa:"text-light-mode-black-400",metaText:"text-light-mode-black-400"}},isCurrent:{true:{},false:{}}}
1,compoundVariants:[{variant:"dark",isCurrent:!0,class:{timelineDot:"bg-aqua text-dark-mode-blue-200"}},{variant:"light",isCurrent:!0,class:{timelineDot:"bg-green-500 text-white"}}],defaultVariants:{variant:"dark",isCurrent:!1}}),V=e=>{var t;let{annotation:a,isFirst:i}=e,{t:n}=(0,j.A)("monitoring"),{locale:l="it"}=(0,u.useRouter)(),r=a.created_at?((e,t)=>{var a;let s=new Date(e);return isNaN(s.getTime())?"-":(0,c.default)(s,"dd MMM yyyy, HH:mm",{locale:null!=(a=H.x8[t])?a:U.default})})(a.created_at,l):"-",{container:o,timelineDot:d,timelineLine:m,taxa:x,currentBadge:h,latinTaxa:g,metaText:p}=q({isCurrent:i});return(0,s.jsxs)("div",{className:o(),children:[(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsx)("div",{className:d(),children:(0,s.jsx)(b.In,{icon:i?"material-symbols:check":"material-symbols:history",width:16,height:16})}),(0,s.jsx)("div",{className:m()})]}),(0,s.jsxs)("div",{className:"flex flex-1 flex-col gap-2 pt-1",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)("span",{className:x(),children:null!=(t=a.taxa)?t:n("monitoring-observations:censuses.annotationHistory.unknownSpecies")}),i&&(0,s.jsx)("span",{className:h(),children:n("monitoring-observations:censuses.annotationHistory.current")})]}),a.latin_taxa&&(0,s.jsx)("span",{className:g(),children:a.latin_taxa}),(0,s.jsxs)("div",{className:p(),children:[(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[(0,s.jsx)(b.In,{icon:"material-symbols:calendar-today-outline",width:14,height:14}),r]}),a.user_email&&(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[(0,s.jsx)(b.In,{icon:"material-symbols:person-outline",width:14,height:14}),a.user_email]}),a.iconic_taxa&&(0,s.jsxs)("span",{className:"flex items-center gap-1",children:[(0,s.jsx)(b.In,{icon:"material-symbols:category-outline",width:14,height:14}),a.iconic_taxa]})]})]})]})},W=(0,M.tv)({slots:{emptyIcon:"mb-4",emptyText:"text-sm",skeletonWrapper:"flex flex-col gap-4"},variants:{variant:{dark:{emptyIcon:"text-dark-mode-blue-1000",emptyText:"text-dark-mode-blue-1000"},light:{emptyIcon:"text-light-mode-black-400",emptyText:"text-light-mode-black-400"}}},defaultVariants:{variant:"dark"}}),$=e=>{var t;let{isOpen:a,setIsOpen:i,obsId:n,obsType:l}=e,{t:r}=(0,j.A)("monitoring"),{query:o,locale:d="it"}=(0,u.useRouter)(),c=o.slug,x=Number(o.id),h=(0,m.useSession)(),{isLoading:g,data:p=[]}=(0,F.wpJ)(c,x,n,{type:l},(null==h||null==(t=h.data)?void 0:t.accessToken)?{authorization:"Bearer ".concat(h.data.accessToken),"accept-language":d}:void 0,{query:{enabled:a&&!!n,retry:!1}}),{emptyIcon:v,emptyText:f}=W();return(0,s.jsx)(P.bL,{open:a,onOpenChange:i,children:(0,s.jsxs)(P.h,{side:"right",variant:"dark-blue-200",showCloseButton:!1,className:"w-full sm:max-w-md",children:[(0,s.jsxs)(P.Fm,{variant:"dark-blue-200",children:[(0,s.jsxs)(P.qp,{variant:"dark-blue-200",className:"flex items-center gap-2",children:[(0,s.jsx)(b.In,{icon:"material-symbols:history",width:24,height:24}),r("monitoring-observations:censuses.annotationHistory.title")]}),(0,s.jsx)(P.Qs,{variant:"dark-blue-200",children:r("monitoring-observations:censuses.annotationHistory.description")})]}),(0,s.jsx)("div",{className:"mt-4 flex flex-col",children:g?(0,s.jsx)("div",{className:"flex flex-col gap-4",children:(0,s.jsx)(D.A,{height:80,count:3})}):0===p.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 text-center",children:[(0,s.jsx)(b.In,{icon:"material-symbols:history-off",width:48,height:48,className:v()}),(0,s.jsx)("p",{className:f(),children:r("monitoring-observations:censuses.annotationHistory.empty")})]}):(0,s.jsx)("div",{className:"flex flex-col",children:p.map((e,t)=>(0,s.jsx)(V,{annotation:e,isFirst:0===t},"".concat(e.created_at,"-").concat(t)))})})]})})};var Q=a(45027),G=a(94819),K=a(72730),Z=a(85164);let J=e=>{var t;let{obs:a,note:i,isCreating:n=!1,onCancelCreating:l}=e,{t:r}=(0,j.A)("monitoring"),o=(0,h.r)(),{query:d}=(0,u.useRouter)(),c=d.slug,x=Number(d.id),{toast:g}=G.dj(),p=(0,m.useSession)(),v=(0,Q.jE)(),[f,y]=(0,_.useState)(n),w=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];
1e&&await v.invalidateQueries((0,F.wJi)(c,x,a.id,{type:a.type,user_upload:a.userUpload})),y(!1),null==l||l()},{mutateAsync:N,isLoading:k}=(0,F.yuY)({mutation:{onError:()=>{g({variant:"error",description:r("monitoring-observations:censuses.notes.error")}),w()},onSuccess:()=>{g({variant:"success",description:r("monitoring-observations:censuses.notes.success")}),w(!0)}}}),{mutateAsync:S,isLoading:I}=(0,F.Ewd)({mutation:{onError:()=>{g({variant:"error",description:r("monitoring-observations:censuses.notes.error")}),w()},onSuccess:()=>{g({variant:"success",description:r("monitoring-observations:censuses.notes.successUpdate")}),w(!0)}}}),{mutateAsync:A}=(0,F.GG6)({mutation:{onError:()=>{g({variant:"error",description:r("monitoring-observations:censuses.notes.error")}),w()},onSuccess:()=>{g({variant:"success",description:r("monitoring-observations:censuses.notes.successDelete")}),w(!0)}}}),z=async()=>{var e;await A({userSlug:c,siteId:x,commentId:i.id,headers:{authorization:"Bearer ".concat(null==p||null==(e=p.data)?void 0:e.accessToken)}})},R=async e=>{var t,s;if(/^<p>\s*<\/p>$/.test(e))return void w();if(i){if(!i.me)throw Error("You are not the author of this note");await S({userSlug:c,siteId:x,commentId:i.id,data:{comment:e},headers:{authorization:"Bearer ".concat(null==p||null==(s=p.data)?void 0:s.accessToken)}});return}await N({userSlug:c,siteId:x,obsId:a.id,data:{meta:{type:a.type,user_upload:a.userUpload},comment:e},headers:{authorization:"Bearer ".concat(null==p||null==(t=p.data)?void 0:t.accessToken)}})};return(0,s.jsxs)("div",{className:(0,C.cn)("flex flex-col text-sm",!f&&"border-b border-light-mode-black-800 pb-3 last:border-0"),children:[(0,s.jsxs)("div",{className:(0,C.cn)("flex justify-between",!f&&"items-start",f&&"flex-col gap-1"),children:[(0,s.jsx)(K.w,{isEditing:f,text:null!=(t=null==i?void 0:i.comment)?t:"",onCancel:w,onConfirm:R,className:"whitespace-break-spaces text-light-mode-black-200",hideSlotBefore:!0,footer:(0,s.jsxs)("div",{className:"mb-10 flex flex-row justify-end gap-2",children:[(0,s.jsx)(K.w.CancelButton,{disabled:k||I,variant:"outline-monitoring-600(base)",className:"w-max px-4 py-2",children:r("common:cancel")}),(0,s.jsx)(K.w.ConfirmButton,{disabled:k||I,variant:"monitoring-600(base)",className:"w-max px-4 py-2",children:r("common:save")})]})}),(null==i?void 0:i.me)&&!f&&(0,s.jsxs)(Z.bL,{children:[(0,s.jsx)(Z.ty,{children:(0,s.jsx)(b.In,{icon:"mage:dots",width:20,height:20,color:"white"})}),(0,s.jsxs)(Z.SQ,{side:"right",align:"end",sideOffset:2,className:"min-w-44 rounded-lg ".concat("light"===o?"bg-white text-black":"bg-dark-mode-blue-400 text-white"),children:[(0,s.jsx)(Z._2,{onSelect:e=>{e.preventDefault(),y(!0)},className:"cursor-pointer rounded-md ".concat("light"===o?"hover:bg-light-mode-black-100":"hover:bg-dark-mode-blue-500"),children:r("common:common.edit")}),(0,s.jsx)(Z._2,{onSelect:z,className:"cursor-pointer rounded-md font-bold text-red-600 hover:bg-red-500 hover:text-white",children:r("common:common.delete")})]})]})]}),i&&!f&&(0,s.jsx)("span",{className:"light"===o?"text-light-mode-black-500":"text-dark-mode-blue-1000",children:i.user_email})]})},Y=()=>{var e,t,a;let{t:i}=(0,j.A)("monitoring"),{query:n}=(0,u.useRouter)(),r=n.slug,o=Number(n.id),d=(0,h.r)(),{selectedObservation:c}=(0,l._R)(),x=(0,m.useSession)(),{canReadSite:p,canEditSite:v}=(0,g.A)(),[f,y]=(0,_.useState)(!1),[w,N]=(0,_.useState)(!1),[k,C]=(0,_.useState)(!1),{isLoading:S,data:I=[]}=(0,F._y6)(r,o,c.obs_id,{type:c.type,user_upload:null!=(t=c.user_upload)&&t},(null==x||null==(e=x.data)?void 0:e.accessToken)?{authorization:"Bearer ".concat(x.data.accessToken)}:void 0,{query:{enabled:null!==c&&p,retry:!1}});
1return p&&c?S?(0,s.jsx)(D.A,{height:100,width:"100%"}):(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsx)("hr",{className:"border-1 ".concat("light"===d?"border-light-mode-black-200":"border-dark-mode-blue-900")}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-5",children:[v&&(0,s.jsxs)(T.$,{variant:"unstyled",size:"xs",className:"h-auto gap-2 ".concat("light"===d?"!text-light-mode-black-500":"!text-dark-mode-blue-1000"," disabled:!pointer-events-auto disabled:!opacity-70"),disabled:w,onClick:()=>N(!0),children:[(0,s.jsx)(b.In,{icon:"akar-icons:plus"}),i("monitoring-observations:censuses.notes.add")]}),I.length>0&&(0,s.jsxs)(T.$,{variant:"unstyled",size:"xs",className:"h-auto gap-2 ".concat("light"===d?"!text-light-mode-black-500":"!text-dark-mode-blue-1000"),onClick:()=>y(e=>!e),children:[(0,s.jsx)(b.In,{icon:f?"akar-icons:chevron-up":"akar-icons:chevron-down"}),i(f?"monitoring-observations:censuses.notes.hide":"monitoring-observations:censuses.notes.show")]}),(0,s.jsxs)(T.$,{variant:"unstyled",size:"xs",className:"h-auto gap-2 ".concat("light"===d?"!text-light-mode-black-500":"!text-dark-mode-blue-1000"),onClick:()=>C(!0),children:[(0,s.jsx)(b.In,{icon:"material-symbols:history"}),i("monitoring-observations:censuses.annotationHistory.button")]})]}),(0,s.jsxs)(O.N,{children:[w&&(0,s.jsx)(B.P.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},children:(0,s.jsx)(J,{obs:{id:c.obs_id,type:c.type,userUpload:null!=(a=c.user_upload)&&a},isCreating:!0,onCancelCreating:()=>N(!1)})}),f&&(0,s.jsx)(B.P.div,{initial:{x:"100%",opacity:0}
1,animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},className:"custom-scrollbar-dark-mode-blue flex max-h-64 flex-col gap-5 overflow-y-auto pr-5",children:I.map(e=>{var t;return(0,s.jsx)(J,{obs:{id:c.obs_id,type:c.type,userUpload:null!=(t=c.user_upload)&&t},note:e},e.id)})})]}),(0,s.jsx)($,{isOpen:k,setIsOpen:C,obsId:c.obs_id,obsType:c.type})]}):null};var X=a(36159);let ee=(0,M.tv)({slots:{container:"flex items-center gap-2.5 pl-[23px] text-sm leading-[1.4] tracking-[0.5px]",date:"shrink-0",taxa:"",email:"italic"},variants:{variant:{dark:{date:"text-light-mode-black-400",taxa:"text-white",email:"text-dark-mode-blue-1000"},light:{date:"text-light-mode-black-600",taxa:"text-black",email:"text-light-mode-black-400"}}},defaultVariants:{variant:"dark"}}),et=e=>{let{item:t}=e,{locale:a="it"}=(0,u.useRouter)(),i=t.date?((e,t)=>{var a;let s=new Date(e);return isNaN(s.getTime())?"-":(0,c.default)(s,"dd.MM.yy",{locale:null!=(a=H.x8[t])?a:U.default})})(t.date,a):"-",{container:n,date:l,taxa:r,email:o}=ee();return(0,s.jsxs)("div",{className:n(),children:[(0,s.jsx)("span",{className:l(),children:i}),(0,s.jsx)("span",{className:r(),children:t.taxaName||"-"}),(0,s.jsxs)("span",{className:o(),children:["(",t.userEmail||"-",")"]})]})},ea=(0,M.tv)({slots:{icon:"",title:"text-sm"},variants:{variant:{dark:{icon:"text-dark-mode-neutral-200",title:"text-dark-mode-neutral-200"},light:{icon:"text-light-mode-black-600",title:"text-light-mode-black-600"}}},defaultVariants:{variant:"dark"}}),es=e=>{let{items:t,defaultExpanded:a=!1,className:i}=e,{t:n}=(0,j.A)("monitoring"),l=(0,_.useId)(),[r,o]=(0,_.useState)(a),{icon:d,title:c}=ea();return 0===t.length?null:(0,s.jsxs)("div",{className:(0,C.cn)("flex flex-col",i),children:[(0,s.jsxs)("button",{type:"button",onClick:()=>{o(e=>!e)},className:"flex cursor-pointer items-center gap-2 border-none bg-transparent p-0","aria-expanded":r,"aria-controls":l,children:[(0,s.jsx)(B.P.div,{animate:{rotate:r?0:-90},transition:{duration:.2},children:(0,s.jsx)(b.In,{icon:"material-symbols:keyboard-arrow-up",width:20,height:20,className:d()})}),(0,s.jsx)("span",{className:c(),children:n("monitoring-observations:censuses.annotationHistory.title")})]}),(0,s.jsx)(O.N,{initial:!1,children:r&&(0,s.jsx)(B.P.div,{id:l,initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:(0,s.jsx)("div",{className:"mt-3 flex flex-col gap-1.5",children:t.map((e,t)=>(0,s.jsx)(et,{item:e},"".concat(e.id,"-").concat(t)))})})})]})},ei=w()(()=>Promise.all([a.e(82683),a.e(4463)]).then(a.bind(a,4463)).then(e=>e.ModifyGPSDialog),{loadableGenerated:{webpack:()=>[4463]},ssr:!1}),en=w()(()=>Promise.all([a.e(69468),a.e(82683),a.e(92783),a.e(38058),a.e(17807),a.e(11379),a.e(11157),a.e(67296),a.e(72419)]).then(a.bind(a,1549)).then(e=>e.ShowInMapDialog),{loadableGenerated:{webpack:()=>[1549]},ssr:!1}),el=()=>{var e,t,a,y,w,N,R,D,M,T,E,F;let{t:O}=(0,j.A)("monitoring"),B=(0,h.r)(),{viewMode:P,selectedObservation:U,groupConsecutive:H,activeSession:q,event:V}=(0,l._R)(),{canReadSite:W}=(0,g.A)(),[$,Q]=(0,_.useState)(null),[G,K]=(0,_.useState)({width:0,height:0}),Z="list"===P&&H&&!!q,{clips:J,isLoading:ee,refetch:et}=(e=>{var t;let{taxonId:a,fromDt:s,toDt:i,enabled:n}=e,{query:h,locale:g="it"}=(0,u.useRouter)(),p=h.slug,b=Number(h.id),v=(0,m.useSession)(),{polygonVersion:f,area:j,polygons:y,device:w,filterDate:N,filterSpecies:k,filterSubSpecies:_,filterFamily:C,filterGenre:S,filterOrder:I,filterIndex:A,minimumConfidenceValue:z,statisticsEndemicFilter:R,geoProbabilityFilter:D,classificationFilter:M,generateQueryKey:T}=(0,l._R)(),E={...f&&{polygon_id:f.id},...y.length>0&&{subpolygon_idx:y.map(e=>e.id).join(",")},...j&&{trancept_ids:j.id.toString()},...w&&{hive_ids:w.id.toString()},...N.from&&{date_from:(0,c.default)(N.from,"yyyy-MM-dd")},...N.to&&{date_to:(0,c.default)(N.to,"yyyy-MM-dd")},...k.size>0&&{iconic_taxa:Array.from(k.keys()).join(",")},..._.size>0&&{taxa:Array.from(_.keys()).join(",")},...C.size>0&&{family_taxa:Array.from(C.keys()).join(",")},...S.size>0&&{genus_taxa:Array.from(S.keys()).join(",")},...I.size>0&&{order_taxa:Array.from(I.keys()).join(",")},...A&&{index_id:A.id},...z&&{min_confidence:z},..."all"!==R&&{endemic_filter:R},...(0,x.z)(D),..."all"!==M&&{classification_filter:M},exclude_taxa:l.Wg,from_dt:s,to_dt:i,..."number"==typeof a&&{session_taxon_id:a}},L={"accept-language":g,...(null==v||null==(t=v.data)?void 0:t.accessToken)?{authorization:"Bearer ".concat(v.data.accessToken)}:void 0},{data:F=[],isLoading:O,isFetching:B,refetch:P}=(0,o.I)({queryKey:[...T(p,b,"observations_censuses"),"session_clips",a,s,i],queryFn:()=>(0,d.S)({url:"/v1/monitoring/".concat(p,"/sites/").concat(b,"/observations/censuses/sessions/clips"),method:"GET",params:E,headers:L}),enabled:n&&!!p&&!Number.isNaN(b)&&!!s&&!!i,retry:!1,select:e=>e.filter(e=>"unknown"!==e.type).map(e=>({...e,id:"".concat(e.obs_id,"-").concat(e.type,"-").concat(e.user_upload),url:(0,r.V)(e.url)}))});return{clips:F,isLoading:O,isFetching:B,refetch:P}})({taxonId:null==q?void 0:q.taxonId,fromDt:null==q?void 0:q.fromDt,toDt:null==q?void 0:q.toDt,enabled:Z});return((0,_.useEffect)(()=>{V&&Z&&et()},[V,Z,et]),(0,_.useEffect)(()=>{var e;if((null==U?void 0:U.type)!=="image")return;let t=new window.Image;t.src=null!=(e=U.url)?e:"",t.onload=()=>
1{K({width:t.naturalWidth,height:t.naturalHeight})}},[U]),U)?(0,s.jsxs)("div",{className:"grid grid-cols-1 gap-5 sm:grid-cols-12 ".concat("light"===B?"text-black":"text-white"),children:[(0,s.jsxs)("div",{className:(0,C.cn)("col-span-1 flex flex-col gap-5 sm:col-span-9",(!W&&0===U.predictions.length||"list"!==P)&&"sm:col-span-full"),children:[Z&&(0,s.jsx)(L,{clips:J,isLoading:ee,variant:B}),(0,s.jsxs)("span",{className:"font-bold",children:[null==(e=U.taxa)?void 0:e.taxa," ",(null==(t=U.taxa)?void 0:t.latin_taxa)&&(0,s.jsxs)("i",{className:"!font-extralight",children:["(",U.taxa.latin_taxa,")"]})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 gap-y-5",children:[(null==(a=U.taxa)?void 0:a.probability)&&(0,s.jsxs)("div",{className:"pointer-events-auto relative hover:z-[9999]",children:[(0,s.jsx)(S.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"peer !bg-transparent ".concat("light"===B?"border-light-mode-black-200":"border-dark-mode-blue-1100"),children:(0,s.jsx)("span",{className:"bg-gradient-yellow-pink-cyan-green bg-clip-text text-transparent",children:O("monitoring-observations:censuses.probability",{probability:U.taxa.probability})})}),(0,s.jsx)(i.A,{className:"pointer-events-none absolute bottom-full left-1/2 z-[99999] mb-2 -translate-x-1/2 whitespace-nowrap rounded-lg px-2 py-1 text-xs opacity-0 transition-opacity peer-hover:opacity-100 ".concat("light"===B?"bg-light-mode-black-100 text-light-mode-black-600(base)":"bg-dark-mode-blue-1100 text-dark-mode-blue-400"),description:O("monitoring-observations:censuses.badge.predictionAffinity")})]}),(0,s.jsx)(n.U,{geoClass:U.geo_class,geoReason:U.geo_reason,geoDistanceKm:U.geo_distance_km,variant:B}),U.hive_name&&(0,s.jsx)(S.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"!bg-transparent ".concat("light"===B?"border-light-mode-black-200":"border-dark-mode-blue-1100"),children:U.hive_name}),U.device_external_id&&(0,s.jsx)(S.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"!bg-transparent ".concat("light"===B?"border-light-mode-black-200":"border-dark-mode-blue-1100"),children:U.device_external_id}),U.user_upload_email&&(0,s.jsx)(S.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"!bg-transparent ".concat("light"===B?"border-light-mode-black-200":"border-dark-mode-blue-1100"),children:U.user_upload_email}),(0,s.jsxs)("div",{className:"pointer-events-auto relative hover:z-[9999]",children:[(0,s.jsxs)(S.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"peer !bg-transparent ".concat("light"===B?"border-light-mode-black-200":"border-dark-mode-blue-1100"),children:[U.longitude.toFixed(8),"\xb0 E, ",U.latitude.toFixed(8),"\xb0 N"]}),(0,s.jsx)(i.A,{className:"pointer-events-none absolute bottom-full left-1/2 z-[99999] mb-2 -translate-x-1/2 whitespace-nowrap rounded-lg px-2 py-1 text-xs opacity-0 transition-opacity peer-hover:opacity-100 ".concat("light"===B?"bg-light-mode-black-100 text-light-mode-black-600(base)":"bg-dark-mode-blue-1100 text-dark-mode-blue-400"),description:O("monitoring-observations:censuses.badge.geographicCoordinatesTooltip")})]}),U.trancept_areas_name&&(0,s.jsx)(S.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"!bg-transparent ".concat("light"===B?"border-light-mode-black-200":"border-dark-mode-blue-1100"),children:U.trancept_areas_name}),U.device_battery&&(0,s.jsxs)(S.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"!bg-transparent ".concat("light"===B?"border-light-mode-black-200":"border-dark-mode-blue-1100"),children:[(0,s.jsx)(b.In,{icon:"material-symbols:battery-android-0",width:18,height:18,className:"mr-1"}),Math.round(U.device_battery),"%"]}),(0,s.jsx)(en,{longitude:U.longitude,latitude:U.latitude}),(0,s.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:["list"===P&&(0,s.jsx)(ei,{}),U.url&&(()=>{let e=function(e){var t,a,s,i;let n=function(e){let t=e.trim();return t&&t.replace(/[^A-Za-z0-9._-]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"")||"observation"}(null!=(i=null!=(s=null==(t=e.taxa)?void 0:t.latin_taxa)?s:null==(a=e.taxa)?void 0:a.taxa)?i:"observation"),l=function(e){if(!e)return"";let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toISOString().replace(/\..*$/,"").replace(/:/g,"-")}(e.record_date),r=function(e){if(!e)return"bin";try{let t=new URL(e).pathname,a=t.split(".").pop();if(!a||a===t)return"bin";return a.replace(/[^A-Za-z0-9]/g,"").toLowerCase()||"bin"}catch(e){return"bin"}}(e.url),o=l?"".concat(n,"_").concat(l):"".concat(n,"_").concat(Date.now());return"".concat(o,".").concat(r)}(U),t="/api/proxy/download?url=".concat(encodeURIComponent(U.url),"&filename=").concat(encodeURIComponent(e));return(0,s.jsx)("a",{href:t,rel:"noreferrer",download:e,className:"hover:opacity-70",children:(0,s.jsx)(b.In,{icon:"material-symbols:download",width:24,height:24})})})(),"list"===P&&(0,s.jsx)(z.Q,{})]})]}),U.url&&("sound"===U.type?(0,s.jsx)(A.v,{url:U.url,metadataUrl:U.metadata_url}):"image"===U.type?(0,s.jsx)("div",{className:(0,C.cn)("relative max-h-96 w-full",0===G.width&&0===G.height&&"h-96"),style:{aspectRatio:"".concat(G.width," / ").concat(G.height)},children:(0,s.jsx)(k(),{src:U.url,fill:!0,alt:null!=(T=null!=(M=null==(y=U.taxa)?void 0:y.taxa)?M:null==(w=U.taxa)?void 0:w.latin_taxa)?T:O("monitoring-observations:noTaxa"),className:"object-contain"})}):(0,s.jsxs)(f.bL,{className:(0,C.cn)("h-full max-h-96 w-full",0===G.width&&0===G.height&&"h-96 border ".concat("light"===B?"border-light-mode-black-200":"border-dark-mode-blue-1000")),style:{aspectRatio:"".concat(G.width," / ").concat(G.height)},children:[(0,s.jsx)(f.uN,{}),(0,s.jsx)(f.ai,{src:U.url,className:"h-full w-full object-fill",title:null!=(F=null!=(E=null==(N=U.taxa)?void 0:N.taxa)?E:null==(R=U.taxa)?void 0:R.latin_taxa)?F:O("monitoring-observations:noTaxa"),poster:U.url.replace(/\.mp4$/,".jpg"),preload:"metadata",onLoadedMetadata:e=>{let{videoWidth:t,videoHeight:a}=e.target;K({width:t,height:a})}}),(0,s.jsxs)(f.bX,{children:[(0,s.jsx)(f.nU,{}),(0,s.jsx)(f.G4,{}),(0,s.jsx)(f.z2,{})]})]})),"list"===P&&(0,s.jsx)(X.T,{initialValue:null==(D=U.taxa)?void 0:D.latin_taxa,predictionSelected:$}),"list"===P&&U.tag_history&&U.tag_history.length>0&&(0,s.jsx)(es,{items:U.tag_history.map(e=>({id:e.id,date:e.tagged_at,taxaName:e.taxa_name,userEmail:e.user_email}))})]}),"list"===P&&(W||U.predictions.length>0)&&(0,s.jsxs)("div",{className:"col-span-1 flex flex-col gap-5 sm:col-span-3",children:[U.predictions.length>0&&(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsx)("span",{className:"text-sm font-bold",children:O("monitoring-observations:censuses.couldBe")}),(0,s.jsx)(I.bL,{children:(0,s.jsx)(I.UC,{className:"max-h-96 !snap-y flex-col gap-5 overflow-y-auto overflow-x-hidden",children:U.predictions.map(e=>{var t,a,i,n,l,r,o,d;return(0,s.jsxs)(p.bL,{className:(0,C.cn)("relative min-h-24 w-full overflow-hidden rounded-[15p
1x]",e.iconic_taxa&&"cursor-pointer"),onClick:()=>{e.latin_taxa&&Q(t=>t===e.latin_taxa?null:e.latin_taxa)},children:[(0,s.jsx)("div",{className:"absolute inset-0 z-10 h-full w-full bg-[rgba(9,32,43,0.5)] backdrop-blur-md"}),(0,s.jsx)(k(),{src:null!=(t=e.url)?t:v.A.src,alt:null!=(i=null!=(a=e.taxa)?a:e.latin_taxa)?i:O("monitoring-observations:noTaxa"),unoptimized:!0,fill:!0}),(0,s.jsxs)(p.UC,{blur:"md",direction:"horizontal",className:"relative z-20 p-[10px]",children:[(0,s.jsx)("div",{className:"relative h-[70px] w-[130px] overflow-hidden rounded-[5px]",children:(0,s.jsx)(k(),{src:null!=(n=e.url)?n:v.A.src,fill:!0,className:"object-cover",alt:null!=(r=null!=(l=e.taxa)?l:e.latin_taxa)?r:O("monitoring-observations:noTaxa")})}),(0,s.jsxs)("div",{className:"flex h-full w-full flex-1 flex-col justify-between ".concat("light"===B?"text-black":"text-white"),children:[(0,s.jsx)("span",{className:"text-center text-base font-bold",children:null!=(d=null!=(o=e.taxa)?o:e.latin_taxa)?d:O("monitoring-observations:noTaxa")}),(0,s.jsxs)("span",{className:"text-center text-md text-dark-mode-monitoring-600(base)",children:[e.probability,"%"]})]})]})]},e.url)})})})]}),(0,s.jsx)(Y,{})]})]}):null}},58810:(e,t,a)=>{"use strict";a.d(t,{z:()=>s});let s=e=>"hide_improbable"===e?{exclude_geo_class:"bassa,quasi_impossibile"}:"only_improbable"===e?{geo_class:"bassa,quasi_impossibile"}:{}},59039:(e,t,a)=>{"use strict";a.d(t,{y:()=>tv});var s=a(83815),i=a(95007),n=a(46905),l=a(83038),r=a(28229),o=a(31781),d=a(50951),c=a(27492),m=a(40817),u=a(67556),x=a(24999),h=a(92315),g=a(60938),p=a(33635),b=a(90336),v=a(83797),f=a.n(v),j=a(24552),y=a(54002),w=a(99888),N=a(63070),k=a.n(N),_=a(70679),C=a(43052),S=a(69071),I=a(56199),A=a(49858),z=a(45027),R=a(86921),D=a(87317),M=a(54066),T=a(99402),E=a(95001);let L=e=>{let{name:t,label:a,variant:i="blurred",placeholder:n,...l}=e,{control:r}=(0,D.xW)();return(0,s.jsx)(D.xI,{name:t,control:r,render:e=>{let{field:a}=e;return(0,s.jsxs)("div",{className:"relative w-full",children:[(0,s.jsx)(g.In,{icon:"material-symbols:search-rounded",width:24,height:24,color:"white",className:"absolute left-3 top-1/2 z-10 -translate-y-1/2"}),(0,s.jsx)(T.bL,{id:t,placeholder:n||"",variant:i,className:(0,E.cn)("h-9 rounded-md pl-11 text-sm placeholder:!text-light-mode-black-400"),containerClassName:"w-full",...l,...a})]})}})},F=e=>{let{name:t,label:a,variant:i="outline-dark-mode",placeholder:n,showError:l=!0,...r}=e,{control:o,formState:{errors:d}}=(0,D.xW)();return(0,s.jsx)(D.xI,{name:t,control:o,render:e=>{var o,c;let{field:m}=e;return(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[a&&(0,s.jsx)("label",{className:"text-sm",htmlFor:t,children:a}),(0,s.jsx)(T.bL,{id:t,placeholder:n||"",variant:i,className:(0,E.cn)("h-9 rounded-md text-sm placeholder:!text-light-mode-black-400",{"border-state-colors-error-600(base) text-state-colors-error-600(base) focus:border-state-colors-error-600(base)":d[t]}),containerClassName:"w-full",...m,...r}),!!(null==(o=d[t])?void 0:o.message)&&l&&(0,s.jsx)("p",{className:"text-state-colors-error-900",children:String(null==(c=d[t])?void 0:c.message)})]})}})};var O=a(78929),B=a.n(O),P=a(13898);let U=e=>{let{name:t,options:a,onFilteredOptionsChange:i}=e,{setValue:n}=(0,D.xW)(),l=(0,D.FH)({name:"".concat(t,"_search")}),r=(0,_.useCallback)(e=>{n("".concat(t,"_search"),e),i(e?a.filter(t=>{var a;return null==(a=t.label)?void 0:a.toLowerCase().includes(e.toLowerCase())}):a)},[a,i,n,t]);return(0,s.jsx)("div",{className:"p-2",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(g.In,{icon:"material-symbols:search-rounded",width:24,height:24,color:"white",className:"pointer-events-none absolute left-3 top-1/2 z-10 -translate-y-1/2"}),(0,s.jsx)(F,{onChange:e=>r(e.target.value),name:"".concat(t,"_search"),variant:"outline-blue-1100",value:l||"",autoFocus:!0,className:"pl-12"})]})})};function H(e){let{name:t,label:a,placeholder:i,options:n,searchable:l=!1,variant:r="blue-600(base)",children:o,...d}=e,{control:c,setValue:m,formState:{errors:u}}=(0,D.xW)(),[x,h]=(0,_.useState)([]),[g,p]=(0,_.useState)(!1),b=(0,_.useMemo)(()=>l&&g?x:n,[l,g,x,n]),v=(0,_.useCallback)(e=>{h(e),p(e.length<n.length)},[n.length]),f=(0,_.useCallback)(e=>(m("".concat(t,"_search"),""),p(!1),e),[t,m]);return(0,s.jsx)(D.xI,{name:t,control:c,render:e=>{var c,m,x,h;let{field:g}=e;return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)(P.bL,{value:g.value,onValueChange:e=>{g.onChange(e),f(e)},children:[(0,s.jsxs)(P.bq,{id:t,"aria-label":i,variant:r,className:(0,E.cn)("w-full border-none",u[t]&&"border border-state-colors-error-600(base) text-state-colors-error-600(base)"),...d,children:[(0,s.jsxs)("div",{className:"flex min-w-0 flex-col text-left",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-dark-mode-blue-1000",children:a}),(0,s.jsx)("span",{className:"truncate text-base",children:(null==(m=g.value)||null==(c=m.toUpperCase)?void 0:c.call(m))||i||"â"})]}),(0,s.jsx)(P.I6,{variant:r,icon:"radix-icons:triangle-down",color:"white",width:30,height:30})]}),(0,s.jsxs)(P.gC,{position:"popper",className:"z-[1234567] flex max-h-[80dvh] w-[min(92vw,28rem)] flex-col p-0",variant:r,children:[l&&(0,s.jsx)(U,{name:t,options:n,onFilteredOptionsChange:v}),(0,s.jsx)("div",{className:"max-h-75 overflow-y-auto",children:b.map(e=>(0,s.jsx)(H.Option,{option:e,variant:r},e.value))}),o]})]}),!!(null==(x=u[t])?void 0:x.message)&&(0,s.jsx)("p",{className:"mt-2 text-sm text-state-colors-error-900",children:String(null==(h=u[t])?void 0:h.message)})]})}})}H.Option=function(e){let{option:t,variant:a="blue-600(base)",children:i}=e;return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(P.eb,{value:t.label,variant:a,className:"relative flex w-full min-w-40 cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors duration-100 ease-linear data-[disabled]:pointer-events-none data-[disabled]:opacity-50 hover:cursor-pointer",children:(0,s.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col pr-10",children:[(0,s.jsx)("p",{className:"truncate",children:t.label.toUpperCase()}),t.subtitle&&(0,s.jsx)("p",{className:"truncate text-dark-mode-blue-1100",children:t.subtitle})]})}),i&&(0,s.jsx)("div",{className:"absolute right-2 top-1/2 z-10 -translate-y-1/2",children:_.isValidElement(i)&&_.cloneElement(i,{id:t.id,option:t})})]})},H.Footer=function(e){let{children:t}=e;return(0,s.jsx)("div",{className:"flex flex-1",children:t})},H.FooterButton=function(e){let{label:t,onClick:a}=e;return(0,s.jsx)("div",{className:"px-3 py-3",children:(0,s.jsx)("button",{type:"button",onClick:a,className:"w-full rounded px-3 py-2 text-white transition-colors hover:bg-opacity-90",children:t})})},H.FooterLink=function(e){let{label:t,href:a}=e;return(0,s.jsx)("div",{className:"py-3",children:(0,s.jsx)(B(),{href:a,className:"w-full px-3 py-2 text-center text-white underline transition-all hover:no-underline",children:t})})},H.FooterContent=function(e){let{children:t}=e;return(0,s.jsx)("div",{className:"px-3 py-2",children:t})};
1var q=a(67747),V=a(27149),W=a(10307),$=a(33098),Q=a(44359);let G=e=>{let{spacing:t="none",rounded:a="none",children:i,className:n,...l}=e;return(0,s.jsx)($.Wv,{className:(0,E.cn)("flex h-max w-max items-center",{none:"",sm:"p-5",md:"p-10",lg:"p-20",xl:"p-40","2xl":"p-60","3xl":"p-80"}[t],{none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",xl:"rounded-xl","2xl":"rounded-2xl","3xl":"rounded-3xl"}[a],n),"aria-label":"Date picker",...l,children:i})},K=(0,W.tv)({slots:{icon:"h-6 w-6 transition duration-200",label:"text-xs font-medium text-start",subtitle:"text-base",container:"flex w-full gap-2 rounded-xl border-2 border-dark-mode-blue-600(base) p-2 transition duration-200 hover:brightness-75"},variants:{variant:{dark:{icon:"text-white",label:"text-dark-mode-blue-1000",subtitle:"text-white"},light:{icon:"text-black",label:"text-dark-mode-blue-1000",subtitle:"text-black"}}},defaultVariants:{variant:"dark"}}),Z=e=>{let{t}=(0,y.A)("monitoring"),{locale:a="it"}=(0,w.useRouter)(),{selectedDate:i,onSelectDate:n,children:l,popover:r,popoverContent:o}=e,{date_from:d,date_to:c}=(0,q.s)(),[m,u]=(0,_.useState)(i);return(0,s.jsxs)($.bL,{...r,children:[l,(0,s.jsxs)($.hl,{className:"z-[1234567] w-auto rounded-xl border !border-dark-mode-blue-1000 bg-dark-mode-blue-200 p-1",sideOffset:10,collisionPadding:20,...o,children:[(0,s.jsx)(Q.h,{locale:(0,V.no)(a),_selectedDate:m,_setSelectedDate:u,disabledDates:{after:new Date(c),before:new Date(d)},defaultMonth:i}),(0,s.jsxs)("div",{className:"flex justify-end gap-5 px-5 pb-5",children:[(0,s.jsx)(C.$,{disabled:!m,variant:"outline-monitoring-600(base)",onClick:()=>{n(void 0),u(void 0)},children:t("common.reset")}),(0,s.jsx)(C.$,{variant:"monitoring-600(base)",onClick:()=>{n(m)},className:"shadow-none",children:t("common:confirm")})]})]})]})},J=e=>{let{name:t}=e,{t:a}=(0,y.A)("common"),{control:i}=(0,D.xW)(),n=(0,c.r)(),{field:{value:l,onChange:r}}=(0,D.as)({name:t,control:i}),o=K({variant:n}),d={dateLabel:a("common.interval.dateLabel"),datePickerLabel:l?(0,b.default)(l,"dd/MM/yyyy"):a("common.interval.datePickerLabel")};return(0,s.jsx)(Z,{selectedDate:l,onSelectDate:r,popoverContent:{side:"bottom",align:"center"},children:(0,s.jsx)(G,{className:"h-max w-full","data-html2canvas-ignore":!0,children:(0,s.jsxs)("div",{className:o.container(),children:[(0,s.jsxs)("div",{className:"flex flex-col justify-start",children:[(0,s.jsx)("p",{className:o.label(),children:d.dateLabel}),(0,s.jsx)("p",{className:o.subtitle(),children:d.datePickerLabel})]}),(0,s.jsx)("div",{className:"ml-auto flex items-center",children:(0,s.jsx)(g.In,{icon:"material-symbols:calendar-month-outline-rounded",className:(0,E.cn)(o.icon())})})]})})})};var Y=a(98572),X=a(24664),ee=a(94819),et=a(71342),ea=a(62476),es=a(47496),ei=a(62290),en=a(54569);let el=/^-?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,er=/^-?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,eo=".pdf",ed="application/pdf",ec=e=>{var t,a;let{setFilesWithExtractionProcess:i,setStartedGenerating:n}=e,{t:l}=(0,y.A)("monitoring"),{query:r}=(0,w.useRouter)(),o=Number(r.id),d=r.slug,c=(0,z.jE)(),m=(0,j.useSession)(),{toast:u}=ee.dj(),[x,h]=(0,_.useState)(!1),{files:b,setFiles:v,removeFileByIndex:f}=(0,et.M)({accept:ed,maxFiles:1,maxSize:100,onError:e=>{u({variant:"error",description:l("common.files.errors.".concat(e),{size:100,formats:eo,files:1})})}}),N=(0,D.mN)({resolver:(0,Y.u)((e=>en.z.object({file_name:en.z.string().min(1,e("monitoring-observations:censuses.labReport.dialogUploadFile.errors.fileNameRequired")),analysis_type:en.z.string().min(1,e("monitoring-observations:censuses.labReport.dialogUploadFile.errors.analysisTypeRequired")),acquisition_date:en.z.date({required_error:e("monitoring-observations:censuses.labReport.dialogUploadFile.errors.dateRequired"),invalid_type_error:e("monitoring-observations:censuses.labReport.dialogUploadFile.errors.invalidDateFormat")}),location_latitude:en.z.string().regex(el,e("monitoring-observations:censuses.labReport.dialogUploadFile.errors.invalidLatitude")),location_longitude:en.z.string().regex(er,e("monitoring-observations:censuses.labReport.dialogUploadFile.errors.invalidLongitude")),files:en.z.array(en.z.any()).min(1,e("monitoring-observations:censuses.labReport.dialogUploadFile.errors.minimumO
1neFile"))}))(l)),defaultValues:{file_name:"",analysis_type:"",acquisition_date:new Date,location_latitude:"",location_longitude:"",files:[]}}),{watch:k,formState:{errors:S},handleSubmit:I,clearErrors:A,setValue:R,reset:M}=N;(0,_.useEffect)(()=>{var e;let t=(0,X.capitalize)(null==(e=b[0])?void 0:e.name.replace(".pdf","").replace(/[^a-zA-Z0-9\s]/g," ").replace(/\s+/g," ").trim());t&&R("file_name",t)},[b,R]),(0,_.useEffect)(()=>{x||(M(),v([]))},[x,M,v]);let{data:T}=(0,p.o22)(),E=k("analysis_type"),L=null==T?void 0:T.find(e=>e.name===E),{mutate:O,isLoading:B}=(0,p.AMJ)({mutation:{onSuccess:e=>{u({variant:"success",description:l("common:form.success")}),h(!1),M(),n("noLogs"),i(t=>[...t,e]),c.invalidateQueries()},onError:()=>{u({variant:"error",description:l("common:form.error")})}}});return(0,s.jsxs)(ea.Root,{open:x,onOpenChange:e=>{e&&v([]),B||h(e)},children:[(0,s.jsx)(ea.DialogTrigger,{asChild:!0,children:(0,s.jsxs)("button",{className:"flex items-center justify-center gap-3",children:[(0,s.jsx)(g.In,{icon:"material-symbols:upload-rounded",width:20,height:20}),(0,s.jsx)("span",{children:l("monitoring-observations:censuses.labReport.dialogUploadFile.buttonLabel")})]})}),(0,s.jsxs)(ea.DialogContent,{variant:"dark-mode-blue-1000",className:"w-full md:max-w-sm",children:[(0,s.jsxs)(ea.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)("div",{className:"flex flex-col gap-2",children:(0,s.jsx)(ea.DialogTitle,{children:l("monitoring-observations:censuses.labReport.dialogUploadFile.title")})}),(0,s.jsx)(ea.DialogClose,{asChild:!0,children:(0,s.jsx)(g.In,{icon:"material-symbols:close",width:24,height:24,className:"cursor-pointer"})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(es.u,{onDrop:e=>{if(e.dataTransfer.files.length){let t=Array.from(e.dataTransfer.files);v(t),R("files",t,{shouldValidate:!0}),A("files")}},children:[(0,s.jsx)(es.b,{accept:ed,currentNumberOfFiles:b.length,maxNumberOfFiles:1,onChange:e=>{if(e.target.files){let t=Array.from(e.target.files);v(t),R("files",t,{shouldValidate:!0}),A("files")}}}),(0,s.jsx)(g.In,{icon:"ic:outline-cloud-upload",width:36,height:24,className:"text-dark-mode-monitoring-600(base)"}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"font-medium text-white",children:l("common.files.label")}),(0,s.jsx)("p",{className:"text-center text-xs text-light-mode-black-300",children:l("common.files.maxFileSize",{size:100})}),(0,s.jsx)("p",{className:"text-center text-xs text-light-mode-black-300",children:l("common.files.acceptedFormats",{formats:eo})})]})]}),b.length>0&&(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-white",children:l("common.files.selected")}),(0,s.jsx)("ul",{className:"text-light-mode-black-300",children:b.map((e,t)=>(0,s.jsxs)("li",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{children:e.name}),(0,s.jsx)(C.$,{variant:"unstyled",onClick:()=>f(t),children:(0,s.jsx)(g.In,{icon:"carbon:close",width:20,height:20,className:"text-white"})})]},e.name))})]}),S.files&&(0,s.jsx)("p",{className:"text-sm text-red-400",children:null==(t=S.files.message)?void 0:t.toString()})]}),(0,s.jsxs)(D.Op,{...N,children:[(0,s.jsx)("p",{className:"text-white",children:l("monitoring-observations:censuses.labReport.dialogUploadFile.details")}),(0,s.jsxs)("form",{className:"flex flex-col gap-5",onSubmit:I(e=>{var t;O({userSlug:d,siteId:o,data:{file:b[0],file_name:e.file_name,acquisition_date:e.acquisition_date.toISOString(),location_latitude:Number(e.location_latitude),location_longitude:Number(e.location_longitude),analysis_type_id:Number(null==L?void 0:L.id)},headers:{authorization:"Bearer ".concat(null==m||null==(t=m.data)?void 0:t.accessToken)}})}),children:[(0,s.jsx)(F,{label:l("monitoring-observations:censuses.labReport.dialogUploadFile.fields.fileNameLabel"),name:"file_name",placeholder:l("monitoring-observations:censuses.labReport.dialogUploadFile.fields.fileNamePlaceholder")}),(0,s.jsx)(H,{label:l("monitoring-observations:censuses.labReport.dialogUploadFile.fields.analysisCategoriesLabel"),name:"analysis_type",options:null!=(a=null==T?void 0:T.map(e=>({id:e.id,label:e.name,value:String(e.id)})))?a:[],placeholder:l("monitoring-observations:censuses.labReport.dialogUploadFile.fields.analysisCategoriesPlaceholder")}),(0,s.jsx)(J,{name:"acquisition_date"}),(0,s.jsx)(ei.H,{className:"h-px w-full bg-dark-mode-blue-400"}),(0,s.jsxs)("div",{className:"flex justify-between gap-2",children:[(0,s.jsx)(F,{label:l("monitoring-observations:censuses.labReport.dialogUploadFile.fields.latitudeLabel"),name:"location_latitude",placeholder:l("monitoring-observations:censuses.labReport.dialogUploadFile.fields.latitudePlaceholder")}),(0,s.jsx)(F,{label:l("monitoring-observations:censuses.labReport.dialogUploadFile.fields.longitudeLabel"),name:"location_longitude",placeholder:l("monitoring-observations:censuses.labReport.dialogUploadFile.fields.longitudePlaceholder")})]}),(0,s.jsx)(ei.H,{className:"my-3 h-px w-full bg-dark-mode-blue-400"}),(0,s.jsx)(ea.DialogFooter,{children:(0,s.jsxs)(C.$,{type:"submit",className:"w-full",variant:"monitoring-600(base)",size:"xs",children:[l("monitoring-observations:censuses.labReport.dialogUploadFile.uploadButtonLabel"),B&&(0,s.jsx)(g.In,{icon:"eos-icons:loading",width:20,height:20,className:"block shrink-0",color:"white"})]})})]})]})]})]})};var em=a(21490),eu=a(92682),ex=a(8408);let eh=e=>{let{handleDelete:t,isLoadingDelete:a,isMobile:i}=e,{t:n}=(0,y.A)("monitoring"),[l,r]=(0,_.useState)(!1);return(0,s.jsxs)(ea.Root,{open:l,onOpenChange:r,children:[(0,s.jsx)(ea.DialogTrigger,{asChild:!0,children:(0,s.jsx)("button",{className:"flex flex-row items-center p-1 text-sm text-state-colors-error-600(base)",children:(0,s.jsx)(g.In,{icon:"ph:trash",width:i?24:32,height:32,className:"text-state-colors-error-800"})})}),(0,s.jsxs)(ea.DialogContent,{variant:"state-colors-error-600(base)",className:"min-w-[300px] !gap-3 md:min-w-[500px]",children:[(0,s.jsxs)(ea.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(ea.DialogTitle,{children:n("common:alert")}),(0,s.jsx)(ea.DialogClose,{asChild:!0,disabled:a,children:(0,s.jsx)(g.In,{icon:"material-symbols:close",width:24,height:24,className:"cursor-pointer"})})]}),(0,s.jsx)(ea.DialogDescription,{children:(0,s.jsx)(ex.A,{i18nKey:n("stakeholders.deleteStakeholderModal.description"),components:{b:(0,s.jsx)("strong",{})}})}),(0,s.jsxs)(ea.DialogFooter,{className:"flex justify-end",children:[(0,s.jsx)(C.$,{variant:"outline-error-600(base)",onClick:()=>{r(!1)},size:"xs",disabled:a,children:n("common:cancel")}),(0,s.jsxs)(C.$,{variant:"error-600(base)",onClick:t,size:"xs",disabled:a,children:[n("common:common.delete"),a&&(0,s.jsx)(g.In,{icon:"eos-icons:three-dots-loading",width:48,height:48,color:"#3c3300"})]})]})]})]})},eg=e=>{let{row:t,onRowClick:a,isAdminOrCanEditSite:i}=e,{t:n}=(0,y.A)("monitoring"),{query:l,locale:r="it"}=(0,w.useRouter)(),o=l.slug,d=Number(l.id),c=(0,z.jE)(),m=(0,j.use
1Session)(),{toast:u}=ee.dj(),{mutateAsync:x,isLoading:h}=(0,p.E4K)({mutation:{onSuccess:()=>{u({variant:"success",description:n("monitoring-observations:censuses.labReport.deleteLabSuccess")}),c.invalidateQueries((0,p.yn3)(o,d))},onError:()=>{u({variant:"error",description:n("monitoring-observations:censuses.labReport.deleteLabError")})}}}),v=async()=>{var e;await x({userSlug:o,siteId:d,labReportId:t.id,headers:{authorization:"Bearer ".concat(null==m||null==(e=m.data)?void 0:e.accessToken)}})},f=(0,eu.A)(t.acquisition_date),N=(0,b.default)(f,"dd LLL yyyy",{locale:(0,V.no)(r)}),k=t.uploader_full_name===em.Wj?"-":t.uploader_full_name;return(0,s.jsxs)("tr",{onClick:()=>a(t),className:"group cursor-pointer transition-colors duration-200 hover:bg-dark-mode-blue-400",children:[(0,s.jsx)("td",{className:"rounded-l-3xl border-b-2 border-l-2 border-t-2 border-dark-mode-blue-600(base) text-white",children:t.file_name}),(0,s.jsx)("td",{className:"border-b-2 border-t-2 border-dark-mode-blue-600(base) text-white",children:k}),(0,s.jsx)("td",{className:"border-b-2 border-t-2 border-dark-mode-blue-600(base) text-white",children:N}),i&&(0,s.jsx)("td",{onClick:e=>e.stopPropagation(),className:"border-b-2 border-t-2 border-dark-mode-blue-600(base) text-white",children:h?(0,s.jsx)(g.In,{icon:"eos-icons:three-dots-loading",width:80,height:80,color:"#F5D000"}):(0,s.jsx)(eh,{isLoadingDelete:h,handleDelete:v})}),(0,s.jsx)("td",{className:"rounded-r-3xl border-b-2 border-r-2 border-t-2 border-dark-mode-blue-600(base) text-white",children:(0,s.jsx)("div",{className:"flex h-full w-full items-center justify-end p-1",children:(0,s.jsx)(g.In,{icon:"material-symbols:chevron-right-rounded",height:32,color:"white"})})})]})};var ep=a(45717),eb=a(75258),ev=a.n(eb),ef=a(45954),ej=a(71498),ey=a(55062),ew=a(21392);let eN=e=>{let{name:t,label:a,variant:i="darkVariant",placeholder:n,...l}=e,{control:r,formState:{errors:o}}=(0,D.xW)();return(0,s.jsx)(D.xI,{name:t,control:r,render:e=>{var r;let{field:d}=e;return(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[a&&(0,s.jsx)("label",{className:"text-sm md:text-base",htmlFor:t,children:a}),(0,s.jsx)(ew.b,{id:t,placeholder:n,variant:i,className:"h-9 rounded-md text-sm placeholder:!text-light-mode-black-400",...d,...l}),o[t]&&(0,s.jsx)("p",{className:"text-state-colors-error-900",children:String(null==(r=o[t])?void 0:r.message)})]})}})};var ek=a(4971),e_=a(86666),eC=a.n(e_);let eS=e=>{let{onDelete:t,onEdit:a,isAuthorNoteEmail:i}=e,{t:n}=(0,y.A)("monitoring"),{isAdmin:l}=(0,x.A)(),[r,o]=(0,_.useState)(!1),d=i||l;return(0,s.jsxs)($.bL,{children:[d&&(0,s.jsx)($.Wv,{asChild:!0,children:(0,s.jsx)(C.$,{variant:"unstyled",className:"h-max w-max md:!p-2",children:(0,s.jsx)(g.In,{icon:"material-symbols:more-vert",className:"h-4 w-4 text-white md:h-6 md:w-6"})})}),(0,s.jsxs)($.hl,{side:"bottom",className:"z-[12345678] flex w-max flex-col rounded-lg border border-dark-mode-blue-400 bg-dark-mode-blue-300 p-0 md:min-w-64",children:[d&&(0,s.jsx)(C.$,{variant:"text-only-white",className:"m-1 flex items-center justify-start !rounded-sm px-4 py-1 hover:!bg-dark-mode-blue-1100/20 md:px-8 md:py-2",onClick:a,children:(0,s.jsx)("p",{className:"text-sm font-normal text-white",children:n("common:common.edit")})}),d&&(0,s.jsx)("hr",{className:"border border-dark-mode-blue-400"}),d&&(r?(0,s.jsxs)("div",{className:"m-1 flex min-h-12 items-center justify-between gap-4 px-4 py-1 md:px-8 md:py-2",children:[(0,s.jsx)("p",{className:"text-sm text-white",children:n("common:common.deleteConfirmation")}),(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between gap-2",children:[(0,s.jsx)(C.$,{variant:"unstyled",className:"h-max w-max",onClick:()=>o(!1),children:(0,s.jsx)(g.In,{icon:"material-symbols:close-rounded",className:"h-4 w-4 text-white"})}),(0,s.jsx)(C.$,{variant:"unstyled",className:"h-max w-max",onClick:()=>{t(),o(!1)},children:(0,s.jsx)(g.In,{icon:"material-symbols:check-rounded",className:"h-4 w-4 text-white"})})]})]}):(0,s.jsx)(C.$,{variant:"text-only-white",className:"m-1 flex items-center justify-start !rounded-sm px-4 py-1 hover:!bg-dark-mode-blue-1100/20 md:px-8 md:py-2",onClick:()=>o(!0),children:(0,s.jsx)("p",{className:"text-sm font-bold text-white",children:n("common:common.delete")})}))]})]})},eI=e=>{var t,a,i;let{id:n,text:l,author_name:r,created_at:o,labReportId:d,author_avatar:c,author_email:m}=e,{t:u}=(0,y.A)("monitoring"),{query:h}
1=(0,w.useRouter)(),g=h.slug,b=Number(h.id),v=(0,j.useSession)(),f=(0,z.jE)(),[N,k]=(0,_.useState)(!1),{isAdmin:S}=(0,x.A)(),I=null==(t=v.data)?void 0:t.user.email,A=(0,D.mN)({defaultValues:{note:""}}),{reset:R,handleSubmit:M,formState:{isSubmitting:T}}=A,{mutateAsync:E,isLoading:L}=(0,p.MO_)({mutation:{onSuccess:async()=>{await f.invalidateQueries({queryKey:[(0,p.kh7)(g,b,d)]})}}}),{mutateAsync:F}=(0,p.YXP)({mutation:{onSuccess:async()=>{await f.invalidateQueries({queryKey:[(0,p.kh7)(g,b,d)]})}}});(0,_.useEffect)(()=>{R({note:l})},[l,R]),(0,_.useEffect)(()=>{L||T||k(!1)},[L,T]);let O=(0,_.useMemo)(()=>r?r.split(" ").map(e=>e.charAt(0).toUpperCase()).slice(0,2).join(""):"",[r]),B=(0,_.useCallback)(async()=>{var e;L||await F({userSlug:g,siteId:b,labReportId:d,noteId:n,headers:{authorization:"Bearer ".concat(null==v||null==(e=v.data)?void 0:e.accessToken)}})},[L,F,g,b,d,n,null==v||null==(a=v.data)?void 0:a.accessToken]),P=(0,_.useCallback)(async e=>{var t;L||await E({userSlug:g,siteId:b,labReportId:d,noteId:n,data:{note:e.note},headers:{authorization:"Bearer ".concat(null==v||null==(t=v.data)?void 0:t.accessToken)}})},[L,E,g,b,d,n,null==v||null==(i=v.data)?void 0:i.accessToken]),U=(0,_.useCallback)(()=>{L||k(e=>!e)},[L]),H=(0,_.useCallback)(()=>{k(!1),R({note:l})},[R,l]);return(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex gap-5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[c&&c!==em.Wj?(0,s.jsx)(eC(),{src:c,alt:"avatar",width:40,height:40,className:"rounded-full"}):(0,s.jsx)("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-light-mode-black-200",children:(0,s.jsx)("span",{className:"text-base text-black",children:O})}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("span",{className:"text-base",children:r}),(0,s.jsx)("span",{className:"text-sm text-dark-mode-blue-1000",children:u(S?"common:common.admin":"common:common.user")})]})]}),(0,s.jsx)(ek.H,{created_at:o})]}),!N&&(0,s.jsx)(eS,{isAuthorNoteEmail:I===m,onEdit:U,onDelete:B})]}),(0,s.jsx)(D.Op,{...A,children:(0,s.jsx)("form",{onSubmit:M(P),children:N?(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)(eN,{name:"note",placeholder:u("monitoring-observations:censuses.labReport.kpiNote.enterNote"),disabled:L}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(C.$,{variant:"secondary",type:"button",onClick:H,disabled:L,children:u("common:unlockCards.modal.cancel")}),(0,s.jsx)(C.$,{variant:"teal",type:"submit",disabled:L,children:u("monitoring-observations:censuses.labReport.kpiNote.saveNote")})]})]}):(0,s.jsx)("p",{children:l})})}),(0,s.jsx)(ei.H,{className:"my-5 h-px w-full bg-dark-mode-blue-1000"})]})},eA=e=>{var t;let{labReportId:a}=e,{t:i}=(0,y.A)("monitoring"),{query:n}=(0,w.useRouter)(),l=n.slug,r=Number(n.id),o=(0,j.useSession)(),d=(0,z.jE)(),[c,m]=(0,_.useState)(!1),[u,x]=(0,_.useState)(!1),h=(0,_.useRef)(null),b="authenticated"===o.status,v=(0,D.mN)(),{handleSubmit:f,getValues:N,setValue:k,formState:{isSubmitting:S}}=v,{data:I}=(0,p.i$3)(l,r,a,{authorization:"Bearer ".concat(null==o||null==(t=o.data)?void 0:t.accessToken)},{query:{queryKey:[(0,p.kh7)(l,r,a)]}}),{mutateAsync:A,isLoading:R}=(0,p.glL)({mutation:{onSuccess:async()=>{await d.invalidateQueries({queryKey:[(0,p.kh7)(l,r,a)]}),k("note",""),m(!0)}}});(0,_.useLayoutEffect)(()=>{if(c){let e=h.current;e&&(e.scrollTop=e.scrollHeight),m(!1)}},[I,c]);let M=async()=>{var e;let t=N("note");(null==t?void 0:t.trim())&&(await A({userSlug:l,siteId:r,labReportId:a,data:{note:t},headers:{authorization:"Bearer ".concat(null==o||null==(e=o.data)?void 0:e.accessToken)}}),x(!1))};return(0,s.jsxs)("div",{className:"flex h-full max-h-full flex-col",children:[!!(null==I?void 0:I.length)&&(0,s.jsx)("div",{ref:h,className:"flex-grow overflow-y-auto pr-2 scrollbar-hide",children:I.map(e=>(0,s.jsx)(eI,{...e,labReportId:a},e.id))}),!b&&!(null==I?void 0:I.length)&&(0,s.jsx)("p",{className:"text-center text-dark-mode-blue-900",children:i("monitoring-observations:censuses.labReport.kpiNote.noNotesAvailable")}),(0,s.jsx)("div",{className:"mt-4 pt-4",children:(0,s.jsx)(D.Op,{...v,children:(0,s.jsxs)("form",{onSubmit:f(M),className:"flex flex-col gap-3",children:[u&&(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"font-medium text-white",children:i("monitoring-observations:censuses.labReport.kpiNote.addNe
1wNote")}),(0,s.jsx)(eN,{name:"note",placeholder:i("monitoring-observations:censuses.labReport.kpiNote.enterNote"),disabled:R||S,rows:4})]}),u&&(0,s.jsx)(ei.H,{className:"my-5 h-px w-full bg-dark-mode-blue-1000"}),b&&(0,s.jsxs)("div",{className:"flex gap-3",children:[u&&(0,s.jsx)(C.$,{type:"button",onClick:()=>x(!1),variant:"secondary",disabled:R||S,children:i("common:close")}),(0,s.jsx)(C.$,{type:u?"submit":"button",onClick:u?void 0:()=>x(!0),variant:"teal",disabled:R||S,children:(0,s.jsxs)("div",{className:"flex items-center justify-center gap-1",children:[!u&&(0,s.jsx)(g.In,{icon:"mdi-plus",width:20,height:20,className:"shrink-0"}),(0,s.jsx)("span",{children:i(u?"monitoring-observations:censuses.labReport.kpiNote.saveNote":"monitoring-observations:censuses.labReport.kpiNote.addNote")})]})})]})]})})})]})};var ez=a(79845);let eR=e=>{let{selectedRow:t,locale:a}=e,{t:s}=(0,y.A)("monitoring"),{isAdmin:i,canEditSite:n}=(0,x.A)(),l=[{id:1,value:null==t?void 0:t.file_name},{id:2,value:t&&function(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"dd LLL yyyy";return e?(0,b.default)(new Date(e),a,{locale:(0,V.no)(t)}):"-"}(t.acquisition_date,a)},{id:3,value:"".concat(null==t?void 0:t.location_longitude,"\xb0 E, ").concat(null==t?void 0:t.location_latitude,"\xb0 N")},{id:4,value:null==t?void 0:t.uploader_full_name}],r=[{id:"kpi",label:"KPI"},{id:"interval",label:s("monitoring-observations:censuses.labReport.tableHeaderRowDetail.interval")},{id:"value",label:s("monitoring-observations:censuses.labReport.tableHeaderRowDetail.value")},{id:"unit",label:s("monitoring-observations:censuses.labReport.tableHeaderRowDetail.unit")},{id:"result",label:s("monitoring-observations:censuses.labReport.tableHeaderRowDetail.result")},...i||n?[{id:"actions",label:s("monitoring-observations:censuses.labReport.tableHeaderRowDetail.actions")}]:[]];return{assignLetterFromRange:ez.Ht,tableHeader:r,badges:l}};var eD=a(12259);let eM=en.z.object({value_1:en.z.coerce.number({message:""}).finite(),value_2:en.z.coerce.number({message:""}).finite(),value_3:en.z.coerce.number({message:""}).finite(),value_4:en.z.coerce.number({message:""}).finite(),value_5:en.z.coerce.number({message:""}).finite(),value_6:en.z.coerce.number({message:""}).finite()}).refine(e=>e.value_1<e.value_2,{path:["value_2"],message:""}).refine(e=>e.value_2<e.value_3,{path:["value_3"],message:""}).refine(e=>e.value_3<e.value_4,{path:["value_4"],message:""}).refine(e=>e.value_4<e.value_5,{path:["value_5"],message:""}).refine(e=>e.value_5<e.value_6,{path:["value_6"],message:""}),eT=()=>{let{control:e}=(0,D.xW)(),[t,a]=(0,D.FH)({control:e,name:["value_1","value_6"]});return(0,s.jsxs)("p",{children:["[",isNaN(Number(t))?"...":Number(t)," - ",isNaN(Number(a))?"...":Number(a),"]"]})},eE=[eD.Rj.VERY_HIGH["400-base"],eD.Rj.HIGH["400-base"],eD.Rj.MED["400-base"],eD.Rj.LOW["400-base"],eD.Rj.VERY_LOW["400-base"]],eL=e=>{let{kpiId:t,isEditing:a,ranges:i,id:n}=e,{t:l}=(0,y.A)("monitoring"),r=(0,z.jE)(),o=(0,j.useSession)(),{toast:d}=ee.dj(),[c,m]=(0,_.useState)(!1),[u,x]=(0,_.useState)(!1),h=(0,D.mN)({resolver:(0,Y.u)(eM),mode:"onSubmit"}),{handleSubmit:b,reset:v}=h,f=null==i?void 0:i.find(e=>e.id===n);(0,_.useEffect)(()=>{a&&f&&(x("ASC"!==f.direction),v({value_1:Number(null==f?void 0:f.range[0]),value_2:Number(null==f?void 0:f.range[1]),value_3:Number(null==f?void 0:f.range[2]),value_4:Number(null==f?void 0:f.range[3]),value_5:Number(null==f?void 0:f.range[4]),value_6:Number(null==f?void 0:f.range[5])}))},[a,f,v]);let{mutate:w,isLoading:N}=(0,p.Jy5)({mutation:{onSuccess:()=>{d({variant:"success",description:l("common:form.success")}),m(!1),r.invalidateQueries()},onError:()=>{d({variant:"error",description:l("common:form.error")})}}});return(0,s.jsxs)(ea.Root,{open:c,onOpenChange:e=>{N||m(e)},children:[(0,s.jsx)(ea.DialogTrigger,{asChild:!0,children:a?(0,s.jsx)("button",{disabled:(null==f?void 0:f.type)!=="CUSTOM",className:"flex items-center justify-center gap-3",children:(null==f?void 0:f.type)==="CUSTOM"?(0,s.jsx)(g.In,{icon:"mdi-pencil",width:20,height:20}):(0,s.jsx)(g.In,{icon:"mdi-pencil-off",color:eD.y,width:20,height:20})}):(0,s.jsx)("button",{className:"flex items-center justify-center gap-3",children:(0,s.jsx)("span",{children:l("monitoring-observations:censuses.labReport.dialogAddKpi.createRange")})})}),(0,s.jsxs)(ea.DialogContent,{variant:"dark-mode-blue-1000",className:"w-full md:max-w-sm",children:[(0,s.jsxs)(ea.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)("div",{className:"flex flex-col gap-2",children:(0,s.jsx)(ea.DialogTitle,{children:a?l("monitoring-observations:censuses.labReport.dialogAddKpi.editRange"):l("monitoring-observations:censuses.labReport.dialogAddKpi.createRange")})}),(0,s.jsx)(ea.DialogClose,{asChild:!0,children:(0,s.jsx)(g.In,{icon:"material-symbols:close",width:24,height:24,className:"cursor-pointer"})})]}),(0,s.jsxs)(D.Op,{...h,children:[(0,s.jsx)("p",{className:"text-white",children:l("monitoring-observations:censuses.labReport.dialogAddKpi.selectRangeValues")}),(0,s.jsxs)("form",{className:"flex flex-col gap-5",onSubmit:b(e=>{var a;w({kpiId:t,data:{direction:u?"DESC":"ASC",range:[String(e.value_1),String(e.value_2),String(e.value_3),String(e.value_4),String(e.value_5),String(e.value_6)]},headers:{authorization:"Bearer ".concat(null==o||null==(a=o.data)?void 0:a.accessToken)}})}),children:[(0,s.jsxs)("div",{className:"flex h-full w-full flex-col rounded-xl bg-dark-mode-blue-300 p-3",children:[(0,s.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,s.jsx)("button",{type:"button",onClick:()=>x(e=>!e),children:(0,s.jsx)(g.In,{icon:"mdi-arrow-".concat(u?"up":"down"),width:20,height:20})}),(0,s.jsx)("p",{children:(0,s.jsx)(eT,{})})]}),(0,s.jsx)("div",{className:"flex h-full flex-col items-center justify-center gap-3",children:(0,s.jsxs)("div",{className:"flex h-full",children:[(0,s.jsx)("div",{className:(0,E.cn)("flex h-full flex-col justify-around ga
1p-3",{"flex-col-reverse":u}),children:em.mt.map(e=>(0,s.jsx)("p",{className:"text-sm font-bold",children:e},e))}),(0,s.jsx)("div",{className:(0,E.cn)("flex h-full flex-col justify-between gap-2 px-5",{"flex-col-reverse":u}),children:eE.map((e,t)=>(0,s.jsx)("div",{style:{backgroundColor:e},className:(0,E.cn)("h-20 w-2",{"first:rounded-bl-md first:rounded-br-md last:rounded-tl-md last:rounded-tr-md":!u,"first:rounded-tl-md first:rounded-tr-md last:rounded-bl-md last:rounded-br-md":u})},t))}),(0,s.jsx)("div",{className:"flex h-full w-17 flex-col justify-around gap-3",children:Array.from({length:6}).map((e,t)=>(0,s.jsx)(F,{name:"value_".concat(t+1),placeholder:"Valore"},t))})]})})]}),(0,s.jsx)(ea.DialogFooter,{children:(0,s.jsxs)(C.$,{type:"submit",className:"w-full",variant:"monitoring-600(base)",size:"xs",children:[a?l("monitoring-observations:censuses.labReport.dialogAddKpi.editRangeButtonLabel"):l("monitoring-observations:censuses.labReport.dialogAddKpi.createRangeButtonLabel"),N&&(0,s.jsx)(g.In,{icon:"eos-icons:loading",width:20,height:20,className:"block shrink-0",color:"white"})]})})]})]})]})]})},eF=e=>{let{desktopTableRef:t,measures:a,handleDeleteMeasure:i,isAdminOrCanEditSite:n,assignLetterFromRange:l,customRows:r,setCustomRows:o,kpis:d,kpiSelected:c,ranges:m,rangeSelected:u,hasKpiAndValue:x,letterValue:h,tableHeader:p,isDeleting:b}=e,{t:v}=(0,y.A)("monitoring"),{reset:f}=(0,D.xW)(),[j,{close:w,toggle:N}]=(0,ej.A)(!1),k="h-30 w-1/6 border-b border-r border-[#17506D] px-4 align-middle",_=null==m?void 0:m.find(e=>"CUSTOM"===e.type);return(0,s.jsx)("div",{ref:t,className:"hidden max-h-[60vh] w-full overflow-y-auto text-white scrollbar-hide lg:block 2xl:w-full",children:(0,s.jsxs)("table",{className:"w-full table-fixed border-separate border-spacing-0 text-sm text-white",children:[(0,s.jsx)("thead",{children:(0,s.jsx)("tr",{className:"text-base text-white/80",children:p.map((e,t)=>(0,s.jsx)("th",{className:(0,E.cn)("h-30 w-1/6 border-b border-r border-[#17506D] px-4 text-center align-middle",0===t&&"border-l"),children:e.label},e.id))})}),(0,s.jsxs)("tbody",{children:[null==a?void 0:a.map((e,t)=>{let a=l(e.range,Number(e.value),e.direction);return(0,s.jsxs)("tr",{className:"text-center text-base",children:[(0,s.jsx)("td",{className:"h-30 w-1/6 border-b border-l border-r border-[#17506D] px-4 align-middle",children:e.name}),(0,s.jsx)("td",{className:k,children:"[".concat(e.range[0],", ").concat(e.range[e.range.length-1],"]")}),(0,s.jsx)("td",{className:k,children:e.value}),(0,s.jsx)("td",{className:k,children:(0,s.jsx)("div",{className:"flex h-full items-center justify-center gap-2",children:(0,s.jsx)("span",{className:"text-light-mode-black-500",children:e.unit})})}),(0,s.jsx)("td",{className:k,children:(0,s.jsx)("div",{className:"mx-auto h-9 w-9 rounded-lg",style:{backgroundColor:a.bg},children:(0,s.jsx)("span",{style:{color:a.text},className:"text-center text-lg font-semibold",children:a.value})})}),n&&(0,s.jsx)("td",{className:(0,E.cn)(k),children:(0,s.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,s.jsx)(eh,{handleDelete:()=>i(e.id),isLoadingDelete:b})})})]},"row-".concat(t))}),r.map((e,t)=>(0,s.jsxs)("tr",{className:"text-center text-base",children:[(0,s.jsx)("td",{className:"h-30 w-1/6 border-b border-l border-r border-[#17506D] px-4 align-middle",children:(0,s.jsx)(H,{searchable:!0,placeholder:"KPI",name:"select-kpis",options:(null==d?void 0:d.map(e=>({id:e.id,value:String(e.id),label:e.name})))||[],children:(0,s.jsx)(H.Footer,{children:(0,s.jsxs)(H.FooterContent,{children:[(0,s.jsx)("button",{onClick:N,children:(0,s.jsx)("span",{className:"text-white underline",children:v("monitoring-observations:censuses.labReport.kpiSection.kpiNotFound")})}),(0,s.jsx)(ey._,{close:w,open:j})]})})})}),(0,s.jsx)("td",{className:k,children:(0,s.jsxs)(H,{disabled:!(null==c?void 0:c.id),placeholder:"Range",name:"range",options:[],children:[null==m?void 0:m.map(e=>(0,s.jsx)(H.Option,{option:{id:e.id,value:String(e.id),label:e.type,subtitle:"[".concat(e.range[0],", ").concat(e.range[e.range.length-1],"]")},children:(0,s.jsx)(eL,{isEditing:!0,ranges:m,kpiId:(null==c?void 0:c.id)||0})},e.id)),!_&&(0,s.jsx)(H.Footer,{children:(0,s.jsx)(H.FooterContent,{children:(0,s.jsx)(eL,{kpiId:(null==c?void 0:c.id)||0})})})]})}),(0,s.jsx)("td",{className:k,children:(0,s.jsx)(F,{disabled:!(null==c?void 0:c.id)||!(null==u?void 0:u.id),showError:!1,placeholder:u?"[".concat(null==u?void 0:u.range[0],", ").concat(null==u?void 0:u.range[(null==u?void 0:u.range.length)-1],"]"):v("monitoring-observations:censuses.labReport.kpiSection.enterValue"),name:"kpi-value"})}),(0,s.jsx)("td",{className:"h-30 w-1/6 border-b border-r border-[#17506D] px-4 align-middle text-light-mode-black-500",children:null==c?void 0:c.unit}),(0,s.jsx)("td",{className:"h-30 w-1/6 border-b border-r border-[#17506D] px-4 align-middle text-light-mode-black-500",children:x&&(0,s.jsx)("div",{className:"mx-auto h-9 w-9 rounded-lg",style:{backgroundColor:h.bg},children:(0,s.jsx)("span",{style:{color:h.text},className:"text-center text-lg font-semibold",children:h.value})})}),(0,s.jsx)("td",{className:k,children:(0,s.jsx)(C.$,{variant:"unstyled",className:"rounded p-1",onClick:()=>{o([]),f()},children:(0,s.jsx)(g.In,{icon:"ph:trash",width:32,height:32,className:"text-state-colors-error-800"})})})]},"row-custom-".concat(t)))]})]})})},eO=e=>{let{mobileCardsRef:t,measures:a,handleDeleteMeasure:i,isAdminOrCanEditSite:n,assignLetterFromRange:l,customRows:r,setCustomRows:o,kpis:d,kpiSelected:c,ranges:m,rangeSelected:u,hasKpiAndValue:x,letterValue:h,isDeleting:p}=e,{t:b}=(0,y.A)("monitoring"),{reset:v}=(0,D.xW)(),[f,{close:j,toggle:w}]=(0,ej.A)(!1),N=null==m?void 0:m.find(e=>"CUSTOM"===e.type);return(0,s.jsx)("div",{className:"block lg:hidden",children:(0,s.jsxs)("div",{ref:t,className:"max-h-96 w-full flex-grow
1space-y-4 overflow-y-auto text-white scrollbar-hide",children:[null==a?void 0:a.map((e,t)=>{let a=l(e.range,Number(e.value),e.direction);return(0,s.jsxs)("div",{className:"rounded-lg border border-dark-mode-blue-800 p-4",children:[(0,s.jsxs)("div",{className:"mb-3 flex items-start justify-between",children:[(0,s.jsx)("h3",{className:"truncate pr-2 text-lg font-semibold text-white",children:e.name}),n&&(0,s.jsx)("td",{children:(0,s.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,s.jsx)(eh,{isMobile:!0,handleDelete:()=>i(e.id),isLoadingDelete:p})})})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"mb-1 block text-white/70",children:"Range:"}),(0,s.jsx)("span",{className:"text-white",children:"[".concat(e.range[0],", ").concat(e.range[e.range.length-1],"]")})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("span",{className:"mb-1 block text-white/70",children:[b("monitoring-observations:censuses.labReport.kpiSection.value"),":"]}),(0,s.jsx)("span",{className:"text-white",children:e.value})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"mb-1 block text-white/70",children:(0,s.jsxs)("span",{className:"mb-1 block text-white/70",children:[b("monitoring-observations:censuses.labReport.kpiSection.unit"),":"]})}),(0,s.jsx)("span",{className:"text-light-mode-black-500",children:e.unit})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("span",{className:"mb-1 block text-white/70",children:[b("monitoring-observations:censuses.labReport.kpiSection.result"),":"]}),(0,s.jsx)("div",{className:"inline-flex",children:(0,s.jsx)("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg",style:{backgroundColor:a.bg},children:(0,s.jsx)("span",{style:{color:a.text},className:"text-center text-lg font-semibold",children:a.value})})})]})]})]},"card-".concat(t))}),r.map((e,t)=>(0,s.jsxs)("div",{className:"rounded-lg border border-dark-mode-blue-800 p-4",children:[(0,s.jsxs)("div",{className:"mb-3 flex items-start justify-between",children:[(0,s.jsx)("h3",{className:"text-lg font-semibold text-white",children:b("monitoring-observations:censuses.labReport.kpiSection.newKpi")}),(0,s.jsx)(C.$,{variant:"unstyled",className:"flex-shrink-0 rounded p-1",onClick:()=>{o([]),v()},children:(0,s.jsx)(g.In,{icon:"ph:trash",width:24,height:24,className:"text-state-colors-error-800"})})]}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"mb-2 block text-sm text-white/70",children:"KPI:"}),(0,s.jsx)(H,{searchable:!0,placeholder:"KPI",name:"select-kpis",options:(null==d?void 0:d.map(e=>({id:e.id,value:String(e.id),label:e.name})))||[],children:(0,s.jsx)(H.Footer,{children:(0,s.jsxs)(H.FooterContent,{children:[(0,s.jsx)("button",{onClick:w,children:(0,s.jsx)("span",{className:"text-white underline",children:b("monitoring-observations:censuses.labReport.kpiSection.kpiNotFound")})}),(0,s.jsx)(ey._,{close:j,open:f})]})})})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{className:"mb-2 block text-sm text-white/70",children:[b("monitoring-observations:censuses.labReport.kpiSection.range"),":"]}),(0,s.jsxs)(H,{disabled:!(null==c?void 0:c.id),placeholder:"Range",name:"range",options:[],children:[null==m?void 0:m.map(e=>(0,s.jsx)(H.Option,{option:{id:e.id,value:String(e.id),label:e.type,subtitle:"[".concat(e.range[0],", ").concat(e.range[e.range.length-1],"]")},children:(0,s.jsx)(eL,{isEditing:!0,ranges:m,kpiId:e.id})},e.id)),!N&&(0,s.jsx)(H.Footer,{children:(0,s.jsx)(H.FooterContent,{children:(0,s.jsx)(eL,{kpiId:(null==c?void 0:c.id)||0})})})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{className:"mb-2 block text-sm text-white/70",children:[b("monitoring-observations:censuses.labReport.kpiSection.value"),":"]}),(0,s.jsx)(F,{disabled:!(null==c?void 0:c.id)||!(null==u?void 0:u.id),showError:!1,placeholder:u?"[".concat(null==u?void 0:u.range[0],", ").concat(null==u?void 0:u.range[(null==u?void 0:u.range.length)-1],"]"):b("monitoring-observations:censuses.labReport.kpiSection.enterValue"),name:"kpi-value"})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("span",{className:"mb-1 block text-sm text-white/70",children:[b("monitoring-observations:censuses.labReport.kpiSection.unit"),":"]}),(0,s.jsx)("span",{className:"text-light-mode-black-500",children:null==c?void 0:c.unit})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("span",{className:"mb-1 block text-sm text-white/70",children:[b("monitoring-observations:censuses.labReport.kpiSection.result"),":"]}),x&&(0,s.jsx)("div",{className:"inline-flex",children:(0,s.jsx)("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg",style:{backgroundColor:h.bg},children:(0,s.jsx)("span",{style:{color:h.text},className:"text-center text-lg font-semibold",children:h.value})})})]})]})]})]},"card-custom-".concat(t)))]})})},eB=en.z.object({"select-kpis":en.z.string().min(1),range:en.z.string().min(1),"kpi-value":en.z.string().min(1)}),eP=e=>{let t={};
1return(null==e?void 0:e.length)&&e.forEach(e=>{t["range_".concat(e.type)]=en.z.string().optional()}),eB.extend({"kpi-value":en.z.string().min(1).refine(e=>!isNaN(Number(e)))}).superRefine((t,a)=>{let s=null==e?void 0:e.find(e=>e.type===t.range);if(!(null==s?void 0:s.range.length))return;let i=s.range.map(Number),n=Number(t["kpi-value"]),l=Math.min(...i),r=Math.max(...i);(n<l||n>r)&&a.addIssue({code:en.z.ZodIssueCode.custom,path:["kpi-value"]})})},eU=e=>{var t,a,i,n,l;let{selectedRow:r,rows:o,showKpis:d,filesWithExtractionProcess:c,rowsWithUserInteraction:m,completedGenerations:u,isGeneratingProgressLoading:h,statusLogs:b,setRowsWithUserInteraction:v}=e,{t:f}=(0,y.A)("monitoring"),{query:N,locale:k="it"}=(0,w.useRouter)(),S=N.slug,I=Number(N.id),A=(0,j.useSession)(),{toast:R}=ee.dj(),T=(0,z.jE)(),{isAdmin:E,canEditSite:L}=(0,x.A)(),[F,{close:O,toggle:B}]=(0,ej.A)(!1),{assignLetterFromRange:P,tableHeader:U}=eR({selectedRow:r,locale:k}),[H,q]=(0,_.useState)([]),[V,W]=(0,_.useState)(!1),[$,Q]=(0,_.useState)(()=>eP()),G=(0,_.useRef)(null),K=(0,_.useRef)(null),Z=H.length>0,J=E||L,X=(0,D.mN)({mode:"onChange",reValidateMode:"onChange",resolver:(0,Y.u)($)}),{reset:et,watch:ea,setValue:es,formState:{errors:ei}}=X,en=(null==c?void 0:c.some(e=>{var t;
1return e.file_id===(null==r?void 0:r.id)&&(null==b||null==(t=b.data)?void 0:t.some(t=>t.id===e.measures_extraction_log_id))&&!(null==u?void 0:u.some(t=>t.id===e.measures_extraction_log_id))}))||!1,el=null==c?void 0:c.find(e=>e.file_id===(null==r?void 0:r.id)&&(null==u?void 0:u.some(t=>t.id===e.measures_extraction_log_id))),er=null==u?void 0:u.find(e=>e.id===(null==el?void 0:el.measures_extraction_log_id)),eo=!!el,ed=null==er||null==(t=er.messages.find(e=>"completed"===e.status))?void 0:t.message,ec=null==ed?void 0:ed.match(/\d+/),em=ec?parseInt(ec[0]):null,{mutateAsync:eu}=(0,p.Yhe)({mutation:{onSuccess:async()=>{q([]),es("kpi-value",""),et(),T.invalidateQueries({queryKey:[(0,p.wnM)(S,I,(null==r?void 0:r.id)||0)]}),v(e=>new Set([...e,r.id]))}}}),{mutateAsync:ex,isLoading:eh}=(0,p.k7c)({mutation:{onSuccess:async()=>{R({variant:"success",description:f("monitoring-observations:censuses.labReport.kpiSection.deleteKpiSuccess")}),T.invalidateQueries({queryKey:[(0,p.wnM)(S,I,(null==r?void 0:r.id)||0)]}),es("kpi-value",""),et()},onError:()=>{R({variant:"error",description:f("monitoring-observations:censuses.labReport.kpiSection.deleteKpiError")})}}}),{data:eg,isLoading:ep}=(0,p.U$z)(S,I,(null==r?void 0:r.id)||0,{authorization:"Bearer ".concat(null==A||null==(a=A.data)?void 0:a.accessToken)},{query:{queryKey:[(0,p.wnM)(S,I,(null==r?void 0:r.id)||0),c]}}),{data:eb}=(0,p.WlC)(),ev=ea("select-kpis"),ef=null==eb?void 0:eb.find(e=>e.name===ev),{data:ew}=(0,p.Lel)((null==ef?void 0:ef.id)||0,{},{authorization:"Bearer ".concat(null==A||null==(i=A.data)?void 0:i.accessToken)}),eN=ea("range"),ek=null==ew?void 0:ew.find(e=>e.type===eN),e_=ea("kpi-value"),eC=!isNaN(Number(e_))&&""!==e_,eS=P(null!=(n=null==ek?void 0:ek.range)?n:[],Number(ea("kpi-value")),null!=(l=null==ek?void 0:ek.direction)?l:"ASC"),eI=!!ea("kpi-value")&&!!ea("select-kpis")&&!ei["kpi-value"],ez=m.has((null==r?void 0:r.id)||0),eD=0===em&&!(null==eg?void 0:eg.length)&&!en&&!ez,eM=!(null==eg?void 0:eg.length)&&!Z&&!eD;(0,_.useEffect)(()=>{Q(eP(ew))},[ew]),(0,_.useLayoutEffect)(()=>{if(V){let e=G.current;e&&(e.scrollTop=e.scrollHeight);let t=K.current;t&&(t.scrollTop=t.scrollHeight),W(!1)}},[H,V]),(0,_.useEffect)(()=>{et(),q([])},[et,r]);let eT=async()=>{var e;await eu({siteId:I,userSlug:S,labReportId:r.id,data:{kpi_id:(null==ef?void 0:ef.id)||0,measure_value:String(e_),range_id:(null==ek?void 0:ek.id)||0},headers:{authorization:"Bearer ".concat(null==A||null==(e=A.data)?void 0:e.accessToken)}})},eE=async e=>{var t;await ex({siteId:I,userSlug:S,labReportId:r.id,measureId:e,headers:{authorization:"Bearer ".concat(null==A||null==(t=A.data)?void 0:t.accessToken)}})};return o&&r?ep?(0,s.jsx)(M.A,{count:5,className:"h-full w-full"}):h||en&&!eo?(0,s.jsxs)("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-center text-dark-mode-blue-900",children:[(0,s.jsx)("div",{className:"flex items-center gap-3",children:(0,s.jsx)(g.In,{icon:"eos-icons:loading",width:50,height:50,className:"block shrink-0",color:"white"})}),(0,s.jsx)("p",{className:"text-dark-mode-blue-900",children:f("monitoring-observations:censuses.labReport.kpiSection.extractionProgressMessage")})]}):(0,s.jsx)(s.Fragment,{children:d?(0,s.jsx)(eA,{labReportId:r.id}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(s.Fragment,{children:(null==eg?void 0:eg.length)||H.length?(0,s.jsxs)(D.Op,{...X,children:[(0,s.jsx)(eF,{desktopTableRef:G,measures:eg,handleDeleteMeasure:eE,isAdminOrCanEditSite:J,assignLetterFromRange:P,customRows:H,setCustomRows:q,kpis:eb,kpiSelected:ef,ranges:ew,rangeSelected:ek,hasKpiAndValue:eI,letterValue:eS,tableHeader:U,isDeleting:eh}),(0,s.jsx)(eO,{mobileCardsRef:K,measures:eg,handleDeleteMeasure:eE,isAdminOrCanEditSite:J,assignLetterFromRange:P,customRows:H,setCustomRows:q,kpis:eb,kpiSelected:ef,ranges:ew,rangeSelected:ek,hasKpiAndValue:eI,letterValue:eS,isDeleting:eh})]}):eD?(0,s.jsxs)("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-center text-dark-mode-blue-900",children:[(0,s.jsx)("p",{children:f("monitoring-observations:censuses.labReport.kpiSection.extractionErrorMessage")}),(0,s.jsx)("button",{onClick:B,children:(0,s.jsx)("span",{className:"text-dark-mode-blue-900 underline",children:f("common:common.contactUs")})}),(0,s.jsx)(ey._,{close:O,open:F})]}):eM?(0,s.jsx)("p",{className:"text-center text-dark-mode-blue-900",children:f("monitoring-observations:censuses.labReport.kpiSection.noKpiAvailable".concat(J?"Admin":"User"))}):null}),!!ei["kpi-value"]&&(0,s.jsx)("span",{className:"mt-2 text-red-500",children:eC?f("monitoring-observations:censuses.labReport.kpiSection.outOfRange"):f("monitoring-observations:censuses.labReport.kpiSection.invalidValue")}),J&&(0,s.jsx)("div",{className:"mt-4 flex gap-4",children:Z?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(C.$,{type:"button",variant:"secondary",onClick:()=>{et(),es("kpi-value","")},className:"text-white",children:f("monitoring-observations:censuses.labReport.kpiSection.reset")}),(0,s.jsx)(C.$,{type:"button",variant:"teal",disabled:!!ei["kpi-value"]||!(null==ek?void 0:ek.id)||!(null==ef?void 0:ef.id)||!e_,onClick:()=>{eT()},children:(0,s.jsx)("span",{className:"text-white",children:f("common:save")})})]}):(0,s.jsx)(C.$,{type:"button",variant:"teal",onClick:()=>{q([{kpi:""}]),W(!0)},className:"mt-3 text-white",children:(0,s.jsxs)("div",{className:"flex items-center justify-center gap-1",children:[(0,s.jsx)(g.In,{icon:"mdi-plus",width:20,height:20,className:"shrink-0"}),(0,s.jsx)("span",{children:f("common:common.add")})]})})})]})}):null},eH=ev()(()=>Promise.all([a.e(97035),a.e(89118),a.e(48753),a.e(55016),a.e(71048)]
1).then(a.bind(a,71048)),{loadableGenerated:{webpack:()=>[71048]},ssr:!1}),eq={hidden:{opacity:0},visible:{opacity:1,transition:{duration:.25,ease:"easeOut"}},exit:{opacity:0,transition:{duration:.2,ease:"easeIn"}}},eV=e=>{let{selectedRow:t,rows:a,setSelectedRow:i,selectedIndex:l,filesWithExtractionProcess:r,setFilesWithExtractionProcess:o,isGeneratingProgressLoading:d,generatingLogsInProgress:m,startedGenerating:u,completedGenerations:x,statusLogs:h,setRowsWithUserInteraction:p,rowsWithUserInteraction:b}=e,{t:v}=(0,y.A)("monitoring"),{locale:f="it"}=(0,w.useRouter)(),j=(0,c.r)(),{badges:N}=eR({selectedRow:t,locale:f}),[k,C]=(0,_.useState)(!1),[S,I]=(0,_.useState)(!0);return a&&t?(0,s.jsxs)(ep.P.div,{variants:eq,initial:"hidden",animate:"visible",exit:"exit",className:"absolute inset-0 z-50 flex h-full w-full flex-col overflow-hidden bg-dark-mode-blue-300 px-4",children:[(0,s.jsxs)("div",{className:"mb-6 flex flex-col gap-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-end",children:[(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,s.jsx)("button",{onClick:()=>l>0&&i(a[l-1]),disabled:0===l,className:"text-white disabled:opacity-30",children:(0,s.jsx)(g.In,{icon:"material-symbols:keyboard-arrow-up-rounded",width:32,height:32})}),(0,s.jsx)("button",{onClick:()=>l<a.length-1&&i(a[l+1]),disabled:l===a.length-1,className:"text-white disabled:opacity-30",children:(0,s.jsx)(g.In,{icon:"material-symbols:keyboard-arrow-down-rounded",width:32,height:32})})]}),(0,s.jsx)(ei.H,{orientation:"vertical",decorative:!0,className:"mx-1 bg-dark-mode-blue-600(base)"}),(0,s.jsx)("button",{onClick:()=>i(null),className:"text-white disabled:opacity-30",title:"Successivo",children:(0,s.jsx)(g.In,{icon:"material-symbols:close-small-rounded",width:32,height:32})})]}),(0,s.jsx)(n.T,{variant:"dark"===j?"dark-mode-blue-1100":"dark-mode-blue-400",value:k?"kpi":"titleNote",onCh
1ange:e=>C("kpi"===e),options:[{value:"kpi",label:"KPI"},{value:"titleNote",label:v("monitoring-observations:censuses.labReport.kpiNote.titleNote",{count:2})}]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("div",{className:"my-2 flex flex-wrap gap-3",children:N.map(e=>(0,s.jsx)(ef.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"border-dark-mode-blue-1100 !bg-transparent",children:e.value},e.id))}),(0,s.jsxs)("button",{className:"hidden items-center gap-2 font-medium text-white transition-opacity hover:opacity-80 xl:flex",onClick:()=>I(e=>!e),children:[(0,s.jsx)(g.In,{icon:S?"material-symbols:chevron-right-rounded":"material-symbols:chevron-left-rounded",width:24,height:24}),(0,s.jsx)("p",{children:v(S?"monitoring-observations:censuses.labReport.rowDetail.closeAnalysis":"monitoring-observations:censuses.labReport.rowDetail.openAnalysis")})]})]})]}),(0,s.jsxs)("div",{className:"flex flex-1 flex-col gap-6 overflow-y-auto xl:flex-row xl:overflow-y-hidden xl:scrollbar-hide",children:[(0,s.jsx)(ep.P.div,{className:"flex flex-1 flex-col",transition:{duration:.3},children:(0,s.jsx)(eU,{filesWithExtractionProcess:r,setFilesWithExtractionProcess:o,selectedRow:t,rows:a,showKpis:k,rowsWithUserInteraction:b,setRowsWithUserInteraction:p,isGeneratingProgressLoading:d,generatingLogsInProgress:m,startedGenerating:u,completedGenerations:x,statusLogs:h})}),S&&t&&(0,s.jsx)(ep.P.div,{className:"flex min-h-svh justify-center scrollbar-hide xl:min-h-0 xl:overflow-y-auto",initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},children:(0,s.jsx)("div",{className:"flex xl:overflow-y-auto",children:(0,s.jsx)(eH,{pdfUrl:t.s3_file_url})})})]})]}):null};function eW(){let{t:e}=(0,y.A)("monitoring"),{query:t}=(0,w.useRouter)(),a=t.slug,i=Number(t.id),{isAdmin:n,canEditSite:l}=(0,x.A)(),r=(0,z.jE)(),[o,d]=(0,_.useState)({page:1,pages:1}),[c,m]=(0,_.useState)({fileName:null,userName:null,date:null}),[u,h]=(0,_.useState)(null),[g,b]=(0,_.useState)([]),[v,f]=(0,_.useState)(new Set),{data:j,isLoading:N}=(0,p.s3s)(a,i),{isGeneratingProgressLoading:k,generatingLogsInProgress:C,startedGenerating:T,setStartedGenerating:E,statusLogs:F,completedGenerations:O}=(0,A.u)({category:"lab_report_measures_extraction",onRefetchEnded:()=>r.invalidateQueries({queryKey:[(0,p.wnM)(a,i,(null==u?void 0:u.id)||0)]})}),B=(0,D.mN)(),{watch:P}=B,{PAGE_SIZE:U,paginatedFiles:H}=(e=>{let{reportFiles:t,searchTerm:a,tableColumnsSort:s,tablePagination:i}=e,n=(0,_.useMemo)(()=>{if(!(null==t?void 0:t.files))return[];if(!a)return t.files;let e=a.toLowerCase();return t.files.filter(t=>{var a;return t.file_name.toLowerCase().includes(e)||(null!=(a=t.uploader_full_name)?a:"").toLowerCase().includes(e)})},[null==t?void 0:t.files,a]),l=(0,_.useMemo)(()=>{if(!n.length)return[];let e=Object.entries(s).find(e=>{let[,t]=e;return null!==t});if(!e)return n;let[t,a]=e,i="asc"===a?1:-1,l={fileName:e=>e.file_name.toLowerCase(),userName:e=>{var t;return(null!=(t=e.uploader_full_name)?t:"").toLowerCase()},date:e=>new Date(e.acquisition_date).getTime()}[t];return l?[...n].sort((e,t)=>{let a=l(e),s=l(t);return(a>s?1:a<s?-1:0)*i}):n},[n,s]);return{paginatedFiles:(0,_.useMemo)(()=>l.slice((i.page-1)*6,6*i.page),[l,i.page]),PAGE_SIZE:6}})({reportFiles:j,searchTerm:P("search"),tableColumnsSort:c,tablePagination:o});(0,_.useEffect)(()=>{(null==j?void 0:j.files)&&d(e=>({...e,pages:Math.ceil(j.files.length/U)}))},[U,null==j?void 0:j.files]);let q=u?null==j?void 0:j.files.findIndex(e=>e.id===u.id):-1,V=String(P("search")).length>0&&!H.length,W=n||l;return N?(0,s.jsx)(M.A,{count:5,className:"h-25 w-full"}):(0,s.jsxs)("section",{className:"relative mb-10 min-h-[70svh] overflow-y-auto md:px-0",children:[(0,s.jsxs)("div",{className:"flex max-w-full flex-col justify-between gap-5 py-10 lg:flex-row",children:[(0,s.jsx)("div",{className:"lg:w-1/3",children:(0,s.jsx)("p",{className:"text-white",children:e("monitoring-observations:censuses.labReport.labAnalysisTabInfo")})}),(0,s.jsxs)("div",{className:"flex flex-col-reverse gap-4 sm:flex-row sm:items-center sm:justify-center sm:gap-10",children:[(0,s.jsx)(D.Op,{...B,children:(0,s.jsx)("form",{className:"w-full p-1 sm:w-auto",children:!!(null==j?void 0:j.files.length)&&(0,s.jsx)(L,{name:"search"})})}),W&&(0,s.jsx)(ec,{setStartedGenerating:E,setFilesWithExtractionProcess:b})]})]}),V?(0,s.jsx)("p",{className:"text-center text-dark-mode-blue-900",children:e("monitoring-observations:censuses.labReport.noResultsLabAnalysis")}):(null==j?void 0:j.files.length)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(S.bL,{tableClassName:"border-separate border-spacing-y-3",children:[(0,s.jsx)(S.Y9,{tableColumnsSort:c,setTableColumnsSort:m,tableColumnsLabels:{fileName:e("monitoring-observations:censuses.labReport.tableHeader.fileName"),userName:e("monitoring-observations:censuses.labReport.tableHeader.userName"),date:e("monitoring-observations:censuses.labReport.tableHeader.date"),...W&&{delete:e("common:common.delete")}}}),(0,s.jsx)(S.nB,{className:"[&>tr>td]:border-dark-mode-blue-600(base) [&>tr>td]:py-5 [&>tr>td]:align-middle",children:H.map(e=>(0,s.jsx)(eg,{row:e,onRowClick:h,isAdminOrCanEditSite:W},e.id))}),(0,s.jsx)(I.O,{tablePagination:o,setTablePagination:d})]}),(0,s.jsx)(R.N,{children:u&&(0,s.jsx)(eV,{selectedIndex:q||0,rows:null==j?void 0:j.files,selectedRow:u,setSelectedRow:h,filesWithExtractionProcess:g,setFilesWithExtractionProcess:b,isGeneratingProgressLoading:k,generatingLogsInProgress:C,startedGenerating:T,statusLogs:F,completedGenerations:O,setRowsWithUserInteraction:f,rowsWithUserInteraction:v})})]}):(0,s.jsx)("p",{className:"text-center text-dark-mode-blue-900",children:e("monitoring-observations:censuses.labReport.emptyState".concat(W?"Admin":"User"))})]})}var e$=a(50994),eQ=a(75761),eG=a(18508),eK=a(99101),eZ=a(13416),eJ=a(40488),eY=a(71152),eX=a(58575),e0=a(36159),e1=a(78646);let e2=()=>{let{t:e}=(0,y.A)("monitoring"),t=(0,c.r)(),{selectedObservation:a,setSelectedObservation:i,selectedMultiObservations:n,setSelectedMultiObservations:l,event:o}=(0,r._R)(),{isLoading:d,data:m={pages:[],pageParams:[],obs:[]},refetch:u,isFetching:x,hasNextPage:h,fetchNextPage:p}=(0,e$.x)(),{observe:b,inView:v}=(0,eK.W)({threshold:.3}),f=(0,_.useRef)(null);return((0,_.useEffect)(()=>{o&&o.observations.every(e=>n.some(t=>t.id===e.id))&&u()},[o,n,u]),(0,_.useEffect)(()=>{v&&h&&!x&&p()},[v,h,x,p]),d)?(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsx)(M.A,{width:"100%",height:220}),(0,s.jsxs)("div",{className:"flex w-full gap-10",children:[(0,s.jsx)(M.A,{containerClassName:"flex-1",height:400}),(0,s.jsx)(M.A,{containerClassName:"flex-[0.5]",height:400})]})]}):0===m.obs.length?(0,s.jsx)("span",{className:"text-lg ".concat("light"===t?"text-black":"text-white"),children:e("common.noData")}):(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsx)("p",{children:(0,s.jsx)(eG.A,{text:e("monitoring-observations:censuses.gridViewDescription"),components:{bold:(0,s.jsx)("b",{}),br:(0,s.jsx)("br",{})}})}),(0,s.jsxs)("div",{className:"flex max-md:flex-col [&>div]:md:w-1/2",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("label",{className:"flex cursor-pointer items-center gap-2",children:[(0,s.jsx)(eZ.bL,{variant:"monitoring-600(base)",className:"rounded-sm",checked:n.length===m.obs.length,onCheckedChange:e=>{e?l(m.obs):l([])},children:(0,s.jsx)(eZ.sc,{})}),(0,s.jsxs)("span",{className:"font-bold text-dark-mode-monitoring-600(base)",children:[e("common:common.selection.selectAll")," ",n.length>0&&"(".concat(n.length,")")]})]}),(0,s.jsx)(eY.Q,{})]}),(0,s.jsx)("div",{className:"grid max-h-120 grid-cols-[repeat(auto-fit,minmax(100px,1fr))] gap-3 overflow-y-auto pr-4 ".concat("light"===t?"custom-scrollbar-light-mode-blue":"custom-scrollbar-dark-mode-blue-300"),ref:f,children:m.obs.map((r,d)=>{var c,u,x,h,p,v,f,j,y,w,N,k,_,C,S,I,A;let z=(null==a?void 0:a.id)===r.id,R=n.find(e=>e.id===r.id),D=null==o?void 0:o.observations.some(e=>e.id===r.id);return(0,s.jsxs)(eJ.bL,{id:r.id,ref:d===m.obs.length-3?b:void 0,role:"button",className:(0,E.cn)("relative h-max cursor-pointer rounded-[15p
1x]",z&&"border-2 border-dark-mode-monitoring-600(base)",D&&"cursor-not-allowed"),onClick:()=>{D||i(r)},children:[(0,s.jsx)("div",{className:"pointer-events-none absolute right-[14px] top-[14px] z-40 flex items-center gap-1",children:(0,s.jsx)(e1.U,{geoClass:r.geo_class,geoReason:r.geo_reason,geoDistanceKm:r.geo_distance_km,variant:t,compact:!0})}),(0,s.jsxs)(eJ.nB,{className:"relative h-full w-full overflow-hidden !p-[10px]",children:[D&&(0,s.jsx)("div",{className:"absolute left-0 top-0 z-50 flex h-full w-full items-center justify-center rounded-[inherit] bg-black/80",children:(0,s.jsx)(g.In,{icon:"eos-icons:loading",width:40,height:40})}),(0,s.jsx)("div",{className:"absolute inset-0 z-10 h-full w-full rounded-[inherit] bg-[rgba(9,32,43,0.5)] backdrop-blur-md"}),(0,s.jsx)(eC(),{src:null!=(w=null==(c=r.taxa)?void 0:c.url)?w:eQ.A.src,alt:null!=(k=null!=(N=null==(u=r.taxa)?void 0:u.taxa)?N:null==(x=r.taxa)?void 0:x.latin_taxa)?k:e("monitoring-observations:noTaxa"),unoptimized:!0,fill:!0}),(0,s.jsxs)("div",{className:"relative z-20 mx-auto h-[65px] w-full overflow-hidden rounded-[5px]",children:[(0,s.jsx)(eC(),{src:null!=(_=null==(h=r.taxa)?void 0:h.url)?_:eQ.A.src,fill:!0,className:"object-cover",alt:null!=(S=null!=(C=null==(p=r.taxa)?void 0:p.taxa)?C:null==(v=r.taxa)?void 0:v.latin_taxa)?S:e("monitoring-observations:noTaxa")}),(0,s.jsx)(eZ.bL,{variant:"monitoring-600(base)",className:"absolute inset-1 rounded-sm",onClick:e=>e.stopPropagation(),checked:!!R,onCheckedChange:e=>{e?l(e=>[...e,r]):l(e=>e.filter(e=>e.id!==r.id))},children:(0,s.jsx)(eZ.sc,{})})]}),(0,s.jsxs)("div",{className:"relative z-20 mt-3 flex flex-col justify-between gap-1 ".concat("light"===t?"text-black":"text-white"),children:[(0,s.jsx)("span",{className:"max-w-full truncate whitespace-normal text-center text-base font-bold",children:null!=(A=null!=(I=null==(f=r.taxa)?void 0:f.taxa)?I:null==(j=r.taxa)?void 0:j.latin_taxa)?A:e("monitoring-observations:noTaxa")}),(null==(y=r.taxa)?void 0:y.probability)&&(0,s.jsx)("span",{className:"bg-gradient-yellow-pink-cyan-green bg-clip-text text-center text-sm font-bold text-transparent",children:e("monitoring-observations:censuses.probability",{probability:r.taxa.probability})})]})]})]},r.id)})})]}),(0,s.jsx)("div",{className:"max-md:my-10 max-md:h-px md:mx-10 md:!w-px ".concat("light"===t?"bg-light-mode-black-200":"bg-dark-mode-blue-1000")}),(0,s.jsx)(eX.C,{},null==a?void 0:a.id)]}),(0,s.jsx)(e0.T,{predictionSelected:null})]})};var e5=a(22038),e4=a(85164);let e3=e=>{let{label:t,placeholder:a,data:i,isLoading:n,selectedValue:l,onSelect:r,disabled:o=!1}=e,{t:d}=(0,y.A)("monitoring"),m=(0,c.r)(),[u,x]=(0,_.useState)(!1),[h,p]=(0,_.useState)(""),b=(0,_.useMemo)(()=>i.filter(e=>e.name.toLowerCase().includes(h.toLowerCase())),[i,h]);return(0,s.jsxs)(e4.bL,{open:u,onOpenChange:x,children:[(0,s.jsx)(e4.ty,{asChild:!0,disabled:o,children:(0,s.jsxs)("button",{type:"button",className:(0,E.cn)("inline-flex items-center gap-2 rounded-full px-3 py-1.5 text-sm transition-colors","light"===m?"border border-light-mode-black-200 bg-light-mode-black-100 backdrop-blur-sm":"border border-dark-mode-blue-600(base) bg-dark-mode-blue-400/50 backdrop-blur-sm","light"===m?"hover:bg-light-mode-black-200/50":"hover:bg-dark-mode-blue-500/50",l&&"border-dark-mode-monitoring-600(base) bg-dark-mode-monitoring-600(base)/20",o&&"cursor-not-allowed opacity-50"),children:[(0,s.jsx)("span",{className:"light"===m?"text-black":"text-white",children:l?l.name:t}),l?(0,s.jsx)("span",{role:"button",tabIndex:0,onPointerDown:e=>{e.preventDefault(),e.stopPropagation(),x(!1),r(null)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),e.stopPropagation(),x(!1),r(null))},className:"rounded-full p-0.5 hover:bg-white/10",children:(0,s.jsx)(g.In,{icon:"material-symbols:close",width:14,height:14,className:"light"===m?"text-black":"text-white"})}):(0,s.jsx)(g.In,{icon:"material-symbols:keyboard-arrow-down-rounded",width:18,height:18,className:"light"===m?"text-black":"text-white"})]})}),(0,s.jsxs)(e4.SQ,{variant:"light"===m?"default":"dark-mode-blue-300",className:"z-[123456] max-h-64 min-w-[200px] overflow-hidden",align:"start",sideOffset:4,children:[(0,s.jsx)("div",{className:"border-b p-2 ".concat("light"===m?"border-light-mode-black-200":"border-dark-mode-blue-600(base)"),children:(0,s.jsx)("input",{type:"text",value:h,onChange:e=>p(e.target.value),placeholder:a,className:"w-full rounded-md px-3 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-dark-mode-monitoring-600(base) ".concat("light"===m?"bg-light-mode-black-100 text-black placeholder:text-light-mode-black-400":"bg-dark-mode-blue-400 text-white placeholder:text-dark-mode-blue-600(base)")})}),(0,s.jsx)("div",{className:"max-h-48 overflow-y-auto p-1 ".concat("light"===m?"custom-scrollbar-light-mode-blue":"custom-scrollbar-dark-mode-blue-300"),children:n?(0,s.jsx)("div",{className:"flex items-center justify-center py-4",children:(0,s.jsx)(g.In,{icon:"eos-icons:loading",className:"h-5 w-5 ".concat("light"===m?"text-black":"text-white")})}):0===b.length?(0,s.jsx)("div",{className:"px-3 py-2 text-center text-sm ".concat("light"===m?"text-light-mode-black-400":"text-dark-mode-blue-600(base)"),children:d("common.noResults")}):b.map(e=>(0,s.jsx)(e4._2,{variant:"light"===m?"default":"dark-mode-blue-300",onSelect:()=>{r(e),x(!1),p("")},className:(0,E.cn)("cursor-pointer rounded-md",(null==l?void 0:l.id)===e.id&&"bg-dark-mode-monitoring-600(base)/20"),children:e.name},e.id))})]})]})},e6=e=>{var t;let{className:a}=e,{t:i}=(0,y.A)("monitoring"),n=(0,c.r)(),{locale:l="it",query:o}
1=(0,w.useRouter)(),d=(0,j.useSession)(),m=o.slug,u=Number(o.id),{filterSpecies:x,setFilterSpecies:h,filterOrder:g,setFilterOrder:b,filterFamily:v,setFilterFamily:f,filterGenre:N,setFilterGenre:k,clearChildFiltersFromIconicTaxa:C,clearChildFiltersFromOrder:S,clearChildFiltersFromFamily:I,clearChildFiltersFromGenus:A}=(0,r._R)(),{orderCascadeParams:z,familyCascadeParams:R,genusCascadeParams:D}=(0,e5.m)(),M=(0,_.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==d||null==(e=d.data)?void 0:e.accessToken),"accept-language":l}},[null==d||null==(t=d.data)?void 0:t.accessToken,l]),T=!!(m&&!Number.isNaN(u)),{data:L=[],isLoading:F}=(0,p.SCi)(m,u,{exclude_taxa:r.Wg},M,{query:{retry:!1,enabled:T}}),{data:O=[],isLoading:B}=(0,p.Zd0)(m,u,z,M,{query:{retry:!1,enabled:T&&x.size>0}}),{data:P=[],isLoading:U}=(0,p.PdZ)(m,u,R,M,{query:{retry:!1,enabled:T&&g.size>0}}),{data:H=[],isLoading:q}=(0,p.BOS)(m,u,D,M,{query:{retry:!1,enabled:T&&v.size>0}}),V=(0,_.useMemo)(()=>{if(0===x.size)return null;let[e,t]=Array.from(x.entries())[0];return{id:e,name:t.name}},[x]),W=(0,_.useMemo)(()=>{if(0===g.size)return null;let[e,t]=Array.from(g.entries())[0];return{id:e,name:t.name}},[g]),$=(0,_.useMemo)(()=>{if(0===v.size)return null;let[e,t]=Array.from(v.entries())[0];return{id:e,name:t.name}},[v]),Q=(0,_.useMemo)(()=>{if(0===N.size)return null;let[e,t]=Array.from(N.entries())[0];return{id:e,name:t.name}},[N]),G=(0,_.useCallback)(e=>{e?h(new Map([[e.id,{name:e.name}]])):h(new Map),C()},[h,C]),K=(0,_.useCallback)(e=>{e?b(new Map([[e.id,{name:e.name}]])):b(new Map),S()},[b,S]),Z=(0,_.useCallback)(e=>{e?f(new Map([[e.id,{name:e.name}]])):f(new Map),I()},[f,I]),J=(0,_.useCallback)(e=>{e?k(new Map([[e.id,{name:e.name}]])):k(new Map),A()},[k,A]),Y=x.size>0||g.size>0||v.size>0||N.size>0,X=(0,_.useCallback)(()=>{h(new Map),b(new Map),f(new Map),k(new Map)},[h,b,f,k]);return(0,s.jsxs)("div",{className:(0,E.cn)("flex flex-wrap items-center gap-2",a),children:[(0,s.jsx)(e3,{label:i("monitoring-observations:hierarchy.filters.iconicTaxa"),placeholder:i("monitoring-observations:hierarchy.filters.selectIconicTaxa"),data:L,isLoading:F,selectedValue:V,onSelect:G}),(0,s.jsx)(e3,{label:i("monitoring-observations:hierarchy.filters.order"),placeholder:i("monitoring-observations:hierarchy.filters.selectOrder"),data:O,isLoading:B,selectedValue:W,onSelect:K,disabled:0===x.size}),(0,s.jsx)(e3,{label:i("monitoring-observations:hierarchy.filters.family"),placeholder:i("monitoring-observations:hierarchy.filters.selectFamily"),data:P,isLoading:U,selectedValue:$,onSelect:Z,disabled:0===g.size}),(0,s.jsx)(e3,{label:i("monitoring-observations:hierarchy.filters.genus"),placeholder:i("monitoring-observations:hierarchy.filters.selectGenus"),data:H,isLoading:q,selectedValue:Q,onSelect:J,disabled:0===v.size}),Y&&(0,s.jsx)("button",{type:"button",onClick:X,className:"inline-flex items-center gap-1 rounded-full px-3 py-1.5 text-sm transition-colors ".concat("light"===n?"text-black/70 hover:text-black":"text-white/70 hover:text-white"),children:i("monitoring-observations:hierarchy.filters.resetAll")})]})};var e9=a(4141);let e8=e=>{let{taxa:t,imageUrl:a,cardinality:i,isAlien:n,isEndemic:l,isSelected:r,onClick:o}=e,{t:d}=(0,y.A)("monitoring"),m=(0,c.r)();return(0,s.jsx)(eJ.bL,{role:"button",onClick:o,className:(0,E.cn)("h-max cursor-pointer rounded-[15px] transition-all",r&&"ring-2 ring-dark-mode-monitoring-600(base) ring-offset-2 ".concat("light"===m?"ring-offset-white":"ring-offset-dark-mode-blue-200")),children:(0,s.jsxs)(eJ.nB,{className:"relative h-full w-full overflow-hidden !p-[10px]",children:[(0,s.jsx)("div",{className:"absolute inset-0 z-10 h-full w-full rounded-[inherit] bg-[rgba(9,32,43,0.5)] backdrop-blur-md"}),(0,s.jsxs)("div",{className:"pointer-events-none absolute right-[14px] top-[14px] z-30 flex flex-col gap-1",children:[n&&(0,s.jsx)(ef.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"w-max text-xs",children:d("monitoring-observations:statistics.alien")}),l&&(0,s.jsx)(ef.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"w-max text-xs",children:d("monitoring-observations:statistics.endemic")})]}),(0,s.jsx)(eC(),{src:null!=a?a:eQ.A.src,alt:t,unoptimized:!0,fill:!0}),(0,s.jsx)("div",{className:"relative z-20 mx-auto h-[65px] w-full overflow-hidden rounded-[5px]",children:(0,s.jsx)(eC(),{src:null!=a?a:eQ.A.src,fill:!0,className:"object-cover",alt:t})}),(0,s.jsxs)("div",{className:"relative z-20 mt-3 flex flex-col justify-between gap-1 ".concat("light"===m?"text-black":"text-white"),children:[(0,s.jsx)("span",{className:"max-w-full truncate whitespace-normal text-center text-base font-bold",children:t}),(0,s.jsxs)("span",{className:"text-center text-sm ".concat("light"===m?"text-light-mode-black-500":"text-dark-mode-monitoring-600(base)"),children:[i," ",d("monitoring-observations:hierarchy.species.observations")]})]})]})})}
1,e7=e=>{var t;let{className:a}=e,{t:i}=(0,y.A)("monitoring"),n=(0,c.r)(),{locale:l="it",query:o}=(0,w.useRouter)(),d=(0,j.useSession)(),m=o.slug,u=Number(o.id),{polygonVersion:x,area:h,polygons:g,device:v,filterDate:f,filterSpecies:N,filterSubSpecies:k,filterFamily:C,filterGenre:S,filterOrder:I,filterIndex:A,minimumConfidenceValue:z,generateQueryKey:R,selectedSpecies:D,setSelectedSpecies:T}=(0,r._R)(),L=(0,_.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==d||null==(e=d.data)?void 0:e.accessToken),"accept-language":l}},[null==d||null==(t=d.data)?void 0:t.accessToken,l]),{isLoading:F,data:O=[]}=(0,p.j29)(m,u,{...x&&{polygon_id:x.id},...g.length>0&&{subpolygon_idx:g.map(e=>e.id).join(",")},...h&&{trancept_ids:h.id.toString()},...v&&{hive_ids:v.id.toString()},...f.from&&{date_from:(0,b.default)(f.from,"yyyy-MM-dd")},...f.to&&{date_to:(0,b.default)(f.to,"yyyy-MM-dd")},...N.size>0&&{iconic_taxa:Array.from(N.keys()).join(",")},...k.size>0&&{taxa:Array.from(k.keys()).join(",")},...C.size>0&&{family_taxa:Array.from(C.keys()).join(",")},...S.size>0&&{genus_taxa:Array.from(S.keys()).join(",")},...I.size>0&&{order_taxa:Array.from(I.keys()).join(",")},...A&&{index_id:A.id},...z&&{min_confidence:z},exclude_taxa:r.Wg},L,{query:{queryKey:R(m,u,"observations_statistics_grid"),retry:!1}}),B=(0,_.useMemo)(()=>F?[]:O.filter(e=>null!==e.taxon_id||null!==e.taxa||null!==e.iconic_taxa||null!==e.iconic_taxa_id||null!==e.image_url),[O,F]);return(0,s.jsxs)("div",{className:(0,E.cn)("grid max-h-[600px] grid-cols-[repeat(auto-fit,minmax(130px,1fr))] gap-4 overflow-y-auto p-1 pr-2 ".concat("light"===n?"custom-scrollbar-light-mode-blue":"custom-scrollbar-dark-mode-blue-300"),B.length>0&&"h-min",a),children:[!F&&0===B.length&&(0,s.jsx)("div",{className:"col-span-full flex items-center justify-center py-8 text-lg font-semibold ".concat("light"===n?"text-black":"text-white"),children:i("monitoring-observations:statistics.noData")}),F?Array.from({length:9}).map((e,t)=>(0,s.jsx)(M.A,{height:150},"skeleton-".concat(t))):B.map((e,t)=>{var a;return(0,s.jsx)(e8,{taxa:null!=(a=e.taxa)?a:i("monitoring-observations:noTaxa"),imageUrl:(0,e9.B)(e).url,cardinality:e.cardinality,isAlien:e.is_alien,isEndemic:e.is_endemic,isSelected:(null==D?void 0:D.taxonId)===e.taxon_id,onClick:()=>(e=>{if((null==D?void 0:D.taxonId)===e.taxon_id)T(null);else{var t,a;T({taxonId:null!=(t=e.taxon_id)?t:-1,taxa:null!=(a=e.taxa)?a:i("monitoring-observations:noTaxa"),imageUrl:(0,e9.B)(e).url,cardinality:e.cardinality})}})(e)},"".concat(e.taxon_id,"-").concat(e.iconic_taxa_id,"-").concat(t))})]})};var te=a(62214);let tt=ev()(()=>a.e(61451).then(a.bind(a,61451)).then(e=>e.ObservationDetailDialog),{loadableGenerated:{webpack:()=>[61451]},ssr:!1}),ta=e=>{var t,a;let{className:i}=e,{t:n}=(0,y.A)("monitoring"),{locale:l="it",query:o}=(0,w.useRouter)(),d=(0,j.useSession)(),m=o.slug,u=Number(o.id),x=(0,c.r)(),{polygonVersion:h,area:v,polygons:f,device:N,filterDate:k,minimumConfidenceValue:C,selectedSpecies:S,setSelectedSpecies:I,timezone:A}=(0,r._R)(),[z,R]=(0,_.useState)(null),{observe:D,inView:T}=(0,eK.W)({threshold:.3}),L=(0,_.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==d||null==(e=d.data)?void 0:e.accessToken),"accept-language":l}},[null==d||null==(t=d.data)?void 0:t.accessToken,l]),{data:F,isLoading:O,hasNextPage:B,fetchNextPage:P,isFetching:U}=(0,p.ktV)(m,u,{...h&&{polygon_id:h.id},...f.length>0&&{subpolygon_idx:f.map(e=>e.id).join(",")},...v&&{trancept_ids:v.id.toString()},...N&&{hive_ids:N.id.toString()},...k.from&&{date_from:(0,b.default)(k.from,"yyyy-MM-dd")},...k.to&&{date_to:(0,b.default)(k.to,"yyyy-MM-dd")},...C&&{min_confidence:C},...S&&-1!==S.taxonId&&{taxa:S.taxonId.toString()},pagination_limit:50},L,{query:{enabled:!!S,retry:!1,getNextPageParam:(e,t)=>{if(e&&!(e.length<50))return t.length}}}),H=(0,_.useMemo)(()=>(null==F?void 0:F.pages)?F.pages.flat().filter(e=>"unknown"!==e.type).map(e=>({...e,id:"".concat(e.obs_id,"-").concat(e.type,"-").concat(e.user_upload)})):[],[F]);return((0,_.useEffect)(()=>{T&&B&&!U&&P()},[T,B,U,P]),S)?(0,s.jsxs)("div",{className:(0,E.cn)("flex h-full flex-col rounded-xl p-4 ".concat("light"===x?"bg-light-mode-black-100":"bg-dark-mode-blue-300/50"),i),children:[(0,s.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"relative h-10 w-10 overflow-hidden rounded-full",children:(0,s.jsx)(eC(),{src:null!=(a=S.imageUrl)?a:eQ.A.src,alt:S.taxa,fill:!0,className:"object-cover"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"font-bold ".concat("light"===x?"text-black":"text-white"),children:S.taxa}),(0,s.jsxs)("span",{className:"text-sm ".concat("light"===x?"text-light-mode-black-500":"text-dark-mode-monitoring-600(base)"),children:[S.cardinality," ",n("monitoring-observations:hierarchy.species.observations")]})]})]}),(0,s.jsx)("button",{type:"button",onClick:()=>I(null),className:"rounded-full p-2 transition-colors ".concat("light"===x?"text-black hover:bg-light-mode-black-200":"text-white hover:bg-dark-mode-blue-400"),children:(0,s.jsx)(g.In,{icon:"material-symbols:close",width:20,height:20})})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-1 ".concat("light"===x?"custom-scrollbar-light-mode-blue":"custom-scrollbar-dark-mode-blue-300"),children:O?(0,s.jsx)("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(100px,1fr))] gap-3 p-0.5",children:Array.from({length:6}).map((e,t)=>(0,s.jsx)(M.A,{height:120},"skeleton-".concat(t)))}):0===H.length?(0,s.jsx)("div",{className:"flex h-full items-center justify-center ".concat("light"===x?"text-black":"text-white"),children:n("common.noData")}):(0,s.jsx)("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(100px,1fr))] gap-3 p-0.5",children:H.map((e,t)=>{var a,i,l,r,o,d,c,m,u,h,g,p,b,v,f,j,y;return(0,s.jsx)(eJ.bL,{ref:t===H.length-3?D:void 0,role:"button",className:"h-max cursor-pointer rounded-[15p
1x] transition-all hover:ring-2 hover:ring-dark-mode-monitoring-600(base)",onClick:()=>R(e),children:(0,s.jsxs)(eJ.nB,{className:"relative h-full w-full overflow-hidden !p-[8px]",children:[(0,s.jsx)("div",{className:"absolute inset-0 z-10 h-full w-full rounded-[inherit] bg-[rgba(9,32,43,0.5)] backdrop-blur-md"}),(0,s.jsx)(eC(),{src:null!=(h=null==(a=e.taxa)?void 0:a.url)?h:eQ.A.src,alt:null!=(p=null!=(g=null==(i=e.taxa)?void 0:i.taxa)?g:null==(l=e.taxa)?void 0:l.latin_taxa)?p:n("monitoring-observations:noTaxa"),unoptimized:!0,fill:!0}),(0,s.jsx)("div",{className:"relative z-20 mx-auto h-[50px] w-full overflow-hidden rounded-[5px]",children:(0,s.jsx)(eC(),{src:null!=(b=null==(r=e.taxa)?void 0:r.url)?b:eQ.A.src,fill:!0,className:"object-cover",alt:null!=(f=null!=(v=null==(o=e.taxa)?void 0:o.taxa)?v:null==(d=e.taxa)?void 0:d.latin_taxa)?f:n("monitoring-observations:noTaxa")})}),(0,s.jsxs)("div",{className:"relative z-20 mt-2 flex flex-col gap-0.5 ".concat("light"===x?"text-black":"text-white"),children:[(0,s.jsx)("span",{className:"truncate text-center text-xs font-medium",children:null!=(y=null!=(j=null==(c=e.taxa)?void 0:c.taxa)?j:null==(m=e.taxa)?void 0:m.latin_taxa)?y:n("monitoring-observations:noTaxa")}),(null==(u=e.taxa)?void 0:u.probability)&&(0,s.jsxs)("span",{className:"bg-gradient-yellow-pink-cyan-green bg-clip-text text-center text-xs text-transparent",children:[e.taxa.probability,"%"]}),e.record_date&&(0,s.jsx)("span",{className:"text-center text-[10px] italic text-white/60",children:(0,te.format)(new Date(e.record_date),"dd/MM/yyyy",{timeZone:null!=A?A:"UTC"})})]})]})},e.id)})})}),z&&(0,s.jsx)(tt,{observation:z,onClose:()=>R(null)})]}):null},ts=e=>{let{className:t}=e,a=(0,c.r)(),{selectedSpecies:i}=(0,r._R)();return(0,s.jsxs)("div",{className:(0,E.cn)("flex gap-4",t),children:[(0,s.jsxs)("div",{className:(0,E.cn)("flex flex-col gap-4 transition-all duration-300",i?"w-1/2":"w-full"),children:[(0,s.jsx)(e6,{}),(0,s.jsx)(e7,{})]}),i&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-px shrink-0 ".concat("light"===a?"bg-light-mode-black-200":"bg-dark-mode-blue-600(base)")}),(0,s.jsx)("div",{className:"w-1/2 duration-300 animate-in slide-in-from-right",children:(0,s.jsx)(ta,{})})]})]})};var ti=a(66337),tn=a(95156),tl=a(90452),tr=a(58810),to=a(17439),td=a(2741),tc=a(44568),tm=a(13212);let tu=e=>{var t,a;let{isLoading:i,obs:n,refetch:l,isFetching:o,hasNextPage:d,fetchNextPage:m,getGroupCount:u}=e,{t:x}=(0,y.A)("monitoring"),h=(0,c.r)(),{selectedObservation:p,setSelectedObservation:b,event:v,timezone:f}=(0,r._R)(),{observe:j,inView:w}=(0,eK.W)({threshold:.3}),N=(0,_.useRef)(null),k=(0,_.useCallback)(()=>{b(e=>{var t;let a=null!=(t=n[n.length-1])?t:null;if(e){let t=n.findIndex(t=>t.obs_id===e.obs_id&&t.type===e.type&&t.user_upload===e.user_upload)+1;t<n.length&&(a=n[t])}return a})},[n,b]),S=(0,_.useCallback)(()=>{b(e=>{var t;let a=null!=(t=n[0])?t:null;if(e){let t=n.findIndex(t=>t.obs_id===e.obs_id&&t.type===e.type&&t.user_upload===e.user_upload)-1;t>=0&&(a=n[t])}return a})},[n,b]);return((0,_.useEffect)(()=>{let e=e=>{"ArrowRight"===e.key?k():"ArrowLeft"===e.key&&S()};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[k,S]),(0,_.useEffect)(()=>{v&&v.observations.find(e=>e.id===(null==p?void 0:p.id))&&(l(),k())},[v,p,l,k]),(0,_.useEffect)(()=>{w&&d&&!o&&m()},[w,d,o,m]),(0,_.useEffect)(()=>{if(!p||!N.current)return;let e=document.getElementById("".concat(p.obs_id,"-").concat(p.type,"-").concat(p.user_upload));if(!e)return;let t=N.current.offsetWidth,a=e.offsetWidth,s=e.offsetLeft-t/2+a/2;N.current.scroll({left:s,behavior:"smooth"})},[p]),i)?(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsx)(M.A,{width:"100%",height:220}),(0,s.jsxs)("div",{className:"flex w-full gap-10",children:[(0,s.jsx)(M.A,{containerClassName:"flex-1",height:400}),(0,s.jsx)(M.A,{containerClassName:"flex-[0.5]",height:400})]})]}):0===n.length?(0,s.jsx)("span",{className:"text-lg ".concat("light"===h?"text-black":"text-white"),children:x("common.noData")}):(0,s.jsxs)("div",{className:"relative flex flex-col gap-10",children:[(0,s.jsxs)(tm.bL,{scrollByPxs:150,offset:30,children:[(0,s.jsx)(tm.UC,{ref:N,enableChildrenClick:!1,className:"relative gap-5",children:n.map((e,t)=>{var a,i,l,r,o,d,c,m,y,w,N,k,_,C,S,I,A,z,R,D;let M=(null==p?void 0:p.id)===e.id,T=null==v?void 0:v.observations.some(t=>t.id===e.id),L=null==u?void 0:u(e);return(0,s.jsxs)("div",{id:e.id,className:"relative flex flex-col pt-20",ref:t===n.length-3?j:void 0,children:[(0,s.jsx)("div",{className:"absolute top-14 grid h-0.5 w-[170px] place-content-center last:w-full ".concat("light"===h?"bg-light-mode-black-300":"bg-dark-mode-blue-500"),children:(0,s.jsxs)("div",{className:"relative grid aspect-square h-3 place-content-center rounded-full ".concat("light"===h?"bg-light-mode-black-300":"bg-dark-mode-blue-500"),children:[(0,s.jsx)("div",{className:"aspect-square h-2 animate-pulse rounded-full ".concat("light"===h?"bg-light-mode-black-500":"bg-dark-mode-blue-900")}),(0,s.jsxs)("div",{className:"absolute bottom-full right-0 flex flex-col whitespace-nowrap pb-1 text-left leading-none",children:[(0,s.jsx)("span",{className:(0,E.cn)("text-sm ".concat("light"===h?"text-light-mode-black-400":"text-dark-mode-blue-500"),M&&"text-dark-mode-monitoring-400"),children:(0,te.format)(new Date(e.record_date),"dd.MM.yy",{timeZone:null!=f?f:"UTC"})}),(0,s.jsx)("span",{className:(0,E.cn)("text-sm ".concat("light"===h?"text-light-mode-black-500":"text-dark-mode-blue-1000"),M&&"text-dark-mode-monitoring-600(base)"),children:(0,te.format)(new Date(e.record_date),"HH:mm",{timeZone:null!=f?f:"UTC"})})]})]})}),(0,s.jsxs)("div",{className:"relative mt-5 h-max w-[150px]",children:[L&&L>1&&(0,s.jsx)("div",{className:"pointer-events-none absolute left-[14px] top-[14px] z-30",children:(0,s.jsx)(ef.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"w-max font-bold",children:x("monitoring-observations:censuses.grouping.count",{count:L})})}),(0,s.jsxs)(tc.bL,{className:(0,E.cn)("relative h-full w-full cursor-pointer overflow-hidden rounded-[15p
1x]",M&&"border-2 border-dark-mode-monitoring-600(base)",T&&"cursor-not-allowed"),onClick:()=>{T||b(e)},children:[T&&(0,s.jsx)("div",{className:"absolute left-0 top-0 z-50 flex h-full w-full items-center justify-center bg-black/80",children:(0,s.jsx)(g.In,{icon:"eos-icons:loading",width:40,height:40})}),(0,s.jsx)("div",{className:"absolute inset-0 z-10 h-full w-full bg-[rgba(9,32,43,0.5)] backdrop-blur-md"}),(0,s.jsx)(eC(),{src:null!=(_=null==(a=e.taxa)?void 0:a.url)?_:eQ.A.src,alt:null!=(S=null!=(C=null==(i=e.taxa)?void 0:i.taxa)?C:null==(l=e.taxa)?void 0:l.latin_taxa)?S:x("monitoring-observations:noTaxa"),unoptimized:!0,fill:!0}),(0,s.jsxs)(tc.UC,{blur:"md",direction:"vertical",className:"relative z-20 p-[10px]",children:[(0,s.jsx)("div",{className:"relative h-[90px] w-[130px] overflow-hidden rounded-[5px]",children:(0,s.jsx)(eC(),{src:null!=(I=null==(r=e.taxa)?void 0:r.url)?I:eQ.A.src,fill:!0,className:"object-cover",alt:null!=(z=null!=(A=null==(o=e.taxa)?void 0:o.taxa)?A:null==(d=e.taxa)?void 0:d.latin_taxa)?z:x("monitoring-observations:noTaxa")})}),(0,s.jsxs)("div",{className:"flex h-full w-full flex-1 flex-col justify-between gap-3 ".concat("light"===h?"text-black":"text-white"),children:[(0,s.jsx)("span",{className:"text-center text-base font-bold",children:null!=(D=null!=(R=null==(c=e.taxa)?void 0:c.taxa)?R:null==(m=e.taxa)?void 0:m.latin_taxa)?D:x("monitoring-observations:noTaxa")}),(null==(y=e.taxa)?void 0:y.probability)&&(null==(w=e.taxa)?void 0:w.probability)<100&&(0,s.jsx)("span",{className:"bg-gradient-yellow-pink-cyan-green bg-clip-text text-center text-sm font-bold text-transparent",children:x("monitoring-observations:censuses.probability",{probability:e.taxa.probability})}),"sound"===e.type&&e.url&&(0,s.jsx)(tc.ai,{sound:e.url,maxLoops:1,children:(0,s.jsx)(tc.qz,{onClick:e=>{e.stopPropagation()}})})]})]})]}),(0,s.jsxs)("div",{className:"pointer-events-none absolute right-[14px] top-[14px] z-30 flex flex-col items-end gap-2",children:[(null==(N=e.taxa)?void 0:N.probability)&&(null==(k=e.taxa)?void 0:k.probability)>=100?(0,s.jsxs)("div",{className:"pointer-events-auto relative hover:z-[9999]",children:[(0,s.jsx)(ef.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"peer w-max text-xs",children:x("monitoring-observations:censuses.confirmed")}),(0,s.jsx)(to.A,{className:"pointer-events-none absolute left-1/2 top-full z-[99999] ml-2 mt-2 -translate-x-1/2 whitespace-nowrap rounded-lg px-2 py-1 text-xs opacity-0 transition-opacity peer-hover:opacity-100 ".concat("light"===h?"bg-light-mode-black-100 text-light-mode-black-600(base)":"bg-dark-mode-blue-1100 text-dark-mode-blue-400"),description:e.user_upload?x("monitoring-observations:censuses.badge.confirmedManuallyTooltip"):x("monitoring-observations:censuses.badge.userTooltip")})]}):e.user_tag&&(0,s.jsx)(ef.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"pointer-events-auto w-max text-xs ".concat("light"===h?"border-light-mode-black-200 text-light-mode-black-600(base)":"border-dark-mode-blue-1100 text-dark-mode-blue-1100"),children:x("monitoring-observations:censuses.tagged")}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)(e1.U,{geoClass:e.geo_class,geoReason:e.geo_reason,geoDistanceKm:e.geo_distance_km,variant:h,compact:!0}),(0,s.jsxs)("div",{className:"pointer-events-auto relative hover:z-[9999]",children:[(0,s.jsx)(ef.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"peer w-max ".concat("light"===h?"border-light-mode-black-200 text-light-mode-black-600(base)":"border-dark-mode-blue-1100 text-dark-mode-blue-1100"),children:e.user_upload?(0,s.jsx)(g.In,{icon:"material-symbols:upload-rounded",width:16,height:16}):(0,s.jsx)(td.z,{})}),(0,s.jsx)(to.A,{className:"pointer-events-none absolute left-1/2 top-full z-[99999] ml-2 mt-2 -translate-x-1/2 whitespace-nowrap rounded-lg px-2 py-1 text-xs opacity-0 transition-opacity peer-hover:opacity-100 ".concat("light"===h?"bg-light-mode-black-100 text-light-mode-black-600(base)":"bg-dark-mode-blue-1100 text-dark-mode-blue-400"),description:e.user_upload?x("monitoring-observations:censuses.badge.userTooltip"):x("monitoring-observations:censuses.badge.deviceTooltip")})]})]})]})]})]},e.id)})}),(0,s.jsxs)("div",{className:"-mt-5 flex w-full items-center justify-end gap-5",children:[(0,s.jsx)(C.$,{variant:"unstyled",disabled:(null==p?void 0:p.id)===(null==(t=n[0])?void 0:t.id),className:"!pointer-events-auto !text-light-mode-black-100 disabled:cursor-not-allowed disabled:!opacity-25",onClick:e=>{e.preventDefault(),S()},children:(0,s.jsx)(g.In,{icon:"material-symbols:chevron-left",width:30,height:30})}),(0,s.jsx)(C.$,{variant:"unstyled",disabled:(null==p?void 0:p.id)===(null==(a=n[n.length-1])?void 0:a.id),className:"!pointer-events-auto !text-light-mode-black-100 disabled:cursor-not-allowed disabled:!opacity-25",onClick:e=>{e.preventDefault(),k()},children:(0,s.jsx)(g.In,{icon:"material-symbols:chevron-right",width:30,height:30})})]})]}),(0,s.jsx)(eX.C,{},null==p?void 0:p.id)]})},tx=()=>{let{isLoading:e,data:t={pages:[],pageParams:[],obs:[]},refetch:a,isFetching:i,hasNextPage:n,fetchNextPage:l}=(0,e$.x)();return(0,s.jsx)(tu,{isLoading:e,obs:t.obs,refetch:a,isFetching:i,hasNextPage:n,fetchNextPage:l})},th=()=>{let{selectedObservation:e,setActiveSession:t,event:a}=(0,r._R)(),{isLoading:i,data:n={pages:[],pageParams:[],obs:[]},refetch:l,isFetching:o,hasNextPage:d,fetchNextPage:c}=(e=>{var t;let{query:a,locale:s="it"}
1=(0,w.useRouter)(),i=a.slug,n=Number(a.id),l=(0,j.useSession)(),{polygonVersion:o,area:d,polygons:c,device:m,filterDate:u,filterSpecies:x,filterSubSpecies:h,filterFamily:g,filterGenre:p,filterOrder:v,filterIndex:f,minimumConfidenceValue:y,statisticsEndemicFilter:N,geoProbabilityFilter:k,classificationFilter:_,selectedObservation:C,setSelectedObservation:S,generateQueryKey:I,event:A,setEvent:z}=(0,r._R)(),R={...o&&{polygon_id:o.id},...c.length>0&&{subpolygon_idx:c.map(e=>e.id).join(",")},...d&&{trancept_ids:d.id.toString()},...m&&{hive_ids:m.id.toString()},...u.from&&{date_from:(0,b.default)(u.from,"yyyy-MM-dd")},...u.to&&{date_to:(0,b.default)(u.to,"yyyy-MM-dd")},...x.size>0&&{iconic_taxa:Array.from(x.keys()).join(",")},...h.size>0&&{taxa:Array.from(h.keys()).join(",")},...g.size>0&&{family_taxa:Array.from(g.keys()).join(",")},...p.size>0&&{genus_taxa:Array.from(p.keys()).join(",")},...v.size>0&&{order_taxa:Array.from(v.keys()).join(",")},...f&&{index_id:f.id},...y&&{min_confidence:y},..."all"!==N&&{endemic_filter:N},...(0,tr.z)(k),..."all"!==_&&{classification_filter:_},exclude_taxa:r.Wg,pagination_limit:50},D={"accept-language":s,...(null==l||null==(t=l.data)?void 0:t.accessToken)?{authorization:"Bearer ".concat(l.data.accessToken)}:void 0},{isLoading:M,data:T={pages:[],pageParams:[],obs:[]},refetch:E,isFetching:L,hasNextPage:F,fetchNextPage:O}=(0,tn.q)({queryKey:[...I(i,n,"observations_censuses"),"sessions"],queryFn:e=>{let{pageParam:t}=e;return(0,tl.S)({url:"/v1/monitoring/".concat(i,"/sites/").concat(n,"/observations/censuses/sessions"),method:"GET",params:{...R,page:t||1},headers:D})},enabled:e&&!!i&&!Number.isNaN(n)&&!!o,retry:!1,select:e=>({...e,obs:e.pages.flat().filter(e=>"unknown"!==e.type).map(e=>({...e,id:"".concat(e.obs_id,"-").concat(e.type,"-").concat(e.user_upload),url:(0,ti.V)(e.url)}))}),getNextPageParam:(e,t)=>e.length>0?t.length+1:void 0,onSettled:e=>{var t,a;if(!e)return;let{obs:s}=e||{pages:[],pageParams:[],obs:[]};return A?(z(null),s&&0!==s.length)?void(C&&!s.find(e=>e.id===C.id)&&S(null!=(t=s[0])?t:null)):void S(null):s&&0!==s.length?void(s.find(e=>e.id===(null==C?void 0:C.id))||S(null!=(a=s[0])?a:null)):void S(null)}});return{isLoading:M,data:T,refetch:E,isFetching:L,hasNextPage:F,fetchNextPage:O}})(!0);return(0,_.useEffect)(()=>{a&&l()},[a,l]),(0,_.useEffect)(()=>{if(!e)return void t(null);let a=n.obs.find(t=>t.id===e.id);if(a)if(a.group_count>1){var s,i;t({taxonId:null!=(i=null==(s=a.taxa)?void 0:s.taxon_id)?i:null,fromDt:a.session_last_date,toDt:a.session_first_date,groupCount:a.group_count})}else t(null)},[e,n.obs,t]),(0,s.jsx)(tu,{isLoading:i,obs:n.obs,refetch:l,isFetching:o,hasNextPage:d,fetchNextPage:c,getGroupCount:e=>e.group_count})},tg=()=>{let{groupConsecutive:e}=(0,r._R)();return e?(0,s.jsx)(th,{}):(0,s.jsx)(tx,{})},tp=()=>{let{viewMode:e}=(0,r._R)();return(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:["list"===e&&(0,s.jsx)(tg,{}),"grid"===e&&(0,s.jsx)(e2,{}),"hierarchy"===e&&(0,s.jsx)(ts,{})]})},tb={dark:"dark-mode-blue-1100",light:"light-mode-black-200"},tv=()=>{var e,t,a;let{t:v}=(0,y.A)("monitoring"),{query:N,locale:S="it",asPath:I}=(0,w.useRouter)(),A=N.slug,z=Number(N.id),{polygonVersion:R,area:D,polygons:M,device:T,filterDate:E,filterSpecies:L,filterSubSpecies:F,filterFamily:O,filterGenre:B,filterOrder:P,filterIndex:U,minimumConfidenceValue:H,generateQueryKey:q,viewMode:V,setViewMode:W,event:$}=(0,r._R)(),Q=(0,j.useSession)(),G=(0,m.Q)(),K=(0,c.r)(),{canReadSite:Z,canEditSite:J,isDemoAndOwner:Y}=(0,x.A)(),X=(0,u.R)("DataExport"),ee=J||Z&&X,[et,ea]=(0,_.useState)(!1),[es,ei]=(0,_.useState)(!0),{data:en}=(0,p.s3s)(A,z,void 0,void 0,{query:{enabled:!J}}),el=(null!=(a=null==en||null==(e=en.files)?void 0:e.length)?a:0)>0,er=J||el,{refetch:eo}=(0,p.ffC)(A,z,{...R&&{polygon_id:R.id},...M.length>0&&{subpolygon_idx:M.map(e=>e.id).join(",")},...D&&{trancept_ids:D.id.toString()},...T&&{hive_ids:T.id.toString()},...E.from&&{date_from:(0,b.default)(E.from,"yyyy-MM-dd")},...E.to&&{date_to:(0,b.default)(E.to,"yyyy-MM-dd")},...L.size>0&&{iconic_taxa:Array.from(L.keys()).join(",")},...F.size>0&&{taxa:Array.from(F.keys()).join(",")},...O.size>0&&{family_taxa:Array.from(O.keys()).join(",")},...B.size>0&&{genus_taxa:Array.from(B.keys()).join(",")},...P.size>0&&{order_taxa:Array.from(P.keys()).join(",")},...U&&{index_id:U.id},...H&&{min_confidence:H},exclude_taxa:r.Wg},{"accept-language":S,...(null==Q||null==(t=Q.data)?void 0:t.accessToken)?{authorization:"Bearer ".concat(Q.data.accessToken)}:void 0},{query:{queryKey:q(A,z,"observations_censuses"),enabled:!1}});return(0,s.jsxs)(i.bL,{id:"census-observations","data-description":"Census observations section displaying field surveys and laboratory analysis data",variant:"transparent",children:[!G&&(0,s.jsxs)(i.Y9,{variant:K,className:"flex flex-wrap items-end justify-between gap-3",children:[(0,s.jsx)(l.l,{level:"section",children:v("monitoring-observations:censuses.title")}),(0,s.jsxs)("div",{className:"flex flex-row items-center justify-start gap-4",children:[ee&&(0,s.jsx)(C.$,{id:"census-observations-download-button","data-description":"Download census observations data as CSV file",variant:"unstyled",disabled:et||Y,onClick:async()=>{ea(!0);try{let e=await eo();e&&e.data&&f()(e.data,"survey_census_observations.csv")}catch(e){}finally{ea(!1)}},children:(0,s.jsx)(g.In,{icon:et?"eos-icons:loading":"material-symbols:download",width:24,height:24,color:"light"===K?"black":"white"})}),(0,s.jsx)(o.k,{variant:"white",kind:d.aF.ObservationsCensuses}),(0,s.jsx)(i.Ek,{widget:"census-observations",basePath:I.split(/[?#]/)[0].replace(/\/census\/?$/,"/")})]})]}),(0,s.jsxs)(i.nB,{variant:K,spacing:"md",className:"!rounded-xl",children:[J&&(0,s.jsx)(k(),{src:h.PB}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[er&&(0,s.jsx)(n.T,{variant:tb[K],value:es?"fieldSurveys":"laboratoryAnalysis",onChange:e=>ei("fieldSurveys"===e),options:[{value:"fieldSurveys",label:v("monitoring-observations:censuses.fieldSurveys")},{value:"laboratoryAnalysis",label:v("monitoring-observations:censuses.laboratoryAnalysis")}]}),es&&(0,s.jsx)(n.T,{variant:tb[K],value:V,onChange:e=>W(e),options:[{value:"list",label:(0,s.jsx)(g.In,{icon:"material-symbols:format-list-bulleted-rounded",width:24,height:24}),disabled:null!==$},{value:"grid",label:(0,s.jsx)(g.In,{icon:"material-symbols:grid-view-outline-rounded",width:24,height:24}),disabled:null!==$},{value:"hierarchy",label:(0,s.jsx)(g.In,{icon:"material-symbols:account-tree-outline-rounded",width:24,height:24}),disabled:null!==$}]})]}),(0,s.jsx)("div",{className:"mt-4",children:es?(0,s.jsx)(tp,{}):(0,s.jsx)(eW,{})})]})]})}},60620:(e,t,a)=>{"use strict";a.d(t,{g:()=>h});var s=a(83815),i=a(27149),n=a(60938),l=a(90336),r=a(54002),o=a(86666),d=a.n(o),c=a(99888),m=a(70679),u=a(54066),x=a(95001);function h(e){var t;let{images:a,defaultIndex:o=0,onImageChange:h,isLoading:g=!1,className:p}=e,{t:b}=(0,r.A)("monitoring"),{locale:v="it"}=(0,c.useRouter)(),[f,j]=(0,m.useState)(o),[y,w]=(0,m.useState)(new Set),N=(0,m.useRef)(null),k=(0,m.useRef)(0),_=(0,m.useRef)(0),C=a.filter(e=>!y.has(e.id)),S=Math.max(0,Math.min(f,C.length-1)),I=C[S],A=(0,m.useCallback)(e=>{w(t=>new Set(t).add(e))},[]),z=(0,m.useCallback)(e=>{let t=Math.max(0,Math.min(e,C.length-1));j(t),null==h||h(C[t],t)},[C,h]),R=(0,m.useCallback)(()=>{f<C.length-1?z(f+1):z(0)},[f,C.length,z]),D=(0,m.useCallback)(()=>{f>0?z(f-1):z(C.length-1)},[f,C.length,z]),M=I?I.url.replace(/^http:\/\//i,"https://"):"",T=(()=>{var e;if(!I)return"biodiversa.jpg";let t="jpg";try{let e=new URL(M).pathname.split(".").pop();e&&(t=e.replace(/[^A-Za-z0-9]/g,"").toLowerCase()||"jpg")}catch(e){}let a=(null!=(e=I.taxa)?e:"biodiversa").trim().replace(/[^A-Za-z0-9._-]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"")||"bio
1diversa",s=(()=>{let e=new Date(I.date);return Number.isNaN(e.getTime())?I.id:e.toISOString().replace(/\..*$/,"").replace(/:/g,"-")})();return"".concat(a,"_").concat(s,".").concat(t)})(),E=I?"/api/proxy/download?url=".concat(encodeURIComponent(M),"&filename=").concat(encodeURIComponent(T)):"";if((0,m.useEffect)(()=>{o>=0&&o<C.length?(j(o),C[o]&&(null==h||h(C[o],o))):C.length>0&&(j(0),null==h||h(C[0],0))},[o,C.length]),(0,m.useEffect)(()=>{if(N.current&&C.length>0){let e=N.current,t=36*S-e.clientWidth/2+16;e.scrollTo({left:Math.max(0,t),behavior:"smooth"})}},[S,C.length]),g)return(0,s.jsxs)("div",{className:(0,x.cn)("flex flex-col gap-2",p),children:[(0,s.jsx)(u.A,{height:80,borderRadius:8}),(0,s.jsx)("div",{className:"flex gap-1",children:Array.from({length:4}).map((e,t)=>(0,s.jsx)(u.A,{width:32,height:32,borderRadius:4},t))})]});if(!I||0===C.length)return null;let L=(0,l.default)(new Date(I.date),"dd MMM yyyy HH:mm",{locale:(0,i.no)(v)});return(0,s.jsxs)("div",{className:(0,x.cn)("relative flex select-none flex-col gap-2",p),onTouchStart:e=>{k.current=e.touches[0].clientX},onTouchMove:e=>{_.current=e.touches[0].clientX},onTouchEnd:()=>{let e=k.current-_.current;Math.abs(e)>30&&(e>0?R():D()),k.current=0,_.current=0},children:[(0,s.jsxs)("div",{className:"relative h-20 w-full overflow-hidden rounded-lg bg-dark-mode-blue-400",children:[(0,s.jsx)(d(),{src:I.url,alt:null!=(t=I.taxa)?t:b("map.popup.device.observation"),fill:!0,className:"object-cover",unoptimized:!0,onError:()=>A(I.id)},I.id),(0,s.jsx)("a",{href:E,download:T,rel:"noreferrer",className:"absolute right-1 top-1 z-10 flex size-5 items-center justify-center rounded-full bg-black/50 text-white/80 transition-colors hover:bg-black/70 hover:text-white","aria-label":b("map.popup.device.download"),children:(0,s.jsx)(n.In,{icon:"ph:download-simple",width:12,height:12})}),C.length>1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",onClick:D,className:"absolute left-1 top-1/2 z-10 flex size-5 -translate-y-1/2 items-center justify-center rounded-full bg-black/50 text-white/80 transition-colors hover:bg-black/70 hover:text-white","aria-label":b("kpiCarousel.previousKpi"),children:(0,s.jsx)(n.In,{icon:"mdi:chevron-left",width:14,height:14})}),(0,s.jsx)("button",{type:"button",onClick:R,className:"absolute right-1 top-1/2 z-10 flex size-5 -translate-y-1/2 items-center justify-center rounded-full bg-black/50 text-white/80 transition-colors hover:bg-black/70 hover:text-white","aria-label":b("kpiCarousel.nextKpi"),children:(0,s.jsx)(n.In,{icon:"mdi:chevron-right",width:14,height:14})})]}),(0,s.jsx)("div",{className:"absolute bottom-1 left-1 rounded bg-black/60 px-1.5 py-0.5 text-[9px] text-white",children:L}),C.length>1&&(0,s.jsxs)("div",{className:"absolute bottom-1 right-1 rounded bg-black/60 px-1.5 py-0.5 text-[9px] text-white",children:[S+1,"/",C.length]})]}),C.length>1&&(0,s.jsx)("div",{ref:N,className:"custom-scrollbar-dark-mode-blue-300 flex gap-1 overflow-x-auto pb-1",children:C.map((e,t)=>(0,s.jsx)("button",{type:"button",onClick:()=>z(t),className:(0,x.cn)("relative size-8 shrink-0 overflow-hidden rounded transition-all",t===S?"ring-2 ring-state-colors-success-400(base)":"opacity-60 hover:opacity-100"),"aria-label":"".concat(b("map.popup.device.observation")," ").concat(t+1),children:(0,s.jsx)(d(),{src:e.url,alt:"",fill:!0,className:"object-cover",unoptimized:!0,onError:()=>A(e.id)})},e.id))})]})}},61070:(e,t,a)=>{"use strict";a.d(t,{D5:()=>j,DG:()=>C,JJ:()=>L,O8:()=>U,R8:()=>p,T4:()=>B,TH:()=>f,UO:()=>h,Vb:()=>E,Vq:()=>I,WW:()=>P,Wo:()=>c,YO:()=>w,Y_:()=>b,_3:()=>z,_n:()=>k,aG:()=>x,ai:()=>A,d4:()=>T,dV:()=>g,gN:()=>u,hb:()=>v,iH:()=>o,jr:()=>_,kL:()=>F,mN:()=>O,rA:()=>D,uv:()=>m,vh:()=>R,vs:()=>S,wP:()=>y,yH:()=>d,yU:()=>N});var s=a(84723),i=a(5296),n=a(86314);let l={iconSize:[50,50],iconAnchor:[25,50],popupAnchor:[0,-50]},r={iconSize:[20,20],iconAnchor:[20,20],popupAnchor:[0,-20],className:"marker"},o=e=>{let{color:t="white",borderColor:a="",isSpecificSite:i=!1,region:n="roi"}=e;return(0,s.divIcon)({html:'<div class="relative size-5 rounded-full monitoring-map-sites-marker" style="background-color: '.concat(t,"; ").concat(a?"border-width: 2px; border-color: ".concat(a,";"):""," ").concat("ca"===n?"box-shadow: 0 0 0 3px rgba(255,255,255,0.8), 0 0 0 5px rgba(0,0,0,0.3);":"",'">\n ').concat(i?'<div class="absolute -top-2.5 -right-2.5">\n <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#FFB800" class="size-5" style="filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));">\n <path d="M12 2l2.4 7.4h7.6l-6 4.6 2.3 7.4-6.3-4.6-6.3 4.6 2.3-7.4-6-4.6h7.6z"/>\n </svg>\n </div>':"","\n </div>"),...r,className:"marker overflow-visible"})},d=(0,s.icon)({...l,iconUrl:"/images/owner/marker_site.svg"}),c=(0,s.icon)({...l,iconUrl:"/images/owner/marker_site_active_regeneration.svg"}),m=(0,s.icon)({...l,iconUrl:"/images/owner/marker_site.svg",className:"monitoring-map-sites-marker"}),u=(0,s.icon)({...l,iconUrl:"/images/owner/marker_site_active.svg",className:"monitoring-map-sites-marker"}),x=(0,s.icon)({...l,iconUrl:"/images/owner/marker_own_site.svg"}),h=(0,s.icon)({...l,iconUrl:"/images/owner/marker_own_site_active.svg"}),g=(0,s.icon)({...l,iconUrl:"/images/owner/marker_demo_site.svg"}),p=(0,s.icon)({...l,iconUrl:"/images/owner/marker_demo_site_active.svg"}),b=(0,s.icon)({...l,iconUrl:"/images/owner/marker_bee.svg"});(0,s.icon)({...l,iconUrl:"/images/owner/marker_bee_active.svg"}),(0,s.icon)({...l,iconUrl:"/images/owner/marker_bee_expired.svg"});let v=(0,s.icon)({...l,iconUrl:"/images/owner/marker_shelter.svg"}),f=(0,s.icon)({...l,iconUrl:"/images/owner/marker_shelter_active.svg"}),j=(0,s.icon)({...l,iconUrl:"/images/owner/marker_biolago.svg"}),y=(0,s.icon)({...l,iconUrl:"/images/owner/marker_school.svg"}),w=(0,s.icon)({...l,iconUrl:"/images/owner/marker_school.svg"}),N=(0,s.icon)({...l,iconUrl:"/images/owner/marker_artistic_heritage.svg"}),k=(0,s.icon)({...l,iconUrl:"/images/owner/marker_artistic_heritage_active.svg"}),_=(0,s.icon)({...l,iconUrl:"/images/owner/marker_amenities.svg"}),C=(0,s.icon)({...l,iconUrl:"/images/owner/marker_amenities_active.svg"}),S=(0,s.icon)({...l,iconUrl:"/images/owner/marker_tourism.svg"}),I=(0,s.icon)({...l,iconUrl:"/images/owner/marker_tourism_active.svg"}),A=(0,s.icon)({...l,iconUrl:"/images/owner/marker_building.svg"}),z=(0,s.icon)({...l,iconUrl:"/images/owner/marker_building_active.svg"}),R=(0,s.icon)({...l,iconUrl:"/images/owner/marker_historic.svg"}),D=(0,s.icon)({...l,iconUrl:"/images/owner/marker_historic_active.svg"}),M=new Map;function T(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,a=(0,n.IW)(e),i="".concat(t,"|").concat(a),l=M.get(i);if(l)return l;let r=[Math.round(n.AT[0]*t),Math.round(n.AT[1]*t)],o=[Math.round(n.IP[0]*t),Math.round(n.IP[1]*t)],d=(0,s.icon)({iconSize:r,iconAnchor:o,popupAnchor:[0,-o[1]],iconUrl:a,className:"drop-shadow-[0_3px_5px_rgba(0,0,0,0.6)]"});return M.set(i,d),d}let E=T({key:"mount"});function L(e,t){var a;return T({key:(null!=(a=null==t?void 0:t.active)?a:void 0!==e.device_id&&null!==e.device_id)?(0,i.zJ)(e.device_type):"mount",markerColor:e.marker_color,selected:null==t?void 0:t.selected})}T({key:"biodiversityMount"}),(0,s.icon)({...l,iconUrl:"/images/owner/marker_species.svg"}),(0,s.icon)({...l,iconUrl:"/images/owner/marker_species_active.svg"});let F=(0,s.icon)({...l,iconUrl:"/images/owner/marker_species_pink.svg"}),O=(0,s.icon)({...l,iconUrl:"/images/owner/marker_species_pink_active.svg"}),B=(0,s.icon)({...l,iconUrl:"/images/owner/marker_plant.svg"});(0,s.icon)({...l,iconUrl:"/images/owner/marker_plant_active.svg"});let P=(0,s.icon)({...l,popupAnchor:[0,-50],iconUrl:"/images/owner/marker_bee_b2b.svg"}),U=(0,s.icon)({...l,iconUrl:"/images/owner/marker_tree.svg"})},61614:(e,t,a)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/oasi-v3/[slug]/monitoring/site/[id]/census",function(){return a(82271)}])},62290:(e,t,a)=>{"use strict";a.d(t,{H:()=>l});var s=a(83815),i=a(44090);a(70679);var n=a(95001);function l(e){let{className:t,orientation:a="horizontal",decorative:l=!0,...r}=e;return(0,s.jsx)(i.b,{"data-slot":"separator",decorative:l,orientation:a,className:(0,n.cn)("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=vertical]:h-full data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px",t),...r})}},66337:(e,t,a)=>{"use strict";function s(e){return e&&e.startsWith("http://")?e.replace("http://","https://"):e}a.d(t,{V:()=>s})},68505:(e,t,a)=>{"use strict";a.d(t,{X:()=>g});var s=a(83815),i=a(61070),n=a(28229),l=a(85973),r=a(11379),o=a(33635),d=a(24552),c=a(75258),m=a.n(c),u=a(99888),x=a(70679);let h=m()(()=>Promise.all([a.e(69468),a.e(12385),a.e(93795),a.e(57449),a.e(32175)]).then(a.bind(a,32175)).then(e=>
1e.ModifyAreasDialog),{loadableGenerated:{webpack:()=>[32175]},ssr:!1}),g=e=>{var t,a,c;let{label:m,className:g,children:p}=e,{query:b}=(0,u.useRouter)(),v=b.slug,f=Number(b.id),j=null==(t=(0,d.useSession)().data)?void 0:t.accessToken,{polygonVersion:y}=(0,n._R)(),w=!!(null==y?void 0:y.id)&&!!j,{data:N}=(0,o.pFV)(v,f,null!=(a=null==y?void 0:y.id)?a:0,{},{authorization:"Bearer ".concat(j)},{query:{enabled:w}}),{data:k=[]}=(0,o.Aex)(v,f,null!=(c=null==y?void 0:y.id)?c:0,{authorization:"Bearer ".concat(j)},{query:{enabled:w,retry:!1}}),{data:_=[]}=(0,o._l1)(v,f,{},{authorization:"Bearer ".concat(j)},{query:{retry:!1,select:e=>e.filter(e=>e.latitude&&e.longitude).map(e=>({...e,icon:(0,i.JJ)(e,{active:(0,l.b)(e)})}))}}),C=(0,x.useMemo)(()=>N?(0,r.No)(N.roi):[],[N]),S=(0,x.useMemo)(()=>({type:"FeatureCollection",features:k.map(e=>{let{id:t,name:a,polygon:s}=e;return{type:"Feature",id:t,geometry:s,properties:{name:""===a?void 0:a}}})}),[k]),I=(0,x.useMemo)(()=>k.flatMap(e=>{let{polygon:t}=e;return t.coordinates[0].map(e=>[e[1],e[0]])}),[k]);return(0,s.jsx)(h,{polygon:null==N?void 0:N.roi,devices:_,existingAreaPolygons:S,bounds:[...C,...I],triggerLabel:m,triggerClassName:g,triggerContent:p},"".concat(JSON.stringify(k),"-").concat(JSON.stringify(_)))}},69071:(e,t,a)=>{"use strict";a.d(t,{nB:()=>n,di:()=>r,wi:()=>m.O,Y9:()=>g,bL:()=>p,Qv:()=>c});var s=a(83815),i=a(95001);let n=e=>{let{children:t,className:a}=e;return(0,s.jsx)("tbody",{className:(0,i.cn)("[&>tr>td]:border-dark-mode-blue-300 [&>tr>td]:bg-transparent [&>tr>td]:py-8 [&>tr>td]:align-top [&>tr>td]:leading-none",a),children:t})};var l=a(99888);let r=e=>{let{date:t,className:a}=e,{locale:n="it"}=(0,l.useRouter)(),r=new Intl.DateTimeFormat(n,{hour:"2-digit",minute:"2-digit"}),o=new Intl.DateTimeFormat(n,{day:"2-digit",month:"2-digit",year:"2-digit"});return(0,s.jsxs)("td",{className:(0,i.cn)("!dpt-0 relative min-w-32",a),children:[(0,s.jsx)("div",{className:"absolute right-7 top-0 h-full w-0.5 bg-dark-mode-blue-500"}),t&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex w-max flex-col text-right text-sm leading-none",children:[(0,s.jsx)("span",{className:"font-bold text-light-mode-black-400",children:r.format(t)}),(0,s.jsx)("span",{className:"text-light-mode-black-500",children:o.format(t)})]}),(0,s.jsx)("div",{className:"absolute right-[23px] top-3 z-10 grid h-3 w-3 place-items-center rounded-full bg-dark-mode-blue-500",children:(0,s.jsx)("div",{className:"h-2 w-2 animate-pulse rounded-full bg-dark-mode-blue-900"})})]})]})};var o=a(70679),d=a(52283);let c=e=>{let{timestamps:t}=e,a=(0,o.useMemo)(()=>(0,d.t)(t),[t]),i=(0,o.useMemo)(()=>new Intl.NumberFormat(void 0,{style:"unit",unit:"second",unitDisplay:"short"}).format(a),[a]);return 0===a?(0,s.jsx)("td",{}):(0,s.jsx)("td",{className:"text-sm text-dark-mode-blue-1000",children:i})};var m=a(56199),u=a(60938),x=a(54002),h=a(43052);let g=e=>{let{tableColumnsSort:t,tableColumnsLabels:a,namespace:i="monitoring",setTableColumnsSort:n}=e,{t:l}=(0,x.A)(i),r=Object.keys(a);return(0,s.jsxs)("thead",{children:[(0,s.jsx)("tr",{children:r.map(e=>{let i=t[e];return(0,s.jsx)("th",{className:"border-none bg-transparent first:!relative",title:i?"asc"===i?l("common:paginatedTable.sortDesc"):l("common:paginatedTable.clearSort"):l("common:paginatedTable.sortAsc"),children:void 0===i?(0,s.jsx)("span",{className:"w-max whitespace-nowrap text-base capitalize !text-dark-mode-blue-900",children:l(a[e])}):(0,s.jsxs)(h.$,{variant:"unstyled",className:"w-max whitespace-nowrap !text-dark-mode-blue-900",onClick:()=>n(t=>({...t,[e]:"asc"===i?"desc":"desc"===i?null:"asc"})),children:[l(a[e]),null===i&&(0,s.jsx)(u.In,{icon:"akar-icons:sort",className:"ml-5"}),"asc"===i&&(0,s.jsx)(u.In,{icon:"akar-icons:arrow-up",className:"ml-5"}),"desc"===i&&(0,s.jsx)(u.In,{icon:"akar-icons:arrow-down",className:"ml-5"})]})},e)})}),(0,s.jsx)("tr",{className:"h-0 border-t border-t-dark-mode-blue-300"})]})},p=e=>{let{children:t,className:a,tableClassName:n}=e;return(0,s.jsx)("div",{className:(0,i.cn)("custom-scrollbar-dark-mode-blue overflow-x-auto",a),children:(0,s.jsx)("table",{className:(0,i.cn)("table w-full table-auto p-4",n),children:t})})}},69193:(e,t,a)=>{"use strict";a.d(t,{W:()=>n});var s=a(33635),i=a(36202);let n=e=>{var t,a,n;let{userSlug:l,siteId:r,plantationsPolygonsId:o,areaId:d,accessToken:c}=e,m={authorization:"Bearer ".concat(c)}
1,u=!!d&&!!c,x=!!o&&!!d&&!!c,{data:h}=(0,s.Fbu)(l,r,{trancept_area_id:d,media_type:"image"},m,{query:{enabled:u}}),{data:g}=(0,s.Fbu)(l,r,{trancept_area_id:d,media_type:"video"},m,{query:{enabled:u}}),{data:p}=(0,s.uDx)(l,r,{trancept_area_id:d},m,{query:{enabled:u}}),{data:b}=(0,s.s0H)(l,r,o,{layer_type:(0,i.me)(d)},m,{query:{enabled:x}}),v=(0,i.me)(d);return{images:null!=(t=null==h?void 0:h.length)?t:0,videos:null!=(a=null==g?void 0:g.length)?a:0,notes:null!=(n=null==p?void 0:p.length)?n:0,pins:(null!=b?b:[]).filter(e=>e.layer_type===v).length}}},71152:(e,t,a)=>{"use strict";a.d(t,{Q:()=>b});var s=a(83815),i=a(28229),n=a(27492),l=a(24999),r=a(60938),o=a(45027),d=a(33635),c=a(24552),m=a(54002),u=a(99888),x=a(70679),h=a(94819),g=a(62476),p=a(43052);let b=()=>{let{t:e}=(0,m.A)("monitoring"),{query:t}=(0,u.useRouter)(),a=t.slug,b=Number(t.id),v=(0,n.r)(),{viewMode:f,selectedObservation:j,selectedMultiObservations:y,setSelectedMultiObservations:w,generateQueryKey:N,setEvent:k}=(0,i._R)(),{toast:_}=h.dj(),C=(0,c.useSession)(),{canEditSite:S}=(0,l.A)(),I=(0,o.jE)(),[A,z]=(0,x.useState)(!1),{mutateAsync:R,isLoading:D}=(0,d.JJA)({mutation:{onError:()=>{_({variant:"error",description:e("monitoring-observations:censuses.delete.error")})},onSuccess:()=>{_({variant:"success",description:e("monitoring-observations:censuses.delete.success")}),I.invalidateQueries(N(a,b,"observations_censuses")),I.invalidateQueries(N(a,b,"observations_statistics_charts")),I.invalidateQueries(N(a,b,"observations_statistics_charts_species")),I.invalidateQueries(N(a,b,"observations_statistics_charts_date")),I.invalidateQueries(N(a,b,"observations_statistics_grid"))}}}),{mutateAsync:M,isLoading:T}=(0,d.lhX)({mutation:{onError:()=>{_({variant:"error",description:e("monitoring-observations:censuses.delete.multi.error")})},onSuccess:()=>{_({variant:"success",description:e("monitoring-observations:censuses.delete.multi.success")}),w([]),I.invalidateQueries(N(a,b,"observations_censuses")),I.invalidateQueries(N(a,b,"observations_statistics_charts")),I.invalidateQueries(N(a,b,"observations_statistics_charts_species")),I.invalidateQueries(N(a,b,"observations_statistics_charts_date")),I.invalidateQueries(N(a,b,"observations_statistics_grid"))}}});if(!S)return null;let E="list"===f&&!j||"grid"===f&&!y.length;return(0,s.jsxs)(g.Root,{open:A,onOpenChange:z,children:[(0,s.jsx)(g.DialogTrigger,{asChild:!0,children:(0,s.jsx)(p.$,{variant:"text-only-error-600(base)",className:"!bg-transparent hover:!bg-transparent hover:!text-state-colors-error-300",disabled:E,children:(0,s.jsx)(r.In,{icon:"ph:trash",width:24,height:24})})}),(0,s.jsxs)(g.DialogContent,{variant:"light"===v?"default":"dark-mode-blue-1000",children:[(0,s.jsxs)(g.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(g.DialogTitle,{className:"!text-md font-bold ".concat("light"===v?"text-black":"text-white"),children:e("monitoring-observations:censuses.delete.title")}),(0,s.jsx)(g.DialogClose,{className:"self-start",children:(0,s.jsx)(r.In,{icon:"material-symbols:close",width:20,height:20,color:"light"===v?"black":"white"})})]}),(0,s.jsx)(g.DialogDescription,{className:"!text-sm font-normal ".concat("light"===v?"text-black":"text-white"),children:"list"===f?e("monitoring-observations:censuses.delete.description"):e("monitoring-observations:censuses.delete.multi.description",{count:y.length})}),(0,s.jsxs)(g.DialogFooter,{children:[(0,s.jsx)(g.DialogTrigger,{asChild:!0,children:(0,s.jsx)(p.$,{variant:"outline-error-600(base)",size:"xs",children:e("common:cancel")})}),(0,s.jsx)(p.$,{variant:"error-600(base)",size:"xs",disabled:D||T,onClick:()=>{var e,t,s;if(z(!1),"list"===f){if(!j)return;k({type:"deleting",observations:[j]}),R({userSlug:a,siteId:b,observationId:j.obs_id,params:{type:j.type,user_upload:null!=(t=j.user_upload)&&t},headers:{authorization:"Bearer ".concat(null==C||null==(e=C.data)?void 0:e.accessToken)}})}else k({type:"deleting",observations:y}),M({userSlug:a,siteId:b,data:y.map(e=>{var t;return{obs_id:e.obs_id,obs_type:e.type,user_upload:null!=(t=e.user_upload)&&t}}),headers:{authorization:"Bearer ".concat(null==C||null==(s=C.data)?void 0:s.accessToken)}})},children:e("monitoring-observations:censuses.delete.submit")})]})]})]})}},71342:(e,t,a)=>{"use strict";a.d(t,{M:()=>i});var s=a(70679);let i=e=>{let{accept:t,maxSize:a,maxFiles:i,onError:n}
1=e,[l,r]=(0,s.useState)([]),[o,d]=(0,s.useState)(null),c=(0,s.useCallback)(e=>{let s=null==t?void 0:t.split(",").map(e=>e.trim());if(s){let t=e.name.includes(".")?e.name.slice(e.name.lastIndexOf(".")).toLowerCase():"";if(!s.some(a=>a.startsWith(".")?t===a.toLowerCase():e.type.includes(a.replace("*",""))))return"formatNotAllowed"}return a&&e.size>1024*a*1024?"sizeExceeded":null},[t,a]),m=(0,s.useCallback)(e=>{r(l.filter((t,a)=>a!==e))},[l]);return(0,s.useEffect)(()=>{if(i&&l.length>i){d("maxFilesExceeded"),r(l.slice(0,i));return}l.forEach((e,t)=>{let a=c(e);if(a){d(a),r(l.filter((e,a)=>a!==t));return}})},[i,l,c]),(0,s.useEffect)(()=>{o&&n&&(n(o),d(null))},[o,n]),{files:l,setFiles:r,error:o,validateFile:c,removeFileByIndex:m}}},78646:(e,t,a)=>{"use strict";a.d(t,{U:()=>m});var s=a(83815),i=a(60938),n=a(54002),l=a(45954),r=a(17439);let o=["bassa","quasi_impossibile"],d={media:"border-amber-500/60 text-amber-500",bassa:"border-orange-500/70 text-orange-500",quasi_impossibile:"border-red-500/70 text-red-500"},c={media:"mdi:map-marker-question",bassa:"mdi:map-marker-alert",quasi_impossibile:"mdi:map-marker-remove"},m=e=>{var t,a,m;let{geoClass:u,geoReason:x,geoDistanceKm:h,variant:g="dark",compact:p=!1}=e,{t:b}=(0,n.A)(),v="presente_fuori_stagione"===x;if(!u||!o.includes(u)&&!("media"===u&&v))return null;let f=null!=h,j=b(v?"monitoring-observations:censuses.geo.label.outOfSeason":"monitoring-observations:censuses.geo.label.".concat(u)),y=v?b("monitoring-observations:censuses.geo.tooltip.outOfSeason"):b("monitoring-observations:censuses.geo.tooltip.".concat(u),{distance:f?Math.round(h).toLocaleString():"â"});return p?(0,s.jsxs)("div",{className:"pointer-events-auto relative hover:z-[9999]",role:"img","aria-label":j,children:[(0,s.jsx)(l.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"peer w-max ".concat(null!=(t=d[u])?t:""),children:(0,s.jsx)(i.In,{icon:v?"mdi:calendar-alert":null!=(a=c[u])?a:"mdi:map-marker-alert",width:16,height:16})}),(0,s.jsx)(r.A,{className:"pointer-events-none absolute right-0 top-full z-[99999] mt-2 w-52 whitespace-normal rounded-lg px-2 py-1 text-left text-xs leading-snug opacity-0 transition-opacity peer-hover:opacity-100 ".concat("light"===g?"bg-light-mode-black-100 text-light-mode-black-600(base)":"bg-dark-mode-blue-1100 text-dark-mode-blue-400"),description:y})]}):(0,s.jsxs)("div",{className:"pointer-events-auto relative hover:z-[9999]",children:[(0,s.jsx)(l.E,{variant:"darkModeBlue400",size:"xs",rounded:"lg",className:"peer !bg-transparent ".concat(null!=(m=d[u])?m:""),children:f&&!v?b("monitoring-observations:censuses.geo.badgeWithDistance",{label:j,distance:Math.round(h).toLocaleString()}):j}),(0,s.jsx)(r.A,{className:"pointer-events-none absolute bottom-full left-1/2 z-[99999] mb-2 w-64 -translate-x-1/2 whitespace-normal rounded-lg px-2 py-1 text-left text-xs leading-snug opacity-0 transition-opacity peer-hover:opacity-100 ".concat("light"===g?"bg-light-mode-black-100 text-light-mode-black-600(base)":"bg-dark-mode-blue-1100 text-dark-mode-blue-400"),description:y})]})}},79139:(e,t,a)=>{"use strict";a.d(t,{i:()=>i});var s=a(70679);let i=(e,t)=>{(0,s.useEffect)(()=>{let a=e.current;if(!a)return;let s=a.options.maxNativeZoom;if(s===t)return;a.options.maxNativeZoom=t;let i=a._map;if(!i)return;let n=i.getZoom();Math.min(n,null!=s?s:n)!==Math.min(n,t)&&i.fire("viewreset")},[e,t])}},80163:(e,t,a)=>{"use strict";a.d(t,{i:()=>r});var s=a(28229),i=a(66337),n=a(33635);let l={pages:[],pageParams:[],obs:[]},r=e=>{let{slug:t,siteId:a,filters:r,locale:o="it",accessToken:d,enabled:c=!0,queryKey:m,retry:u=!1,onSettled:x}=e,{isLoading:h,data:g=l,refetch:p,isFetching:b,hasNextPage:v,fetchNextPage:f}=(0,n.ktV)(t,a,{...r,exclude_taxa:s.Wg,pagination_limit:50}
1,{"accept-language":o,...d?{authorization:"Bearer ".concat(d)}:void 0},{query:{enabled:c,...m?{queryKey:m}:void 0,retry:u,select:e=>({...e,obs:e.pages.flat().filter(e=>"unknown"!==e.type).map(e=>({...e,id:"".concat(e.obs_id,"-").concat(e.type,"-").concat(e.user_upload),url:(0,i.V)(e.url)}))}),getNextPageParam:(e,t)=>e.length>0?t.length+1:void 0,...x?{onSettled:e=>x(e)}:void 0}});return{isLoading:h,data:g,refetch:p,isFetching:b,hasNextPage:v,fetchNextPage:f}}},82271:(e,t,a)=>{"use strict";a.r(t),a.d(t,{__N_SSP:()=>sq,default:()=>sV});var s=a(83815),i=a(58143),n=a(33635),l=a(24552),r=a(99888);let o=e=>{var t;let{query:a}=(0,r.useRouter)(),s=a.slug,i=Number(a.id),o=(0,l.useSession)(),{data:d,isLoading:c}=(0,n.Jlj)(s,i,null!=e?e:"",(null==(t=o.data)?void 0:t.accessToken)?{authorization:"Bearer ".concat(o.data.accessToken)}:void 0,{query:{enabled:!!e&&!!s&&!!i,refetchInterval:e=>{let t=null==e?void 0:e.status;return"completed"!==t&&"failed"!==t&&"partial"!==t&&3e3}}}),m=null==d?void 0:d.status,u="completed"===m||"failed"===m||"partial"===m;return{summary:d,isProcessing:!!e&&!u&&!c,isComplete:u,isLoading:c}};var d=a(60938),c=a(54002),m=a(70679),u=a(95001),x=a(62476),h=a(43052),g=a(10307);let p=(0,g.tv)({slots:{accent:"absolute bottom-0 left-0 top-0 w-[3px]",text:"",progress:"h-full transition-all",badge:"inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-semibold uppercase tracking-wide"},variants:{status:{pending:{accent:"bg-dark-mode-blue-1000",text:"text-dark-mode-blue-1000",progress:"bg-dark-mode-blue-1000",badge:"border-dark-mode-blue-1000 bg-dark-mode-blue-1000/15 text-dark-mode-blue-1000"},processing:{accent:"bg-primary-blue-300",text:"text-primary-blue-300",progress:"bg-primary-blue-300",badge:"border-primary-blue-300 bg-primary-blue-300/15 text-primary-blue-300"},completed:{accent:"bg-green-400",text:"text-green-400",progress:"bg-green-400",badge:"border-green-400 bg-green-400/15 text-green-400"},failed:{accent:"bg-red-400",text:"text-red-400",progress:"bg-red-400",badge:"border-red-400 bg-red-400/15 text-red-400"},partial:{accent:"bg-yellow-400",text:"text-yellow-400",progress:"bg-yellow-400",badge:"border-yellow-400 bg-yellow-400/15 text-yellow-400"}}},defaultVariants:{status:"pending"}}),b={single:"material-symbols:image",csv:"material-symbols:table-rows",gdrive:"material-symbols:folder"},v=e=>{var t,a,i,n,l,r,x;let{batch:h,title:g,onExpand:v,onDismiss:f}=e,{t:j}=(0,c.A)("monitoring"),{summary:y,isComplete:w,isProcessing:N}=o(h.batch_id),k=null!=(t=null==y?void 0:y.status)?t:h.status,_=null!=(a=null==y?void 0:y.progress_percent)?a:h.progress_percent,C=null!=(i=null==y?void 0:y.total_files)?i:h.total_files,S=null!=(n=null==y?void 0:y.success_count)?n:h.success_count,I=null!=(l=null==y?void 0:y.failed_count)?l:h.failed_count,A=null!=(r=null==y?void 0:y.pending_count)?r:h.pending_count,[z,R]=(0,m.useState)(null);(0,m.useEffect)(()=>{if("completed"!==k)return;R(5);let e=setInterval(()=>{R(e=>null!==e&&e>0?e-1:e)},1e3),t=setTimeout(()=>{f(h.batch_id)},5e3);return()=>{clearInterval(e),clearTimeout(t)}},[k,h.batch_id,f]);let{accent:D,text:M,progress:T,badge:E}=p({status:k}),L=j("monitoring-observations:upload.history.type".concat(h.upload_type.charAt(0).toUpperCase()).concat(h.upload_type.slice(1)));return(0,s.jsxs)("div",{className:"relative cursor-pointer overflow-hidden rounded-xl border border-dark-mode-blue-400 bg-dark-mode-blue-300 p-3 pl-4 shadow-lg transition-transform hover:-translate-y-0.5 hover:shadow-xl",onClick:e=>{e.target.closest("[data-card-action]")||v(h)},role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),v(h))},children:[(0,s.jsx)("span",{className:D(),"aria-hidden":!0}),(0,s.jsxs)("div",{className:"mb-2 flex items-start justify-between gap-2",children:[(0,s.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[(0,s.jsxs)("span",{className:E(),children:[(0,s.jsx)(d.In,{icon:null!=(x=b[h.upload_type])?x:"material-symbols:upload",width:12,height:12}),L]}),(0,s.jsx)("span",{className:"truncate text-sm font-medium text-white",title:g,children:g})]}),(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[(0,s.jsx)("button",{"data-card-action":!0,type:"button",onClick:e=>{e.stopPropagation(),v(h)},className:"flex h-7 w-7 items-center justify-center rounded-md text-dark-mode-blue-1000 hover:bg-dark-mode-blue-200 hover:text-white",title:j("monitoring-observations:upload.banner.viewDetails"),"aria-label":j("monitoring-observations:upload.banner.viewDetails"),children:(0,s.jsx)(d.In,{icon:"material-symbols:open-in-full",width:14,height:14})}),(0,s.jsx)("button",{"data-card-action":!0,type:"button",onClick:e=>{e.stopPropagation(),f(h.batch_id)},className:"flex h-7 w-7 items-center justify-center rounded-md text-dark-mode-blue-1000 hover:bg-dark-mode-blue-200 hover:text-white",title:j("monitoring-observations:upload.banner.dismiss"),"aria-label":j("monitoring-observations:upload.banner.dismiss"),children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:14,height:14})})]})]}),(0,s.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,s.jsxs)("span",{className:(0,u.cn)("inline-flex items-center gap-1.5 text-xs font-medium",M()),children:[N&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:14,height:14}),w&&"completed"===k&&(0,s.jsx)(d.In,{icon:"material-symbols:check-circle",width:14,height:14}),w&&"failed"===k&&(0,s.jsx)(d.In,{icon:"material-symbols:error",width:14,height:14}),w&&"partial"===k&&(0,s.jsx)(d.In,{icon:"material-symbols:warning",width:14,height:14}),j("monitoring-observations:upload.progress.".concat(k))]}),(0,s.jsxs)("span",{className:"text-xs tabular-nums text-dark-mode-blue-1000",children:[C>0&&j("monitoring-observations:upload.progress.filesProcessed",{current:S+I,total:C}),null!==z&&z>0&&(0,s.jsxs)("span",{className:"ml-1 text-green-400",children:["\xb7 ",j("monitoring-observations:upload.banner.autoDismiss",{seconds:z})]})]})]}),(0,s.jsx)("div",{className:"bg-dark-mode-blue-600 mb-2 h-1.5 w-full overflow-hidden rounded-full",children:(0,s.jsx)("div",{className:T(),style:{width:"".concat(_,"%")}})}),(S>0||I>0||A>0)&&(0,s.jsxs)("div",{className:"flex items-center gap-3 text-xs",children:[S>0&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-1 text-green-400",children:[(0,s.jsx)(d.In,{icon:"material-symbols:check-circle",width:12,height:12}),j("monitoring-observations:upload.progress.success",{count:S})]}),I>0&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-1 text-red-400",children:[(0,s.jsx)(d.In,{icon:"material-symbols:error",width:12,height:12}),j("monitoring-observations:upload.progress.failed_count",{count:I})]}),A>0&&(0,s.jsxs)("span",{className:"text-dark-mode-blue-1000",children:[j("monitoring-observations:upload.progress.pending"),": ",A]})]})]})};var f=a(53863),j=a(57548),y=a(90336);function w(e,t){let a=(0,f.Yx)(e);return a?(0,y.default)(a,"d MMM HH:mm",{locale:j.x8[t]}):null}let N="oasi.dismissedUploadBatches",k="oasi.uploadBatchTitles",_=(e,t)=>
1{try{let a=localStorage.getItem(e);return a?JSON.parse(a):t}catch(e){return t}},C=(e,t)=>{try{localStorage.setItem(e,JSON.stringify(t))}catch(e){}},S=(e,t)=>{let a=_(k,{});a[e]=t,C(k,a)},I=e=>{let t=null==e?void 0:e.status;return!!t&&t>=400&&t<500},A=()=>{var e;let{t}=(0,c.A)("monitoring"),{query:a,locale:i="it"}=(0,r.useRouter)(),o=a.slug,d=Number(a.id),u=(0,l.useSession)(),{dismissed:h,dismiss:g}=(()=>{let[e,t]=(0,m.useState)(new Set);return(0,m.useEffect)(()=>{t(new Set(_(N,[])))},[]),{dismissed:e,dismiss:(0,m.useCallback)(e=>{t(t=>{if(t.has(e))return t;let a=new Set(t);return a.add(e),C(N,[...a]),a})},[])}})(),[p,b]=(0,m.useState)(null),f=(null==(e=u.data)?void 0:e.accessToken)?{authorization:"Bearer ".concat(u.data.accessToken)}:void 0,{data:j=[]}=(0,n.t6g)(o,d,{limit:20},f,{query:{enabled:!!o&&!Number.isNaN(d),retry:(e,t)=>!I(t)&&e<2,refetchInterval:(e,t)=>!I(t.state.error)&&1e4,refetchIntervalInBackground:!1}}),y=(0,m.useMemo)(()=>j.filter(e=>!h.has(e.batch_id)),[j,h]),S=y.slice(0,3),A=y.length-S.length,z=e=>{var a;let s=(e=>{var t;return null!=(t=_(k,{})[e])?t:null})(e.batch_id);if(s)return s;let n=null!=(a=w(e.started_at,i))?a:"",l=t("monitoring-observations:upload.history.type".concat(e.upload_type.charAt(0).toUpperCase()).concat(e.upload_type.slice(1)));return n?"".concat(l," â ").concat(n):l};return 0===y.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"pointer-events-none fixed bottom-28 right-4 z-[12346] flex w-[calc(100%-32px)] max-w-[360px] flex-col gap-2 lg:bottom-4 lg:w-[360px]",role:"region","aria-label":t("monitoring-observations:upload.banner.regionLabel"),children:(0,s.jsxs)("div",{className:"pointer-events-auto flex flex-col gap-2",children:[S.map(e=>(0,s.jsx)(v,{batch:e,title:z(e),onExpand:b,onDismiss:g},e.batch_id)),A>0&&(0,s.jsx)("span",{className:"self-center rounded-full border border-dark-mode-blue-400 bg-dark-mode-blue-300 px-3 py-1 text-xs text-dark-mode-blue-1000",children:t("monitoring-observations:upload.banner.moreUploads",{count:A})})]})}),(0,s.jsx)(x.Root,{open:!!p,onOpenChange:e=>!e&&b(null),children:p&&(0,s.jsx)(D,{batch:p,title:z(p),onClose:()=>b(null)})})]})},z=(0,g.tv)({slots:{text:"",progress:"h-full transition-all",badge:"inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-semibold uppercase tracking-wide"},variants:{status:{pending:{text:"text-dark-mode-blue-1000",progress:"bg-dark-mode-blue-1000",badge:"border-dark-mode-blue-1000 bg-dark-mode-blue-1000/15 text-dark-mode-blue-1000"},processing:{text:"text-primary-blue-300",progress:"bg-primary-blue-300",badge:"border-primary-blue-300 bg-primary-blue-300/15 text-primary-blue-300"},completed:{text:"text-green-400",progress:"bg-green-400",badge:"border-green-400 bg-green-400/15 text-green-400"},failed:{text:"text-red-400",progress:"bg-red-400",badge:"border-red-400 bg-red-400/15 text-red-400"},partial:{text:"text-yellow-400",progress:"bg-yellow-400",badge:"border-yellow-400 bg-yellow-400/15 text-yellow-400"}}},defaultVariants:{status:"pending"}}),R={single:"material-symbols:image",csv:"material-symbols:table-rows",gdrive:"material-symbols:folder"},D=e=>{var t,a,i,n,l,m,g;let{batch:p,title:b,onClose:v}=e,{t:f}=(0,c.A)("monitoring"),{locale:j="it"}=(0,r.useRouter)(),{summary:y,isComplete:N,isProcessing:k}=o(p.batch_id),_=null!=(t=null==y?void 0:y.status)?t:p.status,C=null!=(a=null==y?void 0:y.progress_percent)?a:p.progress_percent,S=null!=(i=null==y?void 0:y.total_files)?i:p.total_files,I=null!=(n=null==y?void 0:y.success_count)?n:p.success_count,A=null!=(l=null==y?void 0:y.failed_count)?l:p.failed_count,D=null!=(m=null==y?void 0:y.pending_count)?m:p.pending_count,{text:M,progress:T,badge:E}=z({status:_}),L=f("monitoring-observations:upload.history.type".concat(p.upload_type.charAt(0).toUpperCase()).concat(p.upload_type.slice(1))),F=w(p.started_at,j);return(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"sm:min-w-[500px]",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,s.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsxs)("span",{className:E(),children:[(0,s.jsx)(d.In,{icon:null!=(g=R[p.upload_type])?g:"material-symbols:upload",width:12,height:12}),L]}),F&&(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-1000",children:F})]}),(0,s.jsx)(x.DialogTitle,{className:"truncate !text-md font-bold text-white",title:b,children:b})]}),(0,s.jsx)(x.DialogClose,{onClick:v,className:"shrink-0 text-dark-mode-blue-1000 hover:text-white",children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20})})]}),(0,s.jsx)(x.DialogDescription,{className:"text-sm text-dark-mode-blue-1000",children:f("monitoring-observations:upload.progress.batchDescription")})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("span",{className:(0,u.cn)("inline-flex items-center gap-2 text-sm font-medium",M()),children:[k&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:18,height:18}),N&&"completed"===_&&(0,s.jsx)(d.In,{icon:"material-symbols:check-circle",width:18,height:18}),N&&"failed"===_&&(0,s.jsx)(d.In,{icon:"material-symbols:error",width:18,height:18}),N&&"partial"===_&&(0,s.jsx)(d.In,{icon:"material-symbols:warning",width:18,height:18}),f("monitoring-observations:upload.progress.".concat(_))]}),S>0&&(0,s.jsx)("span",{className:"text-sm tabular-nums text-dark-mode-blue-1000",children:f("monitoring-observations:upload.progress.filesProcessed",{current:I+A,total:S})})]}),(0,s.jsx)("div",{className:"bg-dark-mode-blue-600 h-2 w-full overflow-hidden rounded-full",children:(0,s.jsx)("div",{className:T(),style:{width:"".concat(C,"%")}})}),(I>0||A>0||D>0)&&(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1 text-sm",children:[I>0&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-1 text-green-400",children:[(0,s.jsx)(d.In,{icon:"material-symbols:check-circle",width:14,height:14}),f("monitoring-observations:upload.progress.success",{count:I})]}),A>0&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-1 text-red-400",children:[(0,s.jsx)(d.In,{icon:"material-symbols:error",width:14,height:14}),f("monitoring-observations:upload.progress.failed_count",{count:A})]}),D>0&&(0,s.jsxs)("span",{className:"text-dark-mode-blue-1000",children:[f("monitoring-observations:upload.progress.pending"),": ",D]})]})]}),(0,s.jsx)(x.DialogFooter,{children:(0,s.jsx)(h.$,{variant:"monitoring-600(base)",className:"w-full",onClick:v,children:f("monitoring-observations:upload.close")})})]})};var M=a(20151),T=a(75258),E=a.n(T),L=a(28229),F=a(59039),O=a(13312),B=a(43732),P=a(95007),U=a(27492),H=a(37302),q=a(60620),V=a(45954);function W(e){let{isOpen:t,onClose:a,title:i,subtitle:n,images:l,isLoading:r=!1,totalCount:o,isAlien:m,isEndemic:u}=e,{t:h}=(0,c.A)("monitoring");return(0,s.jsx)(x.Root,{open:t,onOpenChange:e=>!e&&a(),children:(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"w-[95vw] overflow-hidden lg:w-[50vw]",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-start justify-between gap-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(x.DialogTitle,{className:"text-base font-bold text-white",children:i}),m&&(0,s.jsx)(V.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"text-xs",children:h("monitoring-observations:statistics.alien")}),u&&(0,s.jsx)(V.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:"text-xs",children:h("monitoring-observations:statistics.endemic")})]}),n&&(0,s.jsx)("p",{className:"text-sm text-primary-blue-300",children:n}),void 0!==o&&(0,s.jsx)("p",{className:"text-primary-blue-400 text-xs",children:h("monitoring-observations:summary.topSpecies.totalObservations",{count:o})})]}),(0,s.jsx)(x.DialogClose,{className:"shrink-0 text-white/60 hover:text-white",children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20})})]}),(0,s.jsx)("div",{className:"mt-4 w-full overflow-hidden",children:r?(0,s.jsx)("div",{className:"flex h-40 items-center justify-center",children:(0,s.jsx)(d.In,{icon:"mdi:loading",className:"h-8 w-8 animate-spin text-primary-blue-300"})}):0===l.length?(0,s.jsxs)("div",{className:"flex h-40 flex-col items-center justify-center gap-2 text-primary-blue-300",children:[(0,s.jsx)(d.In,{icon:"mdi:image-off-outline",className:"h-12 w-12 opacity-50"}),(0,s.jsx)("p",{className:"text-sm",children:h("monitoring-observations:summary.topSpecies.noImages")})]}):(0,s.jsx)(q.g,{images:l,isLoading:r,className:"w-full [&>div:first-child]:h-64"})})]})})}function $(e){var t;let{subpolygonIdx:a,conservationStatus:s,iconicTaxa:i,enabled:o=!0,limit:d=50}=e,{locale:c="it",query:u}=(0,r.useRouter)(),x=u.slug,h=Number(u.id),g=(0,l.useSession)(),{device:p,filterDate:b,filterSpecies:v,filterSubSpecies:f,filterFamily:j,filterGenre:w,filterOrder:N,filterIndex:k,minimumConfidenceValue:_}=(0,L._R)(),C=(0,m.useMemo)(()=>({...null!==a&&{subpolygon_idx:a.toString()},...p&&{hive_ids:p.id.toString()},...b.from&&{date_from:(0,y.default)(b.from,"yyyy-MM-dd")},...b.to&&{date_to:(0,y.default)(b.to,"yyyy-MM-dd")},...i?{iconic_taxa:i}:v.size>0&&{iconic_taxa:Array.from(v.keys()).join(",")},...f.size>0&&{taxa:Array.from(f.keys()).join(",")},...j.size>0&&{family_taxa:Array.from(j.keys()).join(",")},...w.size>0&&{genus_taxa:Array.from(w.keys()).join(",")},...N.size>0&&{order_taxa:Array.from(N.keys()).join(",")},...k&&{index_id:k.id},..._&&{min_confidence:_},pagination_limit:d}),[a,p,b,i,v,f,j,w,N,k,_,d]),S=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==g||null==(e=g.data)?void 0:e.accessToken),"accept-language":c}},[null==g||null==(t=g.data)?void 0:t.accessToken,c]),{data:I,isLoading:A,error:z}=(0,n.ktV)(x,h,C,S,{query:{enabled:o&&!!x&&!!h&&null!==a,getNextPageParam:()=>void 0}}),R=(0,m.useMemo)(()=>(null==I?void 0:I.pages)?I.pages.flat():[],[null==I?void 0:I.pages]);return{images:(0,m.useMemo)(()=>R.filter(e=>("image"===e.type||"video"===e.type)&&!!e.url&&(!s||e.conservation_status===s)).sort((e,t)=>
1new Date(t.record_date).getTime()-new Date(e.record_date).getTime()).map(e=>{var t,a,s,i;return{id:e.obs_id.toString(),url:"video"===e.type&&e.url?e.url.replace(/\.mp4$/,".jpg"):null!=(s=e.url)?s:"",date:e.record_date,taxa:null!=(i=null==(t=e.taxa)?void 0:t.taxa)?i:null==(a=e.taxa)?void 0:a.latin_taxa}}),[R,s]),isLoading:A,error:z,totalObservations:R.length}}function Q(e){var t;let{transectId:a,isAlien:s,isEndemic:i,conservationStatus:o,iconicTaxa:d,enabled:c=!0,limit:u=50}=e,{locale:x="it",query:h}=(0,r.useRouter)(),g=h.slug,p=Number(h.id),b=(0,l.useSession)(),{device:v,filterDate:f,filterSpecies:j,filterSubSpecies:w,filterFamily:N,filterGenre:k,filterOrder:_,filterIndex:C,minimumConfidenceValue:S}=(0,L._R)(),I=(0,m.useMemo)(()=>({...a&&{trancept_ids:a.toString()},...v&&{hive_ids:v.id.toString()},...f.from&&{date_from:(0,y.default)(f.from,"yyyy-MM-dd")},...f.to&&{date_to:(0,y.default)(f.to,"yyyy-MM-dd")},...d?{iconic_taxa:d}:j.size>0&&{iconic_taxa:Array.from(j.keys()).join(",")},...w.size>0&&{taxa:Array.from(w.keys()).join(",")},...N.size>0&&{family_taxa:Array.from(N.keys()).join(",")},...k.size>0&&{genus_taxa:Array.from(k.keys()).join(",")},..._.size>0&&{order_taxa:Array.from(_.keys()).join(",")},...C&&{index_id:C.id},...S&&{min_confidence:S},pagination_limit:u}),[a,v,f,d,j,w,N,k,_,C,S,u]),A=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==b||null==(e=b.data)?void 0:e.accessToken),"accept-language":x}},[null==b||null==(t=b.data)?void 0:t.accessToken,x]),{data:z,isLoading:R,error:D}=(0,n.ktV)(g,p,I,A,{query:{enabled:c&&!!g&&!!p&&!!a,getNextPageParam:()=>void 0}}),M=(0,m.useMemo)(()=>(null==z?void 0:z.pages)?z.pages.flat():[],[null==z?void 0:z.pages]);return{images:(0,m.useMemo)(()=>M.filter(e=>("image"===e.type||"video"===e.type)&&!!e.url&&(!0!==s||!0===e.is_alien)&&(!1!==s||!0!==e.is_alien)&&(!0!==i||!0===e.is_endemic)&&(!1!==i||!0!==e.is_endemic)&&(!o||e.conservation_status===o)&&!0).sort((e,t)=>new Date(t.record_date).getTime()-new Date(e.record_date).getTime()).map(e=>{var t,a,s,i;return{id:e.obs_id.toString(),url:"video"===e.type&&e.url?e.url.replace(/\.mp4$/,".jpg"):null!=(s=e.url)?s:"",date:e.record_date,taxa:null!=(i=null==(t=e.taxa)?void 0:t.taxa)?i:null==(a=e.taxa)?void 0:a.latin_taxa}}),[M,s,i,o]),isLoading:R,error:D,totalObservations:M.length}}var G=a(40817),K=a(67556),Z=a(24999),J=a(20859),Y=a(54066),X=a(33423),ee=a(83797),et=a.n(ee);let ea={alien:"#DB6D28"},es={Aves:"#3B82F6",Insecta:"#F59E0B",Mammalia:"#8B5CF6",Reptilia:"#10B981",Amphibia:"#06B6D4",Arachnida:"#EF4444",Plantae:"#22C55E",Fungi:"#A855F7",default:"#238636"};function ei(e){return e.includes(",")||e.includes('"')||e.includes("\n")||e.includes("\r")?'"'.concat(e.replace(/"/g,'""'),'"'):e}let en={native:"#3FB950",alien:"#DB6D28"};function el(e){return e.map(e=>{var t;return null!=(t=e.trancept_areas_name)?t:"T".concat(e.trancept_area_id)})}let er=["CR","EN","VU","NT","LC","DD","NE"],eo=["Insecta","Aves","Plantae","Mammalia","Reptilia","Amphibia","Arachnida","Fungi"];var ed=a(12259),ec=a(99101),em=a(92994);let eu=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:18;return e.length<=t?e:"".concat(e.substring(0,t),"â¦")},ex=e=>{let{labels:t,entityIds:a,entityType:i,datasets:n,width:l,height:r,variant:o,onBarClick:d}=e,{t:u}=(0,c.A)("monitoring"),{observe:x,inView:h}=(0,ec.W)({threshold:.5,unobserveOnEnter:!0}),g="dark"===o?ed.$8:"#333333",p="dark"===o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.1)",b=(0,m.useMemo)(()=>t.map(e=>eu(e)),[t]),v=(0,m.useMemo)(()=>n.map(e=>({label:u("monitoring-observations:summary.biodiversityAnalysis.conservationStatus.statuses.".concat(e.status),{},{default:e.status}),data:e.data,backgroundColor:e.color,hoverBackgroundColor:e.color,borderRadius:4,barPercentage:.75,categoryPercentage:.8})),[n,u]),f=(0,m.useMemo)(()=>Math.ceil(1.15*Math.max(...t.map((e,t)=>n.reduce((e,a)=>e+(a.data[t]||0),0)),0))||10,[t,n]),j=(0,m.useMemo)(()=>({responsive:!1,maintainAspectRatio:!1,indexAxis:"x",scales:{x:{stacked:!0,grid:{display:!1},ticks:{color:g,font:{size:11,weight:"500"},maxRotation:45,minRotation:0},border:{display:!1}},y:{stacked:!0,min:0,max:f,grid:{color:p,lineWidth:1},ticks:{color:g,font:{size:11},stepSize:Math.ceil(f/5)},border:{display:!1}}}
1,plugins:{legend:{display:!0,position:"bottom",labels:{color:g,font:{size:11},boxWidth:12,boxHeight:12,padding:12,usePointStyle:!0,pointStyle:"rectRounded"}},tooltip:{enabled:!0,backgroundColor:"rgba(15, 23, 42, 0.95)",titleColor:"#fff",titleFont:{size:13,weight:"bold"},bodyColor:"#e2e8f0",bodyFont:{size:12},borderColor:"rgba(255, 255, 255, 0.1)",borderWidth:1,padding:12,cornerRadius:8,displayColors:!0,boxPadding:4,callbacks:{title:e=>{var a;let s=null==(a=e[0])?void 0:a.dataIndex;return void 0!==s?t[s]:""},label:e=>{let t=e.dataset.label||"",a=e.parsed.y;return" ".concat(t,": ").concat(a)},afterBody:e=>{var t;let a=null==(t=e[0])?void 0:t.dataIndex;if(void 0===a)return"";let s=n.reduce((e,t)=>e+(t.data[a]||0),0);return"\n".concat(u("monitoring-observations:summary.biodiversityAnalysis.conservationStatus.total"),": ").concat(s)}}},datalabels:{display:!1}},animation:{duration:800,easing:"easeOutQuart"},hover:{mode:"index",intersect:!1},onClick:(e,s)=>{if(s.length>0&&d){var l,r;let e=s[0],o=e.index,c=e.datasetIndex,m=a[o];d({entityId:m,entityName:t[o],entityType:i,conservationStatus:null!=(r=null==(l=n[c])?void 0:l.status)?r:""})}},onHover:(e,t)=>{var a;let s=null==(a=e.native)?void 0:a.target;s&&(s.style.cursor=t.length>0&&d?"pointer":"default")}}),[g,p,f,t,n,u,a,i,d]);return t.length&&n.length?(0,s.jsx)("div",{ref:x,style:{width:l,height:r},children:h&&(0,s.jsx)(em.Es,{width:l,height:r,options:j,labels:b,datasets:v})}):null},eh=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:18;return e.length<=t?e:"".concat(e.substring(0,t),"â¦")},eg=e=>{let{labels:t,entityIds:a,entityType:i,datasets:n,width:l,height:r,variant:o,onBarClick:d}=e,{t:u}=(0,c.A)("monitoring"),{observe:x,inView:h}=(0,ec.W)({threshold:.5,unobserveOnEnter:!0}),g="dark"===o?ed.$8:"#333333",p="dark"===o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.1)",b=(0,m.useMemo)(()=>t.map(e=>eh(e)),[t]),v=(0,m.useMemo)(()=>n.map(e=>({label:u("monitoring-observations:summary.biodiversityAnalysis.iconicTaxaDistribution.taxa.".concat(e.iconicTaxa),{},{default:e.iconicTaxa}),data:e.data,backgroundColor:e.color,hoverBackgroundColor:e.color,borderRadius:4,barPercentage:.75,categoryPercentage:.8})),[n,u]),f=(0,m.useMemo)(()=>Math.ceil(1.15*Math.max(...t.map((e,t)=>n.reduce((e,a)=>e+(a.data[t]||0),0)),0))||10,[t,n]),j=(0,m.useMemo)(()=>({responsive:!1,maintainAspectRatio:!1,indexAxis:"x",scales:{x:{stacked:!0,grid:{display:!1},ticks:{color:g,font:{size:11,weight:"500"},maxRotation:45,minRotation:0},border:{display:!1}},y:{stacked:!0,min:0,max:f,grid:{color:p,lineWidth:1},ticks:{color:g,font:{size:11},stepSize:Math.ceil(f/5)},border:{display:!1}}},plugins:{legend:{display:!0,position:"bottom",labels:{color:g,font:{size:11},boxWidth:12,boxHeight:12,padding:12,usePointStyle:!0,pointStyle:"rectRounded"}},tooltip:{enabled:!0,backgroundColor:"rgba(15, 23, 42, 0.95)",titleColor:"#fff",titleFont:{size:13,weight:"bold"},bodyColor:"#e2e8f0",bodyFont:{size:12},borderColor:"rgba(255, 255, 255, 0.1)",borderWidth:1,padding:12,cornerRadius:8,displayColors:!0,boxPadding:4,callbacks:{title:e=>{var a;let s=null==(a=e[0])?void 0:a.dataIndex;return void 0!==s?t[s]:""},label:e=>{let t=e.dataset.label||"",a=e.parsed.y;return" ".concat(t,": ").concat(a)},afterBody:e=>{var t;let a=null==(t=e[0])?void 0:t.dataIndex;if(void 0===a)return"";let s=n.reduce((e,t)=>e+(t.data[a]||0),0);return"\n".concat(u("monitoring-observations:summary.biodiversityAnalysis.iconicTaxaDistribution.total"),": ").concat(s)}}},datalabels:{display:!1}},animation:{duration:800,easing:"easeOutQuart"},hover:{mode:"index",intersect:!1},onClick:(e,s)=>{if(s.length>0&&d){var l,r;let e=s[0],o=e.index,c=e.datasetIndex,m=a[o];d({entityId:m,entityName:t[o],entityType:i,iconicTaxa:null!=(r=null==(l=n[c])?void 0:l.iconicTaxa)?r:""})}},onHover:(e,t)=>{var a;let s=null==(a=e.native)?void 0:a.target;s&&(s.style.cursor=t.length>0&&d?"pointer":"default")}}),[g,p,f,t,n,u,a,i,d]);return t.length&&n.length?(0,s.jsx)("div",{ref:x,style:{width:l,height:r},children:h&&(0,s.jsx)(em.Es,{width:l,height:r,options:j,labels:b,datasets:v})}):null};var ep=a(16074);let eb=(0,g.tv)({slots:{root:"flex-nowrap gap-0 rounded-lg border",item:"h-max w-max rounded-none px-3 py-1.5 text-sm font-medium transition-colors",itemFirst:"rounded-l-lg",itemLast:"rounded-r-lg"},variants:{variant:{dark:{root:"border-dark-mode-blue-600",item:"text-primary-blue-300 data-[state=on]:bg-dark-mode-blue-600 data-[state=on]:text-white"},light:{root:"border-light-mode-black-400",item:"text-light-mode-black-600(base) data-[state=on]:bg-light-mode-black-200 data-[state=on]:text-3bee-black"}}},defaultVariants:{variant:"dark"}}),ev=e=>{let{viewMode:t,setViewMode:a,variant:i}=e,{t:n}=(0,c.A)("monitoring"),l=eb({variant:i});return(0,s.jsxs)(ep.bL,{type:"single",value:t,onValueChange:e=>{e&&a(e)},className:l.root(),children:[(0,s.jsx)(ep.q7,{value:"transects",className:(0,u.cn)(l.item(),l.itemFirst()),children:n("monitoring-observations:summary.biodiversityAnalysis.viewToggle.transects")}),(0,s.jsx)(ep.q7,{value:"subpolygons",className:(0,u.cn)(l.item(),l.itemLast()),children:n("monitoring-observations:summary.biodiversityAnalysis.viewToggle.subpolygons")})]})},ef=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:12;return e.length<=t?e:"".concat(e.substring(0,t),"â¦")},ej={shannon:{thresholds:{low:1.5,medium:2.5,high:3.5},maxValue:4.5},simpson:{thresholds:{low:.3,medium:.6,high:.8},maxValue:1},evenness:{thresholds:{low:.3,medium:.6,high:.8},maxValue:1}},ey=e=>{let{labels:t,data:a,indexType:i,width:n,height:l,variant:r}=e,{observe:o,inView:d}=(0,ec.W)({threshold:.5,unobserveOnEnter:!0}),c="dark"===r?ed.$8:"#333333",u="dark"===r?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.1)",x=ej[i],h=(0,m.useMemo)(()=>t.map(e=>ef(e)),[t]),g=(0,m.useMemo)(()=>
1{if("undefined"==typeof document)return"#22C55E";let e=document.createElement("canvas").getContext("2d");if(!e)return"#22C55E";let t=e.createLinearGradient(0,0,0,l);return t.addColorStop(0,"#4ADE80"),t.addColorStop(1,"#16A34A"),t},[l]),p=(0,m.useMemo)(()=>[{label:i,data:a.map(e=>null!=e?e:0),backgroundColor:g,hoverBackgroundColor:"#86EFAC",borderRadius:6,barPercentage:.65,categoryPercentage:.85}],[a,i,g]),b=(0,m.useMemo)(()=>({responsive:!1,maintainAspectRatio:!1,scales:{x:{grid:{display:!1},ticks:{color:c,font:{size:9,weight:"500"},maxRotation:45,minRotation:0},border:{display:!1}},y:{min:0,max:x.maxValue,grid:{color:u,lineWidth:1},ticks:{color:c,font:{size:10},stepSize:x.maxValue/4},border:{display:!1}}},plugins:{legend:{display:!1},tooltip:{enabled:!0,backgroundColor:"rgba(15, 23, 42, 0.95)",titleColor:"#fff",titleFont:{size:12,weight:"bold"},bodyColor:"#e2e8f0",bodyFont:{size:11},borderColor:"rgba(255, 255, 255, 0.1)",borderWidth:1,padding:10,cornerRadius:6,callbacks:{title:e=>{var a;let s=null==(a=e[0])?void 0:a.dataIndex;return void 0!==s?t[s]:""},label:e=>{let t=e.parsed.y;return" ".concat(t.toFixed(3))}}},datalabels:{display:!0,color:"#fff",font:{size:9,weight:"bold"},anchor:"end",align:"end",offset:-2,formatter:e=>"number"==typeof e?e.toFixed(2):e}},animation:{duration:800,easing:"easeOutQuart"},hover:{mode:"index",intersect:!1}}),[c,u,x.maxValue,t]);return t.length?(0,s.jsx)("div",{ref:o,style:{width:n,height:l},children:d&&(0,s.jsx)(em.Es,{width:n,height:l,options:b,labels:h,datasets:p})}):null},ew=(0,g.tv)({slots:{wrapper:"flex flex-col gap-4",container:"grid grid-cols-1 gap-4 md:grid-cols-3",chartCard:"flex flex-col gap-2 rounded-lg p-3",header:"flex items-center justify-between",title:"text-sm font-semibold",badge:"text-xs font-medium",chartContainer:"flex-1",legend:"flex flex-wrap items-center justify-center gap-x-6 gap-y-2 rounded-lg p-3 text-xs",legendItem:"flex items-center gap-2",legendDot:"h-2.5 w-2.5 rounded-full",legendText:""},variants:{variant:{dark:{chartCard:"bg-dark-mode-blue-400",title:"text-white",badge:"bg-dark-mode-blue-600 text-primary-blue-300",legend:"bg-dark-mode-blue-400",legendText:"text-primary-blue-300"},light:{chartCard:"bg-light-mode-black-100 border border-light-mode-black-300",title:"text-3bee-black",badge:"bg-light-mode-black-200 text-light-mode-black-600(base)",legend:"bg-light-mode-black-100 border border-light-mode-black-300",legendText:"text-light-mode-black-600(base)"}}},defaultVariants:{variant:"dark"}}),eN=e=>{let{labels:t,shannon:a,simpson:i,evenness:n,variant:l}=e,{t:r}=(0,c.A)("monitoring"),o=ew({variant:l}),[d,u]=(0,m.useState)(null),[x,h]=(0,m.useState)(null),[g,p]=(0,m.useState)(null),{width:b=0}=(0,J.w)({ref:{current:d}}),{width:v=0}=(0,J.w)({ref:{current:x}}),{width:f=0}=(0,J.w)({ref:{current:g}});return t.length>0?(0,s.jsxs)("div",{className:o.wrapper(),children:[(0,s.jsxs)("div",{className:o.container(),children:[(0,s.jsxs)("div",{className:o.chartCard(),children:[(0,s.jsxs)("div",{className:o.header(),children:[(0,s.jsxs)("span",{className:o.title(),children:[r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.shannon.title")," (H')"]}),(0,s.jsx)(V.E,{rounded:"md",className:o.badge(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.shannon.badge")})]}),(0,s.jsx)("div",{ref:u,className:o.chartContainer(),style:{minHeight:180},children:b>0&&(0,s.jsx)(ey,{labels:t,data:a,indexType:"shannon",width:b,height:180,variant:l})})]}),(0,s.jsxs)("div",{className:o.chartCard(),children:[(0,s.jsxs)("div",{className:o.header(),children:[(0,s.jsxs)("span",{className:o.title(),children:[r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.simpson.title")," (D)"]}),(0,s.jsx)(V.E,{rounded:"md",className:o.badge(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.simpson.badge")})]}),(0,s.jsx)("div",{ref:h,className:o.chartContainer(),style:{minHeight:180},children:v>0&&(0,s.jsx)(ey,{labels:t,data:i,indexType:"simpson",width:v,height:180,variant:l})})]}),(0,s.jsxs)("div",{className:o.chartCard(),children:[(0,s.jsxs)("div",{className:o.header(),children:[(0,s.jsxs)("span",{className:o.title(),children:[r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.evenness.title")," (J)"]}
1),(0,s.jsx)(V.E,{rounded:"md",className:o.badge(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.evenness.badge")})]}),(0,s.jsx)("div",{ref:p,className:o.chartContainer(),style:{minHeight:180},children:f>0&&(0,s.jsx)(ey,{labels:t,data:n,indexType:"evenness",width:f,height:180,variant:l})})]})]}),(0,s.jsxs)("div",{className:o.legend(),children:[(0,s.jsxs)("div",{className:o.legendItem(),children:[(0,s.jsx)("span",{className:o.legendDot(),style:{backgroundColor:"#EF4444"}}),(0,s.jsx)("span",{className:o.legendText(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.diversityLegend.low")})]}),(0,s.jsxs)("div",{className:o.legendItem(),children:[(0,s.jsx)("span",{className:o.legendDot(),style:{backgroundColor:"#EAB308"}}),(0,s.jsx)("span",{className:o.legendText(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.diversityLegend.medium")})]}),(0,s.jsxs)("div",{className:o.legendItem(),children:[(0,s.jsx)("span",{className:o.legendDot(),style:{backgroundColor:"#22C55E"}}),(0,s.jsx)("span",{className:o.legendText(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.diversityLegend.high")})]})]}),(0,s.jsxs)("div",{className:o.legend(),children:[(0,s.jsxs)("div",{className:o.legendItem(),children:[(0,s.jsx)("span",{className:o.legendDot(),style:{backgroundColor:"#22C55E"}}),(0,s.jsx)("span",{className:o.legendText(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.simpsonLegend.low")})]}),(0,s.jsxs)("div",{className:o.legendItem(),children:[(0,s.jsx)("span",{className:o.legendDot(),style:{backgroundColor:"#EAB308"}}),(0,s.jsx)("span",{className:o.legendText(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.simpsonLegend.medium")})]}),(0,s.jsxs)("div",{className:o.legendItem(),children:[(0,s.jsx)("span",{className:o.legendDot(),style:{backgroundColor:"#EF4444"}}),(0,s.jsx)("span",{className:o.legendText(),children:r("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.simpsonLegend.high")})]})]})]}):null},ek=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:18;return e.length<=t?e:"".concat(e.substring(0,t),"â¦")},e_=e=>{let{labels:t,nativeData:a,alienData:i,transectIds:n,width:l,height:r,variant:o,onBarClick:d}=e,{t:u}=(0,c.A)("monitoring"),{observe:x,inView:h}=(0,ec.W)({threshold:.5,unobserveOnEnter:!0}),g="dark"===o?ed.$8:"#333333",p="dark"===o?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.1)",b=(0,m.useMemo)(()=>{if("undefined"==typeof document)return en.native;let e=document.createElement("canvas").getContext("2d");if(!e)return en.native;let t=e.createLinearGradient(0,0,0,r);return t.addColorStop(0,"#4ADE80"),t.addColorStop(1,"#22C55E"),t},[r]),v=(0,m.useMemo)(()=>{if("undefined"==typeof document)return en.alien;let e=document.createElement("canvas").getContext("2d");if(!e)return en.alien;let t=e.createLinearGradient(0,0,0,r);return t.addColorStop(0,"#FB923C"),t.addColorStop(1,"#EA580C"),t},[r]),f=(0,m.useMemo)(()=>t.map(e=>ek(e)),[t]),j=(0,m.useMemo)(()=>[{label:u("monitoring-observations:summary.biodiversityAnalysis.nativeAlien.native"),data:a,backgroundColor:b,hoverBackgroundColor:"#86EFAC",borderRadius:6,barPercentage:.75,categoryPercentage:.8},{label:u("monitoring-observations:summary.biodiversityAnalysis.nativeAlien.alien"),data:i,backgroundColor:v,hoverBackgroundColor:"#FDBA74",borderRadius:{topLeft:6,topRight:6,bottomLeft:0,bottomRight:0},barPercentage:.75,categoryPercentage:.8}],[a,i,b,v,u]),y=(0,m.useMemo)(()=>Math.ceil(1.15*Math.max(...a.map((e,t)=>e+(i[t]||0)),0))||10,[a,i]),w=(0,m.useMemo)(()=>({responsive:!1,maintainAspectRatio:!1,indexAxis:"x",scales:{x:{stacked:!0,grid:{display:!1},ticks:{color:g,font:{size:11,weight:"500"},maxRotation:45,minRotation:0},border:{display:!1}},y:{stacked:!0,min:0,max:y,grid:{color:p,lineWidth:1},ticks:{color:g,font:{size:11},stepSize:Math.ceil(y/5)},border:{display:!1}}},plugins:{legend:{display:!1},tooltip:{enabled:!0,backgroundColor:"rgba(15, 23, 42, 0.95)",titleColor:"#fff",titleFont:{size:13,weight:"bold"},bodyColor:"#e2e8f0",bodyFont:{size:12},borderColor:"rgba(255, 255, 255, 0.1)",borderWidth:1,padding:12,cornerRadius:8,displayColors:!0,boxPadding:4,callbacks:{title:e=>{var a;let s=null==(a=e[0])?void 0:a.dataIndex;return void 0!==s?t[s]:""},label:e=>{let t=e.dataset.label||"",a=e.parsed.y;return" ".concat(t,": ").concat(a)},afterBody:e=>{var t;let s=null==(t=e[0])?void 0:t.dataIndex;if(void 0===s)return"";let n=a[s]+(i[s]||0);return"\n".concat(u("monitoring-observations:summary.biodiversityAnalysis.nativeAlien.total"),": ").concat(n)}}},datalabels:{display:!0,color:"#fff",font:{size:10,weight:"bold"},anchor:"end",align:"end",offset:-2,formatter:(e,t)=>1===t.datasetIndex?(a[t.dataIndex]||0)+e:0!==t.datasetIndex||i[t.dataIndex]?"":e}},animation:{duration:800,easing:"easeOutQuart"},hover:{mode:"index",intersect:!1},onClick:(e,a)=>{if(a.length>0&&d){let e=a[0],s=e.index,i=e.datasetIndex,l=n[s];d({transectId:l,transectName:t[s],isAlien:1===i})}},onHover:(e,t)=>{var a;let s=null==(a=e.native)?void 0:a.target;s&&(s.style.cursor=t.length>0&&d?"pointer":"default")}}),[g,p,y,t,a,i,u,n,d]);return t.length?(0,s.jsx)("div",{ref:x,style:{width:l,height:r},children:h&&(0,s.jsx)(em.Es,{width:l,height:r,options:w,labels:f,datasets:j})}):null},eC=(0,g.tv)({slots:{container:"flex flex-col gap-6 rounded-xl p-4 lg:p-5",header:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",headerLeft:"flex flex-col gap-1",title:"flex items-center gap-2 text-lg font-bold",subtitle:"text-sm",sectionTitle:"mb-3 text-base font-semibold",section:"flex flex-col gap-3",legend:"flex items-center gap-4",legendItem:"flex items-center gap-2 text-xs",legendDot:"h-3 w-3 rounded-full",chartContainer:"w-full",emptyState:"flex h-48 items-center justify-center text-sm"},variants:{variant:{dark:{container:"bg-dark-mode-blue-300",title:"text-white",subt
1itle:"text-primary-blue-300",sectionTitle:"text-white",legendItem:"text-primary-blue-300",emptyState:"text-primary-blue-300"},light:{container:"bg-light-mode-black-100 border border-light-mode-black-300",title:"text-3bee-black",subtitle:"text-light-mode-black-600(base)",sectionTitle:"text-3bee-black",legendItem:"text-light-mode-black-600(base)",emptyState:"text-light-mode-black-500"}}},defaultVariants:{variant:"dark"}}),eS=e=>{var t,a,i,o,u,x,h,g,p;let{className:b}=e,{t:v}=(0,c.A)("monitoring"),{locale:f="it",query:j}=(0,r.useRouter)(),w=j.slug,N=Number(j.id),k=(0,l.useSession)(),_=(0,U.r)(),{isDemoAndOwner:C,canReadSite:S}=(0,Z.A)(),I=(0,G.Q)(),A=(0,K.R)("DataExport"),{area:z,polygons:R,polygonVersion:D,device:M,filterDate:T,filterSpecies:E,filterSubSpecies:F,filterFamily:O,filterGenre:B,filterOrder:P,filterIndex:q,minimumConfidenceValue:V}=(0,L._R)(),[ee,et]=(0,m.useState)("transects"),[ea,ei]=(0,m.useState)(null),[ed,ec]=(0,m.useState)(null),[em,eu]=(0,m.useState)(null),[eh,ep]=(0,m.useState)(null),[eb,ef]=(0,m.useState)(null),[ej,ey]=(0,m.useState)(null),[ew,ek]=(0,m.useState)(null),[eS,eI]=(0,m.useState)(null),[eA,ez]=(0,m.useState)(null),{width:eR=0}=(0,J.w)({ref:{current:ea}}),{width:eD=0}=(0,J.w)({ref:{current:ed}}),{width:eM=0}=(0,J.w)({ref:{current:em}}),{width:eT=0}=(0,J.w)({ref:{current:eh}}),{width:eE=0}=(0,J.w)({ref:{current:eb}}),eL=eC({variant:_}),eF=(0,m.useMemo)(()=>({...D&&{polygon_id:D.id},...R.length>0&&{subpolygon_idx:R.map(e=>e.id).join(",")},...z&&{trancept_ids:z.id.toString()},...M&&{hive_ids:M.id.toString()},...T.from&&{date_from:(0,y.default)(T.from,"yyyy-MM-dd")},...T.to&&{date_to:(0,y.default)(T.to,"yyyy-MM-dd")},...E.size>0&&{iconic_taxa:Array.from(E.keys()).join(",")},...F.size>0&&{taxa:Array.from(F.keys()).join(",")},...O.size>0&&{family_taxa:Array.from(O.keys()).join(",")},...B.size>0&&{genus_taxa:Array.from(B.keys()).join(",")},...P.size>0&&{order_taxa:Array.from(P.keys()).join(",")},...q&&{index_id:q.id},...V&&{min_confidence:V}}),[D,R,z,M,T,E,F,O,B,P,q,V]),eO=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==k||null==(e=k.data)?void 0:e.accessToken),"accept-language":f}},[null==k||null==(t=k.data)?void 0:t.accessToken,f]),{data:eB,isLoading:eP,error:eU}=(0,n.hTH)(w,N,eF,eO,{query:{enabled:"transects"===ee&&!!w&&!!N}}),{data:eH,isLoading:eq,error:eV}=(0,n.la_)(w,N,eF,eO,{query:{enabled:"transects"===ee&&!!w&&!!N}}),{data:eW,isLoading:e$,error:eQ}=(0,n.H3t)(w,N,eF,eO,{query:{enabled:"transects"===ee&&!!w&&!!N}}),{data:eG}=(0,n.ymT)(w,N,{polygon_id:null==D?void 0:D.id},eO,{query:{enabled:"subpolygons"===ee&&!!w&&!!N&&!!(null==D?void 0:D.id)}}),{data:eK,isLoading:eZ,error:eJ}=(0,n.qsp)(w,N,null!=(a=null==D?void 0:D.id)?a:0,eF,eO,{query:{enabled:"subpolygons"===ee&&!!w&&!!N&&!!(null==D?void 0:D.id)}}),{data:eY,isLoading:eX,error:e0}=(0,n.QJM)(w,N,null!=(i=null==D?void 0:D.id)?i:0,eF,eO,{query:{enabled:"subpolygons"===ee&&!!w&&!!N&&!!(null==D?void 0:D.id)}}),[e1]=(0,m.useState)(void 0),[e2]=(0,m.useState)(void 0),e5=(0,m.useMemo)(()=>eB&&0!==eB.length?function(e){let t=el(e),a=e.map(e=>e.native_species_count);return{labels:t,nativeData:a,alienData:e.map(e=>e.alien_species_count),transectIds:e.map(e=>e.trancept_area_id)}}(eB):{labels:[],nativeData:[],alienData:[],transectIds:[]},[eB]),{images:e4,isLoading:e3}=Q({transectId:null!=(o=null==ej?void 0:ej.transectId)?o:null,isAlien:null==ej?void 0:ej.isAlien,enabled:!!ej}),{images:e6,isLoading:e9}=$({subpolygonIdx:(null==ew?void 0:ew.entityType)==="subpolygon"&&null!=(u=null==ew?void 0:ew.entityId)?u:null,conservationStatus:null==ew?void 0:ew.conservationStatus,enabled:!!ew}),{images:e8,isLoading:e7}=Q({transectId:(null==eS?void 0:eS.entityType)==="transect"&&null!=(x=null==eS?void 0:eS.entityId)?x:null,conservationStatus:null==eS?void 0:eS.conservationStatus,enabled:!!eS}),{images:te,isLoading:tt}=Q({transectId:(null==eA?void 0:eA.entityType)==="transect"&&null!=(h=null==eA?void 0:eA.entityId)?h:null,iconicTaxa:(null==eA?void 0:eA.entityType)==="transect"?null==eA?void 0:eA.iconicTaxa:void 0,enabled:!!eA&&"transect"===eA.entityType}),{images:ta,isLoading:ts}=$({subpolygonIdx:(null==eA?void 0:eA.entityType)==="subpolygon"&&null!=(g=null==eA?void 0:eA.entityId)?g:null,iconicTaxa:(null==eA?void 0:eA.entityType)==="subpolygon"?null==eA?void 0:eA.iconicTaxa:void 0,enabled:!!eA&&"subpolygon"===eA.entityType}),ti=(0,m.useCallback)(e=>{ey(e)},[]),tn=(0,m.useCallback)(()=>{ey(null)},[]),tl=(0,m.useCallback)(e=>{ek(e)},[]),tr=(0,m.useCallback)(()=>{ek(null)},[]),to=(0,m.useCallback)(e=>{eI(e)},[]),td=(0,m.useCallback)(()=>{eI(null)},[]),tc=(0,m.useCallback)(e=>{ez(e)},[]),tm=(0,m.useCallback)(()=>{ez(null)},[]),tu=(0,m.useMemo)(()=>eH&&0!==eH.length?function(e){let t=el(e),a=e.map(e=>{var t;return null!=(t=e.shannon)?t:null});return{labels:t,shannon:a,simpson:e.map(e=>{var t;return null!=(t=e.simpson)?t:null}),evenness:e.map(e=>{var t;return null!=(t=e.evenness)?t:null})}}(eH):{labels:[],shannon:[],simpson:[],evenness:[]},[eH]),tx=(0,m.useMemo)(()=>eW&&0!==eW.length?function(e){let t=new Set;
1e.forEach(e=>{Object.keys(e.distribution).forEach(e=>t.add(e))});let a=[...t].sort((e,t)=>{let a=er.indexOf(e),s=er.indexOf(t);return(-1===a?999:a)-(-1===s?999:s)}),s=e.map(e=>{var t;return null!=(t=e.trancept_areas_name)?t:"T".concat(e.trancept_area_id)});return{labels:s,transectIds:e.map(e=>e.trancept_area_id),datasets:a.map(t=>{var a;return{status:t,data:e.map(e=>{var a;return null!=(a=e.distribution[t])?a:0}),color:null!=(a=X.m[t])?a:"#999999"}})}}(eW):{labels:[],transectIds:[],datasets:[]},[eW]),th=(0,m.useMemo)(()=>eK&&0!==eK.length?function(e,t){let a=e.map(e=>{var a;let s=null==t?void 0:t.subpolygons.find(t=>t.subpolygon_idx===e.subpolygon_idx);return null!=(a=null==s?void 0:s.name)?a:"SP".concat(e.subpolygon_idx)}),s=e.map(e=>{var t;return null!=(t=e.shannon)?t:null});return{labels:a,shannon:s,simpson:e.map(e=>{var t;return null!=(t=e.simpson)?t:null}),evenness:e.map(e=>{var t;return null!=(t=e.evenness)?t:null})}}(eK,eG):{labels:[],shannon:[],simpson:[],evenness:[]},[eK,eG]),tg=(0,m.useMemo)(()=>eY&&0!==eY.length?function(e,t){let a=new Set;e.forEach(e=>{Object.keys(e.distribution).forEach(e=>a.add(e))});let s=[...a].sort((e,t)=>{let a=er.indexOf(e),s=er.indexOf(t);return(-1===a?999:a)-(-1===s?999:s)}),i=e.map(e=>{var a;let s=null==t?void 0:t.subpolygons.find(t=>t.subpolygon_idx===e.subpolygon_idx);return null!=(a=null==s?void 0:s.name)?a:"SP".concat(e.subpolygon_idx)});return{labels:i,subpolygonIdxs:e.map(e=>e.subpolygon_idx),datasets:s.map(t=>{var a;return{status:t,data:e.map(e=>{var a;return null!=(a=e.distribution[t])?a:0}),color:null!=(a=X.m[t])?a:"#999999"}})}}(eY,eG):{labels:[],subpolygonIdxs:[],datasets:[]},[eY,eG]),tp=(0,m.useMemo)(()=>e1&&0!==e1.length?function(e){let t=new Set;e.forEach(e=>{Object.keys(e.distribution).forEach(e=>t.add(e))});let a=[...t].sort((e,t)=>{let a=eo.indexOf(e),s=eo.indexOf(t);return(-1===a?999:a)-(-1===s?999:s)}),s=e.map(e=>{var t;return null!=(t=e.trancept_areas_name)?t:"T".concat(e.trancept_area_id)});return{labels:s,transectIds:e.map(e=>e.trancept_area_id),datasets:a.map(t=>{var a;return{iconicTaxa:t,data:e.map(e=>{var a;return null!=(a=e.distribution[t])?a:0}),color:null!=(a=es[t])?a:es.default}})}}(e1):{labels:[],transectIds:[],datasets:[]},[e1]),tb=(0,m.useMemo)(()=>e2&&0!==e2.length?function(e,t){let a=new Set;e.forEach(e=>{Object.keys(e.distribution).forEach(e=>a.add(e))});let s=[...a].sort((e,t)=>{let a=eo.indexOf(e),s=eo.indexOf(t);return(-1===a?999:a)-(-1===s?999:s)}),i=e.map(e=>{var a;let s=null==t?void 0:t.subpolygons.find(t=>t.subpolygon_idx===e.subpolygon_idx);return null!=(a=null==s?void 0:s.name)?a:"SP".concat(e.subpolygon_idx)});return{labels:i,subpolygonIdxs:e.map(e=>e.subpolygon_idx),datasets:s.map(t=>{var a;return{iconicTaxa:t,data:e.map(e=>{var a;return null!=(a=e.distribution[t])?a:0}),color:null!=(a=es[t])?a:es.default}})}}(e2,eG):{labels:[],subpolygonIdxs:[],datasets:[]},[e2,eG]),{data:tv,isLoading:tf}=(0,n.SS6)(w,N,{pagination_limit:1},eO,{query:{enabled:!!w&&!!N,retry:!1,staleTime:3e5}}),tj=(null!=(p=null==tv?void 0:tv.length)?p:0)>0,ty=e5.labels.length>0||tu.labels.length>0||tx.labels.length>0,tw=th.labels.length>0||tg.labels.length>0,tN=tj?"noAttributedData":"noObservations",tk="transects"===ee?ty:tw,t_="".concat(w,"_").concat(N,"_biodiversity_analysis");return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(H.bL,{variant:_,className:b,id:t_,children:[(0,s.jsxs)("div",{className:eL.header(),children:[(0,s.jsxs)("div",{className:eL.headerLeft(),children:[(0,s.jsxs)("h3",{className:eL.title(),children:[(0,s.jsx)(d.In,{icon:"mdi:dna",width:24,height:24}),v("monitoring-observations:summary.biodiversityAnalysis.title")]}),(0,s.jsx)("p",{className:eL.subtitle(),children:v("monitoring-observations:summary.biodiversityAnalysis.subtitle")})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(ev,{viewMode:ee,setViewMode:et,variant:_}),(A&&!I&&S||C)&&(0,s.jsx)(H.wM,{children:(0,s.jsx)(H.fd,{className:{trigger:"h-max w-max"},chartId:t_,disabled:C||!tk,withAINatura:!1})})]})]}),"subpolygons"===ee&&(0,s.jsx)(s.Fragment,{children:D?eZ||eX||tf?(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,s.jsx)(Y.A,{height:320,borderRadius:8}),(0,s.jsxs)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[(0,s.jsx)(Y.A,{height:180,borderRadius:8}),(0,s.jsx)(Y.A,{height:180,borderRadius:8}),(0,s.jsx)(Y.A,{height:180,borderRadius:8})]})]}):eJ||e0?(0,s.jsxs)("div",{className:eL.emptyState(),children:[(0,s.jsx)(d.In,{icon:"mdi:alert-circle-outline",className:"mr-2 h-5 w-5"}),v("monitoring-observations:summary.biodiversityAnalysis.apiError")]}):tw?(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[tg.datasets.length>0&&(0,s.jsxs)("div",{className:eL.section(),children:[(0,s.jsx)("h4",{className:eL.sectionTitle(),children:v("monitoring-observations:summary.biodiversityAnalysis.conservationStatus.title")}),(0,s.jsx)("div",{ref:ec,className:eL.chartContainer(),style:{minHeight:320},children:eD>0&&(0,s.jsx)(ex,{labels:tg.labels,entityIds:tg.subpolygonIdxs,entityType:"subpolygon",datasets:tg.datasets,width:eD,height:320,variant:_,onBarClick:tl})})]}),th.labels.length>0&&(0,s.jsxs)("div",{className:eL.section(),children:[(0,s.jsx)("h4",{className:eL.sectionTitle(),children:v("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.title")}),(0,s.jsx)(eN,{labels:th.labels,shannon:th.shannon,simpson:th.simpson,evenness:th.evenness,variant:_})]}),tb.datasets.length>0&&(0,s.jsxs)("div",{className:eL.section(),children:[(0,s.jsx)("h4",{className:eL.sectionTitle(),children:v("monitoring-observations:summary.biodiversityAnalysis.iconicTaxaDistribution.title")}),(0,s.jsx)("div",{ref:ef,className:eL.chartContainer(),style:{minHeight:320},children:eE>0&&(0,s.jsx)(eg,{labels:tb.labels,entityIds:tb.subpolygonIdxs,entityType:"subpolygon",datasets:tb.datasets,width:eE,height:320,variant:_,onBarClick:tc})})]})]}):(0,s.jsx)("div",{className:eL.emptyState(),children:v("monitoring-observations:summary.biodiversityAnalysis.".concat(tN))}):(0,s.jsxs)("div",{className:eL.emptyState(),children:[(0,s.jsx)(d.In,{icon:"mdi:information-outline",className:"mr-2 h-5 w-5"}),v("monitoring-observations:summary.biodiversityAnalysis.noPolygonSelected")]})}),"transects"===ee&&(0,s.jsx)(s.Fragment,{children:eP||eq||e$||tf?(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,s.jsx)(Y.A,{height:320,borderRadius:8}),(0,s.jsxs)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[(0,s.jsx)(Y.A,{height:180,borderRadius:8}),(0,s.jsx)(Y.A,{height:180,borderRadius:8}),(0,s.jsx)(Y.A,{height:180,borderRadius:8})]})]}):eU||eV||eQ?(0,s.jsxs)("div",{className:eL.emptyState(),children:[(0,s.jsx)(d.In,{icon:"mdi:alert-circle-outline",className:"mr-2 h-5 w-5"}),v("monitoring-observations:summary.biodiversityAnalysis.apiError")]}):ty?(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[e5.labels.length>0&&(0,s.jsxs)("div",{className:eL.section(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h4",{className:eL.sectionTitle(),children:v("monitoring-observations:summary.biodiversityAnalysis.nativeAlien.title")}),(0,s.jsxs)("div",{className:eL.legend(),children:[(0,s.jsxs)("div",{className:eL.legendItem(),children:[(0,s.jsx)("span",{className:eL.legendDot(),style:{backgroundColor:en.native}}),v("monitoring-observations:summary.biodiversityAnalysis.nativeAlien.native")]}),(0,s.jsxs)("div",{className:eL.legendItem(),children:[(0,s.jsx)("span",{className:eL.legendDot(),style:{backgroundColor:en.alien}}),v("monitoring-observations:summary.biodiversityAnalysis.nativeAlien.al
1ien")]})]})]}),(0,s.jsx)("div",{ref:ei,className:eL.chartContainer(),style:{minHeight:320},children:eR>0&&(0,s.jsx)(e_,{labels:e5.labels,nativeData:e5.nativeData,alienData:e5.alienData,transectIds:e5.transectIds,width:eR,height:320,variant:_,onBarClick:ti})})]}),tu.labels.length>0&&(0,s.jsxs)("div",{className:eL.section(),children:[(0,s.jsx)("h4",{className:eL.sectionTitle(),children:v("monitoring-observations:summary.biodiversityAnalysis.diversityIndexes.title")}),(0,s.jsx)(eN,{labels:tu.labels,shannon:tu.shannon,simpson:tu.simpson,evenness:tu.evenness,variant:_})]}),tx.datasets.length>0&&(0,s.jsxs)("div",{className:eL.section(),children:[(0,s.jsx)("h4",{className:eL.sectionTitle(),children:v("monitoring-observations:summary.biodiversityAnalysis.conservationStatus.title")}),(0,s.jsx)("div",{ref:eu,className:eL.chartContainer(),style:{minHeight:320},children:eM>0&&(0,s.jsx)(ex,{labels:tx.labels,entityIds:tx.transectIds,entityType:"transect",datasets:tx.datasets,width:eM,height:320,variant:_,onBarClick:to})})]}),tp.datasets.length>0&&(0,s.jsxs)("div",{className:eL.section(),children:[(0,s.jsx)("h4",{className:eL.sectionTitle(),children:v("monitoring-observations:summary.biodiversityAnalysis.iconicTaxaDistribution.title")}),(0,s.jsx)("div",{ref:ep,className:eL.chartContainer(),style:{minHeight:320},children:eT>0&&(0,s.jsx)(eg,{labels:tp.labels,entityIds:tp.transectIds,entityType:"transect",datasets:tp.datasets,width:eT,height:320,variant:_,onBarClick:tc})})]})]}):(0,s.jsx)("div",{className:eL.emptyState(),children:v("monitoring-observations:summary.biodiversityAnalysis.".concat(tN))})})]}),ej&&(0,s.jsx)(W,{isOpen:!!ej,onClose:tn,title:ej.transectName,subtitle:v(ej.isAlien?"monitoring-observations:summary.biodiversityAnalysis.nativeAlien.alienObservations":"monitoring-observations:summary.biodiversityAnalysis.nativeAlien.nativeObservations"),images:e4,isLoading:e3,isAlien:ej.isAlien}),ew&&(0,s.jsx)(W,{isOpen:!!ew,onClose:tr,title:ew.entityName,subtitle:v("monitoring-observations:summary.biodiversityAnalysis.conservationStatus.statuses.".concat(ew.conservationStatus),{},{default:ew.conservationStatus}),images:e6,isLoading:e9}),eS&&(0,s.jsx)(W,{isOpen:!!eS,onClose:td,title:eS.entityName,subtitle:v("monitoring-observations:summary.biodiversityAnalysis.conservationStatus.statuses.".concat(eS.conservationStatus),{},{default:eS.conservationStatus}),images:e8,isLoading:e7}),eA&&(0,s.jsx)(W,{isOpen:!!eA,onClose:tm,title:eA.entityName,subtitle:v("monitoring-observations:summary.biodiversityAnalysis.iconicTaxaDistribution.taxa.".concat(eA.iconicTaxa),{},{default:eA.iconicTaxa}),images:"transect"===eA.entityType?te:ta,isLoading:"transect"===eA.entityType?tt:ts})]})};var eI=a(86666),eA=a.n(eI),ez=a(33098);let eR=(0,g.tv)({slots:{cluster:"flex shrink-0 items-center",trigger:"relative -ml-2 h-7 w-7 shrink-0 cursor-pointer overflow-hidden rounded-full border-2 transition-transform first:ml-0 hover:z-10 hover:scale-110 focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2",fallback:"flex h-full w-full items-center justify-center",content:"flex w-64 flex-col gap-2 p-3",photo:"relative h-36 w-full overflow-hidden rounded-lg",name:"text-sm font-semibold italic",meta:"text-xs",footnote:"text-[10px] italic"},variants:{variant:{dark:{trigger:"border-dark-mode-blue-300 bg-dark-mode-blue-600(base) focus-visible:ring-primary-blue-300",fallback:"text-primary-blue-300",content:"bg-dark-mode-blue-300 text-white",photo:"bg-dark-mode-blue-600(base)",meta:"text-primary-blue-300",footnote:"text-primary-blue-300"},light:{trigger:"border-white bg-light-mode-black-200 focus-visible:ring-light-mode-black-600(base)",fallback:"text-light-mode-black-500",content:"bg-white text-3bee-black",photo:"bg-light-mode-black-200",meta:"text-light-mode-black-600(base)",footnote:"text-light-mode-black-500"}}}}),eD=e=>{var t;let{species:a,variant:i,bandLabel:n}=e,{t:l}=(0,c.A)("monitoring"),[r,o]=(0,m.useState)(!1),u=eR({variant:i}),x=null!=(t=a.fieldImageUrl)?t:a.imageUrl,h=!a.fieldImageUrl&&!!a.imageUrl;return(0,s.jsxs)(ez.bL,{open:r,onOpenChange:o,children:[(0,s.jsx)(ez.Wv,{asChild:!0,children:(0,s.jsx)("button",{type:"button",className:u.trigger(),"aria-label":a.name,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),onFocus:()=>o(!0),onBlur:()=>o(!1),children:x?(0,s.jsx)(eA(),{src:x,alt:a.name,width:28,height:28,className:"h-full w-full object-cover",unoptimized:!0}):(0,s.jsx)("span",{className:u.fallback(),children:(0,s.jsx)(d.In,{icon:"mdi:paw",width:14,height:14})})})}),(0,s.jsxs)(ez.hl,{side:"top",sideOffset:8,className:u.content(),onOpenAutoFocus:e=>e.preventDefault(),onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[x&&(0,s.jsx)("div",{className:u.photo(),children:(0,s.jsx)(eA(),{src:x,alt:a.name,fill:!0,className:"object-cover",unoptimized:!0})}),(0,s.jsx)("span",{className:u.name(),children:a.name}),(0,s.jsxs)("span",{className:u.meta(),children:[a.iconicTaxa?"".concat(a.iconicTaxa," \xb7 "):"",l("monitoring-observations:summary.alt
1itude.popover.inBand",{count:a.observations,band:n})]}),h&&(0,s.jsx)("span",{className:u.footnote(),children:l("monitoring-observations:summary.altitude.popover.cataloguePhoto")})]})]})},eM=e=>{let{species:t,variant:a,bandLabel:i}=e,n=eR({variant:a});return 0===t.length?(0,s.jsx)("div",{className:n.cluster(),"aria-hidden":"true"}):(0,s.jsx)("div",{className:n.cluster(),role:"group",children:t.map(e=>(0,s.jsx)(eD,{species:e,variant:a,bandLabel:i},e.taxonId))})},eT=["#3FB950","#8BC34A","#D4B13F","#C48A3F","#9C6B4E","#B8B8B8","#E6E6E6"];function eE(e,t){return new Intl.NumberFormat(t,{maximumFractionDigits:0}).format(e)}function eL(e){return/[",\n\r]/.test(e)?'"'.concat(e.replace(/"/g,'""'),'"'):e}let eF=(0,g.tv)({slots:{header:"flex flex-col gap-1",title:"flex items-center gap-2 text-lg font-bold",subtitle:"text-sm",warning:"flex items-center gap-1 text-xs",chart:"flex gap-3",axis:"flex w-5 shrink-0 flex-col items-center",axisLine:"w-px flex-1",axisLabel:"mt-1 rotate-180 text-[10px] uppercase tracking-wide [writing-mode:vertical-rl]",rows:"flex min-w-0 flex-1 flex-col gap-1.5",row:"flex items-center gap-3",bandLabel:"w-24 shrink-0 text-right font-mono text-xs tabular-nums",barContainer:"relative flex-1 overflow-hidden rounded-md",bar:"absolute inset-y-0 left-0 rounded-md transition-all duration-300",count:"absolute inset-y-0 right-2 flex items-center text-xs font-semibold",avatars:"flex w-[76px] shrink-0 items-center",species:"w-20 shrink-0 text-xs",emptyState:"flex h-48 items-center justify-center text-sm"},variants:{variant:{dark:{title:"text-white",subtitle:"text-primary-blue-300",warning:"text-primary-blue-300",axisLine:"bg-dark-mode-blue-600(base)",axisLabel:"text-primary-blue-300",bandLabel:"text-primary-blue-300",barContainer:"bg-dark-mode-blue-600(base)",count:"text-white",species:"text-primary-blue-300",emptyState:"text-primary-blue-300"},light:{title:"text-3bee-black",subtitle:"text-light-mode-black-600(base)",warning:"text-light-mode-black-600(base)",axisLine:"bg-light-mode-black-300",axisLabel:"text-light-mode-black-600(base)",bandLabel:"text-light-mode-black-600(base)",barContainer:"bg-light-mode-black-200",count:"text-3bee-black",species:"text-light-mode-black-600(base)",emptyState:"text-light-mode-black-500"}}},defaultVariants:{variant:"dark"}}),eO=e=>{var t,a,i,o,u;let{className:x}=e,{t:h}=(0,c.A)("monitoring"),{locale:g="it",query:p}=(0,r.useRouter)(),b=p.slug,v=Number(p.id),f=(0,l.useSession)(),j=(0,U.r)(),{isDemoAndOwner:w,canReadSite:N}=(0,Z.A)(),k=(0,G.Q)(),_=(0,K.R)("DataExport"),C="".concat(b,"_").concat(v,"_observations_altitude_chart"),{area:S,polygons:I,device:A,filterDate:z,filterSpecies:R,filterSubSpecies:D,filterFamily:M,filterGenre:T,filterOrder:E,filterIndex:F,minimumConfidenceValue:O}=(0,L._R)(),{observe:B,inView:P}=(0,ec.W)({threshold:.1,unobserveOnEnter:!0}),q=eF({variant:j}),V=(0,m.useMemo)(()=>({...I.length>0&&{subpolygon_idx:I.map(e=>e.id).join(",")},...S&&{trancept_ids:S.id.toString()},...A&&{hive_ids:A.id.toString()},...z.from&&{date_from:(0,y.default)(z.from,"yyyy-MM-dd")},...z.to&&{date_to:(0,y.default)(z.to,"yyyy-MM-dd")},...R.size>0&&{iconic_taxa:Array.from(R.keys()).join(",")},...D.size>0&&{taxa:Array.from(D.keys()).join(",")},...M.size>0&&{family_taxa:Array.from(M.keys()).join(",")},...T.size>0&&{genus_taxa:Array.from(T.keys()).join(",")},...E.size>0&&{order_taxa:Array.from(E.keys()).join(",")},...F&&{index_id:F.id},...O&&{min_confidence:O},exclude_taxa:L.Wg}),[I,S,A,z,R,D,M,T,E,F,O]),W=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==f||null==(e=f.data)?void 0:e.accessToken),"accept-language":g}},[null==f||null==(t=f.data)?void 0:t.accessToken,g]),{data:$,isLoading:Q,error:J}=(0,n.GiD)(b,v,V,W,{query:{enabled:P&&!!b&&!!v}}),X=(0,m.useMemo)(()=>(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Unknown";return(null==e?void 0:e.data)&&0!==e.data.length?[...e.data].map(e=>{var a;return{fromM:e.from_m,toM:e.to_m,observations:e.observations,species:e.species,topSpecies:(null!=(a=e.top_species)?a:[]).map(e=>{var a,s,i,n;return{taxonId:e.taxon_id,name:null!=(a=e.taxa)?a:t,iconicTaxa:null!=(s=e.iconic_taxa)?s:void 0,imageUrl:null!=(i=e.image_url)?i:void 0,fieldImageUrl:null!=(n=e.field_image_url)?n:void 0,observations:e.observations}})}}).sort((e,t)=>
1t.fromM-e.fromM):[]})($,h("monitoring-observations:noTaxa")),[$,h]),ee=(0,m.useMemo)(()=>(function(e){return 0===e.length?0:Math.max(...e.map(e=>e.observations))})(X),[X]),ea=null!=(a=null==$?void 0:$.min_elevation_m)?a:0,es=null!=(i=null==$?void 0:$.max_elevation_m)?i:0,ei=null!=(o=null==$?void 0:$.without_elevation)?o:0,en=X.length>0,el=(0,m.useCallback)(async()=>{!function(e,t,a){if(0===e.length)return;let s=new Blob(["\uFEFF"+[[t.from,t.to,t.observations,t.species].map(eL).join(","),...[...e].sort((e,t)=>e.fromM-t.fromM).map(e=>[String(e.fromM),String(e.toM),String(e.observations),String(e.species)].map(eL).join(","))].join("\n")],{type:"text/csv;charset=utf-8;"});et()(s,"".concat(a,".csv"))}(X,{from:h("monitoring-observations:summary.altitude.csv.from"),to:h("monitoring-observations:summary.altitude.csv.to"),observations:h("monitoring-observations:summary.altitude.csv.observations"),species:h("monitoring-observations:summary.altitude.csv.species")},C)},[X,h,C]);return(0,s.jsx)("div",{ref:B,children:(0,s.jsxs)(H.bL,{variant:j,className:x,id:C,children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,s.jsxs)("div",{className:q.header(),children:[(0,s.jsxs)("h3",{className:q.title(),children:[(0,s.jsx)(d.In,{icon:"mdi:image-filter-hdr",width:24,height:24}),h("monitoring-observations:summary.altitude.title")]}),(0,s.jsx)("p",{className:q.subtitle(),children:en?h("monitoring-observations:summary.altitude.range",{min:eE(ea,g),max:eE(es,g),band:null!=(u=null==$?void 0:$.band_m)?u:0}):h("monitoring-observations:summary.altitude.subtitle")}),ei>0&&(0,s.jsxs)("p",{className:q.warning(),children:[(0,s.jsx)(d.In,{icon:"mdi:clock-outline",width:14,height:14}),h("monitoring-observations:summary.altitude.withoutElevation",{count:ei})]})]}),(_&&!k&&N||w)&&(0,s.jsx)(H.wM,{children:(0,s.jsx)(H.fd,{className:{trigger:"h-max w-max"},chartId:C,downloadCsv:el,disabled:w||!en,withAINatura:!1})})]}),Q?(0,s.jsx)("div",{className:"flex flex-col gap-1.5",children:Array.from({length:6}).map((e,t)=>(0,s.jsx)(Y.A,{height:28,borderRadius:8},t))}):J?(0,s.jsxs)("div",{className:q.emptyState(),children:[(0,s.jsx)(d.In,{icon:"mdi:alert-circle-outline",className:"mr-2 h-5 w-5"}),h("monitoring-observations:summary.altitude.error")]}):en?(0,s.jsxs)("div",{className:q.chart(),children:[(0,s.jsxs)("div",{className:q.axis(),"aria-hidden":"true",children:[(0,s.jsx)(d.In,{icon:"mdi:arrow-up",width:16,height:16,className:q.subtitle()}),(0,s.jsx)("div",{className:q.axisLine()}),(0,s.jsx)("span",{className:q.axisLabel(),children:h("monitoring-observations:summary.altitude.axis")})]}),(0,s.jsxs)("div",{className:q.rows(),role:"list",children:[X.map(e=>{var t,a;let i=(t=e.observations,0===(a=ee)?0:t/a*100),n=h("monitoring-observations:summary.altitude.band",{from:eE(e.fromM,g),to:eE(e.toM,g)});return(0,s.jsxs)("div",{className:q.row(),role:"listitem",children:[(0,s.jsx)("span",{className:q.bandLabel(),children:n}),(0,s.jsxs)("div",{className:q.barContainer(),style:{height:28},children:[(0,s.jsx)("div",{className:q.bar(),style:{width:"".concat(Math.max(i,2),"%"),backgroundColor:function(e,t,a){if(a<=t)return eT[0];let s=Math.min(eT.length-1,Math.max(0,Math.round((e-t)/(a-t)*(eT.length-1))));return eT[s]}(e.fromM,ea,es)},title:h("monitoring-observations:summary.altitude.observations",{count:e.observations})}),(0,s.jsx)("span",{className:q.count(),children:e.observations})]}),(0,s.jsx)("div",{className:q.avatars(),children:(0,s.jsx)(eM,{species:e.topSpecies,variant:j,bandLabel:n})}),(0,s.jsx)("span",{className:q.species(),children:h("monitoring-observations:summary.altitude.species",{count:e.species})})]},e.fromM)}),1===X.length&&(0,s.jsx)("p",{className:q.subtitle(),children:h("monitoring-observations:summary.altitude.singleBand")})]})]}):(0,s.jsx)("div",{className:q.emptyState(),children:h("monitoring-observations:summary.altitude.noData")})]})})};var eB=a(46859),eP=a(41804),eU=a(97006),eH=a(27149),eq=a(66064);let eV={line:"#3FB950",gradient:["rgba(63, 185, 80, 0.4)","rgba(63, 185, 80, 0)"],gridLight:"rgba(0, 0, 0, 0.1)",gridDark:"rgba(255, 255, 255, 0.1)"};function eW(e,t){let a=(0,eH.no)(t),s=(0,eq.A)(e,"yyyy-MM-dd",new Date);return(0,y.default)(s,"MMM yyyy",{locale:a})}
1let e$=(0,g.tv)({slots:{container:"flex flex-col gap-4 rounded-xl p-4 lg:p-5",header:"flex flex-col gap-1",title:"flex items-center gap-2 text-lg font-bold",subtitle:"text-sm",chartContainer:"w-full",emptyState:"flex h-48 items-center justify-center text-sm"},variants:{variant:{dark:{container:"bg-dark-mode-blue-300",title:"text-white",subtitle:"text-primary-blue-300",emptyState:"text-primary-blue-300"},light:{container:"bg-light-mode-black-100 border border-light-mode-black-300",title:"text-3bee-black",subtitle:"text-light-mode-black-600(base)",emptyState:"text-light-mode-black-500"}}},defaultVariants:{variant:"dark"}}),eQ=e=>{var t;let{className:a}=e,{t:i}=(0,c.A)("monitoring"),{locale:o="it",query:u}=(0,r.useRouter)(),x=u.slug,h=Number(u.id),g=(0,l.useSession)(),p=(0,U.r)(),{isDemoAndOwner:b,canReadSite:v}=(0,Z.A)(),f=(0,G.Q)(),j=(0,K.R)("DataExport"),w="".concat(x,"_").concat(h,"_observations_timeline_chart"),{area:N,polygons:k,device:_,filterDate:C,filterSpecies:S,filterSubSpecies:I,filterFamily:A,filterGenre:z,filterOrder:R,filterIndex:D,minimumConfidenceValue:M}=(0,L._R)(),[T,E]=(0,m.useState)(null),{width:F=0}=(0,J.w)({ref:{current:T}}),{observe:O,inView:B}=(0,ec.W)({threshold:.1,unobserveOnEnter:!0}),[P,q]=(0,m.useState)(null),V=e$({variant:p}),$=(0,m.useMemo)(()=>({...k.length>0&&{subpolygon_idx:k.map(e=>e.id).join(",")},...N&&{trancept_ids:N.id.toString()},..._&&{hive_ids:_.id.toString()},...C.from&&{date_from:(0,y.default)(C.from,"yyyy-MM-dd")},...C.to&&{date_to:(0,y.default)(C.to,"yyyy-MM-dd")},...S.size>0&&{iconic_taxa:Array.from(S.keys()).join(",")},...I.size>0&&{taxa:Array.from(I.keys()).join(",")},...A.size>0&&{family_taxa:Array.from(A.keys()).join(",")},...z.size>0&&{genus_taxa:Array.from(z.keys()).join(",")},...R.size>0&&{order_taxa:Array.from(R.keys()).join(",")},...D&&{index_id:D.id},...M&&{min_confidence:M},exclude_taxa:L.Wg,interval:"monthly"}),[k,N,_,C,S,I,A,z,R,D,M]),Q=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==g||null==(e=g.data)?void 0:e.accessToken),"accept-language":
1o}},[null==g||null==(t=g.data)?void 0:t.accessToken,o]),{data:X,isLoading:ee,error:et}=(0,n.fMM)(x,h,$,Q,{query:{enabled:B&&!!x&&!!h}}),ea=(0,m.useMemo)(()=>(function(e,t){if(!(null==e?void 0:e.data)||0===Object.keys(e.data).length)return{labels:[],values:[],dates:[]};let a=Object.entries(e.data).sort((e,t)=>{let[a]=e,[s]=t;return a.localeCompare(s)}),s=a.findIndex(e=>{let[,t]=e;return t>0}),i=s>=0?a.slice(s):a,n=i.map(e=>{let[a]=e;return eW(a,t)});return{labels:n,values:i.map(e=>{let[,t]=e;return t}),dates:i.map(e=>{let[t]=e;return t})}})(X,o),[X,o]),es=(0,m.useMemo)(()=>(function(e){return 0===e.length?100:Math.ceil(1.2*Math.max(...e))})(ea.values),[ea.values]),{images:ei,isLoading:en}=function(e){var t;let{dateString:a,enabled:s=!0,limit:i=50}=e,{locale:o="it",query:d}=(0,r.useRouter)(),c=d.slug,u=Number(d.id),x=(0,l.useSession)(),{area:h,device:g,filterSpecies:p,filterSubSpecies:b,filterFamily:v,filterGenre:f,filterOrder:j,filterIndex:w,minimumConfidenceValue:N}=(0,L._R)(),k=(0,m.useMemo)(()=>{if(!a)return null;let e=new Date(a);return{from:(0,y.default)((0,eB.A)(e),"yyyy-MM-dd"),to:(0,y.default)((0,eP.A)(e),"yyyy-MM-dd")}},[a]),_=(0,m.useMemo)(()=>({...k&&{date_from:k.from,date_to:k.to},...h&&{trancept_ids:h.id.toString()},...g&&{hive_ids:g.id.toString()},...p.size>0&&{iconic_taxa:Array.from(p.keys()).join(",")},...b.size>0&&{taxa:Array.from(b.keys()).join(",")},...v.size>0&&{family_taxa:Array.from(v.keys()).join(",")},...f.size>0&&{genus_taxa:Array.from(f.keys()).join(",")},...j.size>0&&{order_taxa:Array.from(j.keys()).join(",")},...w&&{index_id:w.id},...N&&{min_confidence:N},pagination_limit:i}),[k,h,g,p,b,v,f,j,w,N,i]),C=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==x||null==(e=x.data)?void 0:e.accessToken),"accept-language":
1o}},[null==x||null==(t=x.data)?void 0:t.accessToken,o]),{data:S,isLoading:I,error:A}=(0,n.ktV)(c,u,_,C,{query:{enabled:s&&!!c&&!!u&&!!a,getNextPageParam:()=>void 0}}),z=(0,m.useMemo)(()=>(null==S?void 0:S.pages)?S.pages.flat():[],[null==S?void 0:S.pages]);return{images:(0,m.useMemo)(()=>z.filter(e=>("image"===e.type||"video"===e.type)&&!!e.url).sort((e,t)=>new Date(t.record_date).getTime()-new Date(e.record_date).getTime()).map(e=>{var t,a,s,i;return{id:e.obs_id.toString(),url:"video"===e.type&&e.url?e.url.replace(/\.mp4$/,".jpg"):null!=(s=e.url)?s:"",date:e.record_date,taxa:null!=(i=null==(t=e.taxa)?void 0:t.taxa)?i:null==(a=e.taxa)?void 0:a.latin_taxa}}),[z]),isLoading:I,error:A,totalObservations:z.length}}({dateString:P,enabled:!!P}),el=(0,m.useMemo)(()=>P?eW(P,o):"",[P,o]),er=(0,m.useCallback)(()=>{q(null)},[]),eo=(0,m.useCallback)((e,t)=>{if(t.length>0){let e=t[0].index,a=ea.dates[e];a&&q(a)}},[ea.dates]),ed=(0,m.useMemo)(()=>0===ea.values.length?[]:[{...eU.DefaultDatasetArea(eV.line,[...eV.gradient]),tension:.4,pointStyle:"circle",pointRadius:4,pointHoverRadius:6,data:ea.values}],[ea.values]),eu=ea.labels.length>0;return(0,s.jsxs)("div",{ref:O,children:[(0,s.jsxs)(H.bL,{variant:p,className:a,id:w,children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,s.jsxs)("div",{className:V.header(),children:[(0,s.jsxs)("h3",{className:V.title(),children:[(0,s.jsx)(d.In,{icon:"mdi:chart-timeline-variant",width:24,height:24}),i("monitoring-observations:summary.timeline.title")]}),(0,s.jsx)("p",{className:V.subtitle(),children:i("monitoring-observations:summary.timeline.subtitle")})]}),(j&&!f&&v||b)&&(0,s.jsx)(H.wM,{children:(0,s.jsx)(H.fd,{className:{trigger:"h-max w-max"},chartId:w,disabled:b||!eu,withAINatura:!1})})]}),(0,s.jsx)("div",{ref:E,className:V.chartContainer(),style:{minHeight:280},children:ee?(0,s.jsx)(Y.A,{height:280,borderRadius:8}):et?(0,s.jsxs)("div",{className:V.emptyState(),children:[(0,s.jsx)(d.In,{icon:"mdi:alert-circle-outline",className:"mr-2 h-5 w-5"}),i("monitoring-observations:summary.timeline.error")]}):eu?F>0?(0,s.jsx)(em.QF,{width:F,height:280,labels:ea.labels,datasets:ed,options:{onClick:(e,t)=>{t.length>0&&eo(e,t)},onHover:(e,t)=>{var a;let s=null==(a=e.native)?void 0:a.target;s&&(s.style.cursor=t.length>0?"pointer":"default")},scales:{x:{ticks:{color:"dark"===p?"rgba(255, 255, 255, 0.6)":"rgba(0, 0, 0, 0.6)",font:{size:11},maxRotation:45,minRotation:45},grid:{color:"dark"===p?eV.gridDark:eV.gridLight}},y:{display:!0,max:es,ticks:{color:"dark"===p?"rgba(255, 255, 255, 0.6)":"rgba(0, 0, 0, 0.6)",font:{size:11}},grid:{color:"dark"===p?eV.gridDark:eV.gridLight}}},plugins:{tooltip:{callbacks:{label:e=>"".concat(i("monitoring-observations:summary.timeline.observations"),": ").concat(e.parsed.y)}}}}},F):null:(0,s.jsx)("div",{className:V.emptyState(),children:i("monitoring-observations:summary.timeline.noData")})})]}),P&&(0,s.jsx)(W,{isOpen:!!P,onClose:er,title:el,subtitle:i("monitoring-observations:summary.timeline.observationsInMonth"),images:ei,isLoading:en})]})}
1,eG=(0,g.tv)({slots:{container:"flex flex-col gap-4 rounded-xl p-4 lg:p-5",header:"flex flex-col gap-1",title:"flex items-center gap-2 text-lg font-bold",subtitle:"text-sm",listContainer:"flex flex-col gap-2",speciesRow:"flex cursor-pointer items-center gap-3 transition-opacity hover:opacity-80",thumbnail:"relative h-8 w-8 shrink-0 overflow-hidden rounded bg-gray-200",thumbnailFallback:"flex h-full w-full items-center justify-center",rank:"w-6 shrink-0 text-center text-sm font-semibold",speciesInfo:"flex min-w-0 flex-1 flex-col gap-0.5",speciesName:"truncate text-sm font-medium",barContainer:"relative h-6 w-full overflow-hidden rounded-md",bar:"absolute inset-y-0 left-0 rounded-md transition-all duration-300",count:"absolute inset-y-0 right-2 flex items-center text-xs font-semibold text-white",emptyState:"flex h-48 items-center justify-center text-sm",alienBadge:"ml-2 shrink-0"},variants:{variant:{dark:{container:"bg-dark-mode-blue-300",title:"text-white",subtitle:"text-primary-blue-300",thumbnail:"bg-dark-mode-blue-600(base)",thumbnailFallback:"text-primary-blue-300",rank:"text-primary-blue-300",speciesName:"text-white",barContainer:"bg-dark-mode-blue-600(base)",emptyState:"text-primary-blue-300"},light:{container:"bg-light-mode-black-100 border border-light-mode-black-300",title:"text-3bee-black",subtitle:"text-light-mode-black-600(base)",thumbnail:"bg-light-mode-black-200",thumbnailFallback:"text-light-mode-black-500",rank:"text-light-mode-black-500",speciesName:"text-3bee-black",barContainer:"bg-light-mode-black-200",emptyState:"text-light-mode-black-500"}}},defaultVariants:{variant:"dark"}}),eK=e=>{var t,a;let{className:i}=e,{t:o}=(0,c.A)("monitoring"),{locale:u="it",query:x}=(0,r.useRouter)(),h=x.slug,g=Number(x.id),p=(0,l.useSession)(),b=(0,U.r)(),{isDemoAndOwner:v,canReadSite:f}=(0,Z.A)(),j=(0,G.Q)(),w=(0,K.R)("DataExport"),N="".concat(h,"_").concat(g,"_top_species_chart"),{area:k,polygons:_,device:C,filterDate:S,filterSpecies:I,filterSubSpecies:A,filterFamily:z,filterGenre:R,filterOrder:D,filterIndex:M,minimumConfidenceValue:T}=(0,L._R)(),{observe:E,inView:F}=(0,ec.W)({threshold:.1,unobserveOnEnter:!0}),[O,B]=(0,m.useState)(null),P=eG({variant:b}),q=(0,m.useMemo)(()=>({..._.length>0&&{subpolygon_idx:_.map(e=>e.id).join(",")},...k&&{trancept_ids:k.id.toString()},...C&&{hive_ids:C.id.toString()},...S.from&&{date_from:(0,y.default)(S.from,"yyyy-MM-dd")},...S.to&&{date_to:(0,y.default)(S.to,"yyyy-MM-dd")},...I.size>0&&{iconic_taxa:Array.from(I.keys()).join(",")},...A.size>0&&{taxa:Array.from(A.keys()).join(",")},...z.size>0&&{family_taxa:Array.from(z.keys()).join(",")},...R.size>0&&{genus_taxa:Array.from(R.keys()).join(",")},...D.size>0&&{order_taxa:Array.from(D.keys()).join(",")},...M&&{index_id:M.id},...T&&{min_confidence:T},exclude_taxa:L.Wg}),[_,k,C,S,I,A,z,R,D,M,T]),$=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==p||null==(e=p.data)?void 0:e.accessToken),"accept-language":u}},[null==p||null==(t=p.data)?void 0:t.accessToken,u]),{data:Q,isLoading:J,error:X}=(0,n.j29)(h,g,q,$,{query:{enabled:F&&!!h&&!!g}}),ee=(0,m.useMemo)(()=>(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Unknown";return e&&0!==e.length?[...e].filter(e=>e.cardinality>0).sort((e,t)=>t.cardinality-e.cardinality).slice(0,t).map(e=>{var t,s,i,n,l,r;return{taxonId:null!=(t=e.taxon_id)?t:null,name:null!=(s=e.taxa)?s:a,count:e.cardinality,imageUrl:null!=(i=e.image_url)?i:void 0,isAlien:null!=(n=e.is_alien)&&n,isEndemic:null!=(l=e.is_endemic)&&l,iconicTaxa:null!=(r=e.iconic_taxa)?r:void 0}}):[]})(Q,10,o("monitoring-observations:noTaxa")),[Q,o]),en=(0,m.useMemo)(()=>(function(e){return 0===e.length?100:Math.max(...e.map(e=>e.count))})(ee),[ee]),{images:el,isLoading:er}=function(e){var t;let{taxonId:a,enabled:s=!0,limit:i=50}=e,{locale:o="it",query:d}=(0,r.useRouter)(),c=d.slug,u=Number(d.id),x=(0,l.useSession)(),{area:h,device:g,filterDate:p,filterIndex:b,minimumConfidenceValue:v}=(0,L._R)(),f=(0,m.useMemo)(()=>({...a&&{taxa:a.toString()},...h&&{trancept_ids:h.id.toString()}
1,...g&&{hive_ids:g.id.toString()},...p.from&&{date_from:(0,y.default)(p.from,"yyyy-MM-dd")},...p.to&&{date_to:(0,y.default)(p.to,"yyyy-MM-dd")},...b&&{index_id:b.id},...v&&{min_confidence:v},pagination_limit:i}),[a,h,g,p,b,v,i]),j=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==x||null==(e=x.data)?void 0:e.accessToken),"accept-language":o}},[null==x||null==(t=x.data)?void 0:t.accessToken,o]),{data:w,isLoading:N,error:k}=(0,n.ktV)(c,u,f,j,{query:{enabled:s&&!!c&&!!u&&!!a,getNextPageParam:()=>void 0}}),_=(0,m.useMemo)(()=>(null==w?void 0:w.pages)?w.pages.flat():[],[null==w?void 0:w.pages]);return{images:(0,m.useMemo)(()=>_.filter(e=>("image"===e.type||"video"===e.type)&&!!e.url).sort((e,t)=>new Date(t.record_date).getTime()-new Date(e.record_date).getTime()).map(e=>{var t,a,s,i;return{id:e.obs_id.toString(),url:"video"===e.type&&e.url?e.url.replace(/\.mp4$/,".jpg"):null!=(s=e.url)?s:"",date:e.record_date,taxa:null!=(i=null==(t=e.taxa)?void 0:t.taxa)?i:null==(a=e.taxa)?void 0:a.latin_taxa}}),[_]),isLoading:N,error:k,totalObservations:_.length}}({taxonId:null!=(a=null==O?void 0:O.taxonId)?a:null,enabled:!!O}),eo=e=>{e.taxonId&&B(e)},ed=ee.length>0,em=(0,m.useCallback)(async()=>{!function(e,t,a){if(0===e.length)return;let s=new Blob(["\uFEFF"+[[t.rank,t.species,t.count,t.group,t.alien,t.endemic].map(ei).join(","),...e.map((e,a)=>{var s;return[String(a+1),e.name,String(e.count),null!=(s=e.iconicTaxa)?s:"",e.isAlien?t.yes:t.no,e.isEndemic?t.yes:t.no].map(ei).join(",")})].join("\n")],{type:"text/csv;charset=utf-8;"});et()(s,"".concat(a,".csv"))}(ee,{rank:o("monitoring-observations:summary.topSpecies.csv.rank"),species:o("monitoring-observations:summary.topSpecies.csv.species"),count:o("monitoring-observations:summary.topSpecies.csv.count"),group:o("monitoring-observations:summary.topSpecies.csv.group"),alien:o("monitoring-observations:summary.topSpecies.csv.alien"),endemic:o("monitoring-observations:summary.topSpecies.csv.endemic"),yes:o("monitoring-observations:summary.topSpecies.csv.yes"),no:o("monitoring-observations:summary.topSpecies.csv.no")},N)},[ee,o,N]);return(0,s.jsxs)("div",{ref:E,children:[(0,s.jsxs)(H.bL,{variant:b,className:i,id:N,children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,s.jsxs)("div",{className:P.header(),children:[(0,s.jsxs)("h3",{className:P.title(),children:[(0,s.jsx)(d.In,{icon:"mdi:podium-gold",width:24,height:24}),o("monitoring-observations:summary.topSpecies.title")]}),(0,s.jsx)("p",{className:P.subtitle(),children:o("monitoring-observations:summary.topSpecies.subtitle")})]}),(w&&!j&&f||v)&&(0,s.jsx)(H.wM,{children:(0,s.jsx)(H.fd,{className:{trigger:"h-max w-max"},chartId:N,downloadCsv:em,disabled:v||!ed,withAINatura:!1})})]}),J?(0,s.jsx)("div",{className:"flex flex-col gap-2",children:Array.from({length:10}).map((e,t)=>(0,s.jsx)(Y.A,{height:36,borderRadius:8},t))}):X?(0,s.jsxs)("div",{className:P.emptyState(),children:[(0,s.jsx)(d.In,{icon:"mdi:alert-circle-outline",className:"mr-2 h-5 w-5"}),o("monitoring-observations:summary.topSpecies.error")]}):ed?(0,s.jsx)("div",{className:P.listContainer(),children:ee.map((e,t)=>{var a,i;let n=(a=e.count,0===(i=en)?0:a/i*100),l=function(e,t){var a;return t?ea.alien:e&&null!=(a=es[e])?a:es.default}(e.iconicTaxa,e.isAlien);return(0,s.jsxs)("div",{className:P.speciesRow(),onClick:()=>eo(e),onKeyDown:t=>"Enter"===t.key&&eo(e),role:"button",tabIndex:0,children:[(0,s.jsx)("div",{className:P.thumbnail(),children:e.imageUrl?(0,s.jsx)(eA(),{src:e.imageUrl,alt:e.name,fill:!0,className:"object-cover",unoptimized:!0}):(0,s.jsx)("div",{className:P.thumbnailFallback(),children:(0,s.jsx)(d.In,{icon:"mdi:image-off-outline",width:16,height:16})})}),(0,s.jsx)("span",{className:P.rank(),children:t+1}),(0,s.jsxs)("div",{className:P.speciesInfo(),children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("span",{className:P.speciesName(),title:e.name,children:e.name}),e.isAlien&&(0,s.jsx)(V.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:P.alienBadge(),children:o("monitoring-observations:statistics.alien")}),e.isEndemic&&(0,s.jsx)(V.E,{variant:"lightModeBlack(600base)",rounded:"lg",className:P.alienBadge(),children:o("monitoring-observations:statistics.endemic")})]}),(0,s.jsxs)("div",{className:P.barContainer(),children:[(0,s.jsx)("div",{className:P.bar(),style:{width:"".concat(Math.max(n,10),"%"),backgroundColor:l}}),(0,s.jsx)("span",{className:P.count(),children:e.count})]})]})]},"".concat(e.taxonId,"-").concat(t))})}):(0,s.jsx)("div",{className:P.emptyState(),children:o("monitoring-observations:summary.topSpecies.noData")})]}),O&&(0,s.jsx)(W,{isOpen:!!O,onClose:()=>{B(null)},title:O.name,subtitle:O.iconicTaxa,images:el,isLoading:er,totalCount:O.count,isAlien:O.isAlien,isEndemic:O.isEndemic})]})},eZ=e=>{let{className:t}=e,a=(0,U.r)();return(0,s.jsx)(P.bL,{id:"census-summary","data-description":"Census summary section with biodiversity analysis, observations timeline, observations by altitude, and top species charts",variant:"transparent",className:"p-4 lg:p-6 ".concat(null!=t?t:""),children:(0,s.jsxs)(P.nB,{variant:a,spacing:"md",className:"flex flex-col gap-6 !rounded-xl",children:[(0,s.jsx)(eS,{}),(0,s.jsx)(eQ,{}),(0,s.jsx)(eO,{}),(0,s.jsx)(eK,{})]})})};var eJ=a(83038),eY=a(85281),eX=a(16331),e0=a(94819),e1=a(72730);let e2=e=>{let{onCancel:t,onSave:a}=e,{t:i}=(0,c.A)("monitoring"),{query:o}=(0,r.useRouter)(),d=o.slug,m=Number(o.id),u=(0,l.useSession)(),{toast:x}=e0.dj(),{area:h}=(0,L._R)(),{mutateAsync:g,isLoading:p}=(0,n.B5n)({mutation:{onError:()=>{x({variant:"error",description:i("monitoring-observations:transectMedia.notes.error")}),t()},onSuccess:e=>{x({variant:"success",description:i("monitoring-observations:transectMedia.notes.success")}),a(e)}}}),b=async e=>{var a;if(!e.trim()||!h)return void t();await g({userSlug:d,siteId:m,data:{trancept_area_id:h.id,text:e},headers:{authorization:"Bearer ".concat(null==u||null==(a=u.data)?void 0:a.accessToken)}})};return(0,s.jsx)("div",{className:"flex flex-col text-sm",children:(0,s.jsx)(e1.w,{isEditing:!0,text:"",onCancel:t,onConfirm:b,className:"whitespace-break-spaces text-light-mode-black-200",hideSlotBefore:!0,footer:(0,s.jsxs)("div",{className:"mt-4 flex flex-row justify-end gap-2",children:[(0,s.jsx)(e1.w.CancelButton,{disabled:p,variant:"outline-monitoring-600(base)",className:"w-max px-4 py-2",children:i("common:cancel")}),(0,s.jsx)(e1.w.ConfirmButton,{disabled:p,variant:"monitoring-600(base)",className:"w-max px-4 py-2",children:i("common:save")})]})})})};var e5=a(45027),e4=a(71342),e3=a(47496),e6=a(99402);let e9=e=>{let{activeTab:t,closeDialog:a}=e,{t:i}=(0,c.A)("monitoring"),{query:o}=(0,r.useRouter)(),u=o.slug,g=Number(o.id),p=(0,l.useSession)(),{toast:b}=e0.dj(),{area:v}=(0,L._R)(),f=(0,e5.jE)(),[j,y]=(0,m.useState)({}),w="images"===t?"image/*":"video/*",N="images"===t?".jpg, .jpeg, .png, .gif":".mp4, .mov, .avi",{files:k,setFiles:_,removeFileByIndex:C}=(0,e4.M)({accept:w,maxSize:10,onError:e=>{b({variant:"error",description:i("common.files.errors.".concat(e),{files:10,size:10,formats:N})})}}),{mutateAsync:S,isLoading:I}=(0,n.nNw)(),A=!v||0===k.length||I,z=async()=>
1{if(v&&0!==k.length)try{await Promise.all(k.map((e,a)=>{var s,i;let n=null==(s=j[a])?void 0:s.trim();return S({userSlug:u,siteId:g,data:{media:e},params:{trancept_area_id:v.id,media_type:"images"===t?"image":"video",description:n||void 0},headers:(null==p||null==(i=p.data)?void 0:i.accessToken)?{authorization:"Bearer ".concat(p.data.accessToken)}:void 0})})),b({variant:"success",description:i("monitoring-observations:transectMedia.uploadDialog.success")}),a(),f.invalidateQueries(["/v1/monitoring/".concat(u,"/sites/").concat(g,"/trancepts/media")])}catch(e){b({variant:"error",description:i("monitoring-observations:transectMedia.uploadDialog.error")})}};return(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"sm:min-w-[500px]",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-md font-bold text-white",children:i("monitoring-observations:transectMedia.uploadDialog.title")}),(0,s.jsx)(x.DialogClose,{onClick:a,children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]}),(0,s.jsx)(x.DialogDescription,{children:i("monitoring-observations:transectMedia.uploadDialog.maxSize",{size:100})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsx)("div",{className:"w-fit rounded-full border border-dark-mode-blue-600(base) px-3 py-1.5 text-sm text-white",children:(null==v?void 0:v.name)||"Transect ".concat(null==v?void 0:v.id)}),(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(e3.u,{onDrop:e=>{e.dataTransfer.files.length&&_(t=>[...t,...Array.from(e.dataTransfer.files)])},children:[(0,s.jsx)(e3.b,{accept:w,onChange:e=>{let t=e.target.files;t&&_(e=>[...e,...Array.from(t)])},currentNumberOfFiles:k.length,maxNumberOfFiles:99}),(0,s.jsx)(d.In,{icon:"ic:outline-cloud-upload",width:36,height:24,className:"text-dark-mode-monitoring-600(base)"}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"font-medium text-white",children:"images"===t?i("monitoring-observations:transectMedia.uploadDialog.dropImages"):i("monitoring-observations:transectMedia.uploadDialog.dropVideos")}),(0,s.jsx)("p",{className:"text-xs text-light-mode-black-300",children:i("monitoring-observations:transectMedia.uploadDialog.maxFileSize",{size:10})})]})]}),k.length>0&&(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("span",{className:"text-white",children:i("common.files.selected")}),(0,s.jsx)("ul",{className:"flex flex-col gap-3",children:k.map((e,t)=>{var a;return(0,s.jsxs)("li",{className:"flex flex-col gap-2 rounded-xl border border-dark-mode-blue-600(base) p-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 text-light-mode-black-300",children:[(0,s.jsx)("span",{className:"truncate",children:e.name}),(0,s.jsx)(h.$,{variant:"unstyled",onClick:()=>(e=>{C(e),y(t=>{let a={};return Object.entries(t).forEach(t=>{let[s,i]=t,n=Number(s);n<e?a[n]=i:n>e&&(a[n-1]=i)}),a})})(t),children:(0,s.jsx)(d.In,{icon:"carbon:close",width:20,height:20,className:"text-white"})})]}),(0,s.jsx)(e6.bL,{placeholder:i("monitoring-observations:transectMedia.uploadDialog.perFileDescriptionPlaceholder"),variant:"dark-mode",className:"rounded-xl border border-dark-mode-blue-600(base) text-white",withoutParent:!0,value:null!=(a=j[t])?a:"",onChange:e=>y(a=>({...a,[t]:e.target.value})),disabled:I})]},"".concat(e.name,"-").concat(t))})})]})]}),(0,s.jsxs)(h.$,{variant:"monitoring-600(base)",disabled:A,className:"mt-2",onClick:z,children:[I&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:20,height:20,className:"mr-2 text-white"}),i("monitoring-observations:transectMedia.uploadDialog.submit")]})]})]})},e8=e=>{let{onNoteSaved:t}=e,{t:a}=(0,c.A)("monitoring"),{canEditSite:i}=(0,Z.A)(),[n,l]=(0,m.useState)(!1),[r,o]=(0,m.useState)(null);return i?n?(0,s.jsx)("div",{className:"rounded-xl border border-dark-mode-blue-600(base) p-3",children:(0,s.jsx)(e2,{onCancel:()=>l(!1),onSave:()=>{l(!1),t()}})}):(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-3 rounded-xl border border-dashed border-dark-mode-blue-600(base) px-4 py-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm font-semibold text-white",children:[(0,s.jsx)(d.In,{icon:"akar-icons:plus",width:16,height:16,className:"text-dark-mode-monitoring-600(base)"}),(0,s.jsx)("span",{children:a("monitoring-observations:fieldJournal.composer.add")})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>o("images"),className:"flex items-center gap-1.5 rounded-full border border-dark-mode-blue-600(base) px-3 py-1.5 text-xs font-medium text-white transition-colors hover:border-dark-mode-blue-1000",children:[(0,s.jsx)(d.In,{icon:"material-symbols:photo-camera-outline",width:14,height:14}),a("monitoring-observations:fieldJournal.composer.photo")]}),(0,s.jsxs)("button",{type:"button",onClick:()=>o("videos"),className:"flex items-center gap-1.5 rounded-full border border-dark-mode-blue-600(base) px-3 py-1.5 text-xs font-medium text-white transition-colors hover:border-dark-mode-blue-1000",children:[(0,s.jsx)(d.In,{icon:"material-symbols:videocam-outline",width:14,height:14}),a("monitoring-observations:fieldJournal.composer.video")]}),(0,s.jsxs)("button",{type:"button",onClick:()=>l(!0),className:"flex items-center gap-1.5 rounded-full border border-dark-mode-blue-600(base) px-3 py-1.5 text-xs font-medium text-white transition-colors hover:border-dark-mode-blue-1000",children:[(0,s.jsx)(d.In,{icon:"material-symbols:sticky-note-2-outline",width:14,height:14}),a("monitoring-observations:fieldJournal.composer.note")]})]}),(0,s.jsx)(x.Root,{open:null!==r,onOpenChange:e=>!e&&o(null),children:null!==r&&(0,s.jsx)(e9,{activeTab:r,closeDialog:()=>o(null)})})]}):null};var e7=a(85164),te=a(88137);let tt=e=>{var t,a;let{note:i,onSave:o,onDelete:x}=e,{t:h}=(0,c.A)("monitoring"),{locale:g="it",query:p}=(0,r.useRouter)(),b=p.slug,v=Number(p.id),f=(0,l.useSession)(),{toast:j}=e0.dj(),[w,N]=(0,m.useState)(!1),[k,_]=(0,m.useState)(!1),C=(null==(t=f.data)?void 0:t.user.id)===i.user_id,{mutateAsync:S,isLoading:I}=(0,n.$mA)({mutation:{onError:()=>{j({variant:"error",description:h("monitoring-observations:transectMedia.notes.error")}),N(!1)},onSuccess:()=>{j({variant:"success",description:h("monitoring-observations:transectMedia.notes.successU
1pdate")}),N(!1)}}}),{mutateAsync:A,isLoading:z}=(0,n.Q6o)({mutation:{onError:()=>{j({variant:"error",description:h("monitoring-observations:transectMedia.notes.error")})},onSuccess:()=>{j({variant:"success",description:h("monitoring-observations:transectMedia.notes.successDelete")}),null==x||x(i.id)}}}),R=async e=>{var t;if(!e.trim())return void N(!1);await S({userSlug:b,siteId:v,noteId:i.id,data:{text:e},headers:{authorization:"Bearer ".concat(null==f||null==(t=f.data)?void 0:t.accessToken)}}),null==o||o({...i,note:e,updated_at:new Date().toISOString()})},D=async()=>{var e;await A({userSlug:b,siteId:v,noteId:i.id,headers:{authorization:"Bearer ".concat(null==f||null==(e=f.data)?void 0:e.accessToken)}})};return(0,s.jsxs)("div",{className:(0,u.cn)("flex flex-col gap-2 text-sm",!w&&"border-b border-dark-mode-blue-600(base) pb-3 last:border-0"),children:[!w&&(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[i.user_profile_image_url?(0,s.jsx)(eA(),{src:i.user_profile_image_url,width:32,height:32,className:"rounded-full",alt:null!=(a=i.user_fullname)?a:"",unoptimized:!0}):(0,s.jsx)("div",{className:"flex h-8 w-8 items-center justify-center rounded-full bg-dark-mode-blue-600(base)",children:(0,s.jsx)(d.In,{icon:"mdi:account",width:20,height:20,className:"text-white"})}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-white",children:i.user_fullname||i.user_email}),(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-1000",children:i.user_role})]}),(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-1000",children:(0,y.default)(new Date(i.created_at),"dd MMM yyyy",{locale:(0,eH.no)(g)})})]})]}),C&&(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{children:(0,s.jsx)(d.In,{icon:"mage:dots",width:20,height:20,color:"white"})}),(0,s.jsxs)(e7.SQ,{side:"right",align:"start",sideOffset:2,className:"min-w-44",variant:"dark-mode-blue-300",children:[(0,s.jsx)(e7._2,{onSelect:e=>{e.preventDefault(),N(!0)},className:"cursor-pointer rounded-md",variant:"dark-mode-blue-300",children:h("common:common.edit")}),(0,s.jsx)(e7._2,{onSelect:e=>{e.preventDefault(),_(!0)},className:"cursor-pointer rounded-md font-bold text-red-600 hover:bg-red-500 hover:text-white",children:h("common:common.delete")})]})]})]}),C&&(0,s.jsx)(te.K,{open:k,onOpenChange:_,onConfirm:D,isLoading:z,title:h("common:alert"),description:h("monitoring-observations:transectMedia.notes.confirmDeleteDescription")}),(0,s.jsx)(e1.w,{isEditing:w,text:i.note,onCancel:()=>N(!1),onConfirm:R,className:"whitespace-break-spaces text-light-mode-black-200",hideSlotBefore:!0,footer:(0,s.jsxs)("div",{className:"mt-4 flex flex-row justify-end gap-2",children:[(0,s.jsx)(e1.w.CancelButton,{disabled:I,variant:"outline-monitoring-600(base)",className:"w-max px-4 py-2",children:h("common:cancel")}),(0,s.jsx)(e1.w.ConfirmButton,{disabled:I,variant:"monitoring-600(base)",className:"w-max px-4 py-2",children:h("common:save")})]})})]})};var ta=a(27942),ts=a(78929),ti=a.n(ts);let tn=e=>{let{item:t,onMediaChanged:a}=e,{t:i}=(0,c.A)("monitoring"),{locale:o="it"}=(0,r.useRouter)(),{canEditSite:u}=(0,Z.A)(),[g,p]=(0,m.useState)(!1),[b,v]=(0,m.useState)(!1),f=t.raw,j="image"===t.type,{deleteMedia:w,saveDescription:N,isDeleting:k,isUpdatingDescription:_}=(e=>{let{t}=(0,c.A)("monitoring"),{query:a}=(0,r.useRouter)(),s=a.slug,i=Number(a.id),o=(0,l.useSession)(),{toast:d}=e0.dj(),{mutateAsync:m,isLoading:u}=(0,n.qBu)({mutation:{onError:()=>{d({variant:"error",description:t("monitoring-observations:transectMedia.uploadDialog.error")})},onSuccess:()=>{d({variant:"success",description:t("monitoring-observations:transectMedia.media.deleteSuccess")}),e()}}}),{mutateAsync:x,isLoading:h}=(0,n.z3i)({mutation:{onError:()=>{d({variant:"error",description:t("monitoring-observations:transectMedia.uploadDialog.error")})},onSuccess:()=>{d({variant:"success",description:t("monitoring-observations:transectMedia.media.descriptionUpdated")}),e()}}});return{deleteMedia:e=>{var t;return m({userSlug:s,siteId:i,mediaId:e.id,headers:{authorization:"Bearer ".concat(null==(t=o.data)?void 0:t.accessToken)}})},saveDescription:(e,t)=>{var a;return x({userSlug:s,siteId:i,mediaId:e.id,data:{description:t.trim()||void 0},headers:{authorization:"Bearer ".concat(null==(a=o.data)?void 0:a.accessToken)}})},isDeleting:u,isUpdatingDescription:h}})(()=>{v(!1),p(!1),a()}),C=(0,y.default)(new Date(f.created_at),"dd MMM yyyy",{locale:(0,eH.no)(o)}),S=j?i("monitoring-observations:transectMedia.tabs.images"):i("monitoring-observations:transectMedia.tabs.videos");return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,s.jsxs)(V.E,{variant:"darkModeBlue1100",rounded:"lg",size:"xs",className:"gap-1.5 !bg-dark-mode-blue-300 !text-dark-mode-monitoring-600(base)",children:[(0,s.jsx)(d.In,{icon:j?"material-symbols:photo-camera-outline":"material-symbols:videocam-outline",width:14,height:14}),S]}),(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-1000",children:C})]}),(0,s.jsx)("button",{type:"button",onClick:()=>p(!0),className:"relative aspect-video w-full max-w-xs overflow-hidden rounded-xl border border-dark-mode-blue-600(base)",children:j?(0,s.jsx)(eA(),{src:f.media_url,alt:f.description||"",fill:!0,className:"object-cover",unoptimized:!0}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("video",{src:f.media_url,className:"h-full w-full object-cover",muted:!0,preload:"metadata"}),(0,s.jsx)("span",{className:"absolute inset-0 flex items-center justify-center bg-black/30",children:(0,s.jsx)(d.In,{icon:"material-symbols:play-circle",width:48,height:48,className:"text-white"})})]})}),f.description&&(0,s.jsx)("p",{className:"whitespace-break-spaces text-sm text-light-mode-black-200",children:f.description})]}),(0,s.jsx)(x.Root,{open:g,onOpenChange:p,children:(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"sm:min-w-[640px]",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-md font-bold text-white",children:S}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[u&&(0,s.jsx)(h.$,{variant:"textOnlyAqua",title:f.de
1scription?i("monitoring-observations:transectMedia.media.editDescription"):i("monitoring-observations:transectMedia.media.addDescription"),onClick:()=>v(e=>!e),children:(0,s.jsx)(d.In,{icon:"material-symbols:edit-outline",width:22,height:22})}),(0,s.jsx)(h.$,{variant:"textOnlyAqua",asChild:!0,children:(0,s.jsx)(ti(),{href:f.media_url,target:"_blank",download:!0,children:(0,s.jsx)(d.In,{icon:"material-symbols:download",width:22,height:22})})}),u&&(0,s.jsx)(te.K,{onConfirm:async()=>{await w(f)},isLoading:k,title:i("common:alert"),description:i("monitoring-observations:transectMedia.media.confirmDeleteDescription"),trigger:(0,s.jsx)(h.$,{variant:"textOnlyAqua",className:"!text-red-500",children:(0,s.jsx)(d.In,{icon:"material-symbols:delete-outline",width:22,height:22})})})]})]}),(0,s.jsx)(ta.bL,{media:[f],mode:"vertical",children:(0,s.jsx)(ta.rd,{children:()=>{var e;return(0,s.jsxs)("div",{className:"relative flex-1",children:[j?(0,s.jsx)(ta.H0,{src:f.media_url,alt:f.description||""}):(0,s.jsx)(ta.TZ,{src:f.media_url}),b?(0,s.jsx)("div",{className:"mt-3 rounded-xl bg-dark-mode-blue-200 p-3",children:(0,s.jsx)(e1.w,{isEditing:!0,text:null!=(e=f.description)?e:"",onCancel:()=>v(!1),onConfirm:e=>N(f,e),className:"whitespace-break-spaces text-light-mode-black-200",hideSlotBefore:!0,footer:(0,s.jsxs)("div",{className:"mt-4 flex flex-row justify-end gap-2",children:[(0,s.jsx)(e1.w.CancelButton,{disabled:_,variant:"outline-monitoring-600(base)",className:"w-max px-4 py-2",children:i("common:cancel")}),(0,s.jsx)(e1.w.ConfirmButton,{disabled:_,variant:"monitoring-600(base)",className:"w-max px-4 py-2",children:i("common:save")})]})})}):f.description&&(0,s.jsx)(ta.HL,{className:j?"bottom-2":void 0,children:f.description})]})}})})]})})]})},tl=e=>{var t,a,i;let{item:n,onGoToPin:l}=e,{t:o}=(0,c.A)("monitoring"),{locale:m="it"}=(0,r.useRouter)(),u=n.raw,x=(0,y.default)(new Date(null!=(a=u.last_activity_at)?a:u.created_at),"dd MMM yyyy",{locale:(0,eH.no)(m)}),h="".concat(u.latitude.toFixed(5),", ").concat(u.longitude.toFixed(5)),g=(null!=(i=null==(t=u.created_by_user_email)?void 0:t[0])?i:"?").toUpperCase();return(0,s.jsxs)("div",{className:"flex flex-col gap-2 rounded-xl border border-dark-mode-monitoring-600(base)/40 bg-dark-mode-monitoring-600(base)/5 p-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("div",{className:"flex h-8 w-8 items-center justify-center rounded-full bg-dark-mode-monitoring-600(base) text-sm font-bold text-[#0d121e]",children:g}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-white",children:u.created_by_user_email}),(0,s.jsxs)("span",{className:"flex items-center gap-1 rounded-full bg-dark-mode-monitoring-600(base)/20 px-2 py-0.5 text-[10px] font-semibold text-dark-mode-monitoring-600(base)",children:[(0,s.jsx)(d.In,{icon:"material-symbols:location-on-outline",width:11,height:11}),o("monitoring-observations:fieldJournal.pin.onMap")]})]}),(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-1000",children:x})]})]}),(0,s.jsx)("p",{className:"line-clamp-3 whitespace-break-spaces text-sm text-light-mode-black-200",children:u.text_preview}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-dark-mode-blue-1000",children:[(0,s.jsx)(d.In,{icon:"material-symbols:location-on-outline",width:12,height:12}),h]}),(0,s.jsxs)("button",{type:"button",onClick:()=>l(u.id),className:"flex items-center gap-1.5 text-xs font-semibold text-dark-mode-monitoring-600(base) hover:underline",children:[o("monitoring-observations:fieldJournal.pin.goToMap"),(0,s.jsx)(d.In,{icon:"material-symbols:open-in-new",width:13,height:13})]})]}),u.replies_count>0&&(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-1000",children:o("monitoring-observations:fieldJournal.pin.threadCount",{count:u.replies_count})})]})},tr=e=>{let{item:t,onMediaChanged:a,onNoteChanged:i,onGoToPin:n}=e;switch(t.type){case"image":case"video":return(0,s.jsx)(tn,{item:t,onMediaChanged:a});case"note":return(0,s.jsx)(tt,{note:t.raw,onSave:i,onDelete:i});case"pin":return(0,s.jsx)(tl,{item:t,onGoToPin:n})}},to=e=>{let{items:t,isLoading:a,onMediaChanged:i,onNoteChanged:n,onGoToPin:l}=e,{t:r}=(0,c.A)("monitoring");return a?(0,s.jsx)(Y.A,{width:"100%",height:120,count:3,containerClassName:"flex w-full flex-col gap-3"}):0===t.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-10 text-center",children:[(0,s.jsx)(d.In,{icon:"material-symbols:book-2-outline",width:32,height:32,className:"text-dark-mode-blue-1000"}),(0,s.jsx)("span",{className:"text-sm text-light-mode-black-300",children:r("monitoring-observations:fieldJournal.empty")})]}):(0,s.jsx)("div",{className:"flex flex-col gap-4",children:t.map(e=>(0,s.jsx)("div",{className:"border-b border-dark-mode-blue-600(base) pb-4 last:border-0 last:pb-0",children:(0,s.jsx)(tr,{item:e,onMediaChanged:i,onNoteChanged:n,onGoToPin:l})},e.key))})};var td=a(36202);let tc=(0,g.tv)({slots:{chip:"flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-xs font-medium transition-colors",count:"flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px] font-bold leading-none"},variants:{active:{true:{chip:"border-dark-mode-monitoring-600(base) bg-dark-mode-monitoring-600(base) text-[#0d121e]",count:"bg-[#0d121e] text-dark-mode-monitoring-600(base)"},false:{chip:"border-dark-mode-blue-600(base) bg-transparent text-white hover:border-dark-mode-blue-1000",count:"bg-dark-mode-blue-600(base) text-white"}}},defaultVariants:{active:!1}}),tm={image:"material-symbols:photo-camera-outline",video:"material-symbols:videocam-outline",note:"material-symbols:sticky-note-2-outline",pin:"material-symbols:location-on-outline"},tu=e=>
1{let{value:t,onChange:a,counts:i}=e,{t:n}=(0,c.A)("monitoring"),l=[{id:"all",label:n("monitoring-observations:fieldJournal.filters.all"),count:i.all},{id:"image",label:n("monitoring-observations:fieldJournal.filters.photos"),count:i.image,icon:tm.image},{id:"video",label:n("monitoring-observations:fieldJournal.filters.videos"),count:i.video,icon:tm.video},{id:"note",label:n("monitoring-observations:fieldJournal.filters.notes"),count:i.note,icon:tm.note},{id:"pin",label:n("monitoring-observations:fieldJournal.filters.map"),count:i.pin,icon:tm.pin}];return(0,s.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:l.map(e=>{let i=t===e.id,{chip:n,count:l}=tc({active:i});return(0,s.jsxs)("button",{type:"button",onClick:()=>a(e.id),className:(0,u.cn)(n()),"aria-pressed":i,children:[e.icon&&(0,s.jsx)(d.In,{icon:e.icon,width:14,height:14}),(0,s.jsx)("span",{children:e.label}),(0,s.jsx)("span",{className:(0,u.cn)(l()),children:e.count})]},e.id)})})},tx=()=>{var e,t,a,i,o,u;let{t:x}=(0,c.A)("monitoring"),{query:h}=(0,r.useRouter)(),g=h.slug,p=Number(h.id),b=(0,G.Q)(),v=(0,U.r)(),f=(0,l.useSession)(),{area:j,polygonVersion:y}=(0,L._R)(),{setIsPanelOpen:w,setSelectedPinId:N}=(0,eX.t)(),{canEditSite:k}=(0,Z.A)(),[_,C]=(0,m.useState)("all"),[S,I]=(0,m.useState)(!1),A=null==(e=f.data)?void 0:e.accessToken,z={authorization:"Bearer ".concat(A)},R=!!(null==j?void 0:j.id)&&!!A,D=!!(null==y?void 0:y.id)&&!!(null==j?void 0:j.id)&&!!A,{data:M,isLoading:T,refetch:E}=(0,n.Fbu)(g,p,{trancept_area_id:null!=(t=null==j?void 0:j.id)?t:0,media_type:"image"},z,{query:{enabled:R}}),{data:F,isLoading:O,refetch:B}=(0,n.Fbu)(g,p,{trancept_area_id:null!=(a=null==j?void 0:j.id)?a:0,media_type:"video"},z,{query:{enabled:R}}),{data:H,isLoading:q,refetch:V}=(0,n.uDx)(g,p,{trancept_area_id:null!=(i=null==j?void 0:j.id)?i:0},z,{query:{enabled:R}}),{data:W,isLoading:$}=(0,n.s0H)(g,p,null!=(o=null==y?void 0:y.id)?o:0,{layer_type:(0,td.me)(null!=(u=null==j?void 0:j.id)?u:0)},z,{query:{enabled:D}}),Q=(0,m.useMemo)(()=>{var e;return(0,td.Ws)(W,null!=(e=null==j?void 0:j.id)?e:0)},[W,null==j?void 0:j.id]),K=(0,m.useMemo)(()=>(0,td.R0)(M,F,H,Q),[M,F,H,Q]),J=(0,m.useMemo)(()=>(0,td.dh)(K),[K]),Y=(0,m.useMemo)(()=>"all"===_?K:K.filter(e=>e.type===_),[K,_]);return j?(0,s.jsxs)(P.bL,{id:"census-transect-media","data-description":"Unified field journal for a selected transect: chronological feed merging images, videos, notes and geolocated pins",variant:"transparent",children:[!b&&(0,s.jsxs)(P.Y9,{variant:v,className:"flex flex-wrap items-end justify-between gap-3",children:[(0,s.jsx)(eJ.l,{level:"section",children:x("monitoring-observations:transectMedia.title")}),k&&(0,s.jsxs)("button",{type:"button",onClick:()=>I(!0),title:x("monitoring-observations:transectsOverview.manageButton"),className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-mode-blue-600(base) px-3 py-1.5 text-xs font-semibold text-white transition-colors hover:border-dark-mode-blue-1000",children:[(0,s.jsx)(d.In,{icon:"material-symbols:settings-outline",width:14,height:14}),x("monitoring-observations:transectsOverview.manageButton")]})]}),(0,s.jsx)(P.nB,{variant:v,spacing:"md",className:"!rounded-xl",children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(tu,{value:_,onChange:C,counts:J}),(0,s.jsx)(e8,{onNoteSaved:()=>V()}),(0,s.jsx)(to,{items:Y,isLoading:T||O||q||$,onMediaChanged:()=>{E(),B()},onNoteChanged:()=>V(),onGoToPin:e=>{var t;N(e),w(!0),null==(t=document.getElementById("census-trancepts-devices-map"))||t.scrollIntoView({behavior:"smooth"})}})]})}),k&&(0,s.jsx)(eY.Z,{open:S,onOpenChange:I})]}):null};var th=a(68505),tg=a(11549),tp=a(69193);let tb=e=>{let{area:t,userSlug:a,siteId:i,plantationsPolygonsId:n,accessToken:l,onOpenJournal:r}=e,{t:o}=(0,c.A)("monitoring"),m=(0,tp.W)({userSlug:a,siteId:i,plantationsPolygonsId:n,areaId:t.id,accessToken:l}),u=t.name&&""!==t.name?t.name:o("monitoring-observations:transectsOverview.untitled",{id:t.id});return(0,s.jsxs)("button",{type:"button",onClick:()=>r({id:t.id,name:u}),className:"group flex w-full flex-col gap-2 rounded-xl border border-dark-mode-blue-600(base) px-4 py-3 text-left transition-colors hover:border-dark-mode-monitoring-600(base) md:flex-row md:items-center md:gap-4",children:[(0,s.jsx)("span",{className:"min-w-[160px] flex-1 truncate text-sm font-semibold text-white",children:u}),(0,s.jsx)("div",{className:"flex flex-1 items-center",children:(0,s.jsx)(tg.X,{counts:m,size:"sm"})}),(0,s.jsxs)("span",{className:"flex items-center gap-1.5 text-xs font-semibold text-dark-mode-monitoring-600(base)",children:[o("monitoring-observations:transectsOverview.openJournal"),(0,s.jsx)(d.In,{icon:"material-symbols:chevron-right",width:16,height:16,className:"transition-transform group-hover:translate-x-0.5"})]})]})},tv=()=>{var e,t;
1let{t:a}=(0,c.A)("monitoring"),{query:i}=(0,r.useRouter)(),o=i.slug,u=Number(i.id),x=(0,U.r)(),h=null==(e=(0,l.useSession)().data)?void 0:e.accessToken,{area:g,polygonVersion:p,setArea:b}=(0,L._R)(),{canEditSite:v}=(0,Z.A)(),[f,j]=(0,m.useState)(!1),y=null!=(t=null==p?void 0:p.id)?t:0,{data:w=[],isLoading:N}=(0,n.Aex)(o,u,y,{authorization:"Bearer ".concat(h)},{query:{enabled:!!y&&!!h,retry:!1}});if(g||!p)return null;let k=e=>{b(e),requestAnimationFrame(()=>{var e;null==(e=document.getElementById("census-transect-media"))||e.scrollIntoView({behavior:"smooth",block:"start"})})};return(0,s.jsxs)(P.bL,{id:"census-transects-overview","data-description":"Transect overview shown when no transect is selected: lists transects with photo/video/note/pin count chips and opens the field journal on click",variant:"transparent",children:[(0,s.jsxs)(P.Y9,{variant:x,className:"flex flex-wrap items-end justify-between gap-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(d.In,{icon:"material-symbols:description-outline",width:20,height:20,className:"text-dark-mode-monitoring-600(base)"}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)(eJ.l,{level:"section",children:a("monitoring-observations:transectsOverview.title")}),(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-1100",children:a("monitoring-observations:transectsOverview.subtitle")})]})]}),v&&(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>j(!0),className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-mode-blue-600(base) px-3 py-1.5 text-xs font-semibold text-white transition-colors hover:border-dark-mode-blue-1000",children:[(0,s.jsx)(d.In,{icon:"material-symbols:settings-outline",width:14,height:14}),a("monitoring-observations:transectsOverview.manageButton")]}),(0,s.jsx)(th.X,{label:a("monitoring-observations:transectsOverview.drawNew"),className:"inline-flex cursor-pointer items-center gap-1.5 rounded-lg border border-dark-mode-monitoring-600(base) bg-dark-mode-monitoring-600(base)/10 px-3 py-1.5 text-xs font-semibold text-dark-mode-monitoring-600(base) transition-colors hover:bg-dark-mode-monitoring-600(base)/20"})]})]}),(0,s.jsx)(P.nB,{variant:x,spacing:"md",className:"!rounded-xl",children:N?(0,s.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,s.jsx)(d.In,{icon:"eos-icons:three-dots-loading",width:48,height:48,className:"text-dark-mode-monitoring-600(base)"})}):0===w.length?(0,s.jsx)("p",{className:"py-8 text-center text-sm text-dark-mode-blue-1100",children:a("monitoring-observations:transectsOverview.empty")}):(0,s.jsx)("div",{className:"flex flex-col gap-2",children:w.map(e=>(0,s.jsx)(tb,{area:e,userSlug:o,siteId:u,plantationsPolygonsId:y,accessToken:h,onOpenJournal:k}
1,e.id))})}),v&&(0,s.jsx)(eY.Z,{open:f,onOpenChange:j})]})};var tf=a(18508);let tj=()=>{let{t:e}=(0,c.A)("monitoring"),{toolbarViewMode:t}=(0,L._R)();return"transects"!==t?null:(0,s.jsxs)("div",{className:"flex items-start gap-2 bg-dark-mode-blue-200 px-4 py-3 text-dark-mode-blue-1100",children:[(0,s.jsx)(d.In,{icon:"material-symbols:info-outline-rounded",width:20,height:20,className:"mt-0.5 shrink-0"}),(0,s.jsx)("p",{className:"text-sm",children:(0,s.jsx)(tf.A,{text:e("monitoring-observations:censuses.legend.info"),components:{bold:(0,s.jsx)("b",{className:"font-bold"})}})})]})},ty=E()(()=>Promise.all([a.e(69468),a.e(46593),a.e(38058),a.e(80188),a.e(67296),a.e(75447),a.e(97825),a.e(9591),a.e(80674),a.e(5607),a.e(53688)]).then(a.bind(a,47646)).then(e=>e.Map),{loadableGenerated:{webpack:()=>[47646]},ssr:!1}),tw=()=>{let{viewTab:e,viewSection:t}=(0,L._R)();if("sensors"===t)return(0,s.jsx)("div",{className:"flex flex-col gap-15",children:(0,s.jsx)(O.n,{})});let a=(e=>{switch(e){case"detail":return"border-dark-mode-blue-1000/50";case"sensors":return"border-dark-mode-monitoring-600(base)/50";default:return"border-dark-mode-blue-1100/50"}})(e);return"sensors"===e?(0,s.jsx)("div",{className:"flex flex-col gap-15 border-t-2 transition-colors duration-300 ".concat(a),children:(0,s.jsx)(O.n,{})}):"summary"===e?(0,s.jsx)("div",{className:"flex flex-col gap-15",children:(0,s.jsx)(eZ,{})}):(0,s.jsx)(M.Cg,{children:(0,s.jsxs)("div",{className:"flex flex-col gap-3 p-3",children:[(0,s.jsx)(ty,{}),(0,s.jsx)(tj,{}),(0,s.jsx)(F.y,{}),(0,s.jsx)(B.K,{}),(0,s.jsx)(tv,{}),(0,s.jsx)(tx,{})]})})},tN=e=>{let{validCount:t,isSubmitting:a,isDisabled:i,onCancel:n,onConfirm:l}=e,{t:r}=(0,c.A)("monitoring");return(0,s.jsxs)(x.DialogFooter,{className:"mt-2 flex flex-row justify-end gap-2",children:[(0,s.jsx)(h.$,{variant:"unstyled",onClick:n,disabled:a,className:"rounded-md px-3 py-1.5 text-sm text-white hover:opacity-80 disabled:opacity-40",children:r("hivesGeofileImport.actions.cancel")}),(0,s.jsxs)(h.$,{variant:"monitoring-600(base)",className:"min-w-[180px]",onClick:l,disabled:i||a||0===t,children:[a&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:18,height:18,className:"mr-2"}),r("hivesGeofileImport.actions.submit",{count:t})]})]})},tk=[".kml",".kmz",".zip"],t_=["name","Name","NAME","nome","Nome","hive_name","HIVE_NAME"],tC=e=>{let{onFileSelected:t,onClientValidationError:a,isUploading:i,inlineError:n}=e,{t:l}=(0,c.A)("monitoring"),r=(0,m.useCallback)(e=>{let t=function(e){let t=e.lastIndexOf(".");return -1===t?"":e.slice(t).toLowerCase()}(e.name);return tk.includes(t)?e.size>0xa00000?l("hivesGeofileImport.errors.file_too_large"):null:l("hivesGeofileImport.errors.unsupported_format")},[l]),o=(0,m.useCallback)(e=>{if(!e)return;let s=r(e);if(s)return void a(s);t(e)},[r,t,a]);return(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsxs)(e3.u,{onDrop:e=>{var t;o(null==(t=e.dataTransfer.files)?void 0:t[0])},children:[(0,s.jsx)(e3.b,{accept:tk.join(","),onChange:e=>{var t;o(null==(t=e.target.files)?void 0:t[0])},currentNumberOfFiles:0,maxNumberOfFiles:1}),i?(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:36,height:36,className:"text-dark-mode-monitoring-600(base)"}):(0,s.jsx)(d.In,{icon:"material-symbols:map-rounded",width:36,height:36,className:"text-dark-mode-monitoring-600(base)"}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"font-medium text-white",children:i?l("hivesGeofileImport.dropzone.analyzing"):l("hivesGeofileImport.dropzone.label")}),(0,s.jsx)("p",{className:"text-xs text-light-mode-black-300",children:l("hivesGeofileImport.dropzone.sizeHint",{size:10,features:500})}),(0,s.jsx)("p",{className:"text-xs text-light-mode-black-300",children:l("hivesGeofileImport.dropzone.formatHint")})]})]}),n&&(0,s.jsx)("span",{className:"text-xs text-red-400",children:n})]})},tS=e=>{let{errors:t,warnings:a,validCount:i,highlightedFeatureIndex:n,onHighlightFeature:l,includeOutOfSite:r,onIncludeOutOfSiteChange:o}=e,{t:x}=(0,c.A)("monitoring"),[h,g]=(0,m.useState)(new Set),p=(0,m.useMemo)(()=>{let e=new Map;return t.forEach(t=>{var a;let s=null!=(a=e.get(t.reason))?a:[];s.push(t),e.set(t.reason,s)}),Array.from(e.entries())},[t]),b=(0,m.useMemo)(()=>t.filter(e=>"out_of_site_bbox"===e.reason).length,[t]),v=r?t.length-b:t.length,f=r?i+b:i;return(0,s.jsxs)("div",{className:"flex flex-col gap-3 text-sm",children:[a.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-1 rounded-md border border-yellow-500/40 bg-yellow-500/10 p-3 text-xs text-yellow-200",children:a.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-start gap-2",children:[(0,s.jsx)(d.In,{icon:"material-symbols:warning-outline-rounded",width:16,height:16,className:"mt-0.5 shrink-0"}),(0,s.jsx)("span",{children:x("hivesGeofileImport.warnings.".concat(e.reason),{defaultValue:e.detail})})]},"warning-".concat(t)))}),(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-md bg-dark-mode-blue-300 px-3 py-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,s.jsx)("span",{className:"inline-flex h-2 w-2 rounded-full bg-emerald-400"}),(0,s.jsx)("span",{className:"text-white",children:x("hivesGeofileImport.summary.valid",{count:f})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,s.jsx)("span",{className:"inline-flex h-2 w-2 rounded-full bg-red-400"}),(0,s.jsx)("span",{className:"text-white",children:x("hivesGeofileImport.summary.discarded",{count:v})})]})]}),0===p.length?(0,s.jsx)("div",{className:"rounded-md border border-emerald-500/30 bg-emerald-500/10 p-3 text-xs text-emerald-200",children:x("hivesGeofileImport.errors.empty")}):(0,s.jsx)("ul",{className:"flex max-h-[360px] flex-col gap-2 overflow-y-auto pr-1",children:p.map(e=>
1{let[t,a]=e,i=h.has(t),c="out_of_site_bbox"===t,m=c&&r?"bg-amber-500/20 text-amber-200":"bg-red-500/20 text-red-200";return(0,s.jsxs)("li",{className:"rounded-md border border-dark-mode-blue-300",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center justify-between gap-2 px-3 py-2 text-left text-xs font-medium text-white hover:bg-dark-mode-blue-300/60",onClick:()=>(e=>{g(t=>{let a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})})(t),children:[(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsx)(d.In,{icon:i?"material-symbols:expand-more":"material-symbols:chevron-right",width:16,height:16}),x("hivesGeofileImport.errors.reason.".concat(t))]}),(0,s.jsx)("span",{className:(0,u.cn)("rounded-full px-2 py-0.5 text-[11px]",m),children:a.length})]}),c&&(0,s.jsxs)("label",{className:"flex items-center gap-2 border-t border-dark-mode-blue-300 px-3 py-2 text-xs text-white hover:bg-dark-mode-blue-300/40",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("input",{type:"checkbox",checked:r,onChange:e=>o(e.target.checked),className:"h-3.5 w-3.5 cursor-pointer accent-emerald-500"}),(0,s.jsx)("span",{children:x("hivesGeofileImport.outOfSite.toggle",{count:a.length})})]}),i&&(0,s.jsx)("ul",{className:"flex flex-col gap-1 px-3 pb-2 pt-1 text-xs text-light-mode-black-300",children:a.map(e=>{let t=n===e.feature_index;return(0,s.jsxs)("li",{className:(0,u.cn)("flex flex-col gap-0.5 rounded-md px-2 py-1.5 transition-colors",{"bg-dark-mode-blue-400/60":t,"hover:bg-dark-mode-blue-400/30":!t}),onMouseEnter:()=>l(e.feature_index),onMouseLeave:()=>l(null),children:[(0,s.jsxs)("span",{className:"text-white",children:["#",e.feature_index," â ",e.detail]}),e.attributes&&(0,s.jsx)("span",{className:"text-[11px] text-primary-blue-300",children:function(e){if(!e)return"";let t=Object.entries(e).slice(0,2);return 0===t.length?"":t.map(e=>{let[t,a]=e,s="string"==typeof a?a:JSON.stringify(a),i=s.length>40?"".concat(s.slice(0,40),"â¦"):s;return"".concat(t,": ").concat(i)}).join(" \xb7 ")}(e.attributes)})]},"".concat(e.reason,"-").concat(e.feature_index))})})]},t)})})]})};var tI=a(8677),tA=a(52375),tz=a(84723),tR=a.n(tz),tD=a(82154),tM=a(82702);let tT=[42.5,12.5],tE=[20,20];function tL(e,t){let a=Math.round(22*t),s=Math.round(10*t);return tR().divIcon({html:'<div style="position:relative;width:'.concat(a,"px;height:").concat(a,'px;display:flex;align-items:center;justify-content:center;">\n <div style="position:absolute;inset:0;border-radius:9999px;background:').concat(e,';opacity:0.25;"></div>\n <div style="position:relative;width:').concat(s,"px;height:").concat(s,"px;border-radius:9999px;background:").concat(e,';box-shadow:0 0 0 2px white;"></div>\n </div>'),iconSize:[a,a],iconAnchor:[a/2,a/2],popupAnchor:[0,-a/2],className:"hives-geofile-import-marker"})}let tF=e=>{let{validHives:t,errorsWithCoords:a,highlightedFeatureIndex:i,onHighlightFeature:n,siteLatitude:l,siteLongitude:r,includeOutOfSite:o}=e,{t:d}=(0,c.A)("monitoring"),u=(0,m.useMemo)(()=>tL("#10b981",1),[]),x=(0,m.useMemo)(()=>tL("#ef4444",1),[]),h=(0,m.useMemo)(()=>tL("#f59e0b",1),[]),g=(0,m.useMemo)(()=>tL("#10b981",1.4),[]),p=(0,m.useMemo)(()=>tL("#ef4444",1.4),[]),b=(0,m.useMemo)(()=>tL("#f59e0b",1.4),[]),v=(0,m.useMemo)(()=>{let e=[];return(t.forEach(t=>{e.push([t.latitude,t.longitude])}),a.forEach(t=>{e.push([t.latitude,t.longitude])}),0===e.length&&null!==l&&null!==r)?[[l-.01,r-.01],[l+.01,r+.01]]:e},[t,a,l,r]),f=(0,m.useMemo)(()=>null!==l&&null!==r?[l,r]:tT,[l,r]);return(0,s.jsxs)(tI.default,{id:"hives-geofile-import-map",height:"100%",variant:"green",bounds:v,center:f,className:"relative h-full w-full overflow-hidden rounded-lg",maxZoomRefreshBounds:tA.gl,mapExtraOptions:{boundsOptions:{padding:tE}},children:[t.map(e=>{let t=i===e.source_feature_index;return(0,s.jsx)(tD.p,{position:[e.latitude,e.longitude],icon:t?g:u,eventHandlers:{mouseover:()=>n(e.source_feature_index),mouseout:()=>n(null),click:()=>n(e.source_feature_index)},children:(0,s.jsx)(tM.z,{children:(0,s.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,s.jsx)("span",{className:"font-semibold text-emerald-700",children:e.name}),(0,s.jsxs)("span",{className:"text-gray-600",children:[e.latitude.toFixed(6),", ",e.longitude.toFixed(6)]})]})})},"valid-".concat(e.source_feature_index))}),a.map(e=>{let t=i===e.feature_index,a="out_of_site_bbox"===e.reason&&o;return(0,s.jsx)(tD.p,{position:[e.latitude,e.longitude],icon:a?t?b:h:t?p:x,eventHandlers:{mouseover:()=>n(e.feature_index),mouseout:()=>n(null),click:()=>n(e.feature_index)},children:(0,s.jsx)(tM.z,{children:(0,s.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,s.jsx)("span",{className:a?"font-semibold text-amber-700":"font-semibold text-red-700",children:d("hivesGeofileImport.errors.reason.".concat(e.reason))}),a&&(0,s.jsx)("span",{className:"text-amber-700",children:d("hivesGeofileImport.outOfSite.willBeImported")}),(0,s.jsx)("span",{className:"text-gray-600",children:e.detail})]})})},"error-".concat(e.feature_index))})]})},tO=/lat=(-?\d+(?:\.\d+)?)\s*,\s*lon=(-?\d+(?:\.\d+)?)/i,tB=e=>{let{preview:t,siteLatitude:a,siteLongitude:i,highlightedFeatureIndex:n,onHighlightFeature:l,inlineError:r,includeOutOfSite:o,onIncludeOutOfSiteChange:d}=e,{t:u}=(0,c.A)("monitoring"),x=(0,m.useMemo)(()=>{let e=[];
1return t.errors.forEach(t=>{let a=function(e){let t=tO.exec(e);if(!t)return null;let a=Number(t[1]),s=Number(t[2]);return Number.isNaN(a)||Number.isNaN(s)?null:{latitude:a,longitude:s}}(t.detail);a&&e.push({...t,latitude:a.latitude,longitude:a.longitude})}),e},[t.errors]);return(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"text-sm font-semibold text-white",children:t.source_file.name}),(0,s.jsx)("span",{className:"text-xs text-primary-blue-300",children:u("hivesGeofileImport.sourceFile.summary",{type:t.source_file.type,count:t.source_file.feature_count})})]}),(0,s.jsxs)("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1.1fr)_minmax(0,1fr)]",children:[(0,s.jsx)("div",{className:"h-[360px] min-h-[320px] w-full overflow-hidden rounded-lg border border-dark-mode-blue-300",children:(0,s.jsx)(tF,{validHives:t.valid_hives,errorsWithCoords:x,highlightedFeatureIndex:n,onHighlightFeature:l,siteLatitude:a,siteLongitude:i,includeOutOfSite:o})}),(0,s.jsx)(tS,{errors:t.errors,warnings:t.warnings,validCount:t.valid_hives.length,highlightedFeatureIndex:n,onHighlightFeature:l,includeOutOfSite:o,onIncludeOutOfSiteChange:d})]}),r&&(0,s.jsx)("div",{className:"rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-xs text-red-200",children:u("hivesGeofileImport.errors.submit_failed",{defaultValue:r})})]})};var tP=a(96890),tU=a(90452),tH=a(60952);let tq=["file_too_large","unsupported_format","parse_error","no_features_found","network_error"],tV=/lat=(-?\d+(?:\.\d+)?)\s*,\s*lon=(-?\d+(?:\.\d+)?)/i;function tW(e){if(!e)return null;for(let t of t_){let a=e[t];if("string"==typeof a&&a.trim().length>0)return a.slice(0,100)}return null}let t$=(0,g.tv)({slots:{content:"flex flex-col gap-4",header:"flex flex-row items-center justify-between",title:"!text-md font-bold text-white",description:"text-xs text-primary-blue-300"},variants:{mode:{compact:{content:"max-w-[540px]"},expanded:{content:"min-w-[720px] max-w-[820px]"}}},defaultVariants:{mode:"compact"}}),tQ=e=>{var t,a,i;let{open:o,onOpenChange:u,onSuccess:g}=e,{t:p}=(0,c.A)("monitoring"),{query:b,locale:v="it"}=(0,r.useRouter)(),f=b.slug,j=Number(b.id),y=(0,l.useSession)(),{toast:w}=e0.dj(),{isAdmin:N}=(0,Z.A)(),[k,_]=(0,m.useState)(null),[C,S]=(0,m.useState)(null),I=(0,m.useCallback)(()=>{_(null),S(null),u(!1)},[u]),{state:A,uploadFile:z,confirmImport:R,reset:D,includeOutOfSite:M,setIncludeOutOfSite:T}=function(e){var t;let{userSlug:a,siteId:s,onSuccess:i,onClose:r}=e,o=(0,l.useSession)(),d=(0,e5.jE)(),[c,u]=(0,m.useState)({step:"idle"}),[x,h]=(0,m.useState)(!1),g=(0,m.useMemo)(()=>{var e;return(null==o||null==(e=o.data)?void 0:e.accessToken)?{authorization:"Bearer ".concat(o.data.accessToken)}:void 0},[null==o||null==(t=o.data)?void 0:t.accessToken]),{mutateAsync:p}=(0,n.eZx)(),{mutateAsync:b}=(0,tP.n)({mutationFn:e=>{var t,a,s,i;return t=e.userSlug,a=e.siteId,s=e.data,i=e.headers,(0,tU.S)({url:"/v1/monitoring/".concat(t,"/sites/").concat(a,"/trancepts/hives/bulk-create"),method:"POST",headers:{"Content-Type":"application/json",...i},data:s})}}),v=(0,m.useCallback)(()=>{u({step:"idle"}),h(!1)},[]),f=(0,m.useCallback)(async e=>{u({step:"uploading",file:e}),h(!1);try{let t=await p({userSlug:a,siteId:s,data:{file:e},headers:g});if(0===t.valid_hives.length&&0===t.errors.length)return void u({step:"error",code:"no_features_found",retryable:!0});u({step:"previewing",preview:t,inlineError:null})}catch(t){let e=function(e){if(tH.A.isAxiosError(e)){var t;if(!e.response)return"network_error";let a=null==(t=e.response.data)?void 0:t.detail;if("string"==typeof a&&tq.includes(a))return a}return"parse_error"}(t);u({step:"error",code:e,retryable:"unsupported_format"!==e})}},[p,a,s,g]),j=(0,m.useCallback)(async()=>{if("previewing"!==c.step)return;let e=c.preview,t=e.valid_hives.map(e=>{let t={name:e.name,latitude:e.latitude,longitude:e.longitude};return void 0!==e.id&&null!==e.id&&(t.id=e.id),void 0!==e.device_id&&null!==e.device_id&&(t.device_id=e.device_id),void 0!==e.marker_color&&null!==e.marker_color&&(t.marker_color=e.marker_color),t}),i=x?function(e,t){let a=[],s=t+1;
1return e.forEach(e=>{var t;if("out_of_site_bbox"!==e.reason)return;let i=tV.exec(e.detail);if(!i)return;let n=Number(i[1]),l=Number(i[2]);if(Number.isNaN(n)||Number.isNaN(l))return;let r=null!=(t=tW(e.attributes))?t:"Supporto ".concat(s);tW(e.attributes)||(s+=1),a.push({name:r,latitude:n,longitude:l})}),a}(e.errors,t.length):[],l=[...t,...i];u({step:"submitting",hives:l,preview:e});try{await b({userSlug:a,siteId:s,data:l,headers:g}),d.invalidateQueries((0,n.ef)(a,s)),u({step:"success",createdCount:l.length})}catch(t){u({step:"previewing",preview:e,inlineError:tH.A.isAxiosError(t)&&t.response?String(t.response.status):"network_error"})}},[c,x,b,a,s,g,d]);return(0,m.useEffect)(()=>{if("success"!==c.step)return;let e=setTimeout(()=>{null==i||i(c.createdCount),r(),u({step:"idle"})},3e3);return()=>clearTimeout(e)},[c,i,r]),{state:c,uploadFile:f,confirmImport:j,reset:v,includeOutOfSite:x,setIncludeOutOfSite:h}}({userSlug:f,siteId:j,onSuccess:(0,m.useCallback)(e=>{w({variant:"success",description:p("hivesGeofileImport.toast.success",{count:e})}),null==g||g(e)},[w,p,g]),onClose:I}),{data:E}=(0,n.HFe)(f,j,{"accept-language":v,authorization:"Bearer ".concat(null==y||null==(t=y.data)?void 0:t.accessToken)},{query:{enabled:o&&!!j}}),L=null!=(a=null==E?void 0:E.latitude)?a:null,F=null!=(i=null==E?void 0:E.longitude)?i:null,O="submitting"===A.step,B=t$({mode:"previewing"===A.step||"submitting"===A.step?"expanded":"compact"});return N?(0,s.jsx)(x.Root,{open:o,onOpenChange:e=>{if(e||!O){if(!e){D(),I();return}u(e)}},children:(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:B.content(),onEscapeKeyDown:e=>{O&&e.preventDefault()},onPointerDownOutside:e=>{O&&e.preventDefault()},children:[(0,s.jsxs)(x.DialogHeader,{className:B.header(),children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)(x.DialogTitle,{className:B.title(),children:p("hivesGeofileImport.title")}),(0,s.jsx)(x.DialogDescription,{className:B.description(),children:p("hivesGeofileImport.subtitle")})]}),!O&&(0,s.jsx)(x.DialogClose,{children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]}),"idle"===A.step||"uploading"===A.step?(0,s.jsx)(tC,{onFileSelected:e=>{_(null),z(e)},onClientValidationError:e=>_(e),isUploading:"uploading"===A.step,inlineError:k}):null,("previewing"===A.step||"submitting"===A.step)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tB,{preview:A.preview,siteLatitude:L,siteLongitude:F,highlightedFeatureIndex:C,onHighlightFeature:S,inlineError:"previewing"===A.step?A.inlineError:null,includeOutOfSite:M,onIncludeOutOfSiteChange:T}),(0,s.jsx)(tN,{validCount:A.preview.valid_hives.length+(M?A.preview.errors.filter(e=>"out_of_site_bbox"===e.reason).length:0),isSubmitting:O,isDisabled:!1,onCancel:I,onConfirm:R})]}),"success"===A.step&&(0,s.jsxs)("div",{className:"flex flex-col items-center gap-3 py-6",children:[(0,s.jsx)(d.In,{icon:"material-symbols:check-circle",width:48,height:48,className:"text-emerald-400"}),(0,s.jsx)("span",{className:"text-white",children:p("hivesGeofileImport.toast.success",{count:A.createdCount})})]}),"error"===A.step&&(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex items-start gap-2 rounded-md border border-red-500/40 bg-red-500/10 p-3 text-sm text-red-200",children:[(0,s.jsx)(d.In,{icon:"material-symbols:error-outline-rounded",width:20,height:20,className:"mt-0.5 shrink-0"}),(0,s.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"font-semibold",children:p("hivesGeofileImport.errors.fatal.".concat(A.code,".title"))}),(0,s.jsx)("span",{className:"text-xs",children:p("hivesGeofileImport.errors.fatal.".concat(A.code,".description"))})]})]}),A.retryable&&(0,s.jsx)(h.$,{variant:"monitoring-600(base)",className:"w-full",onClick:D,children:p("hivesGeofileImport.actions.retry")}),!A.retryable&&(0,s.jsx)(h.$,{variant:"monitoring-600(base)",className:"w-full",onClick:I,children:p("hivesGeofileImport.actions.close")})]})]})}):null},tG=()=>{let{t:e}=(0,c.A)("monitoring"),{isAdmin:t}=(0,Z.A)(),[a,i]=(0,m.useState)(!1);return t?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(h.$,{id:"census-hives-geofile-import-button","data-description":"Open dialog to bulk-import hives from a .kml, .kmz, or shapefile .zip",variant:"unstyled",className:"min-w-max gap-1 !text-sm font-semibold !text-white hover:!opacity-60",onClick:()=>i(!0),children:[(0,s.jsx)(d.In,{icon:"material-symbols:map-rounded",width:20,height:20}),e("hivesGeofileImport.trigger")]}),(0,s.jsx)(tQ,{open:a,onOpenChange:i})]}):null};var tK=a(44359),tZ=a(80261),tJ=a(52885),tY=a(8110),tX=a(54569);let t0=/^-?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,t1=/^-?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,t2=e=>tX.z.object({latitude:tX.z.string().regex(t0,e("errors.invalidLatitude")),longitude:tX.z.string().regex(t1,e("errors.invalidLongitude"))}),t5=(e,t,a,s)=>
1{e.invalidateQueries(t(a,s,"observations_censuses")),e.invalidateQueries(t(a,s,"observations_statistics_charts")),e.invalidateQueries(t(a,s,"observations_statistics_charts_species")),e.invalidateQueries(t(a,s,"observations_statistics_charts_date")),e.invalidateQueries(t(a,s,"observations_statistics_grid"))},t4=(0,g.tv)({slots:{text:"",progress:"h-full transition-all"},variants:{status:{pending:{text:"text-dark-mode-blue-400",progress:"bg-dark-mode-blue-400"},processing:{text:"text-primary-blue-300",progress:"bg-primary-blue-300"},completed:{text:"text-green-400",progress:"bg-green-400"},failed:{text:"text-red-400",progress:"bg-red-400"},partial:{text:"text-yellow-400",progress:"bg-yellow-400"}}},defaultVariants:{status:"pending"}}),t3=(0,g.tv)({base:"",variants:{status:{pending:"text-primary-blue-300",processing:"text-primary-blue-300",success:"text-green-400",failed:"text-red-400"}},defaultVariants:{status:"pending"}}),t6=e=>{let{value:t,colorClass:a}=e;return(0,s.jsx)("div",{className:"bg-dark-mode-blue-600 relative h-2 w-full overflow-hidden rounded-full",children:(0,s.jsx)("div",{className:(0,u.cn)("h-full transition-all",a),style:{width:"".concat(t,"%")}})})},t9=e=>{let{t}=(0,c.A)("monitoring");if("batch"===e.mode){let{status:a,progressPercent:i,totalFiles:n,successCount:l,failedCount:r,pendingCount:o,isProcessing:c,isComplete:m}=e,{text:x,progress:h}=t4({status:a}),g=x(),p=h();return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[c&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:20,height:20,className:"text-primary-blue-300"}),m&&"completed"===a&&(0,s.jsx)(d.In,{icon:"material-symbols:check-circle",width:20,height:20,className:"text-green-400"}),m&&"failed"===a&&(0,s.jsx)(d.In,{icon:"material-symbols:error",width:20,height:20,className:"text-red-400"}),m&&"partial"===a&&(0,s.jsx)(d.In,{icon:"material-symbols:warning",width:20,height:20,className:"text-yellow-400"}),(0,s.jsx)("span",{className:(0,u.cn)("font-medium",g),children:t("monitoring-observations:upload.progress.".concat(a))})]}),(0,s.jsx)("span",{className:"text-sm text-dark-mode-blue-400",children:t("monitoring-observations:upload.progress.filesProcessed",{current:l+r,total:n})})]}),(0,s.jsx)(t6,{value:i,colorClass:p}),(0,s.jsxs)("div",{className:"flex gap-4 text-sm",children:[l>0&&(0,s.jsx)("span",{className:"text-green-400",children:t("monitoring-observations:upload.progress.success",{count:l})}),r>0&&(0,s.jsx)("span",{className:"text-red-400",children:t("monitoring-observations:upload.progress.failed_count",{count:r})}),o>0&&(0,s.jsxs)("span",{className:"text-dark-mode-blue-400",children:[t("monitoring-observations:upload.progress.pending"),": ",o]})]})]})}let{status:a,fileName:i,errorMessage:n,clipsProgress:l,totalClips:r,processedClips:o,isLoading:m}=e,x=t3({status:null!=a?a:"pending"});return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(m||"pending"===a||"processing"===a)&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:20,height:20,className:"text-primary-blue-300"}),"success"===a&&(0,s.jsx)(d.In,{icon:"material-symbols:check-circle",width:20,height:20,className:"text-green-400"}),"failed"===a&&(0,s.jsx)(d.In,{icon:"material-symbols:error",width:20,height:20,className:"text-red-400"}),(0,s.jsx)("span",{className:(0,u.cn)("font-medium",x),children:t(a?"monitoring-observations:upload.progress.".concat(a):"monitoring-observations:upload.progress.pending")})]}),i&&(0,s.jsx)("span",{className:"text-sm text-dark-mode-blue-400",children:i}),null!=l&&r&&(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)(t6,{value:l,colorClass:"bg-primary-blue-300"}),(0,s.jsx)("span",{className:"text-sm text-dark-mode-blue-400",children:t("monitoring-observations:upload.progress.clipsProcessed",{current:null!=o?o:0,total:r})})]}),n&&(0,s.jsxs)("div",{className:"flex items-start gap-2 rounded-md bg-red-900/20 p-2 text-sm text-red-300",children:[(0,s.jsx)(d.In,{icon:"carbon:warning-alt",width:16,height:16,className:"mt-0.5 shrink-0"}),(0,s.jsx)("span",{children:n})]})]})},t8=".jpg, .jpeg, .png, .gif, .mp3, .wav, .mp4, .mov",t7="image/*,audio/*,video/*",ae=e=>{let{closeDialog:t}=e,{t:a}=(0,c.A)("monitoring"),{query:i,locale:o="it"}=(0,r.useRouter)(),u=i.slug,g=Number(i.id),p=(0,l.useSession)(),{toast:b}=e0.dj(),{files:v,setFiles:f,removeFileByIndex:j}=(0,e4.M)({accept:t7,maxFiles:1,maxSize:4,onError:e=>{b({variant:"error",description:a("common.files.errors.".concat(e),{files:1,size:4,formats:t8})})}}),w=(0,e5.jE)(),{generateQueryKey:N}=(0,L._R)(),[k,_]=(0,m.useState)(null),[C,I]=(0,m.useState)(!1),[A,z]=(0,m.useState)(""),[R,D]=(0,m.useState)(null),[M,T]=(0,m.useState)(void 0),[E,F]=(0,m.useState)(""),[O,B]=(0,m.useState)(""),[P,U]=(0,m.useState)(!1),[H,q]=(0,m.useState)(""),{status:V,isProcessing:W,isComplete:$,clipsProgress:Q,totalClips:G,processedClips:K,errorMessage:Z}={status:void 0,isProcessing:!1,isComplete:!1,clipsProgress:null,totalClips:void 0,processedClips:void 0,errorMessage:void 0},[J,Y]=(0,m.useState)(""),X=(0,m.useMemo)(()=>(0,tJ.debounce)(e=>Y(e),500),[]);(0,m.useEffect)(()=>X.cancel,[X]),(0,m.useEffect)(()=>{$&&P&&t5(w,N,u,g)},[$,P,w,N,u,g]);let ee=()=>{P&&t5(w,N,u,g),null==t||t()},et=(0,m.useMemo)(()=>!M||!v.length||!E||!O||!t2(a).safeParse({latitude:O.replace(",","."),longitude:E.replace(",",".")}).success,[M,v.length,E,O,a]),{data:ea=[],isFetching:es}=(0,n.o7h)({query:J,locale:o,page_size:15},{query:{enabled:J.length>3}}
1),{mutate:ei,isLoading:en}=(0,n.oqf)({mutation:{onError:()=>{b({variant:"error",description:a("monitoring-observations:upload.single.error")})},onSuccess:e=>{var t,s;if(e.not_uploaded&&e.not_uploaded.length>0)return void b({variant:"error",description:a("monitoring-observations:upload.single.error")});b({variant:"success",description:a("monitoring-observations:upload.single.success")});let i=null!=(s=null==(t=v[0])?void 0:t.name)?s:"";q(i),U(!0),e.batch_id&&(S(e.batch_id,i||a("monitoring-observations:upload.history.typeSingle")),w.invalidateQueries((0,n.jes)(u,g,{limit:20})))}}});return P?(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"sm:min-w-[400px]",children:[(0,s.jsx)("div",{className:"flex flex-col gap-2",children:(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-md font-bold text-white",children:a("monitoring-observations:upload.single.title")}),(0,s.jsx)(x.DialogClose,{onClick:ee,children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]})}),(0,s.jsx)("div",{className:"mt-4",children:(0,s.jsx)(t9,{mode:"single",status:V,fileName:H,errorMessage:Z,clipsProgress:Q,totalClips:G,processedClips:K,isLoading:!V&&W})}),(0,s.jsx)(x.DialogFooter,{className:"mt-4",children:(0,s.jsx)(h.$,{variant:"monitoring-600(base)",className:"w-full",onClick:ee,children:a("monitoring-observations:upload.close")})})]}):(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",ref:_,className:"sm:min-w-[500px]",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-md font-bold text-white",children:a("monitoring-observations:upload.single.title")}),(0,s.jsx)(x.DialogClose,{children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]}),(0,s.jsx)(x.DialogDescription,{children:a("monitoring-observations:upload.single.subtitle",{files:1})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(e3.u,{onDrop:e=>{e.dataTransfer.files.length&&f(Array.from(e.dataTransfer.files))},children:[(0,s.jsx)(e3.b,{accept:t7,onChange:e=>{e.target.files&&f(Array.from(e.target.files))},currentNumberOfFiles:v.length,maxNumberOfFiles:5}),(0,s.jsx)(d.In,{icon:"ic:outline-cloud-upload",width:36,height:24,className:"text-dark-mode-monitoring-600(base)"}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"font-medium text-white",children:a("common.files.label")}),(0,s.jsx)("p",{className:"text-xs text-light-mode-black-300",children:a("common.files.maxFileSize",{size:4})}),(0,s.jsx)("p",{className:"text-xs text-light-mode-black-300",children:a("common.files.acceptedFormats",{formats:t8})})]})]}),v.length>0&&(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-white",children:a("common.files.selected")}),(0,s.jsx)("ul",{className:"flex flex-col gap-1 text-light-mode-black-300",children:v.map((e,t)=>(0,s.jsxs)("li",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{children:e.name}),(0,s.jsx)(h.$,{variant:"unstyled",onClick:()=>j(t),children:(0,s.jsx)(d.In,{icon:"carbon:close",width:20,height:20,className:"text-white"})})]},e.name))})]})]}),(0,s.jsx)("span",{className:"mt-2 text-white",children:a("monitoring-observations:upload.single.details.title")}),(0,s.jsxs)("div",{className:"grid max-w-md grid-cols-1 gap-5 gap-x-9 sm:grid-cols-2",children:[(0,s.jsxs)(ez.bL,{open:C,onOpenChange:e=>{I(e),e||(z(""),Y(""))},children:[(0,s.jsxs)(ez.Wv,{className:"flex h-fit w-full min-w-52 rounded-xl border-none bg-transparent p-2 ring-2 ring-dark-mode-blue-600(base) hover:opacity-70",disabled:en,children:[(0,s.jsxs)("div",{className:"flex flex-col p-1 text-left",children:[(0,s.jsx)("span",{className:"text-xs text-primary-blue-300",children:a("monitoring-observations:upload.single.details.species.label")}),(0,s.jsx)("span",{className:"text-base",children:R?R.name:a("monitoring-observations:upload.single.details.species.placeholder")})]}),(0,s.jsx)(d.In,{icon:"ci:search-magnifying-glass",width:20,height:20,className:"ml-auto self-center text-white"})]}),(0,s.jsx)(ez.hl,{container:k,className:"bg-dark-mode-blue-300",align:"start",children:(0,s.jsxs)(tY.bL,{shouldFilter:!1,children:[(0,s.jsx)(tY.pd,{variant:"blue-600(base)",placeholder:a("monitoring-observations:upload.single.details.species.placeholder"),className:"h-9",value:A,onValueChange:e=>{z(e),X(e)}}),es&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:40,height:40,className:"mx-auto mt-3 text-white"}),!es&&0===ea.length&&(0,s.jsx)("span",{className:"mt-3 text-center text-sm",children:a("monitoring-observations:upload.single.details.species.noResults")}),(0,s.jsx)(tY.B8,{className:"overflow-hidden",children:(0,s.jsx)(tY.YJ,{variant:"blue-600(base)",className:"pb-0",children:(0,s.jsx)("ul",{className:"custom-scrollbar-dark-mode-blue-300 flex max-h-96 flex-col gap-5 overflow-auto",children:null==ea?void 0:ea.map(e=>(0,s.jsx)(tY.q7,{variant:"blue-600(base)",value:e.taxon_id.toString(),selected:(null==R?void 0:R.taxon_id)===e.taxon_id,onSelect:()=>{D(e),I(!1)},className:"rounded-lg p-0",children:e.name},e.taxon_id))})})})]})})]}),(0,s.jsxs)(ez.bL,{children:[(0,s.jsxs)(ez.Wv,{className:"flex h-fit w-full min-w-52 rounded-xl border-none bg-transparent p-2 ring-2 ring-d
1ark-mode-blue-600(base) hover:opacity-70",disabled:en,children:[(0,s.jsxs)("div",{className:"flex flex-col p-1 text-left",children:[(0,s.jsxs)("span",{className:"text-xs text-primary-blue-300",children:[a("monitoring-observations:upload.single.details.date.label"),(0,s.jsx)("b",{children:" *"})]}),(0,s.jsx)("span",{className:"text-base",children:M?(0,y.default)(M,"yyyy-MM-dd"):a("monitoring-observations:upload.single.details.date.placeholder")})]}),(0,s.jsx)(d.In,{icon:"radix-icons:calendar",width:20,height:20,className:"ml-auto self-center text-white"})]}),(0,s.jsx)(ez.hl,{container:k,className:"w-fit overflow-hidden bg-dark-mode-blue-300 !p-2",children:(0,s.jsx)(tK.h,{_selectedDate:M,_setSelectedDate:T,className:"!m-0 bg-dark-mode-blue-300",disabledDates:{after:new Date}})})]}),(0,s.jsx)(at,{type:"latitude",label:a("monitoring-observations:upload.single.details.latitude.label"),placeholder:a("monitoring-observations:upload.single.details.latitude.placeholder"),value:O?O.toString():"",onChange:e=>B(e.target.value)}),(0,s.jsx)(at,{type:"longitude",label:a("monitoring-observations:upload.single.details.longitude.label"),placeholder:a("monitoring-observations:upload.single.details.longitude.placeholder"),value:E?E.toString():"",onChange:e=>F(e.target.value)})]}),(0,s.jsxs)(h.$,{variant:"monitoring-600(base)",disabled:en||et,className:"mt-5",onClick:()=>{var e;ei({userSlug:u,siteId:g,data:{files:v,upload_date:(0,y.default)(M,"yyyy-MM-dd"),taxon_id:null==R?void 0:R.taxon_id,source:tZ.KQ$.Manual,longitude:Number(E.replace(",",".")),latitude:Number(O.replace(",","."))},headers:(null==p||null==(e=p.data)?void 0:e.accessToken)?{authorization:"Bearer ".concat(p.data.accessToken)}:void 0})},children:[en&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:20,height:20,className:"mr-2 text-white"}),a("monitoring-observations:upload.submit")]})]})]})},at=e=>{let{type:t,label:a,placeholder:i,value:n,onChange:l}=e,{t:r}=(0,c.A)("common"),[o,d]=(0,m.useState)(!0);return(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("label",{className:"text-sm text-white",children:[a,(0,s.jsx)("b",{children:" *"})]}),(0,s.jsx)(e6.bL,{placeholder:i,variant:"dark-mode",className:"rounded-md border border-light-mode-black-400 text-white",withoutParent:!0,value:n,onChange:e=>{l(e),d("latitude"===t?t2(r).shape.latitude.safeParse(e.target.value.replace(",",".")).success:t2(r).shape.longitude.safeParse(e.target.value.replace(",",".")).success)}}),!o&&(0,s.jsx)("span",{className:"text-xs text-red-400",children:"latitude"===t?r("errors.invalidLatitude"):r("errors.invalidLongitude")})]})},aa=e=>{let{devices:t,isLoading:a,value:i,onChange:n,triggerClassName:l=""}=e,{t:r}=(0,c.A)("monitoring"),[o,x]=(0,m.useState)(!1),[h,g]=(0,m.useState)(""),p=(0,m.useMemo)(()=>t.filter(e=>{var t;return null==(t=e.name)?void 0:t.toLowerCase().includes(h.toLowerCase())}),[t,h]);if(a)return(0,s.jsx)(Y.A,{width:150,height:65});if(0===t.length)return null;let b=e=>{n(e),g(""),x(!1)};return(0,s.jsxs)(ez.bL,{modal:!0,open:o,onOpenChange:x,children:[(0,s.jsxs)(ez.Wv,{className:(0,u.cn)("flex h-fit rounded-xl border-none bg-transparent px-2 py-1 ring-2 ring-dark-mode-blue-600(base) hover:opacity-70",l),children:[(0,s.jsxs)("div",{className:"flex flex-col text-left",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-primary-blue-300",children:r("monitoring-observations:upload.gdrive.deviceOptional")}),(0,s.jsx)("span",{className:"truncate text-base capitalize max-lg:max-w-[160px]",children:i?i.name:r("monitoring-observations:upload.gdrive.noDevice")})]}),(0,s.jsx)(d.In,{icon:"radix-icons:triangle-down",className:"ml-auto shrink-0 self-center"})]}),(0,s.jsx)(ez.hl,{withNoPortal:!0,variant:"outline-blue-600(base)",align:"start",className:"z-[12345678] shadow shadow-dark-mode-blue-1100",children:(0,s.jsxs)(tY.bL,{shouldFilter:!1,children:[(0,s.jsx)(tY.pd,{variant:"blue-600(base)",placeholder:r("monitoring-observations:device.search"),className:"h-9",value:h,onValueChange:g}),(0,s.jsx)(tY.B8,{className:"custom-scrollbar-dark-mode-blue-300 max-h-[180px] overflow-y-auto",children:(0,s.jsxs)(tY.YJ,{variant:"blue-600(base)",className:"pb-0",children:[""===h&&(0,s.jsx)(tY.q7,{value:r("monitoring-observations:upload.gdrive.noDevice"),className:"px-2 py-1.5 italic",onSelect:()=>b(null),variant:"blue-600(base)",selected:null===i,children:r("monitoring-observations:upload.gdrive.noDevice")}),p.map(e=>{let{id:t,name:a}=e;return(0,s.jsx)(tY.q7,{value:"".concat(t),className:"px-2 py-1.5 capitalize",onSelect:()=>b({id:t,name:a}),variant:"blue-600(base)",selected:(null==i?void 0:i.id)===t,children:a},t)}),0===p.length&&(0,s.jsx)("span",{className:"block px-2 py-1.5 text-sm text-white",children:r("monitoring-observations:device.n
1oResults")})]})})]})})]})},as=e=>{let{closeDialog:t}=e,{t:a}=(0,c.A)("monitoring"),{query:i}=(0,r.useRouter)(),u=i.slug,g=Number(i.id),p=(0,l.useSession)(),{toast:b}=e0.dj(),v=(0,e5.jE)(),{generateQueryKey:f}=(0,L._R)(),[j,w]=(0,m.useState)(""),[N,k]=(0,m.useState)(null),{summary:_,isComplete:C,isProcessing:I}=o(N);(0,m.useEffect)(()=>{C&&N&&t5(v,f,u,g)},[C,N,v,f,u,g]);let A=()=>{N&&t5(v,f,u,g),null==t||t()},[z,R]=(0,m.useState)(null),[D,M]=(0,m.useState)(""),[T,E]=(0,m.useState)(""),[F,O]=(0,m.useState)(void 0),B=(0,m.useMemo)(()=>!j||!D||!T||!t2(a).safeParse({latitude:T.replace(",","."),longitude:D.replace(",",".")}).success,[j,D,T,a]),{data:P=[],isLoading:U}=(0,n._l1)(u,g,{group_by_device_type:!1},{},{query:{select:e=>Array.isArray(e)?e:[],retry:!1}}),{mutate:H,isLoading:q}=(0,n.Tbh)({mutation:{onError:()=>{b({variant:"error",description:a("monitoring-observations:upload.gdrive.error")})},onSuccess:e=>{(null==e?void 0:e.batch_id)?(b({variant:"success",description:a("monitoring-observations:upload.gdrive.success")}),k(e.batch_id),S(e.batch_id,j),v.invalidateQueries((0,n.jes)(u,g,{limit:20}))):((null==e?void 0:e.skipped_files)&&e.skipped_files>0?b({variant:"warning",description:a("monitoring-observations:upload.gdrive.allSkipped",{count:e.skipped_files})}):b({variant:"warning",description:a("monitoring-observations:upload.gdrive.nothingToUpload")}),null==t||t())}}});if(N){var V,W,$,Q,G,K;return(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"sm:min-w-[500px]",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-md font-bold text-white",children:a("monitoring-observations:upload.gdrive.title")}),(0,s.jsx)(x.DialogClose,{onClick:A,children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]}),(0,s.jsx)(x.DialogDescription,{children:a("monitoring-observations:upload.progress.batchDescription")})]}),(0,s.jsx)(t9,{mode:"batch",status:null!=(V=null==_?void 0:_.status)?V:"pending",progressPercent:null!=(W=null==_?void 0:_.progress_percent)?W:0,totalFiles:null!=($=null==_?void 0:_.total_files)?$:0,successCount:null!=(Q=null==_?void 0:_.success_count)?Q:0,failedCount:null!=(G=null==_?void 0:_.failed_count)?G:0,pendingCount:null!=(K=null==_?void 0:_.pending_count)?K:0,isProcessing:I,isComplete:C}),(0,s.jsx)(x.DialogFooter,{children:(0,s.jsx)(h.$,{variant:"monitoring-600(base)",className:"w-full",onClick:A,children:a("monitoring-observations:upload.close")})})]})}return(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"sm:min-w-[500px]",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-md font-bold text-white",children:a("monitoring-observations:upload.gdrive.title")}),(0,s.jsx)(x.DialogClose,{children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]}),(0,s.jsx)(x.DialogDescription,{children:a("monitoring-observations:upload.gdrive.subtitle")})]}),(0,s.jsxs)("div",{className:"flex max-w-md flex-col gap-5",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("label",{className:"text-sm text-white",children:[a("monitoring-observations:upload.gdrive.id"),(0,s.jsx)("b",{children:" *"})]}),(0,s.jsx)(e6.bL,{placeholder:"https://drive.google.com/drive/folders/3DEFg-HIJKLmnOPQR",variant:"dark-mode",className:"rounded-md border border-light-mode-black-400 text-white",withoutParent:!0,value:j,onChange:e=>w((e=>{let t=e.trim(),a=t.match(/\/folders\/([a-zA-Z0-9_-]+)/);return a?a[1]:t})(e.target.value))}),(0,s.jsxs)("div",{className:"flex items-start gap-2 text-sm text-dark-mode-blue-1000",children:[(0,s.jsx)(d.In,{icon:"material-symbols:info-outline-rounded",width:16,height:16,className:"shrink-0"}),(0,s.jsx)("p",{children:(0,s.jsx)(tf.A,{text:a("monitoring-observations:upload.gdrive.infoAboutId"),components:{br:(0,s.jsx)("br",{}),bold:(0,s.jsx)("b",{}),yellow:(0,s.jsx)("span",{className:"text-dark-mode-monitoring-600(base)"})}})})]}),(0,s.jsxs)("div",{className:"flex items-start gap-2 text-sm text-dark-mode-blue-1000",children:[(0,s.jsx)(d.In,{icon:"material-symbols:warning-outline",width:16,height:16,className:"shrink-0 text-dark-mode-monitoring-600(base)"}),(0,s.jsx)("p",{children:(0,s.jsx)(tf.A,{text:a("monitoring-observations:upload.gdrive.infoAboutFiles"),components:{br:(0,s.jsx)("br",{}),bold:(0,s.jsx)("b",{}),yellow:(0,s.jsx)("span",{className:"text-dark-mode-monitoring-600(base)"})}})})]})]}),(0,s.jsx)("span",{className:"mt-2 text-white",children:a("monitoring-observations:upload.single.details.title")}),(0,s.jsxs)("div",{className:"grid grid-cols-1 gap-5 gap-x-9 sm:grid-cols-2",children:[(0,s.jsx)(aa,{devices:P,isLoading:U,value:z,onChange:R,triggerClassName:"col-span-full"}),(0,s.jsx)(at,{type:"latitude",label:a("monitoring-observations:upload.single.details.latitude.label"),placeholder:a("monitoring-observations:upload.single.details.latitude.placeholder"),value:T?T.toString():"",onCh
1ange:e=>E(e.target.value)}),(0,s.jsx)(at,{type:"longitude",label:a("monitoring-observations:upload.single.details.longitude.label"),placeholder:a("monitoring-observations:upload.single.details.longitude.placeholder"),value:D?D.toString():"",onChange:e=>M(e.target.value)}),(0,s.jsxs)(ez.bL,{children:[(0,s.jsxs)(ez.Wv,{className:"col-span-full flex h-fit rounded-xl border-none bg-transparent px-2 py-1 ring-2 ring-dark-mode-blue-600(base) hover:opacity-70",disabled:q,children:[(0,s.jsxs)("div",{className:"flex flex-col text-left",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-primary-blue-300",children:a("monitoring-observations:upload.gdrive.overrideDate")}),(0,s.jsx)("span",{className:"text-base",children:F?(0,y.default)(F,"yyyy-MM-dd"):a("monitoring-observations:upload.gdrive.overrideDatePlaceholder")})]}),(0,s.jsxs)("div",{className:"ml-auto flex shrink-0 items-center gap-1 self-center",children:[F&&(0,s.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),O(void 0)},className:"flex h-6 w-6 items-center justify-center rounded-md text-dark-mode-blue-1000 hover:bg-dark-mode-blue-200 hover:text-white","aria-label":a("monitoring-observations:upload.gdrive.clearOverrideDate"),title:a("monitoring-observations:upload.gdrive.clearOverrideDate"),children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:14,height:14})}),(0,s.jsx)(d.In,{icon:"radix-icons:calendar",width:20,height:20,className:"text-white"})]})]}),(0,s.jsx)(ez.hl,{align:"start",className:"z-[12345678] w-fit overflow-hidden bg-dark-mode-blue-300 !p-2 shadow shadow-dark-mode-blue-1100",children:(0,s.jsx)(tK.h,{_selectedDate:F,_setSelectedDate:O,className:"!m-0 bg-dark-mode-blue-300",disabledDates:{after:new Date}})})]})]}),(0,s.jsxs)(h.$,{variant:"monitoring-600(base)",disabled:q||B,className:"mt-5",onClick:()=>{var e;H({userSlug:u,siteId:g,params:{gdrive_folder_id:j,longitude:Number(D.replace(",",".")),latitude:Number(T.replace(",",".")),device_id:null==z?void 0:z.id,override_datetime:F?(0,y.default)(F,"yyyy-MM-dd 12:00:00"):void 0},headers:(null==(e=p.data)?void 0:e.accessToken)?{authorization:"Bearer ".concat(p.data.accessToken)}:void 0})},children:[q&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:20,height:20,className:"mr-2 text-white"}),a("monitoring-observations:upload.submit")]})]})]})};var ai=a(69071);let an=".csv",al="text/csv",ar=e=>{let{closeDialog:t}=e,{t:a}=(0,c.A)("monitoring"),{query:i,locale:u="it"}=(0,r.useRouter)(),g=i.slug,p=Number(i.id),b=(0,l.useSession)(),{toast:v}=e0.dj(),{files:f,setFiles:j,removeFileByIndex:y}=(0,e4.M)({accept:al,maxFiles:1,maxSize:10,onError:e=>{v({variant:"error",description:a("common.files.errors.".concat(e),{size:10,formats:an,files:5})})}}),w=(0,e5.jE)(),{generateQueryKey:N}=(0,L._R)(),[k,_]=(0,m.useState)([]),[C,I]=(0,m.useState)(null),[A,z]=(0,m.useState)(null),{data:R=[],isLoading:D}=(0,n._l1)(g,p,{group_by_device_type:!1},{},{query:{select:e=>Array.isArray(e)?e:[],retry:!1}}),{summary:M,isComplete:T,isProcessing:E}=o(C);(0,m.useEffect)(()=>{T&&C&&t5(w,N,g,p)},[T,C,w,N,g,p]);let F=()=>{C&&t5(w,N,g,p),null==t||t()},{mutate:O,isLoading:B}=(0,n.WpC)({mutation:{onSettled:(e,t)=>{var s,i,l;let r=null!=(s=null==e?void 0:e.validation_errors)?s:[];if(t){v({variant:"error",description:a("monitoring-observations:upload.multiple.error")});try{if(t instanceof Error){let e=JSON.parse(t.message);(null==e?void 0:e.detail)&&r.push(e.detail)}}catch(e){}}if(r.length>0)return void _(r);!t&&(null==e?void 0:e.batch_id)&&(v({variant:"success",description:a("monitoring-observations:upload.multiple.success")}),I(e.batch_id),S(e.batch_id,null!=(l=null==(i=f[0])?void 0:i.name)?l:"CSV"),w.invalidateQueries((0,n.jes)(g,p,{limit:20})),j([]))}}});if(C){var P,U,H,q,V,W;return(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"sm:min-w-[500px]",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-md font-bold text-white",children:a("monitoring-observations:upload.multiple.title")}),(0,s.jsx)(x.DialogClose,{onClick:F,children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]}),(0,s.jsx)(x.DialogDescription,{children:a("monitoring-observations:upload.progress.batchDescription")})]}),(0,s.jsx)(t9,{mode:"batch",status:null!=(P=null==M?void 0:M.status)?P:"pending",progressPercent:null!=(U=null==M?void 0:M.progress_percent)?U:0,totalFiles:null!=(H=null==M?void 0:M.total_files)?H:0,successCount:null!=(q=null==M?void 0:M.success_count)?q:0,failedCount:null!=(V=null==M?void 0:M.failed_count)?V:0,pendingCount:null!=(W=null==M?void 0:M.pending_count)?W:0,isProcessing:E,isComplete:T}),(0,s.jsx)(x.DialogFooter,{children:(0,s.jsx)(h.$,{variant:"monitoring-600(base)",className:"w-full",onClick:F,children:a("monitoring-observations:upload.close")})})]})}return(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"sm:min-w-[500px]",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-md font-bold text-white",children:a("monitoring-observations:upload.multiple.title")}),(0,s.jsx)(x.DialogClose,{children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20,color:"white"})})]}),(0,s.jsx)(x.DialogDescription,{children:a("monitoring-observations:upload.multiple.subtitle")})]}),(0,s.jsx)(()=>{let e=a("monitoring-observations:upload.multiple.csvStructure.alerts",{},{returnObjects:!0,default:[]});return(0,s.jsxs)("div",{className:"mb-5 flex flex-col gap-2",children:[(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsx)("p",{className:"text-sm font-semibold",children:a("monitoring-observations:upload.multiple.csvStructure.title")}),(0,s.jsxs)(ti(),{href:"/templates/observations_upload.csv",rel:"noopener noreferrer",target:"_blank",download:!0,className:"ml-auto flex items-center gap-1 text-xs hover:opacity-60",children:[(0,s.jsx)(d.In,{icon:"material-symbols:download",width:20,height:20}),a("monitoring-observations:upload.multiple.csvStructure.download")]})]}),(0,s.jsxs)(ai.bL,{className:"mt-2 rounded-md border border-light-mode-black-400 max-xl:max-w-[90vw]",children:[(0,s.jsx)("thead",{children:(0,s.jsx)("tr",{className:"border-b border-light-mode-black-300 [&>th:first-child]:static",children:["name","taxon_id","latitude","longitude","user_email","acquisition_date","link","n_individuals"].map((e,t)=>(0,s.jsx)("th",{className:"border-none bg-transparent px-4 text-xs font-semibold normal-case",children:e},t))})}),(0,s.jsx)(ai.nB,{className:"[&>tr>td]:!p-4 [&_tr:last-child]:border-0",children:["Acer rubrum, 12345, 45.1, 12.1, [email protected], 2025-04-15, https://example.com/media1.jpg,","Geranium carolinianum, , 45.1, 12.1, [email protected], 2025-04-15, https://example.com/media2.wav,","Gryllus campestris, , 45.1, 12.1, , 2025-04-15, , 5",", 12345 , 45.1, 12.1, , 2025-04-15, ,",", , 45.1, 12.1, , 2025-04-15, https://example.com/media1.jpg,"].map((e,t)=>(0,s.jsx)("tr",{className:"border-b border-light-mode-black-300",children:e.split(",").map((e,t)=>(0,s.jsx)("td",{className:"border-none bg-transparent text-xs",children:e},t))},t))})]}),e.length>0&&(0,s.jsx)("ul",{className:"flex flex-col gap-1 text-light-mode-black-300",children:e.map((e,t)=>(0,s.jsxs)("li",{className:"flex items-center gap-2",children:[(0,s.jsx)(d.In,{icon:"radix-icons:info-circled",width:20,height:20}),(0,s.jsx)("span",{className:"text-sm",children:e})]},t))})]})},{}),(0,s.jsx)(aa,{devices:R,isLoading:D,value:A,onChange:z}),(0,s.jsxs)(e3.u,{onDrop:e=>{e.dataTransfer.files.length&&j(Array.from(e.dataTransfer.files))},children:[(0,s.jsx)(e3.b,{accept:al,onChange:e=>{e.target.files&&j(Array.from(e.target.files))},currentNumberOfFiles:f.length,maxNumberOfFiles:1}),(0,s.jsx)(d.In,{icon:"ic:outline-cloud-upload",width:36,height:24,className:"text-dark-mode-monitoring-600(base)"}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"font-medium text-white",children:a("common.files.label")}),(0,s.jsx)("p",{className:"text-center text-xs text-light-mode-black-300",children:a("common.files.maxFileSize",{size:10})}),(0,s.jsx)("p",{className:"text-center text-xs text-light-mode-black-300",children:a("common.files.acceptedFormats",{formats:an})})]})]}),f.length>0&&(0,s.jsxs)("div",{className:"mt-2 flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-white",children:a("common.files.selected")}),(0,s.jsx)("ul",{className:"flex flex-col gap-1 text-light-mode-black-300",children:f.map((e,t)=>(0,s.jsxs)("li",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{children:e.name}),(0,s.jsx)(h.$,{variant:"unstyled",onClick:()=>y(t),children:(0,s.jsx)(d.In,{icon:"carbon:close",width:20,height:20,className:"text-white"})})]},e.name))})]}),B&&(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:40,height:40,className:"mx-auto text-white"}),k.length>0&&(0,s.jsxs)("div",{className:"mt-2 flex flex-col gap-2",children:[(0,s.jsx)("span",{className:"text-red-500",children:a("monitoring-observations:upload.multiple.errors")}),(0,s.jsx)("ul",{className:"max-h-64 overflow-y-auto text-red-400 scrollbar-hide",children:k.map((e,t)=>(0,s.jsxs)("li",{className:"flex items-center gap-2",children:[(0,s.jsx)(d.In,{icon:"carbon:warning-alt",width:20,height:20}),(0,s.jsx)("span",{children:e})]},t))})]}),(0,s.jsx)(x.DialogFooter,{children:(0,s.jsx)(h.$,{variant:"monitoring-600(base)",disabled:B||!f.length,className:"w-full",onClick:()=>{var e;f.length&&(null==b||null==(e=b.data)?void 0:e.accessToken)&&(_([]),O({userSlug:g,siteId:p,data:{file:f[0]},params:(null==A?void 0:A.id)?{device_id:A.id}:void 0,headers:{"accept-language":u,authorization:"Bearer ".concat(b.data.accessToken)}}))},children:a("monitoring-observations:upload.submit")})})]})};var ao=a(81139);let ad=e=>{var t;let{open:a,onOpenChange:i}=e,{t:o}=(0,c.A)("monitoring"),{query:m,locale:u="it"}=(0,r.useRouter)(),h=m.slug,g=Number(m.id),p=(0,l.useSession)(),b=(null==(t=p.data)?void 0:t.accessToken)?{authorization:"Bearer ".concat(p.data.accessToken),"accept-language":u}:void 0,{data:v=[],isLoading:y}=(0,n.t6g)(h,g,{limit:20}
1,b,{query:{enabled:a&&!!h&&!!g}});return(0,s.jsx)(x.Root,{open:a,onOpenChange:i,children:(0,s.jsxs)(x.DialogContent,{className:"max-w-md bg-dark-mode-blue-1000 p-0",children:[(0,s.jsxs)(x.DialogHeader,{className:"border-dark-mode-blue-600 flex flex-row items-start justify-between border-b p-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)(x.DialogTitle,{className:"text-base font-bold text-white",children:o("monitoring-observations:upload.history.title")}),(0,s.jsx)("p",{className:"text-sm text-dark-mode-blue-400",children:o("monitoring-observations:upload.history.description")})]}),(0,s.jsx)(x.DialogClose,{className:"shrink-0 text-dark-mode-blue-400 hover:text-white",children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:20,height:20})})]}),(0,s.jsx)("div",{className:"custom-scrollbar-dark-mode-blue-300 max-h-[60vh] overflow-y-auto p-4",children:y?(0,s.jsx)("div",{className:"flex flex-col gap-3",children:Array.from({length:5}).map((e,t)=>(0,s.jsx)(Y.A,{height:60,className:"rounded-md"},t))}):0===v.length?(0,s.jsx)("div",{className:"py-8 text-center text-dark-mode-blue-400",children:o("monitoring-observations:upload.history.emptyBatches")}):(0,s.jsx)("ul",{className:"flex flex-col gap-3",children:v.map(e=>(0,s.jsxs)("li",{className:"bg-dark-mode-blue-600 flex items-start gap-3 rounded-md p-3",children:[(e=>{switch(e){case"completed":case"success":return(0,s.jsx)(d.In,{icon:"material-symbols:check-circle",width:16,height:16,className:"text-green-400"});case"failed":return(0,s.jsx)(d.In,{icon:"material-symbols:error",width:16,height:16,className:"text-red-400"});case"partial":return(0,s.jsx)(d.In,{icon:"material-symbols:warning",width:16,height:16,className:"text-yellow-400"});default:return(0,s.jsx)(d.In,{icon:"eos-icons:loading",width:16,height:16,className:"text-primary-blue-300"})}})(e.status),(0,s.jsxs)("div",{className:"flex flex-1 flex-col gap-1",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-white",children:(e=>{switch(e){case"single":return o("monitoring-observations:upload.history.typeSingle");case"csv":return o("monitoring-observations:upload.history.typeCsv");case"gdrive":return o("monitoring-observations:upload.history.typeGdrive");default:return e}})(e.upload_type)}),(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-400",children:function(e,t){let a=(0,f.Yx)(e);return a?(0,ao.A)(a,{addSuffix:!0,locale:j.x8[t]}):null}(e.started_at,u)})]}),(0,s.jsxs)("div",{className:"flex gap-2 text-xs",children:[(0,s.jsxs)("span",{className:"text-green-400",children:[e.success_count," ",o("monitoring-observations:upload.history.filesCompleted")]}),e.failed_count>0&&(0,s.jsxs)("span",{className:"text-red-400",children:[e.failed_count," ",o("monitoring-observations:upload.history.filesFailed")]})]})]})]},e.batch_id))})})]})})},ac=()=>{let{t:e}=(0,c.A)("monitoring"),[t,a]=(0,m.useState)(!1),[i,n]=(0,m.useState)("single"),[l,r]=(0,m.useState)(!1),{canEditSite:o}=(0,Z.A)();return o?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(x.Root,{open:t,onOpenChange:a,children:(0,s.jsx)("div",{className:"flex items-center gap-2",children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{className:"flex w-fit items-center gap-2 text-sm font-semibold hover:!opacity-60 lg:text-base",asChild:!0,children:(0,s.jsxs)(h.$,{id:"census-observations-upload-button","data-description":"Open dropdown to upload single or multiple species observations",variant:"unstyled",className:"min-w-max gap-1 !text-sm font-semibold !text-white hover:!opacity-60",children:[(0,s.jsx)(d.In,{icon:"material-symbols:upload-rounded",width:20,height:20}),e("monitoring-observations:upload.title")]})}),(0,s.jsxs)(e7.SQ,{variant:"dark-mode-blue-300",side:"bottom",className:"z-[12345678] w-fit p-1.5 shadow-none",children:[(0,s.jsx)(x.DialogTrigger,{asChild:!0,children:(0,s.jsx)(e7._2,{variant:"dark-mode-blue-300",className:"cursor-pointer rounded-md",onClick:()=>n("single"),children:e("monitoring-observations:upload.single.title")})}),(0,s.jsx)(x.DialogTrigger,{asChild:!0,children:(0,s.jsx)(e7._2,{variant:"dark-mode-blue-300",className:"cursor-pointer rounded-md",onClick:()=>n("multiple"),children:e("monitoring-observations:upload.multiple.title")})}),(0,s.jsx)(x.DialogTrigger,{asChild:!0,children:(0,s.jsxs)(e7._2,{variant:"dark-mode-blue-300",className:"cursor-pointer rounded-md",onClick:()=>n("gdrive"),children:[(0,s.jsx)(d.In,{icon:"logos:google-drive",width:16,height:16,className:"mr-1"}),e("monitoring-observations:upload.gdrive.title")]})}),(0,s.jsx)("div",{className:"my-1 border-t border-dark-mode-blue-400"}),(0,s.jsxs)(e7._2,{variant:"dark-mode-blue-300",className:"cursor-pointer rounded-md",onClick:()=>r(!0),children:[(0,s.jsx)(d.In,{icon:"material-symbols:history",width:16,height:16,className:"mr-1"}),e("monitoring-observations:upload.history.title")]})]}),(()=>{switch(i){case"single":return(0,s.jsx)(ae,{closeDialog:()=>a(!1)},t.toString());case"multiple":return(0,s.jsx)(ar,{closeDialog:()=>a(!1)},t.toString());case"gdrive":return(0,s.jsx)(as,{closeDialog:()=>a(!1)},t.toString())}})()]})})}),(0,s.jsx)(ad,{open:l,onOpenChange:r})]}):null};var am=a(90097),au=a(23622),ax=a(86921),ah=a(45717),ag=a(3491);let ap=e=>{var t;let{polygon:a,isSelected:i,onSelect:o}=e,{t:u}=(0,c.A)("monitoring"),{query:x}=(0,r.useRouter)(),g=x.slug,p=Number(x.id),{canEditSite:b,isDemoAndOwner:v}=(0,Z.A)(),f=(0,l.useSession)(),j=(0,e5.jE)(),{toast:y}=e0.dj(),[w,N]=(0,m.useState)(!1),[k,_]=(0,m.useState)(null!=(t=a.name)?t:""),{mutateAsync:C,isLoading:S}=(0,n.CpY)(),I=async()=>{var e,t;if(!k.trim()||k===a.name){N(!1),_(null!=(t=a.name)?t:"");return}await C({userSlug:g,siteId:p,plantationsPolygonsId:a.id,data:{name:k.trim()},headers:{authorization:"Bearer ".concat(null==f||null==(e=f.data)?void 0:e.accessToken)}},{onSuccess:()=>{j.invalidateQueries((0,n.ks)(g,p)),y({variant:"success",description:u("polygonVersionsList.editPolygonSuccess")}),N(!1)},onError:()=>{y({variant:"error",description:u("polygonVersionsList.editPolygonError")})}})},A=()=>{var e;N(!1),_(null!=(e=a.name)?e:"")};return(0,s.jsx)(tY.q7,{value:a.id.toString(),onSelect:()=>{w||o(a)},variant:"blue-600(base)",selected:i,className:"my-0.5 rounded-lg",children:w?(0,s.jsxs)("div",{className:"flex w-full flex-col gap-1.5",onClick:e=>e.stopPropagation(),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),I()),"Escape"===e.key&&(e.preventDefault(),A())},children:[(0,s.jsxs)("span",{className:"text-sm font-semibold text-white",children:["V",a.version]}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(e6.bL,{value:k,type:"text",variant:"outline-blue-1100",onChange:e=>_(e.target.value),disabled:S,className:"!h-7 !text-xs",autoFocus:!0}),S?(0,s.jsx)(d.In,{icon:"eos-icons:three-dots-loading",width:20,height:20,className:"text-yellow-400"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.$,{variant:"text-only-monitoring-600(base)",onClick:A,disabled:S,className:"h-fit min-h-[0px] !p-0.5 !text-xs",children:u("common:cancel")}),(0,s.jsx)(h.$,{variant:"monitoring-600(base)",onClick:I,disabled:!k.trim()||k===a.name||S,className:"h-fit min-h-[0px] !p-0.5 !text-xs",children:u("common:save")})]})]})]}):(0,s.jsxs)("div",{className:"flex w-full items-center justify-between gap-3",children:[(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsxs)("span",{className:"flex items-center gap-1.5 text-base font-normal text-white",children:[(e=>
1e.name?e.name:"V".concat(e.version))(a),a.starred&&(0,s.jsx)("span",{role:"img",title:u("toolbar.defaultPolygon"),"aria-label":u("toolbar.defaultPolygon"),className:"flex shrink-0",children:(0,s.jsx)(d.In,{icon:"material-symbols:star-rounded",className:"h-4 w-4 text-amber-400"})})]}),a.ca_label&&(0,s.jsx)("span",{className:"text-primary-blue-400 text-xs",children:a.ca_label})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(b||v)&&(0,s.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),N(!0)},className:"shrink-0 rounded p-0.5 text-dark-mode-blue-900 transition-colors hover:text-white",title:u("toolbar.editName"),children:(0,s.jsx)(d.In,{icon:"material-symbols:edit-rounded",width:14,height:14})}),i&&(0,s.jsx)(d.In,{icon:"mdi:check",className:"text-emerald-400",width:18,height:18})]})]})},"".concat(a.id,"-").concat(a.version))};var ab=a(20534),av=a(1215),af=a(5769),aj=a(29596);let ay="".concat(aj.hU,"\n").concat("\n/* Filters list */\n.filters-list {\n list-style: none; padding: 0; margin: 12pt 0;\n}\n.filters-list li {\n padding: 8pt 12pt; border-bottom: 0.5pt solid var(--color-border-light);\n display: flex; gap: 10pt; font-size: 9pt;\n}\n.filters-list li strong {\n min-width: 140pt; flex-shrink: 0; color: var(--color-text-secondary);\n font-weight: 700; text-transform: uppercase; font-size: 7pt;\n letter-spacing: 0.08em; align-self: center;\n}\n.filters-list li span { color: var(--color-text-dark); font-weight: 500; }\n\n/* KPI grid overrides for census (3 columns) */\n.kpi-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10pt; margin-bottom: 16pt; }\n.kpi-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10pt; margin-bottom: 16pt; }\n\n/* Data tables (census-specific styling) */\n.data-table {\n width: 100%; border-collapse: collapse; margin: 16pt 0;\n font-size: 9pt; border-radius: 8pt; overflow: hidden;\n}\n.data-table caption {\n background: linear-gradient(135deg, var(--color-primary-darkest) 0%, var(--color-primary-dark) 100%);\n color: var(--color-white); padding: 10pt 16pt;\n font-weight: 700; font-size: 9pt; text-align: center;\n text-transform: uppercase; letter-spacing: 0.06em;\n}\n.data-table th {\n background: var(--color-primary-dark);\n color: var(--color-white); padding: 8pt 12pt;\n font-weight: 600; text-align: center; font-size: 8pt;\n text-transform: uppercase; letter-spacing: 0.06em;\n border: 0.5pt solid rgba(32,113,152,0.3);\n}\n.data-table td {\n padding: 8pt 12pt; text-align: center;\n border: 0.5pt solid var(--color-border-light);\n font-size: 9pt; color: var(--color-text-dark);\n}\n.data-table tr:nth-child(even) td { background: var(--color-bg-subtle); }\n.data-table td:first-child { text-align: left; font-weight: 600; }\n\n/* Species grid */\n.species-grid {\n display: grid; grid-template-columns: repeat(3, 1fr);\n gap: 12pt; margin: 16pt 0;\n}\n.species-card {\n border: 0.5pt solid var(--color-border-light);\n border-radius: 8pt; overflow: hidden; text-align: center;\n background: var(--color-white);\n box-shadow: 0 1px 4px rgba(0,0,0,0.04);\n}\n.species-card img {\n width: 100%; height: 120pt; object-fit: cover;\n}\n.species-card .species-img-placeholder {\n width: 100%; height: 120pt; background: var(--color-bg-subtle);\n display: flex; align-items: center; justify-content: center;\n color: var(--color-primary-light); font-style: italic; font-size: 8pt;\n}\n.species-card .species-info { padding: 8pt 10pt; }\n.species-card .species-name {\n font-size: 9pt; font-weight: 700; font-style: italic;\n color: var(--color-text-dark);\n}\n.species-card .species-count {\n font-size: 7.5pt; color: var(--color-text-secondary);\n margin-top: 2pt;\n}\n\n/* Content block */\n.content-block { margin-bottom: 16pt; }\n.content-block p { margin-bottom: 10pt; text-align: justify; font-size: 9pt; color: var(--color-text-secondary); line-height: 1.6; }\n\n/* Screen media overrides for content pages */\n@media screen {\n .content-page {\n background: white; max-width: 210mm; min-height: 200mm;\n margin: 24px auto; padding: 15mm 20mm; border-radius: 4px;\n box-shadow: 0 2px 8px rgba(0,0,0,0.08), 0 8px 32px rgba(0,0,0,0.12);\n position: relative;\n }\n}\n");function aw(e){return"census-en"===e}function aN(e){return(0,aj.ZD)(e&&""!==e.trim()?e:"--")}function ak(e,t){let a=aw(t),s=(0,aj.ZD)(e.siteName),i=aw(t)?"End of Report":"Fine del Report",n='\n <p data-editable="report-footer-note" data-editable-label="'.concat(aw(t)?"Footer Note":"Nota a pi\xe8 di pagina",'">\n ').concat(aw(t)?"Generated by XNatura â 3Bee S.r.l.":"Generato da XNatura â 3Bee S.r.l.","\n </p>"),l="".concat(function(e,t){let a=aw(t)?"Census Report":"Report Censimenti",s=aw(t)?"Species Observation Census":"Censimento Osservazioni Specie",i=aw(t)?"CENSUS REPORT":"REPORT CENSIMENTI",n=(0,aj.kh)(e.date||new Date().toISOString());return'\n <div class="cover-page" data-removable data-removable-label="'.concat(aw(t)?"Cover":"Copertina",'">\n <div class="cover-glow"></div>\n <div class="cover-watermark"><img src="').concat(aj.if,'" alt="" /></div>\n <div class="cover-header">\n <div class="cover-logo"><img src="').concat(aj.f2,'" alt="XN" /></div>\n <div>\n <div class="cover-badge"><span class="cover-badge-dot"></span> ').concat((0,aj.UQ)(i),'</div>\n <div class="cover-date" style="margin-top:4pt;text-align:right;">').concat(n,'</div>\n </div>\n </div>\n <div class="cover-content">\n <h1 data-editable="cover-title" data-editable-label="').concat(aw(t)?"Report Title":"Titolo Report",'">').concat((0,aj.UQ)(a),'</h1>\n <p class="cover-subtitle" data-editable="cover-subtitle" data-editable-label="').concat(aw(t)?"Subtitle":"Sottotitolo",'">').concat((0,aj.UQ)(s),'</p>\n <div class="cover-divider"></div>\n <p class="cover-site-address" data-editable="cover-site-name" data-editable-label="').concat(aw(t)?"Site Name":"Nome Sito",'">').concat(aN(e.siteName),'</p>\n <p class="cover-coordinates">').concat(aN(e.latitude),", ").concat(aN(e.longitude),'</p>\n <div class="cover-meta">\n <div class="cover-meta-item">
1\n <span class="meta-label">').concat(aw(t)?"OWNER":"PROPRIETARIO",'</span>\n <span class="meta-value" data-editable="cover-owner" data-editable-label="').concat(aw(t)?"Owner":"Proprietario",'" style="font-size:10pt;">').concat(aN(e.customerName),'</span>\n </div>\n <div class="cover-meta-item">\n <span class="meta-label">').concat(aw(t)?"AREA":"ESTENSIONE",'</span>\n <span class="meta-value" style="font-size:10pt;">').concat(aN(e.siteHectares),' ha</span>\n </div>\n <div class="cover-meta-item">\n <span class="meta-label">').concat(aw(t)?"ECOSYSTEM":"ECOSISTEMA",'</span>\n <span class="meta-value" data-editable="cover-ecosystem" data-editable-label="').concat(aw(t)?"Ecosystem":"Ecosistema",'" style="font-size:10pt;">').concat(aN(e.ecosystemType),'</span>\n </div>\n <div class="cover-meta-item">\n <span class="meta-label">').concat(aw(t)?"LOCATION":"POSIZIONE",'</span>\n <span class="meta-value" data-editable="cover-location" data-editable-label="').concat(aw(t)?"Location":"Posizione",'" style="font-size:10pt;">').concat(aN(e.siteLocation),'</span>\n </div>\n </div>\n </div>\n <div class="cover-footer">').concat(aw(t)?"Generated by XNatura â 3Bee S.r.l.":"Generato da XNatura â 3Bee S.r.l.","</div>\n </div>")}(e,t),"\n").concat(function(e,t){let a=aw(t)?"Table of Contents":"Indice",s=aw(t)?"Census Report":"Report Censimenti",i=[{href:"#filters",label:aw(t)?"Active Filters":"Filtri Attivi"},{href:"#overview",label:aw(t)?"Transects Overview":"Panoramica Transetti"},{href:"#transect-stats",label:aw(t)?"Transect Statistics":"Statistiche Transetti"},{href:"#devices",label:aw(t)?"Devices Installed":"Dispositivi Installati"},{href:"#species-list",label:aw(t)?"Species List":"Lista Specie"},{href:"#species-grid",label:aw(t)?"Species Gallery":"Galleria Specie"}];return(0,aj.aM)(aj.f2,a,s,i,aw(t)?"Table of Contents":"Indice")}(0,t),"\n").concat(function(e,t){let a=aw(t)?"Active Filters":"Filtri Attivi",s=aw(t)?"Census Report":"Report Censimenti";if(0===e.activeFilters.length)return'\n <section id="filters" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <div class="content-block">\n <p data-editable="filters-none" data-editable-label="').concat(aw(t)?"No Filters":"Nessun Filtro",'">').concat(aw(t)?"No filters are currently applied.":"Nessun filtro \xe8 attualmente applicato.","</p>\n </div>\n </section>");let i=e.activeFilters.map(e=>"<li><strong>".concat((0,aj.ZD)(e.label),":</strong> <span>").concat((0,aj.ZD)(e.value),"</span></li>")).join("\n");return'\n <section id="filters" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <ul class="filters-list">\n ').concat(i,"\n </ul>\n </section>")}(e,t),"\n").concat(function(e,t){let a=aw(t)?"Transects Overview":"Panoramica Transetti",s=aw(t)?"Census Report":"Report Censimenti";return'\n <section id="overview" class="content-page page-break-before" data-block="info" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <div class="kpi-grid-3">\n <div class="kpi-card">\n <div class="kpi-card-value" data-editable="overview-transects" data-editable-label="').concat(aw(t)?"Transect Count":"Numero Transetti",'">').concat(aN(e.transectCount),'</div>\n <div class="kpi-card-label">').concat(aw(t)?"Transects":"Transetti",'</div>\n </div>\n <div class="kpi-card">\n <div class="kpi-card-value" data-editable="overview-species" data-editable-label="').concat(aw(t)?"Total Species":"Specie Totali",'">').concat(aN(e.totalSpecies),'</div>\n <div class="kpi-card-label">').concat(aw(t)?"Total Species":"Specie Totali",'</div>\n </div>\n <div class="kpi-card">\n <div class="kpi-card-value" data-editable="overview-indiv
1iduals" data-editable-label="').concat(aw(t)?"Total Individuals":"Individui Totali",'">').concat(aN(e.totalIndividuals),'</div>\n <div class="kpi-card-label">').concat(aw(t)?"Total Individuals":"Individui Totali",'</div>\n </div>\n </div>\n <div class="kpi-grid-2">\n <div class="kpi-card">\n <div class="kpi-card-value" data-editable="overview-shannon" data-editable-label="').concat(aw(t)?"Shannon Index":"Indice di Shannon",'">').concat(aN(e.shannonIndex),'</div>\n <div class="kpi-card-label">').concat(aw(t)?"Shannon Index":"Indice di Shannon",'</div>\n </div>\n <div class="kpi-card">\n <div class="kpi-card-value" data-editable="overview-hourly" data-editable-label="').concat(aw(t)?"Hourly IDs":"ID Orari",'">').concat(aN(e.identificationsPerHour),'</div>\n <div class="kpi-card-label">').concat(aw(t)?"Identifications / Hour":"Identificazioni / Ora","</div>\n </div>\n </div>\n </section>")}(e,t),"\n").concat(function(e,t){let a=aw(t)?"Transect Statistics":"Statistiche Transetti",s=aw(t)?"Census Report":"Report Censimenti";if(0===e.transectSummaryRows.length)return'\n <section id="transect-stats" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <div class="content-block">\n <p>').concat(aw(t)?"No transect data available.":"Nessun dato transetto disponibile.","</p>\n </div>\n </section>");let i="\n <tr>\n <th>".concat(aw(t)?"Transect":"Transetto","</th>\n <th>").concat(aw(t)?"Shannon Index":"Indice di Shannon","</th>\n <th>").concat(aw(t)?"Alien Species %":"% Specie Aliene","</th>\n <th>").concat(aw(t)?"Total Species":"Specie Totali","</th>\n <th>").concat(aw(t)?"Top 5 Species":"Top 5 Specie","</th>\n </tr>"),n=e.transectSummaryRows.map((e,a)=>'\n <tr>\n <td data-editable="transect-name-'.concat(a,'" data-editable-label="').concat(aw(t)?"Transect Name":"Nome Transetto"," ").concat(a+1,'">').concat(aN(e.name),'</td>\n <td data-editable="transect-shannon-').concat(a,'" data-editable-label="Shannon ').concat(a+1,'">').concat(aN(e.shannonIndex),'</td>\n <td data-editable="transect-alien-').concat(a,'" data-editable-label="').concat(aw(t)?"Alien %":"% Aliene"," ").concat(a+1,'">').concat(aN(e.alienPercentage),'</td>\n <td data-editable="transect-species-').concat(a,'" data-editable-label="').concat(aw(t)?"Species":"Specie"," ").concat(a+1,'">').concat(aN(e.totalSpecies),"</td>\n <td>").concat(e.topSpecies.length>0?e.topSpecies.map(e=>(0,aj.ZD)(e)).join(", "):"--","</td>\n </tr>")).join("\n");return'\n <section id="transect-stats" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <table class="data-table">\n <caption>').concat((0,aj.UQ)(a),"</caption>\n <thead>").concat(i,"</thead>\n <tbody>").concat(n,"</tbody>\n </table>\n </section>")}(e,t),"\n").concat(function(e,t){let a=aw(t)?"Devices Installed":"Dispositivi Installati",s=aw(t)?"Census Report":"Report Censimenti";if(0===e.deviceRows.length)return'\n <section id="devices" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <div class="content-block">\n <p>').concat(aw(t)?"No devices installed at this site.":"Nessun dispositivo installato presso questo sito.","</p>\n </div>\n </section>");let i="\n <tr>\n <th>".concat(aw(t)?"Device Name":"Nome Dispositivo","</th>\n <th>").concat(aw(t)?"Device ID":"ID Dispositivo","</th>\n <th>").concat(aw(t)?"Latitude":"Latitudine","</th>\n <th>").concat(aw(t)?"Longitude":"Longitudine","</th>\n </tr>"),n=e.deviceRows.map((e,a)=>'\n <tr>\n <td data-editable="device-name-'.concat(a,'" data-editable-label="').concat(aw(t)?"Device":"Dispositivo"," ").concat(a+1,'">').concat(aN(e.name),"</td>\n <td>").concat(aN(e.deviceId),"</td>\n <td>").concat(aN(e.latitude),"</td>\n <td>").concat(aN(e.longitude),"</td>\n </tr>")).join("\n");return'\n <section id="devices" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <table class="data-table">\n <caption>').concat((0,aj.UQ)(a),"</caption>\n <thead>").concat(i,"</thead>\n <tbody>").concat(n,"</tbody>\n </table>\n </section>")}(e,t),"\n").concat(function(e,t){let a=aw(t)?"Species List":"Lista Specie",s=aw(t)?"Census Report":"Report Censimenti";if(0===e.speciesRows.length)return'\n <section id="species-list" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <div class="content-block">\n <p>
1').concat(aw(t)?"No species data available.":"Nessun dato sulle specie disponibile.","</p>\n </div>\n </section>");let i="\n <tr>\n <th>".concat(aw(t)?"Scientific Name":"Nome Scientifico","</th>\n <th>").concat(aw(t)?"Common Name":"Nome Comune","</th>\n <th>").concat(aw(t)?"Count":"Conteggio","</th>\n </tr>"),n=e.speciesRows.map(e=>"\n <tr>\n <td><em>".concat((0,aj.ZD)(e.scientificName),"</em></td>\n <td>").concat((0,aj.ZD)(e.commonName||"--"),"</td>\n <td>").concat(e.count,"</td>\n </tr>")).join("\n");return'\n <section id="species-list" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <table class="data-table">\n <caption>').concat((0,aj.UQ)(a),"</caption>\n <thead>").concat(i,"</thead>\n <tbody>").concat(n,"</tbody>\n </table>\n </section>")}(e,t),"\n").concat(function(e,t){let a=aw(t)?"Species Gallery":"Galleria Specie",s=aw(t)?"Census Report":"Report Censimenti",i=e.speciesRows.filter(e=>e.imageUrl).slice(0,12);if(0===i.length)return'\n <section id="species-grid" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <div class="content-block">\n <p>').concat(aw(t)?"No species images available.":"Nessuna immagine specie disponibile.","</p>\n </div>\n </section>");let n=i.map(e=>{let a=e.imageUrl?'<img src="'.concat((0,aj.ZD)(e.imageUrl),'" alt="').concat((0,aj.ZD)(e.scientificName),'" />'):'<div class="species-img-placeholder">'.concat(aw(t)?"No image":"Nessuna immagine","</div>");return'\n <div class="species-card">\n '.concat(a,'\n <div class="species-info">\n <div class="species-name">').concat((0,aj.ZD)(e.scientificName),'</div>\n <div class="species-count">').concat(e.count," ").concat(aw(t)?"observations":"osservazioni","</div>\n </div>\n </div>")}).join("\n");return'\n <section id="species-grid" class="content-page page-break-before" data-block="category" data-block-label="'.concat((0,aj.UQ)(a),'">\n ').concat((0,aj.p8)(aj.f2,a,s),'\n <h2 class="section-heading">').concat((0,aj.UQ)(a),'</h2>\n <div class="species-grid">\n ').concat(n,"\n </div>\n </section>")}(e,t),"\n").concat((0,aj.RT)(aj.f2,i,n,aw(t)?"Report End":"Fine Report"));return(0,aj.xZ)(a?"en":"it","".concat(a?"Census Report":"Report Censimenti"," - ").concat(s),ay,l,aj.f2)}var a_=a(75692);let aC=[{id:"census-en",labelKey:"census.htmlReport.templateEn",descriptionKey:"census.htmlReport.templateEnDesc"},{id:"census-it",labelKey:"census.htmlReport.templateIt",descriptionKey:"census.htmlReport.templateItDesc"}];function aS(e){let{open:t,onSelect:a,onClose:i}=e,{t:n}=(0,c.A)("monitoring"),[l,r]=(0,m.useState)("census-en");return(0,s.jsx)(x.Root,{open:t,onOpenChange:e=>!e&&i(),children:(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"w-full max-w-md",children:[(0,s.jsxs)(x.DialogHeader,{children:[(0,s.jsx)(x.DialogTitle,{children:n("census.htmlReport.selectTemplate")}),(0,s.jsx)(x.DialogDescription,{children:n("census.htmlReport.selectTemplateDescription")})]}),(0,s.jsx)(a_.z,{value:l,onValueChange:e=>r(e),className:"flex flex-col gap-3",children:aC.map(e=>(0,s.jsxs)("label",{htmlFor:e.id,className:"hover:border-dark-mode-blue-600 flex cursor-pointer items-start gap-3 rounded-lg border border-dark-mode-blue-400 p-3 transition-colors",children:[(0,s.jsx)(a_.C,{value:e.id,id:e.id,className:"border-dark-mode-blue-600 mt-0.5 shrink-0"}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-white",children:n(e.labelKey)}),(0,s.jsx)("span",{className:"text-xs text-dark-mode-blue-800",children:n(e.descriptionKey)})]})]},e.id))}),(0,s.jsxs)(x.DialogFooter,{children:[(0,s.jsx)(h.$,{variant:"textOnly",size:"sm",onClick:i,children:n("toolbar.htmlReport.cancel")}),(0,s.jsx)(h.$,{variant:"monitoring-600(base)",size:"sm",onClick:()=>{a(l)},children:n("toolbar.htmlReport.generate")})]})]})})}function aI(e){return null==e||isNaN(e)?"--":e.toFixed(2)}var aA=a(1808),az=a(1975),aR=a(20425),aD=a(70502),aM=a(98572),aT=a(87317),aE=a(13898),aL=a(1158),aF=a(78386),aO=a(13416);let aB=e=>{let{data:t,filterType:a,setFilterType:i,filterTypeKey:n,className:l,listHeight:r=100,itemHeight:o=40,addSelectAll:u=!1,translations:x}=e,{t:g}=(0,c.A)("monitoring"),{setFilterIndex:p}=(0,L._R)(),[b,v]=(0,m.useState)(""),f=(0,m.useRef)(null),j=(0,m.useRef)(null),y=(0,m.useMemo)(()=>t.filter(e=>e.name.toLowerCase().includes(b.toLowerCase())),[t,b]),w=(0,m.useRef)((0,tJ.debounce)(()=>{i(new Map)},100));(0,m.useEffect)(()=>{let e=j.current;if(!e)return;let t=e=>{e.stopPropagation()};return e.addEventListener("focus",t,!0),e.addEventListener("blur",t,!0),()=>{e.removeEventListener("focus",t,!0),e.removeEventListener("blur",t,!0)}},[]);let N=(0,m.useRef)((0,tJ.debounce)((e,t)=>{i(a=>{let s=new Map(a);return s.has(e)?s.delete(e):(s.set(e,{name:t}),p(null)),s})},150)).current,k=(0,m.useRef)((0,tJ.debounce)(()=>{i(e=>{if(e.size===y.length)return new Map;let t=new Map(e);
1return y.forEach(e=>{t.set(e.id,{name:e.name})}),p(null),t})},150)).current;(0,m.useEffect)(()=>{let e=w.current;return()=>{e.cancel(),N.cancel(),k.cancel()}},[N,k]);let _=(0,m.useCallback)(e=>{let{index:t,style:i}=e,{id:n,name:l}=y[t],r=a.has(n);return(0,s.jsx)("div",{style:i,className:"flex items-center px-2 hover:bg-blue-600/10",children:(0,s.jsxs)("label",{className:"flex w-full cursor-pointer items-center gap-2 py-2",onClick:e=>{e.preventDefault(),e.stopPropagation(),N(n,l)},children:[(0,s.jsx)(aO.bL,{variant:"white",className:"pointer-events-none shrink-0",checked:r,onCheckedChange:()=>{},children:(0,s.jsx)(aO.sc,{})}),(0,s.jsx)("span",{className:"select-none text-sm",children:l})]})})},[y,a,N]);return(0,s.jsxs)("div",{className:l,ref:j,children:[(0,s.jsxs)("div",{className:"mb-2 flex gap-2",children:[(0,s.jsxs)("div",{className:"relative flex-1",children:[(0,s.jsx)("input",{type:"text",className:"w-full rounded-md border border-dark-mode-blue-600(base) bg-dark-mode-blue-600(base)/30 px-3 py-2 pr-10 text-sm text-white backdrop-blur-sm placeholder:text-dark-mode-blue-1000 focus:outline-none focus:ring-1 focus:ring-cyan-400/50",placeholder:(null==x?void 0:x.search)?x.search:g("monitoring-observations:filters.values.".concat(n,".search")),"aria-label":(null==x?void 0:x.search)?x.search:g("monitoring-observations:filters.values.".concat(n,".search")),value:b,onChange:e=>v(e.target.value)}),(0,s.jsx)("div",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2",children:(0,s.jsx)(d.In,{icon:"material-symbols:search",width:22,height:22,className:"white"})})]}),a.size>0&&(0,s.jsx)(h.$,{variant:"error-600(base)",className:"h-auto !min-h-0 shrink-0 !p-1 !px-3",title:(null==x?void 0:x.clear)?x.clear:g("monitoring-observations:filters.values.".concat(n,".clear")),"aria-label":(null==x?void 0:x.clear)?x.clear:g("monitoring-observations:filters.values.".concat(n,".clear")),onClick:w.current,children:(0,s.jsx)(d.In,{icon:"ph:trash",width:20,height:20,color:"white"})})]}),(0,s.jsx)("div",{className:"overflow-hidden rounded-md",children:0===y.length?(0,s.jsx)("div",{className:"px-3 py-4 text-center text-sm text-gray-400",children:(null==x?void 0:x.noResults)?x.noResults:g("monitoring-observations:filters.values.".concat(n,".noResults"))}):(0,s.jsxs)(s.Fragment,{children:[u&&(0,s.jsx)("div",{className:"flex items-center px-2 hover:bg-blue-600/10",children:(0,s.jsxs)("label",{className:"flex w-full cursor-pointer items-center gap-2 py-2",children:[(0,s.jsx)(aO.bL,{variant:"white",className:"pointer-events-none shrink-0",checked:a.size===y.length,onCheckedChange:k,children:(0,s.jsx)(aO.sc,{})}),(0,s.jsx)("span",{className:"select-none text-sm",children:(null==x?void 0:x.selectAll)?x.selectAll:g("monitoring-observations:filters.values.".concat(n,".allSelected"))})]})}),(0,s.jsx)(aF.Y1,{ref:f,width:"100%",height:r,itemSize:o,itemCount:y.length,itemKey:e=>y[e].id,className:"custom-scrollbar-dark-mode-blue-300",overscanCount:5,style:{overflow:"auto"},children:_})]})})]})},aP=e=>{let{type:t,isLoading:a,items:i,setSelectedItems:n}=e,{t:l}=(0,c.A)("monitoring"),[r,o]=(0,m.useState)(!1),[u,x]=(0,m.useState)(new Map);if((0,m.useEffect)(()=>{i.length&&x(new Map(i.map(e=>[e.id,{name:e.name}])))},[i]),a)return(0,s.jsx)(Y.A,{width:"100%",height:50});if(0===i.length&&!a)return null;let h="trancepts"===t;return(0,s.jsxs)(ez.bL,{modal:!0,open:r,onOpenChange:e=>{if(o(e),!e){let e=u.size===i.length,t=Array.from(u,e=>{let[t,{name:a}]=e;return{id:t,name:a}});n(e?[]:0===t.length?[{id:-1,name:"none"}]:t)}},children:[(0,s.jsxs)(ez.Wv,{className:"flex w-full rounded-xl border-none bg-transparent px-2 py-1 ring-2 ring-dark-mode-blue-600(base) hover:opacity-70",children:[(0,s.jsxs)("div",{className:"flex flex-col text-left",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-primary-blue-300",children:l(h?"monitoring-observations:area.label":"monitoring-observations:filters.values.".concat(t,".label"))}),(0,s.jsx)("span",{className:"truncate text-base max-lg:max-w-[160px]",children:0===u.size?l(h?"monitoring-observations:area.noSelected":"monitoring-observations:filters.values.".concat(t,".noSelected")):u.size===i.length?l(h?"monitoring-observations:area.allSelected":"monitoring-observations:filters.values.".concat(t,".allSelected")):Array.from(u.values()).map(e=>e.name).join(", ")})]}),(0,s.jsx)(d.In,{icon:"radix-icons:triangle-down",className:"ml-auto shrink-0 self-center"})]}),(0,s.jsx)(ez.hl,{className:"z-[1234567] w-auto rounded-xl border !border-dark-mode-blue-1100 bg-dark-mode-blue-300 p-1 text-white",sideOffset:10,collisionPadding:20,children:(0,s.jsx)(aB,{data:i,filterType:u,setFilterType:x,filterTypeKey:t,addSelectAll:!0,translations:"trancepts"===t?{search:l("monitoring-observations:area.search"),selectAll:l("monitoring-observations:area.allSelected"),clear:l("common:common.selection.deselectAll"),noResults:l("monitoring-observations:area.noResults")}:void 0})})]})},aU=e=>{var t;let{selectedItems:a,setSelectedItems:i}=e,{query:o,locale:d="it"}=(0,r.useRouter)(),c=o.slug,m=Number(o.id),u=(0,l.useSession)(),{isLoading:x,data:h=[]}=(0,n.PdZ)(c,m,{exclude_taxa:L.Wg},{authorization:"Bearer ".concat(null==u||null==(t=u.data)?void 0:t.accessToken),"accept-language":d},{query:{retry:!1}});return(0,s.jsx)(aP,{type:"family",isLoading:x,items:h,selectedItems:a,setSelectedItems:i})},aH=e=>{var t;let{selectedItems:a,setSelectedItems:i}=e,{query:o,locale:d="it"}=(0,r.useRouter)(),c=o.slug,m=Number(o.id),u=(0,l.useSession)(),{isLoading:x,data:h=[]}=(0,n.BOS)(c,m,{exclude_taxa:L.Wg},{authorization:"Bearer ".concat(null==u||null==(t=u.data)?void 0:t.accessToken),"accept-language":d},{query:{retry:!1}});return(0,s.jsx)(aP,{type:"genre",isLoading:x,items:h,selectedItems:a,setSelectedItems:i})},aq=e=>{var t;let{selectedItems:a,setSelectedItems:i}=e,{query:o,locale:d="it"}=(0,r.useRouter)(),c=o.slug,m=Number(o.id),u=(0,l.useSession)(),{isLoading:x,data:h=[]}=(0,n.Zd0)(c,m,{exclude_taxa:L.Wg},{authorization:"Bearer ".concat(null==u||null==(t=u.data)?void 0:t.accessToken),"accept-language":d},{query:{retry:!1}});return(0,s.jsx)(aP,{type:"order",isLoading:x,items:h,selectedItems:a,setSelectedItems:i})},aV=e=>{var t;let{selectedItems:a,setSelectedItems:i}=e,{query:o,locale:d="it"}=(0,r.useRouter)(),c=o.slug,m=Number(o.id),u=(0,l.useSession)(),{isLoading:x,data:h=[]}=(0,n.SCi)(c,m,{exclude_taxa:L.Wg},{authorization:"Bearer ".concat(null==u||null==(t=u.data)?void 0:t.accessToken),"accept-language":d},{query:{retry:!1}});return(0,s.jsx)(aP,{type:"species",isLoading:x,items:h,selectedItems:a,setSelectedItems:i})},aW=e=>{var t;let{selectedItems:a,setSelectedItems:i}=e,{query:o,locale:d="it"}=(0,r.useRouter)(),c=o.slug,m=Number(o.id),u=(0,l.useSession)(),{isLoading:x,data:h=[]}=(0,n.tqT)(c,m,{exclude_taxa:L.Wg},{authorization:"Bearer ".concat(null==u||null==(t=u.data)?void 0:t.accessToken),"accept-language":d},{query:{retry:!1}});return(0,s.jsx)(aP,{type:"subspecies",isLoading:x,items:h,selectedItems:a,setSelectedItems:i})},a$=e=>{var t,a;let{selectedItems:i,setSelectedItems:o}=e,{query:d}=(0,r.useRouter)(),c=(0,l.useSession)(),m=d.slug,u=Number(d.id),{polygonVersion:x}=(0,L._R)(),{isLoading:h,data:g=[]}=(0,n.Aex)(m,u,null!=(a=null==x?void 0:x.id)?a:0,{authorization:"Bearer ".concat(null==c||null==(t=c.data)?void 0:t.accessToken)},{query:{enabled:!!x,select:e=>e.map(e=>{var t;return{id:e.id,name:null!=(t=e.name)?t:"AREA"}}),retry:!1}});return(0,s.jsx)(aP,{type:"trancepts",isLoading:h,items:g,selectedItems:i,setSelectedItems:o})},aQ=e=>tX.z.object({email:tX.z.string().email({message:e("common:form.invali
1dEmail")}),language:tX.z.string(),templateId:tX.z.string(),fromDate:tX.z.date().optional(),toDate:tX.z.date().optional(),trancepts:tX.z.array(tX.z.object({id:tX.z.number(),name:tX.z.string()})),species:tX.z.array(tX.z.object({id:tX.z.number(),name:tX.z.string()})),subSpecies:tX.z.array(tX.z.object({id:tX.z.number(),name:tX.z.string()})),families:tX.z.array(tX.z.object({id:tX.z.number(),name:tX.z.string()})),genres:tX.z.array(tX.z.object({id:tX.z.number(),name:tX.z.string()})),orders:tX.z.array(tX.z.object({id:tX.z.number(),name:tX.z.string()}))}),aG=e=>{var t,a,i;let{setStartedGenerating:o,setDialogOpen:u,dialogOpen:g}=e,{t:p}=(0,c.A)("monitoring"),{query:b}=(0,r.useRouter)(),v=b.slug,f=parseInt(b.id,10),{polygonVersion:j,year:y}=(0,L._R)(),w=(0,l.useSession)(),{toast:N}=e0.dj(),{isAdmin:k}=(0,Z.A)(),_=(0,e5.jE)(),{register:C,formState:{errors:S},clearErrors:I,handleSubmit:A,reset:z,watch:R,setValue:D}=(0,aT.mN)({resolver:(0,aM.u)(aQ(p)),defaultValues:{language:aD.U[0],templateId:"",trancepts:[],species:[],subSpecies:[],families:[],genres:[],orders:[]}}),[M,T]=(0,m.useState)(null),[E,F]=(0,m.useState)(!1),O=R("email"),B=R("language"),P=R("templateId"),U=R("fromDate"),H=R("toDate"),q=R("trancepts"),V=R("species"),W=R("subSpecies"),$=R("families"),Q=R("genres"),G=R("orders"),{data:K,isLoading:J,refetch:X}=(0,n.Bwi)(v,{language:B,template_type:"census"},{authorization:"Bearer ".concat(null==w||null==(t=w.data)?void 0:t.accessToken)},{query:{enabled:!!B}});(0,m.useEffect)(()=>()=>{g||(z(),I())},[I,g,z]),(0,m.useEffect)(()=>{var e;if(P)return;let t=(null!=(e=null==K?void 0:K.templates)?e:[])[0];t&&D("templateId",t.doc_id)},[D,P,null==K?void 0:K.templates]);let{mutateAsync:ee,isLoading:et}=(0,n.l41)({mutation:{onSuccess:async()=>{N({variant:"success",title:p("toolbar.siteReport.downloadNewReport.success"),description:p("toolbar.siteReport.reportWillArriveByEmail")}),u(!1),o("noLogs")},onError:()=>N({variant:"error",description:p("toolbar.siteReport.downloadNewReport.error")})}}),{mutate:ea,isLoading:es}=(0,n.kSq)({mutation:{onSuccess:()=>{N({variant:"success",description:p("toolbar.siteReport.downloadNewReport.updateTemplateNameSuccess")}),_.invalidateQueries((0,n.Fsb)(v,{language:B,template_type:"census"}))},onError:()=>{N({variant:"error",description:p("toolbar.siteReport.downloadNewReport.updateTemplateNameError")})}}}),{mutate:ei,isLoading:en}=(0,n.X85)({mutation:{onSuccess:()=>{N({variant:"success",description:p("toolbar.siteReport.downloadNewReport.deleteTemplateSuccess")}),_.invalidateQueries((0,n.Fsb)(v,{language:B,template_type:"census"}))},onError:()=>{N({variant:"error",description:p("toolbar.siteReport.downloadNewReport.deleteTemplateError")})}}}),el=async e=>{var t;j&&y&&await ee({userSlug:v,siteId:f,data:{polygon_id:j.id,year:y,doc_id_template:e.templateId,mail_to:e.email,trancept_ids:e.trancepts.map(e=>e.id),iconic_taxa:e.species.map(e=>e.id),taxon_id:e.subSpecies.map(e=>e.id),family_taxa:e.families.map(e=>e.id),genus_taxa:e.genres.map(e=>e.id),order_taxa:e.orders.map(e=>e.id)},headers:{authorization:"Bearer ".concat(null==w||null==(t=w.data)?void 0:t.accessToken),"accept-language":e.language}})};return(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"min-w-[300px] !gap-7 md:min-w-[500px]",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{children:p("toolbar.siteReport.downloadNewReport.title")}),(0,s.jsx)(x.DialogClose,{asChild:!0,disabled:et,children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:24,height:24,className:"cursor-pointer"})})]}),(0,s.jsx)(x.DialogDescription,{children:p("toolbar.siteReport.downloadNewReport.description")}),(0,s.jsxs)(x.DialogDescription,{className:"text-dark-mode-blue-1000",children:[p("toolbar.siteReport.downloadNewReport.checkLogs"),":"," ",(0,s.jsx)(ti(),{target:"_blank",href:"".concat(window.location.href,"/logs"),className:"underline",children:"Logs"})]})]}),(0,s.jsxs)("form",{onSubmit:A(el),className:"flex flex-col gap-7",children:[(0,s.jsxs)("div",{className:"flex w-full flex-col items-start gap-2",children:[(0,s.jsx)("label",{className:"text-sm md:text-base",htmlFor:"email",children:p("common:email")}),(0,s.jsx)(e6.bL,{id:"email",type:"email",placeholder:p("toolbar.siteReport.downloadNewReport.emailPlaceholder"),autoComplete:"email",variant:"dark-mode",className:"h-9 rounded-md text-sm placeholder:!text-light-mode-black-400",containerClassName:"w-full",...C("email")}),S.email&&(0,s.jsx)("p",{className:"text-state-colors-error-900",children:S.email.message})]}),(0,s.jsx)("hr",{className:"h-px w-full border-0 bg-dark-mode-blue-1000"}),(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-base",children:p("toolbar.siteReport.downloadNewReport.reportDetails")}),(0,s.jsxs)("div",{className:"col-span-full grid gap-5 md:col-span-1 md:grid-cols-2",children:[(0,s.jsxs)(aE.bL,{...C("language"),value:B,onValueChange:e=>{D("language",e),X()},children:[(0,s.jsxs)(aE.bq,{className:"w-full border-none","aria-label":p("toolbar.siteReport.downloadNewReport.languagePlaceholder"),variant:"outline-blue-600(base)",children:[(0,s.jsxs)("div",{className:"flex flex-col text-left",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-dark-mode-blue-1000",children:p("toolbar.siteReport.downloadNewReport.languagePlaceholder")}),(0,s.jsx)("span",{className:"text-base",children:B.toUpperCase()})]}),(0,s.jsx)(aE.I6,{variant:"outline-blue-600(base)",icon:"radix-icons:triangle-down",color:"white",width:30,height:30})]}),(0,s.jsx)(aE.gC,{className:"z-[1234567]",variant:"outline-blue-600(base)",children:aD.U.map(e=>(0,s.jsx)(aE.eb,{variant:"outline-blue-600(base)",value:e,children:(0,s.jsxs)("div",{className:"flex flex-row gap-2",children:[(0,s.jsx)("span",{className:"relative h-6 w-6 overflow-hidden rounded-full",children:(0,s.jsx)(aA.i,{locale:e})})," ",e.toUpperCase()]})},e))})]}),J?(0,s.jsx)(Y.A,{width:200,height:48,borderRadius:5}):(0,s.jsxs)("div",{className:"col-span-full flex flex-col gap-2 md:col-span-1",children:[(0,s.jsxs)(aE.bL,{...C("templateId"),value:P,onValueChange:e=>D("templateId",e),children:[(0,s.jsxs)(aE.bq,{className:"w-full border-none","aria-label":p("toolbar.siteReport.downloadNewReport.templatePlaceholder"),variant:"outline-blue-600(base)",children:[(0,s.jsxs)("div",{className:"flex flex-col text-left",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-dark-mode-blue-1000",children:p("toolbar.siteReport.downloadNewReport.templatePlaceholder")}),(0,s.jsx)("span",{className:"text-base",children:void 0!==P&&K&&K.templates.length>0&&null!=(i=null==(a=K.templates.find(e=>e.doc_id===P))?void 0:a.template_name)?i:"-"})]}),(0,s.jsx)(aE.I6,{variant:"outline-blue-600(base)",icon:"radix-icons:triangle-down",color:"white",width:30,height:30})]}),!!K&&K.templates.length>0&&(0,s.jsx)(aE.gC,{className:"z-[1234567]",variant:"outline-blue-600(base)",children:K.templates.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)(aE.eb,{variant:"outline-blue-600(base)",value:e.doc_id,children:e.template_name}),k&&e.url_template&&(0,s.jsx)(ti(),{href:e.url_template,target:"_blank",className:"shrink-0",children:(0,s.jsx)(d.In,{icon:"akar-icons:link-out",width:16,height:16})}),(0,s.jsx)("button",{className:"text-white",title:p("toolbar.siteReport.downloadNewReport.updateTemplateName"),"aria-label":p("toolbar.siteReport.downloadNewReport.updateTemplateName"),onClick:()=>{var t;T(e.id),ea({templateId:e.id,userSlug:v,headers:{authorization:"Bearer ".concat(null==w||null==(t=w.data)?void 0:t.accessToken)}})},disabled:es,children:(0,s.jsx)(d.In,{icon:es&&M===e.id?"eos-icons:three-dots-loading":"ic:round-refresh",width:16,height:16,className:"shrink-0"})}),(0,s.jsx)(aL.A,{isDeleting:en,onDelete:()=>{var t;ei({templateId:e.id,userSlug:v,headers:{authorization:"Bearer ".concat(null==w||null==(t=w.data)?void 0:t.accessToken)}})}})]},e.doc_id))})]}),(0,s.jsx)(aR.k,{refetchTemplates:X,templateType:"census"})]}),(0,s.jsxs)(ez.bL,{modal:!0,open:E,onOpenChange:F,children:[(0,s.jsxs)(ez.Wv,{className:"col-span-full flex h-fit items-center gap-2 rounded-xl border-none bg-transparent p-2 ring-2 ring-d
1ark-mode-blue-600(base) hover:opacity-70",children:[(0,s.jsx)(d.In,{icon:"mdi:calendar",width:20,height:20,className:"shrink-0"}),(0,s.jsxs)("div",{className:"flex flex-col text-left",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-dark-mode-blue-1000",children:"Data"}),(0,s.jsx)("span",{className:"max-w-full truncate text-base sm:max-w-sm",children:U&&H?"".concat(U.toLocaleDateString()," - ").concat(H.toLocaleDateString()):p("common:common.interval.dateRangePickerLabel")})]})]}),(0,s.jsx)(ez.hl,{className:"z-[1234567] w-auto rounded-xl border !border-dark-mode-blue-1000 bg-dark-mode-blue-200 p-1",sideOffset:10,collisionPadding:20,children:(0,s.jsx)(az.U,{_selectedStartDate:U,_selectedEndDate:H,onSelect:e=>{D("fromDate",null==e?void 0:e.from),D("toDate",null==e?void 0:e.to)},classNames:{range_start:"!to-dark-mode-blue-600(base) [&>button]:!bg-dark-mode-blue-600(base)",range_middle:"bg-dark-mode-blue-600(base)",range_end:"!to-dark-mode-blue-600(base) [&>button]:!bg-dark-mode-blue-600(base)",selected:"bg-dark-mode-blue-600(base)"}})})]}),(0,s.jsx)(a$,{selectedItems:q,setSelectedItems:e=>D("trancepts",e)}),(0,s.jsx)(aV,{selectedItems:V,setSelectedItems:e=>D("species",e)}),(0,s.jsx)(aW,{selectedItems:W,setSelectedItems:e=>D("subSpecies",e)}),(0,s.jsx)(aU,{selectedItems:$,setSelectedItems:e=>D("families",e)}),(0,s.jsx)(aH,{selectedItems:Q,setSelectedItems:e=>D("genres",e)}),(0,s.jsx)(aq,{selectedItems:G,setSelectedItems:e=>D("orders",e)})]})]}),(0,s.jsx)("hr",{className:"h-px w-full border-0 bg-dark-mode-blue-1000"}),(0,s.jsxs)(x.DialogFooter,{className:"flex justify-end",children:[(0,s.jsx)(h.$,{type:"button",variant:"outline-monitoring-600(base)",className:"px-5",onClick:()=>u(!1),size:"xs",disabled:et,children:p("common:cancel")}),(0,s.jsxs)(h.$,{variant:"monitoring-600(base)",className:"hover:!bg-dark-mode-border-dark-mode-monitoring-600(base) gap-2 px-5",type:"submit",size:"xs",disabled:!O||!P||et,children:[p("common.generate"),et&&(0,s.jsx)(d.In,{icon:"eos-icons:three-dots-loading",width:48,height:48,color:"#3c3300"})]})]})]})]})};var aK=a(28414),aZ=a(22506);let aJ=e=>{var t;let{setStartedGenerating:a,setDialogOpen:i,dialogOpen:o}=e,{t:u}=(0,c.A)("monitoring"),{locale:g="it",query:p}=(0,r.useRouter)(),b=p.slug,v=parseInt(p.id,10),{polygonVersion:f,year:j}=(0,L._R)(),y=(0,l.useSession)(),{toast:w}=e0.dj(),N=(0,aK.H)(f),{register:k,formState:{errors:_},clearErrors:C,handleSubmit:S,reset:I,watch:A,setValue:z}=(0,aT.mN)({resolver:(0,aM.u)(aQ(u)),defaultValues:{language:aD.U[0],templateId:"",trancepts:[],species:[],subSpecies:[],families:[],genres:[],orders:[]}}),[R,D]=(0,m.useState)(null),[M,T]=(0,m.useState)(!1),E=A("fromDate"),F=A("toDate"),O=A("trancepts"),B=A("species"),P=A("subSpecies"),U=A("families"),H=A("genres"),q=A("orders");(0,m.useEffect)(()=>()=>{o||(I(),C())},[C,o,I]);let{data:W,isLoading:$}=(0,n.$Ai)(b,v,{year:j,polygon_id:null==f?void 0:f.id,template_type:"census"},{authorization:"Bearer ".concat(null==y||null==(t=y.data)?void 0:t.accessToken)},{query:{enabled:!!j&&!!f}}),{mutateAsync:Q,isLoading:G}=(0,n.l41)({mutation:{onSuccess:async()=>{w({variant:"success",title:u("toolbar.siteReport.downloadNewReport.success"),description:u("toolbar.siteReport.reportWillArriveByEmail")}),i(!1),a("noLogs")},onError:()=>w({variant:"error",description:u("toolbar.siteReport.downloadNewReport.error")})}}),K=async e=>{var t;let a=null==W?void 0:W.reports.find(e=>e.doc_id===R);f&&a&&j&&await Q({userSlug:b,siteId:v,data:{polygon_id:f.id,year:j,doc_id_template:a.doc_id,mail_to:e.email,trancept_ids:e.trancepts.map(e=>e.id),iconic_taxa:e.species.map(e=>e.id),taxon_id:e.subSpecies.map(e=>e.id),family_taxa:e.families.map(e=>e.id),genus_taxa:e.genres.map(e=>e.id),order_taxa:e.orders.map(e=>e.id)},headers:{authorization:"Bearer ".concat(null==y||null==(t=y.data)?void 0:t.accessToken),"accept-language":a.language}}
1)};return(0,s.jsxs)(x.DialogContent,{variant:"dark-mode-blue-1000",className:"min-w-[300px] !gap-7 md:min-w-[500px]",overlayClassName:"py-0",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)(x.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(x.DialogTitle,{children:u("toolbar.siteReport.updateReport.title")}),(0,s.jsx)(x.DialogClose,{asChild:!0,children:(0,s.jsx)(d.In,{icon:"material-symbols:close",width:24,height:24,className:"cursor-pointer"})})]}),(0,s.jsxs)(x.DialogDescription,{className:"flex flex-col gap-0",children:[(0,s.jsxs)("span",{children:[u("toolbar.year"),": ",j]}),f&&(0,s.jsxs)("span",{className:"flex flex-row items-center gap-1",children:[u("toolbar.polygon"),":",(0,s.jsxs)("div",{className:"flex gap-2 font-bold",children:[(0,s.jsx)("span",{className:"max-w-[100px] truncate",children:"V".concat(null==f?void 0:f.version," ").concat(N)}),(0,s.jsx)("div",{className:"min-h-full w-0.5 bg-white"}),(0,s.jsx)("span",{className:"max-w-[100px] truncate",children:null==f?void 0:f.ca_label})]})]})]})]}),(0,s.jsx)(x.DialogDescription,{className:"text-light-mode-black-400",children:u("toolbar.siteReport.updateReport.latestGenerations")}),(0,s.jsx)("div",{className:"custom-scrollbar-dark-mode-blue max-h-[20vh] overflow-y-scroll px-1",children:$?(0,s.jsx)(Y.A,{width:"100%",height:300,borderRadius:5}):W&&W.reports.map(e=>(0,s.jsxs)("div",{className:"mb-4 flex flex-col gap-2",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center gap-3",children:[(0,s.jsx)(aO.bL,{id:e.doc_id,variant:"light-mode-black-300",checked:R===e.doc_id,onCheckedChange:()=>{D(R===e.doc_id?null:e.doc_id)},children:(0,s.jsx)(aO.sc,{variant:"light-mode-black-300",className:"h-full w-full"})}),(0,s.jsxs)("div",{className:"flex w-full items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex flex-row gap-0",children:[(0,s.jsx)("label",{htmlFor:e.doc_id,children:(0,s.jsx)("span",{className:"max-w-96 cursor-pointer overflow-hidden text-ellipsis font-bold leading-normal",children:e.name_report})}),e.url_report&&(0,s.jsx)(ti(),{href:e.url_report,target:"_blank",className:"ml-3",children:(0,s.jsx)(d.In,{icon:"akar-icons:link-out",width:20,height:20})})]}),(0,s.jsx)(V.E,{variant:"success",rounded:"lg",className:"w-max flex-shrink-0 font-semibold",children:u("logs.filters.values.status.enum.completed")})]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-0",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("span",{className:"text-dark-mode-blue-1000",children:u("toolbar.siteReport.updateReport.date")}),":"," ",new Date(e.created_at).toLocaleDateString(g)," ",new Date(e.created_at).toLocaleTimeString(g,{hour:"2-digit",minute:"2-digit"})]}),(0,s.jsxs)("span",{children:[(0,s.jsx)("span",{className:"text-dark-mode-blue-1000",children:u("toolbar.siteReport.updateReport.language")}),": ",e.language]}),(0,s.jsxs)("span",{children:[(0,s.jsx)("span",{className:"text-dark-mode-blue-1000",children:u("toolbar.siteReport.updateReport.template")}),": ",e.template_name]})]})]},e.doc_id))}),(0,s.jsx)(aZ.bL,{type:"single",collapsible:!0,value:R?"report-form":void 0,children:(0,s.jsx)(aZ.As,{value:"report-form",children:(0,s.jsx)(aZ.ub,{className:"px-1",children:(0,s.jsxs)("form",{onSubmit:S(K),className:"flex flex-col gap-7 transition-all duration-200",children:[(0,s.jsx)("hr",{className:"h-px w-full border-0 bg-dark-mode-blue-1000"}),(0,s.jsxs)("div",{className:"grid gap-5 md:col-span-1 md:grid-cols-2",children:[(0,s.jsx)(x.DialogTitle,{className:"!text-base",children:u("toolbar.siteReport.downloadNewReport.reportDetails")}),(0,s.jsxs)("div",{className:"col-span-full flex flex-col items-start gap-2",children:[(0,s.jsx)("label",{className:"text-sm md:text-base",htmlFor:"email",children:u("common:email")}),(0,s.jsx)(e6.bL,{id:"email",type:"email",placeholder:u("toolbar.siteReport.downloadNewReport.emailPlaceholder"),autoComplete:"email",variant:"dark-mode",className:"h-9 rounded-md text-sm placeholder:!text-light-mode-black-400",containerClassName:"w-full",...k("email")}),_.email&&(0,s.jsx)("p",{className:"text-state-colors-error-900",children:_.email.message})]}),(0,s.jsxs)(ez.bL,{modal:!0,open:M,onOpenChange:T,children:[(0,s.jsxs)(ez.Wv,{className:"col-span-full flex h-fit items-center gap-2 rounded-xl border-none bg-transparent p-2 ring-2 ring-d
1ark-mode-blue-600(base) hover:opacity-70",children:[(0,s.jsx)(d.In,{icon:"mdi:calendar",width:20,height:20,className:"shrink-0"}),(0,s.jsxs)("div",{className:"flex flex-col text-left",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-dark-mode-blue-1000",children:"Data"}),(0,s.jsx)("span",{className:"max-w-full truncate text-base sm:max-w-sm",children:E&&F?"".concat(E.toLocaleDateString()," - ").concat(F.toLocaleDateString()):u("common:common.interval.dateRangePickerLabel")})]})]}),(0,s.jsx)(ez.hl,{className:"z-[1234567] w-auto rounded-xl border !border-dark-mode-blue-1000 bg-dark-mode-blue-200 p-1",sideOffset:10,collisionPadding:20,children:(0,s.jsx)(az.U,{_selectedStartDate:E,_selectedEndDate:F,onSelect:e=>{z("fromDate",null==e?void 0:e.from),z("toDate",null==e?void 0:e.to)},classNames:{range_start:"!to-dark-mode-blue-600(base) [&>button]:!bg-dark-mode-blue-600(base)",range_middle:"bg-dark-mode-blue-600(base)",range_end:"!to-dark-mode-blue-600(base) [&>button]:!bg-dark-mode-blue-600(base)",selected:"bg-dark-mode-blue-600(base)"}})})]}),(0,s.jsx)(a$,{selectedItems:O,setSelectedItems:e=>z("trancepts",e)}),(0,s.jsx)(aV,{selectedItems:B,setSelectedItems:e=>z("species",e)}),(0,s.jsx)(aW,{selectedItems:P,setSelectedItems:e=>z("subSpecies",e)}),(0,s.jsx)(aU,{selectedItems:U,setSelectedItems:e=>z("families",e)}),(0,s.jsx)(aH,{selectedItems:H,setSelectedItems:e=>z("genres",e)}),(0,s.jsx)(aq,{selectedItems:q,setSelectedItems:e=>z("orders",e)})]}),(0,s.jsx)("hr",{className:"h-px w-full border-0 bg-dark-mode-blue-1000"}),(0,s.jsxs)(x.DialogFooter,{className:"flex justify-end",children:[(0,s.jsx)(h.$,{type:"button",variant:"outline-monitoring-600(base)",className:"px-5",onClick:()=>i(!1),size:"xs",disabled:G,children:u("common:cancel")}),(0,s.jsxs)(h.$,{variant:"monitoring-600(base)",className:"hover:!bg-dark-mode-border-dark-mode-monitoring-600(base) gap-2 px-5",type:"submit",size:"xs",children:[u("common.generate"),G&&(0,s.jsx)(d.In,{icon:"eos-icons:three-dots-loading",width:48,height:48,color:"#3c3300"})]})]})]})})})})]})},aY=()=>{var e;let{t}=(0,c.A)("monitoring"),a=(0,l.useSession)(),{query:i}=(0,r.useRouter)(),o=i.slug,u=parseInt(i.id,10),{polygonVersion:h,year:g}=(0,L._R)(),{canEditSite:p,isDemoAndOwner:b}=(0,Z.A)(),v=(0,K.R)("SiteReport"),f=function(){var e,t,a,i,o,d,u;let{t:x}=(0,c.A)("monitoring"),{query:h,locale:g="it"}=(0,r.useRouter)(),p=h.slug,b=Number(h.id),v=(0,l.useSession)(),f=(0,L._R)(),j=(0,K.R)("SiteHtmlReport"),[w,N]=(0,m.useState)(!1),[k,_]=(0,m.useState)(null),[C,S]=(0,m.useState)(!1),I=(0,m.useMemo)(()=>{var e;return{authorization:"Bearer ".concat(null==v||null==(e=v.data)?void 0:e.accessToken)}},[null==v||null==(e=v.data)?void 0:e.accessToken]),A=(0,m.useMemo)(()=>{var e;return{"accept-language":g,authorization:"Bearer ".concat(null==v||null==(e=v.data)?void 0:e.accessToken)}},[g,null==v||null==(t=v.data)?void 0:t.accessToken]),z=j&&!!(null==v||null==(a=v.data)?void 0:a.accessToken),{data:R}=(0,n.HFe)(p,b,A,{query:{enabled:z}}),{data:D}=(0,n.Aex)(p,b,null!=(u=null==(i=f.polygonVersion)?void 0:i.id)?u:0,I,{query:{enabled:z&&!!(null==(o=f.polygonVersion)?void 0:o.id)}}),M=(0,m.useMemo)(()=>{var e;return{polygon_id:null==(e=f.polygonVersion)?void 0:e.id,...f.filterDate.from&&{date_from:(0,y.default)(f.filterDate.from,"yyyy-MM-dd")},...f.filterDate.to&&{date_to:(0,y.default)(f.filterDate.to,"yyyy-MM-dd")},min_confidence:f.minimumConfidenceValue,...f.area&&{trancept_ids:String(f.area.id)},...f.device&&{hive_ids:String(f.device.id)},...f.filterSpecies.size>0&&{taxa:Array.from(f.filterSpecies.keys()).join(",")},...f.filterFamily.size>0&&{family_taxa:Array.from(f.filterFamily.keys()).join(",")},...f.filterGenre.size>0&&{genus_taxa:Array.from(f.filterGenre.keys()).join(",")},...f.filterOrder.size>0&&{order_taxa:Array.from(f.filterOrder.keys()).join(",")},...f.filterClass.size>0&&{class_taxa:Array.from(f.filterClass.keys()).join(",")},exclude_taxa:L.Wg}},[f]),{data:T}=(0,n.Ihj)(p,b,M,A,{query:{enabled:z&&!!(null==(d=f.polygonVersion)?void 0:d.id)}}),{data:E}=(0,n._l1)(p,b,{},I,{query:{enabled:z}}),F=(0,m.useMemo)(()=>(function(e,t){let a=[];return e.filterDate.from&&a.push({label:t("census.htmlReport.filterDateFrom"),value:(0,y.default)(e.filterDate.from,"dd/MM/yyyy")}),e.filterDate.to&&a.push({label:t("census.htmlReport.filterDateTo"),value:(0,y.default)(e.filterDate.to,"dd/MM/yyyy")}),e.filterSpecies.size>0&&a.push({label:t("census.htmlReport.filterSpecies"),value:Array.from(e.filterSpecies.values()).map(e=>e.name).join(", ")}),e.filterFamily.size>0&&a.push({label:t("census.htmlReport.filterFamily"),value:Array.from(e.filterFamily.values()).map(e=>e.name).join(", ")}),e.filterGenre.size>0&&a.push({label:t("census.htmlReport.filterGenus"),value:Array.from(e.filterGenre.values()).map(e=>e.name).join(", ")}),e.filterOrder.size>0&&a.push({label:t("census.htmlReport.filterOrder"),value:Array.from(e.filterOrder.values()).map(e=>e.name).join(", ")}),e.filterClass.size>0&&a.push({label:t("census.htmlReport.filterClass"),value:Array.from(e.filterClass.values()).map(e=>e.name).join(", ")}),e.minimumConfidenceValue>0&&a.push({label:t("census.htmlReport.filterMinConfidence"),value:"".concat((100*e.minimumConfidenceValue).toFixed(0),"%")}),e.area&&a.push({label:t("census.htmlReport.filterArea"),value:e.area.name}),e.device&&a.push({label:t("census.htmlReport.filterDevice"),value:e.device.name}),a})(f,x),[f,x]),O=(0,m.useMemo)(()=>{var e,t,a,s,i,n,l,r,o,d,c;let m=null!=(s=null==R?void 0:R.hectares)?s:0,u=f.statisticsAlienFilter,x=f.statisticsEndemicFilter,h=null==T?void 0:T["alien_only"===u?"alien_only":"native_only"===u?"native_only":"endemic_only"===x?"endemic_only":"non_endemic_only"===x?"non_endemic_only":"all_data"],g=(null!=D?D:[]).map(e=>{var t;return{name:null!=(t=e.name)?t:"Transect ".concat(e.id),shannonIndex:"--",alienPercentage:"--",totalSpecies:"--",topSpecies:[]}}),b=Array.isArray(E)?E:[];return{siteName:null!=(i=null==R?void 0:R.name)?i:p,siteLocation:[null==R?void 0:R.city,null==R?void 0:R.province,null==R?void 0:R.country].filter(
1Boolean).join(", ")||"N/A",siteHectares:m.toFixed(2),ecosystemType:null!=(n=null==R?void 0:R.ecosystem_name)?n:"N/A",customerName:p,date:new Date().toISOString(),latitude:null!=(l=null==R||null==(e=R.latitude)?void 0:e.toString())?l:"N/A",longitude:null!=(r=null==R||null==(t=R.longitude)?void 0:t.toString())?r:"N/A",activeFilters:F,transectCount:String(null!=(o=null==D?void 0:D.length)?o:0),totalSpecies:String(null!=(d=null==h?void 0:h.species_richness)?d:0),totalIndividuals:String(null!=(c=null==h?void 0:h.total)?c:0),shannonIndex:aI(null==h||null==(a=h.shannon)?void 0:a.shannon),identificationsPerHour:aI(null==h?void 0:h.hourly),transectSummaryRows:g,deviceRows:b&&Array.isArray(b)?b.map(e=>{var t,a,s,i,n,l,r,o;return{name:null!=(i=e.name)?i:"--",deviceId:null!=(l=null!=(n=e.device_external_id)?n:null==(t=e.device_id)?void 0:t.toString())?l:"--",latitude:null!=(r=null==(a=e.latitude)?void 0:a.toString())?r:"--",longitude:null!=(o=null==(s=e.longitude)?void 0:s.toString())?o:"--"}}):[],speciesRows:[],isDataLoading:!1}},[R,p,D,T,E,F,f.statisticsAlienFilter]),B=(0,m.useCallback)(async e=>{S(!0),N(!1);try{let t=await (0,n.JNi)(p,b,{...M,pagination_limit:1e3},A),a=function(e){let t=new Map;for(let i of e){let e=i.taxa;if(!(null==e?void 0:e.taxa))continue;let n=e.taxa,l=t.get(n);if(l)l.count+=1,!l.imageUrl&&i.url&&(l.imageUrl=i.url);else{var a,s;t.set(n,{scientificName:null!=(a=e.latin_taxa)?a:e.taxa,commonName:e.taxa,count:1,imageUrl:null!=(s=i.url)?s:null})}}return Array.from(t.values()).sort((e,t)=>t.count-e.count)}(null!=t?t:[]),s={...O,speciesRows:a},i=ak(s,e);_(i)}catch(t){_(ak(O,e))}finally{S(!1)}},[O,p,b,M,A]),P=(0,m.useCallback)(()=>{_(null)},[]);return{isSiteHtmlReportActive:j,showTemplateSelector:w,setShowTemplateSelector:N,isGeneratingHtml:C,reportHtml:k,handleCloseEditor:P,TemplateSelectorElement:(0,s.jsx)(aS,{open:w,onSelect:B,onClose:()=>N(!1)}),EditorOverlayElement:k?(0,s.jsx)(af.Z,{html:k,onClose:P}):null}}(),[j,w]=(0,m.useState)(!1),[N,k]=(0,m.useState)(!1),[_,C]=(0,m.useState)("newReport"),{isGeneratingProgressLoading:S,startedGenerating:I,setStartedGenerating:A,forceRefetchStatusLogs:z}=(0,av.J)({category:"report_generation_census",dateFrom:j?void 0:""}),{data:R,isLoading:D}=(0,n.$Ai)(o,u,{year:g,polygon_id:null==h?void 0:h.id,template_type:"census"},{authorization:"Bearer ".concat(null==a||null==(e=a.data)?void 0:e.accessToken)},{query:{enabled:!!g&&!!h}});return(p||b)&&(v||f.isSiteHtmlReportActive)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(x.Root,{open:j,onOpenChange:w,children:[(0,s.jsx)(x.DialogTrigger,{asChild:!0,children:(0,s.jsx)(()=>S&&v?(0,s.jsx)(Y.A,{width:150,height:35,borderRadius:5}):I&&v?(0,s.jsx)(ab.a,{forceRefetchStatusLogs:z,label:t("toolbar.siteReport.reportGenerating")}):(0,s.jsxs)(e7.bL,{open:N,onOpenChange:k,children:[(0,s.jsxs)(e7.ty,{id:"census-report-generation-button","data-description":"Open dropdown to generate or view census reports",className:"flex flex-nowrap gap-2 font-bold disabled:!opacity-30",children:[(0,s.jsx)(d.In,{icon:"material-symbols:docs-outline-rounded",width:24,height:24,className:"shrink-0"}),t("common.generate")]}),(0,s.jsxs)(e7.SQ,{variant:"dark-mode-blue-300",side:"bottom",className:"z-[12345678] w-fit p-1.5 shadow-none",children:[v&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(x.DialogTrigger,{asChild:!0,children:(0,s.jsx)(e7._2,{variant:"dark-mode-blue-300",className:"cursor-pointer rounded-md",onClick:()=>{C("newReport")},children:t("toolbar.siteReport.new")})}),D?(0,s.jsx)(Y.A,{width:150,height:35,borderRadius:5}):R&&R.reports.length>0&&(0,s.jsx)(x.DialogTrigger,{asChild:!0,children:(0,s.jsx)(e7._2,{variant:"dark-mode-blue-300",className:"cursor-pointer rounded-md",onClick:()=>{C("viewReport")},children:t("toolbar.siteReport.view")})})]}),f.isSiteHtmlReportActive&&(0,s.jsx)(e7._2,{variant:"dark-mode-blue-300",className:"cursor-pointer rounded-md",onClick:()=>{k(!1),f.setShowTemplateSelector(!0)},disabled:f.isGeneratingHtml,children:f.isGeneratingHtml?t("toolbar.htmlReport.generating"):t("toolbar.report.htmlEditor")})]})]}),{})}),"newReport"===_?(0,s.jsx)(aG,{setStartedGenerating:A,setDialogOpen:w,dialogOpen:j}):(0,s.jsx)(aJ,{setStartedGenerating:A,setDialogOpen:w,dialogOpen:j})]}),f.TemplateSelectorElement,f.EditorOverlayElement]}
1):null},aX=e=>{let{isLoadingYears:t,isLoadingPolygons:a,polygonsByYear:i}=e,{t:n}=(0,c.A)("monitoring"),{setYear:l,polygonVersion:r,setPolygonVersion:o}=(0,L._R)(),u=(0,au.W)({current:document.getElementById("census-trancepts-devices-map")},{amount:.4}),[x,h]=(0,m.useState)(!1),g=(0,m.useMemo)(()=>r?new Date(r.related_at).getFullYear():null,[r]),p=(0,m.useMemo)(()=>r?(e=>e.name?e.name:"V".concat(e.version))(r):"",[r]);return(0,s.jsx)(P.nB,{id:"census-trancepts-devices-toolbar",variant:"transparent",className:"z-[123456] -ml-5 -mt-5 w-[calc(100%+40px)] gap-2.5 !rounded-none border-b border-b-dark-mode-blue-300 bg-dark-mode-blue-200 !px-5 !pb-4 !pt-2 pl-0 pr-0 text-white transition-all duration-300 ease-in-out max-lg:hidden lg:sticky lg:top-0",children:(0,s.jsxs)("div",{className:"flex items-center gap-5 max-xl:flex-wrap",children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-4",children:[(0,s.jsx)(am.d,{}),(0,s.jsxs)(ez.bL,{open:x,onOpenChange:h,modal:!0,children:[t||a?(0,s.jsx)(Y.A,{width:250,height:50,borderRadius:12}):(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)(ax.N,{children:u&&(0,s.jsxs)(ah.P.span,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"mb-1 flex items-center gap-1.5 text-xs font-medium text-primary-blue-300",children:[(0,s.jsx)(d.In,{icon:"mdi:map-outline",width:14,height:14}),(0,s.jsx)("span",{children:n("toolbar.perimeter")})]})}),(0,s.jsxs)(ez.Wv,{className:"z-[999999] flex h-fit w-max min-w-[150px] items-center justify-between gap-3 rounded-xl border-none bg-transparent px-3 py-2 ring-2 ring-dark-mode-blue-600(base) transition-all hover:ring-dark-mode-blue-500",children:[r?(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-base font-semibold text-white",children:g}),(0,s.jsx)("span",{className:"text-primary-blue-400",children:"\xb7"}),(0,s.jsx)("span",{className:"max-w-[150px] truncate text-base text-emerald-400",children:p})]}):(0,s.jsx)("span",{className:"text-primary-blue-300",children:n("toolbar.selectPerimeter")}),(0,s.jsx)(d.In,{icon:"radix-icons:triangle-down",className:"text-primary-blue-300"})]})]}),(0,s.jsx)(ez.hl,{variant:"outline-blue-600(base)",align:"start",className:"z-[999999] min-w-[200px] p-0 shadow shadow-dark-mode-blue-1100",children:(0,s.jsx)(tY.bL,{className:"max-h-[350px] overflow-y-auto",children:i.map(e=>(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"bg-dark-mode-blue-100 sticky top-0 z-10 flex items-center gap-2 px-3 py-2 text-xs font-semibold uppercase tracking-wide text-primary-blue-300",children:[(0,s.jsx)(d.In,{icon:"mdi:calendar",width:14,height:14}),e.year]}),(0,s.jsx)(tY.YJ,{variant:"blue-600(base)",className:"ml-3 border-l-2 border-emerald-500/40 pl-2",children:e.polygons.map(e=>(0,s.jsx)(ap,{polygon:e,isSelected:e.id===(null==r?void 0:r.id),onSelect:e=>{o(e),l(new Date(e.related_at).getFullYear()),h(!1)}},"".concat(e.id,"-").concat(e.version)))})]},e.year))})})]})]}),(0,s.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,s.jsx)(ac,{}),(0,s.jsx)(tG,{}),(0,s.jsx)(aY,{}),(0,s.jsx)("span",{"aria-hidden":"true",className:"mx-1 h-6 w-px bg-white/10"}),(0,s.jsx)(ag.p,{sections:{functionalities:!0}})]})]})})};var a0=a(96020),a1=a(66278),a2=a(71148);let a5=e=>{let{className:t}=e,{t:a}=(0,c.A)("monitoring"),{locale:i="it"}=(0,r.useRouter)(),{viewSection:n,viewTab:l,filterDate:o,setFilterDate:d,filterFamily:x,setFilterFamily:h,filterGenre:g,setFilterGenre:p,filterOrder:b,setFilterOrder:v,filterClass:f,setFilterClass:j,filterSpecies:w,setFilterSpecies:N,filterSubSpecies:k,setFilterSubSpecies:_,filterIndex:C,setFilterIndex:S,minimumConfidenceValue:I,setMinimumConfidenceValue:A}=(0,L._R)(),z=(0,m.useMemo)(()=>{let e=[],t=(0,eH.no)(i);return C&&e.push((0,s.jsx)(a4,{label:"".concat(a("monitoring-observations:filters.values.index.label"),": ").concat(C.name),onDelete:()=>S(null)},"index")),I>0&&.5!==I&&e.push((0,s.jsx)(a4,{label:"".concat(a("monitoring-observations:filters.values.confidence.levelOf"),": ").concat(I.toFixed((0,eH.AP)(.05))),onDelete:()=>A(.5)},"confidence")),(o.from||o.to)&&e.push((0,s.jsx)(a4,{label:"".concat(o.from?(0,y.default)(o.from,"dd MMMM yyyy",{locale:t}):""," ").concat(o.to?"- "+(0,y.default)(o.to,"dd MMMM yyyy",{locale:t}):""),onDelete:()=>d({from:void 0,to:void 0})},"date")),x.size>0&&x.forEach((t,a)=>{e.push((0,s.jsx)(a4,{label:t.name,onDelete:()=>h(e=>{let t=new Map(e);return t.delete(a),t})},"family-".concat(a)))}),g&&g.size>0&&g.forEach((t,a)=>{e.push((0,s.jsx)(a4,{label:t.name,onDelete:()=>p(e=>{let t=new Map(e);return t.delete(a),t})},"genus-".concat(a)))}),b&&b.size>0&&b.forEach((t,a)=>{e.push((0,s.jsx)(a4,{label:t.name,onDelete:()=>v(e=>{let t=new Map(e);return t.delete(a),t})},"order-".concat(a)))}),f&&f.size>0&&f.forEach((t,a)=>{e.push((0,s.jsx)(a4,{label:t.name,onDelete:()=>j(e=>{let t=new Map(e);return t.delete(a),t})},"class-".concat(a)))}),w.size>0&&w.forEach((t,a)=>{e.push((0,s.jsx)(a4,{label:t.name,onDelete:()=>N(e=>{let t=new Map(e);return t.delete(a),t})},"species-".concat(a)))}),k.size>0&&k.forEach((t,a)=>{e.push((0,s.jsx)(a4,{label:t.name,onDelete:()=>_(e=>{let t=new Map(e);return t.delete(a),t})},"subspecies-".concat(a)))}),e},[i,o,d,x,h,g,p,b,v,f,j,w,N,C,S,I,A,k,_]);return"sensors"===n||"sensors"===l||0===z.length?null:(0,s.jsx)("div",{className:(0,u.cn)("flex min-w-0 max-w-full flex-nowrap items-center gap-2 overflow-x-auto scrollbar-hide",t),children:z})},a4=e=>{let{label:t,onDelete:a}=e;return(0,s.jsxs)(V.E,{size:"xs",rounded:"lg",className:"!gap-2 whitespace-nowrap !border-dark-mode-blue-1100 !bg-transparent !px-1.5 !py-0.5 !text-dark-mode-blue-1100",children:[(0,s.jsx)("span",{children:t}),(0,s.jsx)(h.$,{variant:"unstyled",className:"!h-max p-0 !text-dark-mode-blue-1100",onClick:a,children:(0,s.jsx)(d.In,{icon:"mdi:close",width:16,height:16})})]})},a3=e=>{let{isLoadingYears:t,isLoadingPolygons:a,polygonsByYear:i}=e,{t:n}=(0,c.A)("monitoring"),[l]=(0,a0.J)(),{setYear:r,polygonVersion:o,setPolygonVersion:x}=(0,L._R)(),h=(0,U.r)(),[g,p]=(0,m.useState)(!1),[b,v]=(0,m.useState)(!1),f=(0,m.useMemo)(()=>o?new Date(o.related_at).getFullYear():null,[o]),j=(0,m.useMemo)(()=>o?(e=>e.name?e.name:"V".concat(e.version))(o):"",[o]);return(0,s.jsx)(a1.X,{isClosed:g,setIsClosed:p,variant:"dark"===h?"dark-mode-blue-600(base)":"light-mode-black-300",showMinimizedTabText:n("toolbar.openInfo"),
1commonClassName:(0,u.cn)("lg:!hidden",{"!hidden":l.isExpanded}),children:(0,s.jsxs)(a2.bL,{defaultValue:"info",children:[(0,s.jsx)(a2.j7,{className:"flex flex-wrap justify-center gap-5",children:(0,s.jsx)(a2.Xi,{value:"info",variant:"dark"===h?"dark-mode-blue-1000":"light",children:n("toolbar.info")})}),(0,s.jsxs)(a2.av,{value:"info",className:"!mt-0 flex flex-col gap-5 !p-0",children:[(0,s.jsxs)("div",{className:"flex flex-row items-end justify-between",children:[(0,s.jsx)(am.d,{}),(0,s.jsx)("span",{className:"mb-0",children:(0,s.jsx)(ag.p,{sections:{functionalities:!0}})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("span",{className:"flex items-center gap-1.5 text-xs font-medium text-primary-blue-300",children:[(0,s.jsx)(d.In,{icon:"mdi:map-outline",width:14,height:14}),n("toolbar.perimeter")]}),(0,s.jsxs)(ez.bL,{open:b,onOpenChange:v,modal:!0,children:[t||a?(0,s.jsx)(Y.A,{width:220,height:50,borderRadius:5}):(0,s.jsxs)(ez.Wv,{className:"flex h-fit w-full items-center justify-between gap-3 rounded-xl border-none bg-transparent px-3 py-2 ring-2 ring-dark-mode-blue-600(base) transition-all hover:ring-dark-mode-blue-500",children:[o?(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-base font-semibold text-white",children:f}),(0,s.jsx)("span",{className:"text-primary-blue-400",children:"\xb7"}),(0,s.jsx)("span",{className:"max-w-[150px] truncate text-base text-emerald-400",children:j})]}):(0,s.jsx)("span",{className:"text-primary-blue-300",children:n("toolbar.selectPerimeter")}),(0,s.jsx)(d.In,{icon:"radix-icons:triangle-down",className:"text-primary-blue-300"})]}),(0,s.jsx)(ez.hl,{variant:"outline-blue-600(base)",align:"start",className:"z-[12345] min-w-[280px] p-0 shadow shadow-dark-mode-blue-1100",children:(0,s.jsx)(tY.bL,{className:"max-h-[350px] overflow-y-auto",children:i.map(e=>(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"bg-dark-mode-blue-100 sticky top-0 z-10 flex items-center gap-2 px-3 py-2 text-xs font-semibold uppercase tracking-wide text-primary-blue-300",children:[(0,s.jsx)(d.In,{icon:"mdi:calendar",width:14,height:14}),e.year]}),(0,s.jsx)(tY.YJ,{variant:"blue-600(base)",className:"ml-3 border-l-2 border-emerald-500/40 pl-2",children:e.polygons.map(e=>(0,s.jsx)(ap,{polygon:e,isSelected:e.id===(null==o?void 0:o.id),onSelect:e=>{x(e),r(new Date(e.related_at).getFullYear()),v(!1)}},"".concat(e.id,"-").concat(e.version)))})]},e.year))})})]})]}),(0,s.jsx)("hr",{className:"h-px w-full border-0 bg-dark-mode-blue-1000"}),(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)(ac,{}),(0,s.jsx)(tG,{})]}),(0,s.jsx)("span",{className:"relative flex min-w-0 max-w-full items-center gap-2",children:(0,s.jsx)(a5,{})})]})]})]})})},a6=new Date().getFullYear(),a9=e=>new Date(e.related_at).getFullYear(),a8=()=>{var e,t,a,i,o,d;let{query:c,locale:u="it"}=(0,r.useRouter)(),x=(0,l.useSession)(),h=c.slug,g=Number(c.id),{year:p,setYear:b,polygonVersion:v,setPolygonVersion:f}=(0,L._R)(),j=Number.parseInt(c.year,10),y=Number.isFinite(j)&&j<=a6?j:null,{data:w}=(0,n.HFe)(h,g,{"accept-language":u,authorization:"Bearer ".concat(null==x||null==(e=x.data)?void 0:e.accessToken)},{query:{enabled:!!h&&!!g&&!!(null==x||null==(t=x.data)?void 0:t.accessToken)}}),N=null!=(d=null==w||null==(a=w.settings)?void 0:a.default_year)?d:null,{data:k=[],isLoading:_}=(0,n.l8J)(h,g,{authorization:"Bearer ".concat(null==x||null==(i=x.data)?void 0:i.accessToken)},{query:{select:e=>{let t=e.sort((e,t)=>t.shortname.localeCompare(e.shortname));return 0===t.length?[{date_from:"".concat(a6,"-01-01"),date_to:"".concat(a6,"-12-31"),shortname:a6.toString()}]:t}}}),{data:C=[],isLoading:S}=(0,n.Oyv)(h,g,{},{authorization:"Bearer ".concat(null==x||null==(o=x.data)?void 0:o.accessToken)},{});(0,m.useEffect)(()=>{var e,t,a;if(v||0===k.length||S)return;let s=e=>null===e?void 0:k.find(t=>t.shortname===e.toString()),i=parseInt((null!=(t=null!=(e=s(y))?e:s(N))?t:k[0]).shortname,10),n=[...C].sort((e,t)=>
1Number(!!t.starred)-Number(!!e.starred)||new Date(t.related_at).getTime()-new Date(e.related_at).getTime()||t.version-e.version),l=null!=(a=n.find(e=>a9(e)===i))?a:n[0];l?(f(l),b(a9(l))):b(i)},[k,C,S,p,v,y,N,b,f]);let I=(0,m.useMemo)(()=>Object.entries(C.reduce((e,t)=>{let a=a9(t);return e[a]||(e[a]=[]),e[a].push(t),e},{})).map(e=>{let[t,a]=e;return{year:parseInt(t,10),polygons:a.sort((e,t)=>t.version-e.version)}}).sort((e,t)=>t.year-e.year),[C]);return _||0!==k.length?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(aX,{isLoadingYears:_,years:k,isLoadingPolygons:S,polygonsByYear:I}),(0,s.jsx)(a3,{isLoadingYears:_,years:k,isLoadingPolygons:S,polygonsByYear:I})]}):null},a7=e=>{let{children:t}=e,{viewSection:a}=(0,L._R)();return"sensors"===a?(0,s.jsx)("div",{className:"flex flex-col overflow-hidden transition-colors duration-300",children:t}):(0,s.jsx)("div",{className:"flex flex-col transition-colors duration-300",children:t})},se=[{value:"census",labelKey:"monitoring-observations:viewSection.census",icon:"mdi:notebook-multiple"},{value:"sensors",labelKey:"monitoring-observations:viewSection.sensors",icon:"mdi:radio-tower"}],st=()=>{let{t:e}=(0,c.A)("monitoring"),{viewSection:t,setViewSection:a}=(0,L._R)(),{asPath:i}=(0,r.useRouter)();return(0,s.jsxs)("div",{className:"flex items-center gap-1 border-b border-dark-mode-blue-300 bg-dark-mode-blue-200 px-5",children:[(0,s.jsx)("div",{role:"tablist",className:"flex items-center gap-1",children:se.map(i=>{let n=t===i.value;return(0,s.jsxs)("button",{type:"button",role:"tab","aria-selected":n,onClick:()=>a(i.value),className:(0,u.cn)("inline-flex items-center gap-2 border-b-2 px-4 py-2.5 text-sm font-semibold transition-colors",n?"border-emerald-400 text-white":"border-transparent text-white/45 hover:text-white"),children:[(0,s.jsx)(d.In,{icon:i.icon,className:"size-4","aria-hidden":"true"}),(0,s.jsx)("span",{children:e(i.labelKey)})]},i.value)})}),(0,s.jsx)(a5,{className:"ml-auto hidden min-w-0 max-w-[45%] lg:flex"}),"sensors"===t&&(0,s.jsx)("span",{className:"ml-auto flex items-center py-1.5 pl-2",children:(0,s.jsx)(P.Ek,{widget:"census-sensors",previewHeight:700,iframeHeight:800,basePath:i.split(/[?#]/)[0].replace(/\/census\/?$/,"/")})})]})};var sa=a(92502),ss=a(46905),si=a(32129),sn=a(22038);let sl=(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,s.jsx)("path",{d:"M12 2L2 7L12 12L22 7L12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,s.jsx)("path",{d:"M2 17L12 22L22 17",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,s.jsx)("path",{d:"M2 12L12 17L22 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),sr=()=>{var e;let{t}=(0,c.A)("monitoring"),{query:a,locale:i="it"}=(0,r.useRouter)(),o=a.slug,d=Number(a.id),u=(0,l.useSession)(),{filterClass:x,setFilterClass:g,clearChildFiltersFromClass:p}=(0,L._R)(),{classCascadeParams:b}=(0,sn.m)(),v=(0,m.useRef)(x.size);(0,m.useEffect)(()=>{v.current!==x.size&&p(),v.current=x.size},[x.size,p]);let{isLoading:f,data:j=[]}=(0,n.TWo)(o,d,b,{authorization:"Bearer ".concat(null==u||null==(e=u.data)?void 0:e.accessToken),"accept-language":i},{query:{retry:!1}});if(f)return(0,s.jsx)("li",{className:"mt-2 hover:!bg-transparent",children:(0,s.jsx)(Y.A,{height:30,width:"100%",borderRadius:8})});let y=j.length>0,w=t("monitoring-observations:filters.noData");return(0,s.jsx)("li",{className:y?"":"cursor-not-allowed opacity-50",title:y?void 0:w,children:(0,s.jsx)(e7._2,{disabled:!y,onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,disabled:!y,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 ".concat(y?"!text-white":"pointer-events-none !text-white/50"),disabled:!y,children:[sl,t("monitoring-observations:filters.values.class.label"),!y&&(0,s.jsxs)("span",{className:"ml-auto text-xs opacity-70",children:["(",w,")"]})]})}),(0,s.jsx)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:10,className:"z-[123456] min-w-44 rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 text-white",children:(0,s.jsx)(aB,{data:j,filterType:x,setFilterType:g,filterTypeKey:"class"})})]})})})},so=()=>{let{t:e}=(0,c.A)("monitoring"),{classificationFilter:t,setClassificationFilter:a}=(0,L._R)();return(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",onClick:()=>{a("unclassified_only"===t?"all":"unclassified_only")},children:[(0,s.jsx)(d.In,{icon:"mdi:help-circle-outline",width:24}),e("monitoring-observations:statistics.classificationSelector.unclassifiedOnly"),"unclassified_only"===t&&(0,s.jsx)(d.In,{icon:"mdi:check",width:16,className:"ml-auto text-emerald-400"})]})})})};var sd=a(8562);let sc=()=>{let{t:e}=(0,c.A)("monitoring"),{minimumConfidenceValue:t,setMinimumConfidenceValue:a}=(0,L._R)();return(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",children:[(0,s.jsx)(d.In,{icon:"material-symbols:sliders",width:24}),e("monitoring-observations:filters.values.confidence.label")]})}),(0,s.jsxs)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:10,className:"z-[123456] min-w-64 roun
1ded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 p-4 text-white",children:[(0,s.jsxs)("h4",{className:"pb-4 text-center text-sm font-bold text-white",children:[e("monitoring-observations:filters.values.confidence.levelOf"),": ",t.toFixed((0,eH.AP)(.05))]}),(0,s.jsx)(sd.bL,{className:"relative flex w-full touch-none select-none items-center",step:.05,max:1,min:0,onValueChange:e=>{a(e[0])},defaultValue:[t],value:[t],trackClassName:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-slate-600",rangeClassName:"absolute h-full bg-white",children:(0,s.jsx)(sd.zi,{className:"block h-5 w-5 rounded-full border-white bg-white"})})]})]})})})};var sm=a(89512),su=a(18153);let sx=new Date().getFullYear(),sh=()=>{var e;let{t}=(0,c.A)("monitoring"),{filterDate:a,setFilterDate:i}=(0,L._R)(),n=(0,m.useMemo)(()=>{let e=[];for(let t=sx;t>=sx-10;t--)e.push(t);return e},[]);return(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",children:[(0,s.jsx)(d.In,{icon:"mdi:calendar",width:24}),t("monitoring-observations:filters.values.date.label")]})}),(0,s.jsxs)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:105,className:"z-[123456] min-w-44 rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 text-white",children:[(0,s.jsxs)("div",{className:"border-dark-mode-blue-600 mb-2 border-b pb-2",children:[(0,s.jsx)("div",{className:"mb-1 px-2 text-xs font-medium text-white/60",children:t("monitoring-observations:filters.values.year.label")}),(0,s.jsx)("div",{className:"flex flex-wrap gap-1 px-2",children:n.slice(0,6).map(e=>(0,s.jsx)("button",{onClick:()=>(e=>{let t=new Date(e,0,1);i({from:(0,sm.A)(t),to:(0,su.A)(t)})})(e),className:"hover:bg-dark-mode-blue-600 rounded bg-dark-mode-blue-500 px-2 py-1 text-xs",children:e},e))})]}),(0,s.jsx)(az.U,{_selectedStartDate:null==a?void 0:a.from,_selectedEndDate:null==a?void 0:a.to,onSelect:e=>{i({from:null==e?void 0:e.from,to:null==e?void 0:e.to})},classNames:{range_start:"!to-dark-mode-blue-600(base) [&>button]:!bg-dark-mode-blue-600(base)",range_middle:"bg-dark-mode-blue-600(base)",range_end:"!to-dark-mode-blue-600(base) [&>button]:!bg-dark-mode-blue-600(base)",selected:"bg-dark-mode-blue-600(base)"}},null==a||null==(e=a.from)?void 0:e.getFullYear()),(0,s.jsxs)("div",{className:"text-center font-medium",children:[(null==a?void 0:a.from)&&"".concat((0,y.default)(null==a?void 0:a.from,"dd/MM/yyyy")," - "),(null==a?void 0:a.to)&&(0,y.default)(null==a?void 0:a.to,"dd/MM/yyyy")]})]})]})})})},sg=()=>{let{t:e}=(0,c.A)("monitoring"),{statisticsEndemicFilter:t,setStatisticsEndemicFilter:a}=(0,L._R)(),i=e=>{a(e===t?"all":e)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",onClick:()=>i("endemic_only"),children:[(0,s.jsx)(d.In,{icon:"mdi:map-marker-star",width:24}),e("monitoring-observations:statistics.endemicSelector.endemicOnly"),"endemic_only"===t&&(0,s.jsx)(d.In,{icon:"mdi:check",width:16,className:"ml-auto text-emerald-400"})]})})}),(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",onClick:()=>i("non_endemic_only"),children:[(0,s.jsx)(d.In,{icon:"mdi:map-marker-off",width:24}),e("monitoring-observations:statistics.endemicSelector.nonEndemicOnly"),"non_endemic_only"===t&&(0,s.jsx)(d.In,{icon:"mdi:check",width:16,className:"ml-auto text-emerald-400"})]})})})]})},sp=()=>{let{t:e}=(0,c.A)("monitoring"),{geoProbabilityFilter:t,setGeoProbabilityFilter:a}=(0,L._R)(),i=e=>{a(e===t?"all":e)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",onClick:()=>i("hide_improbable"),children:[(0,s.jsx)(d.In,{icon:"mdi:map-marker-remove-outline",width:24}),e("monitoring-observations:censuses.geo.filter.hideImprobable"),"hide_improbable"===t&&(0,s.jsx)(d.In,{icon:"mdi:check",width:16,className:"ml-auto text-emerald-400"})]})})}),(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",onClick:()=>i("only_improbable"),children:[(0,s.jsx)(d.In,{icon:"mdi:map-marker-alert-outline",width:24}),e("monitoring-observations:censuses.geo.filter.onlyImprobable"),"only_improbable"===t&&(0,s.jsx)(d.In,{icon:"mdi:check",width:16,className:"ml-auto text-emerald-400"})]})})})]})},sb=(0,s.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,s.jsx)("path",{d:"M7.40039 8C7.82665 8.0001 8.21329 8.16761 8.5 8.43945C8.78671 8.16761 9.17335 8.0001 9.59961 8H14.4004C14.8267 8.0001 15.2133 8.16761 15.5 8.43945C15.7867 8.16761 16.1733 8.0001 16.5996 8H21.4004C22.2837 8.00021 22.9998 8.71626 23 9.59961V14.4004C22.9998 15.2837 22.2837 15.9998 21.4004 16H16.5996C16.1731 15.9999 15.7868 15.8317 15.5 15.5596C15.2132 15.8317 14.8269 15.9999 14.4004 16H9.59961C9.1731 15.9999 8.78676 15.8317 8.5 15.5596C8.21324 15.8317 7.8269 15.9999 7.40039 16H2.59961C1.71626 15.9998 1.00021 15.2837 1 14.4004V9.59961C1.00021 8.71626 1.71626 8.00021 2.59961 8H7.40039ZM2.59961 14.4004H7.40039V9.59961H2.59961V14.4004ZM9.59961 14.4004H14.4004V9.59961H9.59961V14.4004ZM16.5996 14.4004H21.4004V9.59961H16.5996V14.4004Z",fill:"#ffffff"})}),sv=()=>{var e;let{t}=(0,c.A)("monitoring"),{query:a,locale:i="it"}=(0,r.useRouter)(),o=a.slug,d=Number(a.id),u=(0,l.useSession)(),{filterFamily:x,setFilterFamily:g,clearChildFiltersFromFamily:p}=(0,L._R)(),{familyCascadeParams:b}=(0,sn.m)(),v=(0,m.useRef)(x.size);(0,m.useEffect)(()=>{v.current!==x.size&&p(),v.current=x.size},[x.size,p]);let{isLoading:f,data:j=[]}=(0,n.PdZ)(o,d,b,{authorization:"Bearer ".concat(null==u||null==(e=u.data)?void 0:e.accessToken),"accept-language":i},{query:{retry:!1}});if(f)return(0,s.jsx)("li",{className:"mt-2 hover:!bg-transparent",children:(0,s.jsx)(Y.A,{height:30,width:"100%",borderRadius:8})});let y=j.length>0,w=t("monitoring-observations:filters.noData");return(0,s.jsx)("li",{className:y?"":"cursor-not-allowed opacity-50",title:y?void 0:w,children:(0,s.jsx)(e7._2,{disabled:!y,onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,disabled:!y,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 ".concat(y?"!text-white":"pointer-events-none !text-white/50"),disabled:!y,children:[sb,t("monitoring-observations:filters.values.family.label"),!y&&(0,s.jsxs)("span",{className:"ml-auto text-xs opacity-70",children:["(",w,")"]})]})}),(0,s.jsx)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:10,className:"z-[123456] min-w-44 rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 text-white",children:(0,s.jsx)(aB,{data:j,filterType:x,setFilterType:g,filterTypeKey:"family"})})]})})})},sf=(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,s.jsx)("path",{d:"M11 4H5C4.44772 4 4 4.44772 4 5V11C4 11.5523 4.44772 12 5 12H11C11.5523 12 12 11.5523 12 11V
15C12 4.44772 11.5523 4 11 4Z",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,s.jsx)("path",{d:"M19 12H13C12.4477 12 12 12.4477 12 13V19C12 19.5523 12.4477 20 13 20H19C19.5523 20 20 19.5523 20 19V13C20 12.4477 19.5523 12 19 12Z",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),sj=()=>{var e;let{t}=(0,c.A)("monitoring"),{query:a,locale:i="it"}=(0,r.useRouter)(),o=a.slug,d=Number(a.id),u=(0,l.useSession)(),{filterGenre:x,setFilterGenre:g,clearChildFiltersFromGenus:p}=(0,L._R)(),{genusCascadeParams:b}=(0,sn.m)(),v=(0,m.useRef)(x.size);(0,m.useEffect)(()=>{v.current!==x.size&&p(),v.current=x.size},[x.size,p]);let{isLoading:f,data:j=[]}=(0,n.BOS)(o,d,b,{authorization:"Bearer ".concat(null==u||null==(e=u.data)?void 0:e.accessToken),"accept-language":i},{query:{retry:!1}});if(f)return(0,s.jsx)("li",{className:"mt-2 hover:!bg-transparent",children:(0,s.jsx)(Y.A,{height:30,width:"100%",borderRadius:8})});let y=j.length>0,w=t("monitoring-observations:filters.noData");return(0,s.jsx)("li",{className:y?"":"cursor-not-allowed opacity-50",title:y?void 0:w,children:(0,s.jsx)(e7._2,{disabled:!y,onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,disabled:!y,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 ".concat(y?"!text-white":"pointer-events-none !text-white/50"),disabled:!y,children:[sf,t("monitoring-observations:filters.values.genre.label"),!y&&(0,s.jsxs)("span",{className:"ml-auto text-xs opacity-70",children:["(",w,")"]})]})}),(0,s.jsx)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:15,className:"z-[123456] min-w-44 rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 text-white",children:(0,s.jsx)(aB,{data:j,filterType:x,setFilterType:g,filterTypeKey:"genre"})})]})})})},sy=()=>{let{t:e}=(0,c.A)("monitoring"),{groupConsecutive:t,setGroupConsecutive:a}=(0,L._R)();return(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",onClick:()=>a(e=>!e),children:[(0,s.jsx)(d.In,{icon:"material-symbols:stacked-bar-chart-rounded",width:24}),e("monitoring-observations:censuses.grouping.toggleLabel"),t&&(0,s.jsx)(d.In,{icon:"mdi:check",width:16,className:"ml-auto text-emerald-400"})]})})})},sw=()=>{let{t:e}=(0,c.A)("monitoring"),{query:t}=(0,r.useRouter)(),a=t.slug,{filterIndex:i,setFilterIndex:l,clearTaxonFilters:o}=(0,L._R)(),[u,x]=(0,m.useState)(""),{isLoading:g,data:p=[]}=(0,n.bv4)(a,void 0,{query:{retry:!1}}),b=(0,m.useMemo)(()=>u?p.filter(e=>e.name.toLowerCase().includes(u.toLowerCase())):p,[p,u]),v=(0,m.useCallback)(e=>{(null==i?void 0:i.id)===e.id?l(null):(o(),l(e))},[i,l,o]),f=(0,m.useCallback)(()=>{l(null)},[l]);return g?(0,s.jsx)("li",{className:"hover:!bg-transparent",children:(0,s.jsx)(Y.A,{height:30,width:"100%",borderRadius:8})}):0===p.length?null:(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",children:[(0,s.jsx)(d.In,{icon:"material-symbols:grid-view-outline-rounded",width:24}),e("monitoring-observations:filters.values.index.label")]})}),(0,s.jsxs)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:10,className:"z-[123456] w-60 rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 text-white",children:[(0,s.jsxs)("div",{className:"mb-2 flex gap-2",children:[(0,s.jsxs)("div",{className:"relative flex-1",children:[(0,s.jsx)("input",{type:"text",className:"border-dark-mode-blue-600 bg-dark-mode-blue-600/30 w-full rounded-md border px-3 py-2 pr-10 text-sm text-white backdrop-blur-sm placeholder:text-dark-mode-blue-1000 focus:outline-none focus:ring-1 focus:ring-cyan-400/50",placeholder:e("monitoring-observations:filters.values.index.search"),"aria-label":e("monitoring-observations:filters.values.index.search"),value:u,onChange:e=>x(e.target.value)}),(0,s.jsx)("div",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2",children:(0,s.jsx)(d.In,{icon:"material-symbols:search",width:22,height:22,className:"white"})})]}),i&&(0,s.jsx)(h.$,{variant:"error-600(base)",className:"h-auto !min-h-0 shrink-0 !p-1 !px-3",title:e("monitoring-observations:filters.values.index.clear"),"aria-label":e("monitoring-observations:filters.values.index.clear"),onClick:f,children:(0,s.jsx)(d.In,{icon:"ph:trash",width:20,height:20,color:"white"})})]}),(0,s.jsx)("div",{className:"max-h-48 overflow-y-auto rounded-md",children:0===b.length?(0,s.jsx)("div",{className:"px-3 py-4 text-center text-sm text-gray-400",children:e("monitoring-observations:filters.values.index.noResults")}):b.map(e=>{let t=(null==i?void 0:i.id)===e.id;return(0,s.jsx)("div",{className:"flex items-center px-2 hover:bg-blue-600/10",children:(0,s.jsxs)("label",{className:"flex w-full cursor-pointer items-center gap-2 py-2",onClick:t=>{t.preventDefault(),t.stopPropagation(),v({id:e.id,name:e.name})},children:[(0,s.jsx)(aO.bL,{variant:"white",className:"pointer-events-none shrink-0",checked:t,onCheckedChange:()=>{},children:(0,s.jsx)(aO.sc,{})}),(0,s.jsx)("span",{className:"select-none text-sm",children:e.name})]})},e.id)})})]})]})})})};var sN=a(28781);let sk=(0,g.tv)({base:"flex flex-1 items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-semibold transition-colors border",variants:{kingdom:{fauna:"",flora:""},selected:{true:"",false:"border-white/40 bg-white/10 text-white hover:bg-white/20"}},compoundVariants:[{kingdom:"fauna",selected:!0,class:"bg-amber-500/30 text-amber-300 border-amber-500/50"}
1,{kingdom:"flora",selected:!0,class:"bg-green-500/30 text-green-300 border-green-500/50"}]}),s_=()=>{var e,t;let{t:a}=(0,c.A)("monitoring"),{query:i,locale:o="it"}=(0,r.useRouter)(),u=i.slug,x=Number(i.id),h=(0,l.useSession)(),{filterSpecies:g,setFilterSpecies:p,clearChildFiltersFromIconicTaxa:b}=(0,L._R)(),{data:v=[]}=(0,n.SCi)(u,x,{exclude_taxa:L.Wg},{authorization:"Bearer ".concat(null==h||null==(e=h.data)?void 0:e.accessToken),"accept-language":o},{query:{retry:!1,enabled:!!(null==h||null==(t=h.data)?void 0:t.accessToken)}}),{faunaData:f,floraData:j}=(0,m.useMemo)(()=>({faunaData:v.filter(e=>e.id!==sN.yY.PLANTAE),floraData:v.filter(e=>e.id===sN.yY.PLANTAE)}),[v]),y=f.length>0&&f.every(e=>g.has(e.id)),w=j.length>0&&j.every(e=>g.has(e.id)),N=f.length>0,k=j.length>0;return N||k?(0,s.jsx)("li",{className:"list-none !bg-transparent px-2 py-1",children:(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[N&&(0,s.jsxs)("button",{type:"button",onClick:()=>{if(y){let e=new Map(g);f.forEach(t=>e.delete(t.id)),p(e)}else{let e=new Map;f.forEach(t=>e.set(t.id,{name:t.name})),p(e)}b()},className:sk({kingdom:"fauna",selected:y}),children:[(0,s.jsx)(d.In,{icon:"mdi:paw",width:16}),a("monitoring-observations:filters.values.kingdom.fauna")]}),k&&(0,s.jsxs)("button",{type:"button",onClick:()=>{if(w){let e=new Map(g);j.forEach(t=>e.delete(t.id)),p(e)}else{let e=new Map;j.forEach(t=>e.set(t.id,{name:t.name})),p(e)}b()},className:sk({kingdom:"flora",selected:w}),children:[(0,s.jsx)(d.In,{icon:"mdi:leaf",width:16}),a("monitoring-observations:filters.values.kingdom.flora")]})]})}):null},sC=(0,s.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,s.jsx)("path",{d:"M14.4004 1C15.2837 1.00021 15.9998 1.71626 16 2.59961V7.40039C15.9999 7.8269 15.8317 8.21324 15.5596 8.5C15.8317 8.78676 15.9999 9.1731 16 9.59961V14.4004C15.9999 14.8269 15.8317 15.2132 15.5596 15.5C15.8317 15.7868 15.9999 16.1731 16 16.5996V21.4004C15.9998 22.2837 15.2837 22.9998 14.4004 23H9.59961C8.71626 22.9998 8.00021 22.2837 8 21.4004V16.5996C8.0001 16.1733 8.16761 15.7867 8.43945 15.5C8.16761 15.2133 8.0001 14.8267 8 14.4004V9.59961C8.0001 9.17335 8.16761 8.78671 8.43945 8.5C8.16761 8.21329 8.0001 7.82665 8 7.40039V2.59961C8.00021 1.71626 8.71626 1.00021 9.59961 1H14.4004ZM9.59961 21.4004H14.4004V16.5996H9.59961V21.4004ZM9.59961 14.4004H14.4004V9.59961H9.59961V14.4004ZM9.59961 7.40039H14.4004V2.59961H9.59961V7.40039Z",fill:"#ffffff"})}),sS=()=>{var e;let{t}=(0,c.A)("monitoring"),{query:a,locale:i="it"}=(0,r.useRouter)(),o=a.slug,d=Number(a.id),u=(0,l.useSession)(),{filterOrder:x,setFilterOrder:g,clearChildFiltersFromOrder:p}=(0,L._R)(),{orderCascadeParams:b}=(0,sn.m)(),v=(0,m.useRef)(x.size);(0,m.useEffect)(()=>{v.current!==x.size&&p(),v.current=x.size},[x.size,p]);let{isLoading:f,data:j=[]}=(0,n.Zd0)(o,d,b,{authorization:"Bearer ".concat(null==u||null==(e=u.data)?void 0:e.accessToken),"accept-language":i},{query:{retry:!1}});if(f)return(0,s.jsx)("li",{className:"mt-2 hover:!bg-transparent",children:(0,s.jsx)(Y.A,{height:30,width:"100%",borderRadius:8})});let y=j.length>0,w=t("monitoring-observations:filters.noData");return(0,s.jsx)("li",{className:y?"":"cursor-not-allowed opacity-50",title:y?void 0:w,children:(0,s.jsx)(e7._2,{disabled:!y,onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,disabled:!y,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 ".concat(y?"!text-white":"pointer-events-none !text-white/50"),disabled:!y,children:[sC,t("monitoring-observations:filters.values.order.label"),!y&&(0,s.jsxs)("span",{className:"ml-auto text-xs opacity-70",children:["(",w,")"]})]})}),(0,s.jsx)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:10,className:"z-[123456] min-w-44 rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 text-white",children:(0,s.jsx)(aB,{data:j,filterType:x,setFilterType:g,filterTypeKey:"order"})})]})})})};var sI=a(45145),sA=a(96985),sz=a(5278);let sR=new Date,sD=()=>{let{t:e}=(0,c.A)("monitoring"),{setFilterDate:t}=(0,L._R)(),a=e=>{let a;switch(e){case"last7days":a=(0,sI.A)(sR,7);break;case"last30days":a=(0,sI.A)(sR,30);break;case"last3months":a=(0,sA.A)(sR,3);break;
1case"lastYear":a=(0,sz.A)(sR,1);break;case"last5years":a=(0,sz.A)(sR,5);break;case"last10years":a=(0,sz.A)(sR,10)}a&&sR&&t({from:a,to:sR})};return(0,s.jsx)("li",{children:(0,s.jsx)(e7._2,{onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 !text-white",children:[(0,s.jsx)(d.In,{icon:"mdi:clock-outline",width:24}),e("monitoring-observations:filters.values.periods.label")]})}),(0,s.jsxs)(e7.SQ,{align:"start",side:"left",sideOffset:8,className:"z-[123456] min-w-44 rounded-lg border border-dark-mode-blue-1100 bg-gradient-to-br from-dark-mode-blue-400 to-dark-mode-blue-200 text-white shadow-xl",children:[(0,s.jsx)(e7._2,{onSelect:()=>a("last7days"),className:"cursor-pointer px-3 py-2 text-sm hover:bg-dark-mode-blue-500",children:e("monitoring-observations:filters.values.periods.last7days")}),(0,s.jsx)(e7._2,{onSelect:()=>a("last30days"),className:"cursor-pointer px-3 py-2 text-sm hover:bg-dark-mode-blue-500",children:e("monitoring-observations:filters.values.periods.last30days")}),(0,s.jsx)(e7._2,{onSelect:()=>a("last3months"),className:"cursor-pointer px-3 py-2 text-sm hover:bg-dark-mode-blue-500",children:e("monitoring-observations:filters.values.periods.last3months")}),(0,s.jsx)(e7._2,{onSelect:()=>a("lastYear"),className:"cursor-pointer px-3 py-2 text-sm hover:bg-dark-mode-blue-500",children:e("monitoring-observations:filters.values.periods.lastYear")}),(0,s.jsx)(e7._2,{onSelect:()=>a("last5years"),className:"cursor-pointer px-3 py-2 text-sm hover:bg-dark-mode-blue-500",children:e("monitoring-observations:filters.values.periods.last5years")}),(0,s.jsx)(e7._2,{onSelect:()=>a("last10years"),className:"cursor-pointer px-3 py-2 text-sm hover:bg-dark-mode-blue-500",children:e("monitoring-observations:filters.values.periods.last10years")})]})]})})})},sM=()=>{var e;let{t}=(0,c.A)("monitoring"),{query:a,locale:i="it"}=(0,r.useRouter)(),o=a.slug,u=Number(a.id),x=(0,l.useSession)(),{filterSpecies:g,setFilterSpecies:p,clearChildFiltersFromIconicTaxa:b}=(0,L._R)(),{iconicTaxaCascadeParams:v}=(0,sn.m)(),f=(0,m.useRef)(g.size);(0,m.useEffect)(()=>{f.current!==g.size&&b(),f.current=g.size},[g.size,b]);let{isLoading:j,data:y=[]}=(0,n.SCi)(o,u,v,{authorization:"Bearer ".concat(null==x||null==(e=x.data)?void 0:e.accessToken),"accept-language":i},{query:{retry:!1}});if(j)return(0,s.jsx)("li",{className:"mt-2 hover:!bg-transparent",children:(0,s.jsx)(Y.A,{height:30,width:"100%",borderRadius:8})});let w=y.length>0,N=t("monitoring-observations:filters.noData");return(0,s.jsx)("li",{className:"mt-2 ".concat(w?"":"cursor-not-allowed opacity-50"),title:w?void 0:N,children:(0,s.jsx)(e7._2,{disabled:!w,onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,disabled:!w,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 ".concat(w?"!text-white":"pointer-events-none !text-white/50"),disabled:!w,children:[(0,s.jsx)(d.In,{icon:"material-symbols:category-outline-rounded",width:24}),t("monitoring-observations:filters.values.species.label"),!w&&(0,s.jsxs)("span",{className:"ml-auto text-xs opacity-70",children:["(",N,")"]})]})}),(0,s.jsx)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:60,className:"z-[123456] w-60 rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 text-white",children:(0,s.jsx)(aB,{data:y,filterType:g,setFilterType:p,filterTypeKey:"species"})})]})})})},sT=()=>{var e;let{t}=(0,c.A)("monitoring"),{query:a,locale:i="it"}=(0,r.useRouter)(),o=a.slug,m=Number(a.id),u=(0,l.useSession)(),{filterSubSpecies:x,setFilterSubSpecies:g}=(0,L._R)(),{taxaCascadeParams:p}=(0,sn.m)(),{isLoading:b,data:v=[]}=(0,n.tqT)(o,m,p,{authorization:"Bearer ".concat(null==u||null==(e=u.data)?void 0:e.accessToken),"accept-language":i},{query:{retry:!1}});if(b)return(0,s.jsx)("li",{className:"mt-2 hover:!bg-transparent",children:(0,s.jsx)(Y.A,{height:30,width:"100%",borderRadius:8})});let f=v.length>0,j=t("monitoring-observations:filters.noData");return(0,s.jsx)("li",{className:"mt-2 ".concat(f?"":"cursor-not-allowed opacity-50"),title:f?void 0:j,children:(0,s.jsx)(e7._2,{disabled:!f,onSelect:e=>e.preventDefault(),children:(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,disabled:!f,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"!h-auto w-full justify-start gap-3 p-0 ".concat(f?"!text-white":"pointer-events-none !text-white/50"),disabled:!f,children:[(0,s.jsx)(d.In,{icon:"material-symbols:dashboard-2-outline-rounded",width:24}),t("monitoring-observations:filters.values.subspecies.label"),!f&&(0,s.jsxs)("span",{className:"ml-auto text-xs opacity-70",children:["(",j,")"]})]})}),(0,s.jsx)(e7.SQ,{align:"end",alignOffset:-15,side:"bottom",sideOffset:15,className:"z-[123456] w-60 rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 text-white",children:(0,s.jsx)(aB,{data:v,filterType:x,setFilterType:g,filterTypeKey:"subspecies"})})]})})})},sE=e=>{let{icon:t,label:a}=e;return(0,s.jsxs)("div",{className:"mb-1 flex items-center gap-2 px-2 pt-2 text-[10px] font-semibold uppercase tracking-wider text-white/50",children:[(0,s.jsx)(d.In,{icon:t,width:12}),a]})},sL=()=>{let{t:e}=(0,c.A)("monitoring"),{viewMode:t}=(0,L._R)();return(0,s.jsxs)(e7.bL,{children:[(0,s.jsx)(e7.ty,{asChild:!0,children:(0,s.jsxs)(h.$,{variant:"unstyled",className:"min-w-max gap-1 !text-sm font-semibold !text-white hover:!opacity-60",children:[(0,s.jsx)(d.In,{icon:"ic:round-filter-alt",width:16,height:16}),e("monitoring-observations:filters.label")]})}),(0,s.jsx)(e7.SQ,{side:"bottom",sideOffset:2,align:"end",className:"z-[123456] rounded-lg border border-dark-mode-blue-1100 bg-dark-mode-blue-300 p-2 text-white",children:(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsxs)("div",{className:"flex min-w-40 flex-col",children:["list"===t&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(sE,{icon:"mdi:eye-outline",label:e("monitoring-observations:filters.sections.view")}),(0,s.jsx)("ul",{className:"flex flex-col [&>li:hover]:bg-dark-mode-blue-500 [&>li]:rounded-md",children:(0,s.jsx)(sy,{})})]}),(0,s.jsx)(sE,{icon:"mdi:calendar-clock",label:e("monitoring-observations:filters.sections.time")}
1),(0,s.jsxs)("ul",{className:"flex flex-col [&>li:hover]:bg-dark-mode-blue-500 [&>li]:rounded-md",children:[(0,s.jsx)(sD,{}),(0,s.jsx)(sh,{})]}),(0,s.jsx)(sE,{icon:"mdi:chart-line",label:e("monitoring-observations:filters.sections.analysis")}),(0,s.jsx)("ul",{className:"flex flex-col [&>li:hover]:bg-dark-mode-blue-500 [&>li]:rounded-md",children:(0,s.jsx)(sw,{})}),(0,s.jsx)(sE,{icon:"mdi:check-circle-outline",label:e("monitoring-observations:filters.sections.quality")}),(0,s.jsx)("ul",{className:"flex flex-col [&>li:hover]:bg-dark-mode-blue-500 [&>li]:rounded-md",children:(0,s.jsx)(sc,{})}),(0,s.jsx)(sE,{icon:"mdi:map-marker-star",label:e("monitoring-observations:statistics.endemic")}),(0,s.jsx)("ul",{className:"flex flex-col [&>li:hover]:bg-dark-mode-blue-500 [&>li]:rounded-md",children:(0,s.jsx)(sg,{})}),(0,s.jsx)(sE,{icon:"mdi:map-marker-question-outline",label:e("monitoring-observations:censuses.geo.filter.title")}),(0,s.jsx)("ul",{className:"flex flex-col [&>li:hover]:bg-dark-mode-blue-500 [&>li]:rounded-md",children:(0,s.jsx)(sp,{})}),(0,s.jsx)(sE,{icon:"mdi:help-circle-outline",label:e("monitoring-observations:statistics.classification")}),(0,s.jsx)("ul",{className:"flex flex-col [&>li:hover]:bg-dark-mode-blue-500 [&>li]:rounded-md",children:(0,s.jsx)(so,{})})]}),(0,s.jsx)("div",{className:"bg-dark-mode-blue-600 w-px"}),(0,s.jsxs)("div",{className:"flex min-w-44 flex-col",children:[(0,s.jsx)(sE,{icon:"mdi:dna",label:e("monitoring-observations:filters.sections.taxonomy")}),(0,s.jsx)(s_,{}),(0,s.jsxs)("ul",{className:"mt-1 flex flex-col border-l border-white/20 pl-2 [&>li:hover]:bg-dark-mode-blue-500 [&>li]:rounded-md",children:[(0,s.jsx)(sM,{}),(0,s.jsx)(sr,{}),(0,s.jsx)(sS,{}),(0,s.jsx)(sv,{}),(0,s.jsx)(sj,{}),(0,s.jsx)(sT,{})]})]})]})})]})},sF=[{value:"detail",labelKey:"monitoring-observations:viewTabs.detail"},{value:"summary",labelKey:"monitoring-observations:viewTabs.summary"}],sO=()=>{let{t:e}=(0,c.A)("monitoring"),{viewTab:t,setViewTab:a,viewSection:i}=(0,L._R)();return"sensors"===i?null:(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-3",children:[(0,s.jsx)(sL,{}),(0,s.jsx)("div",{className:"border-dark-mode-blue-600/60 inline-flex items-center rounded-full border bg-dark-mode-blue-300/60 p-1",children:sF.map(i=>{let n=t===i.value;return(0,s.jsx)("button",{type:"button",onClick:()=>a(i.value),className:(0,u.cn)("rounded-full px-5 py-1.5 text-sm font-medium transition-colors duration-200",n?"bg-dark-mode-blue-1000/40 text-white shadow-sm":"text-gray-400 hover:text-white"),children:e(i.labelKey)},i.value)})})]})},sB=()=>{var e,t,a,i,o,x,g,p;let{t:b}=(0,c.A)("monitoring"),{query:v}=(0,r.useRouter)(),f=v.slug,j=Number(v.id),y=(0,l.useSession)(),{polygonVersion:w,area:N,setArea:k,polygons:_,setPolygons:C,device:S,setDevice:I,toolbarViewMode:A,setToolbarViewMode:z,viewSection:R}=(0,L._R)(),D=(0,e5.jE)(),{toast:M}=e0.dj(),{canEditSite:T}=(0,Z.A)(),[E,F]=(0,m.useState)(null),[O,B]=(0,m.useState)(""),[P,U]=(0,m.useState)(""),[H,q]=(0,m.useState)(null),[W,$]=(0,m.useState)(""),Q=(0,m.useRef)(null),{mutate:G,isLoading:K}=(0,n.GtR)({mutation:{onSuccess:()=>{var e;D.invalidateQueries((0,n.F94)(f,j,null!=(e=null==w?void 0:w.id)?e:0)),M({variant:"success",description:b("toolbar.roiSubpolygonSelector.renameSuccess"),duration:1500}),q(null)},onError:()=>{M({variant:"error",description:b("toolbar.roiSubpolygonSelector.renameError")})}}}),X=(0,m.useCallback)((e,t)=>{q(e),$(t)},[]),ee=(0,m.useCallback)(e=>{var t;let a=W.trim();a&&w&&G({userSlug:f,siteId:j,plantationsPolygonsId:w.id,geometryIndex:e,data:{name:a},headers:{authorization:"Bearer ".concat(null==y||null==(t=y.data)?void 0:t.accessToken)}})},[W,w,G,f,j,null==y||null==(e=y.data)?void 0:e.accessToken]),et=(0,m.useCallback)(()=>{q(null),$("")},[]);(0,m.useEffect)(()=>{null!==H&&Q.current&&(Q.current.focus(),Q.current.select())},[H]);let{height:ea}=(0,J.w)({ref:{current:E},box:"border-box"});(0,m.useEffect)(()=>{F(document.getElementById("census-trancepts-devices-toolbar"))},[]);let es=!!w&&"sensors"!==R,{data:ei}=(0,n.pFV)(f,j,null!=(g=null==w?void 0:w.id)?g:0,{},{authorization:"Bearer ".concat(null==y||null==(t=y.data)?void 0:t.accessToken)},{query:{enabled:es,retry:!1}}),{data:en=[],isLoading:el}=(0,n.Aex)(f,j,null!=(p=null==w?void 0:w.id)?p:0,{authorization:"Bearer ".concat(null==y||null==(a=y.data)?void 0:a.accessToken)},{query:{enabled:es,retry:!1}}),{data:er=[],isLoading:eo}=(0,n._l1)(f,j,{polygon_id:null==w?void 0:w.id},{authorization:"Bearer ".concat(null==y||null==(i=y.data)?void 0:i.accessToken)},{query:{enabled:es,retry:!1,select:e=>e}}),ed=(0,m.useMemo)(()=>{var e;return(null==ei||null==(e=ei.roi)?void 0:e.features)&&ei.roi.features.length>1},[ei]);(0,m.useEffect)(()=>{el||eo||(en.length>0?z("transects"):er.length>0?z("devices"):ed&&z("polygons"))},[en.length,er.length,ed,el,eo,z]);let ec=(0,m.useMemo)(()=>en.filter(e=>{var t;return(null!=(t=e.name)?t:"Transect ".concat(e.id)).toLowerCase().includes(O.toLowerCase())}),[en,O]),em=(0,m.useMemo)(()=>{let e=er;return N&&(e=e.filter(e=>e.trancept_id===N.id)),P&&(e=e.filter(e=>{var t;return(null!=(t=e.name)?t:"Device ".concat(e.id)).toLowerCase().includes(P.toLowerCase())})),e},[er,N,P]),eu=(0,m.useMemo)(()=>{let e=[];return ed&&e.push({value:"polygons",label:(0,s.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(d.In,{icon:"uil:polygon",width:16,height:16}),"polygons"===A&&(0,s.jsx)("span",{children:b("common.polygon_one")})]})}),en.length>0&&e.push({value:"transects",label:(0,s.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(d.In,{icon:"fluent:shape-organic-20-regular",width:18,height:18}),"transects"===A&&(0,s.jsx)("span",{children:b("monitoring-observations:type.area")})]})}),er.length>0&&e.push({value:"devices",label:(0,s.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,s.jsx)(d.In,{icon:"mdi:camera-outline",width:18,height:18}),"devices"===A&&(0,s.jsx)("span",{children:b("monitoring-observations:type.device")})]})}),e},[ed,en.length,er.length,A,b]);if("sensors"===R)return null;let ex=ed||en.length>0&&er.length>0;return 0!==en.length||el||!w||0!==er.length||eo||ed?(0,s.jsx)("div",{className:"sticky z-[123456] w-full border-b border-b-dark-mode-blue-300 bg-dark-mode-blue-200 text-white transition-all duration-300 ease-in-out max-lg:top-0 lg:pb-1 lg:pt-0",style:{to
1p:null!=ea?ea:0},children:(0,s.jsxs)("div",{className:"flex w-full flex-col gap-4 lg:mx-auto lg:flex-row lg:items-center lg:gap-2.5",children:[ex&&eu.length>0&&(0,s.jsx)("div",{className:"flex shrink-0 items-center gap-2 px-4 pt-2 lg:px-5 lg:pt-0",children:(0,s.jsx)(ss.T,{value:A,options:eu,onChange:e=>{e&&(z(e),k(null),C([]),I(null))},variant:"dark-mode-blue-1100"})}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col items-start gap-2 overflow-x-hidden px-5 lg:flex-row lg:items-center lg:px-1",children:["transects"===A&&en.length>5?(0,s.jsx)(sa.I,{items:[],onClickResult:()=>{},value:O,onChange:e=>B(e.target.value),onDelete:()=>B(""),variant:"outline-dark-mode-blue-500",showResults:!1,placeholder:"".concat(b("monitoring-observations:area.search"),"..."),className:"!h-8 !rounded-lg !text-sm lg:w-44",iconClassName:"w-5 h-5",containerClassName:" lg:!py-2"}):"devices"===A&&er.length>5?(0,s.jsx)(sa.I,{items:[],onClickResult:()=>{},value:P,onChange:e=>U(e.target.value),onDelete:()=>U(""),variant:"outline-dark-mode-blue-500",showResults:!1,placeholder:"".concat(b("monitoring-observations:device.search"),"..."),className:"!h-8 !rounded-lg !text-sm lg:w-44",iconClassName:"w-5 h-5",containerClassName:" lg:!py-2"}):null,(0,s.jsxs)("div",{className:"custom-scrollbar-dark-mode-blue flex w-[calc(100vw_-_40px)] flex-1 items-center gap-2 overflow-x-auto p-0 max-lg:scrollbar-hide lg:w-full lg:px-2 lg:py-2 lg:pb-3 lg:pt-2",children:["transects"===A&&(0,s.jsx)(s.Fragment,{children:el?(0,s.jsx)(Y.A,{width:100,height:28,className:"rounded-lg"}):(0,s.jsxs)("div",{className:"flex flex-row items-center gap-2",children:[(0,s.jsx)(h.$,{variant:"unstyled",className:"!h-max shrink-0 p-0",onClick:()=>{k(null),I(null)},children:(0,s.jsxs)(V.E,{size:"xs",rounded:"lg",variant:null===N?"darkModeBlue1100":"outlineDarkModeBlue1100",className:(0,u.cn)("gap-0.5 whitespace-nowrap",{"font-bold":null===N}),children:[null===N&&(0,s.jsx)(d.In,{icon:"material-symbols:check",height:16,width:16}),(0,s.jsx)("span",{children:b("monitoring-observations:area.allSelected")})]})}),0===ec.length&&""!==O&&(0,s.jsx)("span",{className:"text-sm text-white",children:b("common:common.noResults")}),ec.map(e=>{var t;let a=(null==N?void 0:N.id)===e.id,i=null!=(t=e.name)?t:"Transect ".concat(e.id);return(0,s.jsx)(h.$,{variant:"unstyled",className:"group/transect !h-max shrink-0 p-0",onClick:()=>(e=>{if((null==N?void 0:N.id)===e.id)k(null);else{var t;k({id:e.id,name:null!=(t=e.name)?t:""})}I(null)})(e),children:(0,s.jsxs)(V.E,{size:"xs",rounded:"lg",variant:"outlineDarkModeBlue1100",className:(0,u.cn)("gap-0.5 whitespace-nowrap text-white transition-all",{"bg-dark-mode-blue-1100/30 font-bold":a}),children:[a&&(0,s.jsx)(d.In,{icon:"material-symbols:check",height:16,width:16}),(0,s.jsx)("span",{title:i,className:"max-w-40 overflow-hidden text-ellipsis capitalize transition-all duration-300 group-hover/transect:max-w-[500px]",children:i})]})},e.id)})]})}),"devices"===A&&(0,s.jsx)(s.Fragment,{children:eo?(0,s.jsx)(Y.A,{width:100,height:28,className:"rounded-lg"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.$,{variant:"unstyled",className:"!h-max shrink-0 p-0",onClick:()=>{I(null)},children:(0,s.jsxs)(V.E,{size:"xs",rounded:"lg",variant:null===S?"darkModeBlue1100":"outlineDarkModeBlue1100",className:(0,u.cn)("gap-0.5 whitespace-nowrap",{"font-bold":null===S}),children:[null===S&&(0,s.jsx)(d.In,{icon:"material-symbols:check",height:16,width:16}),(0,s.jsx)("span",{children:b("monitoring-observations:device.all")})]})}),0===em.length&&""!==P&&(0,s.jsx)("span",{className:"text-sm text-white",children:b("common:common.noResults")}),em.map(e=>{var t;let a=(null==S?void 0:S.id)===e.id,i=null!=(t=e.name)?t:"Device ".concat(e.id);return(0,s.jsx)(h.$,{variant:"unstyled",className:"group/device !h-max shrink-0 p-0",onClick:()=>(e=>{if((null==S?void 0:S.id)===e.id)I(null);else{var t;I({id:e.id,name:null!=(t=e.name)?t:""})}})(e),children:(0,s.jsxs)(V.E,{size:"xs",rounded:"lg",variant:"outlineDarkModeBlue1100",className:(0,u.cn)("gap-0.5 whitespace-nowrap text-white transition-all",{"bg-dark-mode-blue-1100/30 font-bold":a}),children:[a&&(0,s.jsx)(d.In,{icon:"material-symbols:check",height:16,width:16}),(0,s.jsx)("span",{title:i,className:"max-w-40 overflow-hidden text-ellipsis capitalize transition-all duration-300 group-hover/device:max-w-[500px]",children:i})]})},e.id)})]})}),"polygons"===A&&ed&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.$,{variant:"unstyled",className:"!h-max shrink-0 p-0",onClick:()=>{C([])},children:(0,s.jsxs)(V.E,{size:"xs",rounded:"lg",variant:0===_.length?"darkModeBlue1100":"outlineDarkModeBlue1100",className:(0,u.cn)("gap-0.5 whitespace-nowrap",{"font-bold":0===_.length}),children:[0===_.length&&(0,s.jsx)(d.In,{icon:"material-symbols:check",height:16,width:16}),(0,s.jsx)("span",{children:b("toolbar.roiSubpolygonSelector.allSelected")})]})}
1),null==ei||null==(x=ei.roi)||null==(o=x.features)?void 0:o.map(e=>{var t,a,i,n;let l=Number(null!=(n=null==(t=e.properties)?void 0:t.order)?n:0),r=String(l),o=_.some(e=>e.id===r),c=(null==(a=e.properties)?void 0:a.name)||"".concat(b("common.polygon_one")," ").concat(l),m=null==(i=e.properties)?void 0:i.color,x=Number(((0,si.A)(e)/1e4).toFixed(3));return H===r?(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[(0,s.jsx)("input",{ref:Q,type:"text",value:W,onChange:e=>$(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ee(l),"Escape"===e.key&&et()},className:"h-7 w-32 rounded-md border border-dark-mode-blue-500 bg-dark-mode-blue-300 px-2 text-xs text-white outline-none focus:border-emerald-400",disabled:K}),K?(0,s.jsx)(d.In,{icon:"eos-icons:three-dots-loading",width:20,height:20,className:"text-yellow-400"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.$,{variant:"unstyled",className:"!h-max !p-0.5",onClick:()=>ee(l),disabled:!W.trim(),children:(0,s.jsx)(d.In,{icon:"material-symbols:check",height:16,width:16,className:"text-emerald-400"})}),(0,s.jsx)(h.$,{variant:"unstyled",className:"!h-max !p-0.5",onClick:et,children:(0,s.jsx)(d.In,{icon:"material-symbols:close",height:16,width:16,className:"text-dark-mode-blue-900"})})]})]},r):(0,s.jsxs)("div",{className:"group/polygon flex shrink-0 items-center gap-1",children:[(0,s.jsx)(h.$,{variant:"unstyled",className:"!h-max shrink-0 p-0",onClick:()=>((e,t)=>{_.some(t=>t.id===e)?C(_.filter(t=>t.id!==e)):C([..._,{id:e,name:t}])})(r,c),children:(0,s.jsxs)(V.E,{size:"xs",rounded:"lg",variant:"outlineDarkModeBlue1100",className:(0,u.cn)("gap-0.5 whitespace-nowrap text-white transition-all",{"font-bold":o}),style:{borderColor:m,backgroundColor:o?"".concat(m,"40"):"transparent"},children:[o&&(0,s.jsx)(d.In,{icon:"material-symbols:check",height:16,width:16}),(0,s.jsx)("span",{className:"max-w-40 overflow-hidden text-ellipsis transition-all duration-300 group-hover/polygon:max-w-[500px]",children:c}),(0,s.jsxs)("span",{children:["⢠",x," ha"]})]})}),T&&(0,s.jsx)(h.$,{variant:"unstyled",className:"!h-max !p-0.5",onClick:t=>{var a,s;t.stopPropagation(),X(r,null!=(s=null==(a=e.properties)?void 0:a.name)?s:"")},children:(0,s.jsx)(d.In,{icon:"mdi:pencil-outline",height:14,width:14,className:"text-dark-mode-blue-900 transition-all hover:text-white"})})]},r)})]})]})]}),(0,s.jsx)("div",{className:"flex shrink-0 items-center justify-end px-4 pb-2 lg:px-5 lg:pb-0",children:(0,s.jsx)(sO,{})})]})}):(0,s.jsx)("div",{className:"sticky z-[123456] w-full border-b border-b-dark-mode-blue-300 bg-dark-mode-blue-200 text-white max-lg:top-0 lg:pb-1 lg:pt-0",style:{to
1p:null!=ea?ea:0},children:(0,s.jsx)("div",{className:"flex w-full justify-end px-4 pb-2 lg:mx-auto lg:px-5 lg:pb-0 lg:pt-0",children:(0,s.jsx)(sO,{})})})};var sP=a(68234),sU=a(4711);let sH=E()(()=>Promise.all([a.e(44693),a.e(79617)]).then(a.bind(a,79617)).then(e=>e.MobileDesktopOnlyPage),{loadableGenerated:{webpack:()=>[79617]},ssr:!0});var sq=!0;function sV(e){return(0,sU.a)(1024,e.isMobileSsr)?(0,s.jsx)(sH,{slug:e.slug}):(0,s.jsx)(sP.K,{pageProps:e,showCover:!1,parentLink:"monitoring",contentClassName:"gap-0",children:(0,s.jsxs)(L.BX,{children:[(0,s.jsx)(i.U,{}),(0,s.jsx)(a8,{}),(0,s.jsx)(st,{}),(0,s.jsxs)(a7,{children:[(0,s.jsx)(sB,{}),(0,s.jsx)(tw,{})]}),(0,s.jsx)(A,{})]})})}},85281:(e,t,a)=>{"use strict";a.d(t,{Z:()=>k});var s=a(83815),i=a(28229),n=a(24999),l=a(60938),r=a(45027),o=a(33635),d=a(24552),c=a(54002),m=a(99888),u=a(70679),x=a(94819),h=a(62476),g=a(68505),p=a(37482),b=a(99402),v=a(43052),f=a(88137),j=a(11549),y=a(69193);let w=e=>{var t;let{area:a,userSlug:i,siteId:n,plantationsPolygonsId:r,accessToken:o,isMutating:m,onRename:x,onDelete:h,onManageUsers:g}=e,{t:p}=(0,c.A)("monitoring"),w=(0,d.useSession)(),N=(0,y.W)({userSlug:i,siteId:n,plantationsPolygonsId:r,areaId:a.id,accessToken:null!=o?o:null==(t=w.data)?void 0:t.accessToken}),k=a.name&&""!==a.name?a.name:p("monitoring-observations:transectsOverview.untitled",{id:a.id}),[_,C]=(0,u.useState)(!1),[S,I]=(0,u.useState)(k),[A,z]=(0,u.useState)(!1),R=async()=>{let e=S.trim();if(""===e||e===k)return void C(!1);await x(a.id,e),C(!1)};return(0,s.jsxs)("div",{className:"flex flex-col gap-2 border-b border-dark-mode-blue-600(base) px-4 py-3 last:border-b-0 md:flex-row md:items-center md:gap-4",children:[(0,s.jsx)("div",{className:"flex min-w-[200px] flex-1 items-center gap-2",children:_?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(b.bL,{value:S,onChange:e=>I(e.target.value),autoFocus:!0,onKeyDown:e=>{"Enter"===e.key&&R(),"Escape"===e.key&&C(!1)},className:"h-8 flex-1"}),(0,s.jsx)(v.$,{variant:"monitoring-600(base)",size:"xs",onClick:R,disabled:m,children:p("common:save")}),(0,s.jsx)(v.$,{variant:"outline-monitoring-600(base)",size:"xs",onClick:()=>C(!1),disabled:m,children:p("common:cancel")})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"truncate text-sm font-semibold text-white",children:k}),(0,s.jsx)("button",{type:"button",title:p("monitoring-observations:transectsOverview.actions.rename"),onClick:()=>{I(k),C(!0)},disabled:m,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-dark-mode-blue-600(base) text-dark-mode-blue-1100 transition-colors hover:border-dark-mode-blue-1000 disabled:opacity-40",children:(0,s.jsx)(l.In,{icon:"material-symbols:edit-outline",width:14,height:14})})]})}),!_&&(0,s.jsx)("div",{className:"flex flex-1 items-center",children:(0,s.jsx)(j.X,{counts:N,size:"sm"})}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("button",{type:"button",title:p("monitoring-observations:map.biodiversaUsers.triggerLabel"),onClick:()=>g({tranceptId:a.id,tranceptName:k}),disabled:m,className:"flex h-8 items-center gap-1.5 rounded-md border border-dark-mode-blue-600(base) px-2.5 text-xs font-medium text-white transition-colors hover:border-dark-mode-blue-1000 disabled:opacity-40",children:[(0,s.jsx)(l.In,{icon:"mdi:account-group-outline",width:14,height:14}),p("monitoring-observations:transectsOverview.actions.users")]}),(0,s.jsx)(f.K,{open:A,onOpenChange:z,isLoading:m,title:p("monitoring-observations:transectsOverview.delete.title"),description:p("monitoring-observations:transectsOverview.delete.description",{name:k}),onConfirm:()=>h(a.id)}),(0,s.jsx)("button",{type:"button",title:p("monitoring-observations:transectsOverview.actions.delete"),onClick:()=>z(!0),disabled:m,className:"flex h-8 w-8 items-center justify-center rounded-md border border-state-colors-error-600(base)/40 text-state-colors-error-600(base) transition-colors hover:border-state-colors-error-600(base) disabled:opacity-40",children:(0,s.jsx)(l.In,{icon:"material-symbols:delete-outline",width:16,height:16})})]})]})},N=e=>({id:e.id,name:e.name,polygon:e.polygon}),k=e=>{var t,a;let{open:b,onOpenChange:v}=e,{t:f}=(0,c.A)("monitoring"),{query:j}=(0,m.useRouter)(),y=j.slug,k=Number(j.id),_=null==(t=(0,d.useSession)().data)?void 0:t.accessToken,C=_?{authorization:"Bearer ".concat(_)}:void 0,{polygonVersion:S}=(0,i._R)(),{canEditSite:I}=(0,n.A)(),A=(0,r.jE)(),{toast:z}=x.dj(),R=null!=(a=null==S?void 0:S.id)?a:0,[D,M]=(0,u.useState)(null),{data:T=[],isLoading:E,refetch:L}=(0,o.Aex)(y,k,R,C,{query:{enabled:b&&!!R&&!!_,retry:!1}}),{mutateAsync:F,isLoading:O}=(0,o.PX1)(),B=()=>
1{A.invalidateQueries((0,o.YtF)(y,k,R)),L()},P=async(e,t)=>{var a;let s=(null!=(a=(await L()).data)?a:T).map(a=>a.id===e?{...N(a),name:t}:N(a));try{await F({userSlug:y,siteId:k,plantationsPolygonsId:R,data:s,headers:C}),z({variant:"success",description:f("monitoring-observations:map.areasSuccess")}),B()}catch(e){z({variant:"error",description:f("monitoring-observations:map.areasError")})}},U=async e=>{var t;let a=(null!=(t=(await L()).data)?t:T).filter(t=>t.id!==e).map(N);try{await F({userSlug:y,siteId:k,plantationsPolygonsId:R,data:a,headers:C}),z({variant:"success",description:f("monitoring-observations:transectsOverview.delete.success")}),B()}catch(e){z({variant:"error",description:f("monitoring-observations:map.areasError")})}};return I?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.Root,{open:b,onOpenChange:v,children:(0,s.jsxs)(h.DialogContent,{variant:"dark-mode-blue-1000",className:"w-[95vw] max-w-[760px] !gap-0 p-0",children:[(0,s.jsxs)(h.DialogHeader,{className:"flex flex-row items-center justify-between gap-3 border-b border-dark-mode-blue-600(base) p-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,s.jsx)(h.DialogTitle,{children:f("monitoring-observations:transectsOverview.manage.title")}),(0,s.jsx)(h.DialogDescription,{className:"text-xs text-dark-mode-blue-1000",children:f("monitoring-observations:transectsOverview.manage.subtitle")})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(g.X,{label:f("monitoring-observations:transectsOverview.drawNew")}),(0,s.jsx)(h.DialogClose,{asChild:!0,children:(0,s.jsx)(l.In,{icon:"material-symbols:close",width:24,height:24,className:"cursor-pointer"})})]})]}),(0,s.jsx)("div",{className:"flex max-h-[60vh] flex-col overflow-y-auto",children:E?(0,s.jsx)("div",{className:"flex items-center justify-center p-8",children:(0,s.jsx)(l.In,{icon:"eos-icons:three-dots-loading",width:48,height:48,className:"text-dark-mode-monitoring-600(base)"})}):0===T.length?(0,s.jsx)("p",{className:"p-8 text-center text-sm text-dark-mode-blue-1000",children:f("monitoring-observations:transectsOverview.empty")}):T.map(e=>(0,s.jsx)(w,{area:e,userSlug:y,siteId:k,plantationsPolygonsId:R,accessToken:_,isMutating:O,onRename:P,onDelete:U,onManageUsers:M},e.id))})]})}),(0,s.jsx)(p.h,{trancept:null!=D?D:{tranceptId:0,tranceptName:""},open:!!D,onOpenChange:e=>{e||M(null)}})]}):null}},85973:(e,t,a)=>{"use strict";a.d(t,{b:()=>s});let s=e=>{let t=Date.now(),a=!e.adoption_starting_at||new Date(e.adoption_starting_at).getTime()<=t,s=!e.adoption_ending_at||new Date(e.adoption_ending_at).getTime()>t;return a&&s}},88137:(e,t,a)=>{"use strict";a.d(t,{K:()=>d});var s=a(83815),i=a(60938),n=a(54002),l=a(70679),r=a(62476),o=a(43052);let d=e=>{let{onConfirm:t,isLoading:a=!1,title:d,description:c,trigger:m,open:u,onOpenChange:x}=e,{t:h}=(0,n.A)("monitoring"),[g,p]=(0,l.useState)(!1),b=void 0!==u&&void 0!==x,v=b?x:p,f=async()=>{try{await t(),v(!1)}catch(e){}};return(0,s.jsxs)(r.Root,{open:b?u:g,onOpenChange:e=>{(e||!a)&&v(e)},children:[m&&(0,s.jsx)(r.DialogTrigger,{asChild:!0,children:m}),(0,s.jsxs)(r.DialogContent,{"aria-busy":a,variant:"state-colors-error-600(base)",className:"min-w-[300px] !gap-3 md:min-w-[500px]",children:[(0,s.jsxs)(r.DialogHeader,{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)(r.DialogTitle,{children:d}),(0,s.jsx)(r.DialogClose,{asChild:!0,disabled:a,children:(0,s.jsx)(i.In,{icon:"material-symbols:close",width:24,height:24,className:"cursor-pointer"})})]}),(0,s.jsx)(r.DialogDescription,{children:c}),(0,s.jsxs)(r.DialogFooter,{className:"flex justify-end",children:[(0,s.jsx)(o.$,{variant:"outline-error-600(base)",onClick:()=>v(!1),size:"xs",disabled:a,children:h("common:cancel")}),(0,s.jsxs)(o.$,{variant:"error-600(base)",onClick:f,size:"xs",disabled:a,children:[h("common:common.delete"),a&&(0,s.jsx)(i.In,{icon:"eos-icons:three-dots-loading",width:48,height:48,color:"#3c3300"})]})]})]})]})}},92502:(e,t,a)=>{"use strict";a.d(t,{I:()=>c});var s=a(83815),i=a(60938),n=a(54002),l=a(70679),r=a(99402),o=a(95001),d=a(43052);let c=e=>{var t;let{children:a,onChange:i,onDelete:n,items:d,onClickResult:c,value:u,variant:x,className:h,showResults:g=!0,isLoading:p=!1,containerClassName:b,iconClassName:v,...f}=e,[j,y]=(0,l.useState)([]),w=(0,l.useCallback)(e=>{let t=e.target.value;y(d.filter(e=>{var a;return e.id.toString().includes(t.toLowerCase())||e.name.toLowerCase().includes(t.toLowerCase())||!!e.polygon_name&&(null==(a=e.polygon_name)?void 0:a.toLowerCase().includes(t.toLowerCase()))})),""===e.target.value&&y([]),null==i||i(e)},[d,i]),N=(0,l.useCallback)(e=>{y([]),c(e)},[c]);return(0,s.jsxs)(r.bL,{variant:"blurred",type:"search",value:u,...f,onChange:w,className:(0,o.cn)("h-14 text-[20px]",{"text-3bee-black placeholder:text-3bee-black/60":"light"===x,"bg-regeneration-600 focus:ring-regeneration-600":"green"===x,"bg-dark-mode-blue-300":"dark"===x,"border border-light-mode-black-200 bg-white text-3bee-black placeholder:text-light-mode-black-400 focus:ring-dark-mode-blue-400":"white"===x,"border border-dark-mode-blue-500 bg-dark-mode-blue-200 text-white placeholder:text-light-mode-black-400 focus:ring-dark-mode-blue-400":"outline-dark-mode-blue-500"===x},h),containerClassName:b,children:[g&&(0,s.jsx)(m,{items:j,onClick:N,variant:x,isLoading:p},null==(t=j[0])?void 0:t.id),(0,s.jsx)(r.In,{variant:"blurred",icon:u&&n?"ci:close-md":"ci:search-magnifying-glass",className:(0,o.cn)("right-2.5 h-6 w-6",{"curs
1or-pointer":u&&n,"text-3bee-black":"light"===x,"text-light-mode-black-400":"white"===x||"outline-dark-mode-blue-500"===x},v),onClick:u?n:void 0})]})},m=e=>{let{items:t,onClick:a,variant:l,isLoading:r}=e,{t:c}=(0,n.A)("common");return t.length?(0,s.jsx)("div",{className:"absolute top-full z-[9999] mt-3 animate-fade-in-out-30 overflow-hidden rounded-2xl bg-[rgba(10,37,51,0.40)] backdrop-blur-md duration-100",children:(0,s.jsxs)("ul",{className:(0,o.cn)("flex max-h-64 min-w-[300px] flex-col gap-3 overflow-y-scroll p-5",{"custom-scrollbar-dark-mode-blue-300 bg-dark-mode-blue-300 backdrop-blur-none":"dark"===l,"custom-scrollbar-dark-mode-regeneration-200":"green"===l,"scrollbar-hide":"blurred"===l}),children:[r&&(0,s.jsxs)("li",{className:"flex flex-row items-center gap-1.5 p-2 text-white",children:[(0,s.jsx)(i.In,{icon:"eos-icons:three-dots-loading",width:24,height:24,color:"#F5D000"}),c("common:loading")]}),t.sort((e,t)=>e.name<t.name?-1:1).map(e=>(0,s.jsx)(d.$,{asChild:!0,type:"button",className:"font-md justify-start text-base font-medium !text-white hover:!bg-orange-500/10 hover:!text-orange-500",onClick:()=>a(e),variant:"textOnly",children:(0,s.jsx)("li",{children:e.name})},e.id))]})}):null}}},e=>{e.O(0,[83057,24624,82683,96939,29411,54569,87317,74717,63323,57052,45717,45880,81050,78746,90336,66064,73857,26342,54978,74305,74639,97814,57472,21377,137,25640,73229,14189,84193,48753,52971,45490,78386,49369,60952,71444,26675,33635,53329,28534,20426,45465,80261,37302,61906,59828,56529,16284,18746,1248,75534,65473,83616,13312,21351,90636,46593,38792],()=>e(e.s=61614)),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.