;((window,document)=>{ // OfficeFindThreeWidget let widgetStateV3={},geoLevelMapping={divisional_level:["division"],district_level:["division","district"],city_corporation_level:["division","district","city_corporation"],upazila_level:["division","district","upazila"],upazila_regional_office:["division","district","upazila"],pourashava_level:["division","district","upazila"],union_level:["division","district","upazila","union"],regional_office:["division"]},geoApiEndpoints={division:"/ajax/division/list",district:"/ajax/district/{loc_id}/list",upazila:"/ajax/upazilla/{loc_id}/list",union:"/ajax/union/{loc_id}/list",city_corporation:"/ajax/city-corporation/{loc_id}/list"},geoFieldMapping={division:"loc_division_id",district:"loc_district_id",upazila:"loc_upazila_id",union:"loc_union_id",city_corporation:"loc_district_id"};function getLangV3(e){return widgetStateV3[e]?.lang||"bn"}function getTitleFieldV3(e){return"en"===e?"title_en":"title_bn"}let placeholdersV3={office_level:{en:"Select Office Level",bn:"অফিস স্তর নির্বাচন করুন"},division:{en:"Select Division",bn:"বিভাগ নির্বাচন করুন"},district:{en:"Select District",bn:"জেলা নির্বাচন করুন"},upazila:{en:"Select Upazila",bn:"উপজেলা নির্বাচন করুন"},union:{en:"Select Union",bn:"ইউনিয়ন নির্বাচন করুন"},city_corporation:{en:"Select City Corporation",bn:"সিটি কর্পোরেশন নির্বাচন করুন"},office:{en:"Select Office",bn:"অফিস নির্বাচন করুন"}};function getPlaceholderV3(e,i){return placeholdersV3[e]?.[i]||placeholdersV3[e]?.bn||""}function createDropdownV3(e,i,t){var o=document.createElement("select"),e=(o.id=e,document.createElement("option"));return e.value="",e.textContent=i,o.appendChild(e),t&&o.addEventListener("change",function(e){updateSelectTitleV3(this),t.call(this,e)}),o}function updateSelectTitleV3(e){e&&0<=e.selectedIndex&&(e.title=e.options[e.selectedIndex].text||"")}function populateDropdownV3(o,e,n,a="_id"){for(;1{var i=document.createElement("option"),t=(i.value=e[a],e[n]||e.title_en||e.title_bn||"");i.textContent=t,i.title=t,i.dataset.item=JSON.stringify(e),o.appendChild(i)})}function setDropdownValueV3(e,i){e&&i&&(e.value=i,updateSelectTitleV3(e))}function showSpinnerV3(e){hideSpinnerV3(e);var i=document.createElement("span");return i.className="loading-spinner",i.innerHTML='',e.appendChild(i),i}function hideSpinnerV3(e){e=e.querySelector(".loading-spinner");e&&e.remove()}function clearDropdownsAfterV3(e,i){let t=!1;Array.from(e.children).forEach(e=>{t&&e.remove(),e===i&&(t=!0)})}async function handleOfficeLevelChangeV3(e,i,t,o){var n=i.options[i.selectedIndex],a=i.value;getLangV3(e);clearDropdownsAfterV3(t,i),o.setAttribute("disabled",!0),a&&(n=(i=JSON.parse(n.dataset.item||"{}")).is_geo_level||0,i=i.code||"",widgetStateV3[e].officeLevelId=a,widgetStateV3[e].levelCode=i,widgetStateV3[e].isGeoLevel=n,widgetStateV3[e].geoLocations={},1===n&&0<(a=geoLevelMapping[i]||[]).length?await loadGeoDropdownV3(e,t,o,a,0,null):await loadOfficesDropdownV3(e,t,o))}async function loadGeoDropdownV3(t,o,n,a,l,e){var i=getLangV3(t);let d=a[l],c=geoApiEndpoints[d];e&&(c=c.replace("{loc_id}",e)),showSpinnerV3(o);try{var r=await fetch(c);if(hideSpinnerV3(o),!r.ok)throw new Error(`Failed to fetch ${d} list`);var s,f,p=await r.json();p&&0e._id.toString()===l.officeLevelId)),e){if(widgetStateV3[a].officeLevelId=e._id,widgetStateV3[a].levelCode=e?.code||"",widgetStateV3[a].isGeoLevel=e?.is_geo_level||0,1===e?.is_geo_level){let n=geoLevelMapping[e?.code]||[];for(let o=0;o{function e(){document.querySelectorAll(".office-findthree-widget[data-preselect]").forEach(function(e){try{var i,t,o,n=e.dataset.widgetId,a=JSON.parse(e.dataset.preselect||"{}");n&&a.officeTypeId&&(i=document.getElementById("officeType_"+n),t=e.querySelector(".dynamic-dropdowns"),o=e.querySelector('button[id^="i"]'),i)&&t&&o&&window.initOfficeFindThreePreselect(n,t.id,o.id,a)}catch(e){console.error("Error auto-initializing OfficeFindThreeWidget:",e)}})}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):setTimeout(e,100)})(); })(_window,_document);