(()=>{"use strict";const e=window.wp.i18n,o=window.wp.blocks,t=window.wp.blockEditor,l=window.wp.components,r=window.wp.data,n=window.ReactJSXRuntime;(0,o.registerBlockType)("lightweight-accordion/accordion-group",{title:(0,e.__)("Accordion Group"),category:"widgets",icon:"list-view",description:(0,e.__)("Group multiple accordions together so only one can be open at a time."),supports:{anchor:!0,html:!1,inserter:!1},attributes:{groupName:{type:"string",default:""}},providesContext:{"lightweight-accordion/groupName":"groupName"},edit:function({attributes:c,setAttributes:i,clientId:a}){const{groupName:s}=c,{insertBlock:d}=(0,r.useDispatch)("core/block-editor"),{innerBlockCount:g}=(0,r.useSelect)(e=>({innerBlockCount:e("core/block-editor").getBlockCount(a)}),[a]),u=(0,t.useBlockProps)({className:"lightweight-accordion-group"}),h=(0,t.useInnerBlocksProps)({},{allowedBlocks:["lightweight-accordion/lightweight-accordion"],renderAppender:!1});return(0,n.jsxs)("div",{...u,children:[(0,n.jsx)(t.BlockControls,{children:(0,n.jsx)(l.ToolbarGroup,{children:(0,n.jsx)(l.ToolbarButton,{onClick:()=>{const e=(0,o.createBlock)("lightweight-accordion/lightweight-accordion",{});d(e,g,a)},children:(0,e.__)("Add Item")})})}),(0,n.jsx)(t.InspectorControls,{children:(0,n.jsx)(l.PanelBody,{title:(0,e.__)("Group Settings"),children:(0,n.jsx)(l.TextControl,{label:(0,e.__)("Group Name"),value:s,onChange:e=>i({groupName:e}),help:(0,e.__)("All accordions in this group will auto-close when another opens. To disable auto-closing, remove the group name.")})})}),(0,n.jsx)("div",{...h})]})},save:function(){return(0,n.jsx)(t.InnerBlocks.Content,{})}}),(0,o.registerBlockType)("lightweight-accordion/lightweight-accordion",{title:(0,e.__)("Lightweight Accordion"),category:"widgets",icon:"editor-ul",keywords:[(0,e.__)("accordion"),(0,e.__)("list"),(0,e.__)("collapse"),(0,e.__)("collapsable"),(0,e.__)("faq"),(0,e.__)("toggle")],supports:{anchor:!0},attributes:{content:{type:"array",source:"children"},anchor:{type:"string",default:null},title:{type:"string",default:null},title_tag:{type:"string",default:"span"},title_text_color:{type:"string",default:""},title_background_color:{type:"string",default:""},accordion_open:{type:"boolean",default:!1},bordered:{type:"boolean",default:!1},schema:{type:"string",default:""},group:{type:"string",default:""}},usesContext:["lightweight-accordion/groupName"],example:{attributes:{title:(0,e.__)("Accordion Title"),bordered:!0}},edit:function({attributes:c,setAttributes:i,className:a,context:s,clientId:d}){const{title:g,title_tag:u,title_text_color:h,title_background_color:p,accordion_open:_,bordered:b,schema:w,group:k}=c,x=!!s["lightweight-accordion/groupName"],{replaceBlocks:m,insertBlock:v}=(0,r.useDispatch)("core/block-editor"),{parentBlock:B,blockIndex:C,currentBlock:j}=(0,r.useSelect)(e=>{const{getBlock:o,getBlockRootClientId:t,getBlockIndex:l}=e("core/block-editor"),r=t(d);return{parentBlock:r?o(r):null,blockIndex:l(d),currentBlock:o(d)}},[d]),y="lightweight-accordion/accordion-group"===B?.name,f=(0,t.useBlockProps)({className:"lightweight-accordion "+(b?"bordered":""),id:c.anchor||void 0});return(0,n.jsxs)("div",{...f,children:[(0,n.jsx)(t.BlockControls,{children:(0,n.jsx)(l.ToolbarGroup,{children:(0,n.jsx)(l.ToolbarButton,{onClick:()=>{const e=(0,o.createBlock)("lightweight-accordion/lightweight-accordion",{});if(y&&B)v(e,C+1,B.clientId);else{const t=(0,o.createBlock)("lightweight-accordion/accordion-group",{groupName:"accordion-group-"+Math.random().toString(36).substring(2,11)},[(0,o.createBlock)("lightweight-accordion/lightweight-accordion",{...j.attributes},j.innerBlocks),e]);m(d,t)}},children:(0,e.__)("Add Item")})})}),(0,n.jsx)("summary",{className:`lightweight-accordion-title ${a||""}`,style:{color:h||void 0,background:p||void 0},children:(0,n.jsx)(t.RichText,{tagName:u,value:g,onChange:e=>i({title:e}),placeholder:(0,e.__)("Accordion title..."),allowedFormats:["core/bold","core/italic"]})}),(0,n.jsx)("div",{className:`lightweight-accordion-body ${a||""}`,style:{borderColor:p||void 0},children:(0,n.jsx)(t.InnerBlocks,{})}),(0,n.jsxs)(t.InspectorControls,{children:[(0,n.jsxs)(l.PanelBody,{children:[(0,n.jsx)(l.ToggleControl,{label:(0,e.__)("Open by default?"),checked:_,onChange:e=>i({accordion_open:e})}),(0,n.jsx)(l.ToggleControl,{label:(0,e.__)("Border?"),checked:b,onChange:e=>i({bordered:e})}),(0,n.jsx)(l.SelectControl,{label:(0,e.__)("HTML tag for accordion title"),value:u,onChange:e=>i({title_tag:e}),options:[{value:"span",label:"span"},{value:"div",label:"div"},{value:"p",label:"p"},{value:"h1",label:"H1"},{value:"h2",label:"H2"},{value:"h3",label:"H3"},{value:"h4",label:"H4"},{value:"h5",label:"H5"},{value:"h6",label:"H6"}]}),(0,n.jsx)(l.SelectControl,{label:(0,e.__)("Schema Markup?"),value:w,onChange:e=>i({schema:e}),options:[{value:"",label:"None"},{value:"faq",label:"FAQ"}]}),!x&&(0,n.jsx)(l.TextControl,{label:(0,e.__)("Accordion Group"),value:k,onChange:e=>i({group:e}),help:(0,e.__)('Accordions with the same group name will auto-close when another opens. Or use the "Add Item" button to create grouped accordions.')}),x&&(0,n.jsx)("p",{className:"components-base-control__help",children:(0,e.__)("This accordion is part of a group. Only one accordion in the group can be open at a time.")})]}),(0,n.jsx)(t.PanelColorSettings,{title:(0,e.__)("Color Settings"),colorSettings:[{value:h||void 0,onChange:e=>i({title_text_color:e}),label:(0,e.__)("Title Text Color")},{value:p||void 0,onChange:e=>i({title_background_color:e}),label:(0,e.__)("Title Background Color")}]})]})]})},save:function(){return(0,n.jsx)(t.InnerBlocks.Content,{})}})})();