(self.webpackChunkhws_provider_media=self.webpackChunkhws_provider_media||[]).push([[262],{721:function(){},2043:function(e,t,a){"use strict";a.d(t,{j:function(){return r}});let i={GetStorageInfo:{action:"HWS_PROVIDER_MEDIA_GET_MEDIA_STORAGE_INFO",description:"Get the media storage info",inputInterface:"",example:{}},GetMediaByType:{action:"HWS_PROVIDER_MEDIA_GET_MEDIA_BY_TYPE",description:"Get the media by type",inputInterface:`interface GetMediaByType {
      MediaType: string;
    }`,example:{MediaType:"Image"}},GetMediaByTypes:{action:"HWS_PROVIDER_MEDIA_GET_MEDIA_BY_TYPES",description:"Get the media by type",inputInterface:`interface GetMediaByTypes {
      MediaType: string;
    }`,example:{MediaTypes:["Image"]}},GetLookups:{action:"HWS_PROVIDER_MEDIA_GET_LOOKUPS",description:"Get the media lookups",inputInterface:"",example:{}},DeleteMedia:{action:"HWS_PROVIDER_MEDIA_DELETE_MEDIA",description:"Delete media",inputInterface:`interface DeleteMedia {
      Id: string;
    }`,example:{Id:"1"}},GetDownloadUrl:{action:"HWS_PROVIDER_MEDIA_GET_DOWNLOAD_URL",description:"Get the media download url",inputInterface:`interface GetDownloadUrl {
      Media: string;
    }`,example:{Media:"1"}},Download:{action:"HWS_PROVIDER_MEDIA_DOWNLOAD",description:"Download media file bytes",inputInterface:`interface DownloadMedia {
      Id: string;
    }`,example:{Id:"1"},protocol:"HttpRest",route:"/media/{id}",responseType:"blob"},UploadMedia:{action:"HWS_PROVIDER_MEDIA_UPLOAD_MEDIA",description:"Upload media",inputInterface:`interface UploadMedia {
      Request: MediaUploadRequest;
    }`,example:{MediaId:"1",FileName:"1",Title:"1",Caption:"1",Description:"1",FormFile:"1",Path:"1",MediaSource:"1",MediaType:"1"}},GetMediaCount:{action:"HWS_PROVIDER_MEDIA_GET_MEDIA_COUNT",description:"Get the media count",inputInterface:`interface GetMediaCount {
      FilterText?: string | null;
      MediaType?: string | null;
    }`,example:{FilterText:"1",MediaType:"1"}},GetMedia:{action:"HWS_PROVIDER_MEDIA_GET_MEDIA",description:"Get the media",inputInterface:`interface GetMedia {
      FilterText?: string | null;
      MediaType?: string | null;
      SelectSettings: {
        PageSize?: number;
        Page?: number;
        OrderBy?: string | null;
        OrderDescendingBy?: string | null;
      }
    }`,example:{FilterText:"1",MediaType:"1",SelectSettings:{PageSize:1,Page:1,OrderBy:"1",OrderDescendingBy:"1"}}}};var n=a(6701);class r{static async getMediaCount(e,t){return await (0,n.XE)(i.GetMediaCount.action,{FilterText:e,MediaType:t})}static async getMedia(e,t,a,r,s,l){return await (0,n.XE)(i.GetMedia.action,{FilterText:e,MediaType:t,SelectSettings:{PageSize:a,Page:r,OrderBy:s,OrderDescendingBy:l}})}static async getLookups(){return await (0,n.XE)(i.GetLookups.action,null)}static async getDownloadUrl(e){return await (0,n.XE)(i.GetDownloadUrl.action,{Media:e})}static async getMediaByType(e){return await (0,n.XE)(i.GetMediaByType.action,{MediaType:e})}static async getMediaByTypes(e){return await (0,n.XE)(i.GetMediaByTypes.action,{MediaTypes:e})}static async upload(e,t){let a=new FormData;return a.append("MetaData",JSON.stringify({FileName:e})),a.append("FormFile",t),a.append("Action",i.UploadMedia.action),await (0,n.EA)(a)}async update(e,t){let a=new FormData;return a.append("MetaData",JSON.stringify(e)),null!=t&&a.append("FormFile",t),a.append("Action",i.UploadMedia.action),await (0,n.EA)(a)}static async getStorageInfo(){return await (0,n.XE)(i.GetStorageInfo.action,null)}static async delete(e){return await (0,n.XE)(i.DeleteMedia.action,{Id:e})}static async download(e){try{return await (0,n.XE)(i.Download.action,{Id:e},{protocol:"HttpRest"})}catch(e){return e}}}},2811:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return P}});var i=a(1995),n=a(6135),r=a(6141),s=a(9434),l=a.n(s),o=a(68),d=a(5905),c=a(8578),u=a(707),p=a(7068),x=a(8160),m=a(5985),h=a(4056),y=a(4421),g=a(3859),f=a(2047),j=a.n(f),D=a(4221),I=a(2043);let S=e=>{let{onClose:t,open:a,setRefresh:s,setSelectedMedia:o,setMediaType:m=[],...h}=e,{enqueueSnackbar:f}=(0,D.useSnackbar)(),[S,A]=l().useState(!1),[E,v]=l().useState(),[M,w]=l().useState(),_=e=>window?.HWS?.I18n?.t(e)??e,b=async e=>{w(e.target.files[0]),v(e.target.files[0].name)},N=async()=>{A(!0);try{let e=await I.j.upload(E,M);e.Success&&(s(!0),o&&o(e.Data),t()),A(!1)}catch(e){f(e.message||"An error occurred",{variant:"error"}),A(!1)}};return(0,i.jsxs)(d.A,{sx:{"& .MuiDialog-paper":{width:"60%",maxHeight:420}},open:a,...h,children:[(0,i.jsx)(p.A,{children:(0,i.jsxs)("div",{style:{display:"flex"},children:[_("HWS_PROVIDER_MEDIA_UPLOAD_MEDIA"),(0,i.jsx)("div",{style:{flex:"1 1 auto"}}),(0,i.jsx)(y.A,{className:"min-w-auto",size:"small",color:"primary",onClick:()=>{t()},children:(0,i.jsx)(n.A,{children:"cancel"})})]})}),(0,i.jsx)(u.A,{dividers:!0,style:{display:"flex",flexDirection:"column"},children:(0,i.jsxs)(i.Fragment,{children:[null!=M&&(0,i.jsx)(j(),{type:"file",file:M}),(0,i.jsx)(g.A,{className:"mb-16",label:"FormFile",autoFocus:!0,type:"file",inputProps:{accept:(()=>{if(!Array.isArray(m)||0===m.length)return"";let e={Image:"image/*",Video:"video/*",Audio:"audio/*",Document:".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt",Archive:".zip,.rar,.7z,.tar,.gz",Other:".exe,.apk,.iso"};return m.filter(t=>e[t]).map(t=>e[t]).join(",")})(),onChange:e=>{b(e)}},variant:"outlined",required:!1,fullWidth:!0,disabled:S})]})}),(0,i.jsxs)(c.A,{style:{alignSelf:"flex-end"},children:[(0,i.jsx)(x.A,{variant:"outlined",color:"primary",className:"w-150",onClick:t,children:_("HWS_PROVIDER_MEDIA_MEDIA_CANCEL")}),(0,i.jsxs)(x.A,{onClick:()=>{N()},variant:"outlined",color:"success",className:"w-150",disabled:S,children:[S&&(0,i.jsx)(r.A,{size:"2rem"}),_("HWS_PROVIDER_MEDIA_UPLOAD")]})]})]})};a(721);var A=a(5833),E=a(7508),v=a(6731),M=a(2576),w=a(3519);let _={image:"Image",video:"Video",audio:"Audio",document:"Document",other:"Other",archive:"Archive",database:"HWS_PLUGIN_MEDIA_DATABASE",bunny:"HWS_PLUGIN_MEDIA_BUNNY"},b=e=>{let{row:t,mediaTypes:a,mode:n}=e,r=(()=>{let e=a.find(e=>e.Id===t.MediaType);return e?e.Name:"Unknown"})(),s=t.MediaSource?t.MediaSource:"Unknown";if(r===_.image){if(s===_.database&&t.Data){if(0===t.Data.length)return t.Name;let e=t.Data;return(e=>{try{return window.atob(e),!0}catch(e){return!1}})(t.Data)||(e=window.btoa(new Uint8Array(t.Data).reduce(function(e,t){return e+String.fromCharCode(t)},""))),(0,i.jsx)("div",{className:"media-container",children:(0,i.jsx)("img",{src:`data:image/jpeg;base64,${e}`,className:"max-w-[162px] max-h-[162px] object-contain",style:{width:"auto",height:"auto",alignSelf:"center"}})})}return s===_.bunny&&t.URL?(0,i.jsx)("div",{className:"media-container",children:(0,i.jsx)("img",{src:t.URL,className:"max-w-[162px] max-h-[162px] object-contain",style:{width:"auto",height:"auto",alignSelf:"center"}})}):t.Name}return r===_.document?(0,i.jsxs)("div",{className:"media-container",children:[(0,i.jsx)("div",{className:"media-img-container ",children:(0,i.jsx)(v.A,{style:{fontSize:"80px"}})}),(0,i.jsx)("div",{className:"media-container-span",children:(0,i.jsx)("div",{className:"text-container",children:(0,i.jsx)("span",{children:t.Name})})})]}):r===_.audio?(0,i.jsxs)("div",{className:"media-container",children:[(0,i.jsx)("div",{className:"media-img-container ",children:(0,i.jsx)(A.A,{style:{fontSize:"80px"}})}),(0,i.jsx)("div",{className:"media-container-span",children:(0,i.jsx)("div",{className:"text-container",children:(0,i.jsx)("span",{children:t.Name})})})]}):r===_.video?(0,i.jsxs)("div",{className:"media-container",children:[(0,i.jsx)("div",{className:"media-img-container ",children:(0,i.jsx)(E.A,{style:{fontSize:"80px"}})}),(0,i.jsx)("div",{className:"media-container-span",children:(0,i.jsx)("div",{className:"text-container",children:(0,i.jsx)("span",{children:t.Name})})})]}):r===_.archive?(0,i.jsxs)("div",{className:"media-container",children:[(0,i.jsx)("div",{className:"media-img-container ",children:(0,i.jsx)(w.A,{style:{fontSize:"80px"}})}),(0,i.jsx)("div",{className:"media-container-span",children:(0,i.jsx)("div",{className:"text-container",children:(0,i.jsx)("span",{children:t.Name})})})]}):r===_.other?(0,i.jsxs)("div",{className:"media-container",children:[(0,i.jsx)("div",{className:"media-img-container ",children:(0,i.jsx)(M.A,{style:{fontSize:"80px"}})}),(0,i.jsx)("div",{className:"media-container-span",children:(0,i.jsx)("div",{className:"text-container",children:(0,i.jsx)("span",{children:t.Name})})})]}):(0,i.jsxs)("div",{className:"media-container",children:[(0,i.jsx)("div",{className:"media-img-container ",children:(0,i.jsx)(M.A,{style:{fontSize:"80px"}})}),(0,i.jsx)("div",{className:"media-container-span",children:(0,i.jsx)("div",{className:"text-container",children:(0,i.jsx)("span",{children:t.Name})})})]})};var N=a(6701);let R=e=>{let{media:t,types:a=[],mediaTypes:r=[],onChange:l,onClose:o,open:y,...g}=e,[f,j]=(0,s.useState)([]),[D,A]=(0,s.useState)(!0),[E,v]=(0,s.useState)(null),[M,w]=(0,s.useState)(t),[_,R]=(0,s.useState)(!1);(0,s.useEffect)(()=>{T()},[]),(0,s.useEffect)(()=>{w(t)},[t]);let T=async()=>{A(!0);let e=[],t=a;t&&0!==t.length||(t=r.map(e=>e.Name));let i=await I.j.getMediaByTypes(t);i.Success&&i.Data&&(e=i.Data),j(e.length>0?e:[]),A(!1)},C=e=>window?.HWS?.I18n?.t(e)??e;return(0,s.useEffect)(()=>{E&&T()},[E]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(d.A,{sx:{"& .MuiDialog-paper":{width:"100%",maxHeight:"100%"}},open:y,...g,children:[(0,i.jsx)(p.A,{children:(0,i.jsxs)("div",{className:"flex flex-row",children:[(0,i.jsx)("div",{children:C("HWS_PROVIDER_MEDIA_SELECT_MEDIA")}),(0,i.jsx)("div",{style:{flex:"1 1 auto"}}),(0,i.jsx)("div",{style:{display:"flex",alignItems:"center"},children:(0,i.jsxs)(x.A,{onClick:()=>{R(!0)},variant:"outlined",color:"success",className:"w-150",children:[(0,i.jsx)(n.A,{children:"upload"}),C("HWS_PROVIDER_MEDIA_UPLOAD")]})})]})}),(0,i.jsx)(u.A,{dividers:!0,style:{display:"flex",flexDirection:"column"},children:D?(0,i.jsx)(N.Eb,{}):(0,i.jsxs)(i.Fragment,{children:[(null===t||f&&0===f.length)&&(0,i.jsx)(h.motion.div,{initial:{opacity:0},animate:{opacity:1,transition:{delay:.1}},className:"flex flex-1 items-center justify-center h-full",children:(0,i.jsx)("div",{style:{fontSize:"16px",color:"#888"},children:C("No such type media is uploaded")})}),f&&f.length>0&&(0,i.jsx)("div",{style:{display:"flex",flexWrap:"wrap",width:"550px",justifyContent:"center"},children:f.map((e,t)=>(0,i.jsx)("div",{style:{margin:"5px"},children:(0,i.jsxs)(m.A,{className:`image-list-item ${M===e.Id?"selected":""}`,onClick:t=>{t.stopPropagation(),w(e.Id)},style:{border:M===e.Id?"2px solid blue":"1px solid gray",borderRadius:"5px",cursor:"pointer",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",backgroundColor:"#f9f9f9",overflow:"hidden",height:"150px"},children:[b({row:e,mediaTypes:r,mode:"grid"}),(0,i.jsx)("div",{style:{margin:"5px",textAlign:"center",fontSize:"12px",color:"#333",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",width:"100%"},children:e.Name})]},e.Id)},e.Id))})]})}),(0,i.jsxs)(c.A,{style:{alignSelf:"flex-end"},children:[(0,i.jsx)(x.A,{variant:"outlined",color:"primary",className:"w-150",onClick:o,disabled:_,children:C("HWS_PROVIDER_MEDIA_MEDIA_CANCEL")}),(0,i.jsx)(x.A,{onClick:()=>{l(f.find(e=>e.Id===M)??M),o()},variant:"outlined",color:"success",disabled:_||!M||0==f.length,className:"w-150",children:C("HWS_PROVIDER_MEDIA_SELECT")})]})]}),_&&(0,i.jsx)(S,{setMediaType:a,setRefresh:v,open:_,onClose:()=>{R(!1)},setSelectedMedia:w})]})};var T=a(2372),C=a(8641);let O=e=>{let t,{field:a,column:l,disabled:o,errors:d,isDependencyRequired:c,onChangeProp:u,mediaTypesState:p,mediaTypes:x,isDialogOpen:m,openDialog:h,closeDialog:y}=e,[g,f]=(0,s.useState)(null),[j,D]=(0,s.useState)(!1),[S,b]=(0,s.useState)(!1),N=(0,s.useRef)(null),O=(0,s.useCallback)(async e=>{D(!0);try{let t=x;t&&0!==t.length||(t=p.map(e=>e.Name));let a=await I.j.getMediaByTypes(t);if(a.Success&&a.Data){let t=a.Data.find(t=>t.Id===e);f(t??null)}else f(null)}catch{f(null)}finally{D(!1)}},[x,p]);(0,s.useEffect)(()=>{if(!a.value){f(null),N.current=null;return}N.current!==a.value&&(N.current=a.value,O(a.value))},[a.value,O]);let P=e=>{let t="object"==typeof e&&e?.Id,i=t?e.Id:e??"";a.onChange(i),t?(N.current=i,f(e)):(N.current=null,f(null)),u&&u({name:l.Name,value:i})},k=e=>{if(!e||!p.length)return null;let t=p.find(t=>t.Id===e.MediaType);return t?.Name??null},G=e=>{try{return window.atob(e),!0}catch{return!1}},F=!!a.value,H=!!d[l.Name],W=l.IsRequired??c,z=l.I18n?(t=l.I18n,window?.HWS?.I18n?.t(t)??t):l.Label??l.Name,L=H?"#d32f2f":S&&!o?"#1976d2":"rgba(0,0,0,0.23)";return(0,i.jsxs)("div",{style:{marginBottom:"16px",marginTop:"5px"},children:[(0,i.jsxs)("div",{onClick:o?void 0:h,onMouseEnter:()=>b(!0),onMouseLeave:()=>b(!1),style:{position:"relative",border:`1px solid ${L}`,borderStyle:F?"solid":"dashed",borderRadius:"8px",cursor:o?"default":"pointer",backgroundColor:o?"rgba(0,0,0,0.04)":S&&!F?"rgba(25,118,210,0.04)":"transparent",transition:"border-color 0.2s, background-color 0.2s"},children:[(0,i.jsxs)("span",{style:{position:"absolute",top:"-9px",left:"12px",background:o?"transparent":"white",padding:"0 4px",fontSize:"12px",color:H?"#d32f2f":S&&!o?"#1976d2":"rgba(0,0,0,0.6)",lineHeight:1,pointerEvents:"none",userSelect:"none",transition:"color 0.2s",zIndex:1},children:[z,W&&" *"]}),F?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{style:{width:"100%",height:"160px",display:"flex",alignItems:"center",justifyContent:"center",padding:"10px",boxSizing:"border-box",borderRadius:"8px 8px 0 0",overflow:"hidden",backgroundColor:"#f7f7f7"},children:j?(0,i.jsx)(r.A,{size:32}):g&&(e=>{let t={fontSize:"52px",color:"#bbb"},a=k(e),n=e?.MediaSource??"",r={width:"100%",height:"100%",objectFit:"contain",display:"block"};if(a===_.image){if(n===_.database&&e.Data&&e.Data.length>0){let t=e.Data;return G(t)||(t=window.btoa(new Uint8Array(t).reduce((e,t)=>e+String.fromCharCode(t),""))),(0,i.jsx)("img",{src:`data:image/jpeg;base64,${t}`,style:r,alt:e.Name})}if(e.URL)return(0,i.jsx)("img",{src:e.URL,style:r,alt:e.Name})}return a===_.document?(0,i.jsx)(v.A,{style:t}):a===_.audio?(0,i.jsx)(A.A,{style:t}):a===_.video?(0,i.jsx)(E.A,{style:t}):a===_.archive?(0,i.jsx)(w.A,{style:t}):(0,i.jsx)(M.A,{style:t})})(g)}),g?.Name&&(0,i.jsx)("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(0,0,0,0.08)",backgroundColor:"rgba(0,0,0,0.02)",borderRadius:"0 0 8px 8px",display:"flex",alignItems:"center"},children:(0,i.jsx)("span",{style:{fontSize:"12px",color:"rgba(0,0,0,0.5)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.Name})}),S&&!o&&(0,i.jsxs)("div",{style:{position:"absolute",inset:0,background:"rgba(0,0,0,0.4)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"6px",color:"white",borderRadius:"7px"},children:[(0,i.jsx)(C.A,{style:{fontSize:"22px"}}),(0,i.jsx)("span",{style:{fontSize:"13px",fontWeight:500},children:"Click to change"})]}),!o&&(0,i.jsx)("div",{onClick:e=>{e.stopPropagation(),P("")},onMouseEnter:e=>e.currentTarget.style.background="rgba(211,47,47,0.9)",onMouseLeave:e=>e.currentTarget.style.background="rgba(0,0,0,0.5)",style:{position:"absolute",top:"6px",right:"6px",width:"22px",height:"22px",borderRadius:"50%",background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2,transition:"background 0.15s"},children:(0,i.jsx)(n.A,{style:{fontSize:"14px",color:"white",lineHeight:1},children:"close"})})]}):(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"8px",padding:"24px 12px",color:S?"#1976d2":"rgba(0,0,0,0.35)",transition:"color 0.2s"},children:[(0,i.jsx)(T.A,{style:{fontSize:"32px"}}),(0,i.jsx)("span",{style:{fontSize:"13px"},children:"Click to select media"})]})]}),m&&(0,i.jsx)(R,{types:x,media:a.value,mediaTypes:p,onChange:e=>P(e),open:m,onClose:y})]})};var P=e=>{let{column:t,control:a,mediaTypes:n,disabled:r,errors:l,isDependencyRequired:d,onChange:c}=e,[u,p]=(0,s.useState)(!1),[x,m]=(0,s.useState)([]);return((0,s.useEffect)(()=>{(async()=>{let e=await I.j.getLookups();e.Success&&e.Data&&m(e.Data.HWS_PROVIDER_MEDIA_MEDIA_TYPES??[])})()},[]),t)?(0,i.jsx)(o.Controller,{name:t.Name,control:a,defaultValue:"",render:e=>{let{field:a}=e;return(0,i.jsx)(O,{field:a,column:t,disabled:r,errors:l,isDependencyRequired:d,onChangeProp:c,mediaTypesState:x,mediaTypes:n,isDialogOpen:u,openDialog:()=>p(!0),closeDialog:()=>p(!1)})}}):(0,i.jsx)("p",{children:(0,i.jsx)("em",{children:"Loading..."})})}},6701:function(e,t,a){"use strict";function i(e){let t=window;if(!t.core||!t.core[e]){console.warn(`[coreExports] window.core.${String(e)} not ready`);return}return t.core[e]}a.d(t,{EA:function(){return r},Eb:function(){return n},XE:function(){return s}}),i("Error404Page"),i("FusePageCarded");let n=i("FuseLoading");i("FuseDialog"),i("FuseSvgIcon"),i("FusePageSimple"),i("FuseSplashScreen"),i("NavLinkAdapter"),i("Store"),i("UnAuthorized"),i("useThemeMediaQuery"),i("ErrorBoundary"),i("FuseLayout"),i("FuseTheme"),i("ThemeLayouts"),i("BrowserRouter"),i("FuseUtils"),i("WithRouter"),i("History"),i("HUIDynamic"),i("HWSRoutes"),i("HWSContext"),i("HorizechWorkspaceProvider"),i("useHorizechWorkspace"),i("RunAction");let r=i("RunFormAction"),s=i("InvokeAction");i("APIResult")}}]);