1import{eu as P,ev as M,cl as j,j as t,R as h,bU as oe}from"./vendor-ct_YKIP6_bundle.js";import{t as I}from"./analytics-Bx8GuRNa_bundle.js";import{t as g}from"./registration-BfOA5mCx_bundle.js";import"./moment-DyvZl3Ud_bundle.js";import{ay as y,W as ne,aE as Q,Y as re,az as le,bs as ie,ci as de,cN as pe,aH as ce}from"./speedboat-vendor-DBIVks5t_bundle.js";import{b as A,c as R}from"./index-BiagCLbs_bundle.js";import{J as B,e as me,g as ue,b as be,i as ge,h as he,A as je,u as fe}from"./AgentBadge-cUgzCgff_bundle.js";import{B as Te}from"./Badge-CWDeSV2F_bundle.js";import{B as L}from"./Button-CgrHqwU2_bundle.js";import{u as xe,B as ye,c as _e}from"./BulkActionBar-UAJ9dxa3_bundle.js";import{C as Ie}from"./ConfirmDialog-BnWKVci5_bundle.js";import{a as Se}from"./DataTable-uF2mc6oU_bundle.js";import{D as K,a as z,b as V,f as De,e as ve,d as Y,c as C}from"./DropdownMenu-DEmPX796_bundle.js";import{I as we,a as Ce,b as Ee}from"./InputGroup-ByLJr-2v_bundle.js";import{L as ke}from"./ListPagination-CQp02ttX_bundle.js";import{P as Ne}from"./PageHeader-C9O9jzJh_bundle.js";import{P as F}from"./PageState-DtpmvJeu_bundle.js";import{S as Pe}from"./SpeedboatPage-DYBZ2zvb_bundle.js";import{T as b}from"./Text-B2BbGQxe_bundle.js";import{J,E as U,t as Me,T as $,p as G,a as Ae,b as Be,c as Le}from"./useCreateJobTemplateMutation-CEWeb81P_bundle.js";import"./useSageStore-BO85gJVX_bundle.js";import{u as Je}from"./useDebouncedValue-3IKAS9NO_bundle.js";import{m as Oe}from"./slackIntegration-mZcBTumD_bundle.js";import"./useSpeedboatLayoutStore-DlBUjk6G_bundle.js";import"./cacheInvalidation-CBJ-aFQu_bundle.js";import{A as qe,a as Re,b as Fe,d as Qe,e as Ke,f as ze,g as Ve,h as Ye}from"./AlertDialog-WWsmw_yy_bundle.js";import"./sentry-DLDmuXKN_bundle.js";import"./datadog-DxmyjtSX_bundle.js";import"./stripe-BA7RN6Z4_bundle.js";import"./bulkActions.api-CuuOYhPs_bundle.js";import"./Checkbox-RE7Al_ua_bundle.js";import"./Callout-BBIQOkyN_bundle.js";import"./Input-BkDyWfPc_bundle.js";import"./Select-CgJf-0iD_bundle.js";import"./Table-UsUTmpjE_bundle.js";import"./Empty-BGOBZB-E_bundle.js";import"./Skeleton-S1mHjS99_bundle.js";import"./Dialog-DTaKb2SE_bundle.js";import"./Label-B7hWMDeB_bundle.js";import"./Popover-BeIfQEoI_bundle.js";import"./Textarea-BPPmh3An_bundle.js";import"./useMasterItemsCatalogQuery-hVW8nS0Q_bundle.js";import"./useMasterItemSearchInfiniteQuery-AjpueujV_bundle.js";import"./activityHistory.api-CcFZLS9T_bundle.js";import"./useLocationsTreeQuery-DbkPFKXr_bundle.js";import"./locations.api-sCu28iOe_bundle.js";const Ue=()=>{const{id:e}=A(),o=P(),l=e==null?void 0:String(e);return M({mutationFn:s=>{if(!l)throw new Error("Missing company id");return me(l,s)},onSuccess:(s,n)=>{I("delete_job_template",{template_id:n}),o.invalidateQueries({queryKey:[J]}),o.removeQueries({queryKey:[B,l,n]})}})};function $e({templateId:e,templateName:o,open:l,onOpenChange:s}){const{t:n}=j(),r=Ue(),a=m=>{s(m),m||r.reset()},d=m=>{m.preventDefault(),r.mutate(e,{onSuccess:()=>{y.success(n("speedboat.pages.jobTemplates.delete.success")),s(!1)}})};return t.jsx(qe,{open:l,onOpenChange:a,children:t.jsxs(Re,{children:[t.jsxs(Fe,{children:[t.jsx(Qe,{children:n("speedboat.pages.jobTemplates.delete.title")}),t.jsx(Ke,{children:n("speedboat.pages.jobTemplates.delete.description",{name:o})})]}),r.isError&&t.jsx(b,{variant:"body-sm",tone:"danger",children:n("speedboat.pages.jobTemplates.delete.error")}),t.jsxs(ze,{children:[t.jsx(Ve,{disabled:r.isPending,children:n("speedboat.pages.jobTemplates.delete.cancel")}),t.jsx(Ye,{variant:"destructive",onClick:d,disabled:r.isPending,children:r.isPending?n("speedboat.pages.jobTemplates.delete.deleting"):n("speedboat.pages.jobTemplates.delete.confirm")})]})]})})}const Ge=(e,o,l=[])=>{const s=new Set(l),n=new Map(e.map(i=>[i.masterItemId,i.quantity])),r=new Set(o.map(i=>i.masterItemId)),a=[],d=[];o.forEach(i=>{n.has(i.masterItemId)?n.get(i.masterItemId)!==i.quantity&&!s.has(i.masterItemId)&&d.push(i):a.push(i)});const m=e.filter(i=>!r.has(i.masterItemId)).map(i=>i.masterItemId);return{add:a,update:d,remove:m}},He=()=>{const{id:e}=A(),o=P(),l=e==null?void 0:String(e);return M({mutationFn:({templateId:s,input:n})=>{if(!l)throw new Error("Missing company id");return ue(l,s,n)},onSuccess:s=>{I("update_job_template",{template_id:s.id}),o.invalidateQueries({queryKey:[J]}),o.invalidateQueries({queryKey:[B]})}})};function We({templateId:e,open:o,onOpenChange:l}){const{t:s}=j(),n=be(e,o),r=He(),a=n.data,d=h.useMemo(()=>a?Me(a):U,[a]),m=u=>{l(u),u||r.reset()},i=u=>{if(!a)return;const f=Ge(a.templateItems.map(p=>({masterItemId:p.masterItemId,quantity:p.quantity})),u.items.map(p=>({masterItemId:p.masterItemId,quantity:p.quantity})),a.templateItems.filter(p=>p.masterItemDeletedAt).map(p=>p.masterItemId)),E=f.add.length>0||f.update.length>0||f.remove.length>0,T=u.name.trim(),S=u.jobType.trim()||null,D=G(u.duration),v=u.description.trim()||null;r.mutate({templateId:e,input:{...T!==a.name?{name:T}:{},...S!==(a.jobType??null)?{jobType:S}:{},...D!==(a.durationDays??null)?{durationDays:D}:{},...v!==(a.description??null)?{description:v}:{},...E?{templateItems:f}:{},version:a.version}},{onSuccess:()=>{y.success(s("speedboat.pages.jobTemplates.form.update_success")),l(!1)},onError:p=>{ge(p)&&y.error(s("speedboat.pages.jobTemplates.form.master_deleted"))}})};return t.jsx($,{mode:"edit",open:o,onOpenChange:m,initialValues:d,onSubmit:i,attribution:a?{source:a.source,createdById:a.createdById}:void 0,isLoading:n.isLoading,loadError:n.isError,onRetryLoad:()=>n.refetch(),isSubmitting:r.isPending,submitError:r.isError})}function Xe(){const{t:e}
1=j(),[o,l]=h.useState(!1),s=Ae(),n=a=>{l(a),a||s.reset()},r=a=>{s.mutate({name:a.name,jobType:a.jobType.trim()||null,durationDays:G(a.duration),description:a.description,templateItems:a.items.map(d=>({masterItemId:d.masterItemId,quantity:d.quantity}))},{onSuccess:()=>{y.success(e("speedboat.pages.jobTemplates.form.create_success")),l(!1)}})};return t.jsx($,{mode:"create",open:o,onOpenChange:n,initialValues:U,onSubmit:r,isSubmitting:s.isPending,submitError:s.isError,trigger:t.jsxs(L,{children:[t.jsx(ne,{}),e("speedboat.pages.jobTemplates.new_template")]})})}const Ze=()=>{const{id:e}=A(),o=P(),l=e==null?void 0:String(e);return M({mutationFn:s=>{if(!l)throw new Error("Missing company id");return he(l,s)},onSuccess:s=>{I("bulk_delete_job_templates",{succeeded_count:s.succeededIds.length,skipped_count:s.skippedIds.length}),o.invalidateQueries({queryKey:[J]}),s.succeededIds.forEach(n=>{o.removeQueries({queryKey:[B,l,n]})})}})},N=12;function et(e){return e===void 0?g("speedboat.pages.jobTemplates.none"):g(e===1?"speedboat.pages.jobTemplates.duration_day":"speedboat.pages.jobTemplates.duration_days",{count:e})}function tt({template:e}){const{t:o}=j(),l=oe(),[s,n]=h.useState(!1),[r,a]=h.useState(!1);return t.jsxs(t.Fragment,{children:[t.jsxs(K,{children:[t.jsx(z,{asChild:!0,children:t.jsx(L,{variant:"ghost",size:"icon-sm","aria-label":o("speedboat.pages.jobTemplates.actions.open"),children:t.jsx(de,{})})}),t.jsxs(V,{align:"end",className:"min-w-44",children:[t.jsxs(C,{className:"gap-2.5",onSelect:()=>{I("use_job_template",{template_id:e.id}),l(`${Oe}/jobs/new?templateId=${e.id}`)},children:[t.jsx(pe,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t.jsx(b,{as:"span",variant:"body-sm",tone:"inherit",children:o("speedboat.pages.jobTemplates.actions.use")})]}),t.jsxs(C,{className:"gap-2.5",onSelect:()=>n(!0),children:[t.jsx(ce,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),t.jsx(b,{as:"span",variant:"body-sm",tone:"inherit",children:o("speedboat.pages.jobTemplates.actions.edit")})]}),t.jsx(Y,{}),t.jsxs(C,{className:"gap-2.5",variant:"destructive",onSelect:()=>a(!0),children:[t.jsx(Q,{className:"size-4","aria-hidden":"true"}),t.jsx(b,{as:"span",variant:"body-sm",tone:"inherit",children:o("speedboat.pages.jobTemplates.actions.delete")})]})]})]}),s&&t.jsx(We,{templateId:e.id,open:s,onOpenChange:n}),r&&t.jsx($e,{templateId:e.id,templateName:e.name,open:r,onOpenChange:a})]})}function st({jobType:e}){const{t:o}=j();return e?t.jsx(Te,{variant:"default",children:e}):t.jsx(b,{as:"span",variant:"body-sm",tone:"muted",children:o("speedboat.pages.jobTemplates.none")})}function at({roleId:e}){const{t:o}=j(),{getRoleName:l}=Le(),s=l(e);return t.jsx(b,{as:"span",variant:"body-sm",tone:"muted",truncate:!0,children:s??o("speedboat.pages.jobTemplates.none")})}function ot({count:e}){return t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(ie,{className:"size-4 shrink-0"}),t.jsx(b,{as:"span",variant:"body-sm",children:e})]})}const nt=[_e({get selectAllLabel(){return g("speedboat.pages.jobTemplates.selection.select_all")},getRowLabel:e=>g("speedboat.pages.jobTemplates.selection.select_row",{name:e.name})}),{accessorKey:"name",header:()=>g("speedboat.pages.jobTemplates.columns.name"),cell:({row:e})=>t.jsxs("div",{className:"flex min-w-[320px] items-center gap-2",children:[t.jsx(b,{variant:"body",weight:"medium",truncate:!0,children:e.original.name}),e.original.source==="agent"&&t.jsx(je,{})]}),enableSorting:!1},{accessorKey:"jobType",header:()=>g("speedboat.pages.jobTemplates.columns.job_type"),cell:({row:e})=>t.jsx(st,{jobType:e.original.jobType}),enableSorting:!1},{accessorKey:"durationDays",header:()=>g("speedboat.pages.jobTemplates.columns.duration"),cell:({row:e})=>t.jsx(b,{as:"span",variant:"body-sm",tone:"muted",children:et(e.original.durationDays)}),enableSorting:!1},{id:"items",header:()=>g("speedboat.pages.jobTemplates.columns.items"),cell:({row:e})=>t.jsx(ot,{count:e.original.itemCount}),enableSorting:!1},{id:"createdBy",header:()=>g("speedboat.pages.jobTemplates.columns.created_by"),cell:({row:e})=>t.jsx(at,{roleId:e.original.createdById}),enableSorting:!1},{id:"actions",cell:({row:e})=>t.jsx("div",{className:"flex justify-end",children:t.jsx(tt,{template:e.original})}),enableSorting:!1,enableHiding:!1}];function rt({type:e,onSelectType:o,onClearType:l}){const{t:s}=j(),{jobTypes:n}=fe();return t.jsxs(K,{children:[t.jsx(z,{asChild:!0,children:t.jsxs(L,{variant:"secondary","aria-label":s("speedboat.pages.jobTemplates.filters.job_type_aria"),className:"w-full font-medium text-foreground-soft lg:w-auto",children:[s("speedboat.pages.jobTemplates.filters.job_type"),e&&t.jsx("span",{className:"inline-flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-brand px-1",children:t.jsx(b,{as:"span",variant:"caption",weight:"semibold",tone:"inverse",children:"1"})}),t.jsx(le,{className:"size-3 text-muted-foreground"})]})}),t.jsxs(V,{className:"w-48",align:"start",children:[t.jsx(De,{children:s("speedboat.pages.jobTemplates.filters.job_type")}),n.map(r=>
1t.jsx(ve,{checked:e===r,onCheckedChange:()=>o(r),onSelect:a=>a.preventDefault(),children:r},r)),e&&t.jsxs(t.Fragment,{children:[t.jsx(Y,{}),t.jsx(C,{onSelect:l,children:s("speedboat.pages.jobTemplates.filters.clear")})]})]})]})}function lt({onSearchChange:e,onSelectType:o,onClearType:l,searchQuery:s,typeFilter:n}){const{t:r}=j();return t.jsxs("div",{"data-testid":"sb-filter-bar",className:"flex flex-col gap-3 lg:flex-row lg:items-center",children:[t.jsxs("label",{htmlFor:"job-templates-search",className:"w-full shrink-0 lg:w-80",children:[t.jsx("span",{className:"sr-only",children:r("speedboat.pages.jobTemplates.search_label")}),t.jsxs(we,{className:"h-10",children:[t.jsx(Ce,{align:"inline-start",children:t.jsx(re,{className:"size-4 text-muted-foreground","aria-hidden":"true"})}),t.jsx(Ee,{id:"job-templates-search","data-testid":"sb-search-input",value:s,onChange:a=>e(a.target.value),placeholder:r("speedboat.pages.jobTemplates.search_placeholder")})]})]}),t.jsx(rt,{type:n,onSelectType:o,onClearType:l})]})}function es(){const{t:e}=j(),[o,l]=h.useState(""),[s,n]=h.useState(null),[r,a]=h.useState(1),d=Je(o.trim());h.useEffect(()=>{d&&I("search_job_templates",{keyword_length:d.length})},[d]);const{data:m,isError:i,isFetching:u,isLoading:f,refetch:E}=Be({page:r,perPage:N,keyword:d||void 0,jobType:s??void 0}),T=m?.templates??[],S=m?.meta.offset??(r-1)*N,{rowSelection:D,setRowSelection:v,selectedIds:p,clearSelection:O}=xe(`${r}|${d}|${s??""}`),[H,k]=h.useState(!1),_=Ze(),x=p.length,W=T.find(c=>c.id===p[0])?.name??"",X=c=>{k(c),c||_.reset()},Z=()=>{_.mutate(p,{onSuccess:c=>{const w=c.succeededIds.length,q=c.skippedIds.length;w===0?y.success(e("speedboat.pages.jobTemplates.bulk_delete_dialog.skipped_only")):q>0?y.success(e("speedboat.pages.jobTemplates.bulk_delete_dialog.success_with_skipped",{count:w,skipped:q})):y.success(w===1?e("speedboat.pages.jobTemplates.bulk_delete_dialog.success_one"):e("speedboat.pages.jobTemplates.bulk_delete_dialog.success_other",{count:w})),O(),k(!1)}})},ee=c=>{l(c),a(1)},te=c=>{I("filter_job_templates",{job_type:c}),n(c),a(1)},se=()=>{n(null),a(1)},ae=t.jsx(ke,{page:r,hasPrev:m?.meta.hasPrev??!1,hasNext:m?.meta.hasNext??!1,rangeStart:T.length?S+1:0,rangeEnd:S+T.length,onPageChange:a,rangeEmptyLabel:e("speedboat.pages.jobTemplates.pagination.range_empty")});return t.jsxs(Pe,{contentClassName:"min-h-0",children:[t.jsx(Ne,{title:e("speedboat.pages.jobTemplates.title"),subtitle:e("speedboat.pages.jobTemplates.description"),actions:t.jsx(Xe,{})}),t.jsx(lt,{onSearchChange:ee,onSelectType:te,onClearType:se,searchQuery:o,typeFilter:s}),f&&t.jsx(F,{kind:"loading",loadingLabel:e("speedboat.pages.jobTemplates.loading")}),!f&&i&&t.jsx(F,{kind:"error",title:e("speedboat.pages.jobTemplates.error.title"),description:e("speedboat.pages.jobTemplates.error.description"),retryLabel:e("speedboat.pages.jobTemplates.error.retry"),onRetry:()=>E()}),!f&&!i&&t.jsxs("div",{className:R("flex min-h-0 flex-1 flex-col gap-3",u&&"opacity-60"),children:[t.jsx(ye,{className:"shrink-0",count:x,selectionLabel:x===1?e("speedboat.pages.jobTemplates.selection.count_one"):e("speedboat.pages.jobTemplates.selection.count_other",{count:x}),actionLabel:e("speedboat.pages.jobTemplates.selection.delete"),clearLabel:e("speedboat.pages.jobTemplates.selection.clear"),onAction:()=>k(!0),onClear:O,isPending:_.isPending}),t.jsx(Se,{columns:nt,data:T,getRowId:c=>c.id,pageSize:N,className:"flex min-h-0 flex-1 flex-col gap-4 space-y-0",emptyMessage:e("speedboat.pages.jobTemplates.empty.title"),rowSelection:D,onRowSelectionChange:v,containerClassName:"min-h-64 flex-1 overflow-y-auto",tableClassName:R("[&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10","[&_th:nth-child(1)]:w-10 [&_th:nth-child(3)]:w-[200px]","[&_th:nth-child(4)]:w-[160px] [&_th:nth-child(5)]:w-[120px]","[&_th:nth-child(6)]:w-[180px] [&_th:nth-child(7)]:w-14"),renderPagination:()=>ae})]}),t.jsx(Ie,{open:H,onOpenChange:X,title:x===1?e("speedboat.pages.jobTemplates.bulk_delete_dialog.title_one"):e("speedboat.pages.jobTemplates.bulk_delete_dialog.title_other",{count:x}),description:x===1?e("speedboat.pages.jobTemplates.bulk_delete_dialog.description_one",{name:W}):e("speedboat.pages.jobTemplates.bulk_delete_dialog.description_other",{count:x}),warning:e("speedboat.pages.jobTemplates.bulk_delete_dialog.warning"),error:_.isError?e("speedboat.pages.jobTemplates.bulk_delete_dialog.error"):void 0,confirmLabel:_.isPending?e("speedboat.pages.jobTemplates.bulk_delete_dialog.deleting"):e("speedboat.pages.jobTemplates.bulk_delete_dialog.confirm"),cancelLabel:e("speedboat.pages.jobTemplates.bulk_delete_dialog.cancel"),confirmVariant:"destructive",isConfirming:_.isPending,icon:t.jsx(Q,{className:"size-5 text-danger","aria-hidden":"true"}),onConfirm:Z})]})}export{es as default}; 2//# sourceMappingURL=speedboat_job_templates-DM3Xz0na_bundle.js.map
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.