function c(r){var y;const{elementId:e,fetchShowUrl:w,fetchSearchUrl:f,oldValue:S=null,existingValue:m=null,isReadOnly:I=!1,placeholder:g="Search...",searchPlaceholder:C="Type to search...",errorClass:h="border-red-500",alignmentClass:b="choices--align-left",shouldShowPopover:v=!1,popoverId:_=null,labelKey:s="label",customLabelKey:p=null}=r,t=document.getElementById(e);if(!t)return;const U=t.classList.contains(h),a=new Choices(t,{allowHTML:!0,placeholderValue:g,searchPlaceholderValue:C,searchResultLimit:20,shouldSort:!1,classNames:{containerOuter:`choices ${b}`,containerInner:`choices__inner flex items-center ${U?h:""}`}}),u=S||m;if(u&&fetch(w(u)).then(o=>o.json()).then(o=>{a.clearChoices(),a.setChoices([{value:o.value,label:o[s],customProperties:{dropdown_label:o.dropdown_label||o[s]},selected:!0}],"value","label",!1)}).catch(o=>console.error("Error fetching single item:",o)),t.addEventListener("search",o=>{const i=o.detail.value||"";fetch(f(i)).then(l=>l.json()).then(l=>{const d=l.map(n=>({value:n.value,label:p?n[p]:n[s],customProperties:{dropdown_label:n.dropdown_label||n[s]}}));a.clearChoices(),a.setChoices(d,"value","label",!0)}).catch(l=>console.error("Error searching items:",l))}),v&&_){const o=(y=t.closest(".choices"))==null?void 0:y.querySelector(".choices__list--single"),i=document.getElementById(_);o&&i&&(o.addEventListener("mouseenter",()=>{var d;const l=a.getValue();l&&((d=l.customProperties)!=null&&d.dropdown_label)&&(i.textContent=l.customProperties.dropdown_label,i.style.display="block")}),o.addEventListener("mouseleave",()=>{i.style.display="none"}))}I&&a.disable()}function P(){const r=window.__IS_READONLY__===!0;c({elementId:"place_of_birth_city_id",fetchShowUrl:e=>`/api/cities/${e}`,fetchSearchUrl:e=>`/api/cities?search=${encodeURIComponent(e)}`,oldValue:window.__OLD_place_of_birth_city_id,existingValue:window.__EXISTING_place_of_birth_city_id,isReadOnly:r,placeholder:"Type to search for a city...",searchPlaceholder:"Pretraži gradove...",errorClass:"border-red-500",alignmentClass:"choices--align-left",shouldShowPopover:!1,popoverId:null}),c({elementId:"place_of_birth_country_id",fetchShowUrl:e=>`/api/passport-city-show/${e}`,fetchSearchUrl:e=>`/api/passport-city-search?search=${encodeURIComponent(e)}`,oldValue:window.__OLD_place_of_birth_country_id,existingValue:window.__EXISTING_place_of_birth_country_id,isReadOnly:r,placeholder:"Type to search...",searchPlaceholder:"Type to search...",errorClass:"border-red-500",alignmentClass:"choices--align-left",shouldShowPopover:!0,popoverId:"fullCityPopover"}),c({elementId:"country_code_country_id",fetchShowUrl:e=>`/api/countrycode-show/${e}`,fetchSearchUrl:e=>`/api/countrycode-search?search=${encodeURIComponent(e)}`,oldValue:window.__OLD_country_code_country_id,existingValue:window.__EXISTING_country_code_country_id,isReadOnly:r,placeholder:"Search country...",searchPlaceholder:"Search country...",errorClass:"border-red-500",shouldShowPopover:!0,popoverId:"fullCountryCodePopover"}),c({elementId:"nationality_country_id",fetchShowUrl:e=>`/api/nationality-show/${e}`,fetchSearchUrl:e=>`/api/nationality-search?search=${encodeURIComponent(e)}`,oldValue:window.__OLD_nationality_country_id,existingValue:window.__EXISTING_nationality_country_id,isReadOnly:r,placeholder:"Search nationality...",searchPlaceholder:"Search nationality...",errorClass:"border-red-500",alignmentClass:"choices--align-right",shouldShowPopover:!0,popoverId:"fullNationalityPopover"}),c({elementId:"residence_city_id_create",fetchShowUrl:e=>`/api/cities/${e}`,fetchSearchUrl:e=>`/api/cities?search=${encodeURIComponent(e)}`,oldValue:window.__OLD_residence_city_id,existingValue:window.__EXISTING_residence_city_id,isReadOnly:r,placeholder:"Search for a city...",searchPlaceholder:"Search...",errorClass:"border-red-500"}),c({elementId:"residence_city_id_update",fetchShowUrl:e=>`/api/cities/${e}`,fetchSearchUrl:e=>`/api/cities?search=${encodeURIComponent(e)}`,oldValue:window.__OLD_residence_city_id,existingValue:window.__EXISTING_residence_city_id,isReadOnly:r,placeholder:"Search for a city...",searchPlaceholder:"Search...",errorClass:"border-red-500"}),c({elementId:"mailing_city_id_create",fetchShowUrl:e=>`/api/cities/${e}`,fetchSearchUrl:e=>`/api/cities?search=${encodeURIComponent(e)}`,oldValue:window.__OLD_mailing_city_id,existingValue:window.__EXISTING_mailing_city_id,isReadOnly:r,placeholder:"Search for a city...",searchPlaceholder:"Search...",errorClass:"border-red-500"}),c({elementId:"mailing_city_id_update",fetchShowUrl:e=>`/api/cities/${e}`,fetchSearchUrl:e=>`/api/cities?search=${encodeURIComponent(e)}`,oldValue:window.__OLD_mailing_city_id,existingValue:window.__EXISTING_mailing_city_id,isReadOnly:r,placeholder:"Search for a city...",searchPlaceholder:"Search...",errorClass:"border-red-500"})}document.addEventListener("DOMContentLoaded",P);
