function d(t){if(t===0)return 0;const n=Math.ceil(t/2)*20;return t%2===1?n:-n}function g(t,e,n){let o=t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"");o||(o="entity");let r=o,l=1;for(;e.some(a=>a===r&&a!==n);)r=`${o}_${l}`,l++;return r}function m(t){return t&&t.split(/\s+/).map(e=>e&&e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ")}function _(t,e){if(!e||e.length===0||!t)return t;const n=t.toLowerCase();for(const o of e){if(o===""){console.warn("Invalid empty prefix found in entity_prefixes config. Skipping this prefix.");continue}if(n.startsWith(o.toLowerCase())){const r=t.substring(o.length);return r===""?(console.log(`Entity label "${t}" equals prefix "${o}", resulting in empty string. Displaying original label.`),t):r}}return e.length>0&&e.some(o=>o&&o!=="")&&console.log(`Stripping prefixes [${e.join(", ")}] from label "${t}"`),t}function p(t){return t?t.label_prefixes&&t.label_prefixes.length>0?t.label_prefixes:t.entity_prefix??[]:[]}function y(t,e=[],n=[]){const o=t.toLowerCase();for(const r of e||[])if(r&&o.startsWith(r.toLowerCase()))return"dimension";for(const r of n||[])if(r&&o.startsWith(r.toLowerCase()))return"fact";return null}function $(t,e=[]){return _(t,e).split("_").map(o=>o.charAt(0).toUpperCase()+o.slice(1).toLowerCase()).join(" ")}function v(t){const e=t.split(".");if(e.length>=3&&e[0]==="model"){const n=e[e.length-1];return/^v\d+$/.test(n)&&e.length>=4?e[e.length-2]:n}return t.includes(".")?t.split(".").pop():t}function b(t){if(!t.file_path)return null;let e=t.file_path.replace(/\\/g,"/");const n=e.lastIndexOf("/");let r=(n!==-1?e.substring(0,n):"").split("/").filter(l=>l!=="."&&l!=="");return r[0]==="models"&&r.shift(),r.length>1?(r.shift(),r.join("/")):null}function x(t){if(!t)return[];const e=n=>n.map(o=>String(o).trim()).filter(o=>o.length>0);if(Array.isArray(t))return Array.from(new Set(e(t)));if(typeof t=="string"){const n=t.split(",").map(o=>o.trim()).filter(Boolean);return Array.from(new Set(n))}return[]}function C(t){const e=new Map;return t.forEach(n=>{const o=n.source<n.target?`${n.source}-${n.target}`:`${n.target}-${n.source}`;e.has(o)||e.set(o,[]),e.get(o).push(n)}),Array.from(e.entries()).map(([n,o])=>{const r=o[0],l=r.source,a=r.target,s=o.map(i=>({source_model_name:i.source_model_name,source_model_version:i.source_model_version??null,target_model_name:i.target_model_name,target_model_version:i.target_model_version??null,source_field:i.source_field,target_field:i.target_field}));return{id:`e${l}-${a}`,source:l,target:a,type:"custom",data:{label:r.label||"",type:r.type||"one_to_many",source_field:r.source_field,target_field:r.target_field,label_dx:r.label_dx||0,label_dy:r.label_dy||0,parallelOffset:0,models:s,modelCount:s.length}}})}function h(t,e){const n=e.source<e.target?`${e.source}-${e.target}`:`${e.target}-${e.source}`,o=t.find(r=>(r.source<r.target?`${r.source}-${r.target}`:`${r.target}-${r.source}`)===n);if(o){const r=o.data?.models||[],l={source_model_name:e.source_model_name,source_model_version:e.source_model_version??null,target_model_name:e.target_model_name,target_model_version:e.target_model_version??null,source_field:e.source_field,target_field:e.target_field};return r.some(s=>s.source_model_name===l.source_model_name&&s.source_model_version===l.source_model_version&&s.target_model_name===l.target_model_name&&s.target_model_version===l.target_model_version&&s.source_field===l.source_field&&s.target_field===l.target_field)?t:t.map(s=>s.id!==o.id?s:{...s,data:{...s.data||{},models:[...r,l],modelCount:r.length+1,source_field:s.data?.source_field||e.source_field,target_field:s.data?.target_field||e.target_field}})}else{const r=e.source,l=e.target,s={id:`e${r}-${l}`,source:r,target:l,type:"custom",data:{label:e.label||"",type:e.type||"one_to_many",source_field:e.source_field,target_field:e.target_field,label_dx:e.label_dx||0,label_dy:e.label_dy||0,parallelOffset:0,models:[{source_model_name:e.source_model_name,source_model_version:e.source_model_version??null,target_model_name:e.target_model_name,target_model_version:e.target_model_version??null,source_field:e.source_field,target_field:e.target_field}],modelCount:1}};return[...t,s]}}function S(t,e,n,o){const r=o.get(t);if(r){const a=r.columns.find(s=>s.name===e);if(a?.data_tests){for(const s of a.data_tests)if(s.relationships)return"fk"}}const l=o.get(n);if(l){for(const a of l.columns)if(a.data_tests){for(const s of a.data_tests)if(s.relationships){const c=s.relationships,i=c.arguments?.to||c.to,u=c.arguments?.field||c.field;if(i&&u===e){const f=i.match(/ref\(['"]?([^'"]+)['"]?\)/);if(f&&f[1]===t)return"pk"}}}}return"unknown"}export{d as a,b,y as c,S as d,v as e,$ as f,g,p as h,C as i,h as m,x as n,m as t};
