1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4543],{6191:(e,a,t)=>{t.d(a,{A:()=>n});let n=(0,t(71847).A)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},19408:(e,a,t)=>{t.d(a,{A:()=>n});let n=(0,t(71847).A)("Building2",[["path",{d:"M6 22V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v18Z",key:"1b4qmf"}],["path",{d:"M6 12H4a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2",key:"i71pzd"}],["path",{d:"M18 9h2a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-2",key:"10jefs"}],["path",{d:"M10 6h4",key:"1itunk"}],["path",{d:"M10 10h4",key:"tcdvrf"}],["path",{d:"M10 14h4",key:"kelpxr"}],["path",{d:"M10 18h4",key:"1ulq68"}]])},24543:(e,a,t)=>{t.r(a),t.d(a,{default:()=>b});var n=t(95155),l=t(12115),s=t(96648),i=t(19408),r=t(6191),o=t(35299),c=t(61362),d=t(65229),p=t(86651),m=t(76907),x=t(18720),u=t(29813);function b(e){let{projectId:a}=e,t=(0,l.useMemo)(()=>(0,s.createClient)(),[]),[b,f]=(0,l.useState)([]),[h,y]=(0,l.useState)(!0),[j,k]=(0,l.useState)(!1),[w,v]=(0,l.useState)(!1),[g,N]=(0,l.useState)(!1),[_,z]=(0,l.useState)(!1),[C,A]=(0,l.useState)(!1),[S,P]=(0,l.useState)(""),[I,M]=(0,l.useState)([]),[R,q]=(0,l.useState)({name:"",nip:"",rola:"klient",phone:"",email:"",address:""}),B=(0,l.useCallback)(async()=>{y(!0);let{data:e}=await t.from("project_clients").select("id, client_id, company_name, company_nip, company_address, company_email, company_phone, contact_name, rola").eq("project_id",a).order("created_at",{ascending:!1});f(e||[]),y(!1)},[a,t]);(0,l.useEffect)(()=>{B()},[B]),(0,l.useEffect)(()=>{if(!S.trim()||S.trim().length<2)return void M([]);let e=setTimeout(async()=>{N(!0);let e=S.trim(),{data:a}=await t.from("clients").select("id, name, client_type, nip, address, city, phone, email, client_contacts(first_name, last_name, is_primary)").or("name.ilike.%".concat(e,"%,nip.ilike.%").concat(e,"%,city.ilike.%").concat(e,"%")).limit(8);M(a||[]),N(!1)},280);return()=>clearTimeout(e)},[S,t]);let D=async function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"klient",l=e.client_contacts.find(e=>e.is_primary)||e.client_contacts[0]||null,{error:s}=await t.from("project_clients").insert({project_id:a,client_id:e.id,company_name:e.name,company_nip:e.nip,company_address:e.address,company_email:e.email,company_phone:e.phone,contact_name:l?"".concat(l.first_name," ").concat(l.last_name):null,rola:n});if(s)return void x.oR.error("Nie udaÅo siÄ przypisaÄ klienta: ".concat(s.message));x.oR.success('Dodano klienta "'.concat(e.name,'" do projektu')),P(""),M([]),k(!1),v(!1),B()},E=async()=>{let e=(0,u.H2)(R.nip);if(10===e.length){A(!0);try{let a=await fetch("/api/companies/lookup?nip=".concat(e)),t=await a.json();if(!a.ok)return void x.oR.error(t.error||"Nie udaÅo siÄ pobraÄ danych po NIP");let n=(0,u.U1)(t.address);q(e=>({...e,name:t.name||e.name,nip:t.nip||e.nip,address:[n.addressLine,n.postalCode,n.city].filter(Boolean).join(", ")||e.address})),x.oR.success("UzupeÅniono dane klienta: ".concat(t.name))}catch(e){x.oR.error("BÅÄ
d poÅÄ
czenia z rejestrem")}finally{A(!1)}}},H=async()=>{if(!R.name.trim())return void x.oR.error("Podaj nazwÄ klienta");z(!0);try{let{data:{user:e}}=await t.auth.getUser();if(!e)return void x.oR.error("Brak aktywnej sesji");let a=(0,u.H2)(R.nip),n=null;if(a){let{data:l}=await t.from("clients").select("id, name, client_type, nip, address, city, phone, email, client_contacts(first_name, last_name, is_primary)").eq("user_id",e.id).eq("nip",a).maybeSingle();l&&(n=l)}if(!n){let{data:a}=await t.from("clients").select("id, name, client_type, nip, address, city, phone, email, client_contacts(first_name, last_name, is_primary)").eq("user_id",e.id).ilike("name",R.name.trim()).maybeSingle();a&&(n=a)}if(!n){let{data:l,error:s}=await t.from("clients").insert({user_id:e.id,name:R.name.trim(),client_type:"inwestor"===R.rola?"inwestor":"klient",nip:a||null,address:R.address||null,phone:R.phone||null,email:R.email||null,source:"project_inline"}).select("id, name, client_type, nip, address, city, phone, email, client_contacts(first_name, last_name, is_primary)").single();if(s||!l)return void x.oR.error("Nie udaÅo siÄ utworzyÄ kartoteki klienta: ".concat((null==s?void 0:s.message)||"nieznany bÅÄ
d"));n=l}await D(n,R.rola),q({name:"",nip:"",rola:"klient",phone:"",email:"",address:""})}finally{z(!1)}},K=async e=>{let{error:a}=await t.from("project_clients").delete().eq("id",e);if(a)return void x.oR.error("Nie udaÅo siÄ usunÄ
Ä powiÄ
zania: ".concat(a.message));f(a=>a.filter(a=>a.id!==e)),x.oR.success("UsuniÄto odbiorcÄ z projektu")};return(0,n.jsxs)("div",{className:"rounded-md border border-[#30363d] bg-[#161b22] p-4",children:[(0,n.jsxs)("div",{className:"mb-4 flex items-center justify-between gap-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h2",{className:"flex items-center gap-2 text-[11px] font-black uppercase tracking-wide text-[#e6edf3]",children:[(0,n.jsx)(i.A,{className:"h-4 w-4 text-[#58a6ff]"}),"Klienci / odbiorcy oferty"]}),(0,n.jsx)("p",{className:"mt-1 text-[11px] text-[#8b949e]",children:"Przypisz klienta z kartoteki albo dodaj nowego rÄcznie do katalogu i projektu jednoczeÅnie."})]}),!j&&(0,n.jsxs)("button",{onClick:()=>k(!0),className:"brand-gradient-cta flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-black text-white transition-colors",children:[(0,n.jsx)(r.A,{className:"h-3.5 w-3.5"}),"Dodaj klienta"]})]}),h?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-2 text-xs text-[#8b949e]",children:[(0,n.jsx)(o.A,{className:"h-3.5 w-3.5 animate-spin"}),"Åadowanie klient\xf3w projektu..."]}):b.length>0?(0,n.jsx)("div",{className:"mb-3 space-y-2",children:b.map(e=>(0,n.jsxs)("div",{className:"group flex items-center justify-between rounded-md border border-[#30363d] bg-[#0d1117] p-2.5 transition-colors hover:border-[#58a6ff]/30",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md bg-[#58a6ff]/10",children:(0,n.jsx)(i.A,{className:"h-4 w-4 text-[#58a6ff]"})}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("p",{className:"text-xs font-semibold text-[#c9d1d9]",children:e.company_name||"-"}),(0,n.jsx)("span",{className:"rounded bg-[#21262d] px-1.5 py-0.5 text-[10px] text-[#8b949e]",children:u.z9[e.rola]||e.rola}),e.client_id&&(0,n.jsx)(c.A,{className:"h-3.5 w-3.5 text-emerald-400"})]}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-[#8b949e]",children:[e.company_nip&&(0,n.jsxs)("span",{children:["NIP: ",e.company_nip]}),e.contact_name&&(0,n.jsxs)("span",{children:["Kontakt: ",e.contact_name]}),e.company_email&&(0,n.jsx)("span",{children:e.company_email})]})]})]}),(0,n.jsx)("button",{onClick:()=>K(e.id),className:"p-1 text-[#8b949e] opacity-0 transition-all hover:text-red-400 group-hover:opacity-100",children:(0,n.jsx)(d.A,{className:"h-3.5 w-3.5"})})]},e.id))}):(0,n.jsx)("p",{className:"mb-3 text-xs text-[#484f58]",children:"Brak przypisanych klient\xf3w. Dodaj odbiorcÄ oferty, aby pracowaÄ na jednej kartotece klienta."}),j&&(0,n.jsxs)("div",{className:"mt-3 overflow-hidden rounded-md border border-[#30363d] animate-in fade-in slide-in-from-top-1",children:[(0,n.jsxs)("div",{className:"flex gap-1 border-b border-[#30363d] bg-[#0d1117] p-2",children:[(0,n.jsx)("button",{onClick:()=>v(!1),className:"flex-1 rounded-md px-3 py-1.5 text-xs font-black transition-colors ".concat(w?"text-[#8b949e] hover:bg-[#161b22] hover:text-white":"brand-gradient-active"),children:"Wybierz z kartoteki"}),(0,n.jsx)("button",{onClick:()=>{v(!0),M([])},className:"flex-1 rounded-md px-3 py-1.5 text-xs font-black transition-colors ".concat(w?"brand-gradient-active":"text-[#8b949e] hover:bg-[#161b22] hover:text-white"),children:"Dodaj nowego"})]}),(0,n.jsxs)("div",{className:"bg-[#0d1117] p-3",children:[w?(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] font-bold uppercase tracking-[0.12em] text-[#8b949e]",children:"Nazwa klienta"}),(0,n.jsx)("input",{value:R.name,onChange:e=>q(a=>({...a,name:e.target.value})),placeholder:"np. Gmina Piaseczno",className:"w-full rounded-md border border-[#30363d] bg-[#161b22] px-3 py-2 text-sm text-white outline-none transition-colors placeholder:text-[#484f58] focus:border-[#58a6ff]"})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] font-bold uppercase tracking-[0.12em] text-[#8b949e]",children:"Rola w projekcie"}),(0,n.jsx)("select",{value:R.rola,onChange:e=>q(a=>({...a,rola:e.target.value})),className:"w-full rounded-md border border-[#30363d] bg-[#161b22] px-3 py-2 text-sm text-white outline-none transition-colors focus:border-[#58a6ff]",children:u.o$.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] font-bold uppercase tracking-[0.12em] text-[#8b949e]",children:"NIP"}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("input",{value:R.nip,onChange:e=>q(a=>({...a,nip:(0,u.H2)(e.target.value)})),placeholder:"10 cyfr",className:"w-full rounded-md border border-[#30363d] bg-[#161b22] px-3 py-2 text-sm text-white outline-none transition-colors placeholder:text-[#484f58] focus:border-[#58a6ff]"}),(0,n.jsxs)("button",{type:"button",onClick:E,disabled:C||10!==(0,u.H2)(R.nip).length,className:"inline-flex min-w-[140px] items-center justify-center gap-2 rounded-md border border-[#58a6ff]/20 bg-[#58a6ff]/10 px-3 py-2 text-xs font-black text-[#58a6ff] transition-colors disabled:cursor-not-allowed disabled:opacity-40",children:[C?(0,n.jsx)(o.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,n.jsx)(m.A,{className:"h-3.5 w-3.5"}),"Pobierz po NIP"]})]})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] font-bold uppercase tracking-[0.12em] text-[#8b949e]",children:"Telefon"}),(0,n.jsx)("input",{value:R.phone,onChange:e=>q(a=>({...a,phone:e.target.value})),placeholder:"+48 600 000 000",className:"w-full rounded-md border border-[#30363d] bg-[#161b22] px-3 py-2 text-sm text-white outline-none transition-colors placeholder:text-[#484f58] focus:border-[#58a6ff]"})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)("label",{className:"text-[11px] font-bold uppercase tracking-[0.12em] text-[#8b949e]",children:"E-mail"}),(0,n.jsx)("input",{value:R.email,onChange:e=>q(a=>({...a,email:e.target.value})),placeholder:"[email protected]",className:"w-full rounded-md border border-[#30363d] bg-[#161b22] px-3 py-2 text-sm text-white outline-none transition-colors placeholder:text-[#484f58] focus:border-[#58a6ff]"})]}),(0,n.jsxs)("div",{className:"space-y-1.5 md:col-span-2",children:[(0,n.jsx)("label",{className:"text-[11px] font-bold uppercase tracking-[0.12em] text-[#8b949e]",children:"Adres"}),(0,n.jsx)("input",{value:R.address,onChange:e=>q(a=>({...a,address:e.target.value})),placeholder:"ul. PrzykÅadowa 12, 00-001 Warszawa",className:"w-full rounded-md border border-[#30363d] bg-[#161b22] px-3 py-2 text-sm text-white outline-none transition-colors placeholder:text-[#484f58] focus:border-[#58a6ff]"})]})]}),(0,n.jsxs)("button",{type:"button",onClick:H,disabled:_,className:"brand-gradient-cta inline-flex w-full items-center justify-center gap-2 rounded-md px-4 py-2 text-xs font-black text-white transition-colors disabled:opacity-50",children:[_?(0,n.jsx)(o.A,{className:"h-4 w-4 animate-spin"}):(0,n.jsx)(r.A,{className:"h-4 w-4"}),"Dodaj klienta do kartoteki i projektu"]})]}):(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(p.A,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-[#8b949e]"}),(0,n.jsx)("input",{value:S,onChange:e=>P(e.target.value),placeholder:"Szukaj klienta po nazwie, NIP lub mieÅcie",className:"w-full rounded-md border border-[#30363d] bg-[#161b22] py-2 pl-9 pr-3 text-sm text-white outline-none transition-colors placeholder:text-[#484f58] focus:border-[#58a6ff]"})]}),g&&(0,n.jsxs)("div",{className:"flex items-center gap-2 py-2 text-xs text-[#8b949e]",children:[(0,n.jsx)(o.A,{className:"h-3.5 w-3.5 animate-spin"}),"Szukam klient\xf3w..."]}),!g&&I.length>0&&(0,n.jsx)("div",{className:"space-y-2",children:I.map(e=>{let a=e.client_contacts.find(e=>e.is_primary)||e.client_contacts[0]||null;return(0,n.jsxs)("div",{className:"flex flex-col gap-2 rounded-md border border-[#30363d] bg-[#161b22] p-3 md:flex-row md:items-center md:justify-between",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("p",{className:"truncate text-sm font-semibold text-[#c9d1d9]",children:e.name}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-[#8b949e]",children:[e.nip&&(0,n.jsxs)("span",{children:["NIP: ",e.nip]}),e.city&&(0,n.jsx)("span",{children:e.city}),a&&(0,n.jsxs)("span",{children:["Kontakt: ",a.first_name," ",a.last_name]})]})]}),(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:u.o$.slice(0,4).map(a=>(0,n.jsxs)("button",{type:"button",onClick:()=>
1D(e,a.value),className:"inline-flex items-center gap-1 rounded-md border border-[#58a6ff]/20 bg-[#58a6ff]/10 px-2.5 py-1.5 text-[11px] font-black text-[#58a6ff] transition-colors hover:bg-[#58a6ff]/20",children:[(0,n.jsx)(r.A,{className:"h-3 w-3"}),a.label]},a.value))})]},e.id)})})]}),(0,n.jsx)("div",{className:"mt-3 flex justify-end",children:(0,n.jsx)("button",{type:"button",onClick:()=>{k(!1),v(!1),P(""),M([])},className:"text-xs font-bold text-[#8b949e] transition-colors hover:text-white",children:"Zamknij panel dodawania"})})]})]})]})}},29813:(e,a,t)=>{t.d(a,{H2:()=>r,U1:()=>o,gi:()=>n,j8:()=>s,o$:()=>l,on:()=>c,z9:()=>i});let n=[{value:"klient",label:"Klient"},{value:"inwestor",label:"Inwestor"},{value:"generalny_wykonawca",label:"Generalny wykonawca"},{value:"deweloper",label:"Deweloper"},{value:"biuro_projektowe",label:"Biuro projektowe"},{value:"instytucja",label:"Instytucja"},{value:"inny",label:"Inny"}],l=[{value:"klient",label:"Klient"},{value:"inwestor",label:"Inwestor"},{value:"generalny_wykonawca",label:"Generalny wykonawca"},{value:"partner",label:"Partner"},{value:"podwykonawca",label:"Podwykonawca"},{value:"biuro_projektowe",label:"Biuro projektowe"},{value:"instytucja",label:"Instytucja"},{value:"inny",label:"Inny"}],s=Object.fromEntries(n.map(e=>[e.value,e.label])),i=Object.fromEntries(l.map(e=>[e.value,e.label]));function r(e){return(e||"").replace(/[^\d]/g,"")}function o(e){if(!e)return{addressLine:"",city:"",postalCode:""};let a=e.split(",").map(e=>e.trim()).filter(Boolean),t=a.at(-1)||"",n=t.match(/(\d{2}-\d{3})\s+(.*)$/);return{addressLine:a.length>1?a.slice(0,-1).join(", "):e,city:(null==n?void 0:n[2])||t,postalCode:(null==n?void 0:n[1])||""}}function c(e){return"project_inline"===e?"Dodany z projektu":"offer_inline"===e?"Dodany z oferty":"Manualny"}},86651:(e,a,t)=>{t.d(a,{A:()=>n});let n=(0,t(71847).A)("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]])}}]);
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.