1import{b as ae,r as f,j as e,H as ie,I as oe,a as S,t as _,u as ne}from"./app-tjZ_-OOu.js";import{M as le,S as de}from"./messenger-share-actions-B346DG7F.js";import{B as H}from"./badge-BR76Zdcf.js";import{h as E,j as W,q as J,f as Q,B as p,aF as L,aG as ce,aH as pe}from"./sonner-BnWx1Tnu.js";import{c as O,d as M}from"./card-Bi7Nimbe.js";import{C as T}from"./checkbox-JPf-aVVI.js";import{d as me,e as ue,D as z,a as G,b as q,c as R,f as xe}from"./dialog-D9nKO9Xa.js";import{E as he,a as fe,b as je,c as be,d as ge,e as ye,f as ke}from"./empty-DAEfMa_H.js";import{c as ve,a as Ne}from"./input-group-DdsIsYlf.js";import{I as V}from"./input-group-field-B6Hy38JP.js";import{L as I}from"./label-BgScZPhL.js";import{S as Ce}from"./submit-button-B0clHiGQ.js";import{c as De,T as Se,a as K,b as y,d as _e,e as k}from"./table-VFGaZTg2.js";import{u as Ee,C as Fe}from"./use-clipboard-BSPgpF7O.js";import{a as we}from"./authenticated-app-layout-BfE-_pxu.js";import{P as Ae}from"./app-sidebar-menu-CqpU_i_z.js";import{M as Pe}from"./main-UYcEJ9nX.js";import{C as Te}from"./check-C3mYSEdk.js";import{T as X}from"./trash-2-BQtk5q6f.js";import{P as Ie}from"./plus-DRhJHN3d.js";import"./app-ClMwVNe-.js";import"./textarea-BilhGg_-.js";import"./input-error-CsCZtzFi.js";import"./icons-gelrvuNW.js";import"./app-header-layout-XPwmcGh-.js";import"./dropdown-menu-CiZ8CgA8.js";import"./index-Cg0WxTnG.js";import"./visual-viewport-lock-Do1D7T0g.js";import"./avatar-i9ir4Wwt.js";import"./page-wrapper-CqNR-NwG.js";const l=(s,i)=>({url:l.url(s,i),method:"post"});l.definition={methods:["post"],url:"//card46.ru/stores/{store}/employees/invite"};l.url=(s,i)=>{(typeof s=="string"||typeof s=="number")&&(s={store:s}),typeof s=="object"&&!Array.isArray(s)&&"ulid"in s&&(s={store:E(s.ulid,"store")}),Array.isArray(s)&&(s={store:s[0]}),s=W(s);const o={store:E(typeof s.store=="object"?s.store.ulid:s.store,"store")};return l.definition.url.replace("{store}",o.store.toString()).replace(/\/+$/,"")+J(i)};l.post=(s,i)=>({url:l.url(s,i),method:"post"});const Y=(s,i)=>({action:l.url(s,i),method:"post"});Y.post=(s,i)=>({action:l.url(s,i),method:"post"});l.form=Y;const d=(s,i)=>({url:d.url(s,i),method:"delete"});d.definition={methods:["delete"],url:"//card46.ru/stores/{store}/employees/invite"};d.url=(s,i)=>{(typeof s=="string"||typeof s=="number")&&(s={store:s}),typeof s=="object"&&!Array.isArray(s)&&"ulid"in s&&(s={store:E(s.ulid,"store")}),Array.isArray(s)&&(s={store:s[0]}),s=W(s);const o={store:E(typeof s.store=="object"?s.store.ulid:s.store,"store")};return d.definition.url.replace("{store}",o.store.toString()).replace(/\/+$/,"")+J(i)};d.delete=(s,i)=>({url:d.url(s,i),method:"delete"});const Z=(s,i)=>({action:d.url(s,Q("delete",i)),method:"post"});Z.delete=(s,i)=>({action:d.url(s,Q("delete",i)),method:"post"});d.form=Z;function $e({store:s,employees:i,inviteUrl:o,availablePermissions:v}){const c=s,F=ae(),h=(()=>{try{return new URL(F.url,window.location.origin).searchParams.get("name")??""}catch{return""}})(),[j,b]=f.useState(h),[a,g]=f.useState(!1),[w,A]=Ee(),[P,N]=f.useState(null),C=Array.isArray(i?.data)?i.data:[],t=v??[],n=h.trim().length>0,m=C.length===0,u=m&&!n,U=typeof i?.to=="number"?i.to-C.length+1:1,ee=()=>{g(!0);const r=j.trim(),D={};r&&(D.name=r),S.visit(L.url({store:c.ulid},Object.keys(D).length?{query:D}:void 0),{preserveState:!0,preserveScroll:!0,only:["employees"],reset:["employees"],onFinish:()=>g(!1)})},$=()=>{b(""),g(!0),S.visit(L.url({store:c.ulid}),{preserveState:!0,preserveScroll:!0,only:["employees"],reset:["employees"],onFinish:()=>g(!1)})},se=()=>{S.visit(l(c.ulid))},te=()=>{S.visit(d(c.ulid))},re=()=>{o&&(A(o),_.success("СÑÑлка ÑкопиÑована в бÑÑÐµÑ Ð¾Ð±Ð¼ÐµÐ½Ð°"))},B=e.jsxs(p,{variant:u?"default":"outline",className:"gap-gos-4",onClick:se,children:[e.jsx(Ie,{className:"h-4 w-4"}),"СоздаÑÑ Ð¿ÑиглаÑение"]});return e.jsxs(e.Fragment,{children:[e.jsx(ie,{title:"СоÑÑÑдники магазина"}),e.jsx(Ae,{title:"СоÑÑÑдники магазина",sidebarChildren:e.jsx(Pe,{}),hideSidebarOnMobile:!0,children:e.jsxs("div",{className:"space-y-gos-12",children:[!u&&!
1o?e.jsx("div",{className:"flex justify-end",children:B}):null,o?e.jsxs("div",{className:"space-y-gos-4",children:[e.jsx(O,{children:e.jsx(M,{children:e.jsxs("div",{className:"flex items-center gap-gos-8",children:[e.jsx(ve,{children:e.jsx(Ne,{type:"text",readOnly:!0,value:o,"aria-label":"СÑÑлка-пÑиглаÑение"})}),e.jsx(p,{variant:"ghost",size:"icon",onClick:re,"aria-label":"ÐопиÑоваÑÑ ÑÑÑлкÑ",children:w===o?e.jsx(Te,{}):e.jsx(Fe,{})}),e.jsx(p,{variant:"ghost",size:"icon",onClick:te,"aria-label":"УдалиÑÑ Ð¿ÑиглаÑение",children:e.jsx(X,{})})]})})}),e.jsx(le,{url:o,text:de.storeEmployee})]}):null,e.jsx(O,{children:e.jsx(M,{children:e.jsxs("form",{className:"space-y-gos-8",onSubmit:r=>{r.preventDefault(),ee()},children:[e.jsx("div",{className:"grid grid-cols-1 gap-gos-8 md:grid-cols-2",children:e.jsx(V,{id:"name",name:"name",label:"ÐмÑ",placeholder:"ÐоиÑк по имени, email или должноÑÑи",value:j,onChange:r=>b(r.target.value)})}),e.jsxs("div",{className:"flex flex-wrap gap-gos-4",children:[e.jsx(p,{type:"submit",disabled:a,children:"ÐайÑи"}),n?e.jsx(p,{type:"button",variant:"outline",onClick:$,disabled:a,children:"СбÑоÑиÑÑ"}):null]})]})})}),m?e.jsxs(he,{className:"border",children:[e.jsxs(fe,{children:[e.jsx(je,{children:e.jsx(be,{alt:""})}),e.jsx(ge,{children:u?"ÐÐµÑ ÑоÑÑÑдников":"ÐиÑего не найдено"}),e.jsx(ye,{children:u?"СоздайÑе пÑиглаÑение, ÑÑÐ¾Ð±Ñ Ð¿ÐµÑвÑй ÑоÑÑÑдник поÑвилÑÑ Ð² ÑпиÑке.":"ÐопÑобÑйÑе измениÑÑ Ð¿Ð°ÑамеÑÑÑ Ð¿Ð¾Ð¸Ñка или ÑбÑоÑиÑÑ ÑилÑÑÑÑ."})]}),u&&o?null:e.jsx(ke,{children:u?B:e.jsx(p,{type:"button",variant:"outline",onClick:$,disabled:a,children:"СбÑоÑиÑÑ ÑилÑÑÑÑ"})})]}):e.jsx(oe,{data:"employees",buffer:150,onlyNext:!0,preserveUrl:!0,loading:({loading:r})=>r?e.jsx("div",{className:"mt-gos-8 text-center text-plain-small text-interlineare",children:"ÐагÑÑзка..."}):null,children:e.jsxs(De,{children:[e.jsx(Se,{children:e.jsxs(K,{children:[e.jsx(y,{className:"w-[1%]","data-test":"employees-col-number",children:"#"}),e.jsx(y,{children:"ÐмÑ"}),e.jsx(y,{children:"Email"}),e.jsx(y,{children:"ÐолжноÑÑÑ"}),e.jsx(y,{children:"ÐÑедÑÑавиÑелÑ"}),e.jsx(y,{children:"ÐÑава доÑÑÑпа"})]})}),e.jsx(_e,{children:C.map((r,D)=>e.jsxs(f.Fragment,{children:[e.jsxs(K,{className:"cursor-pointer","data-test":"employee-row",tabIndex:0,role:"button","aria-label":`РедакÑиÑоваÑÑ ÑоÑÑÑдника ${r.user?.name||r.user?.email||""}`.trim(),onClick:()=>N(r.id),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),N(r.id))},children:[e.jsx(k,{className:"text-interlineare tabular-nums","data-test":"employee-row-number",children:U+D}),e.jsx(k,{className:"max-w-md font-medium whitespace-normal",children:r.user?.name||"Ðе Ñказано"}),e.jsx(k,{children:r.user?.email||"Ðе Ñказано"}),e.jsx(k,{children:r.job_name||"â"}),e.jsx(k,{children:r.default_spokesperson?e.jsx(H,{variant:"default","data-test":"employee-spokesperson-badge",children:"ÐÑедÑÑавиÑÐµÐ»Ñ Ð¿Ð¾ ÑмолÑаниÑ"}):r.is_spokesperson?e.jsx(H,{variant:"dark","data-test":"employee-spokesperson-badge",children:"ÐÑедÑÑавиÑелÑ"}):"â"}),e.jsx(k,{children:r.permissions&&r.permissions.length>0?e.jsxs("div",{className:"flex flex-wrap items-center gap-gos-4","data-test":"employee-permissions",children:[e.jsx("span",{className:"rounded-gos-4 bg-azzurro-alice px-gos-6 py-gos-2 text-plain-text text-gosblue",children:r.permissions[0].description||r.permissions[0].name}),r.permissions.length>1&&e.jsxs("span",{className:"rounded-gos-4 bg-azzurro-alice px-gos-6 py-gos-2 text-plain-text text-gosblue","data-test":"employee-permissions-more",title:r.permissions.slice(1).map(x=>x.description||x.name).join(", "),children:["+",r.permissions.length-1]})]}):e.jsx("span",{className:"text-interlineare",children:"ÐÐµÑ Ð¿Ñав доÑÑÑпа"})})]}),e.jsx(Be,{employee:r,storeId:c.ulid,availablePermissions:t,isOpen:P===r.id,onOpenChange:x=>N(x?r.id:null)})]},r.id))})]})})]})})]})}function Be({employee:s,storeId:i,availablePermissions:o,isOpen:v,onOpenChange:c}){const[F,h]=f.useState(!1),[j,b]=f.useState(!1),a=ne({job_name:s.job_name??null,is_spokesperson:s.is_spokesperson??!1,default_spokesperson:s.default_spokesperson??!1,permissions:s.permissions?.map(t=>
1t.id)??[]});f.useEffect(()=>{v&&(h(!1),b(!1),a.setData({job_name:s.job_name??null,is_spokesperson:s.is_spokesperson??!1,default_spokesperson:s.default_spokesperson??!1,permissions:s.permissions?.map(t=>t.id)??[]}),a.clearErrors())},[v,s.id]);const g=t=>{const n=a.data.permissions||[],m=n.includes(t)?n.filter(u=>u!==t):[...n,t];a.setData("permissions",m)},w=t=>{a.setData({...a.data,is_spokesperson:t,default_spokesperson:t?a.data.default_spokesperson:!1})},A=t=>{a.setData({...a.data,default_spokesperson:t,is_spokesperson:t?!0:a.data.is_spokesperson})},P=t=>{t.preventDefault(),a.submit(pe({store:i,employee:s.id}),{onSuccess:()=>{_.success("СоÑÑÑдник обновлÑн"),c(!1)},onError:n=>{const m=Object.values(n)[0];_.error("Ðе ÑдалоÑÑ Ð¾Ð±Ð½Ð¾Ð²Ð¸ÑÑ ÑоÑÑÑдника",{description:m})}})},N=()=>{b(!0),S.delete(ce.url({store:i,employee:s.id}),{onSuccess:()=>{_.success("СоÑÑÑдник ÑÑпеÑно Ñдален"),c(!1)},onError:t=>{const n=Object.values(t)[0];_.error("ÐÑибка пÑи Ñдалении ÑоÑÑÑдника",{description:n})},onFinish:()=>b(!1)})},C=t=>{t||h(!1),c(t)};return e.jsx(me,{open:v,onOpenChange:C,children:e.jsx(ue,{"data-test":"edit-employee-dialog",children:F?e.jsxs(e.Fragment,{children:[e.jsxs(z,{children:[e.jsx(G,{children:"УдалиÑÑ ÑоÑÑÑдника"}),e.jsxs(q,{children:["ÐÑ ÑвеÑенÑ, ÑÑо Ñ
оÑиÑе ÑдалиÑÑ"," ",s.user?.name||s.user?.email," из магазина? ÐÑо дейÑÑвие нелÑÐ·Ñ Ð¾ÑмениÑÑ."]})]}),e.jsxs(R,{children:[e.jsx(p,{type:"button",variant:"outline",onClick:()=>h(!1),disabled:j,children:"ÐÑмена"}),e.jsx(p,{type:"button",variant:"destructive","data-test":"confirm-delete-employee",onClick:N,disabled:j,children:j?"Удаление...":"УдалиÑÑ"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(z,{children:[e.jsx(G,{children:"РедакÑиÑоваÑÑ ÑоÑÑÑдника"}),e.jsxs(q,{children:["ÐолжноÑÑÑ, ÑÑаÑÑÑ Ð¿ÑедÑÑавиÑÐµÐ»Ñ Ð¸ пÑава доÑÑÑпа длÑ"," ",s.user?.name||s.user?.email]})]}),e.jsxs("form",{onSubmit:P,className:"flex min-h-0 flex-1 flex-col",children:[e.jsx(xe,{children:e.jsxs("div",{className:"space-y-gos-16",children:[e.jsxs("div",{className:"space-y-gos-8",children:[e.jsx(V,{id:`job-name-${s.id}`,name:"job_name",type:"text",label:"ÐолжноÑÑÑ",placeholder:"ÐапÑимеÑ, менеджеÑ",value:a.data.job_name??"",onChange:t=>a.setData("job_name",t.target.value||null),error:a.errors.job_name,maxLength:255}),e.jsxs("div",{className:"flex items-center gap-gos-8",children:[e.jsx(T,{id:`is-spokesperson-${s.id}`,checked:a.data.is_spokesperson,onCheckedChange:t=>w(t===!0)}),e.jsx(I,{htmlFor:`is-spokesperson-${s.id}`,className:"flex-1 cursor-pointer",children:"ÐÑедÑÑавиÑелÑ"})]}),a.errors.is_spokesperson&&e.jsx("p",{className:"text-plain-small text-destructive",children:a.errors.is_spokesperson}),e.jsxs("div",{className:"flex items-center gap-gos-8",children:[e.jsx(T,{id:`default-spokesperson-${s.id}`,checked:a.data.default_spokesperson,onCheckedChange:t=>A(t===!0)}),e.jsx(I,{htmlFor:`default-spokesperson-${s.id}`,className:"flex-1 cursor-pointer",children:"ÐÑедÑÑавиÑÐµÐ»Ñ Ð¿Ð¾ ÑмолÑаниÑ"})]}),a.errors.default_spokesperson&&e.jsx("p",{className:"text-plain-small text-destructive",children:a.errors.default_spokesperson})]}),e.jsxs("div",{className:"space-y-gos-8",children:[e.jsx("p",{className:"text-plain-text font-semibold",children:"ÐÑава доÑÑÑпа"}),o.map(t=>{const m=(a.data.permissions||[]).includes(t.id);return e.jsxs("div",{className:"flex items-center gap-gos-8",children:[e.jsx(T,{id:`permission-${t.id}`,checked:m,onCheckedChange:()=>g(t.id)}),e.jsx(I,{htmlFor:`permission-${t.id}`,className:"flex-1 cursor-pointer",children:t.description||t.name})]},t.id)}),a.errors.permissions&&e.jsx("p",{className:"text-plain-small text-destructive",children:a.errors.permissions})]})]})}),e.jsxs(R,{className:"sm:justify-between",children:[e.jsxs(p,{type:"button",variant:"destructive","data-test":"delete-employee",onClick:()=>h(!0),disabled:a.processing,children:[e.jsx(X,{className:"h-4 w-4"}),"УдалиÑÑ"]}),e.jsx(Ce,{isLoading:a.processing,children:"СоÑ
ÑаниÑÑ"})]})]})]})})})}$e.layout=we;export{$e 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.