1import{r as v,n as g,j as r,o as O,q as x,aK as L}from"./index-D4ZV_K8b.js";import{A as P}from"./ActionCell-C1BlIwBU.js";import{cM as V,an as K,aa as D,al as k,ap as A,ah as h,at as T,fL as R,fM as G,ea as j,fN as M,fO as U,as as l,dv as $,ab as E,fP as B,af as H,cN as J,d$ as Q,fQ as Y,du as z,f7 as W,ec as X,fR as Z,ep as ee,f5 as ae}from"./DrawerManager-BTAIt4rj.js";import{S as re}from"./ServiceField-DQfqwsxH.js";import{T as _}from"./TranslatableField-DiKL9FAW.js";import{E as se}from"./EntityTable-XYDYvlvY.js";import{T as ie}from"./TranslatableCell-BUWm4e0n.js";import{u as te}from"./useTableDefaultProps-BOJ_p08j.js";import"./Table-CBH_UStO.js";import"./useUpdateDrawer-CVpLbLvt.js";import"./EntityTableHeader-D_Vnkgm3.js";import"./PageTitle-CORj4igL.js";import"./TableEmpty-BEoG5Zst.js";import"./MultipleTableContext-BX7ZxVqD.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"2d6c35713634c8052e41534f4a9f7d04cf04849f"};var a=new e.Error().stack;a&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[a]="bb546fe4-b478-426c-8f72-dba3ebf5f99e",e._sentryDebugIdIdentifier="sentry-dbid-bb546fe4-b478-426c-8f72-dba3ebf5f99e")}catch{}})();L({mixed:{default:"field_invalid",required:"field_required"}});async function oe(e,a){if(e.image.length){const s=await a(J(e.image),{throw:!0,displayToastOnError:!0});e.image=s.key}else delete e.image;return{name:e.name,translations:e.translations,canonical:z(e.canonical),description:e.description,url:e.url,order:Y(e.order),available:e.available,services:Q(e.services),image:e.image}}const le=O({name:x().required(),canonical:j().required(),description:x().required(),url:x().required(),order:M().required(),services:j().required()}),ne=e=>({skip:!0,method:e?"put":"post",include:["services"],url:e?R(e.attributes._id):G()}),ce=({resetField:e,t:a,image:t,register:s,control:o,errors:i})=>r.jsxs("div",{className:"flex flex-col flex-grow gap-3",children:[r.jsx(U,{...s("_id")}),r.jsx(_,{name:"name",register:s,label:a("name"),error:l("name",i,a)}),r.jsx($,{label:a("canonical"),name:"canonical",control:o,resetField:e,entity:"subscriptionGroup",property:"canonical",error:l("canonical",i,a)}),r.jsx(_,{name:"description",textArea:!0,register:s,label:a("description"),error:l("description",i,a)}),r.jsx(E,{min:0,max:255,type:"number",label:a("order"),error:l("order",i,a),...s("order",{required:!0})}),r.jsx(E,{type:"url",error:l("url",i,a),label:a("url"),...s("url",{required:!0})}),r.jsx(B,{...s("image"),defaultValue:t,error:l(["file","image"],i,a),label:a("image"),accept:"image/*"}),r.jsx(H,{label:a("available"),...s("available")}),r.jsx(re,{name:"services",error:l("services",i,a),control:o,resetField:e,label:a("services")})]}),ue=e=>{var m;if(!e)return{};const a=e.id,{name:t,canonical:s,url:o,image:i,order:u,available:d,availability:p,description:b,translations:n}=e.attributes,{services:c}=e.relationships;return{_id:a,translations:n&&!Array.isArray(n)?n:{name:{en:""},description:{en:""}},name:t,canonical:s,url:o,image:i,order:u,available:d,availability:p,description:b,services:((m=c==null?void 0:c.data)==null?void 0:m.map(f=>f.id))??[]}},de=({entity:e=void 0,onClose:a})=>{const{fetchData:t,loading:s,error:o}=V(),{fetchData:i,loading:u,error:d}=K(ne(e)),{t:p}=D("subscription_group",{keyPrefix:"form.fields"}),{image:b,...n}=v.useMemo(()=>ue(e),[e]),{register:c,handleSubmit:m,resetField:f,control:F,setError:y,formState:{errors:S}}=k({shouldUseNativeValidation:!0,resolver:A(le),defaultValues:n}),q=async C=>{const N=await oe(C,t),I=await i(N,{throw:!0});a(!0,I)},w=()=>{a(!1)};return v.useEffect(()=>{g(y,d),g(y,o)},[d,o,y]),r.jsx("div",{children:r.jsxs("form",{"data-testid":"subscription_groups",onSubmit:m(q),children:[r.jsx(ce,{t:p,control:F,resetField:f,image:b,errors:S,register:c}),r.jsxs("div",{className:"flex gap-2 justify-end mt-4 w-full",children:[r.jsx(h,{disabled:!1,onClick:w,children:r.jsx(T,{i18nKey:"ui.button.cancel"})}),r.jsx(h,{saving:u||s,color:"primary",type:"submit",children:r.jsx(T,{i18nKey:"ui.button.submit"})})]})]})})},me=(e,a,t)=>{var s,o;return{id:e.id,name:r.jsx(ie,{entity:e,field:"name"}),canonical:r.jsx(ee,{entity:"subscriptionGroup",property:"canonical",value:e.attributes.canonical}),services:(o=(s=e.relationships)==null?void 0:s.services)==null?void 0:o.data.map(i=>i.attributes.name).join(", "),actions:r.jsx(P,{entity:e,actions:t})}},pe=[{label:"ui.table.name",dataKey:"name"},{label:"ui.table.type",dataKey:"canonical"},{label:"ui.table.services",dataKey:"services"},{label:"ui.table.order",dataKey:"order"},{label:"ui.table.actions",dataKey:"actions"}],be=({entityTableProps:e})=>{const{t:a}=D(),{entityTableDefaultProps:t}=te(),s=W({url:X({mine:!0}),apiSearch:!0,multiple:!0,property:"services",label:a("ui.table.services"),buildOption:ae,componentProps:{className:"min-w-[165px]",paperClassName:"min-w-[250px]"}});return r.jsx(se,{...t,path:Z,queryParams:{include:"services"},searchPlaceholder:a("ui.table.search_by_name"),filters:[s],columns:pe,form:de,parseItem:me,translationDomain:"subscription_group",...e})};be.displayName="SubscriptionGroups";export{be as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.