import{ad as y,r as i,b as S,W as N,j as a,B as k,I as C}from"./index-vDL8KyrI.js";import{D as I}from"./DashboardFeatureWrapper-CotxeSO1.js";import{b as g,F as T,g as M}from"./Feature-Dn8iv4tk.js";import{I as v}from"./InputField-B5sOh_uD.js";import{S as R}from"./SelectField-apZm61cq.js";function A(s){if(y(s)){const e=[];for(const c in s.endpoints){const t=s.endpoints[c];for(const o of t.scenes)e.push({...o})}return e}return s.scenes}const L=["schedule_","_mode","_options","_startup"],D=["effect"],$=["state","color_temp","color","transition","brightness"],j=(s,e)=>{if(s){if($.includes(s))return!0;for(const c of L)if(s.includes(c))return!1;if(D.includes(s))return!1}return e===g.ALL||e===g.SET||e===g.STATE_SET};function F(s,e={}){const{property:c,name:t,access:o}=s;if("features"in s&&s.features&&s.features.length>0){const n=[],d=c?e[c]: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,o)?{...s,features:n}:void 0}return j(t,o)?{...s}:void 0}const V=i.memo(s=>{const{target:e,deviceState:c}=s,{t}=S("scene"),{sendMessage:o}=i.useContext(N),[n,d]=i.useState(0),[m,l]=i.useState(""),u=i.useMemo(()=>A(e),[e]),p=i.useMemo(()=>{var b;const r=[];if(y(e))for(const E of((b=e.definition)==null?void 0:b.exposes)??[]){const x=F(E,c);x&&r.push(x)}return r},[e,c]),_=i.useCallback(async r=>{await o(`${e.friendly_name}/set`,r)},[o,e]),h=i.useCallback(async()=>{const r={ID:n,name:m||`Scene ${n}`};await o(`${e.friendly_name}/set`,{scene_store:r})},[o,e,n,m]),f=i.useMemo(()=>n>=0&&n<=255&&!u.find(r=>r.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(v,{name:"scene_id",label:t("scene_id"),type:"number",value:n,onChange:r=>!!r.target.value&&d(r.target.valueAsNumber),min:0,max:255}),a.jsx(v,{name:"scene_name",label:t("scene_name"),type:"text",value:m,placeholder:`Scene ${n}`,onChange:r=>l(r.target.value)}),p.length>0&&a.jsx("div",{className:"card card-border bg-base-100 shadow my-2",children:a.jsx("div",{className:"card-body",children:p.map(r=>a.jsx(T,{feature:r,device:e,deviceState:c,onChange:_,featureWrapperClass:I,minimal:!0,parentFeatures:[]},M(r)))})})]}),a.jsx(k,{disabled:!f,onClick:h,className:"btn btn-primary",children:t("store")})]})}),w=i.memo(s=>{const{t:e}=S("scene"),{onSceneSelected:c,scenes:t=[],value:o}=s;return t.length>0?a.jsxs(R,{name:"scene_picker",label:e("scene_name"),value:(o==null?void 0:o.id)??"",onChange:n=>!n.target.validationMessage&&!!n.target.value&&c(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(v,{name:"scene_picker",label:e("scene_id"),type:"number",value:(o==null?void 0:o.id)??"",onChange:n=>!n.target.validationMessage&&!!n.target.value&&c(n.target.valueAsNumber),min:0,max:255})}),z=i.memo(s=>{const{target:e}=s,{sendMessage:c}=i.useContext(N),{t}=S(["scene","common"]),[o,n]=i.useState({id:0,name:"Scene 0"}),[d,m]=i.useState(!0),l=i.useMemo(()=>A(e),[e]),u=i.useCallback(f=>{m(!1);const r=l.find(b=>b.id===f);n(r!==void 0?r:{id:f,name:`Scene ${f}`})},[l]),p=i.useCallback(async()=>await c(`${e.friendly_name}/set`,{scene_recall:o.id}),[c,e.friendly_name,o.id]),_=i.useCallback(async()=>await c(`${e.friendly_name}/set`,{scene_remove:o.id}),[c,e.friendly_name,o.id]),h=i.useCallback(async()=>await c(`${e.friendly_name}/set`,{scene_remove_all:""}),[c,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(w,{onSceneSelected:u,value:d?void 0:o,scenes:l})}),a.jsxs("div",{className:"join join-vertical lg:join-horizontal",children:[a.jsx(k,{disabled:d,onClick:p,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:h,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{V as A,z as R,F as g};
