import{ag as j,r,b as S,W as y,j as t,B as N,R as C}from"./index-BeDhuS24.js";import{D as F}from"./DashboardFeatureWrapper-QO-XFtKk.js";import{b as v,F as E,g as R}from"./Feature-B18PTY7Z.js";import{I as g}from"./InputField-E2g5qJCn.js";import{S as T}from"./SelectField-CgXiODUe.js";function k(s){if(j(s)){const e=[];for(const o in s.endpoints){const a=s.endpoints[o];for(const i of a.scenes)e.push({...i})}return e}return s.scenes}const I=["schedule_","_mode","_options","_startup","_type","inching_","cyclic_"],M=["effect"],L=["state","color_temp","color","transition","brightness"],D=(s,e)=>{if(s){if(L.includes(s))return!0;for(const o of I)if(s.includes(o))return!1;if(M.includes(s))return!1}return e===v.ALL||e===v.SET||e===v.STATE_SET};function A(s,e={}){const{property:o,name:a,access:i}=s;if(D(a,i)){if("features"in s&&s.features&&s.features.length>0){const n=[],d=o?e[o]:e;for(const m of s.features){const l=A(m,d);l&&!n.some(u=>u.property===l.property)&&n.push(l)}return{...s,features:n}}return{...s}}}const P=r.memo(s=>{const{target:e,deviceState:o}=s,{t:a}=S("scene"),{sendMessage:i}=r.useContext(y),[n,d]=r.useState(0),[m,l]=r.useState(""),u=r.useMemo(()=>k(e),[e]),f=r.useMemo(()=>{const c=[];if(j(e))for(const h of e.definition?.exposes??[]){const x=A(h,o);x&&c.push(x)}return c},[e,o]),_=r.useCallback(async c=>{await i(`${e.friendly_name}/set`,c)},[i,e]),b=r.useCallback(async()=>{const c={ID:n,name:m||`Scene ${n}`};await i(`${e.friendly_name}/set`,{scene_store:c})},[i,e,n,m]),p=r.useMemo(()=>n>=0&&n<=255&&!u.find(c=>c.id===n),[n,u]);return t.jsxs(t.Fragment,{children:[t.jsx("h2",{className:"text-lg font-semibold",children:a("add_update_header")}),t.jsxs("div",{className:"mb-3",children:[t.jsx(g,{name:"scene_id",label:a("scene_id"),type:"number",value:n,onChange:c=>!!c.target.value&&d(c.target.valueAsNumber),min:0,max:255}),t.jsx(g,{name:"scene_name",label:a("scene_name"),type:"text",value:m,placeholder:`Scene ${n}`,onChange:c=>l(c.target.value)}),f.length>0&&t.jsx("div",{className:"card card-border bg-base-200 shadow my-2",children:t.jsx("div",{className:"card-body",children:f.map(c=>t.jsx(E,{feature:c,device:e,deviceState:o,onChange:_,featureWrapperClass:F,minimal:!0,parentFeatures:[]},R(c)))})})]}),t.jsx(N,{disabled:!p,onClick:b,className:"btn btn-primary",children:a("store")})]})}),$=r.memo(s=>{const{t:e}=S("scene"),{onSceneSelected:o,scenes:a=[],value:i}=s;return a.length>0?t.jsxs(T,{name:"scene_picker",label:e("scene_name"),value:i?.id??"",onChange:n=>!n.target.validationMessage&&!!n.target.value&&o(Number.parseInt(n.target.value,10)),children:[t.jsx("option",{value:"",disabled:!0,children:e("select_scene")}),a.map(n=>t.jsxs("option",{value:n.id,children:[n.id,": ",n.name]},n.id))]}):t.jsx(g,{name:"scene_picker",label:e("scene_id"),type:"number",value:i?.id??"",onChange:n=>!n.target.validationMessage&&!!n.target.value&&o(n.target.valueAsNumber),min:0,max:255})}),V=r.memo(s=>{const{target:e}=s,{sendMessage:o}=r.useContext(y),{t:a}=S(["scene","common"]),[i,n]=r.useState({id:0,name:"Scene 0"}),[d,m]=r.useState(!0),l=r.useMemo(()=>k(e),[e]),u=r.useCallback(p=>{m(!1);const c=l.find(h=>h.id===p);n(c!==void 0?c:{id:p,name:`Scene ${p}`})},[l]),f=r.useCallback(async()=>await o(`${e.friendly_name}/set`,{scene_recall:i.id}),[o,e.friendly_name,i.id]),_=r.useCallback(async()=>await o(`${e.friendly_name}/set`,{scene_remove:i.id}),[o,e.friendly_name,i.id]),b=r.useCallback(async()=>await o(`${e.friendly_name}/set`,{scene_remove_all:""}),[o,e.friendly_name]);return t.jsxs(t.Fragment,{children:[t.jsx("h2",{className:"text-lg font-semibold",children:a("manage_scenes_header")}),t.jsx("div",{className:"mb-3",children:t.jsx($,{onSceneSelected:u,value:d?void 0:i,scenes:l})}),t.jsxs("div",{className:"join join-horizontal",children:[t.jsx(N,{disabled:d,onClick:f,className:"btn btn-success join-item",children:a("recall")}),t.jsx(C,{disabled:d,onClick:_,className:"btn btn-error join-item",title:a("remove"),modalDescription:a("common:dialog_confirmation_prompt"),modalCancelLabel:a("common:cancel"),children:a("remove")}),t.jsx(C,{onClick:b,className:"btn btn-error btn-outline join-item",title:a("remove_all"),modalDescription:a("common:dialog_confirmation_prompt"),modalCancelLabel:a("common:cancel"),children:a("remove_all")})]})]})});export{P as A,V as R,A as g};
