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