import{ex as t,eM as e,eN as i,eO as a,l as n,eA as s,ev as r,j as l}from"./card-b98d578d.js";import{l as o}from"./live-provider-845afb16.js";const c=(t,e,i)=>{const a=i?.url??t.go2rtc?.url,n=i?.stream??t.go2rtc?.stream;if(!a||!n)return null;const s=e(a,n);return{endpoint:s,sign:s.startsWith("/")}},g=(t,e)=>c(t,((t,e)=>`${t}/api/ws?src=${e}`),e),u=(t,e)=>c(t,((t,e)=>`${t}/api/streams?src=${e}&video=all&audio=allµphone`),e),h=(t,e,i)=>"preset"===e?(i?.preset?t.ptz.presets?.[i.preset]:null)??null:i?.phase?t.ptz[`actions_${e}_${i.phase}`]??null:t.ptz[`actions_${e}`]??null,p=(t,e,i)=>!!h(t,e,i),_=(e,i)=>{const a=p(e,i,{phase:"start"})&&p(e,i,{phase:"stop"}),n=p(e,i);return a||n?[...a?[t.Continuous]:[],...n?[t.Relative]:[]]:null},d=t=>{const e=_(t,"left"),i=_(t,"right"),a=_(t,"up"),n=_(t,"down"),s=_(t,"zoom_in"),r=_(t,"zoom_out"),l=t.ptz.presets?Object.keys(t.ptz.presets):void 0;return e?.length||i?.length||a?.length||n?.length||s?.length||r?.length||l?.length?{...e?{left:e}:{},...i?{right:i}:{},...a?{up:a}:{},...n?{down:n}:{},...s?{zoomIn:s}:{},...r?{zoomOut:r}:{},...l?{presets:l}:{}}:null};class b{constructor(t,i,a){this._destroyCallbacks=[],this._stateChangeHandler=t=>{this._eventCallback?.({cameraID:this.getID(),type:e(t.newState.state)?"new":"end"})},this._config=t,this._engine=i,this._eventCallback=a?.eventCallback,this._capabilities=a?.capabilities}async initialize(t){return await this._initialize(t),this._capabilities=t.capabilityOptions?.capabilities??this._capabilities??await this._buildCapabilities(t),this._subscribeBasedOnCapabilities(t.stateWatcher),this._onDestroy((()=>t.stateWatcher.unsubscribe(this._stateChangeHandler))),this}async _initialize(t){}async _buildCapabilities(t){const e=await this._getRawCapabilities(t),a=this.getConfig(),n=await o(t.hass,a,this._getGo2RTCMetadataEndpoint(),this.getProxyConfig());return new i({...e,"2-way-audio":n},{disable:a.capabilities?.disable,disableExcept:a.capabilities?.disable_except})}async _getRawCapabilities(t){return{live:!0,menu:!0,substream:!0,trigger:!0,"remote-control-entity":!0,...t.capabilityOptions?.raw}}async destroy(){this._destroyCallbacks.forEach((t=>t()))}getConfig(){return this._config}setID(t){this._config.id=t}getID(){if(this._config.id)return this._config.id;throw new a(n("error.no_camera_id"))}getEngine(){return this._engine}getCapabilities(){return this._capabilities??null}getEndpoints(t){const e=this._getUIEndpoint(t),i=this._getGo2RTCStreamEndpoint(),a=this._getWebRTCCardEndpoint();return e||i||a?{...e&&{ui:e},...i&&{go2rtc:i},...a&&{webrtcCard:a}}:null}_getGo2RTCMetadataEndpoint(){return u(this._config)}_getGo2RTCStreamEndpoint(){return g(this._config)}_getWebRTCCardEndpoint(){return this._config.camera_entity?{endpoint:this._config.camera_entity}:null}_getUIEndpoint(t){return null}getProxyConfig(){return{live:"auto"===this._config.proxy.live?"go2rtc"===this._config.live_provider&&!!this._config.go2rtc?.url:this._config.proxy.live,media:"auto"!==this._config.proxy.media&&this._config.proxy.media,dynamic:this._config.proxy.dynamic,ssl_verification:!1!==this._config.proxy.ssl_verification,ssl_ciphers:"auto"===this._config.proxy.ssl_ciphers?"default":this._config.proxy.ssl_ciphers}}async executePTZAction(t,e,i){const a=h(this.getConfig(),e,i);return!!a&&(await t.executeActions({actions:a}),!0)}_onDestroy(t){this._destroyCallbacks.push(t)}_subscribeBasedOnCapabilities(t){this._capabilities?.has("trigger")&&(t.unsubscribe(this._stateChangeHandler),t.subscribe(this._stateChangeHandler,this._config.triggers.entities))}}class y{constructor(t,e){this._stateWatcher=t,this._eventCallback=e}getEngineType(){return s.Generic}async createCamera(t,e){return await new b(e,this,{eventCallback:this._eventCallback}).initialize({hass:t,stateWatcher:this._stateWatcher,capabilityOptions:{raw:{ptz:d(e)??void 0},disable:e.capabilities?.disable,disableExcept:e.capabilities?.disable_except}})}generateDefaultEventQuery(t,e,i){return null}generateDefaultRecordingQuery(t,e,i){return null}generateDefaultRecordingSegmentsQuery(t,e,i){return null}async getEvents(t,e,i,a){return null}async getRecordings(t,e,i,a){return null}async getRecordingSegments(t,e,i,a){return null}generateMediaFromEvents(t,e,i,a){return null}generateMediaFromRecordings(t,e,i,a){return null}async getMediaDownloadPath(t,e,i){return null}async favoriteMedia(t,e,i,a){}getQueryResultMaxAge(t){return null}async getMediaSeekTime(t,e,i,a,n){return null}async getMediaMetadata(t,e,i,a){return null}getCameraMetadata(t,e){const i=r(e);return{title:e.title??l(t,e.camera_entity)??l(t,e.webrtc_card?.entity)??e.id??"",icon:{entity:i??void 0,icon:e.icon,fallback:"mdi:video"}}}getMediaCapabilities(t){return null}}var f=Object.freeze({__proto__:null,GenericCameraManagerEngine:y});export{b as C,y as G,u as a,g as b,f as e,d as g};