image-salon-sdk 1.0.71 → 1.0.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6184,14 +6184,15 @@ const qs = async (s, e, t = !0) => {
6184
6184
  var a;
6185
6185
  const r = (a = window.ImageSalonSDK) == null ? void 0 : a.grpcConfig, i = new Yr(r), o = kn.create();
6186
6186
  try {
6187
- o.mimeType = s;
6188
- const c = t;
6189
- return await i.uploadUserImage(o, {
6190
- meta: {
6191
- Authorization: e,
6192
- "app-id": n === "production" ? "hamropatro" : "hamropatro-android"
6187
+ return o.mimeType = s, await i.uploadUserImage(
6188
+ o,
6189
+ {
6190
+ meta: {
6191
+ Authorization: e,
6192
+ "app-id": n === "production" ? "hamropatro" : "hamropatro-android"
6193
+ }
6193
6194
  }
6194
- }), c;
6195
+ );
6195
6196
  } catch (c) {
6196
6197
  throw c;
6197
6198
  }
@@ -6224,22 +6225,19 @@ const qs = async (s, e, t = !0) => {
6224
6225
  t,
6225
6226
  n,
6226
6227
  r
6227
- );
6228
- console.log("upload response", a);
6229
- const c = (i = a.response) == null ? void 0 : i.uploadUrl, d = (o = a == null ? void 0 : a.response) == null ? void 0 : o.accessUrl;
6228
+ ), c = (i = a.response) == null ? void 0 : i.uploadUrl, d = (o = a == null ? void 0 : a.response) == null ? void 0 : o.accessUrl;
6230
6229
  return await ei(s, c, e), d;
6231
6230
  } catch (a) {
6232
6231
  throw a;
6233
6232
  }
6234
6233
  }, zs = (s, e) => {
6235
6234
  const t = e.type.split("/")[0];
6236
- console.log("file type", t), console.log("base 64 image", s);
6237
6235
  let n = "";
6238
- t === "video" ? n = s == null ? void 0 : s.replace(/^data:video\/\w+;base64,/, "") : t === "image" ? n = s == null ? void 0 : s.replace(/^data:image\/\w+;base64,/, "") : t === "audio" && (n = s == null ? void 0 : s.replace(/^data:audio\/\w+;base64,/, "")), console.log("base 64 string", n);
6236
+ t === "video" ? n = s == null ? void 0 : s.replace(/^data:video\/\w+;base64,/, "") : t === "image" ? n = s == null ? void 0 : s.replace(/^data:image\/\w+;base64,/, "") : t === "audio" && (n = s == null ? void 0 : s.replace(/^data:audio\/\w+;base64,/, ""));
6239
6237
  const r = atob(n), i = new Uint8Array(r.length);
6240
6238
  for (let o = 0; o < r.length; o++)
6241
6239
  i[o] = r.charCodeAt(o);
6242
- return console.log("buffer", i), i;
6240
+ return i;
6243
6241
  };
