import{cg as e,b$ as t,c0 as a,ci as i,cj as c,c4 as r,l as o,c6 as s,ck as n,cl as l,cm as d,cn as p,bS as f,co as u,cp as m,cq as y,c8 as h,c9 as g,ca as w,ce as _,ch as b}from"./card-555679fd.js";import{C as M}from"./engine-e412e9a0.js";import{p as x}from"./index-af8cf05c.js";import{GenericCameraManagerEngine as k}from"./engine-generic-395b8c68.js";import{V as G,a as v}from"./media-b0eb3f2a.js";class C extends G{constructor(t,a,i){super(t,a),this._browseMedia=i,i._metadata?.startDate?this._id=`${a}/${e(i._metadata.startDate,"yyyy-MM-dd HH:mm:ss")}`:this._id=i.media_content_id}getStartTime(){return this._browseMedia._metadata?.startDate??null}getEndTime(){return null}getVideoContentType(){return v.MP4}getID(){return this._id}getContentID(){return this._browseMedia.media_content_id}getTitle(){const e=this.getStartTime();return e?t(e):this._browseMedia.title}getThumbnail(){return this._browseMedia.thumbnail}getWhat(){return null}getScore(){return null}getTags(){return null}isGroupableWith(e){return this.getMediaType()===e.getMediaType()&&a(this.getWhere(),e.getWhere())&&a(this.getWhat(),e.getWhat())}}class D{static createEventViewMedia(e,t,a){return new C(e,a,t)}}const E=(e,t,a)=>{const i=t??a;return!i||!!e._metadata&&p({start:e._metadata.startDate,end:e._metadata.endDate},{start:t??i,end:a??i})};class S extends k{constructor(e,t,a){super(),this._cameraEntities=new Map,this._browseMediaManager=e,this._resolvedMediaCache=t,this._requestCache=a}async initializeCamera(e,t,a){const i=a.camera_entity?await t.getEntity(e,a.camera_entity):null;if(!i||!a.camera_entity)throw new r(o("error.no_camera_entity"),a);return this._cameraEntities.set(a.camera_entity,i),a}generateDefaultEventQuery(e,t,a){return[{type:s.Event,cameraIDs:t,...a}]}async getMediaDownloadPath(e,t,a){const i=a.getContentID();if(!i)return null;const c=await n(e,i,this._resolvedMediaCache);return c?{endpoint:l(e,c.url)}:null}getQueryResultMaxAge(e){return e.type===s.Event?d:null}getCameraCapabilities(e){const t=super.getCameraCapabilities(e);return t?{...t,supportsClips:!0,supportsSnapshots:!0,supportsTimeline:!0}:null}getMediaCapabilities(e){return{canFavorite:!1,canDownload:!0}}}class T{static isMotionEyeEventQueryResults(e){return e.engine===f.MotionEye&&e.type===g.Event}}const F={"%Y":"yyyy","%m":"MM","%d":"dd","%H":"HH","%M":"mm","%S":"ss"},B=new RegExp(/(%Y|%m|%d|%H|%M|%S)/g);class z extends S{getEngineType(){return f.MotionEye}_convertMotionEyeTimeFormatToDateFNS(e){return e.replace(B,((e,t)=>F[t]))}_motionEyeMetadataGeneratorFile(e,t,a,i){let c=i?._metadata?.startDate??new Date;if(t){const e=a.title.replace(/\.[^/.]+$/,"");if(c=x(e,t,c),!u(c))return null}return{cameraID:e,startDate:c,endDate:c}}_motionEyeMetadataGeneratorDirectory(e,t,a,i){let c=i?._metadata?.startDate??new Date;if(t){const e=x(a.title,t,c);if(!u(e))return null;c=m(e)}return{cameraID:e,startDate:c,endDate:i?._metadata?.endDate??y(c)}}async _getMatchingDirectories(e,t,a,i,c){const r=t.get(a)?.camera_entity,o=r?this._cameraEntities.get(r):null,s=o?.config_entry_id,n=o?.device_id,l=t.get(a);if(!s||!n||!l)return null;const d=(e,t)=>{const c=e.shift();if(!c)return[];const r=c.includes("%")?this._convertMotionEyeTimeFormatToDateFNS(c):null;return[{targets:t,metadataGenerator:(e,t)=>this._motionEyeMetadataGeneratorDirectory(a,r,e,t),matcher:e=>e.can_expand&&(!!r||e.title===c)&&E(e,i?.start,i?.end),advance:t=>d(e,t)}]};return await this._browseMediaManager.walkBrowseMedias(e,[...!1===i?.hasClip||i?.hasSnapshot?[]:d(l.motioneye.movies.directory_pattern.split("/"),[`media-source://motioneye/${s}#${n}#movies`]),...!1===i?.hasSnapshot||i?.hasClip?[]:d(l.motioneye.images.directory_pattern.split("/"),[`media-source://motioneye/${s}#${n}#images`])],{useCache:c?.useCache})}async getEvents(e,t,a,r){if(a.favorite||a.tags?.size||a.what?.size||a.where?.size)return null;const o=new Map,s=async s=>{const n={...a,cameraIDs:new Set([s])},l=r?.useCache??1?this._requestCache.get(n):null;if(l)return void o.set(n,l);const d=t.get(s);if(!d)return;const p=await this._getMatchingDirectories(e,t,s,n,r);if(!p||!p.length)return;const u=this._convertMotionEyeTimeFormatToDateFNS(d.motioneye.movies.file_pattern),m=this._convertMotionEyeTimeFormatToDateFNS(d.motioneye.images.file_pattern),y=await this._browseMediaManager.walkBrowseMedias(e,[{targets:p,metadataGenerator:(e,t)=>e.media_class===c||e.media_class===i?this._motionEyeMetadataGeneratorFile(s,e.media_class===c?m:u,e,t):null,matcher:e=>!e.can_expand&&E(e,n.start,n.end)}],{useCache:r?.useCache}),h=_(y,(e=>e._metadata?.startDate),"desc").slice(0,n.limit??M),w={type:g.Event,engine:f.MotionEye,browseMedia:h};(r?.useCache??1)&&this._requestCache.set(n,{...w,cached:!0},w.expiry),o.set(n,w)};return await h(a.cameraIDs,(e=>s(e))),o.size?o:null}generateMediaFromEvents(e,t,a,r){return T.isMotionEyeEventQueryResults(r)?(e=>{const t=new Map;for(const a of e){const e=a._metadata?.cameraID;if(!e)continue;const r=a.media_class===i?"clip":a.media_class===c?"snapshot":null;if(!r)continue;const o=D.createEventViewMedia(r,a,e);if(o){const e=o.getID(),a=t.get(e);(!a||"snapshot"===a.getMediaType()&&"clip"===o.getMediaType())&&t.set(e,o)}}return[...t.values()]})(r.browseMedia):null}async getMediaMetadata(e,t,a,i){const c=new Map;if((i?.useCache??1)&&this._requestCache.has(a)){const e=this._requestCache.get(a);if(e)return c.set(a,e),c}const r=new Set,o=async a=>{const c=await this._getMatchingDirectories(e,t,a,null,i);for(const e of c??[])e._metadata&&r.add(b(e._metadata?.startDate))};await h(a.cameraIDs,(e=>o(e)));const s={type:g.MediaMetadata,engine:f.MotionEye,metadata:{...r.size&&{days:r}},expiry:w(new Date,{seconds:d}),cached:!1};return(i?.useCache??1)&&this._requestCache.set(a,{...s,cached:!0},s.expiry),c.set(a,s),c}getCameraMetadata(e,t){return{...super.getCameraMetadata(e,t),engineLogo:"data:image/svg+xml,%3c%3fxml version='1.0' encoding='UTF-8' standalone='no'%3f%3e%3c!-- Created with Inkscape (http://www.inkscape.org/) --%3e%3csvg xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:cc='http://creativecommons.org/ns%23' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd' xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape' id='svg2' version='1.1' inkscape:version='0.91 r13725' width='64' height='64' xml:space='preserve' sodipodi:docname='motioneye-icon.svg' inkscape:export-filename='/home/ccrisan/projects/motioneye/static/img/motioneye-logo.png' inkscape:export-xdpi='960' inkscape:export-ydpi='960'%3e%3cmetadata id='metadata8'%3e%3crdf:RDF%3e%3ccc:Work rdf:about=''%3e%3cdc:format%3eimage/svg%2bxml%3c/dc:format%3e%3cdc:type rdf:resource='http://purl.org/dc/dcmitype/StillImage' /%3e%3cdc:title /%3e%3c/cc:Work%3e%3c/rdf:RDF%3e%3c/metadata%3e%3cdefs id='defs6'%3e%3clinearGradient id='linearGradient4351' inkscape:collect='always'%3e%3cstop id='stop4353' offset='0' style='stop-color:%23737373%3bstop-opacity:1' /%3e%3cstop id='stop4355' offset='1' style='stop-color:%23585858%3bstop-opacity:1' /%3e%3c/linearGradient%3e%3clinearGradient inkscape:collect='always' id='linearGradient4205'%3e%3cstop style='stop-color:%234aa3e0%3bstop-opacity:1' offset='0' id='stop4207' /%3e%3cstop style='stop-color:%233096db%3bstop-opacity:1' offset='1' id='stop4209' /%3e%3c/linearGradient%3e%3clinearGradient inkscape:collect='always' id='linearGradient4197'%3e%3cstop style='stop-color:%23787878%3bstop-opacity:1' offset='0' id='stop4199' /%3e%3cstop style='stop-color:%23585858%3bstop-opacity:1' offset='1' id='stop4201' /%3e%3c/linearGradient%3e%3clinearGradient inkscape:collect='always' xlink:href='%23linearGradient4351' id='linearGradient4203' x1='26.445793' y1='47.517574' x2='26.445793' y2='3.8183768' gradientUnits='userSpaceOnUse' /%3e%3clinearGradient inkscape:collect='always' xlink:href='%23linearGradient4205' id='linearGradient4211' x1='26.602072' y1='43.034946' x2='26.602072' y2='29.466328' gradientUnits='userSpaceOnUse' gradientTransform='matrix(0.96428571%2c0%2c0%2c0.96428571%2c0.91428571%2c0.91428571)' /%3e%3cfilter style='color-interpolation-filters:sRGB%3b' inkscape:label='Drop Shadow' id='filter4285'%3e%3cfeFlood flood-opacity='0.588235' flood-color='rgb(0%2c0%2c0)' result='flood' id='feFlood4287' /%3e%3cfeComposite in='flood' in2='SourceGraphic' operator='in' result='composite1' id='feComposite4289' /%3e%3cfeGaussianBlur in='composite1' stdDeviation='0.6' result='blur' id='feGaussianBlur4291' /%3e%3cfeOffset dx='0' dy='-1' result='offset' id='feOffset4293' /%3e%3cfeComposite in='SourceGraphic' in2='offset' operator='over' result='composite2' id='feComposite4295' /%3e%3c/filter%3e%3clinearGradient inkscape:collect='always' xlink:href='%23linearGradient4197' id='linearGradient4309' gradientUnits='userSpaceOnUse' x1='26.445793' y1='47.517574' x2='26.445793' y2='3.8183768' /%3e%3clinearGradient inkscape:collect='always' xlink:href='%23linearGradient4197' id='linearGradient4311' gradientUnits='userSpaceOnUse' x1='26.445793' y1='47.517574' x2='26.445793' y2='3.8183768' /%3e%3clinearGradient inkscape:collect='always' xlink:href='%23linearGradient4197' id='linearGradient4313' gradientUnits='userSpaceOnUse' x1='26.445793' y1='47.517574' x2='26.445793' y2='3.8183768' /%3e%3cfilter style='color-interpolation-filters:sRGB%3b' inkscape:label='Drop Shadow' id='filter4315' x='-0.10000000000000001' y='-0.16000000000000003'%3e%3cfeFlood flood-opacity='0.588235' flood-color='rgb(0%2c0%2c0)' result='flood' id='feFlood4317' /%3e%3cfeComposite in='flood' in2='SourceGraphic' operator='in' result='composite1' id='feComposite4319' /%3e%3cfeGaussianBlur in='composite1' stdDeviation='0.6' result='blur' id='feGaussianBlur4321' /%3e%3cfeOffset dx='0' dy='-1' result='offset' id='feOffset4323' /%3e%3cfeComposite in='SourceGraphic' in2='offset' operator='over' result='composite2' id='feComposite4325' /%3e%3c/filter%3e%3cfilter style='color-interpolation-filters:sRGB%3b' inkscape:label='Drop Shadow' id='filter4327'%3e%3cfeFlood flood-opacity='0.588235' flood-color='rgb(0%2c0%2c0)' result='flood' id='feFlood4329' /%3e%3cfeComposite in='flood' in2='SourceGraphic' operator='in' result='composite1' id='feComposite4331' /%3e%3cfeGaussianBlur in='composite1' stdDeviation='0.6' result='blur' id='feGaussianBlur4333' /%3e%3cfeOffset dx='0' dy='-1' result='offset' id='feOffset4335' /%3e%3cfeComposite in='SourceGraphic' in2='offset' operator='over' result='composite2' id='feComposite4337' /%3e%3c/filter%3e%3cfilter style='color-interpolation-filters:sRGB%3b' inkscape:label='Drop Shadow' id='filter4339'%3e%3cfeFlood flood-opacity='0.588235' flood-color='rgb(0%2c0%2c0)' result='flood' id='feFlood4341' /%3e%3cfeComposite in='flood' in2='SourceGraphic' operator='in' result='composite1' id='feComposite4343' /%3e%3cfeGaussianBlur in='composite1' stdDeviation='0.2' result='blur' id='feGaussianBlur4345' /%3e%3cfeOffset dx='0' dy='-0.5' result='offset' id='feOffset4347' /%3e%3cfeComposite in='SourceGraphic' in2='offset' operator='over' result='composite2' id='feComposite4349' /%3e%3c/filter%3e%3c/defs%3e%3csodipodi:namedview pagecolor='white' bordercolor='%23666666' borderopacity='1' objecttolerance='10' gridtolerance='10' guidetolerance='10' inkscape:pageopacity='0' inkscape:pageshadow='2' inkscape:window-width='1920' inkscape:window-height='1025' id='namedview4' showgrid='false' inkscape:zoom='2' inkscape:cx='-94.597631' inkscape:cy='10.226517' inkscape:window-x='0' inkscape:window-y='27' inkscape:window-maximized='1' inkscape:current-layer='g10' showguides='true' inkscape:guide-bbox='true' /%3e%3cg id='g10' inkscape:groupmode='layer' inkscape:label='ink_ext_XXXXXX' transform='matrix(1.25%2c0%2c0%2c-1.25%2c0%2c64)'%3e%3cg id='g4170' style='fill:url(%23linearGradient4203)%3bfill-opacity:1%3bfilter:url(%23filter4327)' transform='matrix(0.96428571%2c0%2c0%2c0.96428571%2c0.91428571%2c0.91428571)'%3e%3cpath id='path4244' d='M 8.9346154%2c40.515385 C 5.3647588%2c36.547307 3.2%2c31.357779 3.2%2c25.6 3.2%2c13.228821 13.228821%2c3.2 25.6%2c3.2 37.971179%2c3.2 48%2c13.228821 48%2c25.6 c 0%2c5.736682 -2.161128%2c10.952493 -5.707692%2c14.915385 -1.695935%2c-0.623286 -3.387833%2c-1.349065 -5.061539%2c-2.288462 3.2394%2c-0.937363 5.6%2c-3.937988 5.6%2c-7.457692 0%2c-4.260339 -3.469626%2c-7.753846 -7.753846%2c-7.753846 -3.633936%2c0 -6.690552%2c2.51055 -7.538461%2c5.869231 l -3.876924%2c0 c -0.840685%2c-3.360193 -3.903443%2c-5.869231 -7.538461%2c-5.869231 -4.284219%2c0 -7.7807693%2c3.493507 -7.7807693%2c7.753846 0%2c3.56112 2.4570323%2c6.5856 5.7615383%2c7.484616 -1.676267%2c0.912203 -3.404813%2c1.620556 -5.1692306%2c2.261538 z M 25.6%2c26.461538 c 0.532632%2c-1.981435 1.101793%2c-3.947553 3.446154%2c-5.16923 L 25.6%2c16.123077 22.153846%2c21.292308 c 2.053593%2c1.454966 3.000771%2c3.237758 3.446154%2c5.16923 z' style='fill:url(%23linearGradient4309)%3bfill-opacity:1%3bstroke:none' inkscape:connector-curvature='0' /%3e%3cpath id='path4242' d='m 16.123077%2c33.353847 c -1.427443%2c0 -2.584616%2c-1.157173 -2.584616%2c-2.584616 0%2c-1.427444 1.157173%2c-2.584615 2.584616%2c-2.584615 1.427444%2c0 2.584615%2c1.157171 2.584615%2c2.584615 0%2c1.427443 -1.157171%2c2.584616 -2.584615%2c2.584616 z' style='fill:url(%23linearGradient4311)%3bfill-opacity:1%3bstroke:none' inkscape:connector-curvature='0' /%3e%3cpath id='path4240' d='m 35.076923%2c33.353847 c -1.427443%2c0 -2.584615%2c-1.157173 -2.584615%2c-2.584616 0%2c-1.427444 1.157172%2c-2.584615 2.584615%2c-2.584615 1.427443%2c0 2.584616%2c1.157171 2.584616%2c2.584615 0%2c1.427443 -1.157173%2c2.584616 -2.584616%2c2.584616 z' style='fill:url(%23linearGradient4313)%3bfill-opacity:1%3bstroke:none' inkscape:connector-curvature='0' /%3e%3c/g%3e%3cpath inkscape:connector-curvature='0' style='fill:%23737373%3bfill-opacity:1%3bstroke:none%3bfilter:url(%23filter4339)' d='m 25.6%2c47.2 c -4.373944%2c0 -8.437159%2c-1.399808 -11.838461%2c-3.634616 3.677605%2c-0.394237 7.305921%2c-1.342945 11.423077%2c-3.375 4.166157%2c2.122533 8.434154%2c3.008875 12.279808%2c3.452886 C 34.057131%2c45.890032 29.986674%2c47.2 25.6%2c47.2 Z' id='path4248' /%3e%3cpath inkscape:connector-curvature='0' style='fill:url(%23linearGradient4211)%3bfill-opacity:1%3bstroke:none%3bfilter:url(%23filter4315)' d='M 39.723077%2c42.552884 C 35.394064%2c42.5242 29.479588%2c40.397223 25.184616%2c38.432418 20.668821%2c40.064102 16.035448%2c42.649343 10.801923%2c42.526924 10.453022%2c42.51873 10.118061%2c42.50105 9.7634616%2c42.475 L 5.6615384%2c42.1375 9.5557693%2c40.839424 c 5.3417977%2c-1.74056 10.0398397%2c-2.851302 14.1749997%2c-10.025963 0.959101%2c0 2.845924%2c-4.15e-4 3.738462%2c-4.15e-4 4.11884%2c7.134039 9.059296%2c8.324614 14.149039%2c10.026378 L 45.460577%2c42.085577 41.4625%2c42.475 c -0.544847%2c0.05181 -1.120992%2c0.08198 -1.739423%2c0.07788 z' id='path4246' sodipodi:nodetypes='cccccccccccc' /%3e%3c/g%3e%3c/svg%3e"}}getCameraEndpoints(e,t){const a=e.motioneye?.url?{endpoint:e.motioneye.url}:null;return{...a&&{ui:a}}}}export{z as MotionEyeCameraManagerEngine};