1import{r as e}from"./chunk-QTnfLwEv.js";import{t}from"./react-xd4aoMiW.js";import{t as n}from"./jsx-runtime-DsKLSDJq.js";import{t as r}from"./client-Dx86dDvJ.js";import{r as i}from"./dist-Dwz9hXTh.js";import{t as a}from"./button-eRC2Y0Fi.js";import{a as o,i as s,n as c,r as l,t as u}from"./select-DnYfwyQ4.js";import{t as d}from"./pencil-CCVbbXN7.js";import{t as f}from"./plus-l4z-tLFa.js";import{t as p}from"./triangle-alert-BzPO_Gco.js";import{Et as m,Kt as h,Mt as g,Nt as _,V as v,Vt as y,_t as b,dn as x,dt as S,ft as C,gt as w,ht as T,it as E,mt as D,ot as O,pt as k,un as A,ut as j,yt as M}from"./index-BAF8SXXG.js";var N=e(t(),1),P=n(),F={"Beyaz EÅya":11,"Klima & Isıtma":12,Bilgisayar:7,"Cep Telefonu":5,"TV & Ses":9,"Küçük Ev Aletleri":6,Otomobil:16,DiÄer:10},I={"Beyaz EÅya":`kompresör / pompa yıpranması`,"Klima & Isıtma":`gaz kaçaÄı ve fan arızası`,Bilgisayar:`termal macun ve disk yıpranması`,"Cep Telefonu":`batarya kapasite kaybı`,"TV & Ses":`panel besleme kartı arızası`,"Küçük Ev Aletleri":`motor fırçası aÅınması`,Otomobil:`triger ve fren aksamı bakımı`,DiÄer:`genel yıpranma`};function L(e){let t=[],n=(e,n)=>{if(!e)return;let r=new Date(e);Number.isNaN(r.getTime())||t.push({...n,date:r})};if(n(e.purchase_date,{label:`Satın alındı`,detail:`${e.brand} ${e.model}`,tone:`past`,icon:`buy`}),n(e.last_service_date,{label:`Son servis`,detail:`Bakım / onarım kaydı`,tone:`past`,icon:`service`}),n(e.warranty_end,{label:`Garanti bitiÅ`,detail:new Date(e.warranty_end??0).getTime()<Date.now()?`Garanti süresi doldu`:`Garanti devam ediyor`,tone:new Date(e.warranty_end??0).getTime()<Date.now()?`past`:`future`,icon:`warranty`}),n(e.next_service_date,{label:`Planlı bakım`,detail:`Hatırlatma kurulu`,tone:`future`,icon:`service`}),e.purchase_date){let n=F[e.category]??10,r=new Date(e.purchase_date);if(!Number.isNaN(r.getTime())){let i=new Date(r);i.setMonth(i.getMonth()+Math.round(n*12*.7));let a=Math.round((i.getTime()-Date.now())/(1e3*60*60*24*30.4));t.push({date:i,label:a>0?`Risk penceresi â ${a} ay sonra`:`Risk penceresinde`,detail:`Bu yaÅ aralıÄında en sık: ${I[e.category]??`genel yıpranma`}`,tone:`risk`,icon:`risk`})}}return t.sort((e,t)=>e.date.getTime()-t.date.getTime())}var R={buy:x,warranty:_,service:M,risk:p};function z({devices:e}){let t=(0,N.useMemo)(()=>e.map(e=>({device:e,events:L(e)})).filter(e=>e.events.length>0),[e]);return t.length?(0,P.jsxs)(`section`,{className:`mb-8 rounded-xl border border-line bg-paper p-5`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,P.jsx)(g,{className:`h-4 w-4 text-brand`}),(0,P.jsx)(`h2`,{className:`font-display text-lg font-bold text-ink`,children:`Arıza Zaman Tüneli`})]}),(0,P.jsx)(`p`,{className:`text-sm text-muted-ink mb-5`,children:`Cihazlarınızın geçmiÅi ve önümüzdeki riskler tek bir çizgide. Tahminler kategori ortalama ömrüne dayanır.`}),(0,P.jsx)(`div`,{className:`space-y-7`,children:t.map(({device:e,events:t})=>(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`font-semibold text-ink`,children:e.nickname||`${e.brand} ${e.model}`}),(0,P.jsx)(v,{variant:`soft`,children:e.category})]}),(0,P.jsxs)(`div`,{className:`relative overflow-x-auto pb-2`,children:[(0,P.jsx)(`div`,{className:`absolute inset-x-0 top-[18px] h-px bg-line`,"aria-hidden":!0}),(0,P.jsx)(`div`,{className:`flex min-w-max gap-6`,children:t.map((e,t)=>{let n=R[e.icon],r=e.date.getTime()<Date.now();return(0,P.jsxs)(`div`,{className:`relative w-[190px] shrink-0`,children:[(0,P.jsxs)(`span`,{className:`relative z-10 grid h-9 w-9 place-items-center rounded-full border-2 border-paper ${e.tone===`risk`?`bg-gold text-ink`:r?`bg-mist text-muted-ink`:`bg-brand text-white`}`,children:[e.tone===`risk`&&(0,P.jsx)(`span`,{className:`absolute inset-0 rounded-full bg-gold/40 animate-ping`}),(0,P.jsx)(n,{className:`relative h-4 w-4`})]}),(0,P.jsxs)(`div`,{className:`mt-2.5`,children:[(0,P.jsx)(`div`,{className:`text-[11px] font-semibold text-muted-ink`,children:e.date.toLocaleDateString(`tr-TR`,{month:`short`,year:`numeric`})}),(0,P.jsx)(`div`,{className:`text-[13px] font-bold text-ink leading-snug`,children:e.label}),(0,P.jsx)(`div`,{className:`text-[12px] text-muted-ink leading-snug`,children:e.detail})]})]},t)})})]})]},e.id))})]}):null}var B=[`Beyaz EÅya`,`Klima & Isıtma`,`Bilgisayar`,`Cep Telefonu`,`TV & Ses`,`Küçük Ev Aletleri`,`DiÄer`],V={category:`Beyaz EÅya`,brand:``,model:``,serial_number:``,nickname:``,purchase_date:``,warranty_end:``,purchase_place:``,notes:``};function H(){let{user:e}=O(),[t,n]=(0,N.useState)([]),[d,p]=(0,N.useState)(!0),[m,g]=(0,N.useState)(!1),[_,v]=(0,N.useState)(null),[y,x]=(0,N.useState)(V),[M,F]=(0,N.useState)(!1);async function I(){if(!e)return;p(!0);let{data:t,error:a}=await r.from(`user_devices`).select(`*`).order(`created_at`,{ascending:!1});a?i.error(a.message):n(t??[]),p(!1)}(0,N.useEffect)(()=>{I()},[e?.id]);function L(){v(null),x(V),g(!0)}function R(e){v(e),x(e),g(!0)}async function H(){if(!e)return;if(!y.category||!y.brand||!y.model){i.error(`Kategori, marka ve model zorunlu.`);return}let t={user_id:e.id,category:y.category,brand:y.brand,model:y.model,serial_number:y.serial_number||null,nickname:y.nickname||null,purchase_date:y.purchase_date||null,warranty_end:y.warranty_end||null,purchase_place:y.purchase_place||null,notes:y.notes||null,last_service_date:y.last_service_date||null,next_service_date:y.next_service_date||null},n;if(_?{error:n}=await r.from(`user_devices`).update(t).eq(`id`,_.id):{error:n}=await r.from(`user_devices`).insert(t),n)return i.error(n.message);i.success(_?`Cihaz güncellendi`:`Cihaz eklendi`),g(!1),I()}async function G(e){if(!confirm(`Cihaz silinsin mi?`))return;let{error:t}=await r.from(`user_devices`).delete().eq(`id`,e);if(t)return i.error(t.message);i.success(`Silindi`),I()}return(0,P.jsxs)(`div`,{className:`mx-auto max-w-5xl px-4 py-8`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between mb-6`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h1`,{className:`font-display text-2xl font-bold`,children:`Cihazlarım`}),(0,P.jsx)(`p`,{className:`text-sm text-muted-ink`,children:`Garanti, bakım, geri çaÄırma ve destek â hepsi tek yerde.`})]}),(0,P.jsxs)(a,{onClick:L,children:[(0,P.jsx)(f,{className:`w-4 h-4 me-1`}),` Cihaz Ekle`]})]}),!d&&t.length>0&&(0,P.jsx)(z,{devices:t}),d?(0,P.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,P.jsx)(h,{className:`w-6 h-6 animate-spin text-brand`})}):t.length===0?(0,P.jsxs)(`div`,{className:`rounded-xl border border-dashed border-line p-12 text-center`,children:[(0,P.jsx)(`p`,{className:`text-muted-ink mb-4`,children:`Henüz k
1ayıtlı cihazınız yok.`}),(0,P.jsxs)(a,{onClick:L,children:[(0,P.jsx)(f,{className:`w-4 h-4 me-1`}),`İlk cihazını ekle`]})]}):(0,P.jsx)(`div`,{className:`grid md:grid-cols-2 gap-4`,children:t.map(e=>(0,P.jsx)(U,{device:e,onEdit:()=>R(e),onDelete:()=>G(e.id)},e.id))}),(0,P.jsx)(C,{open:m,onOpenChange:g,children:(0,P.jsxs)(k,{className:`max-w-2xl max-h-[90vh] overflow-y-auto`,children:[(0,P.jsxs)(w,{children:[(0,P.jsx)(b,{children:_?`Cihaz Düzenle`:`Yeni Cihaz`}),(0,P.jsx)(D,{children:`Garantini takip et, bakım hatırlatmaları al, geri çaÄırma uyarılarını kaçırma.`})]}),(0,P.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3 py-2`,children:[(0,P.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,P.jsx)(E,{children:`Kategori *`}),(0,P.jsxs)(u,{value:y.category,onValueChange:e=>x({...y,category:e}),children:[(0,P.jsx)(s,{children:(0,P.jsx)(o,{})}),(0,P.jsx)(c,{children:B.map(e=>(0,P.jsx)(l,{value:e,children:e},e))})]})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(E,{children:`Marka *`}),(0,P.jsx)(S,{value:y.brand??``,onChange:e=>x({...y,brand:e.target.value}),placeholder:`Arçelik`})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(E,{children:`Model *`}),(0,P.jsx)(S,{value:y.model??``,onChange:e=>x({...y,model:e.target.value}),placeholder:`9142 ETI`})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(E,{children:`Takma Ad`}),(0,P.jsx)(S,{value:y.nickname??``,onChange:e=>x({...y,nickname:e.target.value}),placeholder:`Mutfak Buzdolabı`})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(E,{children:`Seri Numarası`}),(0,P.jsxs)(`div`,{className:`flex gap-2`,children:[(0,P.jsx)(S,{value:y.serial_number??``,onChange:e=>x({...y,serial_number:e.target.value}),placeholder:`SN123...`}),(0,P.jsx)(a,{type:`button`,variant:`outline`,size:`icon`,onClick:()=>F(!0),title:`Kamera ile oku`,children:(0,P.jsx)(A,{className:`w-4 h-4`})})]})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(E,{children:`Satın Alma Tarihi`}),(0,P.jsx)(S,{type:`date`,value:y.purchase_date??``,onChange:e=>x({...y,purchase_date:e.target.value})})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(E,{children:`Garanti BitiÅ`}),(0,P.jsx)(S,{type:`date`,value:y.warranty_end??``,onChange:e=>x({...y,warranty_end:e.target.value})})]}),(0,P.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,P.jsx)(E,{children:`Satın Alma Yeri`}),(0,P.jsx)(S,{value:y.purchase_place??``,onChange:e=>x({...y,purchase_place:e.target.value}),placeholder:`Teknosa - Ankara`})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(E,{children:`Son Bakım`}),(0,P.jsx)(S,{type:`date`,value:y.last_service_date??``,onChange:e=>x({...y,last_service_date:e.target.value})})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(E,{children:`Sonraki Bakım`}),(0,P.jsx)(S,{type:`date`,value:y.next_service_date??``,onChange:e=>x({...y,next_service_date:e.target.value})})]}),(0,P.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,P.jsx)(E,{children:`Notlar`}),(0,P.jsx)(j,{value:y.notes??``,onChange:e=>x({...y,notes:e.target.value}),rows:2})]})]}),(0,P.jsxs)(T,{children:[(0,P.jsx)(a,{variant:`ghost`,onClick:()=>g(!1),children:`İptal`}),(0,P.jsx)(a,{onClick:H,children:_?`Güncelle`:`Ekle`})]})]})}),(0,P.jsx)(W,{open:M,onOpenChange:F,onDetected:e=>{x(t=>({...t,serial_number:e})),F(!1),i.success(`Seri numarası okundu`)}})]})}function U({device:e,onEdit:t,onDelete:n}){let r=(0,N.useMemo)(()=>{if(!e.warranty_end)return null;let t=Math.floor((new Date(e.warranty_end).getTime()-Date.now())/(1e3*60*60*24));return t<0?{label:`Garanti bitti`,tone:`danger`}:t<30?{label:`Garanti ${t} gün`,tone:`warn`}:{label:`Garantide (${t} gün)`,tone:`ok`}},[e.warranty_end]),i=e.next_service_date?Math.floor((new Date(e.next_service_date).getTime()-Date.now())/(1e3*60*60*24)):null;return(0,P.jsxs)(`div`,{className:`rounded-xl border border-line bg-paper p-4 flex flex-col gap-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`div`,{className:`text-[11px] uppercase text-muted-ink font-semibold`,children:e.category}),(0,P.jsx)(`div`,{className:`font-display font-bold text-lg`,children:e.nickname||`${e.brand} ${e.model}`}),(0,P.jsxs)(`div`,{className:`text-sm text-muted-ink`,children:[e.brand,` · `,e.model]}),e.serial_number&&(0,P.jsxs)(`div`,{className:`text-xs text-muted-ink font-mono mt-0.5`,children:[`SN: `,e.serial_number]})]}),(0,P.jsxs)(`div`,{className:`flex gap-1`,children:[(0,P.jsx)(a,{size:`icon`,variant:`ghost`,onClick:t,children:(0,P.jsx)(d,{className:`w-4 h-4`})}),(0,P.jsx)(a,{size:`icon`,variant:`ghost`,onClick:n,children:(0,P.jsx)(m,{className:`w-4 h-4 text-danger`})})]})]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[r&&(0,P.jsxs)(v,{variant:r.tone===`ok`?`default`:r.tone===`warn`?`gold-soft`:`down`,children:[(0,P.jsx)(_,{className:`w-3 h-3 me-1`}),r.label]}),i!==null&&i<30&&(0,P.jsxs)(v,{variant:`gold-soft`,children:[(0,P.jsx)(M,{className:`w-3 h-3 me-1`}),`Bakım `,i<0?`geçti`:`${i} gün`]}),e.recall_status&&e.recall_status!==`none`&&(0,P.jsxs)(v,{variant:`down`,children:[(0,P.jsx)(p,{className:`w-3 h-3 me-1`}),`Geri çaÄırma`]})]}),(0,P.jsx)(`div`,{className:`flex gap-2 pt-2 border-t border-line`,children:(0,P.jsxs)(a,{size:`sm`,variant:`outline`,className:`flex-1`,onClick:()=>window.dispatchEvent(new CustomEvent(`openQuote`,{detail:{device:`${e.brand} ${e.model}`,category:e.category}})),children:[(0,P.jsx)(y,{className:`w-3.5 h-3.5 me-1`}),`Problem çöz`]})})]})}function W({open:e,onOpenChange:t,onDetected:n}){let r=(0,N.useRef)(null),i=(0,N.useRef)(null),[o,s]=(0,N.useState)(null),[c,l]=(0,N.useState)(``),[u,d]=(0,N.useState)(!0);return(0,N.useEffect)(()=>
1{if(!e){i.current?.getTracks().forEach(e=>e.stop()),i.current=null,s(null);return}let t=!1,a=window,o=a.BarcodeDetector!==void 0;return d(o),(async()=>{try{let e=await navigator.mediaDevices.getUserMedia({video:{facingMode:`environment`}});if(t){e.getTracks().forEach(e=>e.stop());return}if(i.current=e,r.current&&(r.current.srcObject=e,await r.current.play()),!o)return;let s=new a.BarcodeDetector({formats:[`qr_code`,`code_128`,`code_39`,`ean_13`,`ean_8`,`data_matrix`,`itf`]}),c=async()=>{if(!(t||!r.current)){try{let e=await s.detect(r.current);if(e.length>0){n(e[0].rawValue);return}}catch{}requestAnimationFrame(c)}};requestAnimationFrame(c)}catch(e){s(e instanceof Error?e.message:`Kameraya eriÅilemedi`)}})(),()=>{t=!0}},[e,n]),(0,P.jsx)(C,{open:e,onOpenChange:t,children:(0,P.jsxs)(k,{className:`max-w-md`,children:[(0,P.jsxs)(w,{children:[(0,P.jsx)(b,{children:`Seri No Oku`}),(0,P.jsx)(D,{children:`Cihazın üzerindeki barkod veya QR'ı kameraya gösterin.`})]}),o?(0,P.jsx)(`div`,{className:`rounded-lg bg-danger/10 text-danger p-3 text-sm`,children:o}):(0,P.jsxs)(`div`,{className:`relative rounded-lg overflow-hidden bg-black aspect-video`,children:[(0,P.jsx)(`video`,{ref:r,className:`w-full h-full object-cover`,playsInline:!0,muted:!0}),(0,P.jsx)(`div`,{className:`absolute inset-8 border-2 border-brand rounded-lg pointer-events-none`})]}),!u&&(0,P.jsx)(`p`,{className:`text-xs text-muted-ink`,children:`Tarayıcın otomatik okumayı desteklemiyor. Numarayı elle girebilirsin.`}),(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(E,{children:`Elle Gir`}),(0,P.jsxs)(`div`,{className:`flex gap-2`,children:[(0,P.jsx)(S,{value:c,onChange:e=>l(e.target.value),placeholder:`Seri numarası`}),(0,P.jsx)(a,{onClick:()=>c&&n(c),children:`Kullan`})]})]})]})})}export{H as component};
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.