import{d as I,u as O,ai as S,q as A,Y as d,o as k,g as P,w as h,a as t,h as c,i as m,t as i,l as a,k as _,af as v,X as B,N as b,aZ as T,v as U,aM as D,ah as $,aN as j,_ as R}from"./XlhOY3QH.js";import{N as X}from"./fcaSiPlX.js";import{_ as Y}from"./DnYDFRQI.js";const Z={class:"min-w-md flex max-w-md flex-col gap-3"},q={class:"flex flex-col gap-2"},E={for:"name"},F={class:"text-lg font-semibold text-contrast"},H=["placeholder","disabled"],J={class:"flex flex-col gap-2"},G={for:"slug"},K={class:"text-lg font-semibold text-contrast"},Q={class:"text-input-wrapper"},W=["disabled"],ee={class:"flex flex-col gap-2"},ae={for:"additional-information",class:"flex flex-col gap-1"},te={class:"text-lg font-semibold text-contrast"},oe={class:"textarea-wrapper"},se=["placeholder","disabled"],ne={class:"m-0"},le={class:"flex justify-end gap-2"},ie=["disabled"],re=I({__name:"OrganizationCreateModal",setup(de,{expose:z}){const y=O(),{addNotification:w}=S(),{formatMessage:o}=A(),s=U({title:{id:"create.organization.title",defaultMessage:"Creating an organization"},nameLabel:{id:"create.organization.name-label",defaultMessage:"Name"},namePlaceholder:{id:"create.organization.name-placeholder",defaultMessage:"Enter organization name..."},urlLabel:{id:"create.organization.url-label",defaultMessage:"URL"},summaryLabel:{id:"create.organization.summary-label",defaultMessage:"Summary"},summaryDescription:{id:"create.organization.summary-description",defaultMessage:"A sentence or two that describes your organization."},summaryPlaceholder:{id:"create.organization.summary-placeholder",defaultMessage:"An organization for..."},ownershipInfo:{id:"create.organization.ownership-info",defaultMessage:"You will be the owner of this organization, but you can invite other members and transfer ownership at any time."},cancel:{id:"create.organization.cancel",defaultMessage:"Cancel"},createOrganization:{id:"create.organization.create-organization",defaultMessage:"Create organization"},errorTitle:{id:"create.organization.error-title",defaultMessage:"An error occurred"}}),u=d(""),p=d(""),g=d(""),x=d(!1),r=d(!1),f=d();async function M(){var l;D();try{const e={name:u.value.trim(),description:g.value.trim(),slug:p.value.trim().replace(/ +/g,"")},n=await $("organization",{method:"POST",body:JSON.stringify(e),apiVersion:3});(l=f.value)==null||l.hide(),await y.push(`/organization/${n.slug}`)}catch(e){console.error(e),w({title:o(s.errorTitle),text:e.data?e.data.description:e,type:"error"})}j()}function L(l){var e;u.value="",g.value="",(e=f.value)==null||e.show(l)}function N(){var l;(l=f.value)==null||l.hide()}function V(){x.value||(p.value=u.value.trim().toLowerCase().replaceAll(" ","-").replaceAll(/[^a-zA-Z0-9!@$()`.+,_"-]/g,"").replaceAll(/--+/gm,"-"))}function C(){x.value=!0}return z({show:L}),(l,e)=>(k(),P(a(X),{ref_key:"modal",ref:f,header:a(o)(a(s).title)},{default:h(()=>[t("div",Z,[c(Y,{modelValue:r.value,"onUpdate:modelValue":e[0]||(e[0]=n=>r.value=n),type:"org"},null,8,["modelValue"]),t("div",q,[t("label",E,[t("span",F,[m(i(a(o)(a(s).nameLabel))+" ",1),e[4]||(e[4]=t("span",{class:"text-brand-red"},"*",-1))])]),_(t("input",{id:"name","onUpdate:modelValue":e[1]||(e[1]=n=>u.value=n),type:"text",maxlength:"64",placeholder:a(o)(a(s).namePlaceholder),autocomplete:"off",disabled:r.value,onInput:V},null,40,H),[[v,u.value]])]),t("div",J,[t("label",G,[t("span",K,[m(i(a(o)(a(s).urlLabel))+" ",1),e[5]||(e[5]=t("span",{class:"text-brand-red"},"*",-1))])]),t("div",Q,[e[6]||(e[6]=t("div",{class:"text-input-wrapper__before"},"https://test.kalataka.ru/organization/",-1)),_(t("input",{id:"slug","onUpdate:modelValue":e[2]||(e[2]=n=>p.value=n),type:"text",maxlength:"64",autocomplete:"off",disabled:r.value,onInput:C},null,40,W),[[v,p.value]])])]),t("div",ee,[t("label",ae,[t("span",te,[m(i(a(o)(a(s).summaryLabel))+" ",1),e[7]||(e[7]=t("span",{class:"text-brand-red"},"*",-1))]),t("span",null,i(a(o)(a(s).summaryDescription)),1)]),t("div",oe,[_(t("textarea",{id:"additional-information","onUpdate:modelValue":e[3]||(e[3]=n=>g.value=n),maxlength:"256",placeholder:a(o)(a(s).summaryPlaceholder),disabled:r.value},null,8,se),[[v,g.value]])])]),t("p",ne,i(a(o)(a(s).ownershipInfo)),1),t("div",le,[c(a(b),{class:"w-24"},{default:h(()=>[t("button",{onClick:N},[c(a(B),{"aria-hidden":"true"}),m(" "+i(a(o)(a(s).cancel)),1)])]),_:1}),c(a(b),{color:"brand",class:"w-40"},{default:h(()=>[t("button",{disabled:r.value,onClick:M},[c(a(T),{"aria-hidden":"true"}),m(" "+i(a(o)(a(s).createOrganization)),1)],8,ie)]),_:1})])])]),_:1},8,["header"]))}}),pe=R(re,[["__scopeId","data-v-7911634d"]]);export{pe as O};