1import{gb as ae}from"./chunk-N6RRKPMH.js";import"./chunk-FJFH4XCE.js";import"./chunk-RWQTLYTV.js";import"./chunk-L7WATY32.js";import"./chunk-2RDPNIM6.js";import"./chunk-XPR5ELEW.js";import{b as w}from"./chunk-GGY6QDTV.js";import{j as re}from"./chunk-5IJU7MQ2.js";import"./chunk-LM6BYTWK.js";import{j as X}from"./chunk-ZWZG7L3J.js";import"./chunk-UXZT3DCY.js";import{o as j}from"./chunk-ECXCM7JU.js";import"./chunk-7DHSGR33.js";import{b as Y,c as z,f as K,g as Z,h as Q,i as ee,j as te,u as ie,w as ne,y as oe}from"./chunk-QO327RTO.js";import"./chunk-4MYWE7CD.js";import"./chunk-RS4X3CMD.js";import"./chunk-EWPP756Y.js";import{d as H}from"./chunk-I5EQON52.js";import{c as J,d as $}from"./chunk-G6PWMA7J.js";import{Ac as y,Bc as A,Cc as E,Fa as L,Fd as G,Gb as b,Jb as f,Jd as W,Lb as v,Nb as F,Ob as T,Pb as V,Qb as g,Qc as l,Rb as r,Rc as p,Sb as a,Tc as q,ac as P,ba as R,cc as _,db as n,ec as h,fd as U,mb as M,oa as x,pa as C,sb as B,sc as s,tc as m,uc as u,vc as O}from"./chunk-IQ6SK2BU.js";import"./chunk-AMJ4GB2S.js";import"./chunk-WGJEEJGF.js";import"./chunk-6ACFICIG.js";import"./chunk-K7BHMZHH.js";import"./chunk-FE7444LI.js";import"./chunk-OXDKANHF.js";import{a as k,b as N}from"./chunk-XUHYVR5R.js";var S=["Pricing","CannedJobs","JobGrouping","PerJobApproval","DeclinedWork","Inspections","Appointments","CustomerLinks","CustomerHistory"];function D(o){if(o==="None")return[];let c=typeof o=="string"?o.split(",").map(e=>e.trim()):[];if(!c.length||c.some(e=>!S.includes(e)))throw new Error("Unknown pilot modules. Reload with a compatible client.");return S.filter(e=>c.includes(e))}function se(o,c,e){let i=new Set(o);return e?(i.add(c),c==="DeclinedWork"&&i.add("PerJobApproval"),i.has("PerJobApproval")&&i.add("JobGrouping")):(i.delete(c),c==="JobGrouping"&&i.delete("PerJobApproval"),i.has("PerJobApproval")||i.delete("DeclinedWork")),S.filter(t=>i.has(t))}var le=(()=>{class o extends re{constructor(){super(...arguments),this.path="admin/v2/shop-pilots",this.requestOptions={timeout:2e4,retryAttempts:0,excludeRetryStatuses:[400,403,404,409]}}list(e,i){let t=new H({fromObject:{search:e,page:i,pageSize:20,_cb:Date.now()}});return this.httpGet(`${this.path}?${t.toString()}`,this.requestOptions)}get(e){return this.httpGet(`${this.path}/${encodeURIComponent(e)}?_cb=${Date.now()}`,this.requestOptions)}grant(e,i){return this.httpPut(`${this.path}/${encodeURIComponent(e)}`,i,this.requestOptions)}revoke(e,i){return this.httpPost(`${this.path}/${encodeURIComponent(e)}/revoke`,i,this.requestOptions)}static{this.\u0275fac=(()=>{let e;return function(t){return(e||(e=L(o)))(t||o)}})()}static{this.\u0275prov=R({token:o,factory:o.\u0275fac,providedIn:"root"})}}return o})();var ce=(o,c)=>c.shopId;function me(o,c){o&1&&(r(0,"p",6),s(1),l(2,"translate"),a()),o&2&&(n(),m(p(2,1,"V2.ADMIN_PILOT.LOADING")))}function he(o,c){if(o&1){let e=P();r(0,"button",12),_("click",function(){let t=x(e).$implicit,d=h();return C(d.select(t.shopId))}),r(1,"strong"),s(2),a(),r(3,"span"),s(4),a(),r(5,"span"),s(6),l(7,"translate"),a()()}if(o&2){let e=c.$implicit,i=h();g("disabled",i.saving||i.loading),b("aria-pressed",(i.selected==null?null:i.selected.shopId)===e.shopId),n(2),m(e.shopName),n(2),m(e.shopId),n(2),m(p(7,5,e.active?"V2.ADMIN_PILOT.ACTIVE":"V2.ADMIN_PILOT.INACTIVE"))}}function ge(o,c){o&1&&(r(0,"p"),s(1),l(2,"translate"),a()),o&2&&(n(),m(p(2,1,"V2.ADMIN_PILOT.EMPTY")))}function _e(o,c){if(o&1&&f(0,ge,3,3,"p"),o&2){let e=h();v(e.loading?-1:0)}}function ue(o,c){if(o&1&&(r(0,"p"),s(1),l(2,"translate"),l(3,"date"),a()),o&2){let e=h(),i=h();n(),O("",p(2,2,"V2.ADMIN_PILOT.EXPIRY"),": ",q(3,4,i.toDate(e.expiresAt),"yyyy-MM-dd HH:mm","UTC"))}}function xe(o,c){if(o&1){let e=P();r(0,"label",16)(1,"input",22),_("ngModelChange",function(t){let d=x(e).$implicit,I=h(2);return C(I.toggle(d,t))}),a(),s(2),l(3,"translate"),a()}if(o&2){let e=c.$implicit,i=h(2);n(),g("name",e)("ngModel",i.modules.includes(e)),n(),u(" ",p(3,3,"V2.ADMIN_PILOT."+e)," ")}}function Ce(o,c){if(o&1){let e=P();r(0,"section",21)(1,"h3"),s(2),l(3,"translate"),a(),r(4,"p"),s(5),a(),r(6,"p"),s(7),a(),r(8,"p"),s(9),l(10,"translate"),a(),r(11,"div",9)(12,"button",10),_("click",function(){x(e);let t=h(2);return C(t.submit())}),s(13),l(14,"translate"),a(),r(15,"button",10),_("click",function(){x(e);let t=h(2);return C(t.review=null)}),s(16),l(17,"translate"),a()()()}if(o&2){let e=c,i=h(),t=h();n(2),m(p(3,9,e.action==="grant"?"V2.ADMIN_PILOT.GRANT":"V2.ADMIN_PILOT.REVOKE")),n(3),O("",i.shopName," \xB7 ",e.body.expectedShopId),n(2),m(e.body.reason),n(2),m(p(10,11,"V2.ADMIN_PILOT.RETAINED")),n(3),g("disabled",t.saving||t.needsReload),n(),u(" ",p(14,13,t.saving?"V2.ADMIN_PILOT.SAVING":"V2.ADMIN_PILOT.CONFIRM")," "),n(2),g("disabled",t.saving||t.needsReload),n(),u(" ",p(17,15,"V2.ADMIN_PILOT.CANCEL")," ")}}function Ie(o,c){if(o&1){let e=P();r(0,"section",11),l(1,"translate"),r(2,"h2"),s(3),a(),r(4,"p",13),s(5),a(),r(6,"p"),s(7),l(8,"translate"),a(),r(9,"p"),s(10),l(11,"translate"),a(),f(12,ue,4,8,"p"),r(13,"button",10),_("click",function(){let t=x(e),d=h();return C(d.select(t.shopId))}),s(14),l(15,"translate"),a(),r(16,"form",14),_("ngSubmit",function(){x(e);let t=h();return C(t.prepare("grant"))}),r(17,"fieldset",15)(18,"legend"),s(19),l(20,"translate"),a(),r(21,"p"),s(22),l(23,"translate"),a(),T(24,xe,4,5,"label",16,F),r(26,"label",17),s(27),l(28,"translate"),a(),r(29,"input",18),E("ngModelChange",function(t){x(e);let d=h();return A(d.expiry,t)||(d.expiry=t),C(t)}),a(),r(30,"label",19),s(31),l(32,"translate"),a(),r(33,"textarea",20),E("ngModelChange",function(t){x(e);let d=h();return A(d.reason,t)||(d.reason=t),C(t)}),a(),r(34,"div",9)(35,"button",4),s(36),l(37,"translate"),a(),r(38,"button",10),_("click",function(){x(e);let t=h();return C(t.prepare("revoke"))}),s(39),l(40,"translate"),a()()()(),f(41,Ce,18,17,"section",21),a()}if(o&2){let e,i=c,t=h();b("aria-label",p(1,21,"V2.ADMIN_PILOT.EDIT")),n(3),m(i.shopName),n(2),m(i.shopId),n(2),O("",p(8,23,"V2.ADMIN_PILOT.VERSION"),": ",i.version),n(3),m(p(11,25,i.active?"V2.ADMIN_PILOT.ACTIVE":"V2.ADMIN_PILOT.INACTIVE")),n(2),v(i.expiresAt?12:-1),n(),g("disabled",t.saving||t.loading),n(),u(" ",p(15,27,"V2.ADMIN_PILOT.RELOAD")," "),n(3),g("disabled",t.loading||t.saving||!!t.review||t.needsReload),n(2),m(p(20,29,"V2.ADMIN_PILOT.MODULES")),n(3),m(p(23,31,"V2.ADMIN_PILOT.DEPENDENCIES")),n(2),V(t.moduleNames),n(3),m(p(28,33,"V2.ADMIN_PILOT.EXPIRY")),n(2),y("ngModel",t.expiry),n(2),m(p(32,35,"V2.ADMIN_PILOT.REASON")),n(2),y("ngModel",t.reason),n(2),g("disabled",!t.validGrant||!t.reason.trim()),n(),u(" ",p(37,37,"V2.ADMIN_PILOT.GRANT")," "),n(2),g("disabled",i.version===0||i.revokedAt!==null||!t.reason.trim()),n(),u(" ",p(40,39,"V2.ADMIN_PILOT.REVOKE")," "),n(2),v((e=t.review)?41:-1,e)}}var ke=(()=>{class o{constructor(e,i,t){this.api=e,this.store=i,this.cdr=t,this.moduleNames=S,this.toDate=w,this.items=[],this.selected=null,this.modules=[],this.search="",this.page=1,this.total=0,this.expiry="",this.reason="",this.loading=!1,this.saving=!1,this.needsReload=!1,this.message="",this.review=null,this.actor=null,this.generation=0}ngOnInit(){this.auth=this.store.select(ae.currentUser).subscribe(e=>
1{let i=e&&X(e)?e.id:null;i!==this.actor&&(this.actor=i,this.cancelRequest(),this.items=[],this.selected=null,this.review=null,this.modules=[],this.reason="",this.expiry="",this.total=0,this.needsReload=!1,this.message=i?"":"ACCESS",i&&this.load(1),this.cdr.markForCheck())})}ngOnDestroy(){this.auth?.unsubscribe(),this.cancelRequest()}cancelRequest(){++this.generation,this.request?.unsubscribe(),this.loading=!1,this.saving=!1}load(e=1){if(!this.actor||this.saving)return;this.cancelRequest();let i=this.generation;this.loading=!0,this.selected=null,this.review=null,this.message="",this.items=[],this.cdr.markForCheck(),this.request=this.api.list(this.search.trim(),e).subscribe({next:t=>{i===this.generation&&(this.items=t.items,this.page=t.page,this.total=t.total,this.loading=!1,this.cdr.markForCheck())},error:()=>{i===this.generation&&(this.loading=!1,this.message="LOAD_ERROR",this.cdr.markForCheck())}})}select(e){if(!this.actor||this.saving)return;this.cancelRequest();let i=this.generation;this.loading=!0,this.selected=null,this.review=null,this.message="",this.cdr.markForCheck(),this.request=this.api.get(e).subscribe({next:t=>{if(i===this.generation){if(this.loading=!1,t.shopId!==e){this.message="LOAD_ERROR",this.cdr.markForCheck();return}this.apply(t),this.cdr.markForCheck()}},error:()=>{i===this.generation&&(this.loading=!1,this.message="LOAD_ERROR",this.cdr.markForCheck())}})}apply(e){try{this.modules=D(e.modules),D(e.retainedModules)}catch{this.selected=null,this.message="LOAD_ERROR";return}this.selected=e,this.expiry=e.expiresAt?w(e.expiresAt).toISOString().slice(0,16):"",this.reason="",this.needsReload=!1,this.review=null}toggle(e,i){this.loading||this.saving||this.review||this.needsReload||(this.modules=se(this.modules,e,i))}get validGrant(){let e=this.expirySeconds();return this.modules.length>0&&Number.isSafeInteger(e)&&e>Date.now()/1e3}expirySeconds(){return Math.floor(Date.parse(`${this.expiry}:00Z`)/1e3)}prepare(e){if(!this.actor||!this.selected||this.loading||this.saving||this.needsReload||!this.reason.trim()||this.reason.length>1e3||e==="grant"&&!this.validGrant||e==="revoke"&&(this.selected.version===0||this.selected.revokedAt!==null))return;let i={expectedUserId:this.actor,expectedShopId:this.selected.shopId,expectedVersion:this.selected.version,reason:this.reason.trim()};this.review={action:e,body:e==="grant"?N(k({},i),{modules:this.modules.join(", "),expiresAt:this.expirySeconds()}):i},this.message=""}submit(){let e=this.review;if(!e||!this.selected||this.saving||this.needsReload||e.body.expectedUserId!==this.actor||e.body.expectedShopId!==this.selected.shopId)return;this.saving=!0,this.message="";let i=this.generation,t=e.action==="grant"?this.api.grant(this.selected.shopId,e.body):this.api.revoke(this.selected.shopId,e.body);this.request=t.subscribe({next:d=>{if(i===this.generation){if(this.saving=!1,d.shopId!==e.body.expectedShopId||d.version<=e.body.expectedVersion){this.needsReload=!0,this.message="UNCERTAIN",this.cdr.markForCheck();return}this.apply(d),this.selected&&(this.items=this.items.map(I=>I.shopId===d.shopId?d:I),this.message="SAVED"),this.cdr.markForCheck()}},error:()=>{i===this.generation&&(this.saving=!1,this.needsReload=!0,this.message="UNCERTAIN",this.cdr.markForCheck())}})}static{this.\u0275fac=function(i){return new(i||o)(M(le),M(j),M(U))}}static{this.\u0275cmp=B({type:o,selectors:[["app-admin-shop-pilots"]],decls:35,vars:34,consts:[[1,"pilot-page"],[1,"pilot-actions",3,"ngSubmit"],["for","pilot-search"],["id","pilot-search","name","search","maxlength","200",3,"ngModelChange","ngModel","disabled"],["type","submit",3,"disabled"],["role","status","aria-live","polite"],["role","status"],[1,"pilot-layout"],["type","button",1,"pilot-shop",3,"disabled"],[1,"pilot-actions"],["type","button",3,"click","disabled"],[1,"pilot-editor"],["type","button",1,"pilot-shop",3,"click","disabled"],[1,"pilot-id"],[3,"ngSubmit"],[3,"disabled"],[1,"pilot-check"],["for","pilot-expiry"],["id","pilot-expiry","name","expiry","type","datetime-local",3,"ngModelChange","ngModel"],["for","pilot-reason"],["id","pilot-reason","name","reason","maxlength","1000","rows","3","required","",3,"ngModelChange","ngModel"],["aria-live","polite",1,"pilot-review"],["type","checkbox",3,"ngModelChange","name","ngModel"]],template:function(i,t){if(i&1&&(r(0,"section",0)(1,"h1"),s(2),l(3,"translate"),a(),r(4,"p"),s(5),l(6,"translate"),a(),r(7,"form",1),_("ngSubmit",function(){return t.load(1)}),r(8,"label",2),s(9),l(10,"translate"),a(),r(11,"input",3),E("ngModelChange",function(I){return A(t.search,I)||(t.search=I),I}),a(),r(12,"button",4),s(13),l(14,"translate"),a()(),r(15,"p",5),s(16),l(17,"translate"),a(),f(18,me,3,3,"p",6),r(19,"div",7)(20,"section"),l(21,"translate"),T(22,he,8,7,"button",8,ce,!1,_e,1,1),r(25,"div",9)(26,"button",10),_("click",function(){return t.load(t.page-1)}),s(27),l(28,"translate"),a(),r(29,"span"),s(30),a(),r(31,"button",10),_("click",function(){return t.load(t.page+1)}),s(32),l(33,"translate"),a()()(),f(34,Ie,42,41,"section",11),a()()),i&2){let d;b("aria-busy",t.loading||t.saving),n(2),m(p(3,18,"V2.ADMIN_PILOT.TITLE")),n(3),m(p(6,20,"V2.ADMIN_PILOT.SCOPE")),n(4),m(p(10,22,"V2.ADMIN_PILOT.SEARCH")),n(2),y("ngModel",t.search),g("disabled",t.saving),n(),g("disabled",t.saving||t.loading),n(),u(" ",p(14,24,"V2.ADMIN_PILOT.SEARCH")," "),n(3),u(" ",t.message?p(17,26,"V2.ADMIN_PILOT."+t.message):""," "),n(2),v(t.loading?18:-1),n(2),b("aria-label",p(21,28,"V2.ADMIN_PILOT.SHOPS")),n(2),V(t.items),n(4),g("disabled",t.loading||t.saving||t.page<=1),n(),u(" ",p(28,30,"V2.ADMIN_PILOT.PREVIOUS")," "),n(3),m(t.page),n(),g("disabled",t.loading||t.saving||t.page*20>=t.total),n(),u(" ",p(33,32,"V2.ADMIN_PILOT.NEXT")," "),n(2),v((d=t.selected)?34:-1,d)}},dependencies:[W,oe,te,z,Y,K,Z,ie,ne,ee,Q,$,G,J],styles:["[_nghost-%COMP%]{display:block}.pilot-page[_ngcontent-%COMP%]{color:var(--color-text)}.pilot-page[_ngcontent-%COMP%] p[_ngcontent-%COMP%]{color:var(--color-text-secondary)}.pilot-layout[_ngcontent-%COMP%]{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,2fr);gap:1rem}
1.pilot-editor[_ngcontent-%COMP%], .pilot-shop[_ngcontent-%COMP%], .pilot-review[_ngcontent-%COMP%]{border:1px solid var(--color-border-strong);border-radius:1rem;padding:1rem;background:var(--color-surface)}.pilot-shop[_ngcontent-%COMP%]{display:flex;flex-direction:column;align-items:flex-start;width:100%;gap:.5rem;margin-bottom:.5rem;text-align:start}.pilot-shop[_ngcontent-%COMP%] span[_ngcontent-%COMP%], .pilot-id[_ngcontent-%COMP%], .pilot-review[_ngcontent-%COMP%] p[_ngcontent-%COMP%]{overflow-wrap:anywhere}.pilot-shop[aria-pressed=true][_ngcontent-%COMP%]{border-color:var(--color-primary)}.pilot-actions[_ngcontent-%COMP%]{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;margin:1rem 0}button[_ngcontent-%COMP%], input[_ngcontent-%COMP%], textarea[_ngcontent-%COMP%]{font:inherit;font-size:1rem;color:var(--color-text)}button[_ngcontent-%COMP%], input[_ngcontent-%COMP%]:not([type=checkbox]), textarea[_ngcontent-%COMP%]{min-height:2.75rem;border:1px solid var(--color-border-strong);border-radius:.75rem;padding:.5rem .75rem;background:var(--color-surface)}button[_ngcontent-%COMP%]{cursor:pointer}button[_ngcontent-%COMP%]:disabled{cursor:default;opacity:.5}button[_ngcontent-%COMP%]:focus-visible, input[_ngcontent-%COMP%]:focus-visible, textarea[_ngcontent-%COMP%]:focus-visible{outline:2px solid var(--color-primary);outline-offset:2px}fieldset[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:.75rem;border:0;padding:0;margin:1rem 0;min-width:0}legend[_ngcontent-%COMP%]{font-weight:600}.pilot-check[_ngcontent-%COMP%]{display:flex;align-items:center;gap:.75rem;min-height:2.75rem}input[type=checkbox][_ngcontent-%COMP%]{width:1.25rem;height:1.25rem;accent-color:var(--color-primary)}input[_ngcontent-%COMP%], textarea[_ngcontent-%COMP%]{min-width:0;max-width:100%}@media(max-width:1023px){.pilot-layout[_ngcontent-%COMP%]{grid-template-columns:minmax(0,1fr)}}"],changeDetection:0})}}return o})();export{ke as AdminShopPilotsComponent};
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.