nnews-react 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -168,7 +168,7 @@ ${ho(this.code(t,n))}
|
|
|
168
168
|
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(i=>r.set(i)),r}static accessor(t){const r=(this[sf]=this[sf]={accessors:{}}).accessors,i=this.prototype;function s(o){const a=ui(o);r[a]||(gL(i,o),r[a]=!0)}return R.isArray(t)?t.forEach(s):s(t),this}};gt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);R.reduceDescriptors(gt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}});R.freezeMethods(gt);function Fa(e,t){const n=this||Gi,r=t||n,i=gt.from(r.headers);let s=r.data;return R.forEach(e,function(a){s=a.call(n,s,i.normalize(),t?t.status:void 0)}),i.normalize(),s}function Yg(e){return!!(e&&e.__CANCEL__)}function Hr(e,t,n){de.call(this,e??"canceled",de.ERR_CANCELED,t,n),this.name="CanceledError"}R.inherits(Hr,de,{__CANCEL__:!0});function Zg(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new de("Request failed with status code "+n.status,[de.ERR_BAD_REQUEST,de.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function mL(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function bL(e,t){e=e||10;const n=new Array(e),r=new Array(e);let i=0,s=0,o;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),u=r[s];o||(o=c),n[i]=l,r[i]=c;let d=s,h=0;for(;d!==i;)h+=n[d++],d=d%e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),c-o<t)return;const f=u&&c-u;return f?Math.round(h*1e3/f):void 0}}function yL(e,t){let n=0,r=1e3/t,i,s;const o=(c,u=Date.now())=>{n=u,i=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const u=Date.now(),d=u-n;d>=r?o(c,u):(i=c,s||(s=setTimeout(()=>{s=null,o(i)},r-d)))},()=>i&&o(i)]}const Hs=(e,t,n=3)=>{let r=0;const i=bL(50,250);return yL(s=>{const o=s.loaded,a=s.lengthComputable?s.total:void 0,l=o-r,c=i(l),u=o<=a;r=o;const d={loaded:o,total:a,progress:a?o/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&u?(a-o)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(d)},n)},of=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},af=e=>(...t)=>R.asap(()=>e(...t)),xL=Je.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Je.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Je.origin),Je.navigator&&/(msie|trident)/i.test(Je.navigator.userAgent)):()=>!0,EL=Je.hasStandardBrowserEnv?{write(e,t,n,r,i,s,o){if(typeof document>"u")return;const a=[`${e}=${encodeURIComponent(t)}`];R.isNumber(n)&&a.push(`expires=${new Date(n).toUTCString()}`),R.isString(r)&&a.push(`path=${r}`),R.isString(i)&&a.push(`domain=${i}`),s===!0&&a.push("secure"),R.isString(o)&&a.push(`SameSite=${o}`),document.cookie=a.join("; ")},read(e){if(typeof document>"u")return null;const t=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return t?decodeURIComponent(t[1]):null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function wL(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function _L(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Xg(e,t,n){let r=!wL(t);return e&&(r||n==!1)?_L(e,t):t}const lf=e=>e instanceof gt?{...e}:e;function Jn(e,t){t=t||{};const n={};function r(c,u,d,h){return R.isPlainObject(c)&&R.isPlainObject(u)?R.merge.call({caseless:h},c,u):R.isPlainObject(u)?R.merge({},u):R.isArray(u)?u.slice():u}function i(c,u,d,h){if(R.isUndefined(u)){if(!R.isUndefined(c))return r(void 0,c,d,h)}else return r(c,u,d,h)}function s(c,u){if(!R.isUndefined(u))return r(void 0,u)}function o(c,u){if(R.isUndefined(u)){if(!R.isUndefined(c))return r(void 0,c)}else return r(void 0,u)}function a(c,u,d){if(d in t)return r(c,u);if(d in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:a,headers:(c,u,d)=>i(lf(c),lf(u),d,!0)};return R.forEach(Object.keys({...e,...t}),function(u){const d=l[u]||i,h=d(e[u],t[u],u);R.isUndefined(h)&&d!==a||(n[u]=h)}),n}const Qg=e=>{const t=Jn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:i,xsrfCookieName:s,headers:o,auth:a}=t;if(t.headers=o=gt.from(o),t.url=Kg(Xg(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&o.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),R.isFormData(n)){if(Je.hasStandardBrowserEnv||Je.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if(R.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([u,d])=>{c.includes(u.toLowerCase())&&o.set(u,d)})}}if(Je.hasStandardBrowserEnv&&(r&&R.isFunction(r)&&(r=r(t)),r||r!==!1&&xL(t.url))){const l=i&&s&&EL.read(s);l&&o.set(i,l)}return t},vL=typeof XMLHttpRequest<"u",kL=vL&&function(e){return new Promise(function(n,r){const i=Qg(e);let s=i.data;const o=gt.from(i.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=i,u,d,h,f,p;function m(){f&&f(),p&&p(),i.cancelToken&&i.cancelToken.unsubscribe(u),i.signal&&i.signal.removeEventListener("abort",u)}let b=new XMLHttpRequest;b.open(i.method.toUpperCase(),i.url,!0),b.timeout=i.timeout;function y(){if(!b)return;const v=gt.from("getAllResponseHeaders"in b&&b.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?b.responseText:b.response,status:b.status,statusText:b.statusText,headers:v,config:e,request:b};Zg(function(B){n(B),m()},function(B){r(B),m()},C),b=null}"onloadend"in b?b.onloadend=y:b.onreadystatechange=function(){!b||b.readyState!==4||b.status===0&&!(b.responseURL&&b.responseURL.indexOf("file:")===0)||setTimeout(y)},b.onabort=function(){b&&(r(new de("Request aborted",de.ECONNABORTED,e,b)),b=null)},b.onerror=function(T){const C=T&&T.message?T.message:"Network Error",N=new de(C,de.ERR_NETWORK,e,b);N.event=T||null,r(N),b=null},b.ontimeout=function(){let T=i.timeout?"timeout of "+i.timeout+"ms exceeded":"timeout exceeded";const C=i.transitional||Wg;i.timeoutErrorMessage&&(T=i.timeoutErrorMessage),r(new de(T,C.clarifyTimeoutError?de.ETIMEDOUT:de.ECONNABORTED,e,b)),b=null},s===void 0&&o.setContentType(null),"setRequestHeader"in b&&R.forEach(o.toJSON(),function(T,C){b.setRequestHeader(C,T)}),R.isUndefined(i.withCredentials)||(b.withCredentials=!!i.withCredentials),a&&a!=="json"&&(b.responseType=i.responseType),c&&([h,p]=Hs(c,!0),b.addEventListener("progress",h)),l&&b.upload&&([d,f]=Hs(l),b.upload.addEventListener("progress",d),b.upload.addEventListener("loadend",f)),(i.cancelToken||i.signal)&&(u=v=>{b&&(r(!v||v.type?new Hr(null,e,b):v),b.abort(),b=null)},i.cancelToken&&i.cancelToken.subscribe(u),i.signal&&(i.signal.aborted?u():i.signal.addEventListener("abort",u)));const _=mL(i.url);if(_&&Je.protocols.indexOf(_)===-1){r(new de("Unsupported protocol "+_+":",de.ERR_BAD_REQUEST,e));return}b.send(s||null)})},NL=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,i;const s=function(c){if(!i){i=!0,a();const u=c instanceof Error?c:this.reason;r.abort(u instanceof de?u:new Hr(u instanceof Error?u.message:u))}};let o=t&&setTimeout(()=>{o=null,s(new de(`timeout ${t} of ms exceeded`,de.ETIMEDOUT))},t);const a=()=>{e&&(o&&clearTimeout(o),o=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>R.asap(a),l}},AL=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,i;for(;r<n;)i=r+t,yield e.slice(r,i),r=i},SL=async function*(e,t){for await(const n of TL(e))yield*AL(n,t)},TL=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},cf=(e,t,n,r)=>{const i=SL(e,t);let s=0,o,a=l=>{o||(o=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:u}=await i.next();if(c){a(),l.close();return}let d=u.byteLength;if(n){let h=s+=d;n(h)}l.enqueue(new Uint8Array(u))}catch(c){throw a(c),c}},cancel(l){return a(l),i.return()}},{highWaterMark:2})},uf=64*1024,{isFunction:ws}=R,CL=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:df,TextEncoder:ff}=R.global,hf=(e,...t)=>{try{return!!e(...t)}catch{return!1}},OL=e=>{e=R.merge.call({skipUndefined:!0},CL,e);const{fetch:t,Request:n,Response:r}=e,i=t?ws(t):typeof fetch=="function",s=ws(n),o=ws(r);if(!i)return!1;const a=i&&ws(df),l=i&&(typeof ff=="function"?(p=>m=>p.encode(m))(new ff):async p=>new Uint8Array(await new n(p).arrayBuffer())),c=s&&a&&hf(()=>{let p=!1;const m=new n(Je.origin,{body:new df,method:"POST",get duplex(){return p=!0,"half"}}).headers.has("Content-Type");return p&&!m}),u=o&&a&&hf(()=>R.isReadableStream(new r("").body)),d={stream:u&&(p=>p.body)};i&&["text","arrayBuffer","blob","formData","stream"].forEach(p=>{!d[p]&&(d[p]=(m,b)=>{let y=m&&m[p];if(y)return y.call(m);throw new de(`Response type '${p}' is not supported`,de.ERR_NOT_SUPPORT,b)})});const h=async p=>{if(p==null)return 0;if(R.isBlob(p))return p.size;if(R.isSpecCompliantForm(p))return(await new n(Je.origin,{method:"POST",body:p}).arrayBuffer()).byteLength;if(R.isArrayBufferView(p)||R.isArrayBuffer(p))return p.byteLength;if(R.isURLSearchParams(p)&&(p=p+""),R.isString(p))return(await l(p)).byteLength},f=async(p,m)=>{const b=R.toFiniteNumber(p.getContentLength());return b??h(m)};return async p=>{let{url:m,method:b,data:y,signal:_,cancelToken:v,timeout:T,onDownloadProgress:C,onUploadProgress:N,responseType:B,headers:q,withCredentials:G="same-origin",fetchOptions:O}=Qg(p),H=t||fetch;B=B?(B+"").toLowerCase():"text";let P=NL([_,v&&v.toAbortSignal()],T),ne=null;const X=P&&P.unsubscribe&&(()=>{P.unsubscribe()});let Y;try{if(N&&c&&b!=="get"&&b!=="head"&&(Y=await f(q,y))!==0){let Q=new n(m,{method:"POST",body:y,duplex:"half"}),le;if(R.isFormData(y)&&(le=Q.headers.get("content-type"))&&q.setContentType(le),Q.body){const[k,ge]=of(Y,Hs(af(N)));y=cf(Q.body,uf,k,ge)}}R.isString(G)||(G=G?"include":"omit");const L=s&&"credentials"in n.prototype,U={...O,signal:P,method:b.toUpperCase(),headers:q.normalize().toJSON(),body:y,duplex:"half",credentials:L?G:void 0};ne=s&&new n(m,U);let F=await(s?H(ne,O):H(m,U));const K=u&&(B==="stream"||B==="response");if(u&&(C||K&&X)){const Q={};["status","statusText","headers"].forEach(se=>{Q[se]=F[se]});const le=R.toFiniteNumber(F.headers.get("content-length")),[k,ge]=C&&of(le,Hs(af(C),!0))||[];F=new r(cf(F.body,uf,k,()=>{ge&&ge(),X&&X()}),Q)}B=B||"text";let w=await d[R.findKey(d,B)||"text"](F,p);return!K&&X&&X(),await new Promise((Q,le)=>{Zg(Q,le,{data:w,headers:gt.from(F.headers),status:F.status,statusText:F.statusText,config:p,request:ne})})}catch(L){throw X&&X(),L&&L.name==="TypeError"&&/Load failed|fetch/i.test(L.message)?Object.assign(new de("Network Error",de.ERR_NETWORK,p,ne),{cause:L.cause||L}):de.from(L,L&&L.code,p,ne)}}},IL=new Map,Jg=e=>{let t=e&&e.env||{};const{fetch:n,Request:r,Response:i}=t,s=[r,i,n];let o=s.length,a=o,l,c,u=IL;for(;a--;)l=s[a],c=u.get(l),c===void 0&&u.set(l,c=a?new Map:OL(t)),u=c;return c};Jg();const Cc={http:VR,xhr:kL,fetch:{get:Jg}};R.forEach(Cc,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const pf=e=>`- ${e}`,RL=e=>R.isFunction(e)||e===null||e===!1;function LL(e,t){e=R.isArray(e)?e:[e];const{length:n}=e;let r,i;const s={};for(let o=0;o<n;o++){r=e[o];let a;if(i=r,!RL(r)&&(i=Cc[(a=String(r)).toLowerCase()],i===void 0))throw new de(`Unknown adapter '${a}'`);if(i&&(R.isFunction(i)||(i=i.get(t))))break;s[a||"#"+o]=i}if(!i){const o=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?o.length>1?`since :
|
|
169
169
|
`+o.map(pf).join(`
|
|
170
170
|
`):" "+pf(o[0]):"as no adapter specified";throw new de("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return i}const em={getAdapter:LL,adapters:Cc};function qa(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Hr(null,e)}function gf(e){return qa(e),e.headers=gt.from(e.headers),e.data=Fa.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),em.getAdapter(e.adapter||Gi.adapter,e)(e).then(function(r){return qa(e),r.data=Fa.call(e,e.transformResponse,r),r.headers=gt.from(r.headers),r},function(r){return Yg(r)||(qa(e),r&&r.response&&(r.response.data=Fa.call(e,e.transformResponse,r.response),r.response.headers=gt.from(r.response.headers))),Promise.reject(r)})}const tm="1.13.2",wo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{wo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const mf={};wo.transitional=function(t,n,r){function i(s,o){return"[Axios v"+tm+"] Transitional option '"+s+"'"+o+(r?". "+r:"")}return(s,o,a)=>{if(t===!1)throw new de(i(o," has been removed"+(n?" in "+n:"")),de.ERR_DEPRECATED);return n&&!mf[o]&&(mf[o]=!0,console.warn(i(o," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,o,a):!0}};wo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function ML(e,t,n){if(typeof e!="object")throw new de("options must be an object",de.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let i=r.length;for(;i-- >0;){const s=r[i],o=t[s];if(o){const a=e[s],l=a===void 0||o(a,s,e);if(l!==!0)throw new de("option "+s+" must be "+l,de.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new de("Unknown option "+s,de.ERR_BAD_OPTION)}}const Os={assertOptions:ML,validators:wo},en=Os.validators;let Vn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new rf,response:new rf}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let i={};Error.captureStackTrace?Error.captureStackTrace(i):i=new Error;const s=i.stack?i.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
171
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Jn(this.defaults,n);const{transitional:r,paramsSerializer:i,headers:s}=n;r!==void 0&&Os.assertOptions(r,{silentJSONParsing:en.transitional(en.boolean),forcedJSONParsing:en.transitional(en.boolean),clarifyTimeoutError:en.transitional(en.boolean)},!1),i!=null&&(R.isFunction(i)?n.paramsSerializer={serialize:i}:Os.assertOptions(i,{encode:en.function,serialize:en.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Os.assertOptions(n,{baseUrl:en.spelling("baseURL"),withXsrfToken:en.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],p=>{delete s[p]}),n.headers=gt.concat(o,s);const a=[];let l=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(l=l&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let u,d=0,h;if(!l){const p=[gf.bind(this),void 0];for(p.unshift(...a),p.push(...c),h=p.length,u=Promise.resolve(n);d<h;)u=u.then(p[d++],p[d++]);return u}h=a.length;let f=n;for(;d<h;){const p=a[d++],m=a[d++];try{f=p(f)}catch(b){m.call(this,b);break}}try{u=gf.call(this,f)}catch(p){return Promise.reject(p)}for(d=0,h=c.length;d<h;)u=u.then(c[d++],c[d++]);return u}getUri(t){t=Jn(this.defaults,t);const n=Xg(t.baseURL,t.url,t.allowAbsoluteUrls);return Kg(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){Vn.prototype[t]=function(n,r){return this.request(Jn(r||{},{method:t,url:n,data:(r||{}).data}))}});R.forEach(["post","put","patch"],function(t){function n(r){return function(s,o,a){return this.request(Jn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Vn.prototype[t]=n(),Vn.prototype[t+"Form"]=n(!0)});let DL=class nm{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(i=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](i);r._listeners=null}),this.promise.then=i=>{let s;const o=new Promise(a=>{r.subscribe(a),s=a}).then(i);return o.cancel=function(){r.unsubscribe(s)},o},t(function(s,o,a){r.reason||(r.reason=new Hr(s,o,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new nm(function(i){t=i}),cancel:t}}};function PL(e){return function(n){return e.apply(null,n)}}function BL(e){return R.isObject(e)&&e.isAxiosError===!0}const Ol={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Ol).forEach(([e,t])=>{Ol[t]=e});function rm(e){const t=new Vn(e),n=Mg(Vn.prototype.request,t);return R.extend(n,Vn.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(i){return rm(Jn(e,i))},n}const Le=rm(Gi);Le.Axios=Vn;Le.CanceledError=Hr;Le.CancelToken=DL;Le.isCancel=Yg;Le.VERSION=tm;Le.toFormData=Eo;Le.AxiosError=de;Le.Cancel=Le.CanceledError;Le.all=function(t){return Promise.all(t)};Le.spread=PL;Le.isAxiosError=BL;Le.mergeConfig=Jn;Le.AxiosHeaders=gt;Le.formToJSON=e=>Vg(R.isHTMLForm(e)?new FormData(e):e);Le.getAdapter=em.getAdapter;Le.HttpStatusCode=Ol;Le.default=Le;const{Axios:N2,AxiosError:A2,CanceledError:S2,isCancel:T2,CancelToken:C2,VERSION:O2,all:I2,Cancel:R2,isAxiosError:L2,spread:M2,toFormData:D2,AxiosHeaders:P2,HttpStatusCode:B2,formToJSON:F2,getAdapter:q2,mergeConfig:U2}=Le,st={ARTICLES:"/api/article",ARTICLES_FILTER:"/api/article/filter",ARTICLE_BY_ID:e=>`/api/article/${e}`,IMAGE_UPLOAD:"/api/Image/uploadImage",INSERT_WITH_AI:"/api/article/insertWithAI",UPDATE_WITH_AI:"/api/article/updateWithAI"};class im{constructor(t){this.client=t}async uploadImage(t){const n=new FormData;n.append("file",t),console.log("[ArticleAPI] uploadImage - Request:",{fileName:t.name,fileSize:t.size});const r=await this.client.post(st.IMAGE_UPLOAD,n,{headers:{"Content-Type":"multipart/form-data"}});return console.log("[ArticleAPI] uploadImage - Response:",r.data),r.data}async listArticles(t,n=1,r=10){const i={page:n,pageSize:r};t&&(i.categoryId=t),console.log("[ArticleAPI] listArticles - Request:",{url:st.ARTICLES,params:i});const s=await this.client.get(st.ARTICLES,{params:i});return console.log("[ArticleAPI] listArticles - Response:",s.data),this.transformArticleDates(s.data)}async filterArticles(t,n,r=1,i=10){const s={page:r,pageSize:i};t&&t.length>0&&(s.roles=t.join(",")),n!==void 0&&(s.parentId=n);const o=await this.client.get(st.ARTICLES_FILTER,{params:s});return this.transformArticleDates(o.data)}async getArticleById(t){const n=await this.client.get(st.ARTICLE_BY_ID(t));return this.transformArticleDate(n.data)}async createArticle(t){console.log("[ArticleAPI] createArticle - Request:",{url:st.ARTICLES,data:t});const n=await this.client.post(st.ARTICLES,t);return console.log("[ArticleAPI] createArticle - Response:",n.data),this.transformArticleDate(n.data)}async updateArticle(t){console.log("[ArticleAPI] updateArticle - Request:",{url:st.ARTICLES,data:t});const n=await this.client.put(st.ARTICLES,t);return console.log("[ArticleAPI] updateArticle - Response:",n.data),this.transformArticleDate(n.data)}async deleteArticle(t){console.log("[ArticleAPI] deleteArticle - Request:",{id:t,url:st.ARTICLE_BY_ID(t)}),await this.client.delete(st.ARTICLE_BY_ID(t)),console.log("[ArticleAPI] deleteArticle - Success")}async createArticleWithAI(t){console.log("[ArticleAPI] createArticleWithAI - Request:",{url:st.INSERT_WITH_AI,data:t});const n=await this.client.post(st.INSERT_WITH_AI,t);return console.log("[ArticleAPI] createArticleWithAI - Response:",n.data),this.transformArticleDate(n.data)}async updateArticleWithAI(t){if(!t.articleId)throw new Error("articleId is required for updateWithAI");console.log("[ArticleAPI] updateArticleWithAI - Request:",{url:st.UPDATE_WITH_AI,data:t});const n=await this.client.put(st.UPDATE_WITH_AI,t);return console.log("[ArticleAPI] updateArticleWithAI - Response:",n.data),this.transformArticleDate(n.data)}transformArticleDate(t){return{...t,dateAt:t.dateAt?new Date(t.dateAt):void 0,createdAt:t.createdAt?new Date(t.createdAt):void 0,updatedAt:t.updatedAt?new Date(t.updatedAt):void 0,category:t.category?{...t.category,createdAt:t.category.createdAt?new Date(t.category.createdAt):void 0,updatedAt:t.category.updatedAt?new Date(t.category.updatedAt):void 0}:void 0}}transformArticleDates(t){return{...t,items:t.items.map(n=>this.transformArticleDate(n))}}}const tn={CATEGORIES:"/api/category",CATEGORIES_FILTER:"/api/category/filter",CATEGORY_BY_ID:e=>`/api/category/${e}`};class sm{constructor(t){this.client=t}async listCategories(){console.log("[CategoryAPI] listCategories - Request:",{url:tn.CATEGORIES});const t=await this.client.get(tn.CATEGORIES);return console.log("[CategoryAPI] listCategories - Response:",t.data),this.transformCategoryDates(t.data)}async filterCategories(t,n){const r={};t&&t.length>0&&(r.roles=t.join(",")),n!==void 0&&(r.parentId=n);const i=await this.client.get(tn.CATEGORIES_FILTER,{params:r});return this.transformCategoryDates(i.data)}async getCategoryById(t){const n=await this.client.get(tn.CATEGORY_BY_ID(t));return this.transformCategoryDate(n.data)}async createCategory(t){console.log("[CategoryAPI] createCategory - Request:",{url:tn.CATEGORIES,data:t});const n=await this.client.post(tn.CATEGORIES,t);return console.log("[CategoryAPI] createCategory - Response:",n.data),this.transformCategoryDate(n.data)}async updateCategory(t){console.log("[CategoryAPI] updateCategory - Request:",{url:tn.CATEGORIES,data:t});const n=await this.client.put(tn.CATEGORIES,t);return console.log("[CategoryAPI] updateCategory - Response:",n.data),this.transformCategoryDate(n.data)}async deleteCategory(t){console.log("[CategoryAPI] deleteCategory - Request:",{id:t,url:tn.CATEGORY_BY_ID(t)}),await this.client.delete(tn.CATEGORY_BY_ID(t)),console.log("[CategoryAPI] deleteCategory - Success")}transformCategoryDate(t){return{...t,createdAt:t.createdAt?new Date(t.createdAt):void 0,updatedAt:t.updatedAt?new Date(t.updatedAt):void 0}}transformCategoryDates(t){return t.map(n=>this.transformCategoryDate(n))}}const Ut={TAGS:"/api/tag",TAG_BY_ID:e=>`/api/tag/${e}`,TAG_MERGE:(e,t)=>`/api/Tag/merge/${e}/${t}`};class om{constructor(t){this.client=t}async listTags(){console.log("[TagAPI] listTags - Request:",{url:Ut.TAGS});const t=await this.client.get(Ut.TAGS);return console.log("[TagAPI] listTags - Response:",t.data),t.data}async getTagById(t){console.log("[TagAPI] getTagById - Request:",{id:t,url:Ut.TAG_BY_ID(t)});const n=await this.client.get(Ut.TAG_BY_ID(t));return console.log("[TagAPI] getTagById - Response:",n.data),n.data}async createTag(t){console.log("[TagAPI] createTag - Request:",{url:Ut.TAGS,data:t});const n=await this.client.post(Ut.TAGS,t);return console.log("[TagAPI] createTag - Response:",n.data),n.data}async updateTag(t){console.log("[TagAPI] updateTag - Request:",{url:Ut.TAGS,data:t});const n=await this.client.put(Ut.TAGS,t);return console.log("[TagAPI] updateTag - Response:",n.data),n.data}async deleteTag(t){console.log("[TagAPI] deleteTag - Request:",{id:t,url:Ut.TAG_BY_ID(t)}),await this.client.delete(Ut.TAG_BY_ID(t)),console.log("[TagAPI] deleteTag - Success")}async mergeTags(t,n){const r=Ut.TAG_MERGE(t,n);console.log("[TagAPI] mergeTags - Request:",{url:r,sourceTagId:t,targetTagId:n}),await this.client.post(r),console.log("[TagAPI] mergeTags - Success")}}const am=$.createContext(void 0);function FL({config:e,children:t}){const n=$.useMemo(()=>{const r=e.apiClient||Le.create({baseURL:e.apiUrl,headers:{"Content-Type":"application/json",...e.headers}}),i=new im(r),s=new sm(r),o=new om(r);return{config:e,apiClient:r,articleApi:i,categoryApi:s,tagApi:o}},[e]);return E.jsx(am.Provider,{value:n,children:t})}function Gr(){const e=$.useContext(am);if(!e)throw new Error("useNNews must be used within a NNewsProvider");return e}function qL({article:e,categories:t=[],availableRoles:n,onFetchRoles:r,onSave:i,onCancel:s,loading:o=!1}){const{articleApi:a}=Gr(),[l,c]=$.useState(""),[u,d]=$.useState(""),[h,f]=$.useState(""),[p,m]=$.useState(""),[b,y]=$.useState(!1),[_,v]=$.useState(ze.Draft),[T,C]=$.useState(null),[N,B]=$.useState(""),[q,G]=$.useState(""),[O,H]=$.useState(!0),[P,ne]=$.useState(new Set),[X,Y]=$.useState([]),[L,U]=$.useState(!1),[F,K]=$.useState({});$.useEffect(()=>{var te;e&&(c(e.title),d(e.content),f(e.imageName||""),console.log("imageName:",e.imageName),e.imageName&&m(e.imageName),v(e.status),C(e.categoryId||null),B(e.dateAt?new Date(e.dateAt).toISOString().slice(0,16):""),G(((te=e.tags)==null?void 0:te.map(ce=>ce.title).join(", "))||""),e.roles&&e.roles.length>0?(H(!1),ne(new Set(e.roles.map(ce=>ce.slug)))):(H(!0),ne(new Set)))},[e]);const w=n||X;$.useEffect(()=>{if(n&&n.length>0||!r)return;let te=!1;return U(!0),r().then(ce=>{te||Y(ce)}).catch(ce=>{console.warn("Failed to fetch roles:",ce)}).finally(()=>{te||U(!1)}),()=>{te=!0}},[n,r]);const Q=$.useCallback(te=>{H(te),te&&ne(new Set)},[]),le=$.useCallback(te=>{ne(ce=>{const Ne=new Set(ce);return Ne.has(te)?Ne.delete(te):Ne.add(te),Ne})},[]),k=()=>{const te={};return l.trim()||(te.title="Title is required"),u.trim()||(te.content="Content is required"),K(te),Object.keys(te).length===0},ge=async te=>{if(te.preventDefault(),!k())return;const ce=O?[]:Array.from(P),Ne={title:l.trim(),content:u.trim(),imageName:h||void 0,status:_,categoryId:T||void 0,dateAt:N||void 0,tagList:q.trim()||void 0,roleIds:ce.length>0?ce:void 0};e?await i({articleId:e.articleId,...Ne}):await i(Ne)},se=async te=>{var qe;const ce=(qe=te.target.files)==null?void 0:qe[0];if(!ce)return;if(!ce.type.startsWith("image/")){K({...F,image:"Please select an image file"});return}if(ce.size>5*1024*1024){K({...F,image:"Image size must be less than 5MB"});return}K({...F,image:""});const Ne=new FileReader;Ne.onloadend=()=>{m(Ne.result)},Ne.readAsDataURL(ce);try{y(!0);const Ue=await a.uploadImage(ce);f(Ue),K({...F,image:""})}catch(Ue){console.error("Error uploading image:",Ue),K({...F,image:"Failed to upload image. Please try again."})}finally{y(!1)}},_e=()=>{m(""),f("")};return E.jsxs("form",{onSubmit:ge,className:"space-y-6",children:[E.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[E.jsxs("div",{className:"col-span-2 p-4",children:[E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"title",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Title *"}),E.jsx("input",{id:"title",type:"text",value:l,onChange:te=>c(te.target.value),className:`w-full rounded-md border ${F.title?"border-red-300 dark:border-red-600":"border-gray-300 dark:border-gray-600"} px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500`,placeholder:"Enter article title"}),F.title&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:F.title})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"dateAt",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Publication Date"}),E.jsx("input",{id:"dateAt",type:"datetime-local",value:N,onChange:te=>B(te.target.value),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"category",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Category"}),E.jsxs("select",{id:"category",value:T||"",onChange:te=>C(te.target.value?Number(te.target.value):null),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[E.jsx("option",{value:"",children:"No Category"}),t.map(te=>E.jsx("option",{value:te.categoryId,children:te.title},te.categoryId))]})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"status",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Status"}),E.jsxs("select",{id:"status",value:_,onChange:te=>v(Number(te.target.value)),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[E.jsx("option",{value:ze.Draft,children:"Draft"}),E.jsx("option",{value:ze.Published,children:"Published"}),E.jsx("option",{value:ze.Archived,children:"Archived"}),E.jsx("option",{value:ze.Scheduled,children:"Scheduled"}),E.jsx("option",{value:ze.Review,children:"Review"})]})]})]}),E.jsx("div",{className:"col-span-1",children:E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"image",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Featured Image"}),p?E.jsxs("div",{className:"relative",children:[E.jsx("img",{src:p,alt:"Preview",className:"w-full h-[250px] object-cover rounded-md border border-gray-300 dark:border-gray-600",style:{height:"250px"}}),E.jsx("button",{type:"button",onClick:_e,className:"absolute top-2 right-2 rounded-full bg-red-600 p-2 text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500",disabled:b,style:{top:"2px",right:"2px"},children:E.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:E.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),b&&E.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black bg-opacity-50 rounded-md",children:E.jsx("span",{className:"text-white text-sm",children:"Uploading..."})})]}):E.jsx("div",{className:"flex items-center",children:E.jsx("input",{id:"image",type:"file",accept:"image/*",onChange:se,disabled:b,className:"block w-full text-sm text-gray-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md cursor-pointer bg-white dark:bg-gray-900 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500"})}),F.image&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:F.image}),E.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"JPG, PNG, GIF. Max 5MB"})]})})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Content *"}),E.jsx(Lg,{value:u,onChange:d,placeholder:"Write your article content...",error:F.content}),F.content&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:F.content})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"tags",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Tags"}),E.jsx("input",{id:"tags",type:"text",value:q,onChange:te=>G(te.target.value),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",placeholder:"Enter tags separated by commas (e.g., AI, Technology, Innovation)"}),E.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Comma-separated list of tags. Tags will be created automatically if they don't exist."})]}),E.jsxs("div",{className:"space-y-3",children:[E.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Visibilidade"}),E.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[E.jsx("input",{type:"checkbox",checked:O,onChange:te=>Q(te.target.checked),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500"}),E.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:"Visível para todos"})]}),!O&&E.jsx("div",{className:"ml-6 space-y-2",children:L?E.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Carregando perfis..."}):w.length>0?E.jsxs("div",{className:"space-y-2",children:[E.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Selecione os perfis que podem visualizar este artigo:"}),w.map(te=>E.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[E.jsx("input",{type:"checkbox",checked:P.has(te.slug),onChange:()=>le(te.slug),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500"}),E.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:te.name})]},te.slug))]}):E.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Nenhum perfil disponível."})})]}),E.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[E.jsx("button",{type:"button",onClick:s,disabled:o,className:"rounded-md border border-gray-300 dark:border-gray-600 px-6 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50",children:"Cancel"}),E.jsx("button",{type:"submit",disabled:o,className:"rounded-md bg-blue-600 px-6 py-2 text-white hover:bg-blue-700 disabled:opacity-50",children:o?"Saving...":e?"Update Article":"Create Article"})]})]})}function UL({mode:e,articleId:t,isOpen:n,onSuccess:r,onClose:i}){const{articleApi:s}=Gr(),[o,a]=$.useState(""),[l,c]=$.useState(!1),[u,d]=$.useState(!1),[h,f]=$.useState(null),[p,m]=$.useState(""),b=()=>o.trim()?o.trim().length<10?(f("Prompt must be at least 10 characters long"),!1):o.length>2e3?(f("Prompt must be less than 2000 characters"),!1):!0:(f("Prompt is required"),!1),y=async()=>{if(b()){if(e==="update"&&!t){f("Article ID is required for update mode");return}d(!0),f(null),m(e==="create"?"Creating article with AI...":"Updating article with AI...");try{const C={...e==="update"&&t&&{articleId:t},prompt:o.trim(),generateImage:l};l&&m("Generating content and image with AI... This may take a few moments.");let N;e==="create"?N=await s.createArticleWithAI(C):N=await s.updateArticleWithAI(C),m(""),r(N),a(""),c(!1),i()}catch(C){console.error("Error generating article with AI:",C),f(C.message||"Failed to generate article with AI. Please try again."),m("")}finally{d(!1)}}},_=()=>{u||(a(""),c(!1),f(null),i())},v=e==="create"?'Describe the article you want to create (e.g., "Write a comprehensive article about AI trends in 2024, including ChatGPT-4, Gemini, and practical applications in different industries")':'Describe the changes you want to make (e.g., "Add a new section about the latest ChatGPT-4 updates launched in January 2024 and improve the introduction to make it more engaging")',T=()=>{const C="w-full rounded-md border px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed",N=h&&!o.trim()?"border-red-300 dark:border-red-600":"border-gray-300 dark:border-gray-600";return`${C} ${N}`};return n?E.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto","aria-labelledby":"modal-title",role:"dialog","aria-modal":"true",children:E.jsxs("div",{className:"flex min-h-screen items-center justify-center p-4 text-center sm:p-0",children:[E.jsx("div",{className:"fixed inset-0 bg-gray-500 dark:bg-gray-900 bg-opacity-75 dark:bg-opacity-75 transition-opacity",onClick:_}),E.jsxs("div",{className:"relative transform overflow-hidden rounded-lg bg-white dark:bg-gray-800 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-2xl",children:[E.jsxs("div",{className:"bg-white dark:bg-gray-800 px-6 pb-4 pt-5",children:[E.jsxs("div",{className:"flex items-start justify-between mb-4",children:[E.jsxs("div",{className:"flex items-start gap-3",children:[E.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900",children:E.jsx("svg",{className:"h-6 w-6 text-blue-600 dark:text-blue-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:E.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),E.jsxs("div",{children:[E.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",id:"modal-title",children:e==="create"?"Create Article with AI":"Update Article with AI"}),E.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:e==="create"?"Use AI to generate a complete article with title, content, and tags based on your description.":"Use AI to modify the existing article content based on your instructions."})]})]}),E.jsxs("button",{type:"button",onClick:_,disabled:u,className:"rounded-md text-gray-400 hover:text-gray-500 dark:hover:text-gray-300 disabled:opacity-50",children:[E.jsx("span",{className:"sr-only",children:"Close"}),E.jsx("svg",{className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:E.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]})]}),E.jsxs("div",{className:"space-y-4",children:[E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"prompt",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Description / Instructions *"}),E.jsx("textarea",{id:"prompt",value:o,onChange:C=>a(C.target.value),rows:6,disabled:u,className:T(),placeholder:v,minLength:10,maxLength:2e3}),E.jsxs("div",{className:"flex justify-between items-center",children:[E.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[o.length," / 2000 characters (minimum 10)"]}),h&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:h})]})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[E.jsx("input",{type:"checkbox",checked:l,onChange:C=>c(C.target.checked),disabled:u,className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed"}),E.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Generate image with DALL-E 3"})]}),E.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ml-6",children:"AI will create an illustrative image for the article. This may take a few extra seconds."})]}),u&&p&&E.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-800 bg-yellow-50 dark:bg-yellow-900/20 p-4",children:E.jsxs("div",{className:"flex items-center gap-3",children:[E.jsxs("svg",{className:"h-5 w-5 text-yellow-600 dark:text-yellow-400 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[E.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),E.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),E.jsxs("div",{children:[E.jsx("p",{className:"text-sm font-medium text-yellow-900 dark:text-yellow-100",children:p}),E.jsx("p",{className:"text-xs text-yellow-700 dark:text-yellow-300 mt-1",children:"Please wait..."})]})]})})]})]}),E.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900 px-6 py-4 flex justify-end gap-3",children:[E.jsx("button",{type:"button",onClick:_,disabled:u,className:"rounded-md border border-gray-300 dark:border-gray-600 px-6 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed",children:"Cancel"}),E.jsx("button",{type:"button",onClick:y,disabled:u||o.trim().length<10,className:"rounded-md bg-gradient-to-r from-blue-600 to-purple-600 px-6 py-2 text-white hover:from-blue-700 hover:to-purple-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:u?E.jsxs(E.Fragment,{children:[E.jsxs("svg",{className:"h-4 w-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[E.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),E.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),E.jsx("span",{children:"Generating..."})]}):E.jsxs(E.Fragment,{children:[E.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:E.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),E.jsx("span",{children:e==="create"?"Create with AI":"Update with AI"})]})})]})]})]})}):null}function $L({value:e,onChange:t,placeholder:n="Write your content in Markdown...",label:r,error:i,minHeight:s="400px"}){const[o,a]=$.useState("edit");return E.jsxs("div",{className:"space-y-2",children:[r&&E.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:r}),E.jsxs("div",{className:"overflow-hidden rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900",children:[E.jsxs("div",{className:"flex border-b border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800",children:[E.jsx("button",{type:"button",onClick:()=>a("edit"),className:`flex-1 px-4 py-2 text-sm font-medium ${o==="edit"?"border-b-2 border-blue-600 bg-white dark:bg-gray-900 text-blue-600 dark:text-blue-400":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100"}`,children:"Edit"}),E.jsx("button",{type:"button",onClick:()=>a("preview"),className:`flex-1 px-4 py-2 text-sm font-medium ${o==="preview"?"border-b-2 border-blue-600 bg-white dark:bg-gray-900 text-blue-600 dark:text-blue-400":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100"}`,children:"Preview"})]}),E.jsx("div",{style:{minHeight:s},children:o==="edit"?E.jsx("textarea",{value:e,onChange:l=>t(l.target.value),placeholder:n,className:"h-full w-full resize-none border-0 p-4 font-mono text-sm bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring-0",style:{minHeight:s}}):E.jsx("div",{className:"prose dark:prose-invert max-w-none p-4 text-gray-900 dark:text-gray-100",children:e?E.jsx(ch,{remarkPlugins:[qh],rehypePlugins:[_p],children:e}):E.jsx("div",{className:"text-gray-400 dark:text-gray-500",children:"Nothing to preview"})})})]}),i&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:i}),E.jsxs("div",{className:"rounded-md bg-gray-50 dark:bg-gray-800 p-3 text-xs text-gray-600 dark:text-gray-400",children:[E.jsx("p",{className:"font-medium",children:"Markdown Syntax Help:"}),E.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-2",children:[E.jsxs("div",{children:[E.jsx("strong",{children:"# Heading 1"})," - Main heading"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"## Heading 2"})," - Subheading"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"**bold text**"})," - Bold"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"*italic text*"})," - Italic"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"[link](url)"})," - Link"]}),E.jsxs("div",{children:[E.jsx("strong",{children:""})," - Image"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"- item"})," - Bullet list"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"1. item"})," - Numbered list"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"`code`"})," - Inline code"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"```language```"})," - Code block"]})]})]})]})}/**
|
|
171
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Jn(this.defaults,n);const{transitional:r,paramsSerializer:i,headers:s}=n;r!==void 0&&Os.assertOptions(r,{silentJSONParsing:en.transitional(en.boolean),forcedJSONParsing:en.transitional(en.boolean),clarifyTimeoutError:en.transitional(en.boolean)},!1),i!=null&&(R.isFunction(i)?n.paramsSerializer={serialize:i}:Os.assertOptions(i,{encode:en.function,serialize:en.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Os.assertOptions(n,{baseUrl:en.spelling("baseURL"),withXsrfToken:en.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],p=>{delete s[p]}),n.headers=gt.concat(o,s);const a=[];let l=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(l=l&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let u,d=0,h;if(!l){const p=[gf.bind(this),void 0];for(p.unshift(...a),p.push(...c),h=p.length,u=Promise.resolve(n);d<h;)u=u.then(p[d++],p[d++]);return u}h=a.length;let f=n;for(;d<h;){const p=a[d++],m=a[d++];try{f=p(f)}catch(b){m.call(this,b);break}}try{u=gf.call(this,f)}catch(p){return Promise.reject(p)}for(d=0,h=c.length;d<h;)u=u.then(c[d++],c[d++]);return u}getUri(t){t=Jn(this.defaults,t);const n=Xg(t.baseURL,t.url,t.allowAbsoluteUrls);return Kg(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){Vn.prototype[t]=function(n,r){return this.request(Jn(r||{},{method:t,url:n,data:(r||{}).data}))}});R.forEach(["post","put","patch"],function(t){function n(r){return function(s,o,a){return this.request(Jn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Vn.prototype[t]=n(),Vn.prototype[t+"Form"]=n(!0)});let DL=class nm{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(i=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](i);r._listeners=null}),this.promise.then=i=>{let s;const o=new Promise(a=>{r.subscribe(a),s=a}).then(i);return o.cancel=function(){r.unsubscribe(s)},o},t(function(s,o,a){r.reason||(r.reason=new Hr(s,o,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new nm(function(i){t=i}),cancel:t}}};function PL(e){return function(n){return e.apply(null,n)}}function BL(e){return R.isObject(e)&&e.isAxiosError===!0}const Ol={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Ol).forEach(([e,t])=>{Ol[t]=e});function rm(e){const t=new Vn(e),n=Mg(Vn.prototype.request,t);return R.extend(n,Vn.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(i){return rm(Jn(e,i))},n}const Le=rm(Gi);Le.Axios=Vn;Le.CanceledError=Hr;Le.CancelToken=DL;Le.isCancel=Yg;Le.VERSION=tm;Le.toFormData=Eo;Le.AxiosError=de;Le.Cancel=Le.CanceledError;Le.all=function(t){return Promise.all(t)};Le.spread=PL;Le.isAxiosError=BL;Le.mergeConfig=Jn;Le.AxiosHeaders=gt;Le.formToJSON=e=>Vg(R.isHTMLForm(e)?new FormData(e):e);Le.getAdapter=em.getAdapter;Le.HttpStatusCode=Ol;Le.default=Le;const{Axios:N2,AxiosError:A2,CanceledError:S2,isCancel:T2,CancelToken:C2,VERSION:O2,all:I2,Cancel:R2,isAxiosError:L2,spread:M2,toFormData:D2,AxiosHeaders:P2,HttpStatusCode:B2,formToJSON:F2,getAdapter:q2,mergeConfig:U2}=Le,st={ARTICLES:"/article",ARTICLES_FILTER:"/article/filter",ARTICLE_BY_ID:e=>`/article/${e}`,IMAGE_UPLOAD:"/Image/uploadImage",INSERT_WITH_AI:"/article/insertWithAI",UPDATE_WITH_AI:"/article/updateWithAI"};class im{constructor(t){this.client=t}async uploadImage(t){const n=new FormData;n.append("file",t),console.log("[ArticleAPI] uploadImage - Request:",{fileName:t.name,fileSize:t.size});const r=await this.client.post(st.IMAGE_UPLOAD,n,{headers:{"Content-Type":"multipart/form-data"}});return console.log("[ArticleAPI] uploadImage - Response:",r.data),r.data}async listArticles(t,n=1,r=10){const i={page:n,pageSize:r};t&&(i.categoryId=t),console.log("[ArticleAPI] listArticles - Request:",{url:st.ARTICLES,params:i});const s=await this.client.get(st.ARTICLES,{params:i});return console.log("[ArticleAPI] listArticles - Response:",s.data),this.transformArticleDates(s.data)}async filterArticles(t,n,r=1,i=10){const s={page:r,pageSize:i};t&&t.length>0&&(s.roles=t.join(",")),n!==void 0&&(s.parentId=n);const o=await this.client.get(st.ARTICLES_FILTER,{params:s});return this.transformArticleDates(o.data)}async getArticleById(t){const n=await this.client.get(st.ARTICLE_BY_ID(t));return this.transformArticleDate(n.data)}async createArticle(t){console.log("[ArticleAPI] createArticle - Request:",{url:st.ARTICLES,data:t});const n=await this.client.post(st.ARTICLES,t);return console.log("[ArticleAPI] createArticle - Response:",n.data),this.transformArticleDate(n.data)}async updateArticle(t){console.log("[ArticleAPI] updateArticle - Request:",{url:st.ARTICLES,data:t});const n=await this.client.put(st.ARTICLES,t);return console.log("[ArticleAPI] updateArticle - Response:",n.data),this.transformArticleDate(n.data)}async deleteArticle(t){console.log("[ArticleAPI] deleteArticle - Request:",{id:t,url:st.ARTICLE_BY_ID(t)}),await this.client.delete(st.ARTICLE_BY_ID(t)),console.log("[ArticleAPI] deleteArticle - Success")}async createArticleWithAI(t){console.log("[ArticleAPI] createArticleWithAI - Request:",{url:st.INSERT_WITH_AI,data:t});const n=await this.client.post(st.INSERT_WITH_AI,t);return console.log("[ArticleAPI] createArticleWithAI - Response:",n.data),this.transformArticleDate(n.data)}async updateArticleWithAI(t){if(!t.articleId)throw new Error("articleId is required for updateWithAI");console.log("[ArticleAPI] updateArticleWithAI - Request:",{url:st.UPDATE_WITH_AI,data:t});const n=await this.client.put(st.UPDATE_WITH_AI,t);return console.log("[ArticleAPI] updateArticleWithAI - Response:",n.data),this.transformArticleDate(n.data)}transformArticleDate(t){return{...t,dateAt:t.dateAt?new Date(t.dateAt):void 0,createdAt:t.createdAt?new Date(t.createdAt):void 0,updatedAt:t.updatedAt?new Date(t.updatedAt):void 0,category:t.category?{...t.category,createdAt:t.category.createdAt?new Date(t.category.createdAt):void 0,updatedAt:t.category.updatedAt?new Date(t.category.updatedAt):void 0}:void 0}}transformArticleDates(t){return{...t,items:t.items.map(n=>this.transformArticleDate(n))}}}const tn={CATEGORIES:"/category",CATEGORIES_FILTER:"/category/filter",CATEGORY_BY_ID:e=>`/category/${e}`};class sm{constructor(t){this.client=t}async listCategories(){console.log("[CategoryAPI] listCategories - Request:",{url:tn.CATEGORIES});const t=await this.client.get(tn.CATEGORIES);return console.log("[CategoryAPI] listCategories - Response:",t.data),this.transformCategoryDates(t.data)}async filterCategories(t,n){const r={};t&&t.length>0&&(r.roles=t.join(",")),n!==void 0&&(r.parentId=n);const i=await this.client.get(tn.CATEGORIES_FILTER,{params:r});return this.transformCategoryDates(i.data)}async getCategoryById(t){const n=await this.client.get(tn.CATEGORY_BY_ID(t));return this.transformCategoryDate(n.data)}async createCategory(t){console.log("[CategoryAPI] createCategory - Request:",{url:tn.CATEGORIES,data:t});const n=await this.client.post(tn.CATEGORIES,t);return console.log("[CategoryAPI] createCategory - Response:",n.data),this.transformCategoryDate(n.data)}async updateCategory(t){console.log("[CategoryAPI] updateCategory - Request:",{url:tn.CATEGORIES,data:t});const n=await this.client.put(tn.CATEGORIES,t);return console.log("[CategoryAPI] updateCategory - Response:",n.data),this.transformCategoryDate(n.data)}async deleteCategory(t){console.log("[CategoryAPI] deleteCategory - Request:",{id:t,url:tn.CATEGORY_BY_ID(t)}),await this.client.delete(tn.CATEGORY_BY_ID(t)),console.log("[CategoryAPI] deleteCategory - Success")}transformCategoryDate(t){return{...t,createdAt:t.createdAt?new Date(t.createdAt):void 0,updatedAt:t.updatedAt?new Date(t.updatedAt):void 0}}transformCategoryDates(t){return t.map(n=>this.transformCategoryDate(n))}}const Ut={TAGS:"/tag",TAG_BY_ID:e=>`/tag/${e}`,TAG_MERGE:(e,t)=>`/Tag/merge/${e}/${t}`};class om{constructor(t){this.client=t}async listTags(){console.log("[TagAPI] listTags - Request:",{url:Ut.TAGS});const t=await this.client.get(Ut.TAGS);return console.log("[TagAPI] listTags - Response:",t.data),t.data}async getTagById(t){console.log("[TagAPI] getTagById - Request:",{id:t,url:Ut.TAG_BY_ID(t)});const n=await this.client.get(Ut.TAG_BY_ID(t));return console.log("[TagAPI] getTagById - Response:",n.data),n.data}async createTag(t){console.log("[TagAPI] createTag - Request:",{url:Ut.TAGS,data:t});const n=await this.client.post(Ut.TAGS,t);return console.log("[TagAPI] createTag - Response:",n.data),n.data}async updateTag(t){console.log("[TagAPI] updateTag - Request:",{url:Ut.TAGS,data:t});const n=await this.client.put(Ut.TAGS,t);return console.log("[TagAPI] updateTag - Response:",n.data),n.data}async deleteTag(t){console.log("[TagAPI] deleteTag - Request:",{id:t,url:Ut.TAG_BY_ID(t)}),await this.client.delete(Ut.TAG_BY_ID(t)),console.log("[TagAPI] deleteTag - Success")}async mergeTags(t,n){const r=Ut.TAG_MERGE(t,n);console.log("[TagAPI] mergeTags - Request:",{url:r,sourceTagId:t,targetTagId:n}),await this.client.post(r),console.log("[TagAPI] mergeTags - Success")}}const am=$.createContext(void 0);function FL({config:e,children:t}){const n=$.useMemo(()=>{const r=e.apiClient||Le.create({baseURL:e.apiUrl,headers:{"Content-Type":"application/json",...e.headers}}),i=new im(r),s=new sm(r),o=new om(r);return{config:e,apiClient:r,articleApi:i,categoryApi:s,tagApi:o}},[e]);return E.jsx(am.Provider,{value:n,children:t})}function Gr(){const e=$.useContext(am);if(!e)throw new Error("useNNews must be used within a NNewsProvider");return e}function qL({article:e,categories:t=[],availableRoles:n,onFetchRoles:r,onSave:i,onCancel:s,loading:o=!1}){const{articleApi:a}=Gr(),[l,c]=$.useState(""),[u,d]=$.useState(""),[h,f]=$.useState(""),[p,m]=$.useState(""),[b,y]=$.useState(!1),[_,v]=$.useState(ze.Draft),[T,C]=$.useState(null),[N,B]=$.useState(""),[q,G]=$.useState(""),[O,H]=$.useState(!0),[P,ne]=$.useState(new Set),[X,Y]=$.useState([]),[L,U]=$.useState(!1),[F,K]=$.useState({});$.useEffect(()=>{var te;e&&(c(e.title),d(e.content),f(e.imageName||""),console.log("imageName:",e.imageName),e.imageName&&m(e.imageName),v(e.status),C(e.categoryId||null),B(e.dateAt?new Date(e.dateAt).toISOString().slice(0,16):""),G(((te=e.tags)==null?void 0:te.map(ce=>ce.title).join(", "))||""),e.roles&&e.roles.length>0?(H(!1),ne(new Set(e.roles.map(ce=>ce.slug)))):(H(!0),ne(new Set)))},[e]);const w=n||X;$.useEffect(()=>{if(n&&n.length>0||!r)return;let te=!1;return U(!0),r().then(ce=>{te||Y(ce)}).catch(ce=>{console.warn("Failed to fetch roles:",ce)}).finally(()=>{te||U(!1)}),()=>{te=!0}},[n,r]);const Q=$.useCallback(te=>{H(te),te&&ne(new Set)},[]),le=$.useCallback(te=>{ne(ce=>{const Ne=new Set(ce);return Ne.has(te)?Ne.delete(te):Ne.add(te),Ne})},[]),k=()=>{const te={};return l.trim()||(te.title="Title is required"),u.trim()||(te.content="Content is required"),K(te),Object.keys(te).length===0},ge=async te=>{if(te.preventDefault(),!k())return;const ce=O?[]:Array.from(P),Ne={title:l.trim(),content:u.trim(),imageName:h||void 0,status:_,categoryId:T||void 0,dateAt:N||void 0,tagList:q.trim()||void 0,roles:ce.length>0?ce:void 0};e?await i({articleId:e.articleId,...Ne}):await i(Ne)},se=async te=>{var qe;const ce=(qe=te.target.files)==null?void 0:qe[0];if(!ce)return;if(!ce.type.startsWith("image/")){K({...F,image:"Please select an image file"});return}if(ce.size>5*1024*1024){K({...F,image:"Image size must be less than 5MB"});return}K({...F,image:""});const Ne=new FileReader;Ne.onloadend=()=>{m(Ne.result)},Ne.readAsDataURL(ce);try{y(!0);const Ue=await a.uploadImage(ce);f(Ue),K({...F,image:""})}catch(Ue){console.error("Error uploading image:",Ue),K({...F,image:"Failed to upload image. Please try again."})}finally{y(!1)}},_e=()=>{m(""),f("")};return E.jsxs("form",{onSubmit:ge,className:"space-y-6",children:[E.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[E.jsxs("div",{className:"col-span-2 p-4",children:[E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"title",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Title *"}),E.jsx("input",{id:"title",type:"text",value:l,onChange:te=>c(te.target.value),className:`w-full rounded-md border ${F.title?"border-red-300 dark:border-red-600":"border-gray-300 dark:border-gray-600"} px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500`,placeholder:"Enter article title"}),F.title&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:F.title})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"dateAt",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Publication Date"}),E.jsx("input",{id:"dateAt",type:"datetime-local",value:N,onChange:te=>B(te.target.value),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"category",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Category"}),E.jsxs("select",{id:"category",value:T||"",onChange:te=>C(te.target.value?Number(te.target.value):null),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[E.jsx("option",{value:"",children:"No Category"}),t.map(te=>E.jsx("option",{value:te.categoryId,children:te.title},te.categoryId))]})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"status",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Status"}),E.jsxs("select",{id:"status",value:_,onChange:te=>v(Number(te.target.value)),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[E.jsx("option",{value:ze.Draft,children:"Draft"}),E.jsx("option",{value:ze.Published,children:"Published"}),E.jsx("option",{value:ze.Archived,children:"Archived"}),E.jsx("option",{value:ze.Scheduled,children:"Scheduled"}),E.jsx("option",{value:ze.Review,children:"Review"})]})]})]}),E.jsx("div",{className:"col-span-1",children:E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"image",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Featured Image"}),p?E.jsxs("div",{className:"relative",children:[E.jsx("img",{src:p,alt:"Preview",className:"w-full h-[250px] object-cover rounded-md border border-gray-300 dark:border-gray-600",style:{height:"250px"}}),E.jsx("button",{type:"button",onClick:_e,className:"absolute top-2 right-2 rounded-full bg-red-600 p-2 text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500",disabled:b,style:{top:"2px",right:"2px"},children:E.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:E.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),b&&E.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black bg-opacity-50 rounded-md",children:E.jsx("span",{className:"text-white text-sm",children:"Uploading..."})})]}):E.jsx("div",{className:"flex items-center",children:E.jsx("input",{id:"image",type:"file",accept:"image/*",onChange:se,disabled:b,className:"block w-full text-sm text-gray-900 dark:text-gray-100 border border-gray-300 dark:border-gray-600 rounded-md cursor-pointer bg-white dark:bg-gray-900 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500"})}),F.image&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:F.image}),E.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"JPG, PNG, GIF. Max 5MB"})]})})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Content *"}),E.jsx(Lg,{value:u,onChange:d,placeholder:"Write your article content...",error:F.content}),F.content&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:F.content})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"tags",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Tags"}),E.jsx("input",{id:"tags",type:"text",value:q,onChange:te=>G(te.target.value),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",placeholder:"Enter tags separated by commas (e.g., AI, Technology, Innovation)"}),E.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Comma-separated list of tags. Tags will be created automatically if they don't exist."})]}),E.jsxs("div",{className:"space-y-3",children:[E.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Visibilidade"}),E.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[E.jsx("input",{type:"checkbox",checked:O,onChange:te=>Q(te.target.checked),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500"}),E.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:"Visível para todos"})]}),!O&&E.jsx("div",{className:"ml-6 space-y-2",children:L?E.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Carregando perfis..."}):w.length>0?E.jsxs("div",{className:"space-y-2",children:[E.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Selecione os perfis que podem visualizar este artigo:"}),w.map(te=>E.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[E.jsx("input",{type:"checkbox",checked:P.has(te.slug),onChange:()=>le(te.slug),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500"}),E.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:te.name})]},te.slug))]}):E.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Nenhum perfil disponível."})})]}),E.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[E.jsx("button",{type:"button",onClick:s,disabled:o,className:"rounded-md border border-gray-300 dark:border-gray-600 px-6 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50",children:"Cancel"}),E.jsx("button",{type:"submit",disabled:o,className:"rounded-md bg-blue-600 px-6 py-2 text-white hover:bg-blue-700 disabled:opacity-50",children:o?"Saving...":e?"Update Article":"Create Article"})]})]})}function UL({mode:e,articleId:t,isOpen:n,onSuccess:r,onClose:i}){const{articleApi:s}=Gr(),[o,a]=$.useState(""),[l,c]=$.useState(!1),[u,d]=$.useState(!1),[h,f]=$.useState(null),[p,m]=$.useState(""),b=()=>o.trim()?o.trim().length<10?(f("Prompt must be at least 10 characters long"),!1):o.length>2e3?(f("Prompt must be less than 2000 characters"),!1):!0:(f("Prompt is required"),!1),y=async()=>{if(b()){if(e==="update"&&!t){f("Article ID is required for update mode");return}d(!0),f(null),m(e==="create"?"Creating article with AI...":"Updating article with AI...");try{const C={...e==="update"&&t&&{articleId:t},prompt:o.trim(),generateImage:l};l&&m("Generating content and image with AI... This may take a few moments.");let N;e==="create"?N=await s.createArticleWithAI(C):N=await s.updateArticleWithAI(C),m(""),r(N),a(""),c(!1),i()}catch(C){console.error("Error generating article with AI:",C),f(C.message||"Failed to generate article with AI. Please try again."),m("")}finally{d(!1)}}},_=()=>{u||(a(""),c(!1),f(null),i())},v=e==="create"?'Describe the article you want to create (e.g., "Write a comprehensive article about AI trends in 2024, including ChatGPT-4, Gemini, and practical applications in different industries")':'Describe the changes you want to make (e.g., "Add a new section about the latest ChatGPT-4 updates launched in January 2024 and improve the introduction to make it more engaging")',T=()=>{const C="w-full rounded-md border px-4 py-2 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed",N=h&&!o.trim()?"border-red-300 dark:border-red-600":"border-gray-300 dark:border-gray-600";return`${C} ${N}`};return n?E.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto","aria-labelledby":"modal-title",role:"dialog","aria-modal":"true",children:E.jsxs("div",{className:"flex min-h-screen items-center justify-center p-4 text-center sm:p-0",children:[E.jsx("div",{className:"fixed inset-0 bg-gray-500 dark:bg-gray-900 bg-opacity-75 dark:bg-opacity-75 transition-opacity",onClick:_}),E.jsxs("div",{className:"relative transform overflow-hidden rounded-lg bg-white dark:bg-gray-800 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-2xl",children:[E.jsxs("div",{className:"bg-white dark:bg-gray-800 px-6 pb-4 pt-5",children:[E.jsxs("div",{className:"flex items-start justify-between mb-4",children:[E.jsxs("div",{className:"flex items-start gap-3",children:[E.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900",children:E.jsx("svg",{className:"h-6 w-6 text-blue-600 dark:text-blue-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:E.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),E.jsxs("div",{children:[E.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",id:"modal-title",children:e==="create"?"Create Article with AI":"Update Article with AI"}),E.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:e==="create"?"Use AI to generate a complete article with title, content, and tags based on your description.":"Use AI to modify the existing article content based on your instructions."})]})]}),E.jsxs("button",{type:"button",onClick:_,disabled:u,className:"rounded-md text-gray-400 hover:text-gray-500 dark:hover:text-gray-300 disabled:opacity-50",children:[E.jsx("span",{className:"sr-only",children:"Close"}),E.jsx("svg",{className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:E.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]})]}),E.jsxs("div",{className:"space-y-4",children:[E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{htmlFor:"prompt",className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Description / Instructions *"}),E.jsx("textarea",{id:"prompt",value:o,onChange:C=>a(C.target.value),rows:6,disabled:u,className:T(),placeholder:v,minLength:10,maxLength:2e3}),E.jsxs("div",{className:"flex justify-between items-center",children:[E.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[o.length," / 2000 characters (minimum 10)"]}),h&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:h})]})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[E.jsx("input",{type:"checkbox",checked:l,onChange:C=>c(C.target.checked),disabled:u,className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed"}),E.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Generate image with DALL-E 3"})]}),E.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ml-6",children:"AI will create an illustrative image for the article. This may take a few extra seconds."})]}),u&&p&&E.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-800 bg-yellow-50 dark:bg-yellow-900/20 p-4",children:E.jsxs("div",{className:"flex items-center gap-3",children:[E.jsxs("svg",{className:"h-5 w-5 text-yellow-600 dark:text-yellow-400 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[E.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),E.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),E.jsxs("div",{children:[E.jsx("p",{className:"text-sm font-medium text-yellow-900 dark:text-yellow-100",children:p}),E.jsx("p",{className:"text-xs text-yellow-700 dark:text-yellow-300 mt-1",children:"Please wait..."})]})]})})]})]}),E.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900 px-6 py-4 flex justify-end gap-3",children:[E.jsx("button",{type:"button",onClick:_,disabled:u,className:"rounded-md border border-gray-300 dark:border-gray-600 px-6 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed",children:"Cancel"}),E.jsx("button",{type:"button",onClick:y,disabled:u||o.trim().length<10,className:"rounded-md bg-gradient-to-r from-blue-600 to-purple-600 px-6 py-2 text-white hover:from-blue-700 hover:to-purple-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:u?E.jsxs(E.Fragment,{children:[E.jsxs("svg",{className:"h-4 w-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[E.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),E.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),E.jsx("span",{children:"Generating..."})]}):E.jsxs(E.Fragment,{children:[E.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:E.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),E.jsx("span",{children:e==="create"?"Create with AI":"Update with AI"})]})})]})]})]})}):null}function $L({value:e,onChange:t,placeholder:n="Write your content in Markdown...",label:r,error:i,minHeight:s="400px"}){const[o,a]=$.useState("edit");return E.jsxs("div",{className:"space-y-2",children:[r&&E.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:r}),E.jsxs("div",{className:"overflow-hidden rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900",children:[E.jsxs("div",{className:"flex border-b border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800",children:[E.jsx("button",{type:"button",onClick:()=>a("edit"),className:`flex-1 px-4 py-2 text-sm font-medium ${o==="edit"?"border-b-2 border-blue-600 bg-white dark:bg-gray-900 text-blue-600 dark:text-blue-400":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100"}`,children:"Edit"}),E.jsx("button",{type:"button",onClick:()=>a("preview"),className:`flex-1 px-4 py-2 text-sm font-medium ${o==="preview"?"border-b-2 border-blue-600 bg-white dark:bg-gray-900 text-blue-600 dark:text-blue-400":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100"}`,children:"Preview"})]}),E.jsx("div",{style:{minHeight:s},children:o==="edit"?E.jsx("textarea",{value:e,onChange:l=>t(l.target.value),placeholder:n,className:"h-full w-full resize-none border-0 p-4 font-mono text-sm bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring-0",style:{minHeight:s}}):E.jsx("div",{className:"prose dark:prose-invert max-w-none p-4 text-gray-900 dark:text-gray-100",children:e?E.jsx(ch,{remarkPlugins:[qh],rehypePlugins:[_p],children:e}):E.jsx("div",{className:"text-gray-400 dark:text-gray-500",children:"Nothing to preview"})})})]}),i&&E.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:i}),E.jsxs("div",{className:"rounded-md bg-gray-50 dark:bg-gray-800 p-3 text-xs text-gray-600 dark:text-gray-400",children:[E.jsx("p",{className:"font-medium",children:"Markdown Syntax Help:"}),E.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-2",children:[E.jsxs("div",{children:[E.jsx("strong",{children:"# Heading 1"})," - Main heading"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"## Heading 2"})," - Subheading"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"**bold text**"})," - Bold"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"*italic text*"})," - Italic"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"[link](url)"})," - Link"]}),E.jsxs("div",{children:[E.jsx("strong",{children:""})," - Image"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"- item"})," - Bullet list"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"1. item"})," - Numbered list"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"`code`"})," - Inline code"]}),E.jsxs("div",{children:[E.jsx("strong",{children:"```language```"})," - Code block"]})]})]})]})}/**
|
|
172
172
|
* @license lucide-react v0.462.0 - ISC
|
|
173
173
|
*
|
|
174
174
|
* This source code is licensed under the ISC license.
|