(()=>{"use strict";const e=window.wp.blocks,s=JSON.parse('{"UU":"better-messages/chat-room"}'),t=window.wp.blockEditor,o=window.wp.data,a=window.wp.i18n,r=window.wp.components,n=window.wp.element,i=window.ReactJSXRuntime;(0,e.registerBlockType)(s.UU,{edit:function({attributes:e,setAttributes:s}){const{chatId:l}=e,{invalidateResolution:c}=(0,o.useDispatch)("core"),[d,m]=(0,n.useState)(0),[p,h]=(0,n.useState)(!1),{chatRooms:b,isLoading:g}=(0,o.useSelect)(e=>{const s={per_page:-1,status:"publish"},t=e("core").getEntityRecords("postType","bpbm-chat",s),o=e("core/data").isResolving("core","getEntityRecords",["postType","bpbm-chat",s]);return p&&!o&&null!==t&&setTimeout(()=>h(!1),0),{chatRooms:t,isLoading:null===t&&!p}},[d,p]),w=[{label:(0,a._x)("-- Select a chat room --","WP Admin","bp-better-messages"),value:0}];b&&b.forEach(e=>{w.push({label:e.title.rendered,value:e.id})});const x=window.wpApiSettings?.root?new URL("admin.php?page=bp-better-messages-chat-rooms",window.location.origin+"/wp-admin/").href:"/wp-admin/admin.php?page=bp-better-messages-chat-rooms";return(0,i.jsx)("div",{...(0,t.useBlockProps)(),children:(0,i.jsxs)("div",{className:"wp-block-better-messages-chat-room-wrap",children:[(0,i.jsx)("div",{className:"chat-header",children:(0,i.jsxs)("div",{children:[(0,a.__)("Better Messages","bp-better-messages")," - ",(0,a.__)("Chat Room","bp-better-messages")]})}),(0,i.jsxs)("div",{className:"chat-settings",children:[g?(0,i.jsxs)("div",{className:"chat-room-loading",children:[(0,i.jsx)(r.Spinner,{}),(0,i.jsx)("span",{children:(0,a._x)("Loading chat rooms...","WP Admin","bp-better-messages")})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(r.SelectControl,{__nextHasNoMarginBottom:!0,disabled:p,label:(0,a._x)("Chat Room","WP Admin","bp-better-messages"),value:l,options:w,onChange:e=>{s({chatId:parseInt(e,10)})}}),(0,i.jsxs)("div",{className:"chat-room-actions",children:[(0,i.jsx)("a",{href:x,target:"_blank",rel:"noopener noreferrer",children:(0,a._x)("+ Create new Chat Room","WP Admin","bp-better-messages")}),(0,i.jsx)(r.Button,{variant:"link",onClick:()=>{h(!0),c("getEntityRecords",["postType","bpbm-chat",{per_page:-1,status:"publish"}]),m(e=>e+1)},disabled:p,children:p?(0,a._x)("Refreshing...","WP Admin","bp-better-messages"):(0,a._x)("Refresh list","WP Admin","bp-better-messages")})]})]}),!g&&!p&&b&&0===b.length&&(0,i.jsxs)("p",{className:"chat-room-no-rooms",children:[(0,a._x)("No chat rooms found.","WP Admin","bp-better-messages")," ",(0,i.jsx)("a",{href:x,target:"_blank",rel:"noopener noreferrer",children:(0,a._x)("Create a chat room","WP Admin","bp-better-messages")})]}),(0,i.jsx)(r.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,a._x)("Auto open full screen in desktop mode","WP Admin","bp-better-messages"),help:(0,a._x)("The chat room will be opened in full screen mode when accessed from desktop devices or mobile full screen mode is disabled","WP Admin","bp-better-messages"),checked:e.fullScreen,onChange:e=>{s({fullScreen:e})}})]})]})})},icon:(0,i.jsxs)("svg",{stroke:"currentColor",fill:"currentColor",strokeWidth:"0",viewBox:"0 0 16 16",height:"200px",width:"200px",xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)("path",{d:"M14 1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H4.414A2 2 0 0 0 3 11.586l-2 2V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v12.793a.5.5 0 0 0 .854.353l2.853-2.853A1 1 0 0 1 4.414 12H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"}),(0,i.jsx)("path",{d:"M5 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0m4 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0m4 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0"})]})})})();