import{_ as $,s as B,t as f,H as E,m as P}from"./UserLayout-CW4WQNv3.js";import{q as g,s as F,x as H,r as L,c as l,o as a,b as e,f as y,a as v,d as k,t as o,j as u,y as r,F as x,l as M,z as w,N as V}from"./app-Cvs0Kf0N.js";import{_ as z,a as N}from"./NoDataFound-gHLvve9L.js";import{_ as C}from"./SpinnerBtn-BRhsJjyu.js";const I={class:"flex justify-between"},Y={class:"flex items-center gap-4"},q=["href"],O={key:0,class:"table-responsive mt-6 w-full"},R={class:"table"},G={class:"whitespace-nowrap"},J={class:"!text-right"},K={key:0,class:"tbody"},Q={key:0},U={key:1},W={class:"capitalize"},X={class:"!text-right"},Z=["onClick"],ee={key:2,class:"flex items-center justify-center"},te={key:3,class:"mt-4 flex justify-end gap-4"},le=Object.assign({layout:$},{__name:"Show",props:["record","scraped_data"],setup(m){B();const p=m,c=g([]),_=g(null),s=g(!1),d=g(!1),j=async()=>{var n;s.value=!0;try{const t=await w.post(route("user.web-scraping.api.scrape.index",p.record.uuid));c.value=[...c.value,...t.data.data],_.value=t.data.next_page_token}catch(t){f.danger(((n=t.response)==null?void 0:n.data)??"Error fetching places")}s.value=!1},S=()=>{s.value=!0,V.patch(route("user.web-scraping.scrape.store_data",p.record.uuid),{},{onSuccess:()=>{s.value=!1,f.success("Places added successfully")},onFinish:()=>{s.value=!1}})};F(()=>{var n,t;((t=(n=p.scraped_data)==null?void 0:n.data)==null?void 0:t.length)>0?(c.value=p.scraped_data.data.map(h=>({id:h.id,...h.data})),d.value=!0):j()});const D=async()=>{var n;if(!_.value)return f.danger("No more places to load");s.value=!0;try{const t=await w.post(route("user.web-scraping.api.scrape.index",p.record.uuid),{next_page_token:_.value});c.value=[...c.value,...t.data.data],_.value=t.data.next_page_token}catch(t){f.danger(((n=t.response)==null?void 0:n.data)??"Error fetching places")}s.value=!1},b=H(()=>c.value),A=n=>{P.init(route("user.web-scraping.scrape.destroy_data",n),{method:"delete",options:{message:r("You would not be revert it back!"),confirm_text:r("Are you sure?"),accept_btn_text:r("Yes, Sure!"),reject_btn_text:r("No, Cancel")},callback:()=>{c.value=c.value.filter(t=>t.id!==n)}})};return(n,t)=>{const h=L("Icon");return a(),l(x,null,[e("div",I,[e("div",Y,[d.value?(a(),l("a",{key:0,class:"btn btn-primary",href:n.route("user.web-scraping.scrape.export_data",m.record.id),target:"_blank"},[k(h,{icon:"bx:export"}),e("span",null,o(u(r)("Export Data")),1)],8,q)):v("",!0),m.record.status!=="completed"&&d.value?(a(),y(C,{key:1,type:"button",icon:"bx:refresh",onClick:S,processing:s.value,btnText:"Sync Number"},null,8,["processing"])):v("",!0)])]),d.value&&!s.value||b.value.length?(a(),l("div",O,[e("table",R,[e("thead",null,[e("tr",null,[e("th",null,o(u(r)("Name")),1),e("th",G,o(u(r)("Phone Number")),1),e("th",null,o(u(r)("Address")),1),e("th",null,o(u(r)("Rating")),1),e("th",null,o(u(r)("Types")),1),e("th",J,o(u(r)("Action")),1)])]),b.value.length?(a(),l("tbody",K,[(a(!0),l(x,null,M(b.value,(i,T)=>(a(),l("tr",{key:T},[e("td",null,o(i.name),1),e("td",null,[d.value?(a(),l("span",U,o(i.phone_number||"N/A"),1)):(a(),l("span",Q,o(u(r)("Hidden")),1))]),e("td",null,o(i.formatted_address),1),e("td",null,o(i.rating||"N/A"),1),e("td",W,o(i.types.join(", ")),1),e("td",X,[e("button",{class:"btn btn-danger btn-sm",onClick:ae=>A(i.id)},[k(h,{icon:"bx:trash"})],8,Z)])]))),128))])):(a(),y(N,{key:1,forTable:!0}))])])):!s.value&&!d.value&&!b.value.length?(a(),y(N,{key:1})):v("",!0),s.value?(a(),l("div",ee,[(a(),y(E,{key:0,class:"my-3 scale-150"}))])):v("",!0),k(z,{links:m.scraped_data.links},null,8,["links"]),d.value?v("",!0):(a(),l("div",te,[k(C,{icon:"bx:refresh",type:"button",onClick:D,processing:s.value,disabled:!_.value||s.value,btnText:"Load More"},null,8,["processing","disabled"])]))],64)}}});export{le as default};
