import{CONFIG_FILE_NAME as s}from"../../../constants/index.js";import{slash as l}from"../../../shared/utils.js";import{reporter as r}from"../../utils/reporter/reporter.js";import{copyStaticFile as m,FileNotFoundError as c}from"../../utils/fs.js";import{resolveSrcSet as v}from"../../utils/resolve-src-set.js";import{resolveAssetPath as f}from"../../utils/resolve-asset-path.js";const p=["png","svg","ico"];async function u(e={},o,a,n){const t={...e};if(e.image)try{t.image=await f(e.image,n,{fromFileRelativePath:o,contentDir:n.cwd,outdir:a})}catch(i){i instanceof c?r.panicOnBuildContentError('Cannot resolve "logo.image": %rp',e.image):r.panicOnBuild(`Cannot resolve "logo.image": %rp: ${i.message}`,e.image)}if(e.srcSet)try{t.srcSet=await v(e.srcSet,n,{fromFileRelativePath:s,contentDir:n.cwd,outdir:a})}catch(i){i instanceof c?r.panicOnBuildContentError(`Cannot resolve "logo.srcSet" "${e.srcSet}"`):r.panicOnBuild(`Cannot resolve "logo.srcSet" "${e.srcSet}": ${i.message}`)}if(e.favicon)try{t.favicon=await f(e.favicon,n,{fromFileRelativePath:s,contentDir:n.cwd,outdir:a})}catch(i){i instanceof c?r.panicOnBuildContentError('Cannot resolve "logo.favicon": %rp',e.favicon):r.panicOnBuild(`Cannot resolve "logo.favicon": %rp: ${i.message}`,e.favicon)}return t.favicon||(t.favicon=await C(a,n)),t}async function C(e,o){for(let a of p){const n=`favicon.${a}`,t=l(n);if(await o.exists(t))return m(o.cwd,n,e)}}export{u as resolveLogoConfig};