6244
6242
  async function vr(s) {
6245
6243
  const e = {
@@ -7260,7 +7258,9 @@ class Gs {
7260
7258
  const r = e.size > n ? await vr(e) : e;
7261
7259
  return await new Promise((o, a) => {
7262
7260
  const c = new FileReader();
7263
- console.log("base 64", c.result), c.onload = async () => {
7261
+ c.readAsDataURL(r), c.onerror = () => {
7262
+ a(c.error);
7263
+ }, c.onload = async () => {
7264
7264
  var d;
7265
7265
  try {
7266
7266
  const l = await Ks(
@@ -7279,12 +7279,10 @@ class Gs {
7279
7279
  } catch (l) {
7280
7280
  a(l);
7281
7281
  }
7282
- }, c.onerror = () => {
7283
- a(c.error), console.log("error", c.error);
7284
- }, c.readAsDataURL(r);
7282
+ };
7285
7283
  });
7286
7284
  } catch (r) {
7287
- throw console.log("error", r), r;
7285
+ throw r;
7288
7286
  }
7289
7287
  }
7290
7288
  _uploadingState() {
@@ -21,7 +21,7 @@ self.addEventListener('message', async (e) => {
21
21
  self.postMessage({ error: e.message + '\\n' + e.stack, id })
22
22
  }
23
23
  })
24
- `;let Gn;function Hs(s,e){return new Promise((t,r)=>{Gn||(Gn=function(o){const a=[];return a.push(o),URL.createObjectURL(new Blob(a))}(Vs));const n=new Worker(Gn);n.addEventListener("message",function(o){if(e.signal&&e.signal.aborted)n.terminate();else if(o.data.progress===void 0){if(o.data.error)return r(new Error(o.data.error)),void n.terminate();t(o.data.file),n.terminate()}else e.onProgress(o.data.progress)}),n.addEventListener("error",r),e.signal&&e.signal.addEventListener("abort",()=>{r(e.signal.reason),n.terminate()}),n.postMessage({file:s,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})})}function Oe(s,e){return new Promise(function(t,r){let n,i,o,a,c,d;if(n={...e},o=0,{onProgress:a}=n,n.maxSizeMB=n.maxSizeMB||Number.POSITIVE_INFINITY,c=typeof n.useWebWorker!="boolean"||n.useWebWorker,delete n.useWebWorker,n.onProgress=f=>{o=f,typeof a=="function"&&a(o)},!(s instanceof Blob||s instanceof Ms))return r(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(s.type))return r(new Error("The file given is not an image"));if(d=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,!c||typeof Worker!="function"||d)return Kr(s,n).then((function(f){try{return i=f,h.call(this)}catch(y){return r(y)}}).bind(this),r);var l=(function(){try{return h.call(this)}catch(f){return r(f)}}).bind(this),u=function(f){try{return Kr(s,n).then(function(y){try{return i=y,l()}catch(k){return r(k)}},r)}catch(y){return r(y)}};try{return n.libURL=n.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",Hs(s,n).then(function(f){try{return i=f,l()}catch{return u()}},u)}catch{u()}function h(){try{i.name=s.name,i.lastModified=s.lastModified}catch{}try{n.preserveExif&&s.type==="image/jpeg"&&(!n.fileType||n.fileType&&n.fileType===s.type)&&(i=Rr(s,i))}catch{}return t(i)}})}Oe.getDataUrlFromFile=Hr,Oe.getFilefromDataUrl=Xn,Oe.loadImage=$r,Oe.drawImageInCanvas=Wr,Oe.drawFileInCanvas=In,Oe.canvasToFile=Tn,Oe.getExifOrientation=jr,Oe.handleMaxWidthOrHeight=qr,Oe.followExifOrientation=Zr,Oe.cleanupCanvasMemory=st,Oe.isAutoOrientationInBrowser=$t,Oe.approximateBelowMaximumCanvasSizeOfBrowser=Pr,Oe.copyExifWithoutOrientation=Rr,Oe.getBrowserName=Rt,Oe.version="2.0.2";class $s extends Te{constructor(){super("com.hamropatro.grpc.common.ImageUploadRequest",[{no:1,name:"mime_type",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.mimeType="",e!==void 0&&Ee(this,t,e),t}internalBinaryRead(e,t,r,n){let i=n??this.create(),o=e.pos+t;for(;e.pos<o;){let[a,c]=e.tag();switch(a){case 1:i.mimeType=e.string();break;default:let d=r.readUnknownField;if(d==="throw")throw new globalThis.Error(`Unknown field ${a} (wire type ${c}) for ${this.typeName}`);let l=e.skip(c);d!==!1&&(d===!0?G.onRead:d)(this.typeName,i,a,c,l)}}return i}internalBinaryWrite(e,t,r){e.mimeType!==""&&t.tag(1,j.LengthDelimited).string(e.mimeType);let n=r.writeUnknownFields;return n!==!1&&(n==!0?G.onWrite:n)(this.typeName,e,t),t}}const Ln=new $s;class Ps extends Te{constructor(){super("com.hamropatro.grpc.common.ImageUploadResponse",[{no:1,name:"key",kind:"scalar",T:9},{no:2,name:"uploadUrl",kind:"scalar",T:9},{no:3,name:"access_url",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.key="",t.uploadUrl="",t.accessUrl="",e!==void 0&&Ee(this,t,e),t}internalBinaryRead(e,t,r,n){let i=n??this.create(),o=e.pos+t;for(;e.pos<o;){let[a,c]=e.tag();switch(a){case 1:i.key=e.string();break;case 2:i.uploadUrl=e.string();break;case 3:i.accessUrl=e.string();break;default:let d=r.readUnknownField;if(d==="throw")throw new globalThis.Error(`Unknown field ${a} (wire type ${c}) for ${this.typeName}`);let l=e.skip(c);d!==!1&&(d===!0?G.onRead:d)(this.typeName,i,a,c,l)}}return i}internalBinaryWrite(e,t,r){e.key!==""&&t.tag(1,j.LengthDelimited).string(e.key),e.uploadUrl!==""&&t.tag(2,j.LengthDelimited).string(e.uploadUrl),e.accessUrl!==""&&t.tag(3,j.LengthDelimited).string(e.accessUrl);let n=r.writeUnknownFields;return n!==!1&&(n==!0?G.onWrite:n)(this.typeName,e,t),t}}const zr=new Ps,Jn=new Dn("com.hamropatro.grpc.common.ImageUploadService",[{name:"Upload",options:{},I:Ln,O:zr},{name:"UploadUserImage",options:{},I:Ln,O:zr}]);class Xr{constructor(e){pe(this,"typeName",Jn.typeName);pe(this,"methods",Jn.methods);pe(this,"options",Jn.options);this._transport=e}upload(e,t){const r=this.methods[0],n=this._transport.mergeOptions(t);return Pe("unary",this._transport,r,n,e)}uploadUserImage(e,t){const r=this.methods[1],n=this._transport.mergeOptions(t);return Pe("unary",this._transport,r,n,e)}}const Ws=async(s,e,t=!0)=>{var o;const r=(o=window.ImageSalonSDK)==null?void 0:o.grpcConfig,n=new Xr(r),i=Ln.create();try{return i.mimeType=s,t?await n.upload(i,e):await n.uploadUserImage(i,e)}catch(a){throw a}},js=async(s,e,t=!0,r)=>{var a;const n=(a=window.ImageSalonSDK)==null?void 0:a.grpcConfig,i=new Xr(n),o=Ln.create();try{o.mimeType=s;const c=t;return await i.uploadUserImage(o,{meta:{Authorization:e,"app-id":r==="production"?"hamropatro":"hamropatro-android"}}),c}catch(c){throw c}},Gr=async(s,e,t,r=!0)=>{var n,i;try{const o=await Ws(e==null?void 0:e.type,t,r),a=(n=o.response)==null?void 0:n.uploadUrl,c=(i=o==null?void 0:o.response)==null?void 0:i.accessUrl;return await Jr(s,a,e),c}catch(o){throw o}},Jr=async(s,e,t)=>{const r=Zs(s,t);try{await fetch(e,{method:"PUT",headers:{"Content-Type":t==null?void 0:t.type},body:r})}catch(n){throw n}},qs=async(s,e,t,r=!1,n)=>{var i,o;try{const a=await js(e==null?void 0:e.type,t,r,n);console.log("upload response",a);const c=(i=a.response)==null?void 0:i.uploadUrl,d=(o=a==null?void 0:a.response)==null?void 0:o.accessUrl;return await Jr(s,c,e),d}catch(a){throw a}},Zs=(s,e)=>{const t=e.type.split("/")[0];console.log("file type",t),console.log("base 64 image",s);let r="";t==="video"?r=s==null?void 0:s.replace(/^data:video\/\w+;base64,/,""):t==="image"?r=s==null?void 0:s.replace(/^data:image\/\w+;base64,/,""):t==="audio"&&(r=s==null?void 0:s.replace(/^data:audio\/\w+;base64,/,"")),console.log("base 64 string",r);const n=atob(r),i=new Uint8Array(n.length);for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);return console.log("buffer",i),i};async function Qr(s){const e={maxSizeMB:2,useWebWorker:!1,alwaysKeepResolution:!0};try{return await Oe(s,e)}catch(t){throw t}}class Ks{constructor(e){z(this,At);z(this,Ae);z(this,ke);z(this,wt);z(this,we,[]);z(this,Ie,[]);z(this,tt);z(this,je);z(this,Dt);z(this,kt);z(this,ot,[]);z(this,nt);z(this,Ft);z(this,Wt);z(this,Qn);z(this,Nt);z(this,It);z(this,yt);z(this,Mt);z(this,at);z(this,lt);z(this,Tt);z(this,Lt);z(this,bt);z(this,jt);z(this,on);z(this,Se);z(this,Ct);z(this,an,!1);z(this,Un);z(this,ln);z(this,ct);z(this,qt);z(this,Ut);z(this,xt);z(this,Zt);z(this,Kt);z(this,zt);z(this,Xt);z(this,cn);z(this,dn);z(this,Gt);z(this,dt);z(this,Jt);H(this,ln,e.isAdmin),H(this,tt,!1),H(this,xt,e==null?void 0:e.mode),e.handleUpload&&H(this,Wt,e.handleUpload.bind(this)),e!=null&&e.accessToken&&(H(this,on,e.accessToken),this._grpcOptionInitializer()),this._init(e).then(()=>{H(this,an,!0),e!=null&&e.parentContainerId&&this._renderView(e),this.updateWindowObject({initialized:!0}),this._initializeGrpcConfig(e.mode,e.endPoint)})}async _init(e){try{const{mode:t}=e;this.updateWindowObject({mode:t})}catch{throw Error("Initialization failed")}}_isAdminOptions(e){return e.isAdmin===!0}_renderView(e){var t,r,n;return this._isAdminOptions(e)?(H(this,je,!1),H(this,Dt,!1),H(this,Nt,0),H(this,lt,""),H(this,bt,!1),H(this,xt,e.mode),H(this,Tt,!1),H(this,Ut,""),H(this,Ct,null),this._removeToastContainer(),this._renderAdminView(e)):(H(this,qt,""),H(this,Zt,e==null?void 0:e.restrictedFileSize),H(this,Kt,e==null?void 0:e.localizedFileRestrictedMessage),H(this,Xt,e==null?void 0:e.localizedSuccessMessage),H(this,zt,e==null?void 0:e.localizedErrorMessage),H(this,dt,e==null?void 0:e.imagePreviewWidth),H(this,Jt,e==null?void 0:e.imagePreviewHeight),H(this,cn,(t=e==null?void 0:e.removeImageConfirm)==null?void 0:t.bind(this)),H(this,dn,(r=e==null?void 0:e.removeImagePreviewCB)==null?void 0:r.bind(this)),H(this,Gt,(n=e==null?void 0:e.getUploadingState)==null?void 0:n.bind(this)),this._removeUserToast(),this._renderUserView(e))}_renderAdminView(e){if(!E(this,an))return;const{parentContainerId:t}=e;if(e.isAdmin===!0)var{buttonProps:r}=e;H(this,At,document.getElementById(t));const n=document.createElement("button");n.className=r!=null&&r.buttonClass?r==null?void 0:r.buttonClass:"browse-image-button",n.addEventListener("focus",()=>{n.blur()});const i=document.createElement("span");i.textContent=r!=null&&r.buttonText?r==null?void 0:r.buttonText:"Browse Files";const o=document.createElement("span");o.innerHTML=r!=null&&r.buttonIcon?r==null?void 0:r.buttonIcon:"",n.type="button",n.append(i,o),r!=null&&r.buttonStyle&&Object.assign(n.style,r==null?void 0:r.buttonStyle),n.addEventListener("click",()=>{this._selectedImageContainer()}),E(this,At).appendChild(n)}async _grpcOptionInitializer(){H(this,Se,await Us(E(this,on),E(this,xt)))}_selectedImageContainer(){var u;H(this,Ft,We(`Save (${(u=E(this,we))==null?void 0:u.length})`,"dialog-btn confirm")),H(this,It,K("folder-container")),H(this,yt,K("folder-list-wrapper")),this._fetchAllFolders();const e=We("Cancel","dialog-btn cancel");We("","dialog-modal-close-btn","",!1,'<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="24" height="24" viewBox="0 0 50 50"> <path d="M 9.15625 6.3125 L 6.3125 9.15625 L 22.15625 25 L 6.21875 40.96875 L 9.03125 43.78125 L 25 27.84375 L 40.9375 43.78125 L 43.78125 40.9375 L 27.84375 25 L 43.6875 9.15625 L 40.84375 6.3125 L 25 22.15625 Z"></path> </svg>').addEventListener("click",()=>{vn.hide(),H(this,we,[]),H(this,Ie,[])}),H(this,Ae,K("browse-container"));const r=K();r.style.display="flex",r.style.alignItems="center",r.style.justifyContent="space-between",r.style.padding="10px 20px";const n=sn("Folders","folder-title"),i=We("","add-folder-btn");i.append(xr()),this._createUpdateFolderDialog(i,"create"),r.append(n,i),E(this,It).append(r,E(this,yt));const o=this._renderSearchField(),a=this._createBrowseMoreContainer(),c=this._createBrowseImageMain(),d=K("footer");e.onclick=()=>{vn.hide(),H(this,Ie,[]),H(this,we,[])},E(this,Ft).onclick=()=>{E(this,Wt).call(this),vn.hide(),H(this,we,[]),H(this,Ie,[])},d.append(e,E(this,Ft));const l=K("container-right-main");l.append(o,a,c,d),E(this,Ae).append(E(this,It),l),vn.show({content:E(this,Ae)})}_renderUserView(e){const{parentContainerId:t,restrictedFileSize:r,imagePreview:n}=e;H(this,At,document.getElementById(t)),H(this,ct,Q("div","user-view-container"));const i=K("user-view-browse-wrapper","user-view-browse-wrapper"),o=Q("span","","",""),a=this._renderUserViewBrowseButton(),c=Q("p","","margin-block: 0px; font-size:14px");if(c.append(o,a),r){const d=Q("p","","margin-block: 0px; font-size: 13px; color: #777",`Max File size: ${r}MB`);i.append(qn(),c,d)}else i.append(qn(),c);return E(this,ct).append(i),n&&this._renderImagePreview(n,"",i,!0),E(this,At).appendChild(E(this,ct)),E(this,At)}_renderImagePreview(e,t,r,n=!1){var T;const i=document.getElementById("user-view-browse-wrapper"),o=i||r;o&&(o.style.display="none");const a=document.getElementById("user-image-preview");a&&a.remove();const c=Q("div","user-image-preview");c.id="user-image-preview";const d=this._renderImageLoadingContainer();c.appendChild(d);const l=Q("img","",`max-width: ${E(this,dt)?E(this,dt):230}px;max-height:${E(this,Jt)?E(this,Jt):250}px;object-fit:cover;`);l.src=e,l.alt=t||"";const u=this._renderImageErrorContainer();c.appendChild(u),l.onload=()=>{f.style.display="none",d.style.display="none",d.remove(),u.style.display="none",u.remove(),l.style.display="block",f.style.display=n?"flex":"none"},l.onerror=C=>{d.style.display="none",d.remove(),u.style.display="flex",l.style.display="none",f.style.display="none"};const h=u.querySelector("#retry-image-btn");h==null||h.addEventListener("click",()=>{d.style.display="flex",u.style.display="none",f.style.display="none",l.src=e});const f=Q("div","","width: 18px; height: 18px; display:none; cursor:pointer; align-items: center; justify-content: center; padding: 4px; position: absolute; top: -5px; right: -5px; background: #c10007; border-radius: 50%;z-index:1");f.id="remove-preview-btn";const y=jn();y.style.fill="#fff",f==null||f.appendChild(y),f.addEventListener("click",()=>{E(this,cn).call(this)});const k=Q("button","","display:none");k.id="image-preview-hidden-btn",k.addEventListener("click",C=>{var R;C.preventDefault(),C.stopPropagation(),(R=E(this,ct))==null||R.removeChild(c),E(this,dn).call(this),this._removeUserToast(),o&&(o.style.display="flex")}),c==null||c.append(l,f,k),(T=E(this,ct))==null||T.append(c)}_renderImageErrorContainer(){const e=Q("div","","display: none; text-align: center;");return e.innerHTML=`
24
+ `;let Gn;function Hs(s,e){return new Promise((t,r)=>{Gn||(Gn=function(o){const a=[];return a.push(o),URL.createObjectURL(new Blob(a))}(Vs));const n=new Worker(Gn);n.addEventListener("message",function(o){if(e.signal&&e.signal.aborted)n.terminate();else if(o.data.progress===void 0){if(o.data.error)return r(new Error(o.data.error)),void n.terminate();t(o.data.file),n.terminate()}else e.onProgress(o.data.progress)}),n.addEventListener("error",r),e.signal&&e.signal.addEventListener("abort",()=>{r(e.signal.reason),n.terminate()}),n.postMessage({file:s,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})})}function Oe(s,e){return new Promise(function(t,r){let n,i,o,a,c,d;if(n={...e},o=0,{onProgress:a}=n,n.maxSizeMB=n.maxSizeMB||Number.POSITIVE_INFINITY,c=typeof n.useWebWorker!="boolean"||n.useWebWorker,delete n.useWebWorker,n.onProgress=f=>{o=f,typeof a=="function"&&a(o)},!(s instanceof Blob||s instanceof Ms))return r(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(s.type))return r(new Error("The file given is not an image"));if(d=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,!c||typeof Worker!="function"||d)return Kr(s,n).then((function(f){try{return i=f,h.call(this)}catch(y){return r(y)}}).bind(this),r);var l=(function(){try{return h.call(this)}catch(f){return r(f)}}).bind(this),u=function(f){try{return Kr(s,n).then(function(y){try{return i=y,l()}catch(k){return r(k)}},r)}catch(y){return r(y)}};try{return n.libURL=n.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",Hs(s,n).then(function(f){try{return i=f,l()}catch{return u()}},u)}catch{u()}function h(){try{i.name=s.name,i.lastModified=s.lastModified}catch{}try{n.preserveExif&&s.type==="image/jpeg"&&(!n.fileType||n.fileType&&n.fileType===s.type)&&(i=Rr(s,i))}catch{}return t(i)}})}Oe.getDataUrlFromFile=Hr,Oe.getFilefromDataUrl=Xn,Oe.loadImage=$r,Oe.drawImageInCanvas=Wr,Oe.drawFileInCanvas=In,Oe.canvasToFile=Tn,Oe.getExifOrientation=jr,Oe.handleMaxWidthOrHeight=qr,Oe.followExifOrientation=Zr,Oe.cleanupCanvasMemory=st,Oe.isAutoOrientationInBrowser=$t,Oe.approximateBelowMaximumCanvasSizeOfBrowser=Pr,Oe.copyExifWithoutOrientation=Rr,Oe.getBrowserName=Rt,Oe.version="2.0.2";class $s extends Te{constructor(){super("com.hamropatro.grpc.common.ImageUploadRequest",[{no:1,name:"mime_type",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.mimeType="",e!==void 0&&Ee(this,t,e),t}internalBinaryRead(e,t,r,n){let i=n??this.create(),o=e.pos+t;for(;e.pos<o;){let[a,c]=e.tag();switch(a){case 1:i.mimeType=e.string();break;default:let d=r.readUnknownField;if(d==="throw")throw new globalThis.Error(`Unknown field ${a} (wire type ${c}) for ${this.typeName}`);let l=e.skip(c);d!==!1&&(d===!0?G.onRead:d)(this.typeName,i,a,c,l)}}return i}internalBinaryWrite(e,t,r){e.mimeType!==""&&t.tag(1,j.LengthDelimited).string(e.mimeType);let n=r.writeUnknownFields;return n!==!1&&(n==!0?G.onWrite:n)(this.typeName,e,t),t}}const Ln=new $s;class Ps extends Te{constructor(){super("com.hamropatro.grpc.common.ImageUploadResponse",[{no:1,name:"key",kind:"scalar",T:9},{no:2,name:"uploadUrl",kind:"scalar",T:9},{no:3,name:"access_url",kind:"scalar",T:9}])}create(e){const t=globalThis.Object.create(this.messagePrototype);return t.key="",t.uploadUrl="",t.accessUrl="",e!==void 0&&Ee(this,t,e),t}internalBinaryRead(e,t,r,n){let i=n??this.create(),o=e.pos+t;for(;e.pos<o;){let[a,c]=e.tag();switch(a){case 1:i.key=e.string();break;case 2:i.uploadUrl=e.string();break;case 3:i.accessUrl=e.string();break;default:let d=r.readUnknownField;if(d==="throw")throw new globalThis.Error(`Unknown field ${a} (wire type ${c}) for ${this.typeName}`);let l=e.skip(c);d!==!1&&(d===!0?G.onRead:d)(this.typeName,i,a,c,l)}}return i}internalBinaryWrite(e,t,r){e.key!==""&&t.tag(1,j.LengthDelimited).string(e.key),e.uploadUrl!==""&&t.tag(2,j.LengthDelimited).string(e.uploadUrl),e.accessUrl!==""&&t.tag(3,j.LengthDelimited).string(e.accessUrl);let n=r.writeUnknownFields;return n!==!1&&(n==!0?G.onWrite:n)(this.typeName,e,t),t}}const zr=new Ps,Jn=new Dn("com.hamropatro.grpc.common.ImageUploadService",[{name:"Upload",options:{},I:Ln,O:zr},{name:"UploadUserImage",options:{},I:Ln,O:zr}]);class Xr{constructor(e){pe(this,"typeName",Jn.typeName);pe(this,"methods",Jn.methods);pe(this,"options",Jn.options);this._transport=e}upload(e,t){const r=this.methods[0],n=this._transport.mergeOptions(t);return Pe("unary",this._transport,r,n,e)}uploadUserImage(e,t){const r=this.methods[1],n=this._transport.mergeOptions(t);return Pe("unary",this._transport,r,n,e)}}const Ws=async(s,e,t=!0)=>{var o;const r=(o=window.ImageSalonSDK)==null?void 0:o.grpcConfig,n=new Xr(r),i=Ln.create();try{return i.mimeType=s,t?await n.upload(i,e):await n.uploadUserImage(i,e)}catch(a){throw a}},js=async(s,e,t=!0,r)=>{var a;const n=(a=window.ImageSalonSDK)==null?void 0:a.grpcConfig,i=new Xr(n),o=Ln.create();try{return o.mimeType=s,await i.uploadUserImage(o,{meta:{Authorization:e,"app-id":r==="production"?"hamropatro":"hamropatro-android"}})}catch(c){throw c}},Gr=async(s,e,t,r=!0)=>{var n,i;try{const o=await Ws(e==null?void 0:e.type,t,r),a=(n=o.response)==null?void 0:n.uploadUrl,c=(i=o==null?void 0:o.response)==null?void 0:i.accessUrl;return await Jr(s,a,e),c}catch(o){throw o}},Jr=async(s,e,t)=>{const r=Zs(s,t);try{await fetch(e,{method:"PUT",headers:{"Content-Type":t==null?void 0:t.type},body:r})}catch(n){throw n}},qs=async(s,e,t,r=!1,n)=>{var i,o;try{const a=await js(e==null?void 0:e.type,t,r,n),c=(i=a.response)==null?void 0:i.uploadUrl,d=(o=a==null?void 0:a.response)==null?void 0:o.accessUrl;return await Jr(s,c,e),d}catch(a){throw a}},Zs=(s,e)=>{const t=e.type.split("/")[0];let r="";t==="video"?r=s==null?void 0:s.replace(/^data:video\/\w+;base64,/,""):t==="image"?r=s==null?void 0:s.replace(/^data:image\/\w+;base64,/,""):t==="audio"&&(r=s==null?void 0:s.replace(/^data:audio\/\w+;base64,/,""));const n=atob(r),i=new Uint8Array(n.length);for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);return i};async function Qr(s){const e={maxSizeMB:2,useWebWorker:!1,alwaysKeepResolution:!0};try{return await Oe(s,e)}catch(t){throw t}}class Ks{constructor(e){z(this,At);z(this,Ae);z(this,ke);z(this,wt);z(this,we,[]);z(this,Ie,[]);z(this,tt);z(this,je);z(this,Dt);z(this,kt);z(this,ot,[]);z(this,nt);z(this,Ft);z(this,Wt);z(this,Qn);z(this,Nt);z(this,It);z(this,yt);z(this,Mt);z(this,at);z(this,lt);z(this,Tt);z(this,Lt);z(this,bt);z(this,jt);z(this,on);z(this,Se);z(this,Ct);z(this,an,!1);z(this,Un);z(this,ln);z(this,ct);z(this,qt);z(this,Ut);z(this,xt);z(this,Zt);z(this,Kt);z(this,zt);z(this,Xt);z(this,cn);z(this,dn);z(this,Gt);z(this,dt);z(this,Jt);H(this,ln,e.isAdmin),H(this,tt,!1),H(this,xt,e==null?void 0:e.mode),e.handleUpload&&H(this,Wt,e.handleUpload.bind(this)),e!=null&&e.accessToken&&(H(this,on,e.accessToken),this._grpcOptionInitializer()),this._init(e).then(()=>{H(this,an,!0),e!=null&&e.parentContainerId&&this._renderView(e),this.updateWindowObject({initialized:!0}),this._initializeGrpcConfig(e.mode,e.endPoint)})}async _init(e){try{const{mode:t}=e;this.updateWindowObject({mode:t})}catch{throw Error("Initialization failed")}}_isAdminOptions(e){return e.isAdmin===!0}_renderView(e){var t,r,n;return this._isAdminOptions(e)?(H(this,je,!1),H(this,Dt,!1),H(this,Nt,0),H(this,lt,""),H(this,bt,!1),H(this,xt,e.mode),H(this,Tt,!1),H(this,Ut,""),H(this,Ct,null),this._removeToastContainer(),this._renderAdminView(e)):(H(this,qt,""),H(this,Zt,e==null?void 0:e.restrictedFileSize),H(this,Kt,e==null?void 0:e.localizedFileRestrictedMessage),H(this,Xt,e==null?void 0:e.localizedSuccessMessage),H(this,zt,e==null?void 0:e.localizedErrorMessage),H(this,dt,e==null?void 0:e.imagePreviewWidth),H(this,Jt,e==null?void 0:e.imagePreviewHeight),H(this,cn,(t=e==null?void 0:e.removeImageConfirm)==null?void 0:t.bind(this)),H(this,dn,(r=e==null?void 0:e.removeImagePreviewCB)==null?void 0:r.bind(this)),H(this,Gt,(n=e==null?void 0:e.getUploadingState)==null?void 0:n.bind(this)),this._removeUserToast(),this._renderUserView(e))}_renderAdminView(e){if(!E(this,an))return;const{parentContainerId:t}=e;if(e.isAdmin===!0)var{buttonProps:r}=e;H(this,At,document.getElementById(t));const n=document.createElement("button");n.className=r!=null&&r.buttonClass?r==null?void 0:r.buttonClass:"browse-image-button",n.addEventListener("focus",()=>{n.blur()});const i=document.createElement("span");i.textContent=r!=null&&r.buttonText?r==null?void 0:r.buttonText:"Browse Files";const o=document.createElement("span");o.innerHTML=r!=null&&r.buttonIcon?r==null?void 0:r.buttonIcon:"",n.type="button",n.append(i,o),r!=null&&r.buttonStyle&&Object.assign(n.style,r==null?void 0:r.buttonStyle),n.addEventListener("click",()=>{this._selectedImageContainer()}),E(this,At).appendChild(n)}async _grpcOptionInitializer(){H(this,Se,await Us(E(this,on),E(this,xt)))}_selectedImageContainer(){var u;H(this,Ft,We(`Save (${(u=E(this,we))==null?void 0:u.length})`,"dialog-btn confirm")),H(this,It,K("folder-container")),H(this,yt,K("folder-list-wrapper")),this._fetchAllFolders();const e=We("Cancel","dialog-btn cancel");We("","dialog-modal-close-btn","",!1,'<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="24" height="24" viewBox="0 0 50 50"> <path d="M 9.15625 6.3125 L 6.3125 9.15625 L 22.15625 25 L 6.21875 40.96875 L 9.03125 43.78125 L 25 27.84375 L 40.9375 43.78125 L 43.78125 40.9375 L 27.84375 25 L 43.6875 9.15625 L 40.84375 6.3125 L 25 22.15625 Z"></path> </svg>').addEventListener("click",()=>{vn.hide(),H(this,we,[]),H(this,Ie,[])}),H(this,Ae,K("browse-container"));const r=K();r.style.display="flex",r.style.alignItems="center",r.style.justifyContent="space-between",r.style.padding="10px 20px";const n=sn("Folders","folder-title"),i=We("","add-folder-btn");i.append(xr()),this._createUpdateFolderDialog(i,"create"),r.append(n,i),E(this,It).append(r,E(this,yt));const o=this._renderSearchField(),a=this._createBrowseMoreContainer(),c=this._createBrowseImageMain(),d=K("footer");e.onclick=()=>{vn.hide(),H(this,Ie,[]),H(this,we,[])},E(this,Ft).onclick=()=>{E(this,Wt).call(this),vn.hide(),H(this,we,[]),H(this,Ie,[])},d.append(e,E(this,Ft));const l=K("container-right-main");l.append(o,a,c,d),E(this,Ae).append(E(this,It),l),vn.show({content:E(this,Ae)})}_renderUserView(e){const{parentContainerId:t,restrictedFileSize:r,imagePreview:n}=e;H(this,At,document.getElementById(t)),H(this,ct,Q("div","user-view-container"));const i=K("user-view-browse-wrapper","user-view-browse-wrapper"),o=Q("span","","",""),a=this._renderUserViewBrowseButton(),c=Q("p","","margin-block: 0px; font-size:14px");if(c.append(o,a),r){const d=Q("p","","margin-block: 0px; font-size: 13px; color: #777",`Max File size: ${r}MB`);i.append(qn(),c,d)}else i.append(qn(),c);return E(this,ct).append(i),n&&this._renderImagePreview(n,"",i,!0),E(this,At).appendChild(E(this,ct)),E(this,At)}_renderImagePreview(e,t,r,n=!1){var T;const i=document.getElementById("user-view-browse-wrapper"),o=i||r;o&&(o.style.display="none");const a=document.getElementById("user-image-preview");a&&a.remove();const c=Q("div","user-image-preview");c.id="user-image-preview";const d=this._renderImageLoadingContainer();c.appendChild(d);const l=Q("img","",`max-width: ${E(this,dt)?E(this,dt):230}px;max-height:${E(this,Jt)?E(this,Jt):250}px;object-fit:cover;`);l.src=e,l.alt=t||"";const u=this._renderImageErrorContainer();c.appendChild(u),l.onload=()=>{f.style.display="none",d.style.display="none",d.remove(),u.style.display="none",u.remove(),l.style.display="block",f.style.display=n?"flex":"none"},l.onerror=C=>{d.style.display="none",d.remove(),u.style.display="flex",l.style.display="none",f.style.display="none"};const h=u.querySelector("#retry-image-btn");h==null||h.addEventListener("click",()=>{d.style.display="flex",u.style.display="none",f.style.display="none",l.src=e});const f=Q("div","","width: 18px; height: 18px; display:none; cursor:pointer; align-items: center; justify-content: center; padding: 4px; position: absolute; top: -5px; right: -5px; background: #c10007; border-radius: 50%;z-index:1");f.id="remove-preview-btn";const y=jn();y.style.fill="#fff",f==null||f.appendChild(y),f.addEventListener("click",()=>{E(this,cn).call(this)});const k=Q("button","","display:none");k.id="image-preview-hidden-btn",k.addEventListener("click",C=>{var R;C.preventDefault(),C.stopPropagation(),(R=E(this,ct))==null||R.removeChild(c),E(this,dn).call(this),this._removeUserToast(),o&&(o.style.display="flex")}),c==null||c.append(l,f,k),(T=E(this,ct))==null||T.append(c)}_renderImageErrorContainer(){const e=Q("div","","display: none; text-align: center;");return e.innerHTML=`
25
25
  <div style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;">
26
26
  <p style="color: #c10007;margin-block:0px;">Failed to load image</p>
27
27
  <button type="button" id="retry-image-btn" style="margin-top: 10px; padding: 5px 10px; background: #3498db; color: white; border: none; border-radius: 4px; cursor: pointer;">
@@ -117,4 +117,4 @@ self.addEventListener('message', async (e) => {
117
117
  </clipPath>
118
118
  </defs>
119
119
  </svg>
120
- `,r.textContent="Looks Empty!"),e.append(t,r),E(this,ke).appendChild(e)}_renderLoadingUI(){const e=K("skeleton");e.innerHTML="",E(this,ke).appendChild(e)}_fileCardBody(e){var ft,Qt,xn,Yt;const t=K("selected-image-content"),r=K("selected-image-top-bar"),n=We("","selected-image-btn","",!1,'<svg width="20px" height="20px" viewBox="0 0 20 20" focusable="false" fill="currentColor"><path fill="none" d="M0 0h20v20H0V0z"></path><path d="M10 6c.82 0 1.5-.68 1.5-1.5S10.82 3 10 3s-1.5.67-1.5 1.5S9.18 6 10 6zm0 5.5c.82 0 1.5-.68 1.5-1.5s-.68-1.5-1.5-1.5-1.5.68-1.5 1.5.68 1.5 1.5 1.5zm0 5.5c.82 0 1.5-.67 1.5-1.5 0-.82-.68-1.5-1.5-1.5s-1.5.68-1.5 1.5c0 .83.68 1.5 1.5 1.5z"></path></svg>');let i,o;(e==null?void 0:e.type)===Qe.IMAGE&&(i=Sr(e==null?void 0:e.url,"selected-image"),o=Es()),(e==null?void 0:e.type)===Qe.VIDEO&&(i=xs(e==null?void 0:e.url,"uploaded-video"),o=Fs()),(e==null?void 0:e.type)===Qe.AUDIO&&(i=_s(e==null?void 0:e.url,"uploaded-audio"),o=Cs());const a=K("selected-image-wrapper");a.setAttribute("data-key",e==null?void 0:e.key);const c=sn(e==null?void 0:e.name,"selected-image-name"),d=oe("","selected-image-type");d.append(o),r.append(d,n);const l=K();l.style.marginTop="10px",l.style.display="flex",l.style.justifyContent="space-between",l.style.alignItems="center",l.append(c),t.append(r,i),a.append(t,l);const u=K("action-wrapper"),h=We("","action-option preview"),f=oe("Preview",""),y=As();h.append(y,f);const k=We("","action-option move"),T=oe("Move",""),C=vs();k.append(C,T);const R=We("","action-option rename"),O=oe("Rename",""),F=Ur();R.append(F,O);const U=We("","action-option delete"),b=oe("Delete",""),B=_r();U.append(B,b);const m=e.name.split(".")[0],g=e.name.split(".")[1],A=rn[e.type],I=K("edit-form-wrapper"),N=K("move-form-wrapper"),L=K("preview-details-container"),v=K("preview-details-wrapper"),_=K("preview-option-image-wrapper"),w=K("preview-option-wrapper"),p=K("preview-option-wrapper"),M=K("preview-option-wrapper"),x=K("preview-option-wrapper"),V=K("preview-option-wrapper"),Z=K("preview-option-wrapper"),P=K("preview-option-wrapper"),q=Sr(e.url,"preview-option-image");_.append(q);const $=oe("File name","preview-title"),S=K("preview-option-name");S.innerHTML=e.name,w.append($,S);const X=oe("Folder name","preview-title"),ce=oe(e.folderName,"preview-option-name");p.append(X,ce);const te=oe("File Extension","preview-title"),Y=oe(g,"preview-option-name extension");M.append(te,Y);const ae=oe("File type","preview-title"),me=oe(A,"preview-option-name");x.append(ae,me);const Fe=oe("Dimension","preview-title"),Et=oe(`${(ft=e==null?void 0:e.metadata)==null?void 0:ft.width} * ${(Qt=e==null?void 0:e.metadata)==null?void 0:Qt.height}`,"preview-option-name");V.append(Fe,Et);const Ke=oe("URL","preview-title"),fe=oe(e.url,"preview-option-name url");Z.append(Ke,fe);const Le=oe("Parent folder","preview-title"),de=oe(e.nestedFolderName,"preview-option-name");P.append(Le,de),v.append(p,w,M,x,((xn=e==null?void 0:e.metadata)==null?void 0:xn.width)>0&&((Yt=e==null?void 0:e.metadata)==null?void 0:Yt.height)>0?V:"",Z,e.nestedFolderName?P:""),L.append(_,v);const re=K("form-control"),ye=document.createElement("input");re.appendChild(ye),ye.classList.add("input-field"),ye.value=e.name;const Ue=K("form-control"),be=oe("Current Folder:","input-label"),xe=K("folder-field current");xe.textContent=e.folderName,xe.prepend(nn()),Ue.append(be,xe);const ge=K("form-control"),ee=K();ee.style.width="100%",ee.style.display="flex",ee.style.alignItems="center",ee.style.justifyContent="space-between";const Ve=oe("Suggested Folder List:","input-label"),Re=oe();Re.style.display="flex",Re.style.alignItems="center",Re.style.gap="5px",Re.style.fontSize="14px",Re.textContent="Move the file in selected folder",Re.appendChild(Wn("14px","14px","#333")),ee.append(Ve,Re);const ht=K();ht.style.width="100%",ht.style.maxHeight="250px",ht.style.overflowY="auto";const Ne=document.createElement("ul");Ne.className="folders",ht.append(Ne),ge.append(ee,ht),E(this,ot).forEach(ue=>{const ze=this._renderEditFolderListContainer(ue);Ne.appendChild(ze)});const ut=K("form-control"),_e=oe("Destination Folder:","input-label"),$e=K("folder-field source","source-folder-wrapper"),De=document.createElement("span");De.id="source-folder-name",De.textContent=E(this,Ut)?E(this,Ut):e.folderName,$e.append(nn(),De);let Me="";ut.append(_e,$e),ye.onchange=ue=>{Me=ue.target.value},Me=Me!==""?Me:e.name,I.append(re),N.append(Ue,ge,ut),u.append(h,k,R,U),h.onclick=ue=>{ue.stopPropagation(),Ze.hide(),ve.show({content:L,header:m,dialogContentStyle:{minWidth:"60rem",padding:"10px"},showCloseBtn:!0})},k.onclick=ue=>{ue.stopPropagation(),Ze.hide(),ve.show({content:N,header:`Move "${e.name}"`,confirmButtonText:"Move",dialogContentStyle:{minWidth:"35rem",padding:"10px"},showCloseBtn:!0,showFooter:!0,onCancel:()=>{ve.hide()},onConfirm:()=>{this._updateFile(Me,e)}})},R.onclick=ue=>{ue.stopPropagation(),Ze.hide(),ve.show({content:I,header:"Rename",confirmButtonText:"Update",dialogContentStyle:{padding:"10px"},showCloseBtn:!0,showFooter:!0,onCancel:()=>{ve.hide()},onConfirm:()=>{this._updateFile(Me,e)}})},U.onclick=ue=>{ue.stopPropagation(),Ze.hide(),ve.show({content:"",dialogContentStyle:{minWidth:"32rem",padding:"10px"},header:`Are you sure you want to delete the file "${e.name}"?`,showFooter:!0,confirmButtonText:"Yes",cancelButtonText:"No",onConfirm:()=>{this._deleteFile(e.key)}})},n.addEventListener("click",ue=>{ue.stopPropagation(),Ze.hide(),Ze.show({content:u,mainContainer:r,divId:e.key}),H(this,Ct,e.key)}),i.addEventListener("click",()=>{const ue=E(this,we).findIndex(pt=>(pt==null?void 0:pt.key)===(e==null?void 0:e.key));if(t.classList.contains("checked"))t.classList.remove("checked"),ue!==-1&&(E(this,we).splice(ue,1),E(this,Nt)===1&&a.remove());else{if(E(this,Un))E(this,we).push(e);else{const pt=document.querySelector(".selected-image-wrapper .checked");pt==null||pt.classList.remove("checked"),H(this,we,[e])}t.classList.add("checked")}this._updateContent()}),document.addEventListener("click",ue=>{const ze=document.querySelector(`#${E(this,Ct)}`);ze&&(ue.composedPath().includes(ze)||Ze.hide())}),E(this,we).findIndex(ue=>(ue==null?void 0:ue.key)===(e==null?void 0:e.key))!==-1?(t.classList.add("checked"),E(this,bt)?E(this,ke).prepend(a):E(this,ke).appendChild(a)):E(this,ke).appendChild(a)}_renderImageCard(e){this._fileCardBody(e)}_renderImageListContainer(){var e,t;((e=E(this,Ie))==null?void 0:e.length)>0&&((t=E(this,Ie))==null||t.forEach(r=>{this._renderImageCard(r)}))}_renderSelectedImageListContainer(){var e;((e=E(this,we))==null?void 0:e.length)>0&&E(this,we).forEach(t=>{this._renderImageCard(t)})}_renderFolderListLoadingUI(){const e=document.createElement("div");e.style.paddingInline="20px";for(let t=0;t<4;t++){const r=K("skeleton");r.className="skeleton folder",r.innerHTML="",e.appendChild(r)}return e}_renderFolderListContainer(e){var o;const t=document.createElement("li");t.className="folder";const r=document.createElement("div");r.style.position="relative",r.style.display="flex",r.style.alignItems="center",r.style.gap="2px";const n=document.createElement("span"),i=document.createElement("span");if(i.className="folder-name",i.textContent=e==null?void 0:e.name,n.appendChild(nn()),r.append(n,i),t.append(r),e.children&&Object.keys(e.children).length>0){const a=document.createElement("button");a.classList.add("expand-icon"),a.appendChild(Tr()),r.prepend(a);const c=document.createElement("ul");c.className="folders nested",t.appendChild(c),a.addEventListener("click",d=>{d.stopPropagation(),t.classList.toggle("active"),c.classList.toggle("visible")}),Object.values(e.children).forEach((d,l)=>{const u=this._renderFolderListContainer(d);c.appendChild(u)})}if(e.nestedFolderName){const a=We("","folder-option-btn","moveToInputField.disabled",!1,'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-ellipsis"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></svg>'),c=K("action-wrapper"),d=We("","action-option edit"),l=oe("Edit",""),u=Ur();d.append(u,l);const h=K("edit-form-wrapper"),f=K("name-field-wrapper"),y=oe("Name","input-label"),k=document.createElement("input");k.classList.add("input-field"),k.value=e.name,k.onchange=F=>{F.target.value},f.append(y,k),h.append(f);const T={key:e.key,name:e.name,nestedFolderName:e.nestedFolderName,createdBy:e.createdBy};this._createUpdateFolderDialog(d,"update",T);const C=We("","action-option delete"),R=oe("Delete",""),O=_r();C.append(O,R),c.append(d,C),C.onclick=F=>{F.stopPropagation(),Ze.hide(),ve.show({content:"",dialogContentStyle:{minWidth:"32rem",padding:"10px"},header:`Are you sure you want to delete the folder "${e==null?void 0:e.name}"?`,showFooter:!0,confirmButtonText:"Yes",cancelButtonText:"No",onConfirm:()=>{this._deleteFolder(e.key)}})},a.addEventListener("click",F=>{F.stopPropagation();const U=document.querySelector(`#${e.key}`);H(this,Ct,null),E(this,Ct)===e.key&&U!==null?Ze.hide():(Ze.hide(),Ze.show({content:c,mainContainer:r,divId:e.key}),H(this,Ct,e.key))}),r.appendChild(a)}return t.addEventListener("click",a=>{var c;a.stopPropagation(),H(this,nt,e),H(this,kt,e==null?void 0:e.name),H(this,we,[]),H(this,Ie,[]),H(this,lt,""),H(this,Tt,!1),(c=document.querySelector(".folder.selected"))==null||c.classList.remove("selected"),t.classList.add("selected"),this._fetchFilesFromFolder(e.name)}),((o=E(this,nt))==null?void 0:o.key)===(e==null?void 0:e.key)&&t.classList.add("selected"),t}_renderEditFolderListContainer(e){var o;const t=document.createElement("li");t.className="folder-move";const r=document.createElement("div");r.style.position="relative",r.style.display="flex",r.style.alignItems="center",r.style.gap="2px";const n=document.createElement("span"),i=document.createElement("span");if(i.className="folder-name",i.textContent=e==null?void 0:e.name,n.appendChild(nn()),r.append(n,i),t.append(r),e.children&&Object.keys(e.children).length>0){const a=document.createElement("button");a.classList.add("expand-icon"),a.appendChild(Tr()),r.prepend(a);const c=document.createElement("ul");c.className="folders nested",t.appendChild(c),a.addEventListener("click",d=>{d.stopPropagation(),t.classList.toggle("active"),c.classList.toggle("visible")}),Object.values(e.children).forEach(d=>{const l=this._renderEditFolderListContainer(d);c.appendChild(l)})}return t.addEventListener("click",a=>{var d;a.stopPropagation(),H(this,Ut,e==null?void 0:e.name);const c=document.querySelector("#source-folder-name");c.textContent="",c.textContent=e==null?void 0:e.name,(d=document.querySelector(".folder-move.selected"))==null||d.classList.remove("selected"),t.classList.add("selected")}),((o=E(this,nt))==null?void 0:o.key)===(e==null?void 0:e.key)&&t.classList.add("selected"),t}_updateFolderListContainer(){if(E(this,It))if(E(this,yt).innerHTML="",E(this,Dt)){const e=this._renderFolderListLoadingUI();E(this,yt).appendChild(e)}else{const e=document.createElement("ul");e.className="folders",E(this,yt).appendChild(e),E(this,ot).forEach(t=>{const r=this._renderFolderListContainer(t);e.appendChild(r)}),E(this,It).appendChild(E(this,yt))}}_renderToastContainer(e,t,r){this._removeToastContainer(),H(this,at,document.createElement("div")),E(this,at).className=`message-container ${t}`;const n=sn(e,"message"),i=t==="success"?Lr():Wn(),o=We("");o.style.cursor="pointer",o.style.border="0",o.style.outline="none",o.style.background="transparent",o.appendChild(jn(t==="error"?"#ee3f3f":"#4caf50")),o.setAttribute("fill",t==="error"?"#ee3f3f":"#4caf50"),o.onclick=()=>this._removeToastContainer(),E(this,at).append(i,n,o),r.appendChild(E(this,at)),setTimeout(()=>{this._removeToastContainer()},5e3)}_removeToastContainer(){E(this,at)&&(E(this,at).remove(),H(this,at,null))}_updateSelectedImageListContainerUI(){var t,r;if(!E(this,ke))return;E(this,ke).innerHTML="",E(this,tt)&&this._renderLoadingUI(),E(this,je)&&this._renderFetchingSkeletonUI();const e=document.getElementById("search-input-wrapper");E(this,Nt)===0?(e&&(e.style.visibility="visible"),((t=E(this,Ie))==null?void 0:t.length)===0&&!E(this,je)?(E(this,ke).classList.add("no-selected-image-container"),this._renderEmptyImageContainer()):(E(this,ke).classList.remove("no-selected-image-container"),this._renderImageListContainer())):(e&&(e.style.visibility="hidden"),((r=E(this,we))==null?void 0:r.length)===0?(E(this,ke).classList.add("no-selected-image-container"),this._renderEmptyImageContainer()):(E(this,ke).classList.remove("no-selected-image-container"),this._renderSelectedImageListContainer())),this._updateContent()}_updateContent(){var t,r,n;const e=document.getElementById("selected-images-tab");e&&(e.textContent=`Selected (${(t=E(this,we))==null?void 0:t.length})`),E(this,Ft).textContent=`Save (${(r=E(this,we))==null?void 0:r.length})`,E(this,Ft).disabled=((n=E(this,we))==null?void 0:n.length)===0}async _uploadAndAddSelectedImageList(e,t){var r,n;this._updateSelectedImageListContainerUI();try{const i=await Gr(e,t,E(this,Se)),o=await ts(t==null?void 0:t.name,"",i,Qe[Zn((r=t.type)==null?void 0:r.split("/")[0])],(n=E(this,nt))==null?void 0:n.name,E(this,Se));E(this,Ie).unshift(o==null?void 0:o.response),this._renderToastContainer("File Uploaded Successfully","success",E(this,Ae))}catch{this._renderToastContainer("Something went wrong while uploading file. Please try again later.","error",E(this,Ae))}finally{H(this,tt,!1),this._updateSelectedImageListContainerUI()}}async _updateFile(e,t){ve.updateUploadBtn(!0);try{const r=await os(t.key,e,t.nestedFolderName,t.url,t.thumborUrl,t.proxyUrl,t.type,E(this,Ut),E(this,Se)),n=E(this,Ie).find(i=>i.key===r.response.key);n.name=e,this._fetchFilesFromFolder(E(this,nt).name),H(this,Ie,[]),H(this,we,[]),this._renderToastContainer("File Updated Successfully","success",E(this,Ae))}catch{this._renderToastContainer("Something went wrong while updating the file. Please try again later.","error",E(this,Ae))}finally{ve.updateUploadBtn(!1),ve.hide(),this._updateSelectedImageListContainerUI()}}async _deleteFile(e){ve.updateUploadBtn(!0);try{await as(e,E(this,Se)),H(this,Ie,E(this,Ie).filter(t=>e!==t.key)),this._renderToastContainer("File Deleted Successfully","success",E(this,Ae))}catch{this._renderToastContainer("Something went wrong while deleting the file. Please try again later.","error",E(this,Ae))}finally{ve.updateUploadBtn(!1),ve.hide(),this._updateSelectedImageListContainerUI()}}async _createFolder(e,t=2){var r;try{const n=await ws(e,(r=E(this,nt))==null?void 0:r.name,"",E(this,Se));H(this,we,[]),H(this,Ie,[]);const i=Ls(E(this,ot),n==null?void 0:n.response);H(this,ot,i),H(this,kt,e),H(this,nt,{...n==null?void 0:n.response,children:{}}),this._fetchFilesFromFolder(e),this._renderToastContainer(`Folder ${e} created successfully`,"success",E(this,Ae))}catch{if(t>1)this._createFolder(e,--t);else throw this._renderToastContainer(`Error creating folder "${e}". Either folder already exist or failed to create folder`,"error",E(this,Ae)),new Error(`Error creating folder "${e}". Either folder already exist or failed to create folder`)}finally{this._updateFolderListContainer()}}async _upload(){return E(this,ln)?E(this,we):E(this,qt)}async _uploadFromSource(e,t){this._removeUserToast();const r=200*1024;try{const n=e.size>r?await Qr(e):e;return await new Promise((o,a)=>{const c=new FileReader;console.log("base 64",c.result),c.onload=async()=>{var d;try{const l=await qs(c.result,n,t,!1,E(this,xt)),u=await rs(l,Qe[Zn((d=n.type)==null?void 0:d.split("/")[0])],t,E(this,xt));o(u)}catch(l){a(l)}},c.onerror=()=>{a(c.error),console.log("error",c.error)},c.readAsDataURL(n)})}catch(n){throw console.log("error",n),n}}_uploadingState(){return E(this,tt)}async _fetchFilesFromFolder(e){var t,r,n;H(this,je,!0),this._updateSelectedImageListContainerUI();try{const i=await is(e,E(this,lt),20,E(this,Se)),o=(t=i.response)==null?void 0:t.files;E(this,Ie).push(...o),H(this,lt,(r=i.response)==null?void 0:r.nextCursor),H(this,Tt,(n=i.response)==null?void 0:n.hasMore)}catch{throw this._renderToastContainer("Error while fetching files from folder"+e,"error",E(this,Ae)),new Error("Something went wrong. Error while fetching files from folder"+e)}finally{H(this,je,!1),this._updateSelectedImageListContainerUI()}}async _fetchAllFolders(){var e,t;H(this,je,!0),H(this,Dt,!0),this._updateSelectedImageListContainerUI(),this._updateFolderListContainer(),this._removeToastContainer();try{const n=(await gs("",200,E(this,Se))).response.folder,i=Ts(n);H(this,kt,(e=i[0])==null?void 0:e.name),this._fetchFilesFromFolder((t=i[0])==null?void 0:t.name),H(this,nt,i[0]),H(this,ot,i)}catch{H(this,je,!1),this._renderToastContainer("Folder not found. Please create a folder or try again later","error",E(this,Ae))}finally{H(this,Dt,!1),this._updateFolderListContainer()}}async _search(e){var t,r;H(this,je,!0),this._updateSelectedImageListContainerUI(),this._removeToastContainer();try{const n=await ss(e,E(this,lt),10,E(this,Se)),i=(t=n.response)==null?void 0:t.items;E(this,Ie).push(...i),H(this,lt,(r=n.response)==null?void 0:r.nextPageCursor)}catch{this._renderToastContainer("Error while searching files","error",E(this,Ae))}finally{H(this,je,!1),this._updateSelectedImageListContainerUI()}}async _updateFolder(e,t){ve.updateUploadBtn(!0);try{const r=await ys(t.key,e,t.nestedFolderName,t.createdBy,E(this,Se))}catch{throw this._renderToastContainer("Something went wrong while updating the folder. Please try again later.","error",E(this,Ae)),new Error("Error updating the folder ")}finally{ve.updateUploadBtn(!1),ve.hide(),this._updateFolderListContainer()}}async _deleteFolder(e){ve.updateUploadBtn(!0);try{await bs(e,E(this,Se)),H(this,ot,E(this,ot).filter(t=>t.key!==e)),this._renderToastContainer("Folder Deleted Successfully","success",E(this,Ae))}catch{throw this._renderToastContainer("Something went wrong while deleting the folder. Please try again later.","error",E(this,Ae)),new Error("Error deleting the folder ")}finally{ve.updateUploadBtn(!1),ve.hide(),this._updateFolderListContainer()}}_createUpdateFolderDialog(e,t,r){e.addEventListener("click",n=>{n.stopPropagation(),Ze.hide();let i;const o=K("edit-form-wrapper"),a=K("form-control"),c=oe("Folder Name","input-label"),d=K();d.style.position="relative";const l=document.createElement("input");l.style.paddingLeft="40px";const u=oe();u.appendChild(nn()),u.style.position="absolute",u.style.top="50%",u.style.left="5%",u.style.transform="translate(-40%, -40%)",l.classList.add("input-field"),d.append(l,u),t==="update"&&(l.value=r.name),l.onchange=h=>{i=h.target.value},a.append(c,d),o.append(a),ve.show({content:o,header:t==="update"?"Update Folder":"Create Folder",confirmButtonText:t==="create"?"Save":"Update",dialogContentStyle:{minWidth:"35rem",padding:"10px"},showFooter:!0,showCloseBtn:!0,onConfirm:()=>{t==="create"?this._createFolder(i):this._updateFolder(i,r),ve.hide()}})})}updateWindowObject(e){window.ImageSalonSDK={...window.ImageSalonSDK,...e}}_initializeGrpcConfig(e,t){let r="https://hamro-cms-backend-grpc.hamrostack.com";t&&(e==="production"||e==="development")?r=t:e==="production"&&(r="https://page-api-grpc.hamropatro.com");const n=new $i({baseUrl:r});this.updateWindowObject({grpcConfig:n})}}return At=new WeakMap,Ae=new WeakMap,ke=new WeakMap,wt=new WeakMap,we=new WeakMap,Ie=new WeakMap,tt=new WeakMap,je=new WeakMap,Dt=new WeakMap,kt=new WeakMap,ot=new WeakMap,nt=new WeakMap,Ft=new WeakMap,Wt=new WeakMap,Qn=new WeakMap,Nt=new WeakMap,It=new WeakMap,yt=new WeakMap,Mt=new WeakMap,at=new WeakMap,lt=new WeakMap,Tt=new WeakMap,Lt=new WeakMap,bt=new WeakMap,jt=new WeakMap,on=new WeakMap,Se=new WeakMap,Ct=new WeakMap,an=new WeakMap,Un=new WeakMap,ln=new WeakMap,ct=new WeakMap,qt=new WeakMap,Ut=new WeakMap,xt=new WeakMap,Zt=new WeakMap,Kt=new WeakMap,zt=new WeakMap,Xt=new WeakMap,cn=new WeakMap,dn=new WeakMap,Gt=new WeakMap,dt=new WeakMap,Jt=new WeakMap,Ks});
120
+ `,r.textContent="Looks Empty!"),e.append(t,r),E(this,ke).appendChild(e)}_renderLoadingUI(){const e=K("skeleton");e.innerHTML="",E(this,ke).appendChild(e)}_fileCardBody(e){var ft,Qt,xn,Yt;const t=K("selected-image-content"),r=K("selected-image-top-bar"),n=We("","selected-image-btn","",!1,'<svg width="20px" height="20px" viewBox="0 0 20 20" focusable="false" fill="currentColor"><path fill="none" d="M0 0h20v20H0V0z"></path><path d="M10 6c.82 0 1.5-.68 1.5-1.5S10.82 3 10 3s-1.5.67-1.5 1.5S9.18 6 10 6zm0 5.5c.82 0 1.5-.68 1.5-1.5s-.68-1.5-1.5-1.5-1.5.68-1.5 1.5.68 1.5 1.5 1.5zm0 5.5c.82 0 1.5-.67 1.5-1.5 0-.82-.68-1.5-1.5-1.5s-1.5.68-1.5 1.5c0 .83.68 1.5 1.5 1.5z"></path></svg>');let i,o;(e==null?void 0:e.type)===Qe.IMAGE&&(i=Sr(e==null?void 0:e.url,"selected-image"),o=Es()),(e==null?void 0:e.type)===Qe.VIDEO&&(i=xs(e==null?void 0:e.url,"uploaded-video"),o=Fs()),(e==null?void 0:e.type)===Qe.AUDIO&&(i=_s(e==null?void 0:e.url,"uploaded-audio"),o=Cs());const a=K("selected-image-wrapper");a.setAttribute("data-key",e==null?void 0:e.key);const c=sn(e==null?void 0:e.name,"selected-image-name"),d=oe("","selected-image-type");d.append(o),r.append(d,n);const l=K();l.style.marginTop="10px",l.style.display="flex",l.style.justifyContent="space-between",l.style.alignItems="center",l.append(c),t.append(r,i),a.append(t,l);const u=K("action-wrapper"),h=We("","action-option preview"),f=oe("Preview",""),y=As();h.append(y,f);const k=We("","action-option move"),T=oe("Move",""),C=vs();k.append(C,T);const R=We("","action-option rename"),O=oe("Rename",""),F=Ur();R.append(F,O);const U=We("","action-option delete"),b=oe("Delete",""),B=_r();U.append(B,b);const m=e.name.split(".")[0],g=e.name.split(".")[1],A=rn[e.type],I=K("edit-form-wrapper"),N=K("move-form-wrapper"),L=K("preview-details-container"),v=K("preview-details-wrapper"),_=K("preview-option-image-wrapper"),w=K("preview-option-wrapper"),p=K("preview-option-wrapper"),M=K("preview-option-wrapper"),x=K("preview-option-wrapper"),V=K("preview-option-wrapper"),Z=K("preview-option-wrapper"),P=K("preview-option-wrapper"),q=Sr(e.url,"preview-option-image");_.append(q);const $=oe("File name","preview-title"),S=K("preview-option-name");S.innerHTML=e.name,w.append($,S);const X=oe("Folder name","preview-title"),ce=oe(e.folderName,"preview-option-name");p.append(X,ce);const te=oe("File Extension","preview-title"),Y=oe(g,"preview-option-name extension");M.append(te,Y);const ae=oe("File type","preview-title"),me=oe(A,"preview-option-name");x.append(ae,me);const Fe=oe("Dimension","preview-title"),Et=oe(`${(ft=e==null?void 0:e.metadata)==null?void 0:ft.width} * ${(Qt=e==null?void 0:e.metadata)==null?void 0:Qt.height}`,"preview-option-name");V.append(Fe,Et);const Ke=oe("URL","preview-title"),fe=oe(e.url,"preview-option-name url");Z.append(Ke,fe);const Le=oe("Parent folder","preview-title"),de=oe(e.nestedFolderName,"preview-option-name");P.append(Le,de),v.append(p,w,M,x,((xn=e==null?void 0:e.metadata)==null?void 0:xn.width)>0&&((Yt=e==null?void 0:e.metadata)==null?void 0:Yt.height)>0?V:"",Z,e.nestedFolderName?P:""),L.append(_,v);const re=K("form-control"),ye=document.createElement("input");re.appendChild(ye),ye.classList.add("input-field"),ye.value=e.name;const Ue=K("form-control"),be=oe("Current Folder:","input-label"),xe=K("folder-field current");xe.textContent=e.folderName,xe.prepend(nn()),Ue.append(be,xe);const ge=K("form-control"),ee=K();ee.style.width="100%",ee.style.display="flex",ee.style.alignItems="center",ee.style.justifyContent="space-between";const Ve=oe("Suggested Folder List:","input-label"),Re=oe();Re.style.display="flex",Re.style.alignItems="center",Re.style.gap="5px",Re.style.fontSize="14px",Re.textContent="Move the file in selected folder",Re.appendChild(Wn("14px","14px","#333")),ee.append(Ve,Re);const ht=K();ht.style.width="100%",ht.style.maxHeight="250px",ht.style.overflowY="auto";const Ne=document.createElement("ul");Ne.className="folders",ht.append(Ne),ge.append(ee,ht),E(this,ot).forEach(ue=>{const ze=this._renderEditFolderListContainer(ue);Ne.appendChild(ze)});const ut=K("form-control"),_e=oe("Destination Folder:","input-label"),$e=K("folder-field source","source-folder-wrapper"),De=document.createElement("span");De.id="source-folder-name",De.textContent=E(this,Ut)?E(this,Ut):e.folderName,$e.append(nn(),De);let Me="";ut.append(_e,$e),ye.onchange=ue=>{Me=ue.target.value},Me=Me!==""?Me:e.name,I.append(re),N.append(Ue,ge,ut),u.append(h,k,R,U),h.onclick=ue=>{ue.stopPropagation(),Ze.hide(),ve.show({content:L,header:m,dialogContentStyle:{minWidth:"60rem",padding:"10px"},showCloseBtn:!0})},k.onclick=ue=>{ue.stopPropagation(),Ze.hide(),ve.show({content:N,header:`Move "${e.name}"`,confirmButtonText:"Move",dialogContentStyle:{minWidth:"35rem",padding:"10px"},showCloseBtn:!0,showFooter:!0,onCancel:()=>{ve.hide()},onConfirm:()=>{this._updateFile(Me,e)}})},R.onclick=ue=>{ue.stopPropagation(),Ze.hide(),ve.show({content:I,header:"Rename",confirmButtonText:"Update",dialogContentStyle:{padding:"10px"},showCloseBtn:!0,showFooter:!0,onCancel:()=>{ve.hide()},onConfirm:()=>{this._updateFile(Me,e)}})},U.onclick=ue=>{ue.stopPropagation(),Ze.hide(),ve.show({content:"",dialogContentStyle:{minWidth:"32rem",padding:"10px"},header:`Are you sure you want to delete the file "${e.name}"?`,showFooter:!0,confirmButtonText:"Yes",cancelButtonText:"No",onConfirm:()=>{this._deleteFile(e.key)}})},n.addEventListener("click",ue=>{ue.stopPropagation(),Ze.hide(),Ze.show({content:u,mainContainer:r,divId:e.key}),H(this,Ct,e.key)}),i.addEventListener("click",()=>{const ue=E(this,we).findIndex(pt=>(pt==null?void 0:pt.key)===(e==null?void 0:e.key));if(t.classList.contains("checked"))t.classList.remove("checked"),ue!==-1&&(E(this,we).splice(ue,1),E(this,Nt)===1&&a.remove());else{if(E(this,Un))E(this,we).push(e);else{const pt=document.querySelector(".selected-image-wrapper .checked");pt==null||pt.classList.remove("checked"),H(this,we,[e])}t.classList.add("checked")}this._updateContent()}),document.addEventListener("click",ue=>{const ze=document.querySelector(`#${E(this,Ct)}`);ze&&(ue.composedPath().includes(ze)||Ze.hide())}),E(this,we).findIndex(ue=>(ue==null?void 0:ue.key)===(e==null?void 0:e.key))!==-1?(t.classList.add("checked"),E(this,bt)?E(this,ke).prepend(a):E(this,ke).appendChild(a)):E(this,ke).appendChild(a)}_renderImageCard(e){this._fileCardBody(e)}_renderImageListContainer(){var e,t;((e=E(this,Ie))==null?void 0:e.length)>0&&((t=E(this,Ie))==null||t.forEach(r=>{this._renderImageCard(r)}))}_renderSelectedImageListContainer(){var e;((e=E(this,we))==null?void 0:e.length)>0&&E(this,we).forEach(t=>{this._renderImageCard(t)})}_renderFolderListLoadingUI(){const e=document.createElement("div");e.style.paddingInline="20px";for(let t=0;t<4;t++){const r=K("skeleton");r.className="skeleton folder",r.innerHTML="",e.appendChild(r)}return e}_renderFolderListContainer(e){var o;const t=document.createElement("li");t.className="folder";const r=document.createElement("div");r.style.position="relative",r.style.display="flex",r.style.alignItems="center",r.style.gap="2px";const n=document.createElement("span"),i=document.createElement("span");if(i.className="folder-name",i.textContent=e==null?void 0:e.name,n.appendChild(nn()),r.append(n,i),t.append(r),e.children&&Object.keys(e.children).length>0){const a=document.createElement("button");a.classList.add("expand-icon"),a.appendChild(Tr()),r.prepend(a);const c=document.createElement("ul");c.className="folders nested",t.appendChild(c),a.addEventListener("click",d=>{d.stopPropagation(),t.classList.toggle("active"),c.classList.toggle("visible")}),Object.values(e.children).forEach((d,l)=>{const u=this._renderFolderListContainer(d);c.appendChild(u)})}if(e.nestedFolderName){const a=We("","folder-option-btn","moveToInputField.disabled",!1,'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-ellipsis"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></svg>'),c=K("action-wrapper"),d=We("","action-option edit"),l=oe("Edit",""),u=Ur();d.append(u,l);const h=K("edit-form-wrapper"),f=K("name-field-wrapper"),y=oe("Name","input-label"),k=document.createElement("input");k.classList.add("input-field"),k.value=e.name,k.onchange=F=>{F.target.value},f.append(y,k),h.append(f);const T={key:e.key,name:e.name,nestedFolderName:e.nestedFolderName,createdBy:e.createdBy};this._createUpdateFolderDialog(d,"update",T);const C=We("","action-option delete"),R=oe("Delete",""),O=_r();C.append(O,R),c.append(d,C),C.onclick=F=>{F.stopPropagation(),Ze.hide(),ve.show({content:"",dialogContentStyle:{minWidth:"32rem",padding:"10px"},header:`Are you sure you want to delete the folder "${e==null?void 0:e.name}"?`,showFooter:!0,confirmButtonText:"Yes",cancelButtonText:"No",onConfirm:()=>{this._deleteFolder(e.key)}})},a.addEventListener("click",F=>{F.stopPropagation();const U=document.querySelector(`#${e.key}`);H(this,Ct,null),E(this,Ct)===e.key&&U!==null?Ze.hide():(Ze.hide(),Ze.show({content:c,mainContainer:r,divId:e.key}),H(this,Ct,e.key))}),r.appendChild(a)}return t.addEventListener("click",a=>{var c;a.stopPropagation(),H(this,nt,e),H(this,kt,e==null?void 0:e.name),H(this,we,[]),H(this,Ie,[]),H(this,lt,""),H(this,Tt,!1),(c=document.querySelector(".folder.selected"))==null||c.classList.remove("selected"),t.classList.add("selected"),this._fetchFilesFromFolder(e.name)}),((o=E(this,nt))==null?void 0:o.key)===(e==null?void 0:e.key)&&t.classList.add("selected"),t}_renderEditFolderListContainer(e){var o;const t=document.createElement("li");t.className="folder-move";const r=document.createElement("div");r.style.position="relative",r.style.display="flex",r.style.alignItems="center",r.style.gap="2px";const n=document.createElement("span"),i=document.createElement("span");if(i.className="folder-name",i.textContent=e==null?void 0:e.name,n.appendChild(nn()),r.append(n,i),t.append(r),e.children&&Object.keys(e.children).length>0){const a=document.createElement("button");a.classList.add("expand-icon"),a.appendChild(Tr()),r.prepend(a);const c=document.createElement("ul");c.className="folders nested",t.appendChild(c),a.addEventListener("click",d=>{d.stopPropagation(),t.classList.toggle("active"),c.classList.toggle("visible")}),Object.values(e.children).forEach(d=>{const l=this._renderEditFolderListContainer(d);c.appendChild(l)})}return t.addEventListener("click",a=>{var d;a.stopPropagation(),H(this,Ut,e==null?void 0:e.name);const c=document.querySelector("#source-folder-name");c.textContent="",c.textContent=e==null?void 0:e.name,(d=document.querySelector(".folder-move.selected"))==null||d.classList.remove("selected"),t.classList.add("selected")}),((o=E(this,nt))==null?void 0:o.key)===(e==null?void 0:e.key)&&t.classList.add("selected"),t}_updateFolderListContainer(){if(E(this,It))if(E(this,yt).innerHTML="",E(this,Dt)){const e=this._renderFolderListLoadingUI();E(this,yt).appendChild(e)}else{const e=document.createElement("ul");e.className="folders",E(this,yt).appendChild(e),E(this,ot).forEach(t=>{const r=this._renderFolderListContainer(t);e.appendChild(r)}),E(this,It).appendChild(E(this,yt))}}_renderToastContainer(e,t,r){this._removeToastContainer(),H(this,at,document.createElement("div")),E(this,at).className=`message-container ${t}`;const n=sn(e,"message"),i=t==="success"?Lr():Wn(),o=We("");o.style.cursor="pointer",o.style.border="0",o.style.outline="none",o.style.background="transparent",o.appendChild(jn(t==="error"?"#ee3f3f":"#4caf50")),o.setAttribute("fill",t==="error"?"#ee3f3f":"#4caf50"),o.onclick=()=>this._removeToastContainer(),E(this,at).append(i,n,o),r.appendChild(E(this,at)),setTimeout(()=>{this._removeToastContainer()},5e3)}_removeToastContainer(){E(this,at)&&(E(this,at).remove(),H(this,at,null))}_updateSelectedImageListContainerUI(){var t,r;if(!E(this,ke))return;E(this,ke).innerHTML="",E(this,tt)&&this._renderLoadingUI(),E(this,je)&&this._renderFetchingSkeletonUI();const e=document.getElementById("search-input-wrapper");E(this,Nt)===0?(e&&(e.style.visibility="visible"),((t=E(this,Ie))==null?void 0:t.length)===0&&!E(this,je)?(E(this,ke).classList.add("no-selected-image-container"),this._renderEmptyImageContainer()):(E(this,ke).classList.remove("no-selected-image-container"),this._renderImageListContainer())):(e&&(e.style.visibility="hidden"),((r=E(this,we))==null?void 0:r.length)===0?(E(this,ke).classList.add("no-selected-image-container"),this._renderEmptyImageContainer()):(E(this,ke).classList.remove("no-selected-image-container"),this._renderSelectedImageListContainer())),this._updateContent()}_updateContent(){var t,r,n;const e=document.getElementById("selected-images-tab");e&&(e.textContent=`Selected (${(t=E(this,we))==null?void 0:t.length})`),E(this,Ft).textContent=`Save (${(r=E(this,we))==null?void 0:r.length})`,E(this,Ft).disabled=((n=E(this,we))==null?void 0:n.length)===0}async _uploadAndAddSelectedImageList(e,t){var r,n;this._updateSelectedImageListContainerUI();try{const i=await Gr(e,t,E(this,Se)),o=await ts(t==null?void 0:t.name,"",i,Qe[Zn((r=t.type)==null?void 0:r.split("/")[0])],(n=E(this,nt))==null?void 0:n.name,E(this,Se));E(this,Ie).unshift(o==null?void 0:o.response),this._renderToastContainer("File Uploaded Successfully","success",E(this,Ae))}catch{this._renderToastContainer("Something went wrong while uploading file. Please try again later.","error",E(this,Ae))}finally{H(this,tt,!1),this._updateSelectedImageListContainerUI()}}async _updateFile(e,t){ve.updateUploadBtn(!0);try{const r=await os(t.key,e,t.nestedFolderName,t.url,t.thumborUrl,t.proxyUrl,t.type,E(this,Ut),E(this,Se)),n=E(this,Ie).find(i=>i.key===r.response.key);n.name=e,this._fetchFilesFromFolder(E(this,nt).name),H(this,Ie,[]),H(this,we,[]),this._renderToastContainer("File Updated Successfully","success",E(this,Ae))}catch{this._renderToastContainer("Something went wrong while updating the file. Please try again later.","error",E(this,Ae))}finally{ve.updateUploadBtn(!1),ve.hide(),this._updateSelectedImageListContainerUI()}}async _deleteFile(e){ve.updateUploadBtn(!0);try{await as(e,E(this,Se)),H(this,Ie,E(this,Ie).filter(t=>e!==t.key)),this._renderToastContainer("File Deleted Successfully","success",E(this,Ae))}catch{this._renderToastContainer("Something went wrong while deleting the file. Please try again later.","error",E(this,Ae))}finally{ve.updateUploadBtn(!1),ve.hide(),this._updateSelectedImageListContainerUI()}}async _createFolder(e,t=2){var r;try{const n=await ws(e,(r=E(this,nt))==null?void 0:r.name,"",E(this,Se));H(this,we,[]),H(this,Ie,[]);const i=Ls(E(this,ot),n==null?void 0:n.response);H(this,ot,i),H(this,kt,e),H(this,nt,{...n==null?void 0:n.response,children:{}}),this._fetchFilesFromFolder(e),this._renderToastContainer(`Folder ${e} created successfully`,"success",E(this,Ae))}catch{if(t>1)this._createFolder(e,--t);else throw this._renderToastContainer(`Error creating folder "${e}". Either folder already exist or failed to create folder`,"error",E(this,Ae)),new Error(`Error creating folder "${e}". Either folder already exist or failed to create folder`)}finally{this._updateFolderListContainer()}}async _upload(){return E(this,ln)?E(this,we):E(this,qt)}async _uploadFromSource(e,t){this._removeUserToast();const r=200*1024;try{const n=e.size>r?await Qr(e):e;return await new Promise((o,a)=>{const c=new FileReader;c.readAsDataURL(n),c.onerror=()=>{a(c.error)},c.onload=async()=>{var d;try{const l=await qs(c.result,n,t,!1,E(this,xt)),u=await rs(l,Qe[Zn((d=n.type)==null?void 0:d.split("/")[0])],t,E(this,xt));o(u)}catch(l){a(l)}}})}catch(n){throw n}}_uploadingState(){return E(this,tt)}async _fetchFilesFromFolder(e){var t,r,n;H(this,je,!0),this._updateSelectedImageListContainerUI();try{const i=await is(e,E(this,lt),20,E(this,Se)),o=(t=i.response)==null?void 0:t.files;E(this,Ie).push(...o),H(this,lt,(r=i.response)==null?void 0:r.nextCursor),H(this,Tt,(n=i.response)==null?void 0:n.hasMore)}catch{throw this._renderToastContainer("Error while fetching files from folder"+e,"error",E(this,Ae)),new Error("Something went wrong. Error while fetching files from folder"+e)}finally{H(this,je,!1),this._updateSelectedImageListContainerUI()}}async _fetchAllFolders(){var e,t;H(this,je,!0),H(this,Dt,!0),this._updateSelectedImageListContainerUI(),this._updateFolderListContainer(),this._removeToastContainer();try{const n=(await gs("",200,E(this,Se))).response.folder,i=Ts(n);H(this,kt,(e=i[0])==null?void 0:e.name),this._fetchFilesFromFolder((t=i[0])==null?void 0:t.name),H(this,nt,i[0]),H(this,ot,i)}catch{H(this,je,!1),this._renderToastContainer("Folder not found. Please create a folder or try again later","error",E(this,Ae))}finally{H(this,Dt,!1),this._updateFolderListContainer()}}async _search(e){var t,r;H(this,je,!0),this._updateSelectedImageListContainerUI(),this._removeToastContainer();try{const n=await ss(e,E(this,lt),10,E(this,Se)),i=(t=n.response)==null?void 0:t.items;E(this,Ie).push(...i),H(this,lt,(r=n.response)==null?void 0:r.nextPageCursor)}catch{this._renderToastContainer("Error while searching files","error",E(this,Ae))}finally{H(this,je,!1),this._updateSelectedImageListContainerUI()}}async _updateFolder(e,t){ve.updateUploadBtn(!0);try{const r=await ys(t.key,e,t.nestedFolderName,t.createdBy,E(this,Se))}catch{throw this._renderToastContainer("Something went wrong while updating the folder. Please try again later.","error",E(this,Ae)),new Error("Error updating the folder ")}finally{ve.updateUploadBtn(!1),ve.hide(),this._updateFolderListContainer()}}async _deleteFolder(e){ve.updateUploadBtn(!0);try{await bs(e,E(this,Se)),H(this,ot,E(this,ot).filter(t=>t.key!==e)),this._renderToastContainer("Folder Deleted Successfully","success",E(this,Ae))}catch{throw this._renderToastContainer("Something went wrong while deleting the folder. Please try again later.","error",E(this,Ae)),new Error("Error deleting the folder ")}finally{ve.updateUploadBtn(!1),ve.hide(),this._updateFolderListContainer()}}_createUpdateFolderDialog(e,t,r){e.addEventListener("click",n=>{n.stopPropagation(),Ze.hide();let i;const o=K("edit-form-wrapper"),a=K("form-control"),c=oe("Folder Name","input-label"),d=K();d.style.position="relative";const l=document.createElement("input");l.style.paddingLeft="40px";const u=oe();u.appendChild(nn()),u.style.position="absolute",u.style.top="50%",u.style.left="5%",u.style.transform="translate(-40%, -40%)",l.classList.add("input-field"),d.append(l,u),t==="update"&&(l.value=r.name),l.onchange=h=>{i=h.target.value},a.append(c,d),o.append(a),ve.show({content:o,header:t==="update"?"Update Folder":"Create Folder",confirmButtonText:t==="create"?"Save":"Update",dialogContentStyle:{minWidth:"35rem",padding:"10px"},showFooter:!0,showCloseBtn:!0,onConfirm:()=>{t==="create"?this._createFolder(i):this._updateFolder(i,r),ve.hide()}})})}updateWindowObject(e){window.ImageSalonSDK={...window.ImageSalonSDK,...e}}_initializeGrpcConfig(e,t){let r="https://hamro-cms-backend-grpc.hamrostack.com";t&&(e==="production"||e==="development")?r=t:e==="production"&&(r="https://page-api-grpc.hamropatro.com");const n=new $i({baseUrl:r});this.updateWindowObject({grpcConfig:n})}}return At=new WeakMap,Ae=new WeakMap,ke=new WeakMap,wt=new WeakMap,we=new WeakMap,Ie=new WeakMap,tt=new WeakMap,je=new WeakMap,Dt=new WeakMap,kt=new WeakMap,ot=new WeakMap,nt=new WeakMap,Ft=new WeakMap,Wt=new WeakMap,Qn=new WeakMap,Nt=new WeakMap,It=new WeakMap,yt=new WeakMap,Mt=new WeakMap,at=new WeakMap,lt=new WeakMap,Tt=new WeakMap,Lt=new WeakMap,bt=new WeakMap,jt=new WeakMap,on=new WeakMap,Se=new WeakMap,Ct=new WeakMap,an=new WeakMap,Un=new WeakMap,ln=new WeakMap,ct=new WeakMap,qt=new WeakMap,Ut=new WeakMap,xt=new WeakMap,Zt=new WeakMap,Kt=new WeakMap,zt=new WeakMap,Xt=new WeakMap,cn=new WeakMap,dn=new WeakMap,Gt=new WeakMap,dt=new WeakMap,Jt=new WeakMap,Ks});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "image-salon-sdk",
3
- "version": "1.0.71",
3
+ "version": "1.0.73",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [