import{K as B,L as T,v as t,x as o,l as i,p,z as r,B as f,s as c,q as x,k as v,F as N,y as D,D as w,C as E,f as k,r as y}from"./x-CuOWXDIc.js";import{P as q}from"./zap-Dlr53vCB.js";import{C as z}from"./chevron-down-pL4huxTV.js";import{C as g}from"./check-D7sgkfv8.js";const F={class:"template-switcher__trigger-label"},O={key:0,class:"template-switcher__dropdown"},P={key:1,class:"template-switcher__check-placeholder"},R=["onClick"],S={key:1,class:"template-switcher__check-placeholder"},$={class:"template-switcher__option-label"},G={__name:"TemplateSwitcher",props:{modelValue:{type:[Number,null],default:null},templates:{type:Array,required:!0}},emits:["update:modelValue"],setup(l,{emit:C}){const u=l,b=C,a=y(!1),m=y(null),d=k(()=>u.modelValue&&u.templates.find(e=>e.id===u.modelValue)||null),V=k(()=>{var e;return((e=d.value)==null?void 0:e.name)||"Без шаблона"});function _(e){b("update:modelValue",e),a.value=!1}function L(){a.value=!a.value}function h(e){m.value&&!m.value.contains(e.target)&&(a.value=!1)}return B(()=>{document.addEventListener("click",h)}),T(()=>{document.removeEventListener("click",h)}),(e,s)=>l.templates.length?(t(),o("div",{key:0,ref_key:"dropdownRef",ref:m,class:"template-switcher"},[i("button",{type:"button",class:c(["template-switcher__trigger",d.value?"template-switcher__trigger--active":"template-switcher__trigger--inactive"]),title:"Шаблон для превью",onClick:L},[p(r(q),{class:"icon-3h"}),i("span",F,f(V.value),1),p(r(z),{class:c(["icon-3",a.value?"block-editor-chevron--open":""])},null,8,["class"])],2),p(E,{name:"slide-down"},{default:x(()=>[a.value?(t(),o("div",O,[i("button",{type:"button",class:c(["template-switcher__option",l.modelValue?"template-switcher__option--unselected":"template-switcher__option--selected"]),onClick:s[0]||(s[0]=n=>_(null))},[l.modelValue?(t(),o("span",P)):(t(),v(r(g),{key:0,class:"icon-3h icon-primary"})),s[1]||(s[1]=i("span",{class:"template-switcher__option-label"},"Без шаблона",-1))],2),s[2]||(s[2]=i("div",{class:"template-switcher__separator"},null,-1)),(t(!0),o(N,null,D(l.templates,n=>(t(),o("button",{key:n.id,type:"button",class:c(["template-switcher__option",l.modelValue===n.id?"template-switcher__option--selected-primary":"template-switcher__option--unselected"]),onClick:A=>_(n.id)},[l.modelValue===n.id?(t(),v(r(g),{key:0,class:"icon-3h icon-primary"})):(t(),o("span",S)),i("span",$,f(n.name),1)],10,R))),128))])):w("",!0)]),_:1})],512)):w("",!0)}};export{G as _};
