/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.cases_bundle_jsonpfunction=window.cases_bundle_jsonpfunction||[]).push([[19],{319:function(e,t,a){var i,l=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,n={};((e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:!0})})(n,{ValidationError:()=>m,decode:()=>M,encode:()=>y,isBlurhashValid:()=>g}),e.exports=(i=n,((e,t,a,i)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let a of s(t))!r.call(e,a)&&undefined!==a&&l(e,a,{get:()=>t[a],enumerable:!(i=o(t,a))||i.enumerable});return e})(l({},"__esModule",{value:!0}),i));var d=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],u=e=>{let t=0;for(let a=0;a{var a="";for(let i=1;i<=t;i++){let l=Math.floor(e)/Math.pow(83,t-i)%83;a+=d[Math.floor(l)]}return a},h=e=>{let t=e/255;return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},p=e=>{let t=Math.max(0,Math.min(1,e));return t<=.0031308?Math.trunc(12.92*t*255+.5):Math.trunc(255*(1.055*Math.pow(t,.4166666666666667)-.055)+.5)},f=(e,t)=>(e=>e<0?-1:1)(e)*Math.pow(Math.abs(e),t),m=class extends Error{constructor(e){super(e),this.name="ValidationError",this.message=e}},b=e=>{if(!e||e.length<6)throw new m("The blurhash string must be at least 6 characters");let t=u(e[0]),a=Math.floor(t/9)+1,i=t%9+1;if(e.length!==4+2*i*a)throw new m(`blurhash length mismatch: length is ${e.length} but it should be ${4+2*i*a}`)},g=e=>{try{b(e)}catch(e){return{result:!1,errorReason:e.message}}return{result:!0}},w=e=>{let t=e>>8&255,a=255&e;return[h(e>>16),h(t),h(a)]},j=(e,t)=>{let a=Math.floor(e/361),i=Math.floor(e/19)%19,l=e%19;return[f((a-9)/9,2)*t,f((i-9)/9,2)*t,f((l-9)/9,2)*t]},M=(e,t,a,i)=>{b(e),i|=1;let l=u(e[0]),o=Math.floor(l/9)+1,s=l%9+1,r=(u(e[1])+1)/166,n=new Array(s*o);for(let t=0;t{let l=0,o=0,s=0,r=4*t;for(let n=0;n{if(i<1||i>9||l<1||l>9)throw new m("BlurHash must have between 1 and 9 components");if(t*a*4!==e.length)throw new m("Width and height must match the pixels array");let o=[];for(let s=0;si*Math.cos(Math.PI*l*e/t)*Math.cos(Math.PI*s*o/a)));o.push(r)}let s,r=o[0],n=o.slice(1),d="";if(d+=c(i-1+9*(l-1),1),n.length>0){let e=Math.max(...n.map((e=>Math.max(...e)))),t=Math.floor(Math.max(0,Math.min(82,Math.floor(166*e-.5))));s=(t+1)/166,d+=c(t,1)}else s=1,d+=c(0,1);return d+=c((e=>(p(e[0])<<16)+(p(e[1])<<8)+p(e[2]))(r),4),n.forEach((e=>{d+=c(((e,t)=>19*Math.floor(Math.max(0,Math.min(18,Math.floor(9*f(e[0]/t,.5)+9.5))))*19+19*Math.floor(Math.max(0,Math.min(18,Math.floor(9*f(e[1]/t,.5)+9.5))))+Math.floor(Math.max(0,Math.min(18,Math.floor(9*f(e[2]/t,.5)+9.5)))))(e,s),2)})),d}},332:function(e,t,a){"use strict";a.r(t),a.d(t,"FileUpload",(function(){return F}));var i=a(2),l=a.n(i),o=a(80),s=a(15),r=a(135),n=a(319);const d={width:120,height:120};async function u(e){const t=window.URL.createObjectURL(e);try{const e=await(a=t,new Promise(((e,t)=>{const i=new window.Image;i.src=a,i.onload=()=>e(i),i.onerror=t}))),i=document.createElement("canvas"),{width:l,height:o}=function(e,t){const a=Math.abs(Math.min(Math.min(d.width/e,d.height/t),1)-1);return{width:Math.floor(e-a*e),height:Math.floor(t-a*t)}}(e.width,e.height);i.width=l,i.height=o;const s=i.getContext("2d");if(!s)throw new Error("Could not get 2d canvas context!");s.drawImage(e,0,0,l,o);const r=s.getImageData(0,0,l,o);return{blurhash:n.encode(r.data,r.width,r.height,4,4),width:e.width,height:e.height}}catch(e){return}finally{window.URL.revokeObjectURL(t)}var a}var c=a(55),h=a.n(c);function p(e){return h()(e,e.getValue())}var f=a(11),m=a(1);const b={defaultPickerLabel:m.i18n.translate("sharedUXPackages.fileUpload.defaultFilePickerLabel",{defaultMessage:"Upload a file"}),upload:m.i18n.translate("sharedUXPackages.fileUpload.uploadButtonLabel",{defaultMessage:"Upload"}),uploading:m.i18n.translate("sharedUXPackages.fileUpload.uploadingButtonLabel",{defaultMessage:"Uploading"}),uploadComplete:m.i18n.translate("sharedUXPackages.fileUpload.uploadCompleteButtonLabel",{defaultMessage:"Upload complete"}),retry:m.i18n.translate("sharedUXPackages.fileUpload.retryButtonLabel",{defaultMessage:"Retry"}),clear:m.i18n.translate("sharedUXPackages.fileUpload.clearButtonLabel",{defaultMessage:"Clear"}),cancel:m.i18n.translate("sharedUXPackages.fileUpload.cancelButtonLabel",{defaultMessage:"Cancel"}),uploadDone:m.i18n.translate("sharedUXPackages.fileUpload.uploadDoneToolTipContent",{defaultMessage:"Your file was successfully uploaded!"}),fileTooLarge:e=>m.i18n.translate("sharedUXPackages.fileUpload.fileTooLargeErrorMessage",{defaultMessage:"File is too large. Maximum size is {expectedSize, plural, one {# byte} other {# bytes} }.",values:{expectedSize:e}}),mimeTypeNotSupported:(e,t)=>m.i18n.translate("sharedUXPackages.fileUpload.mimeTypeNotSupportedErrorMessage",{defaultMessage:'File mime type "{mimeType}" is not supported. Supported mime types are: {supportedMimeTypes}.',values:{mimeType:e,supportedMimeTypes:t}})},g=l.a.createContext(null),w=()=>l.a.useContext(g),j=({onClick:e})=>{const t=w(),a=p(t.uploading$),i=p(t.error$),l=h()(t.done$),o=h()(t.files$,[]);return Object(f.jsx)(s.EuiButton,{key:"uploadButton",isLoading:a,color:l?"success":"primary",iconType:l?"checkInCircleFilled":void 0,disabled:Boolean(!o.length||i||l),onClick:e,size:"s","data-test-subj":"uploadButton"},l?b.uploadComplete:a?b.uploading:b.upload)},M=({onClick:e})=>{const t=p(w().uploading$);return Object(f.jsx)(s.EuiButton,{key:"retryButton",size:"s","data-test-subj":"retryButton",disabled:t,onClick:e},b.retry)},x=({onClick:e,compressed:t})=>{const a=!p(w().uploading$);return t?Object(f.jsx)(s.EuiButtonIcon,{color:"danger","data-test-subj":"cancelButtonIcon",disabled:a,iconType:"cross","aria-label":b.cancel,onClick:e}):Object(f.jsx)(s.EuiButton,{key:"cancelButton",size:"s","data-test-subj":"cancelButton",disabled:a,onClick:e,color:"danger"},b.cancel)},y=({onCancel:e,onUpload:t,immediate:a,compressed:i})=>{const l=w(),o=p(l.uploading$),s=h()(l.files$,[]),r=Boolean(s.some((e=>"upload_failed"===e.status)));return i||o?Object(f.jsx)(x,{compressed:i,onClick:e}):r?Object(f.jsx)(M,{onClick:t}):a?null:Object(f.jsx)(j,{onClick:t})},v=({onClick:e})=>Object(f.jsx)(s.EuiButtonEmpty,{size:"s","data-test-subj":"clearButton",onClick:e,color:"primary"},b.clear),{euiFormMaxWidth:O,euiButtonHeightSmall:U}=r.euiThemeVars,$={horizontalContainer:{name:"ho1qnd",styles:"display:flex;flex-direction:row"},fullWidth:{name:"1d3w5wq",styles:"width:100%"}},S=l.a.forwardRef((({compressed:e,meta:t,accept:a,immediate:i,allowClear:o=!1,multiple:r,initialFilePromptText:n,fullWidth:d,className:u},c)=>{const{euiTheme:m}=Object(s.useEuiTheme)(),g=w(),j=p(g.uploading$),M=p(g.error$),x=h()(g.done$),S=Boolean(M),k=null==M?void 0:M.message,B=Object(s.useGeneratedHtmlId)({prefix:"filesFileUpload"}),C=`${B}_error`;return Object(f.jsx)("div",{"data-test-subj":"filesFileUpload",css:[Object(f.css)("max-width:",d?"100%":O,";",""),d?$.fullWidth:void 0,e?$.horizontalContainer:void 0,"",""],className:u},Object(f.jsx)(s.EuiFilePicker,{fullWidth:d,"aria-label":b.defaultPickerLabel,id:B,ref:c,onChange:e=>{g.setFiles(Array.from(null!=e?e:[])),i&&g.hasFiles()&&g.upload(t)},multiple:r,initialPromptText:n,isLoading:j,isInvalid:S,accept:a,disabled:Boolean((null==x?void 0:x.length)||j),"aria-describedby":k?C:void 0,display:e?"default":"large"}),Object(f.jsx)(s.EuiSpacer,{size:"s",css:e?Object(f.css)("width:",m.size.s,";",""):void 0}),Object(f.jsx)(s.EuiFlexGroup,{justifyContent:"flexStart",alignItems:e?"center":"flexStart",direction:e?void 0:"rowReverse",gutterSize:e?"none":"m",responsive:!1},Object(f.jsx)(s.EuiFlexItem,{grow:!1},Object(f.jsx)(y,{compressed:e,immediate:i,onCancel:g.abort,onUpload:()=>g.upload(t)})),!e&&Boolean(!x&&!j&&k)&&Object(f.jsx)(s.EuiFlexItem,null,Object(f.jsx)(s.EuiText,{"data-test-subj":"error",css:Object(f.css)("display:flex;align-items:center;min-height:",U,";",""),size:"s",color:"danger"},Object(f.jsx)("span",{id:C},k))),!e&&(null==x?void 0:x.length)&&o&&Object(f.jsx)(l.a.Fragment,null,Object(f.jsx)(s.EuiFlexItem,null)," ",Object(f.jsx)(s.EuiFlexItem,{grow:!1},Object(f.jsx)(v,{onClick:g.clear})))))}));var k=a(23),B=a.n(k),C=a(87),E=a(12);class simple_state_subject_SimpleStateSubject extends C.BehaviorSubject{constructor(e){super(e)}getSnapshot(){return this.getValue()}setState(e){this.next(Object(E.merge)({},this.getSnapshot(),e))}}class upload_state_UploadState{constructor(e,t,a={allowRepeatedUploads:!1},i=u){B()(this,"abort$",new C.Subject),B()(this,"files$$",new C.BehaviorSubject([])),B()(this,"files$",this.files$$.pipe(C.switchMap((e=>e.length?C.zip(...e):C.of([]))))),B()(this,"clear$",new C.Subject),B()(this,"error$",new C.BehaviorSubject(void 0)),B()(this,"uploading$",new C.BehaviorSubject(!1)),B()(this,"done$",new C.Subject),B()(this,"subscriptions",void 0),B()(this,"validateFile",(e=>{const t=this.fileKind;if(null!=t.maxSizeBytes&&e.size>this.fileKind.maxSizeBytes){const e=b.fileTooLarge(String(this.fileKind.maxSizeBytes));throw new Error(e)}if(null!=t.allowedMimeTypes&&!t.allowedMimeTypes.includes(e.type)){const a=b.mimeTypeNotSupported(e.type,t.allowedMimeTypes.join(", "));throw new Error(a)}})),B()(this,"setFiles",(e=>{if(this.isUploading())throw new Error("Cannot update files while uploading");let t;e.length||(this.done$.next(void 0),this.error$.next(void 0));try{e.forEach(this.validateFile)}catch(e){t=e}this.files$$.next(e.map((e=>new simple_state_subject_SimpleStateSubject({file:e,status:"idle",error:t}))))})),B()(this,"abort",(()=>{if(!this.isUploading())throw new Error("No upload in progress");this.abort$.next()})),B()(this,"clear",(()=>{this.setFiles([]),this.clear$.next()})),B()(this,"uploadFile",((e,t,a)=>{const i=new AbortController,l=i.signal,{file:o,status:s}=e.getValue();if(!["idle","upload_failed"].includes(s))return C.of(void 0);let r;e.setState({status:"uploading",error:void 0});const{name:n}={name:((d=o.name).substring(0,d.lastIndexOf("."))||d).trim().slice(0,256).replace(/[^a-z0-9\s]/gi,"_")};var d;const u=o.type||void 0,c=a;return C.from(function(e){var t;return Boolean(null===(t=e.type)||void 0===t?void 0:t.startsWith("image/"))}(o)?this.loadImageMetadata(o):C.of(void 0)).pipe(C.mergeMap((e=>this.client.create({kind:this.fileKind.id,name:n,mimeType:u,meta:e?{...e,...c}:c}))),C.mergeMap((e=>(r=e.file,C.race(t.pipe(C.map((()=>{throw i.abort(),new Error("Abort!")}))),this.client.upload({body:o,id:r.id,kind:this.fileKind.id,abortSignal:l,selfDestructOnAbort:!0,contentType:u}))))),C.map((()=>{var t;e.setState({status:"uploaded",id:null===(t=r)||void 0===t?void 0:t.id,fileJSON:r})})),C.catchError((t=>{const a="Abort!"===t.message;return e.setState({status:"upload_failed",error:a?void 0:t}),C.of(a?void 0:t)})))})),B()(this,"upload",(e=>{if(this.isUploading())throw new Error("Upload already in progress");const t=new C.ReplaySubject(1),a=this.abort$.subscribe(t),i=this.files$$.pipe(C.take(1),C.switchMap((a=>C.forkJoin(a.map((a=>this.uploadFile(a,t,e)))))),C.map((()=>{})),C.finalize((()=>{this.opts.allowRepeatedUploads&&this.clear(),a.unsubscribe()})),C.shareReplay());return i.subscribe(),i})),B()(this,"dispose",(()=>{for(const e of this.subscriptions)e.unsubscribe()})),this.fileKind=e,this.client=t,this.opts=a,this.loadImageMetadata=i;const l=this.files$$.pipe(C.switchMap((e=>C.combineLatest(e))));this.subscriptions=[l.pipe(C.map((e=>e.some((e=>"uploading"===e.status)))),C.distinctUntilChanged()).subscribe(this.uploading$),l.pipe(C.map((e=>{const t=e.find((e=>Boolean(e.error)));return t?t.error:void 0})),C.filter(Boolean)).subscribe(this.error$),l.pipe(C.filter((e=>Boolean(e.length)&&e.every((e=>"uploaded"===e.status)))),C.map((e=>e.map((e=>({id:e.id,kind:this.fileKind.id,fileJSON:e.fileJSON})))))).subscribe(this.done$)]}isUploading(){return this.uploading$.getValue()}hasFiles(){return this.files$$.getValue().length>0}}const F=({meta:e,onDone:t,onError:a,fullWidth:l,allowClear:s,onUploadEnd:r,onUploadStart:n,compressed:d=!1,kind:u,multiple:c=!1,initialPromptText:h,immediate:p=!1,allowRepeatedUploads:m=!1,className:b})=>{var w;const{client:j}=Object(o.b)(),M=Object(i.useRef)(null),x=j.getFileKind(u),y=d||m,v=Object(i.useMemo)((()=>(({fileKind:e,client:t,imageMetadataFactory:a,...i})=>new upload_state_UploadState(e,t,i,a))({client:j,fileKind:x,allowRepeatedUploads:y})),[j,y,x]);return Object(i.useEffect)((()=>{const e=[v.clear$.subscribe((()=>{var e;null===(e=M.current)||void 0===e||e.removeFiles()})),v.done$.subscribe((e=>e&&t(e))),v.error$.subscribe((e=>e&&(null==a?void 0:a(e)))),v.uploading$.subscribe((e=>e?null==n?void 0:n():null==r?void 0:r()))];return()=>e.forEach((e=>e.unsubscribe()))}),[v,t,a,n,r]),Object(i.useEffect)((()=>v.dispose),[v]),Object(f.jsx)(g.Provider,{value:v},Object(f.jsx)(S,{compressed:d,ref:M,accept:null===(w=x.allowedMimeTypes)||void 0===w?void 0:w.join(","),meta:e,immediate:d||p,allowClear:s,fullWidth:l,initialFilePromptText:h,multiple:c,className:b}))};t.default=F}}]);