(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var s in o)e.o(o,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:o[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,o=window.wp.domReady;var s=e.n(o);const a=window.dokan.dokanUI,i=window.wp.apiFetch;var r=e.n(i);const n=window.wp.data,l=window.wp.element,c=window.ReactJSXRuntime,d=()=>(0,c.jsxs)("div",{className:"dokan-social-profile space-y-6 animate-pulse",children:[Array.from({length:8}).map((e,t)=>(0,c.jsxs)("div",{className:"grid grid-cols-4 gap-3",children:[(0,c.jsx)("div",{className:"flex justify-end text-right",children:(0,c.jsx)("div",{className:"h-5 w-20 bg-gray-300 rounded"})}),(0,c.jsx)("div",{className:"col-span-3",children:(0,c.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,c.jsx)("div",{className:"h-10 w-10 bg-gray-300 rounded"})," ",(0,c.jsx)("div",{className:"flex-1 h-10 bg-gray-300 rounded"})]})})]},t)),(0,c.jsx)("div",{className:"h-6 bg-gray-200 rounded w-1/2 mx-auto my-4"}),(0,c.jsx)("div",{className:"flex justify-end mt-4",children:(0,c.jsx)("div",{className:"h-10 w-24 bg-gray-300 rounded"})})]}),p=window.dokan.components,w=window.wp.components,u=window.wp.hooks,f=window.dokanSocialProfile?.fields||{},m=({icon:e})=>{const t=e||"fa-share-square-o";return(0,c.jsx)("i",{className:`fab fa-${t}`})},h=()=>{const e=(0,a.useToast)(),o=(0,n.useSelect)(e=>e("dokan/core").getCurrentUser(),[]),[s,i]=(0,l.useState)(null),[h,k]=(0,l.useState)(!0),[y,_]=(0,l.useState)(!1),x=(0,l.useCallback)(async(e="GET",t={})=>{const s="POST"===e;k(!s),_(s);try{const s=await r()({path:`/dokan/v1/stores/${o.id}`,method:e,data:"POST"===e?t:void 0});i(s.social)}catch(e){throw e}finally{k(!1),_(!1)}},[o.id]),g=e=>{if(!s)return!1;const t=e=>{const t=(0,u.applyFilters)("dokan_vendor_social_profile_validation_patterns",{fb:/^(https?:\/\/)?(www\.)?(facebook\.com|fb\.com)\/[a-zA-Z0-9(.?)]+\/?$/,twitter:/^(https?:\/\/)?(www\.)?(twitter\.com|x\.com)\/[A-Za-z0-9_]{1,15}$/,instagram:/^(https?:\/\/)?(www\.)?instagram\.com\/[A-Za-z0-9_.]+$/,linkedin:/^(https?:\/\/)?(www\.)?linkedin\.com\/in\/[A-Za-z0-9-]+\/?$/,youtube:/^(https?:\/\/)?(www\.)?youtube\.com\/@[A-Za-z0-9_-]+$/,pinterest:/^(https?:\/\/)?(www\.)?pinterest\.com\/[A-Za-z0-9_/]+$/,flickr:/^(https?:\/\/)?(www\.)?flickr\.com\/people\/[A-Za-z0-9@]+\/?$/,threads:/^(https?:\/\/)?(www\.)?threads\.net\/@[\w.]+\/?$/,tiktok:/^(https?:\/\/)?(www\.)?(tiktok\.com|vm\.tiktok\.com)\/(@[\w.]+|\w+)\/?$/}),o=s[e],a=t[e];return!a||a.test(o)};if(e)return t(e);for(const e of Object.keys(s))if(s[e]&&!t(e))return!1;return!0},j=e=>{if(!s?.[e])return"";if(!g(e)){const o=(0,u.applyFilters)("dokan_vendor_social_profile_example_urls",{fb:"https://www.facebook.com/yourprofile",twitter:"https://twitter.com/yourprofile",instagram:"https://www.instagram.com/yourprofile",linkedin:"https://www.linkedin.com/in/yourprofile",youtube:"https://www.youtube.com/@yourprofile",pinterest:"https://www.pinterest.com/yourprofile",flickr:"https://www.flickr.com/people/yourprofile",threads:"https://threads.net/@yourprofile",tiktok:"https://www.tiktok.com/@yourprofile"});return(0,t.sprintf)(
// translators: 1 is the social media name, 2 is an example URL
// translators: 1 is the social media name, 2 is an example URL
(0,t.__)("Invalid %1$s URL. Example: %2$s","dokan"),e.charAt(0).toUpperCase()+e.slice(1),o[e]||"")}return""},b=e=>{const t=e.target.name;i({...s,[t]:e.target.value})};return(0,l.useEffect)(()=>{x()},[x]),h?(0,c.jsx)(d,{}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(w.Slot,{name:"dokan_profile_settings_before_form",fillProps:{currentUser:o,socialProfile:s}}),(0,c.jsx)("div",{className:"mb-6",children:(0,t.__)("Social profiles help you to gain more trust. Consider adding your social profile links for better user interaction.","dokan")}),(0,c.jsxs)("div",{className:"dokan-social-profile space-y-4",children:[Object.keys(f).map(e=>(0,c.jsxs)("div",{className:"grid grid-cols-4 gap-3",children:[(0,c.jsx)("label",{htmlFor:`social-${e}`,className:"flex justify-end text-right font-bold text-gray-900",children:f[e]?.title}),(0,c.jsx)("div",{className:"col-span-3",children:(0,c.jsx)(a.SimpleInput,{className:"focus:!outline-none",addOnLeft:(0,c.jsx)(m,{icon:f[e]?.icon}),onChange:b,input:{id:`social-${e}`,type:"url",name:e,value:s[e],placeholder:(0,t.__)("Enter your URL","dokan")},disabled:y,errors:j(e)})})]},e)),(0,c.jsx)(w.Slot,{name:"dokan_profile_settings_form_bottom",fillProps:{currentUser:o,socialProfile:s}}),(0,c.jsx)("div",{className:"flex justify-end mt-4",children:(0,c.jsx)(p.DokanButton,{label:(0,t.__)("Submit","dokan"),onClick:async()=>{if(g())try{await x("POST",{social:s}),e({type:"success",title:(0,t.__)("Social profile updated successfully","dokan")})}catch(o){e({type:"error",title:(0,t.__)("Error updating social profile","dokan")})}else e({type:"error",title:(0,t.__)("Please enter valid social profile URLs","dokan")})},loading:y,disabled:y})}),(0,c.jsx)(a.DokanToaster,{})]}),(0,c.jsx)(w.Slot,{name:"dokan_profile_settings_after_form",fillProps:{currentUser:o,socialProfile:s}})]})};s()(()=>{window.wp.hooks.addFilter("dokan-dashboard-routes","dokan-pro-settings-social",e=>(e.push({id:"settings-social",title:(0,c.jsx)(p.VisitStore,{children:(0,t.__)("Social Profiles","dokan")}),element:(0,c.jsx)(h,{}),path:"/settings/social",exact:!0,order:10,parent:"settings",capabilities:["dokan_view_store_social_menu"]}),e))})})();