import{r as c,u as f,g as C,a as y,E as N,aP as g,s as u,j as s,B as x,a6 as j}from"./index-ClCsMWbS.js";import{D as k}from"./DashboardFeatureWrapper-DSvHZUwh.js";import{F}from"./Feature-C2pFQwpi.js";import{g as w}from"./index-CQLnbJQy.js";import{I as _}from"./InputField-CqTVHKf8.js";import{S as $}from"./SelectField-WiB6Edsu.js";const L=c.memo(({sourceIdx:o,target:l,deviceState:i})=>{const{t}=f("scene"),[e,m]=c.useState(0),[r,d]=c.useState(""),b=c.useMemo(()=>C(l),[l]),p=y(N(n=>g(l)?n.deviceScenesFeatures[o][l.ieee_address]??[]:[])),v=c.useCallback(async n=>{await u(o,`${l.friendly_name}/set`,n)},[o,l]),h=c.useCallback(async()=>{const n={ID:e,name:r||`Scene ${e}`};await u(o,`${l.friendly_name}/set`,{scene_store:n})},[o,l,e,r]),a=c.useMemo(()=>e>=0&&e<=255&&!b.find(n=>n.id===e),[e,b]);return s.jsxs(s.Fragment,{children:[s.jsx("h2",{className:"text-lg font-semibold",children:t(n=>n.add_update_header)}),s.jsxs("div",{className:"mb-3",children:[s.jsx(_,{name:"scene_id",label:t(n=>n.scene_id),type:"number",value:e,onChange:n=>!!n.target.value&&m(n.target.valueAsNumber),min:0,max:255,required:!0}),s.jsx(_,{name:"scene_name",label:t(n=>n.scene_name),type:"text",value:r,placeholder:`Scene ${e}`,onChange:n=>d(n.target.value),required:!0}),p.length>0&&s.jsx("div",{className:"card card-border bg-base-100 shadow my-2",children:s.jsx("div",{className:"card-body p-4",children:p.map(n=>s.jsx(F,{feature:n,device:l,deviceState:i,onChange:v,featureWrapperClass:k,minimal:!0,parentFeatures:[]},w(n)))})})]}),s.jsx(x,{disabled:!a,onClick:h,className:"btn btn-primary",children:t(n=>n.store)})]})}),R=c.memo(({onSceneSelected:o,scenes:l=[],value:i})=>{const{t}=f("scene");return l.length>0?s.jsxs($,{name:"scene_picker",label:t(e=>e.scene_name),value:i?.id??"",onChange:e=>!e.target.validationMessage&&!!e.target.value&&o(Number.parseInt(e.target.value,10)),children:[s.jsx("option",{value:"",disabled:!0,children:t(e=>e.select_scene)}),l.map(e=>s.jsxs("option",{value:e.id,children:[e.id,": ",e.name]},e.id))]}):s.jsx(_,{name:"scene_picker",label:t(e=>e.scene_id),type:"number",value:i?.id??"",onChange:e=>!e.target.validationMessage&&!!e.target.value&&o(e.target.valueAsNumber),min:0,max:255})}),P=c.memo(({sourceIdx:o,target:l})=>{const{t:i}=f(["scene","common"]),[t,e]=c.useState({id:0,name:"Scene 0"}),[m,r]=c.useState(!0),d=c.useMemo(()=>C(l),[l]),b=c.useCallback(a=>{r(!1);const n=d.find(S=>S.id===a);e(n!==void 0?n:{id:a,name:`Scene ${a}`})},[d]),p=c.useCallback(async()=>await u(o,`${l.friendly_name}/set`,{scene_recall:t.id}),[o,l.friendly_name,t.id]),v=c.useCallback(async()=>await u(o,`${l.friendly_name}/set`,{scene_remove:t.id}),[o,l.friendly_name,t.id]),h=c.useCallback(async()=>await u(o,`${l.friendly_name}/set`,{scene_remove_all:""}),[o,l.friendly_name]);return s.jsxs(s.Fragment,{children:[s.jsx("h2",{className:"text-lg font-semibold",children:i(a=>a.manage_scenes_header)}),s.jsx("div",{className:"mb-3",children:s.jsx(R,{onSceneSelected:b,value:m?void 0:t,scenes:d})}),s.jsxs("div",{className:"join join-horizontal w-full",children:[s.jsx(x,{disabled:m,onClick:p,className:"btn btn-success join-item flex-1",children:i(a=>a.recall)}),s.jsx(j,{disabled:m,onClick:v,className:"btn btn-error join-item flex-1",title:i(a=>a.remove,{ns:"common"}),modalDescription:i(a=>a.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:i(a=>a.cancel,{ns:"common"}),children:i(a=>a.remove,{ns:"common"})}),s.jsx(j,{onClick:h,className:"btn btn-error btn-outline join-item flex-1",title:i(a=>a.remove_all),modalDescription:i(a=>a.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:i(a=>a.cancel,{ns:"common"}),children:i(a=>a.remove_all)})]})]})});export{L as A,P as R};
