diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bdf950..4492dba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to Tolk are documented in this file. ## Unreleased +### Changed + +- **Translate from origin** is a button in the field's header (the book icon) instead of an item in the field's actions menu, so one field takes one click. It asks first only when the field holds text of its own: an empty field, or one that still shows the origin's text, is translated at once. While a translation runs, the buttons are disabled instead of hidden. + ## 1.0.0 - 2026-10-15 ### Added diff --git a/README.md b/README.md index 81464dd..f613cdd 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Tolk translates multi-site Statamic content from an origin site into its localizations with large language models from Anthropic, OpenAI or Google Gemini. It works in the entry editor, where translations are filled into the open form for the editor to review and save, on single fields, in bulk from listings and from the command line. It tracks which translations are outdated or edited by hand, so it updates only what has changed. - **In the editor**: create a localization and Tolk offers to translate it; Translate and Update fill the form, unsaved, field by field. Bard, Replicator, Grid, Markdown and tables keep their structure, formatting and links. -- **One field at a time**: "Translate from origin" in a field's actions. +- **One field at a time**: the "Translate from origin" button in a field's header. - **In bulk**: a listing action, an Overview of every collection, taxonomy, global set and navigation by language, and runs with an estimate before they start, progress, cancel and resume. No queue or database needed. - **From the command line**: translate collections, or the whole website into a new language in one command, plus the app's `lang/` files and the texts of forms. - **Updates, not retranslations**: when the origin changes, only the changed paragraphs are sent again. Text a human edited is never overwritten unless you ask. Optionally, saving an entry updates its translations by itself. diff --git a/TASKS.md b/TASKS.md index faebbbc..e6e50ca 100644 --- a/TASKS.md +++ b/TASKS.md @@ -519,7 +519,7 @@ A **run** is a bulk job: `{ id (ULID), status, driver, created_by, created_at, s ### §A13 CP surfaces 1. **Entry and term publish forms**: a banner component pushed above the tabs with `pushComponent` (R3 §2.4). On a localization it shows field status counts and Translate / Update / Review; on an origin it shows the status of each localization and Translate into… / Update. It also opens the offer after `localization.created`. -2. **Field actions**: "Translate from origin" on top-level fields of supported fieldtypes, inside localizations, in the base form only. +2. **Field actions**: "Translate from origin", a button in the header of top-level fields of supported fieldtypes, inside localizations, in the base form only; it asks first only before it replaces text of the localization's own (T11.7). 3. **Bulk action** "Translate…" in entry and term listings and in a structured collection's tree view, which creates a pending run and redirects to its page. 4. **Run page**: item counts, a progressively computed estimate, a Start button, then progress, usage, per-item results (with the reviewer's corrections), cancel, resume and retry. 5. **Overview and Audit pages** (Inertia): the status matrix by content type, container and site, with buttons that create runs (global sets and navs are translated from here); blueprint and setup checks. @@ -1836,6 +1836,7 @@ Goal: many targets at once, with progress, from the CP and the CLI, on a site wi - Built in T5.9: on a localization created in the form, `translations.translate()` first puts the origin's slug back (the store's `created` and `slugKept`), so translating the title through the action does not change the slug either. - Built in T7.5: `translations.translate()` also takes `review` and `reviewer`; left null, the field action reviews when `review_enabled` is on, as the banner's buttons do. Its summary then has the `reviewed` line and the corrections for View changes. - Built (planner's details): `createFieldActions()` in `editor/fieldActions.js` (`register()` once, `action`, `visible`, `run`; the shared `fieldActions` is registered in `cp.js`). `visible` also needs the store entry of `base` to belong to the open item (`container.reference === ctx.reference.value`: the CP keeps the store across Inertia visits, and a global set's form is also named `base`), a model (`!needsSetup(status)`), the handle in the status's `localization.fields` with a status other than `not_applicable`, and a phase outside `BUSY`: the dropdown ignores `disabled`, so the action hides while a translation runs. The value check compares deeply without regard to key order. `translations.translate()` gained `replace`: the requested fields are kept out of `skip`, because a field the editor typed into would otherwise be skipped as `edited_in_form`, against the confirmation's text; Retry keeps it. After the translation a toast reports the error the phase ended with, or a field that was not filled (`describeSummary()`'s failed, edited or "No fields were translated." line), but nothing after Cancel or a switch. While core saves the form (`translations.saving('base')`) it only says so, before calling `translate()`, whose refusal would leave an earlier error phase to be reported. The banner's working line names the field of a one-field translation ("Translating :field into :site…", `data-tolk-working-field`). + - Changed in T11.7 (owner, 2026-10-20): the action is a quick button in the field's header, disabled rather than hidden while a translation runs, and it asks first only when the field holds text that is not the origin's. - **Self-check:** `tests/Browser/field-action.spec.js`: the action shows on a localizable text, a Bard and a Replicator field of a localization; it does not show on the origin, on nested fields or on non-localizable fields; running it replaces only that field and leaves the form unsaved; with a related entry open in a stack, the action is absent on the stacked form's fields. - [x] **T8.13 Origin view: translate into other languages and update all translations** @@ -2164,6 +2165,14 @@ In T0.1 (2026-10-02) the owner asked for none of these for v1 (D29). Each task i - Not built, discussed with the owner: a catalog feed published by Reach (fetched and cached, with `resources/models.php` as the fallback), so that Automatic follows new models without a release, and the providers' model lists for availability and retirement notices. - **Self-check:** `ModelCatalogTest` (the merge by id, the defaults, a changed tier), `ConfigTest` (the empty `models` lists and the pin of `resources/models.php`) and `DocsCoverageTest` (entry keys read from `resources/models.php`) pass, and so does the whole suite. +- [x] **T11.7 Translate from origin as a button in the field's header** (owner, 2026-10-20) + - T8.12's action sits in the field's dots menu and always asks first, so translating one field takes three clicks, even on a field with nothing to lose. It becomes a quick action (`quick: true`): an icon button in the field's header, `dictionary-language-book` like the addon's other surfaces, with the title as its tooltip and `aria-label` (core's `FieldActions.vue` at v6.35.0). Core lists an addon's actions before the fieldtype's own, so it comes first among the header's buttons. + - It asks first only when the translation could lose text: the form's value of the field has text (`textsOf()`) and that text is not the origin's (`sameText()` with the base context's `originValues`). A field that is empty (an empty Bard paragraph included) or that shows the origin's text (an untranslated field inherits it, and so does a copy saved over a translation) is translated at once. Otherwise the confirmation of T8.12 stays as it is. + - Quick actions honour `disabled`, unlike the dropdown's items, so while a translation is under way (`BUSY`) the button stays in place, disabled, instead of the action hiding. T8.12's other visibility rules stay. + - Focus: Cancel and Esc give the focus back to the button (the field header's button whose `aria-label` is the title). The browser drops the focus of a control that becomes disabled, so once a translation starts, with or without the confirmation, a lost focus moves into the banner as after Translate in T8.12. + - Docs: `docs/editor.md` ("Translating one field"), README's feature line, `docs/marketplace-listing.md`, `CHANGELOG.md` (Unreleased); the docs site's editor page and introduction (`/Volumes/1TB/Sites/tolk-docs`). + - **Self-check:** `resources/js/editor/fieldActions.test.js`: quick with the icon; disabled, not hidden, while busy, and re-evaluated by a computed; translates at once on an empty field, an empty Bard value and the origin's text; asks first on text of the localization's own and on text typed into an untranslated field; Cancel gives the focus back to the button, and a direct translation moves a lost focus into the banner. `tests/Browser/field-action.spec.js`: the action is a button in the header of the same fields as before and of none of the others; on a typed title it asks first, the buttons are disabled while the translation runs, and on the untranslated Bard field it translates without a dialog. `npm run cp:build` committed. + ## Phase 12 — Hardening - [x] **T12.1 Processes and locks under real concurrency** @@ -2556,3 +2565,4 @@ Owner decision 2026-10-14 (D28 amended, reproduced by failing tests first): a fi Owner decision 2026-10-14 (reproduced by failing tests first): a run went on through every item while the provider rejected each request (`request_rejected`, a 400 that is not about the key or the account, such as a model option it refuses), so a setting it did not accept cost a whole run of failed items and the reviewer's rejections left every item unreviewed. `UnitOutcome::$rejected` keeps the provider's sanitised message (`Pipeline::call()` and `review()`), and `RunProcessor` counts such units in a row per kind, translation or review (`tolk:run-rejected:{id}:{kind}`, cleared by an answered unit of that kind and by `start()`); at `MAX_REJECTED_UNITS` (3) it forgets the item's plan, so a resume plans it again, and aborts the run with the message and "The run stopped after 3 requests in a row were rejected." §A10's 4xx row, §A12 "Waiting" and T8.4 amended; `docs/bulk-and-runs.md`, `docs/troubleshooting.md` ("Rejected requests") and the changelog. Tests: `RunTranslateTest` +3 (three rejected translations abort with the message and the last item replanned on resume; three rejected reviews between answered translations abort; rejections not in a row do not, a guard that passed before; the two aborts failed before). Owner decision 2026-10-14 (D5 kept, reproduced by failing tests first): a copy of the origin's text saved over a field Tolk translated (a form that still held it, saved after a run or an automatic update translated the field, or an inherited Bard field set back to inherit that rewrote itself) read manual with an unchanged source, so its item read up to date while the field was in the source language, and nothing pointed to it. `StatusResolver` now flags such a field `FieldStatusInfo::$sameAsOrigin` (manual, a machine record, `T == C` with text; `C` is walked only for those fields), which `needsAttention()` counts, so the item reads **attention** on the Overview, in `tolk:status` and in the origin's list; Translate and Update still leave it alone (D5). `editor/status` sends `same_as_origin` per field, and the banner names the fields ("Title holds the text of the origin again. Translate it, or mark it as up to date to keep it.") with **Translate it** / **Translate them** (`translations.translate()` with `mode: all`, those fields and `overwriteManual`, so a field typed into is still skipped and Undo restores the copy); "Mark manual fields as up to date" writes a baseline, which is no machine record, and clears the flag. §A6 rule 3 and the item status amended; `docs/statuses.md` ("Needs attention", item statuses, "A copy saved over a translation"), `docs/troubleshooting.md`, `docs/editor.md`, `docs/cli.md` (`tolk:baseline`) and the changelog. Tests: `StatusResolverTest` +1 (failed before), `EditorStatusTest` +1 (the payload key; failed before), the pinning test in `TargetTranslatorTest` now expects attention, `statuses.test.js` +1, `EditorBanner.test.js` +2. Owner decision 2026-10-15: the repository is public, so `docs/research/` was removed from every commit with `git filter-repo` before tagging 1.0.0 and is git-ignored; the reports stay in the owner's working copy. The commits of pull requests #1 and #2 still hold it on GitHub until GitHub Support removes them. +T11.7 done 2026-10-20: at the owner's request, "Translate from origin" is a quick action, a `dictionary-language-book` icon button in the field's header with the title as tooltip and `aria-label`, disabled instead of hidden while a translation runs (`disabled()`, `BUSY`); `run` asks first only when the form's value has text that is not the origin's (`replacesText()`: `textsOf()` and `sameText()` with `originValues`) and otherwise translates at once (`start()`); Cancel and Esc give the focus back to the header's button with that `aria-label`, and a focus the disabled button lost moves into the banner. Tests: `fieldActions.test.js` 34 (5 new, 4 changed: quick with the icon; disabled, not hidden, in each phase and through a computed; enabled without a base form; at once on '', null, an empty Bard paragraph and the origin's text; asks on the localization's own and on typed text; asks without a base form and reports it; the focus into the banner after a direct translation, back to the button on Cancel), 9 mutations each fail a test; `tests/Browser/field-action.spec.js` (3: the button in the same headers as before and in none of the others, typed title with the confirmation, both buttons disabled during the translation, the untranslated Bard field without a dialog, the focus in the banner after it). Docs: `docs/editor.md`, README, `docs/marketplace-listing.md`, `CHANGELOG.md`; the docs site's editor page, introduction and `field-action` screenshots. Vitest 772 passed, Pest 4,008 passed, Pint clean, `npm run cp:build` committed; browser 69 passed, 4 skipped, 2 failed in `editor-push.spec.js`: "Update translations changes only the edited paragraph" (a Bard image stored wrapped in a paragraph) fails on 1.0.0 too whenever the spec runs after `editor-options.spec.js` and passes alone, and "Translate into…" (the button not disabled after typing) failed only in the full run and passed in four reruns; neither is caused by this task, both left open. Sandbox restored. diff --git a/docs/editor.md b/docs/editor.md index 32b0287..c26fa34 100644 --- a/docs/editor.md +++ b/docs/editor.md @@ -89,12 +89,11 @@ The **Offer to translate new localizations** switch turns the offer on or off fo ## Translating one field -Every top-level field Tolk can translate has **Translate from origin** in its field actions (the menu next to its label), in a localization: +In a localization, every top-level field Tolk can translate has a **Translate from origin** button in its header, at the right: the book icon, whose tooltip names it. Press it, and the field is translated again from the origin, whatever its status, edited by hand included, and filled into the form unsaved. The rest of the form is left alone. It sends the same context as the banner's buttons (the site profile, the instructions, the language's instructions, the glossary, and the entry's title and summary) and follows the review setting. -1. Open the field's actions and choose **Translate from origin**. -2. Confirm: "The current content of this field will be replaced." +When the field holds text of its own, Tolk asks first: "The current content of this field will be replaced." A field that is empty, or that still shows the origin's text, such as a field not translated yet, is translated at once, since nothing is lost. Either way, **Undo** in the banner puts the field back until you save. -The field is translated again from the origin, whatever its status, edited by hand included, and filled into the form unsaved. The rest of the form is left alone. +While a translation runs, the buttons are disabled. The action is not offered on nested fields (inside a Replicator, Grid or Bard set), on fields that are not localizable, in the origin, or while another entry is open in a stack. diff --git a/docs/marketplace-listing.md b/docs/marketplace-listing.md index 3256a0d..77979b2 100644 --- a/docs/marketplace-listing.md +++ b/docs/marketplace-listing.md @@ -14,7 +14,7 @@ Translate multi-site content into every language with Claude, GPT or Gemini: in Tolk translates multi-site Statamic content from an origin site into its localizations with large language models from Anthropic, OpenAI or Google Gemini, using your own API keys. -In the entry editor, Tolk offers to translate a new localization and fills the translations into the open form, unsaved, so an editor reads them and presses Save. One field at a time, "Translate from origin" sits in the field's actions. In bulk, a listing action and an Overview of every collection, taxonomy, global set and navigation start runs with a cost estimate, progress, cancel and resume, and the run keeps going in the browser when there is no queue. From the command line, one command translates a whole website into a new language, and two more translate the app's `lang/` files and the texts of forms. +In the entry editor, Tolk offers to translate a new localization and fills the translations into the open form, unsaved, so an editor reads them and presses Save. One field at a time, a "Translate from origin" button sits in each field's header. In bulk, a listing action and an Overview of every collection, taxonomy, global set and navigation start runs with a cost estimate, progress, cancel and resume, and the run keeps going in the browser when there is no queue. From the command line, one command translates a whole website into a new language, and two more translate the app's `lang/` files and the texts of forms. Tolk tracks, per field, whether a translation is outdated or was edited by hand. An Update sends only the paragraphs that changed and never overwrites text a human wrote unless you ask. A site profile, instructions, per-language formality and a glossary go with every request, and an optional second model reviews each translation and applies its corrections with reasons. New localizations are saved as drafts by default. diff --git a/resources/dist/build/assets/cp-7pjkSVYi.js b/resources/dist/build/assets/cp-CtqImns9.js similarity index 66% rename from resources/dist/build/assets/cp-7pjkSVYi.js rename to resources/dist/build/assets/cp-CtqImns9.js index 34040b5..27de1d7 100644 --- a/resources/dist/build/assets/cp-7pjkSVYi.js +++ b/resources/dist/build/assets/cp-CtqImns9.js @@ -1,2 +1,2 @@ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},{AfterSaveHooks:n,BeforeSaveHooks:r,Pipeline:i,PipelineStopped:a,Request:o}=__STATAMIC__.savePipeline,{BaseTransition:s,BaseTransitionPropsValidators:c,Comment:l,DeprecationTypes:u,EffectScope:d,ErrorCodes:f,ErrorTypeStrings:p,Fragment:m,KeepAlive:h,ReactiveEffect:g,Static:_,Suspense:v,Teleport:y,Text:b,TrackOpTypes:x,Transition:S,TransitionGroup:C,TriggerOpTypes:w,VueElement:ee,__esModule:T,assertNumber:E,callWithAsyncErrorHandling:te,callWithErrorHandling:D,camelize:ne,capitalize:re,cloneVNode:ie,compatUtils:ae,compile:oe,computed:O,createApp:se,createBlock:k,createCommentVNode:A,createElementBlock:j,createElementVNode:M,createHydrationRenderer:ce,createPropsRestProxy:le,createRenderer:ue,createSSRApp:de,createSlots:fe,createStaticVNode:pe,createTextVNode:N,createVNode:P,customRef:me,defineAsyncComponent:he,defineComponent:ge,defineCustomElement:_e,defineEmits:ve,defineExpose:ye,defineModel:be,defineOptions:xe,defineProps:Se,defineSSRCustomElement:Ce,defineSlots:we,devtools:Te,effect:Ee,effectScope:De,getCurrentInstance:Oe,getCurrentScope:ke,getCurrentWatcher:Ae,getTransitionRawChildren:je,guardReactiveProps:Me,h:Ne,handleError:Pe,hasInjectionContext:Fe,hydrate:Ie,hydrateOnIdle:Le,hydrateOnInteraction:Re,hydrateOnMediaQuery:ze,hydrateOnVisible:Be,initCustomFormatter:Ve,initDirectivesForSSR:He,inject:Ue,isMemoSame:We,isProxy:Ge,isReactive:Ke,isReadonly:qe,isRef:Je,isRuntimeOnly:Ye,isShallow:Xe,isVNode:Ze,markRaw:Qe,mergeDefaults:$e,mergeModels:et,mergeProps:tt,nextTick:nt,nodeOps:rt,normalizeClass:it,normalizeProps:at,normalizeStyle:ot,onActivated:st,onBeforeMount:ct,onBeforeUnmount:lt,onBeforeUpdate:ut,onDeactivated:dt,onErrorCaptured:ft,onMounted:pt,onRenderTracked:mt,onRenderTriggered:ht,onScopeDispose:gt,onServerPrefetch:_t,onUnmounted:vt,onUpdated:yt,onWatcherCleanup:bt,openBlock:F,patchProp:xt,popScopeId:St,provide:Ct,proxyRefs:wt,pushScopeId:Tt,queuePostFlushCb:Et,reactive:Dt,readonly:Ot,ref:I,registerRuntimeCompiler:kt,render:At,renderList:L,renderSlot:jt,resolveComponent:Mt,resolveDirective:Nt,resolveDynamicComponent:Pt,resolveFilter:Ft,resolveTransitionHooks:It,setBlockTracking:Lt,setDevtoolsHook:Rt,setTransitionHooks:zt,shallowReactive:Bt,shallowReadonly:Vt,shallowRef:Ht,ssrContextKey:Ut,ssrUtils:Wt,stop:Gt,toDisplayString:R,toHandlerKey:Kt,toHandlers:qt,toRaw:Jt,toRef:Yt,toRefs:Xt,toValue:Zt,transformVNodeArgs:Qt,triggerRef:$t,unref:z,useAttrs:en,useCssModule:tn,useCssVars:nn,useHost:rn,useId:an,useModel:on,useSSRContext:sn,useShadowRoot:cn,useSlots:ln,useTemplateRef:un,useTransitionState:dn,vModelCheckbox:fn,vModelDynamic:pn,vModelRadio:mn,vModelSelect:hn,vModelText:gn,vShow:_n,version:vn,warn:yn,watch:bn,watchEffect:xn,watchPostEffect:Sn,watchSyncEffect:Cn,withAsyncContext:wn,withCtx:B,withDefaults:Tn,withDirectives:En,withKeys:Dn,withMemo:On,withModifiers:kn,withScopeId:An}=window.Vue,{Alert:jn,AuthCard:Mn,Avatar:Nn,Badge:Pn,Button:V,ButtonGroup:Fn,Calendar:In,Card:H,CardList:Ln,CardListItem:Rn,CardPanel:zn,CharacterCounter:Bn,Checkbox:Vn,CheckboxGroup:Hn,CodeEditor:Un,Combobox:Wn,CommandPaletteItem:Gn,ConfirmationModal:Kn,ContentDirection:qn,useContentDirection:Jn,useUiDirection:Yn,Context:Xn,ContextFooter:Zn,ContextHeader:Qn,ContextItem:$n,ContextLabel:er,ContextMenu:tr,ContextSeparator:nr,CreateForm:rr,DatePicker:ir,DateRangePicker:ar,Description:U,DocsCallout:or,DragHandle:sr,Dropdown:cr,DropdownItem:lr,DropdownLabel:ur,DropdownMenu:dr,DropdownSeparator:fr,DropdownFooter:pr,DropdownHeader:mr,Editable:hr,ErrorMessage:gr,EmptyStateItem:_r,EmptyStateMenu:vr,Field:yr,Header:br,Heading:W,HoverCard:xr,Icon:Sr,Input:Cr,InputGroup:wr,InputGroupAppend:Tr,InputGroupPrepend:Er,Label:Dr,Listing:Or,ListingCustomizeColumns:kr,ListingFilters:Ar,ListingHeaderCell:jr,ListingPagination:Mr,ListingPresets:Nr,ListingPresetTrigger:Pr,ListingRowActions:Fr,ListingSearch:Ir,ListingTable:Lr,ListingTableBody:Rr,ListingTableHead:zr,ListingToggleAll:Br,LivePreview:Vr,LivePreviewPopout:Hr,MiddleEllipsis:Ur,Modal:Wr,ModalClose:Gr,ModalTitle:Kr,Pagination:qr,Panel:Jr,PanelFooter:Yr,PanelHeader:Xr,Popover:Zr,PublishComponents:Qr,PublishContainer:$r,publishContextKey:ei,injectPublishContext:ti,PublishField:ni,PublishFields:ri,PublishFieldsProvider:ii,PublishForm:ai,PublishLocalizations:oi,PublishSections:si,PublishTabs:ci,Radio:li,RadioGroup:ui,Select:di,Separator:fi,Slider:pi,Skeleton:mi,SplitterGroup:hi,SplitterPanel:gi,SplitterResizeHandle:_i,StatusIndicator:vi,Subheading:yi,Switch:bi,TabContent:xi,Stack:Si,StackClose:Ci,StackHeader:wi,StackFooter:Ti,StackContent:Ei,Table:Di,TableCell:G,TableColumn:K,TableColumns:Oi,TableRow:ki,TableRows:Ai,TabList:ji,TabProvider:Mi,Tabs:Ni,TabTrigger:Pi,Text:q,Textarea:Fi,TimePicker:Ii,TimezoneHoverCard:Li,Timezones:Ri,ToggleGroup:zi,ToggleItem:Bi,Widget:Vi,registerIconSet:Hi,registerIconSetFromStrings:Ui}=__STATAMIC__.ui,Wi=/(<\/?\d+>|||\s+)/,Gi=/^(?:<\/?\d+>||)$/,Ki=/^\s+$/;function qi(e){return String(e??``).split(Wi).filter(e=>e!==``).map(e=>({text:e,kind:Ki.test(e)?`space`:Gi.test(e)?`placeholder`:`word`}))}function Ji(e,t){let n=new Set,r=new Set;if(e.length*t.length>25e4)return[n,r];let i=t.length+1,a=new Uint32Array((e.length+1)*i);for(let n=e.length-1;n>=0;n--)for(let r=t.length-1;r>=0;r--)a[n*i+r]=e[n]===t[r]?a[(n+1)*i+r+1]+1:Math.max(a[(n+1)*i+r],a[n*i+r+1]);for(let o=0,s=0;o=a[o*i+s+1]?o++:s++;return[n,r]}function Yi(e,t){let n=0,r=e.map(e=>({...e,changed:e.kind!==`space`&&!t.has(n++)}));return r.forEach((e,t)=>{e.kind===`space`&&(e.changed=!!(r[t-1]?.changed&&r[t+1]?.changed))}),r}function Xi(e,t){let n=qi(e),r=qi(t),i=e=>e.filter(e=>e.kind!==`space`).map(e=>e.text),[a,o]=Ji(i(n),i(r));return{before:Yi(n,a),after:Yi(r,o)}}var J=t({ApiError:()=>Zi,asMap:()=>Y,get:()=>Qi,normalizeError:()=>na,post:()=>$i}),Zi=class extends Error{constructor({status:e,code:t,message:n,data:r}){super(n),this.name=`ApiError`,this.status=e,this.code=t,this.data=r}};function Y(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Qi(e,t={}){return ta(`get`,e,{params:t})}function $i(e,t={}){return ta(`post`,e,t)}function ea(){return Statamic.$app.config.globalProperties.$axios}async function ta(e,t,n){let r=ea(),i=/^https?:\/\//i.test(t)?t:cp_url(`tolk/${t.replace(/^\/+/,``)}`);try{return(await r[e](i,n)).data}catch(e){throw na(e)}}function na(e){let t=e?.response,n=t?.data!==null&&typeof t?.data==`object`?t.data:null,r=t?.status??0;return new Zi({status:r,code:typeof n?.code==`string`?n.code:null,message:typeof n?.message==`string`&&n.message!==``?n.message:ra(r),data:n})}function ra(e){return e===0?__(`The server could not be reached.`):__(`The request failed with status :status.`,{status:e})}var ia={untranslated:{text:e=>__n(`:count field untranslated|:count fields untranslated`,e),description:()=>__(`Not translated yet. Translate fills them in.`)},outdated:{text:e=>__n(`:count field outdated|:count fields outdated`,e),description:()=>__(`The source changed since they were translated, or part of their text is still untranslated. Update translates them again.`)},manual:{text:e=>__n(`:count field edited by hand|:count fields edited by hand`,e),description:()=>__(`Edited by hand. Translate and Update leave them alone.`)},attention:{text:e=>__n(`:count needs attention|:count need attention`,e),description:()=>__(`Edited by hand, and the source changed since or they hold its text again. Check them against the source.`)},untracked:{text:e=>__n(`:count untracked|:count untracked`,e),description:()=>__(`Edited by hand before their translation was tracked, so a change to the source cannot be detected. Mark them as up to date to track them.`)},current:{text:e=>__n(`:count field up to date|:count fields up to date`,e),description:()=>__(`Translated and up to date with the source.`)}},aa={missing:`red`,untranslated:`orange`,outdated:`amber`,attention:`purple`,manual:`sky`,untracked:`default`,current:`green`};function oa(e){return aa[e]??`default`}function sa(e){return{missing:__(`Missing`),untranslated:__(`Untranslated`),outdated:__(`Outdated`),attention:__(`Needs attention`),current:__(`Up to date`)}[e]??e}function ca(e={}){return Object.entries(ia).filter(([t])=>(e[t]??0)>0).map(([t,n])=>({key:t,count:e[t],text:n.text(e[t]),description:n.description()}))}function la(e){let t=e?.defaults??{};return!(t.providers_configured||t.fake_engine)||!t.translator}function ua(e){if(e?.translatable!==!0)return{visible:!1,reason:e?.reason??null,setup:!1,translator:null,localization:null,origin:null};let t=la(e);return{visible:!0,reason:null,setup:t,translator:e.defaults?.translator??null,localization:e.localization?da(e.localization,t):null,origin:e.origin?va(e.origin,t):null}}function da(e,t){let n=e.counts??{},r=ca(n),i=Object.entries(e.fields??{}),a=i.filter(([,e])=>e.incomplete).map(([e,t])=>({handle:e,label:t.label})),o=i.filter(([,e])=>e.same_as_origin).map(([e,t])=>({handle:e,label:t.label})),s=(e.out_of_scope??[]).filter(e=>e.reason===`not_localizable`).map(({handle:e,label:t})=>({handle:e,label:t})),c=pa(e,r);return{source:e.source,target:e.target,status:e.status,label:sa(e.status),parts:r,summary:c,lead:r.length>0?__(`From :source:`,{source:e.source?.name??``}):c,incomplete:a,incompleteNote:a.length?ma(a):null,copies:o,copiesNote:o.length?ha(o):null,translateCopies:!t&&o.length>0,translateCopiesLabel:__n(`Translate it|Translate them`,o.length),notLocalizable:s,hint:s.length?ga(_a(s),s.length):null,translate:!t&&(n.untranslated??0)>0,update:!t&&(n.outdated??0)>0,autoUpdated:fa(e.auto_updated,e.source)}}function fa(e,t){let n=Date.parse(e?.at??``);if(Number.isNaN(n))return null;let r={source:t?.name??``,date:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(n)};return e.unpublished?__(`Updated automatically from :source on :date, not published yet.`,r):__(`Updated automatically from :source on :date.`,r)}function pa(e,t){let n=e.source?.name??``;return t.length===0?__(`Nothing to translate from :source.`,{source:n}):t.every(e=>e.key===`current`)?__(`Up to date with :source.`,{source:n}):__(`From :source: :parts.`,{source:n,parts:t.map(e=>e.text).join(`, `)})}function ma(e){return __n(`:fields is partly untranslated. Update translates the rest.|:fields are partly untranslated. Update translates the rest.`,e.length,{fields:_a(e)})}function ha(e){return __n(`:fields holds the text of the origin again. Translate it, or mark it as up to date to keep it.|:fields hold the text of the origin again. Translate them, or mark them as up to date to keep them.`,e.length,{fields:_a(e)})}function ga(e,t){return __n(`:fields is not translated because it is not localizable.|:fields are not translated because they are not localizable.`,t,{fields:e})}function _a(e){return e.map(e=>e.label).join(`, `)}function va(e,t){let n=(e.localizations??[]).map(e=>{let t=!e.exists,n=e.counts??{},r=t?[]:ca(n),i=typeof e.error==`string`&&e.error!==``;return{site:e.site,name:e.name,exists:e.exists,status:e.status,label:i?__(`Unreadable`):sa(e.status),color:i?`red`:oa(e.status),parts:r,summary:i?e.error:ya(e,r),editUrl:e.edit_url??null,translate:!i&&(t||(n.untranslated??0)>0),update:!i&&!t&&(n.outdated??0)>0}});return{localizations:n,upToDate:n.length>0&&n.every(e=>e.status===`current`),translateInto:!t&&n.some(e=>e.translate),update:!t&&n.some(e=>e.update),translatesPublished:e.translates_published===!0,unpublishedChanges:e.unpublished_changes===!0,autoUpdate:{save:__(`Translations are updated automatically each time this entry is saved.`),publish:__(`Translations are updated automatically when this entry is published.`)}[e.auto_update]??null}}function ya(e,t){return e.exists?t.length===0?__(`Nothing to translate.`):t.every(e=>e.key===`current`)?null:t.map(e=>e.text).join(`, `):__(`Not created yet.`)}function ba(e,t=globalThis.Statamic?.$config?.get(`tolk.models`)){if(typeof t?.[e]==`string`)return t[e];let n=e.indexOf(`:`);return n===-1?e:e.slice(n+1)}function xa(e,t){let n=Y(t?.localization?.fields);return e.map(e=>n[e]?.label??e).join(`, `)}function Sa(e,t=null,{retry:n=!1}={}){if(!e)return null;let r=e.kind===`review`,i=e.delivered.length,a=e.corrections?.length??0,o=Object.keys(e.skipped).filter(t=>e.skipped[t]===`edited`),s=Object.keys(e.skipped).filter(t=>e.skipped[t]===`hidden`),c=Object.keys(e.planSkipped??{}).filter(t=>e.planSkipped[t]===`manual`),l=Object.keys(e.failed);return{translated:r?null:wa(i,Ca(e)),reviewed:Ta(e,a),corrections:a,reviewSkipped:e.reviewSkipped?.length?__(`Part of the text could not be reviewed and was kept as it was.`):null,incomplete:e.incomplete.length?__n(`:fields is partly untranslated. Update translates the rest after you save.|:fields are partly untranslated. Update translates the rest after you save.`,e.incomplete.length,{fields:xa(e.incomplete,t)}):null,edited:o.length?__n(`:fields was skipped because you edited it.|:fields were skipped because you edited them.`,o.length,{fields:xa(o,t)}):null,hidden:s.length?Da(s,r,t):null,manual:c.length?Oa(c,r,t):null,failed:l.length?Ea(l,r,n,t):null,cancelled:e.cancelled?r?__(`The review was cancelled before it finished.`):__(`The translation was cancelled before it finished.`):null,unsaved:i>0?__(`Not saved yet. Check the fields, then save.`):null}}function Ca(e){let t=e.models.filter(t=>t!==e.reviewer);return(t.length?t:e.models).map(e=>ba(e)).join(`, `)}function wa(e,t){return e===0?__(`No fields were translated.`):t?__n(`:count field translated with :model.|:count fields translated with :model.`,e,{model:t}):__n(`:count field translated.|:count fields translated.`,e)}function Ta(e,t){if(e.kind===`review`&&(e.planned??[]).length===0)return __(`There was nothing to review: no field holds a translation that is up to date.`);if(!e.reviewer||!e.reviewedUnits?.length)return null;let n=ba(e.reviewer);return t>0?__n(`Reviewed with :model: :count correction.|Reviewed with :model: :count corrections.`,t,{model:n}):__(`Reviewed with :model: nothing to correct.`,{model:n})}function Ea(e,t,n,r){let i=xa(e,r);return n?t?__n(`:fields could not be reviewed. Retry reviews it again.|:fields could not be reviewed. Retry reviews them again.`,e.length,{fields:i}):__n(`:fields could not be translated. Retry translates it again.|:fields could not be translated. Retry translates them again.`,e.length,{fields:i}):t?__n(`:fields could not be reviewed.|:fields could not be reviewed.`,e.length,{fields:i}):__n(`:fields could not be translated.|:fields could not be translated.`,e.length,{fields:i})}function Da(e,t,n){let r=xa(e,n);return t?__n(`:fields was not reviewed because it is hidden. Show it and review again.|:fields were not reviewed because they are hidden. Show them and review again.`,e.length,{fields:r}):__n(`:fields was skipped because it is hidden. Show it and translate again.|:fields were skipped because they are hidden. Show them and translate again.`,e.length,{fields:r})}function Oa(e,t,n){let r=xa(e,n);return t?__n(`:fields was not reviewed because it was edited by hand. Overwrite manual edits in the options reviews it too.|:fields were not reviewed because they were edited by hand. Overwrite manual edits in the options reviews them too.`,e.length,{fields:r}):__n(`:fields was skipped because it was edited by hand. Overwrite manual edits in the options replaces it.|:fields were skipped because they were edited by hand. Overwrite manual edits in the options replaces them.`,e.length,{fields:r})}var ka={class:`space-y-6`},Aa={class:`space-y-2 text-sm`},ja={class:`text-xs font-medium text-gray-500 dark:text-gray-400`},Ma={class:`whitespace-pre-wrap`,"data-tolk-change-before":``},Na={class:`text-xs font-medium text-gray-500 dark:text-gray-400`},Pa={class:`whitespace-pre-wrap`,"data-tolk-change-after":``},Fa={class:`text-xs font-medium text-gray-500 dark:text-gray-400`},Ia={class:`whitespace-pre-wrap`,"data-tolk-change-reason":``},La={class:`flex items-center justify-end gap-3 pt-3 pb-1`},Ra={__name:`ChangesModal`,props:{modal:{type:Object,required:!0},corrections:{type:Array,default:()=>[]},reviewer:{type:String,default:null}},setup(e){let t=e,n=O(()=>t.corrections.map(e=>({...e,key:`${e.handle}:${e.id}`,diff:Xi(e.before,e.after)})));function r(e,t){return e.kind===`placeholder`?[`font-mono text-xs text-gray-500 dark:text-gray-400`,e.changed&&`rounded-sm bg-amber-100 dark:bg-amber-900/40!`]:e.changed?t===`before`?`rounded-sm bg-red-100 text-red-900 line-through dark:bg-red-900/40! dark:text-red-100`:`rounded-sm bg-green-100 text-green-900 underline decoration-green-700/60 dark:bg-green-900/40! dark:text-green-100 dark:decoration-green-300/60`:null}return(t,i)=>(F(),k(z(Wr),{open:``,title:t.__(`Changes by the reviewer`),icon:`dictionary-language-book`,"data-tolk-changes":``,onDismissed:i[1]||=t=>e.modal.dismissed(),"onUpdate:open":i[2]||=t=>e.modal.closed(t)},{footer:B(()=>[M(`div`,La,[P(z(V),{variant:`primary`,text:t.__(`Close`),"data-tolk-changes-action":`close`,onClick:i[0]||=t=>e.modal.hide()},null,8,[`text`])])]),default:B(()=>[M(`div`,ka,[e.reviewer?(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.__(`Corrected by :model. The corrections are in the form; nothing is saved until you press Save.`,{model:z(ba)(e.reviewer)})),1)]),_:1})):A(``,!0),(F(!0),j(m,null,L(n.value,e=>(F(),j(`div`,{key:e.key,class:`space-y-2`,"data-tolk-change":``},[P(z(W),{"data-tolk-change-label":``},{default:B(()=>[N(R(e.label),1)]),_:2},1024),M(`dl`,Aa,[M(`div`,null,[M(`dt`,ja,R(t.__(`Before`)),1),M(`dd`,Ma,[(F(!0),j(m,null,L(e.diff.before,(e,t)=>(F(),k(Pt(e.changed?`del`:`span`),{key:t,class:it(r(e,`before`)),"data-tolk-removed":e.changed&&e.kind!==`space`?``:null},{default:B(()=>[N(R(e.text),1)]),_:2},1032,[`class`,`data-tolk-removed`]))),128))])]),M(`div`,null,[M(`dt`,Na,R(t.__(`After`)),1),M(`dd`,Pa,[(F(!0),j(m,null,L(e.diff.after,(e,t)=>(F(),k(Pt(e.changed?`ins`:`span`),{key:t,class:it(r(e,`after`)),"data-tolk-added":e.changed&&e.kind!==`space`?``:null},{default:B(()=>[N(R(e.text),1)]),_:2},1032,[`class`,`data-tolk-added`]))),128))])]),M(`div`,null,[M(`dt`,Fa,R(t.__(`Reason`)),1),M(`dd`,Ia,R(e.reason),1)])])]))),128))])]),_:1},8,[`title`]))}},za=[`aria-label`,`aria-valuemax`,`aria-valuenow`],Ba={__name:`ProgressBar`,props:{value:{type:Number,default:0},max:{type:Number,default:0},label:{type:String,required:!0}},setup(e){let t=e,n=O(()=>t.max>0?Math.min(100,Math.round(t.value/t.max*100)):0);return(t,r)=>(F(),j(`div`,{role:`progressbar`,"aria-label":e.label,"aria-valuemin":`0`,"aria-valuemax":e.max,"aria-valuenow":e.value,class:`h-1.5 w-full overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700`,"data-tolk-progress":``},[M(`div`,{class:`h-full rounded-full bg-blue-600 transition-[width] duration-300 dark:bg-blue-400!`,style:ot({width:`${n.value}%`})},null,4)],8,za))}},X=`base`;function Va(){let e=Bt(new Map),t=!1;function n(e=Statamic.$events){t||(t=!0,e.$on(`publish-container-created`,r),e.$on(`publish-container-destroyed`,i))}function r(t){let n=(e.get(t.name)?.mounted??0)+1;e.set(t.name,{payload:t,context:null,clean:null,mounted:n})}function i({name:t}){let n=e.get(t);n&&(n.mounted>1?e.set(t,{...n,mounted:n.mounted-1}):e.delete(t))}function a(t,n){let r=e.get(t)??{payload:null,context:null,clean:null,mounted:0};e.set(t,{...r,...n})}function o(t,n){a(t,{context:n,clean:e.get(t)?.clean??Z(n.values.value)})}function s(e){let t=c(e);t!==null&&a(e,{clean:Z(t)})}function c(t){let n=e.get(t);return(n?.context??n?.payload)?.values?.value??null}function l(t){let n=e.get(t)?.clean,r=c(t);return!n||r===null?[]:[...new Set([...Object.keys(r),...Object.keys(n)])].filter(e=>!no(r[e],n[e]))}return{listen:n,attachContext:o,refreshClean:s,dirtyHandles:l,context:t=>e.get(t)?.context??null,payload:t=>e.get(t)?.payload??null,base:()=>e.get(`base`)?.context??null,others:()=>[...e.keys()].filter(e=>e!==X)}}var Ha=Va();function Z(e){return Array.isArray(e)?e.map(Z):typeof e!=`object`||!e?e:Object.fromEntries(Object.keys(e).map(t=>[t,Z(e[t])]))}var Ua=new Set([`type`,`id`,`_id`,`marks`]),Wa=new Set([`type`,`attrs`,`content`,`marks`,`text`]),Ga=e=>e.replace(/\r\n?/g,` -`),Ka=e=>typeof e==`boolean`||typeof e==`number`,qa=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function Ja(e){if(typeof e==`string`)return e===``?null:Ga(e);if(Array.isArray(e))return e.length>0&&e.every(Xa)?Za(e):Ya(e);if(typeof e!=`object`||!e)return null;let t=Object.keys(e).filter(e=>!Ua.has(e)).sort().map(t=>[t,Ja(e[t])]).filter(([,e])=>e!==null);return t.length?Object.fromEntries(t):null}function Ya(e){let t=e.map(Ja);for(;t.length&&t[t.length-1]===null;)t.pop();return t.length?t:null}function Xa(e){return typeof e==`object`&&!!e&&typeof e.type==`string`&&Object.keys(e).every(e=>Wa.has(e))}function Za(e){let t=[],n=[],r=e=>{n.length&&(t.push(n.length===1&&n[0].marks.length===0?Ga(n[0].text):n.map(Qa)),n=[]),e!==null&&t.push(e)},i=e=>{let t=typeof e.text==`string`?e.text:``;if(t===``)return;let r=to(Array.isArray(e.marks)?e.marks:[]),i=JSON.stringify(r),a=n[n.length-1];a?.key===i?a.text+=t:n.push({key:i,marks:r,text:t,title:$a(e.marks)})},a=e=>{Xa(e)?e.type===`text`?i(e):(r(Ja(e.attrs)),r($a(e.marks)),(Array.isArray(e.content)?e.content:[]).forEach(a),r(null)):r(Ja(e))};return e.forEach(a),r(null),t.length?t:null}function Qa({marks:e,text:t,title:n}){return e.length===0?Ga(t):n===null?{text:Ga(t)}:{text:Ga(t),title:n}}function $a(e){let t=(Array.isArray(e)?e:[]).find(e=>qa(e)&&e.type===`link`),n=qa(t?.attrs)?t.attrs.title:null;return typeof n==`string`&&n.trim()!==``?Ga(n):null}var eo=e=>e==null||e===``||typeof e==`object`&&Object.keys(e).length===0;function to(e){return Array.isArray(e)?e.map(to):Ka(e)?String(e):qa(e)?Object.fromEntries(Object.keys(e).sort().map(t=>[t,to(e[t])]).filter(([,e])=>!eo(e))):e??null}function no(e,t){return JSON.stringify(Ja(e))===JSON.stringify(Ja(t))}function ro(e,t){return Array.isArray(e)&&Array.isArray(t)?e.every((e,n)=>n>=t.length||ro(e,t[n])):qa(e)&&qa(t)?Object.keys(e).every(n=>Ua.has(n)||!Object.hasOwn(t,n)||ro(e[n],t[n])):!(Ka(e)||Ka(t))||e===t}function io(e,t){return no(e,t)&&ro(e,t)}var ao=2e3,oo=1e3,so=100,co=50,lo=e=>new Promise(t=>setTimeout(t,e)),uo=e=>typeof e==`function`?e:()=>e,fo=(e,t,n)=>()=>e.reference.value===t&&n();async function po(e,t,n){let r=()=>600-(t()-e());for(let e=r();e>0;e=r())await n(e)}function mo(e,t,n){return Object.hasOwn(t,n)?!no(e.values.value[n],t[n]):e.values.value[n]!==void 0}function ho(e,t,n){return n===null&&typeof e.values.value[t]==`string`?``:Z(n)}function go(e,t){return e.hiddenFields?.value?.[t]?.omitValue===!0}function _o(e,t){for(let[n,r]of Object.entries(t))r.pending||r.sync||r.localizedBefore||(go(e,n)?e.localizedFields.value.includes(n)&&(ko(e,n,!1),r.leftOut=!0):r.leftOut&&=(ko(e,n,!0),!1))}function vo(e,t){let n=e.localizedFields.value;return Object.keys(t).filter(e=>t[e].leftOut||n.includes(e))}function yo(e,t){return!!t&&!t.pending&&t.plan!==e.delivered?.plan}function bo(e,t,n={}){let r=e.localizedFields.value;return{reference:e.reference.value,dirty:Statamic.$dirty.has(e.name.value),fields:Object.fromEntries(t.map(t=>[t,{value:Z(e.values.value[t]),meta:Z(e.meta.value[t]),localized:r.includes(t),delivered:n[t]?Z(n[t]):null}]))}}async function xo(e,t,{reference:n,plan:r,lastChangeAt:i=0,planValues:a={},delivered:o,now:s=Date.now,sleep:c=lo,active:l=()=>!0}){let u=Object.keys(t??{}),d={stale:!1,applied:[],skipped:{},repeated:[]},f=()=>(d.stale=!0,d.applied=[],d.skipped=Object.fromEntries(u.map(e=>[e,`stale`])),d),p=fo(e,n,l);if(!p()||(await po(uo(i),s,c),!p()))return f();let m=[],h={};for(let n of u){let i=t[n];if(o[n]?.plan===r){d.repeated.push(n);continue}if(mo(e,a,n)){d.skipped[n]=`edited`;continue}if(!i.sync&&go(e,n)){d.skipped[n]=`hidden`;continue}o[n]={plan:r,value:void 0,pending:!0,incomplete:!!i.incomplete,sync:!!i.sync,localizedBefore:o[n]?.localizedBefore??e.localizedFields.value.includes(n)},i.meta!==void 0&&e.setFieldMeta(n,Z(i.meta)),h[n]=ho(e,n,i.value),e.setFieldValue(n,Z(h[n])),i.sync?(ko(e,n,!1),Statamic.$dirty.add(e.name.value),m.push(n)):(e.desyncField(n),e.localizedFields.value.includes(n)||(ko(e,n,!0),Statamic.$dirty.add(e.name.value))),d.applied.push(n)}if(!d.applied.length)return d;if(await c(300),!p())return d.applied.forEach(e=>delete o[e]),f();m.filter(t=>io(e.values.value[t],h[t])).forEach(t=>ko(e,t,!1));for(let t of d.applied){let n=e.values.value[t];o[t]={...o[t],value:no(n,h[t])?Z(n):h[t],pending:!1}}return d}async function So(e,t,n,{registry:r=Ha,sleep:i=lo}={}){let a={restored:[],kept:[]};if(!t||e.reference.value!==t.reference)return a;for(let[r,i]of Object.entries(t.fields)){let t=n[r];if(yo(i,t)){if(!no(e.values.value[r],t.value)){a.kept.push(r);continue}a.restored.push(r)}}if(!a.restored.length)return a;e.withoutDirtying(()=>{for(let r of a.restored){let i=t.fields[r];e.setFieldMeta(r,Z(i.meta)),e.setFieldValue(r,ho(e,r,i.value)),ko(e,r,i.localized),i.delivered?n[r]=Z(i.delivered):delete n[r]}});let o=()=>{if(e.reference.value!==t.reference)return;let n=a.restored.filter(n=>!io(e.values.value[n],t.fields[n].value));a.restored.filter(e=>t.fields[e].localized||!n.includes(e)).forEach(n=>ko(e,n,t.fields[n].localized)),!t.dirty&&!n.length&&r.dirtyHandles(e.name.value).length===0&&Statamic.$dirty.remove(e.name.value)};return o(),await i(300),o(),a}function Co(e,t,n){if(!t||e.reference.value!==t.reference)return[];let r=n.filter(e=>Object.hasOwn(t.fields,e));return r.length&&e.withoutDirtying(()=>{for(let n of r){let r=t.fields[n];e.setFieldMeta(n,Z(r.meta)),e.setFieldValue(n,ho(e,n,r.value)),ko(e,n,r.localized)}}),r}async function wo(e,t,{reference:n,lastChangeAt:r=0,now:i=Date.now,sleep:a=lo,active:o=()=>!0}={}){let s=uo(r),c=fo(e,n,o),l=()=>s()+ao-i();if(!c())return{stale:!0,kept:!1,reset:!1};if(!Eo(e,t))return{stale:!1,kept:!1,reset:!1};for(await po(s,i,a);c()&&!Do(e)&&l()>0;)await a(Math.min(so,l()));let u=Do(e);return!c()||!await Oo(e,t,{sleep:a,current:c})?{stale:!0,kept:!1,reset:u}:{stale:!1,kept:!0,reset:u}}async function To(e,t,{reference:n,sleep:r=lo,active:i=()=>!0}={}){let a=fo(e,n,i);return!Eo(e,t)||(await r(oo),!a()||e.values.value.slug===t&&!Do(e))?!1:Oo(e,t,{sleep:r,current:a})}function Eo(e,t){return typeof t==`string`&&t!==``&&Object.hasOwn(e.values.value??{},`slug`)}function Do(e){return e.meta.value?.slug?.auto===!0}async function Oo(e,t,{sleep:n,current:r}){return Do(e)&&e.values.value.slug===t&&(e.setFieldValue(`slug`,``),await n(co),!r())?!1:(e.values.value.slug!==t&&e.setFieldValue(`slug`,t),!0)}function ko(e,t,n){let r=e.localizedFields.value,i=r.indexOf(t);n&&i===-1?r.push(t):!n&&i!==-1&&r.splice(i,1)}var Ao=2e3,jo=5;function Mo(e,t){return new Promise(n=>{if(t?.aborted)return n();let r=()=>{clearTimeout(i),t?.removeEventListener(`abort`,r),n()},i=setTimeout(r,e);t?.addEventListener(`abort`,r,{once:!0})})}function No(e){let t=e?.status??0;return t===429||t===503?`wait`:t===409&&e.code===`busy`?`busy`:t===409&&e.code===`source_changed`||t===410||t===502?`stop`:`fail`}function Po(e,t=``){return{status:e?.status??0,code:e?.code??null,message:e?.message||t}}var Fo=e=>Object.entries(Y(e)),Io=({id:e,fields:t})=>({id:e,fields:t});async function Lo({api:e=J,plan:t,concurrency:n=1,onFields:r=()=>{},onProgress:i=()=>{},signal:a=null,finishing:o=()=>!0,sleep:s=Mo,maxWaits:c=5,busyMs:l=Ao,maxBusyWaits:u=60}){let d=Math.max(1,Math.floor(Number(n))||1),f=[...t.units??[]],p=new Set(f.map(e=>e.id)),m={total:f.length,done:0,waiting:0},h=new Map,g=[],_=[],v=[],y={},b=new Set,x=new Set,S=new Set,C=new Set,w={},ee=null,T=()=>ee!==null||!!a?.aborted,E=()=>i({...m});function te(){if(!T())return f.shift();let e=ee===null&&o()?f.findIndex(e=>!p.has(e.id)):-1;return e===-1?null:f.splice(e,1)[0]}function D(e){let t=Fo(e).map(([e,t])=>(h.set(e,t),e));t.length&&g.push(Promise.resolve().then(()=>r(e)).then(e=>({handles:t,result:e}),e=>({handles:t,error:e})))}function ne(e,t){D(t?.fields);for(let[e,n]of Fo(t?.failed))y[e]=n;(Array.isArray(t?.warnings)?t.warnings:[]).forEach(e=>b.add(e)),(Array.isArray(t?.unchanged)?t.unchanged:[]).forEach(e=>x.add(e)),t?.reviewed===!0&&S.add(e.id),t?.review_skipped===!0&&C.add(e.id);for(let[e,n]of Fo(t?.usage))w[e]=zo(w[e]??{},n);let n=Array.isArray(t?.spawned)?t.spawned:[];f.push(...n),m.total+=n.length}async function re(n){let r=0,i=0;for(;;)try{return ne(n,await e.post(`editor/unit`,{plan:t.plan,unit:n.id}))}catch(e){let t=No(e),o=t===`wait`&&r0?Number(e.data.retry_after):jo;if(m.waiting++,E(),await s(t===`wait`?d*1e3:l,a),m.waiting--,E(),T()){v.push(Io(n));return}}}return D(t.ready),E(),await new Promise(e=>{let t=0,n=()=>{let r;for(;t{t--,m.done++,E(),n()});t===0&&e()};n()}),v.push(...f.map(Io)),Ro(await Promise.all(g),{received:h,failed:y,failedUnits:_,cancelledUnits:v,warnings:[...b],unchanged:x,reviewedUnits:[...S],reviewSkipped:[...C],usage:w,stopped:ee,aborted:!!a?.aborted,progress:m})}function Ro(e,{received:t,failed:n,failedUnits:r,cancelledUnits:i,warnings:a,unchanged:o,reviewedUnits:s,reviewSkipped:c,usage:l,stopped:u,aborted:d,progress:f}){let p=[],m={},h=!1;for(let{handles:t,result:r,error:i}of e){if(i){t.forEach(e=>n[e]??=`not_filled`);continue}h||=r?.stale===!0;for(let e of r?.applied??(r?[]:t))p.includes(e)||p.push(e);Object.assign(m,r?.skipped??{})}for(let e of r)for(let t of e.fields??[])!p.includes(t)&&!(t in m)&&(n[t]??=e.error?.code??`failed`);return p.forEach(e=>delete n[e]),{delivered:p,incomplete:p.filter(e=>t.get(e)?.incomplete===!0),skipped:m,failed:n,failedUnits:r,cancelledUnits:i,warnings:a,corrections:p.flatMap(e=>{let n=t.get(e)?.corrections;return Array.isArray(n)?n.map(t=>({handle:e,...t})):[]}),unchanged:[...o].filter(e=>!p.includes(e)),reviewedUnits:s,reviewSkipped:c,usage:l,models:Object.keys(l),stopped:u,aborted:d,stale:h,units:{total:f.total,done:f.done}}}function zo(e,t){let n={...e};for(let[e,r]of Fo(t))typeof r==`number`&&(n[e]=(n[e]??0)+r);return n}var Bo=t({BACKOFF_MS:()=>Ho,FINAL_STATUSES:()=>Vo,IDLE_MS:()=>Wo,MAX_BACKOFF_MS:()=>Uo,MAX_RETRIES:()=>5,POLL_MS:()=>Go,backoff:()=>ts,estimateLoop:()=>cs,isFinal:()=>Xo,latest:()=>Zo,nonce:()=>qo,pollState:()=>ss,retryable:()=>es,startApplyLoop:()=>as,startLanes:()=>is}),Vo=[`completed`,`completed_with_errors`,`cancelled`,`aborted`],Ho=1e3,Uo=3e4,Wo=1e3,Go=2e3,Ko=null;function qo(){return Ko??=Array.from(crypto.getRandomValues(new Uint8Array(12)),e=>e.toString(16).padStart(2,`0`)).join(``),Ko}var Jo=new WeakMap;function Yo(e,t,n){let r=Jo.get(e)??new Map,i=r.get(t),a=i?i.then(n):new Promise(e=>e(n())),o=a.then(()=>{},()=>{});return Jo.set(e,r),r.set(t,o),o.then(()=>r.get(t)===o&&r.delete(t)),a}function Xo(e){return Vo.includes(e?.run?.status)}function Zo(e){let t=null;return n=>{t!==null&&Qo(n,t)||(t=n,e(n))}}function Qo(e,t){let n=$o(e),r=$o(t);return n=500}function ts(e,t=Ho){return Math.min(t*2**Math.max(0,e-1),Uo)}function ns(e,t){return e==null?t:Math.max(0,Number(e)||0)*1e3}async function rs(e,{retries:t,backoffMs:n,sleep:r,signal:i}){for(let a=1;;a++)try{return{response:await e()}}catch(e){if(i?.aborted)return{};if(a>t||!es(e))return{error:Po(e)};if(await r(ts(a,n),i),i?.aborted)return{}}}function is({api:e=J,urls:t,lanes:n=1,nonce:r=qo(),onState:i=()=>{},onFailure:a=()=>{},signal:o=null,query:s=()=>({}),sleep:c=Mo,retries:l=5,backoffMs:u=Ho,idleMs:d=Wo}){let f=Math.max(1,Math.floor(Number(n))||1),p=new Map,m=new Set,h=[],g=[],_=()=>!!o?.aborted,v=e=>m.forEach(t=>t(e)),y=()=>[...p.values()].filter(e=>e===`running`).length;function b(e,t){let n={lane:e,error:t};return g.push(n),a(n),`failed`}let x=n=>Yo(e,`${t.tick} ${r} ${n}`,()=>_()?null:e.post(t.tick,{...s(),nonce:r,lane:n}));async function S(e){for(;!_();){let{response:t,error:n}=await rs(()=>x(e),{retries:l,backoffMs:u,sleep:c,signal:o});if(_())break;if(n)return b(e,n);if(i(t),v({lane:e,state:t}),Xo(t)||t?.report?.remains!==!0)return`finished`;await c(ns(t.report.wait,d),o)}return`aborted`}function C(e,t){p.set(e,t),v({lane:e,ended:t}),y()===0&&h.splice(0).forEach(e=>e())}function w(e){p.set(e,`running`),S(e).catch(t=>b(e,Po(t))).then(t=>C(e,t))}for(let e=1;e<=f;e++)w(e);return{get active(){return y()},failed:g,restart(){if(_())return 0;let e=[...p].filter(([,e])=>e===`finished`).map(([e])=>e);return e.forEach(w),e.length},idle(){return y()===0?Promise.resolve():new Promise(e=>h.push(e))},subscribe(e){return m.add(e),()=>m.delete(e)}}}async function as({api:e=J,urls:t,lanes:n=null,onState:r=()=>{},onFailure:i=()=>{},signal:a=null,query:o=()=>({}),sleep:s=Mo,retries:c=5,backoffMs:l=Ho,idleMs:u=Wo}){let d=()=>!!a?.aborted,f=null,p=!1,m=null,h=n?.subscribe(e=>{(e.ended||Number(Y(e.state?.counts).translated)>0)&&(p=!0,m?.())})??(()=>{}),g=()=>new Promise(e=>{let t=()=>{m=null,a?.removeEventListener(`abort`,t),e()};m=t,a?.addEventListener(`abort`,t,{once:!0})});try{for(;!d();){p=!1;let{response:m,error:h}=await rs(()=>e.post(t.apply,o()),{retries:c,backoffMs:l,sleep:s,signal:a});if(d())break;if(h)return i({error:h}),{state:f,error:h};if(f=m,r(m),Xo(m))break;if(n&&os(m)&&n.restart(),m?.report?.remains===!0)await s(ns(m.report.wait,u),a);else if(n?.active)p||await g();else break}}finally{h()}return{state:f,error:null}}function os(e){let t=e?.run;return t?.status===`running`&&t?.driver===`browser`&&Number(Y(e.counts).pending)>0}async function ss({api:e=J,url:t,interval:n=Go,onState:r=()=>{},onFailure:i=()=>{},signal:a=null,query:o=()=>({}),sleep:s=Mo,retries:c=5,backoffMs:l=Ho}){let u=null;for(;!a?.aborted;){let{response:d,error:f}=await rs(()=>e.get(t,o()),{retries:c,backoffMs:l,sleep:s,signal:a});if(a?.aborted)break;if(f)return i({error:f}),{state:u,error:f};if(u=d,r(d),Xo(d))break;await s(n,a)}return{state:u,error:null}}async function cs({api:e=J,url:t,estimate:n=null,onEstimate:r=()=>{},onFailure:i=()=>{},signal:a=null,sleep:o=Mo,retries:s=5,backoffMs:c=Ho}){let l=n,u=n===null?0:n.next===null?null:Math.max(0,Math.floor(Number(n.next))||0);for(;u!==null&&!a?.aborted;){let{response:n,error:d}=await rs(()=>e.post(t,{from:u}),{retries:s,backoffMs:c,sleep:o,signal:a});if(a?.aborted)break;if(d)return i({error:d}),{estimate:l,error:d};l=n,r(n),u=Number.isInteger(n?.next)?n.next:null}return{estimate:l,error:null}}var ls=[`pending`,`translating`,`translated`,`applying`,`done`,`skipped`,`failed`],us=[`pending`,`translating`,`translated`,`applying`],ds={pending:`default`,running:`blue`,completed:`green`,completed_with_errors:`orange`,cancelled:`amber`,aborted:`red`},fs={pending:`default`,translating:`blue`,translated:`sky`,applying:`blue`,done:`green`,skipped:`default`,failed:`red`};function ps(e){return{pending:__(`Not started`),running:__(`Running`),completed:__(`Completed`),completed_with_errors:__(`Completed with errors`),cancelled:__(`Cancelled`),aborted:__(`Aborted`)}[e]??e}function ms(e){return ds[e]??`default`}function hs(e){return{pending:__(`Waiting`),translating:__(`Translating`),translated:__(`Translated, not saved yet`),applying:__(`Saving`),done:__(`Done`),skipped:__(`Skipped`),failed:__(`Failed`)}[e]??e}function gs(e){return fs[e]??`default`}function _s(e){return{entry:__(`Entries`),term:__(`Terms`),globals:__(`Global sets`),nav:__(`Navigation`)}[e]??e}function vs(e=[]){let t=Object.fromEntries((Array.isArray(e)?e:[]).map(e=>[e.handle,e.name]));return e=>t[e]??e}function Q(e,t=void 0){return new Intl.NumberFormat(t).format(Number(e)||0)}function ys(e,t=void 0){let n=Number(e)||0,r=n>0&&n<.01?{maximumSignificantDigits:2}:{minimumFractionDigits:2,maximumFractionDigits:2};return new Intl.NumberFormat(t,{style:`currency`,currency:`USD`,...r}).format(n)}function bs(e,t=void 0){let n=Date.parse(e??``);return Number.isNaN(n)?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(n)}function xs(e){let t={...Object.fromEntries(ls.map(e=>[e,0])),...Y(e?.counts)},n=ls.reduce((e,n)=>e+(Number(t[n])||0),0),r=us.reduce((e,n)=>e+(Number(t[n])||0),0);return{counts:t,total:n,finished:n-r,unfinished:r}}function Ss(e){let t=e?.run??{},{counts:n,unfinished:r}=xs(e),i=Xo(e),a=t.status===`running`&&!!e?.stalled;return{start:t.status===`pending`,cancel:t.status===`running`,resume:a||[`cancelled`,`aborted`].includes(t.status)&&r>0,retry:i&&n.failed>0,takeOver:a&&t.driver===`queue`}}function Cs(e,t){let n=[t];return e.skipped>0&&n.push(__n(`:count skipped|:count skipped`,e.skipped)),e.failed>0&&n.push(__n(`:count failed|:count failed`,e.failed)),n.join(`, `)}function ws(e){let t=e?.run??{};if(!Xo(e))return null;let{counts:n}=xs(e),r=Cs(n,__n(`:count done|:count done`,n.done));return{status:t.status,variant:{completed:`success`,completed_with_errors:`warning`,cancelled:`warning`,aborted:`error`}[t.status],text:{completed:__(`The run is complete: :items.`,{items:r}),completed_with_errors:__(`The run is complete, with errors: :items.`,{items:r}),cancelled:__(`The run was cancelled: :items.`,{items:r}),aborted:__(`The run was stopped: :items.`,{items:r})}[t.status],error:t.error??null}}function Ts(e,t=e=>e){return(Array.isArray(e)?e:[]).map(({type:e,site:n,counts:r})=>{let i=xs({counts:r});return{key:`${e}|${n}`,type:_s(e),site:t(n),total:i.total,skipped:i.counts.skipped,done:i.counts.done,failed:i.counts.failed}})}function Es(e){let t={excluded_collection:e=>__n(`:count target is in a collection excluded in the settings.|:count targets are in collections excluded in the settings.`,e),site_not_in_collection:e=>__n(`:count target is in a site its collection does not have.|:count targets are in sites their collection does not have.`,e),unauthorized:e=>__n(`:count target is one you may not edit.|:count targets are ones you may not edit.`,e),from_site:e=>__n(`:count target is a navigation in the site it is translated from.|:count targets are navigations in the site they are translated from.`,e)};return Object.entries(Y(e?.skipped)).filter(([,e])=>Number(e)>0).map(([e,n])=>({reason:e,text:t[e]?.(Number(n))??__(`:count targets left out: :reason.`,{count:n,reason:e.replaceAll(`_`,` `)})}))}function Ds(e){let t=(Array.isArray(e?.out_of_scope)?e.out_of_scope:[]).filter(e=>e.reason===`not_localizable`);if(t.length===0)return null;let n=new Set(t.map(e=>e.container));return ga(t.map(e=>n.size>1?`${e.label||e.handle} (${e.container})`:e.label||e.handle).join(`, `),t.length)}function Os(e,t=e=>e){let n=t=>Array.isArray(e?.[t])?e[t]:[],r=n(`collections`),i=n(`taxonomies`),a=n(`globals`),o=n(`navs`),s=n(`entry_ids`).length,c=n(`term_ids`).length,l=[],u=(e,t)=>{e.includes(`*`)?l.push(t):e.length>0&&l.push(e.join(`, `))};return u(r,__(`All collections`)),s>0&&l.push(__n(`:count selected entry|:count selected entries`,s)),u(i,__(`All taxonomies`)),c>0&&l.push(__n(`:count selected term|:count selected terms`,c)),u(a,__(`All global sets`)),u(o,__(`All navigation`)),{what:l.join(`, `)||__(`Nothing selected`),sites:n(`sites`).map(t).join(`, `),automatic:e?.automatic===!0}}function ks(e,t={}){let n=e=>e?Y(t)[e]??e:null,r=[{key:`mode`,label:__(`Translate`),value:{missing:__(`Only what is not translated yet`),update:__(`Also update outdated translations`),all:__(`Retranslate everything`),review:__(`Review existing translations`)}[e?.mode]??e?.mode??``},{key:`translator`,label:__(`Model`),value:n(e?.translator)??__(`Default`)},{key:`review`,label:__(`Review`),value:e?.review?n(e?.reviewer)??__(`On`):__(`Off`)},{key:`overwrite_manual`,label:__(`Manual edits`),value:e?.overwrite_manual?__(`Overwritten`):__(`Kept`)},{key:`new_status`,label:__(`New localizations`),value:e?.new_status===`mirror`?__(`Same as origin`):__(`Drafts`)}];return e?.publish_changes&&r.push({key:`publish_changes`,label:__(`Revisions`),value:__(`Changes are published`)}),r}function As(e,t=0){if(!e)return null;let n=Number.isInteger(e.next)?e.next:null,r={done:Math.min(n??0,t),total:t};return{finished:n===null,progress:n===null?null:__(`:done of :total items`,r),partial:n===null?null:__(`Only :done of :total items were estimated before the run started.`,r),segments:Number(e.segments)||0,chars:Number(e.chars)||0,inputTokens:Number(e.input_tokens)||0,outputTokens:Number(e.output_tokens)||0,cost:e.cost===null||e.cost===void 0?null:Number(e.cost)}}function js(e,t={}){let n=Object.entries(Y(e?.usage)).map(([e,n])=>({model:Y(t)[e]??e,input:Number(n?.input)||0,output:Number(n?.output)||0,calls:Number(n?.calls)||0}));return{rows:n,input:n.reduce((e,t)=>e+t.input,0),output:n.reduce((e,t)=>e+t.output,0),calls:n.reduce((e,t)=>e+t.calls,0),cost:e?.cost===null||e?.cost===void 0?null:Number(e.cost)}}var Ms={current:()=>__(`up to date`),outdated:()=>__(`outdated, not updated in this mode`),untranslated:()=>__(`not translated yet`),manual:()=>__(`edited by hand, kept`),target_changed:()=>__(`edited meanwhile, kept`),not_applicable:()=>__(`empty in the source`),not_requested:()=>__(`not requested`),origin_untranslated:()=>__(`not translated in its source yet`),structure_differs:()=>__(`its structure differs from the source`),no_corrections:()=>__(`reviewed, nothing to correct`),review_skipped:()=>__(`could not be reviewed`)},Ns={invalid:()=>__(`the model kept breaking its formatting`),missing:()=>__(`the model left it out`),too_long:()=>__(`the model's answer was cut off`),refused:()=>__(`the model refused it`),request_rejected:()=>__(`the provider rejected the request`)},Ps={nothing_to_do:()=>__(`Nothing to do.`),dependency_failed:()=>__(`An item it depends on failed.`),unauthorized:()=>__(`You may not edit it.`),target_changed:()=>__(`Edited by someone while it was being translated.`),no_corrections:()=>__(`Reviewed, nothing to correct.`),source_changed:()=>__(`Its source changed, so it is translated again.`)};function Fs(e,t=e=>e){let n=Object.entries(Y(e?.fields)),r=e=>n.filter(([,t])=>t===e).map(([e])=>e),i=[`applied`,`incomplete`,`partly_reviewed`],a=n.filter(([,e])=>i.includes(e)).length,o=([,e])=>Object.hasOwn(Ns,e),s=n.filter(o).map(([e,t])=>({handle:e,reason:Ns[t]()})),c=n.filter(e=>!i.includes(e[1])&&!o(e)).map(([e,t])=>({handle:e,reason:Ms[t]?.()??String(t).replaceAll(`_`,` `)})),l=e?.reason?Ps[e.reason]?.()??null:null,u=Object.entries(Y(e?.corrections)).flatMap(([e,t])=>(Array.isArray(t)?t:[]).map(t=>({...t,handle:e,label:e})));return{index:e?.index,title:e?.title||e?.source_id||``,site:t(e?.target_site),status:e?.status,statusLabel:hs(e?.status),statusColor:gs(e?.status),editUrl:e?.edit_url??null,applied:a>0?__n(`:count field saved|:count fields saved`,a):null,incomplete:r(`incomplete`),failed:s,notReviewed:r(`partly_reviewed`),kept:c,reason:l,error:e?.error??null,rootPage:e?.root_page?.edit_url?{title:e.root_page.title||``,url:e.root_page.edit_url}:null,warnings:Array.isArray(e?.warnings)?e.warnings:[],corrected:u.length>0?__n(`:count correction|:count corrections`,u.length):null,corrections:u}}function Is(e,t){let n=t?.page;return Number.isInteger(n)&&n{},onEstimate:i=()=>{},onFailures:a=()=>{},query:o=()=>({}),api:s=J,ticker:c=Bo}){let l=null,u=()=>{},d=null,f=null,p=[],m=null,h=!1,g=null;function _(e){p=[...p,e],a(p)}function v(){return!!(d&&d.active>0||f)}function y(){let e=m?.run??{};return e.status===`running`&&e.driver===`browser`&&v()}function b(){let e=n!==null&&y();e!==h&&(h=e,e?Statamic.$dirty.add(n):Statamic.$dirty.remove(n))}function x(){l?.abort(),l=null,d=null,f=null,b()}function S(e){x(),u=c.latest(C),w(e,!0)}function C(e){m=e,r(e),b(),Xo(e)?g=null:Rs(e)!==g&&(x(),w(e,!1))}function w(n,r){let i=new AbortController;l=i,p=[],a(p),g=Rs(n),r&&u(n);let m=n?.run??{},h={onState:u,onFailure:_,signal:i.signal,query:o};if(g===`estimate`)ee(m.estimate??null,i.signal);else if(g===`drive`){d=c.startLanes({api:s,urls:e,lanes:t,...h}),d.subscribe(e=>e.ended&&b());let n=c.startApplyLoop({api:s,urls:e,lanes:d,...h}).catch(e=>_({error:Po(e)})).finally(()=>{f===n&&(f=null,b())});f=n,b()}else g===`poll`&&c.pollState({api:s,url:e.state,...h}).catch(e=>_({error:Po(e)}))}async function ee(t,n){try{let{error:r}=await c.estimateLoop({api:s,url:e.estimate,estimate:t,onEstimate:i,onFailure:_,signal:n});!r&&!n.aborted&&await T()}catch(e){n.aborted||_({error:Po(e)})}}async function T(){let t=l?.signal,n=await s.get(e.state,o());return t&&!t.aborted&&u(n),n}async function E(e,t=!0){let n=await s.post(e,o());return t?S(n):u(n),n}return{follow:S,refresh:T,stop:x,start:()=>E(e.start),cancel:()=>E(e.cancel,!1),resume:()=>E(e.resume),retry:()=>E(e.retry),takeOver:()=>E(e.take_over),get active(){return v()},get driving(){return y()},get failures(){return p}}}function Rs(e){let t=e?.run??{};return t.status===`pending`?`estimate`:t.status===`running`?t.driver===`browser`?`drive`:`poll`:null}var zs=[`idle`,`offer`,`planning`,`working`,`done`,`error`];function Bs(){return{reference:null,status:null,phase:`idle`,progress:{total:0,done:0,waiting:0,cancelling:!1},summary:null,snapshot:null,delivered:{},lastChangeAt:0,planReference:null,error:null,request:null,notSaved:[],created:!1,slugKept:!1,push:null}}var Vs=null;function Hs(){return Vs??=Statamic.$pinia.defineStore(`tolk-editor`,{state:()=>({containers:{}}),getters:{phaseOf:e=>t=>e.containers[t]?.phase??`idle`},actions:{container(e){return this.containers[e]??=Bs(),this.containers[e]},switched(e,t,n=Date.now()){this.containers[e]={...Bs(),reference:t,lastChangeAt:n}},saved(e,t=Date.now()){let n=this.container(e),r={...n.delivered};return n.lastChangeAt=Math.max(n.lastChangeAt,t),Object.keys(r).forEach(e=>delete n.delivered[e]),r},setPhase(e,t,n=null){if(!zs.includes(t))throw Error(`Unknown editor phase [${t}].`);let r=this.container(e);r.phase=t,r.error=t===`error`?n:null},clearResult(e){Object.assign(this.container(e),{summary:null,snapshot:null,request:null}),this.setPhase(e,`idle`)},forget(e){delete this.containers[e]}}}),Vs()}var Us=[`starting`,`running`,`expecting`],Ws=[1e3,2e3,4e3,8e3,15e3];function Gs(e){let t=e?.origin?.auto_update_sites??[];return(e?.origin?.localizations??[]).filter(e=>t.includes(e.site)).filter(e=>!e.exists||[`untranslated`,`outdated`].includes(e.status)).map(e=>e.site)}function Ks(e){return(e?.localizations??[]).filter(e=>e.translate).map(({site:e,name:t,exists:n,summary:r})=>({site:e,name:t,missing:!n,summary:r}))}function qs(e){return(e?.localizations??[]).filter(e=>e.update).map(e=>e.site)}function Js(e,{dirty:t=!1,term:n=!1}={}){return e?.translatesPublished&&(t||e.unpublishedChanges)?__(`Publish first: the translations are made from the published entry.`):t?n?__(`Save first: the translations are made from the saved term.`):__(`Save first: the translations are made from the saved entry.`):null}function Ys(e,{term:t=!1}={}){return t?__(`The saved term is translated and saved in each language you choose. This form stays as it is.`):e?.translatesPublished?__(`The published entry is translated and saved in each language you choose. This form stays as it is.`):__(`The saved entry is translated and saved in each language you choose. This form stays as it is.`)}function Xs(e){return(e?.origin?.localizations??[]).filter(e=>!e.exists).map(e=>e.site)}function Zs(e,t){if(!e)return null;let n=new Map((t?.origin?.localizations??[]).map(e=>[e.site,e])),r=e=>n.get(e)?.name??e,i=e.state,a=(e.sites?.length?e.sites:i?.run?.scope?.sites??[]).map(r),o=xs(i),s=i?Xo(i):!1,c=s?ws(i):null,l=s?(e.missing??[]).filter(e=>n.get(e)?.exists):[],u=i?.run?.driver??e.driver,d=e.phase===`running`&&i?.run?.status===`running`&&!!i.stalled,f=d&&u===`queue`;return{sites:a.join(`, `),automatic:!!e.automatic,progress:o,keepOpen:e.phase===`running`&&u===`browser`,stalled:d?Qs(f):null,takeOver:f,failure:e.failures?.length?e.failures.at(-1).error?.message??null:null,error:e.phase===`error`?e.error?.message??null:null,result:c&&{...c,text:$s(c.status,o.counts),items:(i.items??[]).map(e=>{let t=Fs(e,r);return{...t,handle:e.target_site,editUrl:n.get(e.target_site)?.edit_url??t.editUrl}})},reload:l.length>0}}function Qs(e){return e?__(`No queue worker has worked on these translations for a while. Start a queue worker, or translate them in this page instead.`):__(`The process that updates these translations has not worked on them for a while and may have stopped. Cancel it, then start the translations again.`)}function $s(e,t){let n=Cs(t,__n(`:count saved|:count saved`,t.done));return{completed:__(`The translations are done: :items.`,{items:n}),completed_with_errors:__(`The translations are done, with errors: :items.`,{items:n}),cancelled:__(`The translations were cancelled: :items.`,{items:n}),aborted:__(`The translations were stopped: :items.`,{items:n})}[e]}function ec({store:e=Hs,api:t=J,createFollower:n=Ls,wait:r=e=>new Promise(t=>setTimeout(t,e)),delays:i=Ws}={}){let a=new Map,o=new Set,s=0;function c(t){return Object.values(e().containers).filter(e=>e.push?.run===t)}function l(e,t){for(let n of c(e))n.push.state=t,Xo(t)&&n.push.phase===`running`&&(n.push.phase=`finished`,n.push.cancelling=!1,d(n.reference));Xo(t)&&a.delete(e)}function u(e,t){for(let n of c(e))n.push.failures=t}async function d(n){try{let r=await t.get(`editor/status`,{reference:n});for(let t of Object.values(e().containers))t.reference===n&&(t.status=r)}catch(e){e?.status!==403&&Statamic.$toast.error(__(`The translation status could not be updated: :message`,{message:e?.message??``}))}}function f(e,{run:t=null,driver:n=null,automatic:r=!1,sites:i=null,missing:a=[]}){return{phase:e,run:t,driver:n,automatic:r,sites:i,state:null,failures:[],missing:a,cancelling:!1,takingOver:!1,error:null}}function p(t,n,r,i=null){e().container(t).push=f(`running`,{run:n.run,driver:n.driver,automatic:n.automatic===!0,sites:i,missing:r})}function m(e){return e?.push?.run?a.get(e.push.run)??null:null}function h(e,t){let r=a.get(e.run);r||(r=n({urls:e.urls,lanes:e.lanes,onState:t=>l(e.run,t),onFailures:t=>u(e.run,t)}),a.set(e.run,r)),o.has(e.run)||r.follow(t)}function g(e){return o.add(e),a.get(e)?.stop(),t=>{o.delete(e),a.get(e)?.follow(t)}}async function _(n,{reference:r,sites:i,mode:a,overwriteManual:o=!1,review:s=null,newStatus:c=null}){let l=e().container(n);if(Us.includes(l.push?.phase)||l.reference!==r)return null;let u=Xs(l.status).filter(e=>i.includes(e));l.push=f(`starting`,{sites:i,missing:u});try{let l=await t.post(`editor/push`,{reference:r,sites:i,mode:a,overwrite_manual:o,review:s,new_status:c});return e().containers[n]?.reference===r&&p(n,l,u,i),h(l,l.state),l}catch(t){let i=e().containers[n];return i?.reference===r?t?.code===`run_active`&&t.data?.active_run?(i.push=null,await v(n,{active_run:t.data.active_run,origin:i.status?.origin}),null):(i.push={...i.push,phase:`error`,error:Po(t)},null):null}}async function v(n,r){let i=r?.active_run,a=e().containers[n];if(!i||!a||a.push?.run===i.run)return;let o=a.reference;p(n,i,Xs(r));try{h(i,await t.get(i.urls.state))}catch(t){let r=e().containers[n];r?.reference===o&&r.push?.run===i.run&&(r.push.failures=[{error:Po(t)}])}}async function y(n,a,{published:o=!1}={}){let c=e().containers[n],l=c?.reference;if(a?.active_run){await v(n,a);return}let u=Gs(a),d=o?!!a?.origin?.auto_update:a?.origin?.auto_update===`save`;if(!c||!d||u.length===0||Us.includes(c.push?.phase))return;let p=++s;c.push={...f(`expecting`,{automatic:!0,sites:u}),expecting:p};let m=()=>{let t=e().containers[n];return t?.reference===l&&t.push?.phase===`expecting`&&t.push.expecting===p?t:null};for(let e of i){if(await r(e),!m())return;let i=null;try{i=await t.get(`editor/status`,{reference:l})}catch{}let a=m();if(!a||i===null){a&&(a.push=null);return}if(a.status=i,i.active_run){a.push=null,await v(n,i);return}if(Gs(i).length===0){a.push=f(`updated`,{automatic:!0,sites:u});return}}let h=m();h&&(h.push=null)}async function b(t){let n=e().containers[t],r=m(n);if(r){n.push.failures=[];try{r.follow(await r.refresh())}catch(e){n.push.failures=[{error:Po(e)}]}}}async function x(t){let n=e().containers[t],r=m(n);if(r){n.push.cancelling=!0;try{await r.cancel()}catch(e){n.push.cancelling=!1,Statamic.$toast.error(e.message)}}}async function S(t){let n=e().containers[t],r=m(n),i=n?.push;if(r&&!i.takingOver){i.takingOver=!0;try{await r.takeOver()}catch(e){Statamic.$toast.error(e.message)}finally{i.takingOver=!1}}}function C(t){let n=e().containers[t];n&&!Us.includes(n.push?.phase)&&(n.push=null)}return{start:_,adopt:v,afterSave:y,resume:b,cancel:x,takeOver:S,dismiss:C,lend:g,following:e=>a.has(e)}}var tc=ec(),nc=[`planning`,`working`],rc=[`source_changed`,`plan_expired`,`target_missing`],ic=`edited_in_form`;function ac(e,t=()=>Statamic.$progress){return t()?.names?.().includes(`${e}-entry-publish-form`)??!1}function oc(){return __(`The form is being saved. Try again when the save has finished.`)}function sc(e,t,n){return!!t&&!t.pending&&no(e.values.value[n],t.value)}function cc(e,t,{name:n,registry:r,delivered:i={}}){let a=Y(t?.localization?.fields),o=e.originValues?.value??{},s=new Set(r.dirtyHandles(n));for(let[t,n]of Object.entries(a))n?.status===`untranslated`&&Object.hasOwn(o,t)&&!no(e.values.value[t],o[t])&&s.add(t);return[...s].filter(t=>Object.hasOwn(a,t)&&!sc(e,i[t],t))}function lc(e,t){let n=Y(t?.localization?.fields);return e.localizedFields.value.filter(e=>Object.hasOwn(n,e))}function uc(e,{overwriteManual:t=!1}={}){let n=Object.values(e?.delivered??{}).some(e=>!e.pending&&!e.sync),r=e?.status?.localization?.counts??{};return n||(r.current??0)>0||t&&(r.manual??0)>0}function dc(e){let t=new Set([...e?.delivered??[],...Object.keys(e?.skipped??{}),...e?.unchanged??[]]);return(e?.planned??[]).filter(e=>!t.has(e))}function fc(e){if(e?.phase===`error`)return!0;let t=e?.summary?.failed??{};return e?.phase===`done`&&dc(e.summary).some(e=>Object.hasOwn(t,e))}function pc(e){let t=e?.status?.localization;return e?.created&&!e.slugKept&&!t?.translate_slug?t?.origin_slug??null:null}function mc(e){let t=e?.snapshot?.fields;return t?Object.entries(t).some(([t,n])=>yo(n,e.delivered?.[t])):!1}function hc(e,t){return __n(`:fields was changed after the translation and was kept.|:fields were changed after the translation and were kept.`,e.length,{fields:xa(e,t)})}function gc(e){return Object.entries(Y(e))}function _c(e){return Object.fromEntries(gc(e).filter(([,e])=>e===ic).map(([e])=>[e,`edited`]))}function vc(e){return Object.fromEntries(gc(e).filter(([,e])=>e!==ic))}function yc(e,t){return e.replace===!0&&(e.fields??[]).includes(t)}function bc(e,{reference:t,skip:n}){return{reference:t,mode:e.mode,overwrite_manual:e.overwriteManual,fields:e.fields,skip:n,translator:e.translator,review:e.review,reviewer:e.reviewer}}function xc(e,{reference:t,handles:n,values:r}){return{reference:t,values:Object.fromEntries(n.map(e=>[e,r[e]])),overwrite_manual:e.overwriteManual,reviewer:e.reviewer}}function Sc(e,t){let n=t.snapshot,r=!1;if(!n||n.reference!==e.reference)return e;for(let[i,a]of Object.entries(n.fields))yo(a,t.delivered[i])&&(e.fields[i]=a,r=!0);return r&&(e.dirty=n.dirty),e}function Cc({store:e=Hs,registry:t=Ha,api:n=J,concurrency:r=()=>Statamic.$config.get(`tolk.concurrency`),run:i=Lo,fill:a=xo,undoFill:o=So,keepSlug:s=wo,recheckSlug:c=To,saving:l=ac,toast:u=()=>Statamic.$toast}={}){let d=new Map,f=new Set;function p(e){return l(e)?(u().error(oc()),!0):!1}function m(t){let n=d.get(t),r=e();n&&(d.delete(t),n.controller.abort()),nc.includes(r.containers[t]?.phase)&&r.setPhase(t,`idle`)}function h(t){let n=d.get(t),r=e().containers[t];n&&!n.controller.signal.aborted&&r?.phase===`working`&&(n.controller.abort(),r.progress={...r.progress,cancelling:!0})}async function g(o,l,{continuing:u=!1}={}){let f=e(),m=t.context(o),h=f.container(o);if(!m||nc.includes(h.phase)||d.has(o)||!m.reference.value||p(o))return null;let g=m.reference.value,_={},v=new AbortController,y=()=>d.get(o)?.token===_,b=()=>y()&&f.containers[o]===h&&m.reference.value===g,x=()=>f.containers[o]?.lastChangeAt??0,S=pc(h),C=l.kind===`review`,w=C?l.fields??lc(m,h.status):l.fields,ee=bo(m,w??Object.keys(m.values.value),h.delivered),T=Z(m.values.value),E=C?[]:cc(m,h.status,{name:o,registry:t,delivered:h.delivered}).filter(e=>!yc(l,e)),[te,D]=C?[`editor/review`,xc(l,{reference:g,handles:w,values:T})]:[`editor/plan`,bc(l,{reference:g,skip:E})];u&&Sc(ee,h),d.set(o,{token:_,controller:v}),Object.assign(h,{request:l,snapshot:ee,summary:null,notSaved:[],planReference:g,progress:Bs().progress}),f.setPhase(o,`planning`);let ne=S?s(m,S,{reference:g,lastChangeAt:x,active:y}):null;ne?.catch(()=>{});try{let e=await n.post(te,D);if(!b())return null;if(ne){if(await ne,!b())return null;h.slugKept=!0}f.setPhase(o,`working`),h.progress={...Bs().progress,total:e.units?.length??0};let t={reference:g,plan:e.plan,lastChangeAt:x,planValues:T,delivered:h.delivered,active:y},s=await i({api:n,plan:e,concurrency:r(),signal:v.signal,finishing:y,onFields:e=>a(m,e,t),onProgress:e=>{b()&&(h.progress={...e,cancelling:v.signal.aborted})}});if(ne&&s.delivered.length&&b()&&await c(m,S,{reference:g,active:y}),!b())return null;let u={...s,kind:l.kind,reviewer:e.reviewer??null,plan:e.plan,planned:Array.isArray(e.fields)?e.fields:[],skipped:{..._c(e.skipped),...s.skipped},planSkipped:vc(e.skipped),warnings:[...new Set([...Array.isArray(e.warnings)?e.warnings:[],...s.warnings??[]])],cancelled:v.signal.aborted};return h.summary=u,f.setPhase(o,s.stopped?`error`:`done`,s.stopped),u}catch(e){return b()&&f.setPhase(o,`error`,Po(e,__(`Something went wrong.`))),null}finally{y()&&d.delete(o)}}function _(e,{mode:t=`missing`,fields:n=null,overwriteManual:r=!1,translator:i=null,review:a=null,reviewer:o=null,replace:s=!1}={}){return g(e,{kind:`translate`,mode:t,fields:n,overwriteManual:r,translator:i,review:a,reviewer:o,replace:s})}function v(e,{fields:t=null,overwriteManual:n=!1,reviewer:r=null}={}){return g(e,{kind:`review`,fields:t,overwriteManual:n,reviewer:r})}function y(t){let n=e().containers[t];if(!n?.request||nc.includes(n.phase))return null;let r=n.summary?dc(n.summary):n.request.fields;return r!==null&&r.length===0?(e().setPhase(t,`done`),null):g(t,{...n.request,fields:r},{continuing:!0})}async function b(n){let r=e(),i=r.containers[n],a=t.context(n);if(!a||!i?.snapshot||nc.includes(i.phase)||f.has(n)||p(n))return null;f.add(n);try{let e=await o(a,i.snapshot,i.delivered,{registry:t});return r.containers[n]===i&&r.clearResult(n),e}finally{f.delete(n)}}return{translate:_,review:v,retry:y,cancel:h,abort:m,undo:b,running:e=>d.has(e),current:e=>d.get(e)?.token??null,saving:e=>l(e)}}var $=Cc(),wc=`tolk-banner`;function Tc(e){return typeof e==`string`&&e.startsWith(`term::`)}function Ec(e,t){return[`idle`,`done`,`error`].includes(e)&&!!t?.localization&&!t?.setup}function Dc(e){let t=e?.reference?.value;return e?.name===`base`&&typeof t==`string`&&(t.startsWith(`entry::`)||Tc(t))&&Statamic.$config.get(`tolk.multisite`)===!0&&Statamic.$permissions.has(`translate content`)}function Oc({store:e=Hs,abort:t=e=>$.abort(e)}={}){let n=new Map,r=!1;function i(e=Statamic.$events){r||(r=!0,e.$on(`publish-container-created`,a),e.$on(`publish-container-destroyed`,o))}function a(e){let t=null;s(e.name),Dc(e)&&(t=e.pushComponent(wc,{props:{containerName:e.name}})),n.set(e.name,[...n.get(e.name)??[],t])}function o({name:e}){let[t,...r]=n.get(e)??[];t?.destroy(),r.length?n.set(e,r):(n.delete(e),s(e))}function s(n){t(n),e().forget(n)}return{listen:i,pushed:e=>(n.get(e)??[]).filter(Boolean).length}}var kc=Oc();function Ac({name:e,ctx:t,store:n=Hs(),registry:r=Ha,loadStatus:i=e=>Qi(`editor/status`,{reference:e}),now:a=Date.now,settleMs:o=600,onSwitch:s=e=>$.abort(e),onStatus:c=(e,t)=>tc.adopt(e,t)}){let l=I(null),u=!!t.reference.value&&n.container(e).reference===t.reference.value;r.attachContext(e,t);let d=r=>t.reference.value===r&&n.containers[e]?.reference===r;async function f(r){if(l.value=null,!t.readOnly?.value)try{let t=await i(r);d(r)&&(n.container(e).status=t,c(e,t))}catch(e){d(r)&&e?.status!==403&&(l.value=e)}}function p(t){let i=a();s(e),n.switched(e,t,i),r.refreshClean(e),setTimeout(()=>{n.containers[e]?.lastChangeAt===i&&d(t)&&r.refreshClean(e)},o),f(t)}return{failure:l,stop:bn(()=>[t.reference.value,t.site.value],([t],r)=>{if(t){if(r===void 0&&u){n.container(e).status===null&&f(t);return}p(t)}},{immediate:!0,flush:`post`})}}function jc(){let e=!1,t=!1,n=Dt({open:!1,show(){e?t=!0:n.open=!0},hide(){t=!1,e||(n.open=!1)},dismissed(){e=!0},closed(r){r||(e=!1,n.open=!1,t&&(t=!1,nt(()=>n.open=!0)))}});return n}var Mc={class:`space-y-2 ps-6`,"data-tolk-push":``},Nc={class:`sr-only`,"aria-live":`polite`,"data-tolk-push-announcement":``},Pc={key:0,class:`flex flex-wrap items-center gap-2 pt-1`,"data-tolk-push-actions":``},Fc={key:3,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-phase":`updated`},Ic={key:4,class:`space-y-2`,"data-tolk-push-phase":`running`},Lc={class:`flex flex-wrap items-center justify-between gap-2`},Rc={key:1,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-stalled":``},zc={key:2,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-failure":``},Bc=[`data-tolk-push-status`],Vc={class:`space-y-1`},Hc=[`data-tolk-push-item`,`data-tolk-push-item-status`],Uc=[`href`],Wc=[`href`],Gc={class:`flex flex-wrap gap-2`},Kc={key:6,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-phase":`error`},qc={class:`space-y-6`},Jc={class:`space-y-3`},Yc=[`data-tolk-push-site`],Xc={class:`flex items-center justify-end gap-3 pt-3 pb-1`},Zc={__name:`OriginPush`,props:{containerName:{type:String,required:!0},reference:{type:String,required:!0},origin:{type:Object,required:!0},status:{type:Object,default:null},dirty:{type:Boolean,default:!1}},setup(e){let t=e,n=Hs(),r=O(()=>n.containers[t.containerName]?.push??null),i=O(()=>Zs(r.value,t.status)),a=O(()=>Us.includes(r.value?.phase)),o=O(()=>!a.value&&(t.origin.translateInto||t.origin.update)),s=O(()=>Ks(t.origin)),c=jc(),l=I([]),u=I(`draft`),d=I(!1),f=O(()=>s.value.some(e=>e.missing&&l.value.includes(e.site))),p=O(()=>Tc(t.reference)),h=O(()=>Js(t.origin,{dirty:t.dirty,term:p.value})),g=O(()=>Ys(t.origin,{term:p.value}));function _(){l.value=s.value.map(e=>e.site),u.value=t.status?.defaults?.new_status===`mirror`?`mirror`:`draft`,d.value=t.status?.defaults?.review===!0,c.show()}function v(e,t){l.value=t?[...new Set([...l.value,e])]:l.value.filter(t=>t!==e)}function y(){c.hide(),tc.start(t.containerName,{reference:t.reference,sites:s.value.map(e=>e.site).filter(e=>l.value.includes(e)),mode:`missing`,review:d.value,newStatus:f.value?u.value:null})}function b(){tc.start(t.containerName,{reference:t.reference,sites:qs(t.origin),mode:`update`})}let x=O(()=>i.value?.automatic?__(`Updating the translations automatically into :sites…`,{sites:i.value.sites}):__(`Translating into :sites…`,{sites:i.value.sites})),S=O(()=>__(`The translations into :sites were updated automatically.`,{sites:i.value?.sites??``})),C=O(()=>{switch(r.value?.phase){case`starting`:return __(`Starting the translation…`);case`expecting`:return x.value;case`updated`:return S.value;case`running`:return i.value.failure?__(`The translations stopped: :message`,{message:i.value.failure}):i.value.stalled??x.value;case`error`:return i.value?.error??``;default:return i.value?.result?.text??``}});function w(){window.location.reload()}return(t,n)=>(F(),j(`div`,Mc,[M(`p`,Nc,R(C.value),1),o.value?(F(),j(`div`,Pc,[e.origin.translateInto?(F(),k(z(V),{key:0,variant:`primary`,size:`sm`,disabled:e.dirty,"data-tolk-action":`translate-into`,onClick:_},{default:B(()=>[N(R(t.__(`Translate into…`)),1)]),_:1},8,[`disabled`])):A(``,!0),e.origin.update?(F(),k(z(V),{key:1,size:`sm`,disabled:e.dirty,"data-tolk-action":`update-translations`,onClick:b},{default:B(()=>[N(R(t.__(`Update translations`)),1)]),_:1},8,[`disabled`])):A(``,!0),h.value?(F(),k(z(U),{key:2,"data-tolk-save-first":``},{default:B(()=>[N(R(h.value),1)]),_:1})):A(``,!0)])):A(``,!0),r.value?.phase===`starting`?(F(),k(z(q),{key:1,as:`p`,"data-tolk-push-phase":`starting`},{default:B(()=>[N(R(t.__(`Starting the translation…`)),1)]),_:1})):A(``,!0),r.value?.phase===`expecting`?(F(),k(z(q),{key:2,as:`p`,"data-tolk-push-phase":`expecting`},{default:B(()=>[N(R(x.value),1)]),_:1})):A(``,!0),r.value?.phase===`updated`?(F(),j(`div`,Fc,[P(z(q),null,{default:B(()=>[N(R(S.value),1)]),_:1}),P(z(V),{size:`sm`,variant:`ghost`,"data-tolk-action":`push-close`,onClick:n[0]||=t=>z(tc).dismiss(e.containerName)},{default:B(()=>[N(R(t.__(`Close`)),1)]),_:1})])):A(``,!0),r.value?.phase===`running`?(F(),j(`div`,Ic,[M(`div`,Lc,[r.value.cancelling?(F(),k(z(q),{key:0},{default:B(()=>[N(R(t.__(`Cancelling. Translations already being saved are still saved.`)),1)]),_:1})):(F(),k(z(q),{key:1,"data-tolk-push-working":``},{default:B(()=>[N(R(x.value),1)]),_:1})),P(z(V),{size:`sm`,variant:`ghost`,disabled:r.value.cancelling,"data-tolk-action":`push-cancel`,onClick:n[1]||=t=>z(tc).cancel(e.containerName)},{default:B(()=>[N(R(t.__(`Cancel`)),1)]),_:1},8,[`disabled`])]),P(Ba,{value:i.value.progress.finished,max:i.value.progress.total,label:t.__(`Translation progress`)},null,8,[`value`,`max`,`label`]),P(z(U),{"data-tolk-push-progress":``},{default:B(()=>[N(R(t.__(`:finished of :total translations finished.`,{finished:i.value.progress.finished,total:i.value.progress.total})),1)]),_:1}),i.value.keepOpen?(F(),k(z(U),{key:0},{default:B(()=>[N(R(p.value?t.__(`Keep this page open until the translations are saved. If you leave, they continue when you open this term again.`):t.__(`Keep this page open until the translations are saved. If you leave, they continue when you open this entry again.`)),1)]),_:1})):A(``,!0),i.value.stalled?(F(),j(`div`,Rc,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-amber-600`,"aria-hidden":`true`}),P(z(q),null,{default:B(()=>[N(R(i.value.stalled),1)]),_:1}),i.value.takeOver?(F(),k(z(V),{key:0,size:`sm`,disabled:r.value.takingOver||r.value.cancelling,loading:r.value.takingOver,"data-tolk-action":`push-take-over`,onClick:n[2]||=t=>z(tc).takeOver(e.containerName)},{default:B(()=>[N(R(t.__(`Translate in this page instead`)),1)]),_:1},8,[`disabled`,`loading`])):A(``,!0)])):A(``,!0),i.value.failure?(F(),j(`div`,zc,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-red-600`,"aria-hidden":`true`}),P(z(q),{variant:`danger`},{default:B(()=>[N(R(t.__(`The translations stopped: :message`,{message:i.value.failure})),1)]),_:1}),P(z(V),{size:`sm`,"data-tolk-action":`push-resume`,onClick:n[3]||=t=>z(tc).resume(e.containerName)},{default:B(()=>[N(R(t.__(`Try again`)),1)]),_:1})])):A(``,!0)])):A(``,!0),i.value?.result?(F(),j(`div`,{key:5,class:`space-y-2`,"data-tolk-push-result":``,"data-tolk-push-status":i.value.result.status},[P(z(q),{as:`p`},{default:B(()=>[N(R(i.value.result.text),1)]),_:1}),i.value.result.error?(F(),k(z(q),{key:0,as:`p`,variant:`danger`},{default:B(()=>[N(R(i.value.result.error),1)]),_:1})):A(``,!0),M(`ul`,Vc,[(F(!0),j(m,null,L(i.value.result.items,e=>(F(),j(`li`,{key:e.index,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-item":e.handle,"data-tolk-push-item-status":e.status},[e.editUrl?(F(),j(`a`,{key:0,href:e.editUrl,class:`text-sm font-medium underline`},R(e.site),9,Uc)):(F(),k(z(q),{key:1,variant:`strong`},{default:B(()=>[N(R(e.site),1)]),_:2},1024)),P(z(Pn),{text:e.statusLabel,color:e.statusColor},null,8,[`text`,`color`]),e.error||e.reason?(F(),k(z(U),{key:2},{default:B(()=>[N(R(e.error??e.reason)+` `,1),e.rootPage?(F(),j(`a`,{key:0,href:e.rootPage.url,class:`font-medium underline`,"data-tolk-root-page":``},R(t.__(`Open :title`,{title:e.rootPage.title})),9,Wc)):A(``,!0)]),_:2},1024)):A(``,!0)],8,Hc))),128))]),i.value.reload?(F(),k(z(U),{key:1},{default:B(()=>[N(R(t.__(`Reload the page to see the new localizations in the Sites panel.`)),1)]),_:1})):A(``,!0),M(`div`,Gc,[i.value.reload?(F(),k(z(V),{key:0,size:`sm`,variant:`primary`,"data-tolk-action":`reload`,onClick:w},{default:B(()=>[N(R(t.__(`Reload`)),1)]),_:1})):A(``,!0),P(z(V),{size:`sm`,variant:`ghost`,"data-tolk-action":`push-close`,onClick:n[4]||=t=>z(tc).dismiss(e.containerName)},{default:B(()=>[N(R(t.__(`Close`)),1)]),_:1})])],8,Bc)):A(``,!0),r.value?.phase===`error`?(F(),j(`div`,Kc,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-red-600`,"aria-hidden":`true`}),P(z(q),{variant:`danger`,"data-tolk-push-error":``},{default:B(()=>[N(R(i.value.error),1)]),_:1}),P(z(V),{size:`sm`,variant:`ghost`,"data-tolk-action":`push-close`,onClick:n[5]||=t=>z(tc).dismiss(e.containerName)},{default:B(()=>[N(R(t.__(`Close`)),1)]),_:1})])):A(``,!0),z(c).open?(F(),k(z(Wr),{key:7,open:``,title:t.__(`Translate into other languages`),icon:`dictionary-language-book`,"data-tolk-push-modal":``,onDismissed:n[9]||=e=>z(c).dismissed(),"onUpdate:open":n[10]||=e=>z(c).closed(e)},{footer:B(()=>[M(`div`,Xc,[P(z(V),{variant:`ghost`,text:t.__(`Cancel`),"data-tolk-push-action":`close`,onClick:n[8]||=e=>z(c).hide()},null,8,[`text`]),P(z(V),{variant:`primary`,text:t.__(`Translate`),disabled:l.value.length===0,"data-tolk-push-action":`translate`,onClick:y},null,8,[`text`,`disabled`])])]),default:B(()=>[M(`div`,qc,[P(z(q),{as:`p`},{default:B(()=>[N(R(g.value),1)]),_:1}),M(`div`,Jc,[(F(!0),j(m,null,L(s.value,e=>(F(),j(`div`,{key:e.site,"data-tolk-push-site":e.site},[P(z(Vn),{"model-value":l.value.includes(e.site),label:e.name,description:e.summary,"onUpdate:modelValue":t=>v(e.site,t)},null,8,[`model-value`,`label`,`description`,`onUpdate:modelValue`])],8,Yc))),128))]),f.value?(F(),k(z(yr),{key:0,id:`tolk-push-status`,label:t.__(`New localizations`)},{default:B(()=>[P(z(ui),{modelValue:u.value,"onUpdate:modelValue":n[6]||=e=>u.value=e,appearance:`inline`,"data-tolk-push-new-status":``},{default:B(()=>[P(z(li),{value:`draft`,label:t.__(`Drafts`)},null,8,[`label`]),P(z(li),{value:`mirror`,label:t.__(`Same as origin`)},null,8,[`label`])]),_:1},8,[`modelValue`])]),_:1},8,[`label`])):A(``,!0),P(z(Vn),{modelValue:d.value,"onUpdate:modelValue":n[7]||=e=>d.value=e,label:t.__(`Review after translating`),description:t.__(`A second model checks each translation and corrects it before it is saved.`)},null,8,[`modelValue`,`label`,`description`])])]),_:1},8,[`title`])):A(``,!0)]))}},Qc=`tolk.offer`,$c=null;function el(e,t,{preferences:n=()=>Statamic.$preferences,toast:r=()=>Statamic.$toast}={}){let i=()=>new Promise(r=>r(n().set(e,t))).then(()=>!0,()=>(r().error(__(`Your choice could not be saved.`)),!1)),a=$c?$c.then(i):i();return $c=a,a.then(()=>{$c===a&&($c=null)}),a}function tl(e=Statamic.$preferences){return e.get(Qc,!0)!==!1}function nl(e,t=Statamic.$preferences){return e?.offer===!0&&tl(t)&&ua(e).localization?.translate===!0}function rl(e){let t=ua(e);return{count:e?.localization?.counts?.untranslated??0,source:t.localization?.source?.name??``,target:t.localization?.target?.name??``,translator:t.translator}}var il=350;function al({store:e=Hs,registry:t=Ha,translations:n=$,preferences:r=()=>Statamic.$preferences,toast:i=()=>Statamic.$toast,openAfterMs:a=il,clock:o=()=>Date.now(),wait:s=(e,t)=>setTimeout(e,t)}={}){let c=null,l=!1;function u(e=Statamic.$events){l||(l=!0,e.$on(`localization.created`,d))}function d(n){let r=n?.container?.name,i=t.context(r)?.reference?.value;if(r!==`base`||!i)return;m();let s=e(),l=o()+a;if(f(s,r,i,l))return;let u=bn(()=>{let e=s.containers[r];return[e?.reference,e?.status]},()=>{f(s,r,i,l)&&(u(),c===u&&(c=null))});c=u}function f(e,n,r,i){let a=e.containers[n];return a?.reference===r?(a.created=!0,a.status!==null&&(p(e,n,r,i),!0)):t.context(n)?.reference?.value!==r}function p(e,t,n,i){let a=i-o();if(a>0){s(()=>p(e,t,n,i),a);return}let c=e.containers[t];c?.reference===n&&c.phase===`idle`&&nl(c.status,r())&&e.setPhase(t,`offer`)}function m(){c?.(),c=null}function h(t,n){let a=e();return a.phaseOf(t)===`offer`&&(n&&el(Qc,!1,{preferences:r,toast:i}),a.setPhase(t,`idle`),!0)}function g(e,{dontOfferAgain:t=!1}={}){return h(e,t)?n.translate(e,{mode:`missing`}):null}function _(e,{dontOfferAgain:t=!1}={}){h(e,t)}return{listen:u,created:d,accept:g,decline:_,waiting:e=>e===`base`&&c!==null}}var ol=al(),sl={class:`space-y-1`},cl={class:`flex items-center justify-end gap-3 pt-3 pb-1`},ll={__name:`TranslateOffer`,props:{containerName:{type:String,required:!0},status:{type:Object,default:null},open:{type:Boolean,default:!1}},setup(e){let t=e,n=I(!1),r=O(()=>rl(t.status));bn(()=>t.open,e=>{e&&(n.value=!1)});function i(){ol.accept(t.containerName,{dontOfferAgain:n.value})}function a(){ol.decline(t.containerName,{dontOfferAgain:n.value})}return(t,o)=>(F(),k(z(Wr),{open:e.open,title:t.__(`Translate this entry?`),icon:`dictionary-language-book`,"data-tolk-offer":``,onDismissed:a},{footer:B(()=>[M(`div`,cl,[P(z(V),{variant:`ghost`,text:t.__(`Not now`),"data-tolk-offer-action":`decline`,onClick:a},null,8,[`text`]),P(z(V),{variant:`primary`,text:t.__(`Translate`),"data-tolk-offer-action":`translate`,onClick:i},null,8,[`text`])])]),default:B(()=>[M(`div`,sl,[P(z(q),{as:`p`,"data-tolk-offer-text":``},{default:B(()=>[N(R(t.__n(`Translate :count field from :source into :target. Nothing is saved until you press Save.|Translate :count fields from :source into :target. Nothing is saved until you press Save.`,r.value.count,{source:r.value.source,target:r.value.target})),1)]),_:1}),r.value.translator?(F(),k(z(U),{key:0,"data-tolk-offer-model":``},{default:B(()=>[N(R(t.__(`Model: :model`,{model:z(ba)(r.value.translator)})),1)]),_:1})):A(``,!0)]),P(z(Vn),{modelValue:n.value,"onUpdate:modelValue":o[0]||=e=>n.value=e,label:t.__(`Don't offer again`)},null,8,[`modelValue`,`label`])]),_:1},8,[`open`,`title`]))}},ul=`automatic`;function dl(e){return typeof e==`string`&&e.trim()!==``?e.trim():null}function fl(e){return/^[^\s:]+:\S+$/.test(e)}function pl(e){return{quality:__(`Quality`),fast:__(`Fast`)}[e]??null}function ml(e,t){return{value:e,label:e,note:Y(t)[e.split(`:`)[0]]?.[0]?.configured===!1?__(`No API key`):__(`Custom model`),disabled:!1}}function hl(e,t){let n=[{value:ul,label:e?.automatic||__(`Automatic`),note:null,disabled:!1}],r=e?.fake_engine===!0;for(let t of Object.values(Y(e?.catalog)).flat())n.push({value:t.value,label:t.label,note:t.configured?pl(t.tier):__(`No API key`),disabled:!t.configured&&!r});let i=dl(t);return i&&!n.some(e=>e.value===i)&&n.push(ml(i,e?.catalog)),n}function gl(e,t){if(e===null||e===`automatic`)return null;let n=t.find(t=>t.value===e);if(n)return n.disabled?void 0:n.value;let r=typeof e==`string`?e.trim():``;return fl(r)?r:void 0}var _l=`tolk.editor.translator`,vl=`tolk.editor.reviewer`;function yl(e,t){let n=e.get(t,null);return typeof n==`string`&&n!==``?n:null}function bl(e=Statamic.$preferences,t=_l){let n=yl(e,t);return n!==null&&fl(n)?n:null}function xl(e,{fakeEngine:t=!1,defaultModel:n=null,extra:r=[]}={}){let i=[];for(let r of Object.values(Y(e)).flat())(r.configured||t)&&i.push({value:r.value,label:r.value===n?__(`:model (default)`,{model:r.label}):r.label});for(let e of r)e&&!i.some(t=>t.value===e)&&i.push({value:e,label:e===n?__(`:model (default)`,{model:e}):e});return i}function Sl(e,t,n){if(t.some(t=>t.value===e))return e;let r=typeof e==`string`?e.trim():``;return fl(r)?r:n}function Cl(e,{remembered:t=null,defaultModel:n=null}={}){let r=t=>t!==null&&e.some(e=>e.value===t);return r(t)?t:r(n)?n:e[0]?.value??null}function wl(e,t){return e&&e!==t?e:null}function Tl(e,t,n){return n?e||null:wl(e,t)}function El({model:e=null,defaultModel:t=null,retranslate:n=!1,overwriteManual:r=!1,review:i=null,reviewer:a=null,defaultReviewer:o=null}={}){let s=wl(e,t);return{mode:n?`all`:`update`,overwriteManual:r,translator:s,review:i,reviewer:i===!0?Tl(a,o,s):null}}function Dl({reviewer:e=null,defaultReviewer:t=null,overwriteManual:n=!1}={}){return{overwriteManual:n,reviewer:wl(e,t)}}function Ol(e){let t=e?.localization?.counts??{},n=Object.values(e?.localization?.fields??{}).filter(e=>e.incomplete).length;return{markCurrent:(t.attention??0)+(t.untracked??0)>0,protect:(t.current??0)+(t.outdated??0)-n>0}}function kl(e,t){return e===0?__(`No field needed changing.`):t?__n(`:count field is now protected from updates.|:count fields are now protected from updates.`,e):__n(`:count field marked as up to date.|:count fields marked as up to date.`,e)}function Al({store:e=Hs,registry:t=Ha,api:n=J,translations:r=$,preferences:i=()=>Statamic.$preferences,toast:a=()=>Statamic.$toast}={}){let o=null;function s(){return o??=n.get(`models`).catch(e=>{throw o=null,e}),o}function c(e,t){t!==yl(i(),e)&&el(e,t,{preferences:i,toast:a})}function l(t,n={}){let i=El(n);return nc.includes(e().phaseOf(t))?null:(c(_l,i.translator),i.review===!0&&c(vl,wl(n.reviewer,n.defaultReviewer)),r.translate(t,i))}function u(t,n={}){let i=Dl(n);return nc.includes(e().phaseOf(t))?null:(c(vl,i.reviewer),r.review(t,i))}async function d(r,{protect:i=!1}={}){let o=e().containers[r],s=t.context(r)?.reference?.value??null;if(!o||!s||o.reference!==s||nc.includes(o.phase))return null;try{let{baselined:e=0,...t}=await n.post(`editor/baseline`,{reference:s,protect:i});return o.status=t,a().success(kl(e,i)),e}catch(e){return a().error(e?.message||__(`Something went wrong.`)),null}}function f(e){return el(Qc,e,{preferences:i,toast:a})}return{loadModels:s,translate:l,review:u,baseline:d,setOffers:f}}var jl=Al(),Ml={class:`space-y-4`},Nl={class:`space-y-3`},Pl={class:`grid gap-4 sm:grid-cols-2`},Fl={class:`space-y-3`},Il={key:0,class:`space-y-3 border-t border-gray-200 pt-4 dark:border-gray-700`,"aria-labelledby":`tolk-options-state-heading`,"data-tolk-options-state":``},Ll={key:0,class:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4`},Rl={key:1,class:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4`},zl={key:1,class:`flex items-start justify-between gap-4 border-t border-gray-200 pt-4 dark:border-gray-700`,"data-tolk-options-offer":``},Bl={class:`space-y-0.5`},Vl={class:`flex items-center justify-end gap-3 pt-3 pb-1`},Hl={__name:`TranslateOptions`,props:{containerName:{type:String,required:!0},status:{type:Object,default:null}},setup(e){let t=e,n=Hs(),r=O(()=>Tc(n.containers[t.containerName]?.reference)),i=jc(),a=I(!1),o=I(null),s=I(null),c=I(null),l=I(null),u=I(!1),d=I(!1),f=I(!1),p=I(!0),h=I(!1),g=!!Statamic.$config.get(`tolk.settingsUrl`),_=O(()=>s.value?.defaults?.translator??t.status?.defaults?.translator??null),v=O(()=>s.value?.defaults?.reviewer??null),y=O(()=>bl()),b=O(()=>bl(Statamic.$preferences,vl));function x(e,n,r){return xl(s.value?.catalog,{fakeEngine:t.status?.defaults?.fake_engine===!0,defaultModel:e,extra:g?[e,n,r]:[e]})}let S=O(()=>x(_.value,y.value,c.value)),C=O(()=>x(v.value,b.value,l.value)),w=O(()=>uc(n.containers[t.containerName],{overwriteManual:f.value})),ee=O(()=>u.value||w.value),T=O(()=>Ol(t.status)),E=O(()=>t.status?.offer===!0);async function te(){d.value=!1,f.value=!1,u.value=t.status?.defaults?.review===!0,o.value=null,p.value=tl(),i.show(),a.value=!0;try{s.value=await jl.loadModels()}catch(e){o.value=e.message}finally{a.value=!1}c.value=Cl(S.value,{remembered:y.value,defaultModel:_.value}),l.value=Cl(C.value,{remembered:b.value,defaultModel:v.value})}function D(){i.hide(),jl.translate(t.containerName,{model:c.value,defaultModel:_.value,retranslate:d.value,overwriteManual:f.value,review:u.value,reviewer:l.value,defaultReviewer:v.value})}function ne(){i.hide(),jl.review(t.containerName,{reviewer:l.value,defaultReviewer:v.value,overwriteManual:f.value})}async function re(e){h.value=!0;try{await jl.baseline(t.containerName,{protect:e})!==null&&i.hide()}finally{h.value=!1}}async function ie(e){p.value=e,await jl.setOffers(e)||(p.value=!e)}return(e,t)=>(F(),j(m,null,[P(z(V),{size:`sm`,variant:`ghost`,icon:`sliders-horizontal`,text:e.__(`Options`),"data-tolk-action":`options`,onClick:te},null,8,[`text`]),z(i).open?(F(),k(z(Wr),{key:0,open:``,title:e.__(`Translation options`),icon:`sliders-horizontal`,"data-tolk-options":``,onDismissed:t[8]||=e=>z(i).dismissed(),"onUpdate:open":t[9]||=e=>z(i).closed(e)},{footer:B(()=>[M(`div`,Vl,[P(z(V),{variant:`ghost`,text:e.__(`Close`),"data-tolk-options-action":`close`,onClick:t[7]||=e=>z(i).hide()},null,8,[`text`]),w.value?(F(),k(z(V),{key:0,text:e.__(`Review`),disabled:a.value||!l.value,"data-tolk-options-action":`review`,onClick:ne},null,8,[`text`,`disabled`])):A(``,!0),P(z(V),{variant:`primary`,text:e.__(`Translate`),disabled:a.value||!c.value,"data-tolk-options-action":`translate`,onClick:D},null,8,[`text`,`disabled`])])]),default:B(()=>[M(`div`,Ml,[M(`div`,Nl,[M(`div`,Pl,[P(z(yr),{id:`tolk-options-model`,label:e.__(`Model`)},{default:B(()=>[P(z(Wn),{id:`tolk-options-model`,"model-value":c.value,options:S.value,taggable:z(g),disabled:a.value,placeholder:a.value?e.__(`Loading…`):e.__(`Choose a model`),"data-tolk-options-model":``,"onUpdate:modelValue":t[0]||=e=>c.value=z(Sl)(e,S.value,c.value)},null,8,[`model-value`,`options`,`taggable`,`disabled`,`placeholder`])]),_:1},8,[`label`]),P(z(yr),{id:`tolk-options-reviewer`,label:e.__(`Reviewer`),"data-tolk-options-review":``},{default:B(()=>[P(z(Wn),{id:`tolk-options-reviewer`,"model-value":l.value,options:C.value,taggable:z(g),disabled:a.value||!ee.value,placeholder:a.value?e.__(`Loading…`):e.__(`Choose a model`),"data-tolk-options-reviewer":``,"onUpdate:modelValue":t[1]||=e=>l.value=z(Sl)(e,C.value,l.value)},null,8,[`model-value`,`options`,`taggable`,`disabled`,`placeholder`])]),_:1},8,[`label`])]),z(g)?(F(),k(z(U),{key:0},{default:B(()=>[N(R(e.__(`You may also type a model outside the list, as provider:model.`)),1)]),_:1})):A(``,!0),o.value?(F(),k(z(q),{key:1,as:`p`,variant:`danger`,"data-tolk-options-failure":``},{default:B(()=>[N(R(e.__(`The models could not be loaded: :message`,{message:o.value})),1)]),_:1})):A(``,!0)]),M(`div`,Fl,[P(z(Vn),{modelValue:d.value,"onUpdate:modelValue":t[2]||=e=>d.value=e,label:e.__(`Retranslate everything`),description:e.__(`Also translates the fields that are up to date again.`)},null,8,[`modelValue`,`label`,`description`]),P(z(Vn),{modelValue:f.value,"onUpdate:modelValue":t[3]||=e=>f.value=e,label:e.__(`Overwrite manual edits`),description:e.__(`Also replaces the text of fields edited by hand.`)},null,8,[`modelValue`,`label`,`description`]),P(z(Vn),{modelValue:u.value,"onUpdate:modelValue":t[4]||=e=>u.value=e,label:e.__(`Review after translating`),description:e.__(`The reviewer checks the new translation and corrects it.`)},null,8,[`modelValue`,`label`,`description`])]),T.value.markCurrent||T.value.protect?(F(),j(`section`,Il,[P(z(W),{id:`tolk-options-state-heading`,level:2,text:e.__(`Translation status`)},null,8,[`text`]),T.value.markCurrent?(F(),j(`div`,Ll,[P(z(U),null,{default:B(()=>[N(R(e.__(`Records that the fields edited by hand match the current source, so a later change to the source is flagged.`)),1)]),_:1}),P(z(V),{size:`sm`,class:`shrink-0 self-start sm:self-auto`,text:e.__(`Mark manual fields as up to date`),disabled:h.value,"data-tolk-action":`mark-current`,onClick:t[5]||=e=>re(!1)},null,8,[`text`,`disabled`])])):A(``,!0),T.value.protect?(F(),j(`div`,Rl,[P(z(U),null,{default:B(()=>[N(R(e.__(`Treats the translated fields as edited by hand, so Translate and Update leave them alone.`)),1)]),_:1}),P(z(V),{size:`sm`,class:`shrink-0 self-start sm:self-auto`,text:r.value?e.__(`Protect this term from updates`):e.__(`Protect this entry from updates`),disabled:h.value,"data-tolk-action":`protect`,onClick:t[6]||=e=>re(!0)},null,8,[`text`,`disabled`])])):A(``,!0)])):A(``,!0),E.value&&!r.value?(F(),j(`div`,zl,[M(`div`,Bl,[P(z(Dr),{for:`tolk-options-offer`,text:e.__(`Offer to translate new localizations`)},null,8,[`text`]),P(z(U),{id:`tolk-options-offer-description`},{default:B(()=>[N(R(e.__(`Asks whether to translate each localization you create. Only for your account.`)),1)]),_:1})]),P(z(bi),{id:`tolk-options-offer`,"model-value":p.value,"aria-describedby":`tolk-options-offer-description`,"onUpdate:modelValue":ie},null,8,[`model-value`])])):A(``,!0)])]),_:1},8,[`title`])):A(``,!0)],64))}},Ul=`localizable`,Wl={ok:{color:`green`,icon:`checkmark`,class:`text-green-600`},warning:{color:`amber`,icon:`alert-warning-exclamation-mark`,class:`text-amber-600`},error:{color:`red`,icon:`warning-diamond`,class:`text-red-600`}};function Gl(e){return`tolk-audit-${e}`}function Kl(e){return e?`${e}#${Gl(Ul)}`:null}function ql(e){return{ok:__(`OK`),warning:__(`Warning`),error:__(`Error`)}[e]??e}function Jl(e){return{label:ql(e),...Wl[e]??Wl.warning}}function Yl(e){let t=(Array.isArray(e)?e:[]).flatMap(e=>e.items??[]),n=t.filter(e=>e.level===`error`).length,r=t.filter(e=>e.level===`warning`).length;if(n===0&&r===0)return{level:`ok`,text:__(`Everything is set up. Tolk found nothing to change.`)};let i=[n>0?__n(`:count error|:count errors`,n):null,r>0?__n(`:count warning|:count warnings`,r):null].filter(Boolean);return{level:n>0?`error`:`warning`,text:__(`The audit found :problems. Errors keep Tolk from translating; warnings leave something untranslated or slower than it could be.`,{problems:i.join(`, `)})}}function Xl(e,t){return e?.id===`localizable`?t?__(`A text field that is not localizable is shared by every site, so Tolk does not translate it. Choose the fields that hold text in each language and make them localizable.`):__(`A text field that is not localizable is shared by every site, so Tolk does not translate it. Someone who may edit the Tolk settings and blueprints can make them localizable here, or with php please tolk:doctor --fix-localizable.`):e?.detail??``}function Zl(e){return typeof e?.namespace==`string`&&typeof e?.blueprint==`string`&&Array.isArray(e?.fields)}function Ql(e){return`${e.namespace}|${e.blueprint}`}function $l(e){let t=Array.isArray(e?.fields)?e.fields:[];return{editable:t.filter(e=>!e.fieldset),imported:t.filter(e=>!!e.fieldset)}}function eu(e){return e.label&&e.label!==e.handle?`${e.label} (${e.handle})`:e.handle}function tu(e){return __(`From the fieldset :fieldset: make it localizable in the fieldset, which changes every blueprint that imports it.`,{fieldset:e.fieldset})}function nu(e,t){let n=new Set(Array.isArray(t)?t:[]);return $l(e).editable.map(e=>e.handle).filter(e=>n.has(e))}function ru(e,t){let n=$l(e).editable.filter(e=>t.includes(e.handle)).map(eu).join(`, `);return __n(`This changes the blueprint file of :blueprint: :fields becomes localizable, so each site keeps its own value and Tolk translates it. Existing localizations keep the value they inherit until they are translated or edited.|This changes the blueprint file of :blueprint: :fields become localizable, so each site keeps its own value and Tolk translates them. Existing localizations keep the values they inherit until they are translated or edited.`,t.length,{blueprint:e.name,fields:n})}function iu(e){return e>0?__n(`:count field is now localizable.|:count fields are now localizable.`,e):__(`Nothing changed: the fields were already localizable.`)}function au(e,t){return __n(`:fields was not saved because it was hidden when you saved. Show it and translate it again.|:fields were not saved because they were hidden when you saved. Show them and translate them again.`,e.length,{fields:xa(e,t)})}function ou({PipelineStopped:e,store:t=Hs,registry:n=Ha,api:r=J,now:i=Date.now,running:a=e=>$.current(e),stop:o=e=>$.abort(e),onConfirmed:s=(e,t,n)=>tc.afterSave(e,t,n)}){let c=!1,l=null;function u(e=Statamic.$hooks){if(!c){c=!0;for(let t of[`entry`,`term`])e.on(`${t}.saving`,d),e.on(`${t}.saved`,f);e.on(`entry.published`,m)}}function d(r,i){let o=t(),s=a(X);if(nc.includes(o.phaseOf(`base`))&&s){l!==s&&(l=s,Statamic.$toast.error(__(`A translation is in progress. Wait for it to finish, or cancel it.`))),i(new e);return}let c=n.context(X),u=o.containers[X];c&&u?.reference&&u.reference===c.reference.value&&_o(c,u.delivered),r()}async function f(e,t,n){try{await p(n)}catch(e){console.error(e)}finally{e()}}async function p(e){let a=t(),o=a.containers[X],c=su(e,o);if(!o?.reference||c!==o.reference)return;let l=n.context(X),u=a.saved(X,i()),d=l?.reference.value===c?vo(l,u):Object.keys(u);n.refreshClean(X),(o.phase===`done`||o.phase===`error`)&&a.clearResult(X);try{let{not_saved:e=[],...t}=await r.post(`editor/confirm`,{reference:c,delivered:d}),n=a.containers[X];n?.reference===c&&(n.status=t,n.notSaved=e,s(X,t)),e.length&&Statamic.$toast.error(au(e,t),{duration:1e4})}catch(e){e?.status!==403&&Statamic.$toast.error(__(`The translation status could not be updated: :message`,{message:e?.message??``}))}}function m(e,t,n){try{h(n)}catch(e){console.error(e)}g(n).catch(e=>console.error(e)),e()}function h(e){let r=t(),s=r.containers[X];if(!s?.reference||su(e,s)!==s.reference)return;let c=s.phase,l=nc.includes(c)&&!!a(`base`),u=Object.keys(s.delivered),d=n.context(X);o(X),d&&u.length&&Co(d,s.snapshot,u),r.saved(X,i()),(u.length||![`idle`,`offer`].includes(c))&&r.clearResult(X),(u.length||l)&&Statamic.$toast.info(__(`Publishing discarded the unsaved translation. Translate again to fill in the form.`))}async function g(e){let n=t().containers[X],i=su(e,n);if(n?.reference&&i===n.reference)try{let e=await r.get(`editor/status`,{reference:i}),n=t().containers[X];n?.reference===i&&(n.status=e,s(X,e,{published:!0}))}catch(e){e?.status!==403&&Statamic.$toast.error(__(`The translation status could not be updated: :message`,{message:e?.message??``}))}}return{listen:u,saving:d,saved:f,published:m}}function su(e,t){let n=e?.response?.data?.data;return typeof n?.reference==`string`?n.reference:typeof n?.id==`string`&&t?.reference?.startsWith(`term::${n.id}::`)?t.reference:e?.reference??null}var cu=`[data-tolk-offer], [data-tolk-options], [data-tolk-changes], [data-tolk-push-modal]`,lu=`[data-tolk-action]:not([disabled])`,uu=`[data-tolk-focus]`,du=`button:not([disabled]), [href], [tabindex="0"]`;function fu(e,{modals:t=null,doc:n=globalThis.document,wait:r=setTimeout,delays:i=[0,400]}={}){let a=null;function o(){let r=n?.activeElement,i=e();return!!(r&&i&&(i.contains(r)||t&&r.closest?.(t)))}function s(){return!n.activeElement||n.activeElement===n.body||n.activeElement===a}function c(){let t=e();if(!t?.isConnected||!s())return;let n=t.querySelector(lu),r=n??t.querySelector(uu)??t.querySelector(du);r?.focus(),a=n?null:r}return{holds:o,restore:c,changing(){o()&&i.forEach(e=>r(c,e))}}}var pu={class:`sr-only`,"aria-live":`polite`,"data-tolk-announcement":``},mu={key:0,class:`flex items-center gap-2`},hu={key:0,class:`space-y-2`,"data-tolk-localization":``},gu={class:`flex flex-wrap items-center justify-between gap-x-6 gap-y-3`},_u={class:`flex flex-wrap items-center gap-2`},vu={key:0,class:`flex flex-wrap items-center gap-2`,"data-tolk-actions":``},yu={key:2,class:`flex flex-wrap items-center gap-2`,"data-tolk-copies":``},bu=[`href`],xu={key:1,class:`flex items-center gap-2`,tabindex:`-1`,"data-tolk-focus":``,"data-tolk-phase":`planning`},Su={key:2,class:`space-y-2`,"data-tolk-phase":`working`},Cu={class:`flex flex-wrap items-center justify-between gap-2`},wu={key:3,class:`space-y-1`,"data-tolk-phase":`error`},Tu={class:`flex items-center gap-2`},Eu={key:4,class:`space-y-1`,"data-tolk-summary":``},Du={key:1,class:`flex flex-wrap items-center gap-2`},Ou={key:5,class:`flex flex-wrap gap-2`},ku={key:6,class:`flex items-center gap-2`,"data-tolk-not-saved":``},Au={key:7,class:`space-y-2`,"data-tolk-origin":``},ju={class:`flex items-center gap-2`},Mu={class:`grid grid-cols-[auto_auto_minmax(0,1fr)] items-center gap-x-3 gap-y-1.5 ps-6`},Nu=[`data-tolk-site`],Pu=[`href`],Fu=[`href`],Iu={__name:`EditorBanner`,props:{containerName:{type:String,required:!0}},setup(e){let t=e,n=ti(),r=Hs(),i=t.containerName,{failure:a,stop:o}=Ac({name:i,ctx:n,store:r});lt(o);let s=O(()=>r.containers[i]??null),c=O(()=>s.value?.phase??`idle`),l=Kl(Statamic.$config.get(`tolk.auditUrl`)),u=O(()=>ua(s.value?.status??null)),d=O(()=>mc(s.value)),f=O(()=>fc(s.value)),p=O(()=>rc.includes(s.value?.error?.code)),h=O(()=>Sa(s.value?.summary??null,s.value?.status??null,{retry:f.value&&!p.value})),g=O(()=>s.value?.notSaved?.length?au(s.value.notSaved,s.value.status):null),_=O(()=>Ec(c.value,u.value)),v=O(()=>uc(s.value)),y=O(()=>{let e=s.value?.request;return e?.kind===`translate`&&e.fields?.length===1?xa(e.fields,s.value.status):null}),b=O(()=>{let e=u.value.localization?.target?.name??``;return s.value?.progress?.cancelling?__(`Cancelling. Fields already on their way are still filled in.`):s.value?.request?.kind===`review`?__(`Reviewing the translation…`):y.value?__(`Translating :field into :site…`,{field:y.value,site:e}):__(`Translating into :site…`,{site:e})}),x=O(()=>{switch(c.value){case`planning`:return __(`Preparing the translation…`);case`working`:return b.value;case`error`:return s.value?.error?.message??``;case`done`:return[h.value?.translated,h.value?.reviewed].filter(Boolean).join(` `);default:return``}}),S=jc();bn(()=>s.value?.summary,()=>S.hide());let C=O(()=>!!u.value.origin?.upToDate&&!u.value.localization&&!s.value?.push),w=O(()=>!n.readOnly.value&&(a.value!==null||u.value.visible&&!C.value)),ee=O(()=>Ha.dirtyHandles(i).length>0),T=Statamic.$config.get(`tolk.settingsUrl`),E=O(()=>Tc(s.value?.reference)),te=I(null),D=fu(()=>te.value?.$el??null,{modals:cu});bn([c,()=>s.value?.push?.phase],()=>D.changing()),bn(w,e=>{!e&&D.holds()&&nt(()=>document.getElementById(`content-card`)?.focus())});function ne(e){$.translate(i,{mode:e})}function re(){$.translate(i,{mode:`all`,fields:u.value.localization.copies.map(e=>e.handle),overwriteManual:!0})}async function ie(){let e=D.holds(),t=await $.undo(i);e&&(await nt(),D.restore()),t?.kept.length&&Statamic.$toast.info(hc(t.kept,s.value?.status))}return(e,t)=>{let n=Nt(`tooltip`);return w.value?(F(),k(z(H),{key:0,ref_key:`card`,ref:te,class:`mb-6 space-y-3`,"data-tolk-banner":``},{default:B(()=>[M(`p`,pu,R(x.value),1),z(a)?(F(),j(`div`,mu,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-red-600`,"aria-hidden":`true`}),P(z(q),{variant:`danger`},{default:B(()=>[N(R(e.__(`The translation status could not be loaded: :message`,{message:z(a).message})),1)]),_:1})])):(F(),j(m,{key:1},[u.value.localization?(F(),j(`div`,hu,[M(`div`,gu,[M(`div`,_u,[P(z(Sr),{name:`dictionary-language-book`,class:`size-4 shrink-0 text-gray-500`,"aria-hidden":`true`}),P(z(q),null,{default:B(()=>[N(R(u.value.localization.lead),1)]),_:1}),(F(!0),j(m,null,L(u.value.localization.parts,e=>En((F(),k(z(Pn),{key:e.key,text:e.text,color:z(oa)(e.key),tabindex:`0`,"data-tolk-part":e.key},null,8,[`text`,`color`,`data-tolk-part`])),[[n,e.description]])),128))]),_.value?(F(),j(`div`,vu,[c.value===`idle`?(F(),j(m,{key:0},[u.value.localization.translate?(F(),k(z(V),{key:0,variant:`primary`,size:`sm`,"data-tolk-action":`translate`,onClick:t[0]||=e=>ne(`missing`)},{default:B(()=>[N(R(e.__(`Translate`)),1)]),_:1})):A(``,!0),u.value.localization.update?(F(),k(z(V),{key:1,size:`sm`,"data-tolk-action":`update`,onClick:t[1]||=e=>ne(`update`)},{default:B(()=>[N(R(e.__(`Update`)),1)]),_:1})):A(``,!0)],64)):A(``,!0),v.value?(F(),k(z(V),{key:1,size:`sm`,"data-tolk-action":`review`,onClick:t[2]||=e=>z($).review(z(i))},{default:B(()=>[N(R(e.__(`Review`)),1)]),_:1})):A(``,!0),P(Hl,{"container-name":z(i),status:s.value.status},null,8,[`container-name`,`status`])])):A(``,!0)]),u.value.localization.autoUpdated?(F(),k(z(U),{key:0,"data-tolk-auto-updated":``},{default:B(()=>[N(R(u.value.localization.autoUpdated),1)]),_:1})):A(``,!0),u.value.localization.incompleteNote?(F(),k(z(U),{key:1},{default:B(()=>[N(R(u.value.localization.incompleteNote),1)]),_:1})):A(``,!0),u.value.localization.copiesNote?(F(),j(`div`,yu,[P(z(U),null,{default:B(()=>[N(R(u.value.localization.copiesNote),1)]),_:1}),_.value&&c.value===`idle`&&u.value.localization.translateCopies?(F(),k(z(V),{key:0,size:`sm`,"data-tolk-action":`translate-copies`,onClick:re},{default:B(()=>[N(R(u.value.localization.translateCopiesLabel),1)]),_:1})):A(``,!0)])):A(``,!0),u.value.localization.hint?(F(),k(z(U),{key:3,"data-tolk-not-localizable":``},{default:B(()=>[N(R(u.value.localization.hint)+` `,1),z(l)?(F(),j(`a`,{key:0,href:z(l),"data-tolk-audit-link":``},R(e.__(`Open the setup audit`)),9,bu)):(F(),j(m,{key:1},[N(R(e.__(`Run php please tolk:doctor for details.`)),1)],64))]),_:1})):A(``,!0)])):A(``,!0),c.value===`planning`?(F(),j(`div`,xu,[P(z(q),null,{default:B(()=>[N(R(e.__(`Preparing the translation…`)),1)]),_:1})])):A(``,!0),c.value===`working`?(F(),j(`div`,Su,[M(`div`,Cu,[P(z(q),{"data-tolk-working-field":y.value?``:null},{default:B(()=>[N(R(b.value),1)]),_:1},8,[`data-tolk-working-field`]),P(z(V),{size:`sm`,variant:`ghost`,disabled:s.value.progress.cancelling,"data-tolk-action":`cancel`,onClick:t[3]||=e=>z($).cancel(z(i))},{default:B(()=>[N(R(e.__(`Cancel`)),1)]),_:1},8,[`disabled`])]),P(Ba,{value:s.value.progress.done,max:s.value.progress.total,label:s.value.request?.kind===`review`?e.__(`Review progress`):e.__(`Translation progress`)},null,8,[`value`,`max`,`label`]),s.value.progress.waiting?(F(),k(z(U),{key:0},{default:B(()=>[N(R(e.__(`The provider asked to wait. Trying again shortly.`)),1)]),_:1})):A(``,!0)])):A(``,!0),c.value===`error`?(F(),j(`div`,wu,[M(`div`,Tu,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-red-600`,"aria-hidden":`true`}),P(z(q),{variant:`danger`,"data-tolk-error":``},{default:B(()=>[N(R(s.value.error?.message),1)]),_:1})])])):A(``,!0),h.value&&(c.value===`done`||c.value===`error`)?(F(),j(`div`,Eu,[h.value.translated?(F(),k(z(q),{key:0,as:`p`,"data-tolk-summary-translated":``},{default:B(()=>[N(R(h.value.translated),1)]),_:1})):A(``,!0),h.value.reviewed?(F(),j(`div`,Du,[P(z(q),{"data-tolk-summary-reviewed":``},{default:B(()=>[N(R(h.value.reviewed),1)]),_:1}),h.value.corrections?(F(),k(z(V),{key:0,size:`sm`,variant:`ghost`,"data-tolk-action":`view-changes`,onClick:t[4]||=e=>z(S).show()},{default:B(()=>[N(R(e.__(`View changes`)),1)]),_:1})):A(``,!0)])):A(``,!0),h.value.reviewSkipped?(F(),k(z(U),{key:2,"data-tolk-summary-review-skipped":``},{default:B(()=>[N(R(h.value.reviewSkipped),1)]),_:1})):A(``,!0),h.value.cancelled?(F(),k(z(U),{key:3},{default:B(()=>[N(R(h.value.cancelled),1)]),_:1})):A(``,!0),h.value.incomplete?(F(),k(z(U),{key:4,"data-tolk-summary-incomplete":``},{default:B(()=>[N(R(h.value.incomplete),1)]),_:1})):A(``,!0),h.value.edited?(F(),k(z(U),{key:5,"data-tolk-summary-edited":``},{default:B(()=>[N(R(h.value.edited),1)]),_:1})):A(``,!0),h.value.hidden?(F(),k(z(U),{key:6,"data-tolk-summary-hidden":``},{default:B(()=>[N(R(h.value.hidden),1)]),_:1})):A(``,!0),h.value.manual?(F(),k(z(U),{key:7,"data-tolk-summary-manual":``},{default:B(()=>[N(R(h.value.manual),1)]),_:1})):A(``,!0),h.value.failed?(F(),k(z(U),{key:8,"data-tolk-summary-failed":``},{default:B(()=>[N(R(h.value.failed),1)]),_:1})):A(``,!0),h.value.unsaved?(F(),k(z(U),{key:9,"data-tolk-summary-unsaved":``},{default:B(()=>[N(R(h.value.unsaved),1)]),_:1})):A(``,!0)])):A(``,!0),f.value||c.value===`done`&&d.value?(F(),j(`div`,Ou,[f.value?(F(),k(z(V),{key:0,size:`sm`,variant:`primary`,"data-tolk-action":`retry`,onClick:t[5]||=e=>z($).retry(z(i))},{default:B(()=>[N(R(p.value?e.__(`Start again`):e.__(`Retry`)),1)]),_:1})):A(``,!0),d.value?(F(),k(z(V),{key:1,size:`sm`,"data-tolk-action":`undo`,onClick:ie},{default:B(()=>[N(R(e.__(`Undo`)),1)]),_:1})):A(``,!0)])):A(``,!0),g.value?(F(),j(`div`,ku,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-amber-600`,"aria-hidden":`true`}),P(z(q),null,{default:B(()=>[N(R(g.value),1)]),_:1})])):A(``,!0),u.value.origin?(F(),j(`div`,Au,[M(`div`,ju,[P(z(Sr),{name:`dictionary-language-book`,class:`size-4 shrink-0 text-gray-500`,"aria-hidden":`true`}),P(z(q),null,{default:B(()=>[N(R(E.value?e.__(`Translations of this term:`):e.__(`Translations of this entry:`)),1)]),_:1})]),M(`ul`,Mu,[(F(!0),j(m,null,L(u.value.origin.localizations,e=>(F(),j(`li`,{key:e.site,class:`col-span-3 grid grid-cols-subgrid items-center`,"data-tolk-site":e.site},[e.editUrl?(F(),j(`a`,{key:0,href:e.editUrl,class:`text-sm font-medium underline`},R(e.name),9,Pu)):(F(),k(z(q),{key:1,variant:`strong`},{default:B(()=>[N(R(e.name),1)]),_:2},1024)),P(z(Pn),{text:e.label,color:e.color,class:`justify-self-start`},null,8,[`text`,`color`]),e.exists&&e.summary?(F(),k(z(U),{key:2},{default:B(()=>[N(R(e.summary),1)]),_:2},1024)):A(``,!0)],8,Nu))),128))]),u.value.origin.autoUpdate?(F(),k(z(U),{key:0,class:`ps-6`,"data-tolk-auto-update":``},{default:B(()=>[N(R(u.value.origin.autoUpdate),1)]),_:1})):A(``,!0),P(Zc,{"container-name":z(i),reference:s.value.reference,origin:u.value.origin,status:s.value.status,dirty:ee.value},null,8,[`container-name`,`reference`,`origin`,`status`,`dirty`])])):A(``,!0),u.value.localization?(F(),k(ll,{key:8,"container-name":z(i),status:s.value.status,open:c.value===`offer`},null,8,[`container-name`,`status`,`open`])):A(``,!0),z(S).open?(F(),k(Ra,{key:9,modal:z(S),corrections:s.value.summary?.corrections??[],reviewer:s.value.summary?.reviewer??null},null,8,[`modal`,`corrections`,`reviewer`])):A(``,!0),u.value.setup?(F(),k(z(U),{key:10,"data-tolk-setup":``},{default:B(()=>[N(R(e.__(`Translation is not set up yet.`))+` `,1),z(T)?(F(),j(`a`,{key:0,href:z(T)},R(e.__(`Open the Tolk settings`)),9,Fu)):(F(),j(m,{key:1},[N(R(e.__(`Ask an administrator to configure a provider in the Tolk settings.`)),1)],64))]),_:1})):A(``,!0)],64))]),_:1},512)):A(``,!0)}}},Lu={class:`flex items-center justify-end gap-3 pt-3 pb-1`},Ru={__name:`TranslateFieldConfirm`,emits:[`confirm`,`cancel`],setup(e,{emit:t}){let n=t,r=jc(),i=!1;pt(()=>r.show());function a(e){i||(i=!0,n(e))}function o(e){r.hide(),a(e)}function s(e){r.closed(e),e||a(`cancel`)}return(e,t)=>z(r).open?(F(),k(z(Wr),{key:0,open:``,title:e.__(`Translate from origin`),"data-tolk-field-confirm":``,onDismissed:t[2]||=e=>z(r).dismissed(),"onUpdate:open":s},{footer:B(()=>[M(`div`,Lu,[P(z(V),{variant:`ghost`,text:e.__(`Cancel`),"data-tolk-field-confirm-action":`cancel`,onClick:t[0]||=e=>o(`cancel`)},null,8,[`text`]),P(z(V),{variant:`primary`,text:e.__(`Translate`),"data-tolk-field-confirm-action":`translate`,onClick:t[1]||=e=>o(`confirm`)},null,8,[`text`])])]),default:B(()=>[P(z(q),{as:`p`},{default:B(()=>[N(R(e.__(`The current content of this field will be replaced.`)),1)]),_:1})]),_:1},8,[`title`])):A(``,!0)}},zu=`tolk-translate-field-confirm`;function Bu(e,t){if(e===t)return!0;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>Bu(e,t[n]));if(e===null||t===null||typeof e!=`object`||typeof t!=`object`)return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.hasOwn(t,n)&&Bu(e[n],t[n]))}function Vu({registry:e=Ha,store:t=Hs,translations:n=$,fieldActions:r=()=>Statamic.$fieldActions,config:i=()=>Statamic.$config,permissions:a=()=>Statamic.$permissions,toast:o=()=>Statamic.$toast,components:s=()=>Statamic.$components,doc:c=()=>globalThis.document,wait:l=setTimeout}={}){let u=!1;function d({vm:n,fieldPathPrefix:r,handle:i,config:o,isReadOnly:s}){if(r||s||!o?.localizable||!a().has(`translate content`)||n&&n.publishContainer?.name!==`base`||e.others().length>0)return!1;let c=e.base(),l=t().containers[X],u=l?.status;if(!c||c.readOnly?.value||!u?.localization||l.reference!==c.reference.value)return!1;let d=Y(u.localization.fields)[i];return!la(u)&&!nc.includes(l.phase)&&Object.hasOwn(c.originValues?.value??{},i)&&!!d&&d.status!==`not_applicable`}async function f({handle:r,value:i}){let a=e.base(),s=t();if(!a||!Bu(i,a.values.value[r])){o().error(Tc(s.containers.base?.reference)?__(`This field is not part of the term being translated.`):__(`This field is not part of the entry being translated.`));return}if(nc.includes(s.phaseOf(`base`))||n.running(`base`)){o().error(__(`A translation is already running. Try again when it has finished.`));return}if(n.saving(`base`)){o().error(oc());return}let c=s.containers[X],l=await n.translate(X,{mode:`all`,fields:[r],overwriteManual:!0,replace:!0});if(s.containers.base===c){if(c.phase===`error`){o().error(c.error?.message||__(`Something went wrong.`));return}if(l&&!l.cancelled&&!l.delivered.includes(r)){let e=Sa(l,c.status);o().error(e.failed??e.edited??e.hidden??e.translated)}}}function p(e){return[...c()?.querySelectorAll(`label[for]`)??[]].find(t=>t.getAttribute(`for`)===`field_${e}`)?.closest(`[data-ui-input-group]`)?.querySelector(`[data-ui-field-header] [data-ui-dropdown-trigger]`)??null}function m(){let e=c()?.querySelector(`[data-tolk-banner]`);return e?.querySelector(`[data-tolk-action="cancel"]`)??e?.querySelector(`[data-tolk-focus]`)??null}function h(e){for(let t of[0,400])l(()=>{let t=c()?.activeElement;(!t||t===c().body)&&e()?.focus()},t)}function g(e){let t=s().append(zu,{props:{}});t.on(`confirm`,()=>{t.destroy(),f(e).catch(()=>o().error(__(`Something went wrong.`))),h(()=>m()??p(e.handle))}),t.on(`cancel`,()=>{t.destroy(),h(()=>p(e.handle))})}let _={get title(){return __(`Translate from origin`)},visible:d,run:g};function v(){if(!u){u=!0;for(let e of i().get(`tolk.fieldtypes`)??[])r().add(`${e}-fieldtype`,_)}}return{register:v,action:_,visible:d,run:g}}var Hu=Vu(),{Fieldtype:Uu,IndexFieldtype:Wu,FieldtypeMixin:Gu,HasActionsMixin:Ku,HasInputOptionsMixin:qu,HasPreferencesMixin:Ju,IndexFieldtypeMixin:Yu,InlineEditForm:Xu,DateFormatter:Zu,NumberFormatter:Qu,ItemActions:$u,RelatedItem:ed,RestoreRevision:td,RevisionHistory:nd,RevisionPreview:rd,SaveButtonOptions:id,SortableList:ad,requireElevatedSession:od,requireElevatedSessionIf:sd,clone:cd,debounce:ld,deepClone:ud,resetValuesFromResponse:dd}=__STATAMIC__.core,fd=[`data-tolk-model-note`],pd={__name:`ModelSelect`,props:Uu.props,emits:Uu.emits,setup(e,{expose:t,emit:n}){let r=n,i=e,{expose:a,isReadOnly:o,update:s}=Uu.use(r,i),c=O(()=>hl(i.meta,i.value)),l=O(()=>dl(i.value)??`automatic`);function u(e){let t=gl(e,c.value);t!==void 0&&t!==dl(i.value)&&s(t)}return t(a),(e,t)=>(F(),k(z(Wn),{id:e.id,"model-value":l.value,options:c.value,"read-only":z(o),placeholder:e.__(`Choose a model`),taggable:``,"data-tolk-model-select":``,"onUpdate:modelValue":u},{option:B(e=>[M(`span`,{class:it([`truncate`,{"opacity-50":e.disabled}])},R(e.label),3),e.note?(F(),j(`span`,{key:0,class:it([`ms-auto shrink-0 text-xs text-gray-500 dark:text-gray-400`,{"opacity-50":e.disabled}]),"data-tolk-model-note":e.value},R(e.note),11,fd)):A(``,!0)]),_:1},8,[`id`,`model-value`,`options`,`read-only`,`placeholder`]))}};function md(e){let t=e?.fake_engine===!0;return(Array.isArray(e?.providers)?e.providers:[]).map(e=>{let n=e.configured===!0;return{provider:e.provider,label:e.label,badge:hd(n),source:gd(e.source),hint:n?null:_d(e.env),testable:n||t}})}function hd(e){return e?{text:__(`Configured`),color:`green`}:{text:__(`No API key`),color:`default`}}function gd(e){return{ai:__(`The key comes from config/ai.php, which Tolk shares with the rest of the site.`),addon:__(`The key is Tolk's own, from the addon's config.`)}[e]??null}function _d(e){return e?.ai?__(`Add :variable to the .env file, or :override to give Tolk a key of its own.`,{variable:e.ai,override:e.addon}):null}function vd(e){if(e?.ok!==!0)return{ok:!1,text:e?.error||__(`The test failed.`)};let t={model:e.label||e.model,ms:e.latency_ms};return{ok:!0,text:e.fake?__(`The fake engine answered for :model in :ms ms, without calling the provider.`,t):__(`:model answered in :ms ms.`,t)}}async function yd(e,t=J){try{return await t.post(`providers/test`,{provider:e})}catch(e){return{ok:!1,error:e.message}}}var bd={class:`divide-y divide-gray-200 dark:divide-gray-700`,"data-tolk-providers":``},xd=[`data-tolk-provider`],Sd={class:`flex flex-wrap items-center gap-2`},Cd={__name:`ProvidersStatus`,props:Uu.props,emits:Uu.emits,setup(e,{expose:t,emit:n}){let r=n,i=e,{expose:a}=Uu.use(r,i),o=O(()=>md(i.meta)),s=Dt({}),c=Dt({});async function l(e){s[e]=!0,c[e]=null;try{c[e]=vd(await yd(e))}finally{s[e]=!1}}return t(a),(e,t)=>(F(),j(`div`,bd,[(F(!0),j(m,null,L(o.value,t=>(F(),j(`div`,{key:t.provider,class:`space-y-1 py-3 first:pt-0 last:pb-0`,"data-tolk-provider":t.provider},[M(`div`,Sd,[P(z(q),{variant:`strong`},{default:B(()=>[N(R(t.label),1)]),_:2},1024),P(z(Pn),{text:t.badge.text,color:t.badge.color,"data-tolk-provider-status":``},null,8,[`text`,`color`]),t.testable?(F(),k(z(V),{key:0,class:`ms-auto`,size:`sm`,text:e.__(`Test connection`),loading:!!s[t.provider],disabled:!!s[t.provider],"data-tolk-provider-test":``,onClick:e=>l(t.provider)},null,8,[`text`,`loading`,`disabled`,`onClick`])):A(``,!0)]),t.source?(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.source),1)]),_:2},1024)):A(``,!0),t.hint?(F(),k(z(U),{key:1},{default:B(()=>[N(R(t.hint),1)]),_:2},1024)):A(``,!0),c[t.provider]?(F(),k(z(q),{key:2,variant:c[t.provider].ok?`success`:`danger`,"data-tolk-provider-result":c[t.provider].ok?`ok`:`failed`},{default:B(()=>[N(R(c[t.provider].text),1)]),_:2},1032,[`variant`,`data-tolk-provider-result`])):A(``,!0)],8,xd))),128))]))}},{asMap:wd}=J,Td=`glossary`;function Ed(e,t=J){let n=wd(e),r=Object.hasOwn(n,`translator_model`)?{model:n.translator_model||null}:{};return t.post(`site-profile/generate`,r)}function Dd(e){return typeof e==`string`&&e.trim()!==``}function Od(e){return String(e??``).normalize(`NFKD`).toLowerCase().replace(/\p{Mn}+/gu,``).replace(/[\s\p{Z}]+/gu,` `).trim()}function kd(e){let t=e?.site;return Array.isArray(t)?t.length===0:!t}function Ad(e){return new Set((Array.isArray(e)?e:[]).filter(kd).map(e=>Od(e?.term)).filter(e=>e!==``))}function jd(e,t,n={}){let r=Ad(t);return(Array.isArray(e)?e:[]).map(e=>{let t=r.has(Od(e));return{term:e,inGlossary:t,chosen:!t&&n[e]!==!0}})}function Md(){return Array.from(crypto.getRandomValues(new Uint8Array(12)),e=>`abcdefghijklmnopqrstuvwxyz0123456789`[e%36]).join(``)}function Nd(e){return JSON.parse(JSON.stringify(e??{}))}function Pd(e,t,n,r=Md){let i=Array.isArray(t)?t:[],a=wd(n),o=Ad(i),s={...wd(a.existing)},c=[];for(let t of e){let e=Od(t);if(e===``||o.has(e))continue;let n=r();o.add(e),s[n]=Nd(wd(a.new)),c.push({...Nd(wd(a.defaults)),term:t.trim(),do_not_translate:!0,_id:n})}return{rows:[...i,...c],meta:{...a,existing:s},added:c.map(e=>e.term)}}var Fd={class:`space-y-3`,"data-tolk-site-profile":``},Id={key:0,class:`flex flex-wrap items-center gap-3`},Ld={key:3,class:`space-y-2`,"data-tolk-site-profile-terms":``},Rd={class:`space-y-1`},zd=[`data-tolk-site-profile-term`],Bd={class:`flex flex-wrap items-center gap-3`},Vd={class:`list-disc ps-5 text-sm`},Hd=[`data-tolk-site-profile-term`],Ud={__name:`SiteProfile`,props:Uu.props,emits:Uu.emits,setup(e,{expose:t,emit:n}){let r=n,i=e,{expose:a,isReadOnly:o,update:s}=Uu.use(r,i),c=ti(),l=I(!1),u=I(!1),d=I(null),f=I(null),p=I(null),h=Dt({}),g=O(()=>Y(c?.values.value)),_=O(()=>!o.value&&Object.hasOwn(g.value,`glossary`)&&Object.hasOwn(Y(c?.meta.value),`glossary`)),v=O(()=>jd(f.value?.terms,g.value[Td],h)),y=O(()=>v.value.filter(e=>e.chosen).map(e=>e.term));function b(){Dd(i.value)?u.value=!0:x()}async function x(){u.value=!1,l.value=!0,d.value=null;try{let e=await Ed(g.value);s(e.profile),f.value={label:e.label||e.model,terms:Array.isArray(e.terms)?e.terms:[]},p.value=null,Object.keys(h).forEach(e=>delete h[e])}catch(e){d.value=e.message}finally{l.value=!1}}function S(e,t){h[e]=!t}function C(){let e=Pd(y.value,g.value[Td],c.meta.value[Td]);c.setFieldMeta(Td,e.meta),c.setFieldValue(Td,e.rows),p.value=e.added.length}return t(a),(e,t)=>(F(),j(`div`,Fd,[P(z(Fi),{id:e.id,name:e.handle,"model-value":e.value,"read-only":z(o),rows:8,"onUpdate:modelValue":z(s)},null,8,[`id`,`name`,`model-value`,`read-only`,`onUpdate:modelValue`]),z(o)?A(``,!0):(F(),j(`div`,Id,[P(z(V),{size:`sm`,icon:`ai-sparks`,text:e.__(`Generate`),loading:l.value,disabled:l.value,"data-tolk-site-profile-generate":``,onClick:b},null,8,[`text`,`loading`,`disabled`]),P(z(U),null,{default:B(()=>[N(R(e.__(`Has the translator write a profile from the content of the default site. Check it before you save.`)),1)]),_:1})])),d.value?(F(),k(z(q),{key:1,variant:`danger`,"data-tolk-site-profile-error":``},{default:B(()=>[N(R(d.value),1)]),_:1})):A(``,!0),f.value?(F(),k(z(U),{key:2,"data-tolk-site-profile-written":``},{default:B(()=>[N(R(e.__(`Written by :model. It is not saved until you save the settings.`,{model:f.value.label})),1)]),_:1})):A(``,!0),v.value.length?(F(),j(`div`,Ld,[P(z(q),{variant:`strong`},{default:B(()=>[N(R(e.__(`Names to keep untranslated`)),1)]),_:1}),_.value?(F(),j(m,{key:0},[M(`div`,Rd,[(F(!0),j(m,null,L(v.value,t=>(F(),j(`div`,{key:t.term,"data-tolk-site-profile-term":t.term},[P(z(Vn),{"model-value":t.chosen,label:t.term,description:t.inGlossary?e.__(`Already in the glossary`):null,disabled:t.inGlossary,"onUpdate:modelValue":e=>S(t.term,e)},null,8,[`model-value`,`label`,`description`,`disabled`,`onUpdate:modelValue`])],8,zd))),128))]),M(`div`,Bd,[P(z(V),{size:`sm`,text:e.__(`Add to glossary`),disabled:y.value.length===0,"data-tolk-site-profile-add":``,onClick:C},null,8,[`text`,`disabled`]),p.value===null?A(``,!0):(F(),k(z(U),{key:0,"data-tolk-site-profile-added":``},{default:B(()=>[N(R(e.__n(`Added :count name to the glossary with Do not translate on. Save the settings to keep it.|Added :count names to the glossary with Do not translate on. Save the settings to keep them.`,p.value)),1)]),_:1}))])],64)):(F(),j(m,{key:1},[M(`ul`,Vd,[(F(!0),j(m,null,L(v.value,e=>(F(),j(`li`,{key:e.term,"data-tolk-site-profile-term":e.term},R(e.term),9,Hd))),128))]),P(z(U),null,{default:B(()=>[N(R(e.__(`Add them to the glossary with Do not translate on, so that every translation keeps them.`)),1)]),_:1})],64))])):A(``,!0),u.value?(F(),k(z(Kn),{key:4,open:``,"onUpdate:open":t[0]||=e=>u.value=e,title:e.__(`Replace the site profile?`),"body-text":e.__(`A new profile replaces the text in this field. Nothing is saved until you save the settings.`),"button-text":e.__(`Generate`),onConfirm:x},null,8,[`title`,`body-text`,`button-text`])):A(``,!0)]))}},{Form:Wd,Head:Gd,Link:Kd,router:qd,toggleArchitecturalBackground:Jd,useArchitecturalBackground:Yd,useForm:Xd,usePage:Zd,usePoll:Qd}=__STATAMIC__.inertia,$d={class:`mx-auto max-w-page space-y-6`,"data-tolk-audit":``},ef={class:`flex flex-wrap items-center gap-2`},tf={key:1,class:`space-y-3`},nf=[`data-tolk-item-level`],rf=[`data-tolk-blueprint`],af={class:`flex flex-wrap items-center justify-between gap-2`},of={class:`flex items-center gap-2`},sf=[`href`],cf={class:`space-y-2`},lf=[`data-tolk-field`],uf=[`data-tolk-field-imported`],df=[`href`],ff={key:1,class:`space-y-1 ps-6`},pf=[`data-tolk-field`],mf={class:`text-xs text-gray-600 dark:text-gray-400`},hf={key:1,class:`flex items-start gap-2`},gf={__name:`Audit`,props:{checks:{type:Array,default:()=>[]},canMakeLocalizable:{type:Boolean,default:!1},urls:{type:Object,required:!0}},setup(e){let t=e,n=I(t.checks),r=Dt({}),i=I(null),a=I(null),o=O(()=>Yl(n.value));bn(()=>t.checks,e=>n.value=e);function s(e,t){return(r[Ql(e)]??[]).includes(t)}function c(e,t,n){let i=Ql(e),a=(r[i]??[]).filter(e=>e!==t);r[i]=n?[...a,t]:a}function l(e){let t=nu(e,r[Ql(e)]);t.length>0&&(i.value={item:e,fields:t,text:ru(e,t)})}async function u(){let{item:e,fields:o}=i.value,s=Ql(e);i.value=null,a.value=s;try{let i=await $i(t.urls.localizable,{namespace:e.namespace,blueprint:e.blueprint,fields:o});n.value=i.checks,delete r[s],Statamic.$toast.success(iu(i.changed))}catch(e){Statamic.$toast.error(e.message)}finally{a.value=null}}return(t,d)=>(F(),j(`div`,$d,[P(z(Gd),{title:t.__(`Audit`)},null,8,[`title`]),P(z(br),{title:t.__(`Setup audit`),icon:`clipboard-check`},{default:B(()=>[P(z(Kd),{href:e.urls.overview,class:`text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200`},{default:B(()=>[N(R(t.__(`Overview`)),1)]),_:1},8,[`href`]),P(z(V),{text:t.__(`Check again`),icon:`sync`,"data-tolk-audit-reload":``,onClick:d[0]||=e=>z(qd).reload()},null,8,[`text`])]),_:1},8,[`title`]),P(z(H),{class:`flex items-start gap-3`,"data-tolk-audit-summary":``,"data-tolk-audit-level":o.value.level},{default:B(()=>[P(z(Sr),{name:z(Jl)(o.value.level).icon,class:it([`mt-0.5 size-5 shrink-0`,z(Jl)(o.value.level).class]),"aria-hidden":`true`},null,8,[`name`,`class`]),P(z(q),null,{default:B(()=>[N(R(o.value.text),1)]),_:1})]),_:1},8,[`data-tolk-audit-level`]),(F(!0),j(m,null,L(n.value,n=>(F(),k(z(H),{id:z(Gl)(n.id),key:n.id,class:`space-y-3`,"data-tolk-check":n.id,"data-tolk-check-level":n.level},{default:B(()=>[M(`div`,ef,[P(z(Sr),{name:z(Jl)(n.level).icon,class:it([`size-4 shrink-0`,z(Jl)(n.level).class]),"aria-hidden":`true`},null,8,[`name`,`class`]),P(z(W),{size:`lg`,level:2},{default:B(()=>[N(R(n.title),1)]),_:2},1024),P(z(Pn),{text:z(Jl)(n.level).label,color:z(Jl)(n.level).color},null,8,[`text`,`color`])]),P(z(U),null,{default:B(()=>[N(R(z(Xl)(n,e.canMakeLocalizable)),1)]),_:2},1024),n.items.length===0?(F(),k(z(q),{key:0,"data-tolk-audit-nothing":``},{default:B(()=>[N(R(n.id===z(`localizable`)?t.__(`Every text field Tolk could translate is localizable.`):t.__(`Nothing to report.`)),1)]),_:2},1024)):(F(),j(`ul`,tf,[(F(!0),j(m,null,L(n.items,(i,o)=>(F(),j(`li`,{key:o,"data-tolk-item":``,"data-tolk-item-level":i.level},[z(Zl)(i)?(F(),j(`div`,{key:0,class:`space-y-2 rounded-lg border border-gray-200 p-3 dark:border-gray-700`,"data-tolk-blueprint":z(Ql)(i)},[M(`div`,af,[M(`div`,of,[P(z(Sr),{name:z(Jl)(i.level).icon,class:it([`size-4 shrink-0`,z(Jl)(i.level).class]),role:`img`,"aria-label":z(Jl)(i.level).label},null,8,[`name`,`class`,`aria-label`]),P(z(q),{class:`font-medium`},{default:B(()=>[N(R(i.name),1)]),_:2},1024)]),i.edit_url?(F(),j(`a`,{key:0,href:i.edit_url,class:`text-sm text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-blueprint-link":``},R(t.__(`Edit blueprint`)),9,sf)):A(``,!0)]),n.id===z(`localizable`)?(F(),j(m,{key:0},[M(`div`,cf,[(F(!0),j(m,null,L(z($l)(i).editable,t=>(F(),j(`div`,{key:t.handle,"data-tolk-field":t.handle},[e.canMakeLocalizable?(F(),k(z(Vn),{key:0,"model-value":s(i,t.handle),label:z(eu)(t),disabled:a.value!==null,"onUpdate:modelValue":e=>c(i,t.handle,e)},null,8,[`model-value`,`label`,`disabled`,`onUpdate:modelValue`])):(F(),k(z(q),{key:1},{default:B(()=>[N(R(z(eu)(t)),1)]),_:2},1024))],8,lf))),128)),(F(!0),j(m,null,L(z($l)(i).imported,n=>(F(),j(`div`,{key:n.handle,"data-tolk-field-imported":n.handle},[e.canMakeLocalizable?(F(),k(z(Vn),{key:0,"model-value":!1,label:z(eu)(n),description:z(tu)(n),disabled:``},null,8,[`label`,`description`])):(F(),j(m,{key:1},[P(z(q),null,{default:B(()=>[N(R(z(eu)(n)),1)]),_:2},1024),P(z(U),null,{default:B(()=>[N(R(z(tu)(n)),1)]),_:2},1024)],64)),n.fieldset_url?(F(),j(`a`,{key:2,href:n.fieldset_url,class:`ms-6 text-sm text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-fieldset-link":``},R(t.__(`Edit fieldset`)),9,df)):A(``,!0)],8,uf))),128))]),e.canMakeLocalizable&&z($l)(i).editable.length>0?(F(),k(z(V),{key:0,size:`sm`,variant:`primary`,text:t.__(`Make localizable`),loading:a.value===z(Ql)(i),disabled:a.value!==null||z(nu)(i,r[z(Ql)(i)]).length===0,"data-tolk-make-localizable":``,onClick:e=>l(i)},null,8,[`text`,`loading`,`disabled`,`onClick`])):A(``,!0)],64)):(F(),j(`ul`,ff,[(F(!0),j(m,null,L(i.fields,e=>(F(),j(`li`,{key:e.path??e.handle,"data-tolk-field":e.path??e.handle},[P(z(q),null,{default:B(()=>[N(R(e.label)+` `,1),M(`code`,mf,R(e.path??e.handle),1)]),_:2},1024)],8,pf))),128))]))],8,rf)):(F(),j(`div`,hf,[P(z(Sr),{name:z(Jl)(i.level).icon,class:it([`mt-0.5 size-4 shrink-0`,z(Jl)(i.level).class]),role:`img`,"aria-label":z(Jl)(i.level).label},null,8,[`name`,`class`,`aria-label`]),P(z(q),null,{default:B(()=>[N(R(i.text),1)]),_:2},1024)]))],8,nf))),128))]))]),_:2},1032,[`id`,`data-tolk-check`,`data-tolk-check-level`]))),128)),i.value?(F(),k(z(Kn),{key:0,open:``,title:t.__(`Make these fields localizable?`),"button-text":t.__(`Make localizable`),"data-tolk-localizable-confirm":``,"onUpdate:open":d[1]||=e=>i.value=e?i.value:null,onConfirm:u},{default:B(()=>[P(z(q),null,{default:B(()=>[N(R(i.value.text),1)]),_:1})]),_:1},8,[`title`,`button-text`])):A(``,!0)]))}},_f={class:`overflow-x-auto`},vf={__name:`RunsTable`,props:{runs:{type:Array,default:()=>[]}},setup(e){let t=e,n=vs(Statamic.$config.get(`sites`)),r=O(()=>t.runs.map(e=>{let t=xs({counts:e.counts}),r=js(e),i=Os(e.scope,n);return{id:e.id,url:e.url,status:e.status,what:i.what,automatic:i.automatic,sites:i.sites,progress:__(`:finished of :total`,{finished:Q(t.finished),total:Q(t.total)}),failed:t.counts.failed,tokens:r.input+r.output,cost:r.cost,date:bs(e.created_at),by:e.created_by?.name??(i.automatic?__(`Automatic update`):__(`Command line`))}}));return(e,t)=>(F(),j(`div`,_f,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(e.__(`Status`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Content`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Sites`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Items finished`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Usage`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Created`)),1)]),_:1})]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(r.value,t=>(F(),k(z(ki),{key:t.id,"data-tolk-run-row":``,"data-tolk-run-id":t.id},{default:B(()=>[P(z(G),null,{default:B(()=>[P(z(Kd),{href:t.url,class:`inline-flex`},{default:B(()=>[P(z(Pn),{text:z(ps)(t.status),color:z(ms)(t.status)},null,8,[`text`,`color`])]),_:2},1032,[`href`])]),_:2},1024),P(z(G),null,{default:B(()=>[P(z(Kd),{href:t.url,class:`text-blue-600 hover:underline dark:text-blue-400`},{default:B(()=>[N(R(t.what),1)]),_:2},1032,[`href`]),t.automatic?(F(),k(z(U),{key:0,"data-tolk-run-automatic":``},{default:B(()=>[N(R(e.__(`Automatic update`)),1)]),_:1})):A(``,!0)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(t.sites),1)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(t.progress)+` `,1),t.failed>0?(F(),k(z(U),{key:0},{default:B(()=>[N(R(e.__n(`:count failed|:count failed`,t.failed)),1)]),_:2},1024)):A(``,!0)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(e.__(`:tokens tokens`,{tokens:z(Q)(t.tokens)}))+` `,1),P(z(U),null,{default:B(()=>[N(R(t.cost===null?e.__(`Cost unknown`):z(ys)(t.cost)),1)]),_:2},1024)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(t.date)+` `,1),P(z(U),null,{default:B(()=>[N(R(t.by),1)]),_:2},1024)]),_:2},1024)]),_:2},1032,[`data-tolk-run-id`]))),128))]),_:1})]),_:1})]))}};function yf({scan:e,onChange:t=()=>{},concurrency:n=3}){let r=[],i=0,a=0,o=!1;function s(e){return e.generation===a}function c(){for(;i0;)l(r.shift())}async function l(n){i++,t(n.cell.key,{status:`loading`});try{let r=null;do{let i=await e({...n.cell,cursor:r,fresh:n.fresh});if(!s(n))return;r=i.cursor??null,t(n.cell.key,{...i,status:r===null?`done`:`loading`})}while(r!==null)}catch(e){s(n)&&t(n.cell.key,{status:`failed`,error:e?.message??String(e)})}finally{i--,c()}}function u(){a++,r=[]}function d(e,n){for(let i of e)r.push({cell:i,fresh:n,generation:a}),t(i.key,{status:`waiting`});c()}return{load(e,t={}){u(),o=t.fresh??!1,d(e,o)},retry(e){d([e],o)},stop:u,get active(){return i}}}var bf=[`entry`,`term`,`globals`,`nav`],xf=[`missing`,`untranslated`,`outdated`,`attention`,`current`],Sf={entry:`collections`,term:`taxonomies`,globals:`globals`,nav:`navs`};function Cf(e){return e===`current`?__(`Current`):sa(e)}function wf(e){return{entry:__(`Collections`),term:__(`Taxonomies`),globals:__(`Global sets`),nav:__(`Navigation`)}[e]??e}function Tf(e,t,n){return`${e}|${t}|${n}`}function Ef(e,t){let n=new Set((Array.isArray(e)?e:[]).flatMap(e=>e.sites??[]));return(Array.isArray(t)?t:[]).filter(e=>n.has(e.handle))}function Df(e){let t=Array.isArray(e)?e:[];return bf.map(e=>({type:e,label:wf(e),rows:t.filter(t=>t.type===e)})).filter(e=>e.rows.length>0)}function Of(e,t){return{key:Tf(e.type,e.handle,t),type:e.type,container:e.handle,site:t}}function kf(e){return(Array.isArray(e)?e:[]).flatMap(e=>(e.sites??[]).map(t=>Of(e,t)))}function Af(e){let t=Y(e?.counts),n=e=>Number(t[e])||0;return{counts:Object.fromEntries(xf.map(e=>[e,n(e)])),untracked:Number(e?.untracked)||0,unreadable:Number(e?.unreadable)||0,scanned:Number(e?.scanned)||0,missing:n(`missing`)+n(`untranslated`),outdated:n(`outdated`)}}function jf(e){let t=Af(e);return{...t,badges:xf.filter(e=>t.counts[e]>0).map(e=>({status:e,text:`${Cf(e)} ${t.counts[e]}`,color:oa(e)})),finished:e?.status===`done`,loading:e?.status===`waiting`||e?.status===`loading`,failed:e?.status===`failed`,error:e?.error??null}}function Mf(e,t,n,r){return{sites:[n],[Sf[e]]:[t],options:{mode:r}}}function Nf(e,t,n){let r={};for(let i of Array.isArray(e)?e:[]){if(!(i.sites??[]).includes(n))continue;let e=Y(t)[Tf(i.type,i.handle,n)];(e?.status!==`done`||Af(e).missing!==0)&&(r[Sf[i.type]]??=[]).push(i.handle)}return Object.keys(r).length>0?{sites:[n],...r,options:{mode:`missing`}}:null}function Pf({multisite:e,providers:t,fakeEngine:n}){return e?(Array.isArray(t)?t:[]).some(e=>e.configured)||n?null:`no_provider`:`single_site`}function Ff(e){let t=Y(e?.labels),n=Object.entries(Y(e?.models)).map(([e,n])=>({reference:e,model:t[e]??e,calls:Number(n?.calls)||0,input:Number(n?.input)||0,output:Number(n?.output)||0,cost:n?.cost===null||n?.cost===void 0?null:Number(n.cost),sources:Object.keys(Y(n?.sources))}));return{month:e?.month??``,rows:n,calls:n.reduce((e,t)=>e+t.calls,0),cost:n.some(e=>e.cost===null)?null:n.reduce((e,t)=>e+t.cost,0)}}function If(e){return{editor:__(`Editor`),run:__(`Runs`),cli:__(`Command line`),auto:__(`Automatic updates`)}[e]??e}function Lf(e,t=void 0){let n=/^(\d{4})-(\d{2})$/.exec(e??``);return n?new Intl.DateTimeFormat(t,{month:`long`,year:`numeric`}).format(Date.UTC(n[1],n[2]-1,15)):``}var Rf={class:`mx-auto max-w-page space-y-6`,"data-tolk-overview":``},zf={class:`flex flex-wrap gap-4 text-sm`},Bf=[`href`],Vf={class:`overflow-x-auto`},Hf={class:`flex flex-col items-start gap-1`},Uf={key:1,class:`space-y-1.5`},Wf={key:0,class:`flex flex-wrap gap-1`},Gf={key:5,class:`space-y-1`},Kf={key:6,class:`flex flex-wrap gap-1`},qf={class:`grid gap-6 lg:grid-cols-2`},Jf={class:`flex flex-wrap items-center justify-between gap-2`},Yf={class:`overflow-x-auto`},Xf={class:`space-y-2`},Zf=[`data-tolk-provider`],Qf=[`href`],$f={class:`flex flex-wrap items-baseline justify-between gap-2`},ep={__name:`Overview`,props:{multisite:{type:Boolean,default:!1},sites:{type:Array,default:()=>[]},rows:{type:Array,default:()=>[]},providers:{type:Array,default:()=>[]},fakeEngine:{type:Boolean,default:!1},usage:{type:Object,default:()=>({})},canResetUsage:{type:Boolean,default:!1},runs:{type:Array,default:()=>[]},urls:{type:Object,required:!0}},setup(e){let t=e,n=Dt({}),r=I(null),i=I(t.usage),a=I(!1),o=I(!1),s=Statamic.$config.get(`tolk`)?.settingsUrl??null,c=O(()=>Pf(t)),l=O(()=>Ef(t.rows,t.sites)),u=O(()=>Df(t.rows).map(e=>({...e,rows:e.rows.map(e=>({...e,cells:l.value.map(t=>{let r=Of(e,t.handle),i=e.sites.includes(t.handle),a=n[r.key];return{site:t,cell:r,status:i?a?.status??`waiting`:`none`,view:i?jf(a):null}})}))}))),d=O(()=>kf(t.rows)),f=O(()=>Ff(i.value)),p=O(()=>Object.values(n).some(e=>Number(e?.untracked)>0)),h=O(()=>Object.values(n).some(e=>Number(e?.unreadable)>0)),g=O(()=>Object.fromEntries(l.value.map(e=>[e.handle,Nf(t.rows,n,e.handle)]))),_=yf({scan:({key:e,...n})=>$i(t.urls.scan,n),onChange:(e,t)=>n[e]=t});pt(()=>{c.value===null&&_.load(d.value)}),lt(()=>_.stop());function v(){_.load(d.value,{fresh:!0})}async function y(e,n){r.value=e;try{let{url:e}=await $i(t.urls.store,n);_.stop(),qd.visit(e)}catch(e){Statamic.$toast.error(e.message),r.value=null}}async function b(){let e=Lf(f.value.month);a.value=!1,o.value=!0;try{i.value=(await $i(t.urls.resetUsage,{month:f.value.month})).usage,Statamic.$toast.success(__(`The usage of :month was reset.`,{month:e}))}catch(e){Statamic.$toast.error(e.message)}finally{o.value=!1}}return(t,n)=>(F(),j(`div`,Rf,[P(z(Gd),{title:t.__(`Translations`)},null,8,[`title`]),P(z(br),{title:t.__(`Translations`),icon:`dictionary-language-book`},{default:B(()=>[P(z(Kd),{href:e.urls.runs,class:`text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200`,"data-tolk-runs-link":``},{default:B(()=>[N(R(t.__(`All runs`)),1)]),_:1},8,[`href`]),c.value===null&&d.value.length>0?(F(),k(z(V),{key:0,text:t.__(`Count again`),icon:`sync`,"data-tolk-count-again":``,onClick:v},null,8,[`text`])):A(``,!0)]),_:1},8,[`title`]),c.value===`single_site`?(F(),k(z(H),{key:0,class:`space-y-3`,"data-tolk-overview-empty":`single_site`},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`This site has one language`)},null,8,[`text`]),P(z(q),null,{default:B(()=>[N(R(t.__(`Tolk translates the content of one site into the languages of the others. Add a site for each language in Statamic first; the overview then shows what is translated into each.`)),1)]),_:1}),P(z(Kd),{href:e.urls.audit,class:`text-sm text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-audit-link":``},{default:B(()=>[N(R(t.__(`Check the setup`)),1)]),_:1},8,[`href`])]),_:1})):c.value===`no_provider`?(F(),k(z(H),{key:1,class:`space-y-3`,"data-tolk-overview-empty":`no_provider`},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`No AI provider is set up`)},null,8,[`text`]),P(z(q),null,{default:B(()=>[N(R(t.__(`Tolk needs an API key of Anthropic, OpenAI or Google Gemini in the .env file before it can translate. The settings list the variables to set.`)),1)]),_:1}),M(`div`,zf,[z(s)?(F(),j(`a`,{key:0,href:z(s),class:`text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-settings-link":``},R(t.__(`Open the settings`)),9,Bf)):A(``,!0),P(z(Kd),{href:e.urls.audit,class:`text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-audit-link":``},{default:B(()=>[N(R(t.__(`Check the setup`)),1)]),_:1},8,[`href`])])]),_:1})):e.rows.length===0?(F(),k(z(H),{key:2,"data-tolk-overview-nothing":``},{default:B(()=>[P(z(q),null,{default:B(()=>[N(R(t.__(`No collection, taxonomy, global set or navigation has more than one site yet, so there is nothing to translate.`)),1)]),_:1})]),_:1})):(F(),k(z(H),{key:3,class:`space-y-3`,"data-tolk-matrix":``},{default:B(()=>[M(`div`,Vf,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(t.__(`Content`)),1)]),_:1}),(F(!0),j(m,null,L(l.value,e=>(F(),k(z(K),{key:e.handle,"data-tolk-column":e.handle},{default:B(()=>[M(`div`,Hf,[M(`span`,null,R(e.name),1),g.value[e.handle]?(F(),k(z(V),{key:0,size:`xs`,text:t.__(`Translate everything missing`),"aria-label":t.__(`Translate everything missing into :site`,{site:e.name}),loading:r.value===`site|${e.handle}`,disabled:r.value!==null,"data-tolk-site-action":e.handle,onClick:t=>y(`site|${e.handle}`,g.value[e.handle])},null,8,[`text`,`aria-label`,`loading`,`disabled`,`data-tolk-site-action`,`onClick`])):A(``,!0)])]),_:2},1032,[`data-tolk-column`]))),128))]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(u.value,e=>(F(),j(m,{key:e.type},[P(z(ki),{"data-tolk-group":e.type},{default:B(()=>[P(z(G),{colspan:l.value.length+1,class:`bg-gray-50 dark:bg-gray-900`},{default:B(()=>[P(z(W),{text:e.label},null,8,[`text`])]),_:2},1032,[`colspan`])]),_:2},1032,[`data-tolk-group`]),(F(!0),j(m,null,L(e.rows,e=>(F(),k(z(ki),{key:`${e.type}|${e.handle}`,"data-tolk-row":`${e.type}|${e.handle}`},{default:B(()=>[P(z(G),null,{default:B(()=>[P(z(q),null,{default:B(()=>[N(R(e.title),1)]),_:2},1024),P(z(U),null,{default:B(()=>[N(R(e.handle),1)]),_:2},1024)]),_:2},1024),(F(!0),j(m,null,L(e.cells,({site:i,cell:a,status:o,view:s})=>(F(),k(z(G),{key:i.handle,class:`align-top`,"data-tolk-cell":a.key,"data-tolk-cell-status":o},{default:B(()=>[s?(F(),j(`div`,Uf,[s.badges.length?(F(),j(`div`,Wf,[(F(!0),j(m,null,L(s.badges,e=>(F(),k(z(Pn),{key:e.status,text:e.text,color:e.color,"data-tolk-count":e.status},null,8,[`text`,`color`,`data-tolk-count`]))),128))])):A(``,!0),s.loading?(F(),k(z(U),{key:1},{default:B(()=>[N(R(t.__(`Counting…`)),1)]),_:1})):s.finished&&s.scanned===0?(F(),k(z(U),{key:2},{default:B(()=>[N(R(t.__(`Nothing to translate`)),1)]),_:1})):A(``,!0),s.untracked>0?(F(),k(z(U),{key:3,"data-tolk-untracked":``},{default:B(()=>[N(R(t.__n(`:count untracked field|:count untracked fields`,s.untracked)),1)]),_:2},1024)):A(``,!0),s.unreadable>0?(F(),k(z(U),{key:4,"data-tolk-unreadable":``},{default:B(()=>[N(R(t.__n(`:count item with unreadable state|:count items with unreadable state`,s.unreadable)),1)]),_:2},1024)):A(``,!0),s.failed?(F(),j(`div`,Gf,[P(z(q),{size:`sm`,variant:`danger`,"data-tolk-cell-error":``},{default:B(()=>[N(R(s.error),1)]),_:2},1024),P(z(V),{size:`xs`,text:t.__(`Try again`),"data-tolk-cell-retry":``,onClick:e=>z(_).retry(a)},null,8,[`text`,`onClick`])])):A(``,!0),s.missing>0||s.outdated>0?(F(),j(`div`,Kf,[s.missing>0?(F(),k(z(V),{key:0,size:`xs`,text:t.__(`Translate missing`),"aria-label":t.__(`Translate missing :content into :site`,{content:e.title,site:i.name}),loading:r.value===`${a.key}|missing`,disabled:r.value!==null,"data-tolk-cell-action":`missing`,onClick:t=>y(`${a.key}|missing`,z(Mf)(e.type,e.handle,i.handle,`missing`))},null,8,[`text`,`aria-label`,`loading`,`disabled`,`onClick`])):A(``,!0),s.outdated>0?(F(),k(z(V),{key:1,size:`xs`,text:t.__(`Update outdated`),"aria-label":t.__(`Update outdated :content in :site`,{content:e.title,site:i.name}),loading:r.value===`${a.key}|update`,disabled:r.value!==null,"data-tolk-cell-action":`update`,onClick:t=>y(`${a.key}|update`,z(Mf)(e.type,e.handle,i.handle,`update`))},null,8,[`text`,`aria-label`,`loading`,`disabled`,`onClick`])):A(``,!0)])):A(``,!0)])):(F(),k(z(U),{key:0},{default:B(()=>[...n[2]||=[N(`—`,-1)]]),_:1}))]),_:2},1032,[`data-tolk-cell`,`data-tolk-cell-status`]))),128))]),_:2},1032,[`data-tolk-row`]))),128))],64))),128))]),_:1})]),_:1})]),p.value?(F(),k(z(U),{key:0,"data-tolk-baseline-hint":``},{default:B(()=>[N(R(t.__(`Untracked fields were translated by hand without a record of their origin, so a change to the origin goes unnoticed. Run php please tolk:baseline to record the origin of each.`)),1)]),_:1})):A(``,!0),h.value?(F(),k(z(U),{key:1,"data-tolk-unreadable-hint":``},{default:B(()=>[N(R(t.__(`The translation state of some items cannot be read, so their status is unknown and translating them fails. Run php please tolk:doctor to list the files.`)),1)]),_:1})):A(``,!0)]),_:1})),M(`div`,qf,[P(z(H),{class:`space-y-3`,"data-tolk-usage":``},{default:B(()=>[M(`div`,Jf,[P(z(W),{size:`lg`,text:t.__(`Usage in :month`,{month:z(Lf)(f.value.month)})},null,8,[`text`]),e.canResetUsage&&f.value.rows.length>0?(F(),k(z(V),{key:0,size:`sm`,text:t.__(`Reset`),"aria-label":t.__(`Reset the usage of :month`,{month:z(Lf)(f.value.month)}),loading:o.value,"data-tolk-usage-reset":``,onClick:n[0]||=e=>a.value=!0},null,8,[`text`,`aria-label`,`loading`])):A(``,!0)]),f.value.rows.length===0?(F(),k(z(q),{key:0},{default:B(()=>[N(R(t.__(`No model was called this month.`)),1)]),_:1})):(F(),j(m,{key:1},[M(`div`,Yf,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(t.__(`Model`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Calls`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Tokens`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Cost`)),1)]),_:1})]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(f.value.rows,e=>(F(),k(z(ki),{key:e.reference,"data-tolk-usage-model":e.reference},{default:B(()=>[P(z(G),null,{default:B(()=>[N(R(e.model)+` `,1),P(z(U),null,{default:B(()=>[N(R(e.sources.map(z(If)).join(`, `)),1)]),_:2},1024)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(z(Q)(e.calls)),1)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(t.__(`:input in, :output out`,{input:z(Q)(e.input),output:z(Q)(e.output)})),1)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(e.cost===null?t.__(`Unknown`):z(ys)(e.cost)),1)]),_:2},1024)]),_:2},1032,[`data-tolk-usage-model`]))),128))]),_:1})]),_:1})]),P(z(U),{"data-tolk-usage-total":``},{default:B(()=>[N(R(f.value.cost===null?t.__n(`:calls call this month. The cost is unknown: a model without a price was called.|:calls calls this month. The cost is unknown: a model without a price was called.`,f.value.calls,{calls:z(Q)(f.value.calls)}):t.__n(`:calls call this month, an estimated :cost.|:calls calls this month, an estimated :cost.`,f.value.calls,{calls:z(Q)(f.value.calls),cost:z(ys)(f.value.cost)})),1)]),_:1})],64))]),_:1}),P(z(H),{class:`space-y-3`,"data-tolk-providers":``},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`Providers`)},null,8,[`text`]),M(`ul`,Xf,[(F(!0),j(m,null,L(e.providers,e=>(F(),j(`li`,{key:e.provider,class:`flex items-center justify-between gap-2`,"data-tolk-provider":e.provider},[P(z(q),null,{default:B(()=>[N(R(e.label),1)]),_:2},1024),P(z(Pn),tt({ref_for:!0},z(hd)(e.configured)),null,16)],8,Zf))),128))]),e.fakeEngine?(F(),k(z(U),{key:0,"data-tolk-fake-engine":``},{default:B(()=>[N(R(t.__(`The fake engine is on: translations are made up without calling a provider.`)),1)]),_:1})):A(``,!0),z(s)?(F(),j(`a`,{key:1,href:z(s),class:`text-sm text-blue-600 hover:underline dark:text-blue-400`},R(t.__(`Settings`)),9,Qf)):A(``,!0)]),_:1})]),P(z(H),{class:`space-y-3`,"data-tolk-latest-runs":``},{default:B(()=>[M(`div`,$f,[P(z(W),{size:`lg`,text:t.__(`Latest runs`)},null,8,[`text`]),e.runs.length>0?(F(),k(z(Kd),{key:0,href:e.urls.runs,class:`text-sm text-blue-600 hover:underline dark:text-blue-400`},{default:B(()=>[N(R(t.__(`All runs`)),1)]),_:1},8,[`href`])):A(``,!0)]),e.runs.length===0?(F(),k(z(q),{key:0},{default:B(()=>[N(R(t.__(`No translation runs yet.`)),1)]),_:1})):(F(),k(vf,{key:1,runs:e.runs},null,8,[`runs`]))]),_:1}),a.value?(F(),k(z(Kn),{key:4,open:``,danger:``,title:t.__(`Reset the usage of :month?`,{month:z(Lf)(f.value.month)}),"body-text":t.__(`The calls, tokens and costs counted this month are deleted, and counting starts again from zero. The runs keep their own usage.`),"button-text":t.__(`Reset`),"data-tolk-usage-reset-confirm":``,"onUpdate:open":n[1]||=e=>a.value=e,onConfirm:b},null,8,[`title`,`body-text`,`button-text`])):A(``,!0)]))}},tp={class:`mx-auto max-w-page space-y-6`,"data-tolk-runs":``},np={__name:`Index`,props:{runs:{type:Array,default:()=>[]},canReset:{type:Boolean,default:!1},urls:{type:Object,default:()=>({})}},setup(e){let t=e,n=I(!1),r=I(!1),i=O(()=>t.runs.some(e=>Vo.includes(e.status)));async function a(){n.value=!1,r.value=!0;try{let{deleted:e}=await $i(t.urls.reset);Statamic.$toast.success(__n(`:count run was deleted.|:count runs were deleted.`,e)),qd.reload({only:[`runs`]})}catch(e){Statamic.$toast.error(e.message)}finally{r.value=!1}}return(t,o)=>(F(),j(`div`,tp,[P(z(Gd),{title:t.__(`Translation runs`)},null,8,[`title`]),P(z(br),{title:t.__(`Translation runs`),icon:`dictionary-language-book`},{default:B(()=>[e.canReset&&i.value?(F(),k(z(V),{key:0,text:t.__(`Reset`),loading:r.value,"data-tolk-runs-reset":``,onClick:o[0]||=e=>n.value=!0},null,8,[`text`,`loading`])):A(``,!0)]),_:1},8,[`title`]),e.runs.length===0?(F(),k(z(H),{key:0,"data-tolk-runs-empty":``},{default:B(()=>[P(z(q),null,{default:B(()=>[N(R(t.__(`No translation runs yet. Runs started from a listing, the overview or the command line appear here.`)),1)]),_:1})]),_:1})):(F(),k(z(H),{key:1},{default:B(()=>[P(vf,{runs:e.runs},null,8,[`runs`])]),_:1})),n.value?(F(),k(z(Kn),{key:2,open:``,danger:``,title:t.__(`Delete the finished runs?`),"body-text":t.__(`Every completed, cancelled and aborted run is deleted with its results, and can no longer be resumed or retried. Pending and running runs stay. The translations they saved stay too.`),"button-text":t.__(`Delete`),"data-tolk-runs-reset-confirm":``,"onUpdate:open":o[1]||=e=>n.value=e,onConfirm:a},null,8,[`title`,`body-text`,`button-text`])):A(``,!0)]))}},rp=[`data-tolk-run-status`],ip={class:`flex flex-wrap items-center gap-2`},ap={class:`flex flex-wrap items-center gap-x-4 gap-y-1`,"data-tolk-run-counts":``},op={class:`space-y-3`},sp={class:`flex flex-wrap gap-2`},cp={class:`flex flex-wrap items-center justify-between gap-2`},lp={class:`space-y-3`},up={key:1,class:`flex flex-wrap gap-2`},dp={class:`grid gap-6 lg:grid-cols-2`},fp={class:`overflow-x-auto`},pp={class:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm`},mp={class:`text-gray-600 dark:text-gray-400`},hp=[`data-tolk-option`],gp={class:`flex flex-wrap items-baseline justify-between gap-2`},_p={key:0,class:`flex flex-wrap gap-x-10 gap-y-2 text-sm`},vp={class:`text-gray-600 dark:text-gray-400`},yp={"data-tolk-estimate-segments":``},bp={class:`text-gray-600 dark:text-gray-400`},xp={"data-tolk-estimate-chars":``},Sp={class:`text-gray-600 dark:text-gray-400`},Cp={"data-tolk-estimate-input":``},wp={class:`text-gray-600 dark:text-gray-400`},Tp={"data-tolk-estimate-output":``},Ep={class:`text-gray-600 dark:text-gray-400`},Dp={"data-tolk-estimate-cost":``},Op={class:`flex flex-wrap items-center justify-between gap-2`},kp={class:`w-56`},Ap={class:`overflow-x-auto`},jp=[`href`],Mp={key:1},Np={key:1,class:`flex flex-wrap items-center gap-2`},Pp=[`href`],Fp={key:1,class:`flex items-center justify-end gap-2`,"data-tolk-items-pages":``},Ip={__name:`Show`,props:{state:{type:Object,required:!0},urls:{type:Object,required:!0},models:{type:Object,default:()=>({})},lanes:{type:Number,default:1}},setup(e){let t=e,n=I(t.state),r=I(t.state.run?.estimate??null),i=I([]),a=I(null),o=I(t.state.pagination?.page??1),s=t.state.pagination?.per_page??50,c=I(`all`),l=vs(Statamic.$config.get(`sites`)),u=tc.following(t.state.run?.id),d=Ls({urls:t.urls,lanes:t.lanes,dirty:u?null:`tolk-run`,onState:e=>{n.value=e,r.value=e.run?.estimate??r.value,o.value=Is(o.value,e.pagination)},onEstimate:e=>r.value=e,onFailures:e=>i.value=e,query:()=>({page:o.value,per_page:s,...c.value===`all`?{}:{status:c.value}})});function f(e){d.driving&&(e.preventDefault(),e.returnValue=``)}let p=()=>{};pt(()=>{p=tc.lend(t.state.run?.id),d.follow(t.state),window.addEventListener(`beforeunload`,f)}),lt(()=>{d.stop(),p(n.value),window.removeEventListener(`beforeunload`,f)});let h=O(()=>n.value.run??{}),g=O(()=>h.value.status),_=O(()=>xs(n.value)),v=O(()=>Ss(n.value)),y=O(()=>ws(n.value)),b=O(()=>Os(h.value.scope,l)),x=O(()=>Ts(n.value.breakdown,l)),S=O(()=>Es(h.value.scope)),C=Kl(Statamic.$config.get(`tolk.auditUrl`)),w=O(()=>Ds(h.value.scope)),ee=O(()=>ks(h.value.options,t.models)),T=O(()=>As(r.value,_.value.total)),E=O(()=>js(h.value,t.models)),te=O(()=>(n.value.items??[]).map(e=>Fs(e,l))),D=O(()=>n.value.pagination??{page:1,last_page:1,total:0}),ne=O(()=>g.value===`running`&&h.value.driver===`browser`),re=O(()=>g.value===`running`&&!!n.value.stalled),ie=O(()=>ls.filter(e=>_.value.counts[e]>0).map(e=>({key:e,text:`${Q(_.value.counts[e])} ${hs(e).toLowerCase()}`}))),ae=O(()=>[{label:__(`All items`),value:`all`},...ls.map(e=>({label:hs(e),value:e}))]),oe=I(null),se=fu(()=>oe.value),ce=jc(),le=I([]);function ue(e){le.value=e.corrections,ce.show()}bn(g,()=>se.changing());let de=O(()=>{let e=h.value.created_by?.name,t=bs(h.value.created_at);return b.value.automatic?e?__(`Started automatically on :date, when :name saved the entry.`,{name:e,date:t}):__(`Started automatically on :date, when the entry was saved.`,{date:t}):e?__(`Created by :name on :date`,{name:e,date:t}):__(`Created on :date from the command line`,{date:t})});async function fe(e,t){let n=se.holds();a.value=e;try{let n=await t();e===`retry`&&n?.retried===0&&Statamic.$toast.info(__(`No item failed, so nothing was retried.`))}catch(e){Statamic.$toast.error(e.message)}finally{a.value=null,n&&nt(se.restore)}}async function pe(e){o.value=Math.max(1,e);try{await d.refresh()}catch(e){Statamic.$toast.error(e.message)}}function me(e){c.value=e??`all`,pe(1)}return(t,r)=>(F(),j(`div`,{ref_key:`root`,ref:oe,class:`mx-auto max-w-page space-y-6`,"data-tolk-run":``,"data-tolk-run-status":g.value},[P(z(Gd),{title:t.__(`Translation run`)},null,8,[`title`]),P(z(br),{title:t.__(`Translation run`),icon:`dictionary-language-book`},{default:B(()=>[P(z(Kd),{href:e.urls.index,class:`text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200`,"data-tolk-runs-link":``},{default:B(()=>[N(R(t.__(`All runs`)),1)]),_:1},8,[`href`]),v.value.cancel?(F(),k(z(V),{key:0,text:t.__(`Cancel`),loading:a.value===`cancel`,disabled:a.value!==null,"data-tolk-action":`cancel`,onClick:r[0]||=e=>fe(`cancel`,z(d).cancel)},null,8,[`text`,`loading`,`disabled`])):A(``,!0),v.value.start?(F(),k(z(V),{key:1,variant:`primary`,text:t.__(`Start`),loading:a.value===`start`,disabled:a.value!==null,"data-tolk-action":`start`,onClick:r[1]||=e=>fe(`start`,z(d).start)},null,8,[`text`,`loading`,`disabled`])):A(``,!0)]),_:1},8,[`title`]),P(z(H),{class:`space-y-3`,"data-tolk-run-summary":``},{default:B(()=>[M(`div`,ip,[P(z(Pn),{text:z(ps)(g.value),color:z(ms)(g.value),"data-tolk-run-status-badge":``},null,8,[`text`,`color`]),P(z(q),null,{default:B(()=>[N(R(b.value.sites?t.__(`:what into :sites`,{what:b.value.what,sites:b.value.sites}):b.value.what),1)]),_:1})]),P(z(U),null,{default:B(()=>[N(R(de.value),1)]),_:1}),g.value===`pending`?A(``,!0):(F(),j(m,{key:0},[P(Ba,{value:_.value.finished,max:_.value.total,label:t.__(`Run progress`)},null,8,[`value`,`max`,`label`]),M(`div`,ap,[P(z(q),null,{default:B(()=>[N(R(t.__(`:finished of :total items finished`,{finished:z(Q)(_.value.finished),total:z(Q)(_.value.total)})),1)]),_:1}),(F(!0),j(m,null,L(ie.value,e=>(F(),k(z(U),{key:e.key,"data-tolk-count":e.key},{default:B(()=>[N(R(e.text),1)]),_:2},1032,[`data-tolk-count`]))),128))]),P(z(U),{"data-tolk-run-usage":``},{default:B(()=>[N(R(t.__n(`:input input and :output output tokens in :calls call.|:input input and :output output tokens in :calls calls.`,E.value.calls,{input:z(Q)(E.value.input),output:z(Q)(E.value.output),calls:z(Q)(E.value.calls)}))+` `+R(E.value.cost===null?t.__(`The cost is unknown: a model without a price was called.`):t.__(`Estimated cost so far: :cost.`,{cost:z(ys)(E.value.cost)})),1)]),_:1})],64))]),_:1}),ne.value?(F(),k(z(jn),{key:0,variant:`default`,icon:`info`,"data-tolk-keep-open":``},{default:B(()=>[N(R(z(u)?t.__(`Keep this tab open while the run is in progress. Closing it pauses the run until you open it again.`):t.__(`Keep this page open while the run is in progress. Leaving it pauses the run until you open it again.`)),1)]),_:1})):A(``,!0),re.value?(F(),k(z(jn),{key:1,variant:`warning`,heading:t.__(`This run is not moving`),"data-tolk-stalled":``},{default:B(()=>[M(`div`,op,[h.value.driver===`cli`&&b.value.automatic?(F(),k(z(q),{key:0},{default:B(()=>[N(R(t.__(`The process that updates these translations has not worked on them for a while and may have stopped. Resume continues the run from here.`)),1)]),_:1})):h.value.driver===`cli`?(F(),k(z(q),{key:1},{default:B(()=>[N(R(t.__(`The command running this run has not worked on it for a while and may have stopped. Resume continues the run from here.`)),1)]),_:1})):(F(),k(z(q),{key:2},{default:B(()=>[N(R(t.__(`No queue worker has worked on this run for a while. Start a worker for the queue, or run it in this browser instead.`)),1)]),_:1})),M(`div`,sp,[P(z(V),{size:`sm`,text:t.__(`Resume`),loading:a.value===`resume`,disabled:a.value!==null,"data-tolk-action":`resume`,onClick:r[2]||=e=>fe(`resume`,z(d).resume)},null,8,[`text`,`loading`,`disabled`]),v.value.takeOver?(F(),k(z(V),{key:0,size:`sm`,variant:`primary`,text:t.__(`Run in this browser instead`),loading:a.value===`take-over`,disabled:a.value!==null,"data-tolk-action":`take-over`,onClick:r[3]||=e=>fe(`take-over`,z(d).takeOver)},null,8,[`text`,`loading`,`disabled`])):A(``,!0)])])]),_:1},8,[`heading`])):A(``,!0),(F(!0),j(m,null,L(i.value,(e,i)=>(F(),k(z(jn),{key:i,variant:`error`,"data-tolk-run-failure":``},{default:B(()=>[M(`div`,cp,[P(z(q),null,{default:B(()=>[N(R(t.__(`Following the run stopped: :message`,{message:e.error?.message??``})),1)]),_:2},1024),i===0?(F(),k(z(V),{key:0,size:`sm`,text:t.__(`Try again`),"data-tolk-action":`follow-again`,onClick:r[4]||=e=>z(d).follow(n.value)},null,8,[`text`])):A(``,!0)])]),_:2},1024))),128)),y.value?(F(),k(z(jn),{key:2,variant:y.value.variant,"data-tolk-run-result":``},{default:B(()=>[M(`div`,lp,[P(z(q),{as:`p`},{default:B(()=>[N(R(y.value.text),1)]),_:1}),y.value.error?(F(),k(z(q),{key:0,as:`p`,variant:`danger`},{default:B(()=>[N(R(y.value.error),1)]),_:1})):A(``,!0),v.value.retry||v.value.resume?(F(),j(`div`,up,[v.value.retry?(F(),k(z(V),{key:0,size:`sm`,text:t.__(`Retry failed`),loading:a.value===`retry`,disabled:a.value!==null,"data-tolk-action":`retry`,onClick:r[5]||=e=>fe(`retry`,z(d).retry)},null,8,[`text`,`loading`,`disabled`])):A(``,!0),v.value.resume?(F(),k(z(V),{key:1,size:`sm`,text:t.__(`Resume`),loading:a.value===`resume`,disabled:a.value!==null,"data-tolk-action":`resume`,onClick:r[6]||=e=>fe(`resume`,z(d).resume)},null,8,[`text`,`loading`,`disabled`])):A(``,!0)])):A(``,!0)])]),_:1},8,[`variant`])):A(``,!0),M(`div`,dp,[P(z(H),{class:`space-y-3`,"data-tolk-breakdown":``},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`What it translates`)},null,8,[`text`]),M(`div`,fp,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(t.__(`Content`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Site`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Items`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Skipped`)),1)]),_:1})]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(x.value,e=>(F(),k(z(ki),{key:e.key,"data-tolk-breakdown-row":e.key},{default:B(()=>[P(z(G),null,{default:B(()=>[N(R(e.type),1)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(e.site),1)]),_:2},1024),P(z(G),{"data-tolk-breakdown-total":``},{default:B(()=>[N(R(z(Q)(e.total)),1)]),_:2},1024),P(z(G),{"data-tolk-breakdown-skipped":``},{default:B(()=>[N(R(z(Q)(e.skipped)),1)]),_:2},1024)]),_:2},1032,[`data-tolk-breakdown-row`]))),128))]),_:1})]),_:1})]),x.value.length===0?(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.__(`This run has nothing to translate.`)),1)]),_:1})):A(``,!0),(F(!0),j(m,null,L(S.value,e=>(F(),k(z(U),{key:e.reason,"data-tolk-left-out":e.reason},{default:B(()=>[N(R(e.text),1)]),_:2},1032,[`data-tolk-left-out`]))),128)),w.value?(F(),k(z(U),{key:1,"data-tolk-not-localizable":``},{default:B(()=>[N(R(w.value)+` `,1),z(C)?(F(),k(z(Kd),{key:0,href:z(C),class:`text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-audit-link":``},{default:B(()=>[N(R(t.__(`Open the setup audit`)),1)]),_:1},8,[`href`])):(F(),j(m,{key:1},[N(R(t.__(`Run php please tolk:doctor for details.`)),1)],64))]),_:1})):A(``,!0)]),_:1}),P(z(H),{class:`space-y-3`,"data-tolk-settings":``},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`Settings`)},null,8,[`text`]),M(`dl`,pp,[(F(!0),j(m,null,L(ee.value,e=>(F(),j(m,{key:e.key},[M(`dt`,mp,R(e.label),1),M(`dd`,{"data-tolk-option":e.key},R(e.value),9,hp)],64))),128))])]),_:1})]),g.value===`pending`||T.value?(F(),k(z(H),{key:3,class:`space-y-3`,"data-tolk-estimate":``,"data-tolk-estimate-finished":T.value?.finished?`true`:`false`},{default:B(()=>[M(`div`,gp,[P(z(W),{size:`lg`,text:t.__(`Estimate`)},null,8,[`text`]),T.value?!T.value.finished&&g.value===`pending`?(F(),k(z(U),{key:1},{default:B(()=>[N(R(t.__(`Estimating… :progress`,{progress:T.value.progress})),1)]),_:1})):T.value.finished?A(``,!0):(F(),k(z(U),{key:2,"data-tolk-estimate-partial":``},{default:B(()=>[N(R(T.value.partial),1)]),_:1})):(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.__(`Estimating…`)),1)]),_:1}))]),T.value?(F(),j(`dl`,_p,[M(`div`,null,[M(`dt`,vp,R(t.__(`Segments`)),1),M(`dd`,yp,R(z(Q)(T.value.segments)),1)]),M(`div`,null,[M(`dt`,bp,R(t.__(`Characters`)),1),M(`dd`,xp,R(z(Q)(T.value.chars)),1)]),M(`div`,null,[M(`dt`,Sp,R(t.__(`Input tokens`)),1),M(`dd`,Cp,R(z(Q)(T.value.inputTokens)),1)]),M(`div`,null,[M(`dt`,wp,R(t.__(`Output tokens`)),1),M(`dd`,Tp,R(z(Q)(T.value.outputTokens)),1)]),M(`div`,null,[M(`dt`,Ep,R(t.__(`Cost`)),1),M(`dd`,Dp,R(T.value.cost===null?t.__(`Unknown`):z(ys)(T.value.cost)),1)])])):A(``,!0),P(z(U),null,{default:B(()=>[N(R(t.__(`An estimate: the tokens a language takes vary, and so does what a model writes.`))+` `,1),T.value&&T.value.cost===null?(F(),j(m,{key:0},[N(R(t.__(`The cost is unknown because a model has no price.`)),1)],64)):A(``,!0)]),_:1})]),_:1},8,[`data-tolk-estimate-finished`])):A(``,!0),P(z(H),{class:`space-y-3`,"data-tolk-items":``},{default:B(()=>[M(`div`,Op,[P(z(W),{size:`lg`,text:t.__(`Items`)},null,8,[`text`]),M(`div`,kp,[P(z(di),{"model-value":c.value,options:ae.value,size:`sm`,"data-tolk-items-filter":``,"onUpdate:modelValue":me},null,8,[`model-value`,`options`])])]),M(`div`,Ap,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(t.__(`Title`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Site`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Status`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Result`)),1)]),_:1})]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(te.value,e=>(F(),k(z(ki),{key:e.index,"data-tolk-item":``,"data-tolk-item-status":e.status},{default:B(()=>[P(z(G),null,{default:B(()=>[e.editUrl?(F(),j(`a`,{key:0,href:e.editUrl,class:`text-blue-600 hover:underline dark:text-blue-400`},R(e.title),9,jp)):(F(),j(`span`,Mp,R(e.title),1))]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(e.site),1)]),_:2},1024),P(z(G),null,{default:B(()=>[P(z(Pn),{text:e.statusLabel,color:e.statusColor},null,8,[`text`,`color`])]),_:2},1024),P(z(G),{class:`space-y-1`},{default:B(()=>[e.applied?(F(),k(z(q),{key:0,size:`sm`},{default:B(()=>[N(R(e.applied),1)]),_:2},1024)):A(``,!0),e.corrections.length?(F(),j(`div`,Np,[P(z(q),{size:`sm`},{default:B(()=>[N(R(e.corrected),1)]),_:2},1024),P(z(V),{size:`sm`,variant:`ghost`,text:t.__(`View changes`),"aria-label":t.__(`View changes to :title in :site`,{title:e.title,site:e.site}),"data-tolk-item-changes":``,onClick:t=>ue(e)},null,8,[`text`,`aria-label`,`onClick`])])):A(``,!0),e.incomplete.length?(F(),k(z(U),{key:2},{default:B(()=>[N(R(t.__(`Left incomplete: :fields`,{fields:e.incomplete.join(`, `)})),1)]),_:2},1024)):A(``,!0),e.failed.length?(F(),k(z(U),{key:3,"data-tolk-item-failed":``},{default:B(()=>[N(R(t.__(`Could not be translated: :fields`,{fields:e.failed.map(e=>`${e.handle} (${e.reason})`).join(`, `)})),1)]),_:2},1024)):A(``,!0),e.notReviewed.length?(F(),k(z(U),{key:4},{default:B(()=>[N(R(t.__(`Not reviewed in full: :fields`,{fields:e.notReviewed.join(`, `)})),1)]),_:2},1024)):A(``,!0),e.kept.length?(F(),k(z(U),{key:5},{default:B(()=>[N(R(t.__(`Not changed: :fields`,{fields:e.kept.map(e=>`${e.handle} (${e.reason})`).join(`, `)})),1)]),_:2},1024)):A(``,!0),e.reason?(F(),k(z(U),{key:6},{default:B(()=>[N(R(e.reason),1)]),_:2},1024)):A(``,!0),e.error?(F(),k(z(q),{key:7,size:`sm`,variant:`danger`,"data-tolk-item-error":``},{default:B(()=>[N(R(e.error)+` `,1),e.rootPage?(F(),j(`a`,{key:0,href:e.rootPage.url,class:`text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-root-page":``},R(t.__(`Open :title`,{title:e.rootPage.title})),9,Pp)):A(``,!0)]),_:2},1024)):A(``,!0),(F(!0),j(m,null,L(e.warnings,(e,t)=>(F(),k(z(U),{key:t},{default:B(()=>[N(R(e),1)]),_:2},1024))),128))]),_:2},1024)]),_:2},1032,[`data-tolk-item-status`]))),128))]),_:1})]),_:1})]),te.value.length===0?(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.__(`No items.`)),1)]),_:1})):A(``,!0),D.value.last_page>1?(F(),j(`div`,Fp,[P(z(U),null,{default:B(()=>[N(R(t.__(`Page :page of :pages`,{page:D.value.page,pages:D.value.last_page})),1)]),_:1}),P(z(V),{size:`sm`,icon:`chevron-left`,"aria-label":t.__(`Previous page`),disabled:D.value.page<=1,onClick:r[7]||=e=>pe(D.value.page-1)},null,8,[`aria-label`,`disabled`]),P(z(V),{size:`sm`,icon:`chevron-right`,"aria-label":t.__(`Next page`),disabled:D.value.page>=D.value.last_page,onClick:r[8]||=e=>pe(D.value.page+1)},null,8,[`aria-label`,`disabled`])])):A(``,!0),z(ce).open?(F(),k(Ra,{key:2,modal:z(ce),corrections:le.value},null,8,[`modal`,`corrections`])):A(``,!0)]),_:1})],8,rp))}};Statamic.booting(()=>{Statamic.$components.register(wc,Iu),Statamic.$components.register(zu,Ru),Statamic.$components.register(`tolk_model-fieldtype`,pd),Statamic.$components.register(`tolk_providers-fieldtype`,Cd),Statamic.$components.register(`tolk_site_profile-fieldtype`,Ud),Statamic.$inertia.register(`tolk::Audit`,gf),Statamic.$inertia.register(`tolk::Overview`,ep),Statamic.$inertia.register(`tolk::Runs/Index`,np),Statamic.$inertia.register(`tolk::Runs/Show`,Ip),Ha.listen(),kc.listen(),ol.listen(),ou({PipelineStopped:a}).listen(),Hu.register()}); \ No newline at end of file +`),Ka=e=>typeof e==`boolean`||typeof e==`number`,qa=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function Ja(e){if(typeof e==`string`)return e===``?null:Ga(e);if(Array.isArray(e))return e.length>0&&e.every(Xa)?Za(e):Ya(e);if(typeof e!=`object`||!e)return null;let t=Object.keys(e).filter(e=>!Ua.has(e)).sort().map(t=>[t,Ja(e[t])]).filter(([,e])=>e!==null);return t.length?Object.fromEntries(t):null}function Ya(e){let t=e.map(Ja);for(;t.length&&t[t.length-1]===null;)t.pop();return t.length?t:null}function Xa(e){return typeof e==`object`&&!!e&&typeof e.type==`string`&&Object.keys(e).every(e=>Wa.has(e))}function Za(e){let t=[],n=[],r=e=>{n.length&&(t.push(n.length===1&&n[0].marks.length===0?Ga(n[0].text):n.map(Qa)),n=[]),e!==null&&t.push(e)},i=e=>{let t=typeof e.text==`string`?e.text:``;if(t===``)return;let r=to(Array.isArray(e.marks)?e.marks:[]),i=JSON.stringify(r),a=n[n.length-1];a?.key===i?a.text+=t:n.push({key:i,marks:r,text:t,title:$a(e.marks)})},a=e=>{Xa(e)?e.type===`text`?i(e):(r(Ja(e.attrs)),r($a(e.marks)),(Array.isArray(e.content)?e.content:[]).forEach(a),r(null)):r(Ja(e))};return e.forEach(a),r(null),t.length?t:null}function Qa({marks:e,text:t,title:n}){return e.length===0?Ga(t):n===null?{text:Ga(t)}:{text:Ga(t),title:n}}function $a(e){let t=(Array.isArray(e)?e:[]).find(e=>qa(e)&&e.type===`link`),n=qa(t?.attrs)?t.attrs.title:null;return typeof n==`string`&&n.trim()!==``?Ga(n):null}var eo=e=>e==null||e===``||typeof e==`object`&&Object.keys(e).length===0;function to(e){return Array.isArray(e)?e.map(to):Ka(e)?String(e):qa(e)?Object.fromEntries(Object.keys(e).sort().map(t=>[t,to(e[t])]).filter(([,e])=>!eo(e))):e??null}function no(e,t){return JSON.stringify(Ja(e))===JSON.stringify(Ja(t))}function ro(e,t){return Array.isArray(e)&&Array.isArray(t)?e.every((e,n)=>n>=t.length||ro(e,t[n])):qa(e)&&qa(t)?Object.keys(e).every(n=>Ua.has(n)||!Object.hasOwn(t,n)||ro(e[n],t[n])):!(Ka(e)||Ka(t))||e===t}function io(e,t){return no(e,t)&&ro(e,t)}var ao=2e3,oo=1e3,so=100,co=50,lo=e=>new Promise(t=>setTimeout(t,e)),uo=e=>typeof e==`function`?e:()=>e,fo=(e,t,n)=>()=>e.reference.value===t&&n();async function po(e,t,n){let r=()=>600-(t()-e());for(let e=r();e>0;e=r())await n(e)}function mo(e,t,n){return Object.hasOwn(t,n)?!no(e.values.value[n],t[n]):e.values.value[n]!==void 0}function ho(e,t,n){return n===null&&typeof e.values.value[t]==`string`?``:Z(n)}function go(e,t){return e.hiddenFields?.value?.[t]?.omitValue===!0}function _o(e,t){for(let[n,r]of Object.entries(t))r.pending||r.sync||r.localizedBefore||(go(e,n)?e.localizedFields.value.includes(n)&&(ko(e,n,!1),r.leftOut=!0):r.leftOut&&=(ko(e,n,!0),!1))}function vo(e,t){let n=e.localizedFields.value;return Object.keys(t).filter(e=>t[e].leftOut||n.includes(e))}function yo(e,t){return!!t&&!t.pending&&t.plan!==e.delivered?.plan}function bo(e,t,n={}){let r=e.localizedFields.value;return{reference:e.reference.value,dirty:Statamic.$dirty.has(e.name.value),fields:Object.fromEntries(t.map(t=>[t,{value:Z(e.values.value[t]),meta:Z(e.meta.value[t]),localized:r.includes(t),delivered:n[t]?Z(n[t]):null}]))}}async function xo(e,t,{reference:n,plan:r,lastChangeAt:i=0,planValues:a={},delivered:o,now:s=Date.now,sleep:c=lo,active:l=()=>!0}){let u=Object.keys(t??{}),d={stale:!1,applied:[],skipped:{},repeated:[]},f=()=>(d.stale=!0,d.applied=[],d.skipped=Object.fromEntries(u.map(e=>[e,`stale`])),d),p=fo(e,n,l);if(!p()||(await po(uo(i),s,c),!p()))return f();let m=[],h={};for(let n of u){let i=t[n];if(o[n]?.plan===r){d.repeated.push(n);continue}if(mo(e,a,n)){d.skipped[n]=`edited`;continue}if(!i.sync&&go(e,n)){d.skipped[n]=`hidden`;continue}o[n]={plan:r,value:void 0,pending:!0,incomplete:!!i.incomplete,sync:!!i.sync,localizedBefore:o[n]?.localizedBefore??e.localizedFields.value.includes(n)},i.meta!==void 0&&e.setFieldMeta(n,Z(i.meta)),h[n]=ho(e,n,i.value),e.setFieldValue(n,Z(h[n])),i.sync?(ko(e,n,!1),Statamic.$dirty.add(e.name.value),m.push(n)):(e.desyncField(n),e.localizedFields.value.includes(n)||(ko(e,n,!0),Statamic.$dirty.add(e.name.value))),d.applied.push(n)}if(!d.applied.length)return d;if(await c(300),!p())return d.applied.forEach(e=>delete o[e]),f();m.filter(t=>io(e.values.value[t],h[t])).forEach(t=>ko(e,t,!1));for(let t of d.applied){let n=e.values.value[t];o[t]={...o[t],value:no(n,h[t])?Z(n):h[t],pending:!1}}return d}async function So(e,t,n,{registry:r=Ha,sleep:i=lo}={}){let a={restored:[],kept:[]};if(!t||e.reference.value!==t.reference)return a;for(let[r,i]of Object.entries(t.fields)){let t=n[r];if(yo(i,t)){if(!no(e.values.value[r],t.value)){a.kept.push(r);continue}a.restored.push(r)}}if(!a.restored.length)return a;e.withoutDirtying(()=>{for(let r of a.restored){let i=t.fields[r];e.setFieldMeta(r,Z(i.meta)),e.setFieldValue(r,ho(e,r,i.value)),ko(e,r,i.localized),i.delivered?n[r]=Z(i.delivered):delete n[r]}});let o=()=>{if(e.reference.value!==t.reference)return;let n=a.restored.filter(n=>!io(e.values.value[n],t.fields[n].value));a.restored.filter(e=>t.fields[e].localized||!n.includes(e)).forEach(n=>ko(e,n,t.fields[n].localized)),!t.dirty&&!n.length&&r.dirtyHandles(e.name.value).length===0&&Statamic.$dirty.remove(e.name.value)};return o(),await i(300),o(),a}function Co(e,t,n){if(!t||e.reference.value!==t.reference)return[];let r=n.filter(e=>Object.hasOwn(t.fields,e));return r.length&&e.withoutDirtying(()=>{for(let n of r){let r=t.fields[n];e.setFieldMeta(n,Z(r.meta)),e.setFieldValue(n,ho(e,n,r.value)),ko(e,n,r.localized)}}),r}async function wo(e,t,{reference:n,lastChangeAt:r=0,now:i=Date.now,sleep:a=lo,active:o=()=>!0}={}){let s=uo(r),c=fo(e,n,o),l=()=>s()+ao-i();if(!c())return{stale:!0,kept:!1,reset:!1};if(!Eo(e,t))return{stale:!1,kept:!1,reset:!1};for(await po(s,i,a);c()&&!Do(e)&&l()>0;)await a(Math.min(so,l()));let u=Do(e);return!c()||!await Oo(e,t,{sleep:a,current:c})?{stale:!0,kept:!1,reset:u}:{stale:!1,kept:!0,reset:u}}async function To(e,t,{reference:n,sleep:r=lo,active:i=()=>!0}={}){let a=fo(e,n,i);return!Eo(e,t)||(await r(oo),!a()||e.values.value.slug===t&&!Do(e))?!1:Oo(e,t,{sleep:r,current:a})}function Eo(e,t){return typeof t==`string`&&t!==``&&Object.hasOwn(e.values.value??{},`slug`)}function Do(e){return e.meta.value?.slug?.auto===!0}async function Oo(e,t,{sleep:n,current:r}){return Do(e)&&e.values.value.slug===t&&(e.setFieldValue(`slug`,``),await n(co),!r())?!1:(e.values.value.slug!==t&&e.setFieldValue(`slug`,t),!0)}function ko(e,t,n){let r=e.localizedFields.value,i=r.indexOf(t);n&&i===-1?r.push(t):!n&&i!==-1&&r.splice(i,1)}var Ao=2e3,jo=5;function Mo(e,t){return new Promise(n=>{if(t?.aborted)return n();let r=()=>{clearTimeout(i),t?.removeEventListener(`abort`,r),n()},i=setTimeout(r,e);t?.addEventListener(`abort`,r,{once:!0})})}function No(e){let t=e?.status??0;return t===429||t===503?`wait`:t===409&&e.code===`busy`?`busy`:t===409&&e.code===`source_changed`||t===410||t===502?`stop`:`fail`}function Po(e,t=``){return{status:e?.status??0,code:e?.code??null,message:e?.message||t}}var Fo=e=>Object.entries(Y(e)),Io=({id:e,fields:t})=>({id:e,fields:t});async function Lo({api:e=J,plan:t,concurrency:n=1,onFields:r=()=>{},onProgress:i=()=>{},signal:a=null,finishing:o=()=>!0,sleep:s=Mo,maxWaits:c=5,busyMs:l=Ao,maxBusyWaits:u=60}){let d=Math.max(1,Math.floor(Number(n))||1),f=[...t.units??[]],p=new Set(f.map(e=>e.id)),m={total:f.length,done:0,waiting:0},h=new Map,g=[],_=[],v=[],y={},b=new Set,x=new Set,S=new Set,C=new Set,w={},ee=null,T=()=>ee!==null||!!a?.aborted,E=()=>i({...m});function te(){if(!T())return f.shift();let e=ee===null&&o()?f.findIndex(e=>!p.has(e.id)):-1;return e===-1?null:f.splice(e,1)[0]}function D(e){let t=Fo(e).map(([e,t])=>(h.set(e,t),e));t.length&&g.push(Promise.resolve().then(()=>r(e)).then(e=>({handles:t,result:e}),e=>({handles:t,error:e})))}function ne(e,t){D(t?.fields);for(let[e,n]of Fo(t?.failed))y[e]=n;(Array.isArray(t?.warnings)?t.warnings:[]).forEach(e=>b.add(e)),(Array.isArray(t?.unchanged)?t.unchanged:[]).forEach(e=>x.add(e)),t?.reviewed===!0&&S.add(e.id),t?.review_skipped===!0&&C.add(e.id);for(let[e,n]of Fo(t?.usage))w[e]=zo(w[e]??{},n);let n=Array.isArray(t?.spawned)?t.spawned:[];f.push(...n),m.total+=n.length}async function re(n){let r=0,i=0;for(;;)try{return ne(n,await e.post(`editor/unit`,{plan:t.plan,unit:n.id}))}catch(e){let t=No(e),o=t===`wait`&&r0?Number(e.data.retry_after):jo;if(m.waiting++,E(),await s(t===`wait`?d*1e3:l,a),m.waiting--,E(),T()){v.push(Io(n));return}}}return D(t.ready),E(),await new Promise(e=>{let t=0,n=()=>{let r;for(;t{t--,m.done++,E(),n()});t===0&&e()};n()}),v.push(...f.map(Io)),Ro(await Promise.all(g),{received:h,failed:y,failedUnits:_,cancelledUnits:v,warnings:[...b],unchanged:x,reviewedUnits:[...S],reviewSkipped:[...C],usage:w,stopped:ee,aborted:!!a?.aborted,progress:m})}function Ro(e,{received:t,failed:n,failedUnits:r,cancelledUnits:i,warnings:a,unchanged:o,reviewedUnits:s,reviewSkipped:c,usage:l,stopped:u,aborted:d,progress:f}){let p=[],m={},h=!1;for(let{handles:t,result:r,error:i}of e){if(i){t.forEach(e=>n[e]??=`not_filled`);continue}h||=r?.stale===!0;for(let e of r?.applied??(r?[]:t))p.includes(e)||p.push(e);Object.assign(m,r?.skipped??{})}for(let e of r)for(let t of e.fields??[])!p.includes(t)&&!(t in m)&&(n[t]??=e.error?.code??`failed`);return p.forEach(e=>delete n[e]),{delivered:p,incomplete:p.filter(e=>t.get(e)?.incomplete===!0),skipped:m,failed:n,failedUnits:r,cancelledUnits:i,warnings:a,corrections:p.flatMap(e=>{let n=t.get(e)?.corrections;return Array.isArray(n)?n.map(t=>({handle:e,...t})):[]}),unchanged:[...o].filter(e=>!p.includes(e)),reviewedUnits:s,reviewSkipped:c,usage:l,models:Object.keys(l),stopped:u,aborted:d,stale:h,units:{total:f.total,done:f.done}}}function zo(e,t){let n={...e};for(let[e,r]of Fo(t))typeof r==`number`&&(n[e]=(n[e]??0)+r);return n}var Bo=t({BACKOFF_MS:()=>Ho,FINAL_STATUSES:()=>Vo,IDLE_MS:()=>Wo,MAX_BACKOFF_MS:()=>Uo,MAX_RETRIES:()=>5,POLL_MS:()=>Go,backoff:()=>ts,estimateLoop:()=>cs,isFinal:()=>Xo,latest:()=>Zo,nonce:()=>qo,pollState:()=>ss,retryable:()=>es,startApplyLoop:()=>as,startLanes:()=>is}),Vo=[`completed`,`completed_with_errors`,`cancelled`,`aborted`],Ho=1e3,Uo=3e4,Wo=1e3,Go=2e3,Ko=null;function qo(){return Ko??=Array.from(crypto.getRandomValues(new Uint8Array(12)),e=>e.toString(16).padStart(2,`0`)).join(``),Ko}var Jo=new WeakMap;function Yo(e,t,n){let r=Jo.get(e)??new Map,i=r.get(t),a=i?i.then(n):new Promise(e=>e(n())),o=a.then(()=>{},()=>{});return Jo.set(e,r),r.set(t,o),o.then(()=>r.get(t)===o&&r.delete(t)),a}function Xo(e){return Vo.includes(e?.run?.status)}function Zo(e){let t=null;return n=>{t!==null&&Qo(n,t)||(t=n,e(n))}}function Qo(e,t){let n=$o(e),r=$o(t);return n=500}function ts(e,t=Ho){return Math.min(t*2**Math.max(0,e-1),Uo)}function ns(e,t){return e==null?t:Math.max(0,Number(e)||0)*1e3}async function rs(e,{retries:t,backoffMs:n,sleep:r,signal:i}){for(let a=1;;a++)try{return{response:await e()}}catch(e){if(i?.aborted)return{};if(a>t||!es(e))return{error:Po(e)};if(await r(ts(a,n),i),i?.aborted)return{}}}function is({api:e=J,urls:t,lanes:n=1,nonce:r=qo(),onState:i=()=>{},onFailure:a=()=>{},signal:o=null,query:s=()=>({}),sleep:c=Mo,retries:l=5,backoffMs:u=Ho,idleMs:d=Wo}){let f=Math.max(1,Math.floor(Number(n))||1),p=new Map,m=new Set,h=[],g=[],_=()=>!!o?.aborted,v=e=>m.forEach(t=>t(e)),y=()=>[...p.values()].filter(e=>e===`running`).length;function b(e,t){let n={lane:e,error:t};return g.push(n),a(n),`failed`}let x=n=>Yo(e,`${t.tick} ${r} ${n}`,()=>_()?null:e.post(t.tick,{...s(),nonce:r,lane:n}));async function S(e){for(;!_();){let{response:t,error:n}=await rs(()=>x(e),{retries:l,backoffMs:u,sleep:c,signal:o});if(_())break;if(n)return b(e,n);if(i(t),v({lane:e,state:t}),Xo(t)||t?.report?.remains!==!0)return`finished`;await c(ns(t.report.wait,d),o)}return`aborted`}function C(e,t){p.set(e,t),v({lane:e,ended:t}),y()===0&&h.splice(0).forEach(e=>e())}function w(e){p.set(e,`running`),S(e).catch(t=>b(e,Po(t))).then(t=>C(e,t))}for(let e=1;e<=f;e++)w(e);return{get active(){return y()},failed:g,restart(){if(_())return 0;let e=[...p].filter(([,e])=>e===`finished`).map(([e])=>e);return e.forEach(w),e.length},idle(){return y()===0?Promise.resolve():new Promise(e=>h.push(e))},subscribe(e){return m.add(e),()=>m.delete(e)}}}async function as({api:e=J,urls:t,lanes:n=null,onState:r=()=>{},onFailure:i=()=>{},signal:a=null,query:o=()=>({}),sleep:s=Mo,retries:c=5,backoffMs:l=Ho,idleMs:u=Wo}){let d=()=>!!a?.aborted,f=null,p=!1,m=null,h=n?.subscribe(e=>{(e.ended||Number(Y(e.state?.counts).translated)>0)&&(p=!0,m?.())})??(()=>{}),g=()=>new Promise(e=>{let t=()=>{m=null,a?.removeEventListener(`abort`,t),e()};m=t,a?.addEventListener(`abort`,t,{once:!0})});try{for(;!d();){p=!1;let{response:m,error:h}=await rs(()=>e.post(t.apply,o()),{retries:c,backoffMs:l,sleep:s,signal:a});if(d())break;if(h)return i({error:h}),{state:f,error:h};if(f=m,r(m),Xo(m))break;if(n&&os(m)&&n.restart(),m?.report?.remains===!0)await s(ns(m.report.wait,u),a);else if(n?.active)p||await g();else break}}finally{h()}return{state:f,error:null}}function os(e){let t=e?.run;return t?.status===`running`&&t?.driver===`browser`&&Number(Y(e.counts).pending)>0}async function ss({api:e=J,url:t,interval:n=Go,onState:r=()=>{},onFailure:i=()=>{},signal:a=null,query:o=()=>({}),sleep:s=Mo,retries:c=5,backoffMs:l=Ho}){let u=null;for(;!a?.aborted;){let{response:d,error:f}=await rs(()=>e.get(t,o()),{retries:c,backoffMs:l,sleep:s,signal:a});if(a?.aborted)break;if(f)return i({error:f}),{state:u,error:f};if(u=d,r(d),Xo(d))break;await s(n,a)}return{state:u,error:null}}async function cs({api:e=J,url:t,estimate:n=null,onEstimate:r=()=>{},onFailure:i=()=>{},signal:a=null,sleep:o=Mo,retries:s=5,backoffMs:c=Ho}){let l=n,u=n===null?0:n.next===null?null:Math.max(0,Math.floor(Number(n.next))||0);for(;u!==null&&!a?.aborted;){let{response:n,error:d}=await rs(()=>e.post(t,{from:u}),{retries:s,backoffMs:c,sleep:o,signal:a});if(a?.aborted)break;if(d)return i({error:d}),{estimate:l,error:d};l=n,r(n),u=Number.isInteger(n?.next)?n.next:null}return{estimate:l,error:null}}var ls=[`pending`,`translating`,`translated`,`applying`,`done`,`skipped`,`failed`],us=[`pending`,`translating`,`translated`,`applying`],ds={pending:`default`,running:`blue`,completed:`green`,completed_with_errors:`orange`,cancelled:`amber`,aborted:`red`},fs={pending:`default`,translating:`blue`,translated:`sky`,applying:`blue`,done:`green`,skipped:`default`,failed:`red`};function ps(e){return{pending:__(`Not started`),running:__(`Running`),completed:__(`Completed`),completed_with_errors:__(`Completed with errors`),cancelled:__(`Cancelled`),aborted:__(`Aborted`)}[e]??e}function ms(e){return ds[e]??`default`}function hs(e){return{pending:__(`Waiting`),translating:__(`Translating`),translated:__(`Translated, not saved yet`),applying:__(`Saving`),done:__(`Done`),skipped:__(`Skipped`),failed:__(`Failed`)}[e]??e}function gs(e){return fs[e]??`default`}function _s(e){return{entry:__(`Entries`),term:__(`Terms`),globals:__(`Global sets`),nav:__(`Navigation`)}[e]??e}function vs(e=[]){let t=Object.fromEntries((Array.isArray(e)?e:[]).map(e=>[e.handle,e.name]));return e=>t[e]??e}function Q(e,t=void 0){return new Intl.NumberFormat(t).format(Number(e)||0)}function ys(e,t=void 0){let n=Number(e)||0,r=n>0&&n<.01?{maximumSignificantDigits:2}:{minimumFractionDigits:2,maximumFractionDigits:2};return new Intl.NumberFormat(t,{style:`currency`,currency:`USD`,...r}).format(n)}function bs(e,t=void 0){let n=Date.parse(e??``);return Number.isNaN(n)?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(n)}function xs(e){let t={...Object.fromEntries(ls.map(e=>[e,0])),...Y(e?.counts)},n=ls.reduce((e,n)=>e+(Number(t[n])||0),0),r=us.reduce((e,n)=>e+(Number(t[n])||0),0);return{counts:t,total:n,finished:n-r,unfinished:r}}function Ss(e){let t=e?.run??{},{counts:n,unfinished:r}=xs(e),i=Xo(e),a=t.status===`running`&&!!e?.stalled;return{start:t.status===`pending`,cancel:t.status===`running`,resume:a||[`cancelled`,`aborted`].includes(t.status)&&r>0,retry:i&&n.failed>0,takeOver:a&&t.driver===`queue`}}function Cs(e,t){let n=[t];return e.skipped>0&&n.push(__n(`:count skipped|:count skipped`,e.skipped)),e.failed>0&&n.push(__n(`:count failed|:count failed`,e.failed)),n.join(`, `)}function ws(e){let t=e?.run??{};if(!Xo(e))return null;let{counts:n}=xs(e),r=Cs(n,__n(`:count done|:count done`,n.done));return{status:t.status,variant:{completed:`success`,completed_with_errors:`warning`,cancelled:`warning`,aborted:`error`}[t.status],text:{completed:__(`The run is complete: :items.`,{items:r}),completed_with_errors:__(`The run is complete, with errors: :items.`,{items:r}),cancelled:__(`The run was cancelled: :items.`,{items:r}),aborted:__(`The run was stopped: :items.`,{items:r})}[t.status],error:t.error??null}}function Ts(e,t=e=>e){return(Array.isArray(e)?e:[]).map(({type:e,site:n,counts:r})=>{let i=xs({counts:r});return{key:`${e}|${n}`,type:_s(e),site:t(n),total:i.total,skipped:i.counts.skipped,done:i.counts.done,failed:i.counts.failed}})}function Es(e){let t={excluded_collection:e=>__n(`:count target is in a collection excluded in the settings.|:count targets are in collections excluded in the settings.`,e),site_not_in_collection:e=>__n(`:count target is in a site its collection does not have.|:count targets are in sites their collection does not have.`,e),unauthorized:e=>__n(`:count target is one you may not edit.|:count targets are ones you may not edit.`,e),from_site:e=>__n(`:count target is a navigation in the site it is translated from.|:count targets are navigations in the site they are translated from.`,e)};return Object.entries(Y(e?.skipped)).filter(([,e])=>Number(e)>0).map(([e,n])=>({reason:e,text:t[e]?.(Number(n))??__(`:count targets left out: :reason.`,{count:n,reason:e.replaceAll(`_`,` `)})}))}function Ds(e){let t=(Array.isArray(e?.out_of_scope)?e.out_of_scope:[]).filter(e=>e.reason===`not_localizable`);if(t.length===0)return null;let n=new Set(t.map(e=>e.container));return ga(t.map(e=>n.size>1?`${e.label||e.handle} (${e.container})`:e.label||e.handle).join(`, `),t.length)}function Os(e,t=e=>e){let n=t=>Array.isArray(e?.[t])?e[t]:[],r=n(`collections`),i=n(`taxonomies`),a=n(`globals`),o=n(`navs`),s=n(`entry_ids`).length,c=n(`term_ids`).length,l=[],u=(e,t)=>{e.includes(`*`)?l.push(t):e.length>0&&l.push(e.join(`, `))};return u(r,__(`All collections`)),s>0&&l.push(__n(`:count selected entry|:count selected entries`,s)),u(i,__(`All taxonomies`)),c>0&&l.push(__n(`:count selected term|:count selected terms`,c)),u(a,__(`All global sets`)),u(o,__(`All navigation`)),{what:l.join(`, `)||__(`Nothing selected`),sites:n(`sites`).map(t).join(`, `),automatic:e?.automatic===!0}}function ks(e,t={}){let n=e=>e?Y(t)[e]??e:null,r=[{key:`mode`,label:__(`Translate`),value:{missing:__(`Only what is not translated yet`),update:__(`Also update outdated translations`),all:__(`Retranslate everything`),review:__(`Review existing translations`)}[e?.mode]??e?.mode??``},{key:`translator`,label:__(`Model`),value:n(e?.translator)??__(`Default`)},{key:`review`,label:__(`Review`),value:e?.review?n(e?.reviewer)??__(`On`):__(`Off`)},{key:`overwrite_manual`,label:__(`Manual edits`),value:e?.overwrite_manual?__(`Overwritten`):__(`Kept`)},{key:`new_status`,label:__(`New localizations`),value:e?.new_status===`mirror`?__(`Same as origin`):__(`Drafts`)}];return e?.publish_changes&&r.push({key:`publish_changes`,label:__(`Revisions`),value:__(`Changes are published`)}),r}function As(e,t=0){if(!e)return null;let n=Number.isInteger(e.next)?e.next:null,r={done:Math.min(n??0,t),total:t};return{finished:n===null,progress:n===null?null:__(`:done of :total items`,r),partial:n===null?null:__(`Only :done of :total items were estimated before the run started.`,r),segments:Number(e.segments)||0,chars:Number(e.chars)||0,inputTokens:Number(e.input_tokens)||0,outputTokens:Number(e.output_tokens)||0,cost:e.cost===null||e.cost===void 0?null:Number(e.cost)}}function js(e,t={}){let n=Object.entries(Y(e?.usage)).map(([e,n])=>({model:Y(t)[e]??e,input:Number(n?.input)||0,output:Number(n?.output)||0,calls:Number(n?.calls)||0}));return{rows:n,input:n.reduce((e,t)=>e+t.input,0),output:n.reduce((e,t)=>e+t.output,0),calls:n.reduce((e,t)=>e+t.calls,0),cost:e?.cost===null||e?.cost===void 0?null:Number(e.cost)}}var Ms={current:()=>__(`up to date`),outdated:()=>__(`outdated, not updated in this mode`),untranslated:()=>__(`not translated yet`),manual:()=>__(`edited by hand, kept`),target_changed:()=>__(`edited meanwhile, kept`),not_applicable:()=>__(`empty in the source`),not_requested:()=>__(`not requested`),origin_untranslated:()=>__(`not translated in its source yet`),structure_differs:()=>__(`its structure differs from the source`),no_corrections:()=>__(`reviewed, nothing to correct`),review_skipped:()=>__(`could not be reviewed`)},Ns={invalid:()=>__(`the model kept breaking its formatting`),missing:()=>__(`the model left it out`),too_long:()=>__(`the model's answer was cut off`),refused:()=>__(`the model refused it`),request_rejected:()=>__(`the provider rejected the request`)},Ps={nothing_to_do:()=>__(`Nothing to do.`),dependency_failed:()=>__(`An item it depends on failed.`),unauthorized:()=>__(`You may not edit it.`),target_changed:()=>__(`Edited by someone while it was being translated.`),no_corrections:()=>__(`Reviewed, nothing to correct.`),source_changed:()=>__(`Its source changed, so it is translated again.`)};function Fs(e,t=e=>e){let n=Object.entries(Y(e?.fields)),r=e=>n.filter(([,t])=>t===e).map(([e])=>e),i=[`applied`,`incomplete`,`partly_reviewed`],a=n.filter(([,e])=>i.includes(e)).length,o=([,e])=>Object.hasOwn(Ns,e),s=n.filter(o).map(([e,t])=>({handle:e,reason:Ns[t]()})),c=n.filter(e=>!i.includes(e[1])&&!o(e)).map(([e,t])=>({handle:e,reason:Ms[t]?.()??String(t).replaceAll(`_`,` `)})),l=e?.reason?Ps[e.reason]?.()??null:null,u=Object.entries(Y(e?.corrections)).flatMap(([e,t])=>(Array.isArray(t)?t:[]).map(t=>({...t,handle:e,label:e})));return{index:e?.index,title:e?.title||e?.source_id||``,site:t(e?.target_site),status:e?.status,statusLabel:hs(e?.status),statusColor:gs(e?.status),editUrl:e?.edit_url??null,applied:a>0?__n(`:count field saved|:count fields saved`,a):null,incomplete:r(`incomplete`),failed:s,notReviewed:r(`partly_reviewed`),kept:c,reason:l,error:e?.error??null,rootPage:e?.root_page?.edit_url?{title:e.root_page.title||``,url:e.root_page.edit_url}:null,warnings:Array.isArray(e?.warnings)?e.warnings:[],corrected:u.length>0?__n(`:count correction|:count corrections`,u.length):null,corrections:u}}function Is(e,t){let n=t?.page;return Number.isInteger(n)&&n{},onEstimate:i=()=>{},onFailures:a=()=>{},query:o=()=>({}),api:s=J,ticker:c=Bo}){let l=null,u=()=>{},d=null,f=null,p=[],m=null,h=!1,g=null;function _(e){p=[...p,e],a(p)}function v(){return!!(d&&d.active>0||f)}function y(){let e=m?.run??{};return e.status===`running`&&e.driver===`browser`&&v()}function b(){let e=n!==null&&y();e!==h&&(h=e,e?Statamic.$dirty.add(n):Statamic.$dirty.remove(n))}function x(){l?.abort(),l=null,d=null,f=null,b()}function S(e){x(),u=c.latest(C),w(e,!0)}function C(e){m=e,r(e),b(),Xo(e)?g=null:Rs(e)!==g&&(x(),w(e,!1))}function w(n,r){let i=new AbortController;l=i,p=[],a(p),g=Rs(n),r&&u(n);let m=n?.run??{},h={onState:u,onFailure:_,signal:i.signal,query:o};if(g===`estimate`)ee(m.estimate??null,i.signal);else if(g===`drive`){d=c.startLanes({api:s,urls:e,lanes:t,...h}),d.subscribe(e=>e.ended&&b());let n=c.startApplyLoop({api:s,urls:e,lanes:d,...h}).catch(e=>_({error:Po(e)})).finally(()=>{f===n&&(f=null,b())});f=n,b()}else g===`poll`&&c.pollState({api:s,url:e.state,...h}).catch(e=>_({error:Po(e)}))}async function ee(t,n){try{let{error:r}=await c.estimateLoop({api:s,url:e.estimate,estimate:t,onEstimate:i,onFailure:_,signal:n});!r&&!n.aborted&&await T()}catch(e){n.aborted||_({error:Po(e)})}}async function T(){let t=l?.signal,n=await s.get(e.state,o());return t&&!t.aborted&&u(n),n}async function E(e,t=!0){let n=await s.post(e,o());return t?S(n):u(n),n}return{follow:S,refresh:T,stop:x,start:()=>E(e.start),cancel:()=>E(e.cancel,!1),resume:()=>E(e.resume),retry:()=>E(e.retry),takeOver:()=>E(e.take_over),get active(){return v()},get driving(){return y()},get failures(){return p}}}function Rs(e){let t=e?.run??{};return t.status===`pending`?`estimate`:t.status===`running`?t.driver===`browser`?`drive`:`poll`:null}var zs=[`idle`,`offer`,`planning`,`working`,`done`,`error`];function Bs(){return{reference:null,status:null,phase:`idle`,progress:{total:0,done:0,waiting:0,cancelling:!1},summary:null,snapshot:null,delivered:{},lastChangeAt:0,planReference:null,error:null,request:null,notSaved:[],created:!1,slugKept:!1,push:null}}var Vs=null;function Hs(){return Vs??=Statamic.$pinia.defineStore(`tolk-editor`,{state:()=>({containers:{}}),getters:{phaseOf:e=>t=>e.containers[t]?.phase??`idle`},actions:{container(e){return this.containers[e]??=Bs(),this.containers[e]},switched(e,t,n=Date.now()){this.containers[e]={...Bs(),reference:t,lastChangeAt:n}},saved(e,t=Date.now()){let n=this.container(e),r={...n.delivered};return n.lastChangeAt=Math.max(n.lastChangeAt,t),Object.keys(r).forEach(e=>delete n.delivered[e]),r},setPhase(e,t,n=null){if(!zs.includes(t))throw Error(`Unknown editor phase [${t}].`);let r=this.container(e);r.phase=t,r.error=t===`error`?n:null},clearResult(e){Object.assign(this.container(e),{summary:null,snapshot:null,request:null}),this.setPhase(e,`idle`)},forget(e){delete this.containers[e]}}}),Vs()}var Us=[`starting`,`running`,`expecting`],Ws=[1e3,2e3,4e3,8e3,15e3];function Gs(e){let t=e?.origin?.auto_update_sites??[];return(e?.origin?.localizations??[]).filter(e=>t.includes(e.site)).filter(e=>!e.exists||[`untranslated`,`outdated`].includes(e.status)).map(e=>e.site)}function Ks(e){return(e?.localizations??[]).filter(e=>e.translate).map(({site:e,name:t,exists:n,summary:r})=>({site:e,name:t,missing:!n,summary:r}))}function qs(e){return(e?.localizations??[]).filter(e=>e.update).map(e=>e.site)}function Js(e,{dirty:t=!1,term:n=!1}={}){return e?.translatesPublished&&(t||e.unpublishedChanges)?__(`Publish first: the translations are made from the published entry.`):t?n?__(`Save first: the translations are made from the saved term.`):__(`Save first: the translations are made from the saved entry.`):null}function Ys(e,{term:t=!1}={}){return t?__(`The saved term is translated and saved in each language you choose. This form stays as it is.`):e?.translatesPublished?__(`The published entry is translated and saved in each language you choose. This form stays as it is.`):__(`The saved entry is translated and saved in each language you choose. This form stays as it is.`)}function Xs(e){return(e?.origin?.localizations??[]).filter(e=>!e.exists).map(e=>e.site)}function Zs(e,t){if(!e)return null;let n=new Map((t?.origin?.localizations??[]).map(e=>[e.site,e])),r=e=>n.get(e)?.name??e,i=e.state,a=(e.sites?.length?e.sites:i?.run?.scope?.sites??[]).map(r),o=xs(i),s=i?Xo(i):!1,c=s?ws(i):null,l=s?(e.missing??[]).filter(e=>n.get(e)?.exists):[],u=i?.run?.driver??e.driver,d=e.phase===`running`&&i?.run?.status===`running`&&!!i.stalled,f=d&&u===`queue`;return{sites:a.join(`, `),automatic:!!e.automatic,progress:o,keepOpen:e.phase===`running`&&u===`browser`,stalled:d?Qs(f):null,takeOver:f,failure:e.failures?.length?e.failures.at(-1).error?.message??null:null,error:e.phase===`error`?e.error?.message??null:null,result:c&&{...c,text:$s(c.status,o.counts),items:(i.items??[]).map(e=>{let t=Fs(e,r);return{...t,handle:e.target_site,editUrl:n.get(e.target_site)?.edit_url??t.editUrl}})},reload:l.length>0}}function Qs(e){return e?__(`No queue worker has worked on these translations for a while. Start a queue worker, or translate them in this page instead.`):__(`The process that updates these translations has not worked on them for a while and may have stopped. Cancel it, then start the translations again.`)}function $s(e,t){let n=Cs(t,__n(`:count saved|:count saved`,t.done));return{completed:__(`The translations are done: :items.`,{items:n}),completed_with_errors:__(`The translations are done, with errors: :items.`,{items:n}),cancelled:__(`The translations were cancelled: :items.`,{items:n}),aborted:__(`The translations were stopped: :items.`,{items:n})}[e]}function ec({store:e=Hs,api:t=J,createFollower:n=Ls,wait:r=e=>new Promise(t=>setTimeout(t,e)),delays:i=Ws}={}){let a=new Map,o=new Set,s=0;function c(t){return Object.values(e().containers).filter(e=>e.push?.run===t)}function l(e,t){for(let n of c(e))n.push.state=t,Xo(t)&&n.push.phase===`running`&&(n.push.phase=`finished`,n.push.cancelling=!1,d(n.reference));Xo(t)&&a.delete(e)}function u(e,t){for(let n of c(e))n.push.failures=t}async function d(n){try{let r=await t.get(`editor/status`,{reference:n});for(let t of Object.values(e().containers))t.reference===n&&(t.status=r)}catch(e){e?.status!==403&&Statamic.$toast.error(__(`The translation status could not be updated: :message`,{message:e?.message??``}))}}function f(e,{run:t=null,driver:n=null,automatic:r=!1,sites:i=null,missing:a=[]}){return{phase:e,run:t,driver:n,automatic:r,sites:i,state:null,failures:[],missing:a,cancelling:!1,takingOver:!1,error:null}}function p(t,n,r,i=null){e().container(t).push=f(`running`,{run:n.run,driver:n.driver,automatic:n.automatic===!0,sites:i,missing:r})}function m(e){return e?.push?.run?a.get(e.push.run)??null:null}function h(e,t){let r=a.get(e.run);r||(r=n({urls:e.urls,lanes:e.lanes,onState:t=>l(e.run,t),onFailures:t=>u(e.run,t)}),a.set(e.run,r)),o.has(e.run)||r.follow(t)}function g(e){return o.add(e),a.get(e)?.stop(),t=>{o.delete(e),a.get(e)?.follow(t)}}async function _(n,{reference:r,sites:i,mode:a,overwriteManual:o=!1,review:s=null,newStatus:c=null}){let l=e().container(n);if(Us.includes(l.push?.phase)||l.reference!==r)return null;let u=Xs(l.status).filter(e=>i.includes(e));l.push=f(`starting`,{sites:i,missing:u});try{let l=await t.post(`editor/push`,{reference:r,sites:i,mode:a,overwrite_manual:o,review:s,new_status:c});return e().containers[n]?.reference===r&&p(n,l,u,i),h(l,l.state),l}catch(t){let i=e().containers[n];return i?.reference===r?t?.code===`run_active`&&t.data?.active_run?(i.push=null,await v(n,{active_run:t.data.active_run,origin:i.status?.origin}),null):(i.push={...i.push,phase:`error`,error:Po(t)},null):null}}async function v(n,r){let i=r?.active_run,a=e().containers[n];if(!i||!a||a.push?.run===i.run)return;let o=a.reference;p(n,i,Xs(r));try{h(i,await t.get(i.urls.state))}catch(t){let r=e().containers[n];r?.reference===o&&r.push?.run===i.run&&(r.push.failures=[{error:Po(t)}])}}async function y(n,a,{published:o=!1}={}){let c=e().containers[n],l=c?.reference;if(a?.active_run){await v(n,a);return}let u=Gs(a),d=o?!!a?.origin?.auto_update:a?.origin?.auto_update===`save`;if(!c||!d||u.length===0||Us.includes(c.push?.phase))return;let p=++s;c.push={...f(`expecting`,{automatic:!0,sites:u}),expecting:p};let m=()=>{let t=e().containers[n];return t?.reference===l&&t.push?.phase===`expecting`&&t.push.expecting===p?t:null};for(let e of i){if(await r(e),!m())return;let i=null;try{i=await t.get(`editor/status`,{reference:l})}catch{}let a=m();if(!a||i===null){a&&(a.push=null);return}if(a.status=i,i.active_run){a.push=null,await v(n,i);return}if(Gs(i).length===0){a.push=f(`updated`,{automatic:!0,sites:u});return}}let h=m();h&&(h.push=null)}async function b(t){let n=e().containers[t],r=m(n);if(r){n.push.failures=[];try{r.follow(await r.refresh())}catch(e){n.push.failures=[{error:Po(e)}]}}}async function x(t){let n=e().containers[t],r=m(n);if(r){n.push.cancelling=!0;try{await r.cancel()}catch(e){n.push.cancelling=!1,Statamic.$toast.error(e.message)}}}async function S(t){let n=e().containers[t],r=m(n),i=n?.push;if(r&&!i.takingOver){i.takingOver=!0;try{await r.takeOver()}catch(e){Statamic.$toast.error(e.message)}finally{i.takingOver=!1}}}function C(t){let n=e().containers[t];n&&!Us.includes(n.push?.phase)&&(n.push=null)}return{start:_,adopt:v,afterSave:y,resume:b,cancel:x,takeOver:S,dismiss:C,lend:g,following:e=>a.has(e)}}var tc=ec(),nc=[`planning`,`working`],rc=[`source_changed`,`plan_expired`,`target_missing`],ic=`edited_in_form`;function ac(e,t=()=>Statamic.$progress){return t()?.names?.().includes(`${e}-entry-publish-form`)??!1}function oc(){return __(`The form is being saved. Try again when the save has finished.`)}function sc(e,t,n){return!!t&&!t.pending&&no(e.values.value[n],t.value)}function cc(e,t,{name:n,registry:r,delivered:i={}}){let a=Y(t?.localization?.fields),o=e.originValues?.value??{},s=new Set(r.dirtyHandles(n));for(let[t,n]of Object.entries(a))n?.status===`untranslated`&&Object.hasOwn(o,t)&&!no(e.values.value[t],o[t])&&s.add(t);return[...s].filter(t=>Object.hasOwn(a,t)&&!sc(e,i[t],t))}function lc(e,t){let n=Y(t?.localization?.fields);return e.localizedFields.value.filter(e=>Object.hasOwn(n,e))}function uc(e,{overwriteManual:t=!1}={}){let n=Object.values(e?.delivered??{}).some(e=>!e.pending&&!e.sync),r=e?.status?.localization?.counts??{};return n||(r.current??0)>0||t&&(r.manual??0)>0}function dc(e){let t=new Set([...e?.delivered??[],...Object.keys(e?.skipped??{}),...e?.unchanged??[]]);return(e?.planned??[]).filter(e=>!t.has(e))}function fc(e){if(e?.phase===`error`)return!0;let t=e?.summary?.failed??{};return e?.phase===`done`&&dc(e.summary).some(e=>Object.hasOwn(t,e))}function pc(e){let t=e?.status?.localization;return e?.created&&!e.slugKept&&!t?.translate_slug?t?.origin_slug??null:null}function mc(e){let t=e?.snapshot?.fields;return t?Object.entries(t).some(([t,n])=>yo(n,e.delivered?.[t])):!1}function hc(e,t){return __n(`:fields was changed after the translation and was kept.|:fields were changed after the translation and were kept.`,e.length,{fields:xa(e,t)})}function gc(e){return Object.entries(Y(e))}function _c(e){return Object.fromEntries(gc(e).filter(([,e])=>e===ic).map(([e])=>[e,`edited`]))}function vc(e){return Object.fromEntries(gc(e).filter(([,e])=>e!==ic))}function yc(e,t){return e.replace===!0&&(e.fields??[]).includes(t)}function bc(e,{reference:t,skip:n}){return{reference:t,mode:e.mode,overwrite_manual:e.overwriteManual,fields:e.fields,skip:n,translator:e.translator,review:e.review,reviewer:e.reviewer}}function xc(e,{reference:t,handles:n,values:r}){return{reference:t,values:Object.fromEntries(n.map(e=>[e,r[e]])),overwrite_manual:e.overwriteManual,reviewer:e.reviewer}}function Sc(e,t){let n=t.snapshot,r=!1;if(!n||n.reference!==e.reference)return e;for(let[i,a]of Object.entries(n.fields))yo(a,t.delivered[i])&&(e.fields[i]=a,r=!0);return r&&(e.dirty=n.dirty),e}function Cc({store:e=Hs,registry:t=Ha,api:n=J,concurrency:r=()=>Statamic.$config.get(`tolk.concurrency`),run:i=Lo,fill:a=xo,undoFill:o=So,keepSlug:s=wo,recheckSlug:c=To,saving:l=ac,toast:u=()=>Statamic.$toast}={}){let d=new Map,f=new Set;function p(e){return l(e)?(u().error(oc()),!0):!1}function m(t){let n=d.get(t),r=e();n&&(d.delete(t),n.controller.abort()),nc.includes(r.containers[t]?.phase)&&r.setPhase(t,`idle`)}function h(t){let n=d.get(t),r=e().containers[t];n&&!n.controller.signal.aborted&&r?.phase===`working`&&(n.controller.abort(),r.progress={...r.progress,cancelling:!0})}async function g(o,l,{continuing:u=!1}={}){let f=e(),m=t.context(o),h=f.container(o);if(!m||nc.includes(h.phase)||d.has(o)||!m.reference.value||p(o))return null;let g=m.reference.value,_={},v=new AbortController,y=()=>d.get(o)?.token===_,b=()=>y()&&f.containers[o]===h&&m.reference.value===g,x=()=>f.containers[o]?.lastChangeAt??0,S=pc(h),C=l.kind===`review`,w=C?l.fields??lc(m,h.status):l.fields,ee=bo(m,w??Object.keys(m.values.value),h.delivered),T=Z(m.values.value),E=C?[]:cc(m,h.status,{name:o,registry:t,delivered:h.delivered}).filter(e=>!yc(l,e)),[te,D]=C?[`editor/review`,xc(l,{reference:g,handles:w,values:T})]:[`editor/plan`,bc(l,{reference:g,skip:E})];u&&Sc(ee,h),d.set(o,{token:_,controller:v}),Object.assign(h,{request:l,snapshot:ee,summary:null,notSaved:[],planReference:g,progress:Bs().progress}),f.setPhase(o,`planning`);let ne=S?s(m,S,{reference:g,lastChangeAt:x,active:y}):null;ne?.catch(()=>{});try{let e=await n.post(te,D);if(!b())return null;if(ne){if(await ne,!b())return null;h.slugKept=!0}f.setPhase(o,`working`),h.progress={...Bs().progress,total:e.units?.length??0};let t={reference:g,plan:e.plan,lastChangeAt:x,planValues:T,delivered:h.delivered,active:y},s=await i({api:n,plan:e,concurrency:r(),signal:v.signal,finishing:y,onFields:e=>a(m,e,t),onProgress:e=>{b()&&(h.progress={...e,cancelling:v.signal.aborted})}});if(ne&&s.delivered.length&&b()&&await c(m,S,{reference:g,active:y}),!b())return null;let u={...s,kind:l.kind,reviewer:e.reviewer??null,plan:e.plan,planned:Array.isArray(e.fields)?e.fields:[],skipped:{..._c(e.skipped),...s.skipped},planSkipped:vc(e.skipped),warnings:[...new Set([...Array.isArray(e.warnings)?e.warnings:[],...s.warnings??[]])],cancelled:v.signal.aborted};return h.summary=u,f.setPhase(o,s.stopped?`error`:`done`,s.stopped),u}catch(e){return b()&&f.setPhase(o,`error`,Po(e,__(`Something went wrong.`))),null}finally{y()&&d.delete(o)}}function _(e,{mode:t=`missing`,fields:n=null,overwriteManual:r=!1,translator:i=null,review:a=null,reviewer:o=null,replace:s=!1}={}){return g(e,{kind:`translate`,mode:t,fields:n,overwriteManual:r,translator:i,review:a,reviewer:o,replace:s})}function v(e,{fields:t=null,overwriteManual:n=!1,reviewer:r=null}={}){return g(e,{kind:`review`,fields:t,overwriteManual:n,reviewer:r})}function y(t){let n=e().containers[t];if(!n?.request||nc.includes(n.phase))return null;let r=n.summary?dc(n.summary):n.request.fields;return r!==null&&r.length===0?(e().setPhase(t,`done`),null):g(t,{...n.request,fields:r},{continuing:!0})}async function b(n){let r=e(),i=r.containers[n],a=t.context(n);if(!a||!i?.snapshot||nc.includes(i.phase)||f.has(n)||p(n))return null;f.add(n);try{let e=await o(a,i.snapshot,i.delivered,{registry:t});return r.containers[n]===i&&r.clearResult(n),e}finally{f.delete(n)}}return{translate:_,review:v,retry:y,cancel:h,abort:m,undo:b,running:e=>d.has(e),current:e=>d.get(e)?.token??null,saving:e=>l(e)}}var $=Cc(),wc=`tolk-banner`;function Tc(e){return typeof e==`string`&&e.startsWith(`term::`)}function Ec(e,t){return[`idle`,`done`,`error`].includes(e)&&!!t?.localization&&!t?.setup}function Dc(e){let t=e?.reference?.value;return e?.name===`base`&&typeof t==`string`&&(t.startsWith(`entry::`)||Tc(t))&&Statamic.$config.get(`tolk.multisite`)===!0&&Statamic.$permissions.has(`translate content`)}function Oc({store:e=Hs,abort:t=e=>$.abort(e)}={}){let n=new Map,r=!1;function i(e=Statamic.$events){r||(r=!0,e.$on(`publish-container-created`,a),e.$on(`publish-container-destroyed`,o))}function a(e){let t=null;s(e.name),Dc(e)&&(t=e.pushComponent(wc,{props:{containerName:e.name}})),n.set(e.name,[...n.get(e.name)??[],t])}function o({name:e}){let[t,...r]=n.get(e)??[];t?.destroy(),r.length?n.set(e,r):(n.delete(e),s(e))}function s(n){t(n),e().forget(n)}return{listen:i,pushed:e=>(n.get(e)??[]).filter(Boolean).length}}var kc=Oc();function Ac({name:e,ctx:t,store:n=Hs(),registry:r=Ha,loadStatus:i=e=>Qi(`editor/status`,{reference:e}),now:a=Date.now,settleMs:o=600,onSwitch:s=e=>$.abort(e),onStatus:c=(e,t)=>tc.adopt(e,t)}){let l=I(null),u=!!t.reference.value&&n.container(e).reference===t.reference.value;r.attachContext(e,t);let d=r=>t.reference.value===r&&n.containers[e]?.reference===r;async function f(r){if(l.value=null,!t.readOnly?.value)try{let t=await i(r);d(r)&&(n.container(e).status=t,c(e,t))}catch(e){d(r)&&e?.status!==403&&(l.value=e)}}function p(t){let i=a();s(e),n.switched(e,t,i),r.refreshClean(e),setTimeout(()=>{n.containers[e]?.lastChangeAt===i&&d(t)&&r.refreshClean(e)},o),f(t)}return{failure:l,stop:bn(()=>[t.reference.value,t.site.value],([t],r)=>{if(t){if(r===void 0&&u){n.container(e).status===null&&f(t);return}p(t)}},{immediate:!0,flush:`post`})}}function jc(){let e=!1,t=!1,n=Dt({open:!1,show(){e?t=!0:n.open=!0},hide(){t=!1,e||(n.open=!1)},dismissed(){e=!0},closed(r){r||(e=!1,n.open=!1,t&&(t=!1,nt(()=>n.open=!0)))}});return n}var Mc={class:`space-y-2 ps-6`,"data-tolk-push":``},Nc={class:`sr-only`,"aria-live":`polite`,"data-tolk-push-announcement":``},Pc={key:0,class:`flex flex-wrap items-center gap-2 pt-1`,"data-tolk-push-actions":``},Fc={key:3,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-phase":`updated`},Ic={key:4,class:`space-y-2`,"data-tolk-push-phase":`running`},Lc={class:`flex flex-wrap items-center justify-between gap-2`},Rc={key:1,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-stalled":``},zc={key:2,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-failure":``},Bc=[`data-tolk-push-status`],Vc={class:`space-y-1`},Hc=[`data-tolk-push-item`,`data-tolk-push-item-status`],Uc=[`href`],Wc=[`href`],Gc={class:`flex flex-wrap gap-2`},Kc={key:6,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-phase":`error`},qc={class:`space-y-6`},Jc={class:`space-y-3`},Yc=[`data-tolk-push-site`],Xc={class:`flex items-center justify-end gap-3 pt-3 pb-1`},Zc={__name:`OriginPush`,props:{containerName:{type:String,required:!0},reference:{type:String,required:!0},origin:{type:Object,required:!0},status:{type:Object,default:null},dirty:{type:Boolean,default:!1}},setup(e){let t=e,n=Hs(),r=O(()=>n.containers[t.containerName]?.push??null),i=O(()=>Zs(r.value,t.status)),a=O(()=>Us.includes(r.value?.phase)),o=O(()=>!a.value&&(t.origin.translateInto||t.origin.update)),s=O(()=>Ks(t.origin)),c=jc(),l=I([]),u=I(`draft`),d=I(!1),f=O(()=>s.value.some(e=>e.missing&&l.value.includes(e.site))),p=O(()=>Tc(t.reference)),h=O(()=>Js(t.origin,{dirty:t.dirty,term:p.value})),g=O(()=>Ys(t.origin,{term:p.value}));function _(){l.value=s.value.map(e=>e.site),u.value=t.status?.defaults?.new_status===`mirror`?`mirror`:`draft`,d.value=t.status?.defaults?.review===!0,c.show()}function v(e,t){l.value=t?[...new Set([...l.value,e])]:l.value.filter(t=>t!==e)}function y(){c.hide(),tc.start(t.containerName,{reference:t.reference,sites:s.value.map(e=>e.site).filter(e=>l.value.includes(e)),mode:`missing`,review:d.value,newStatus:f.value?u.value:null})}function b(){tc.start(t.containerName,{reference:t.reference,sites:qs(t.origin),mode:`update`})}let x=O(()=>i.value?.automatic?__(`Updating the translations automatically into :sites…`,{sites:i.value.sites}):__(`Translating into :sites…`,{sites:i.value.sites})),S=O(()=>__(`The translations into :sites were updated automatically.`,{sites:i.value?.sites??``})),C=O(()=>{switch(r.value?.phase){case`starting`:return __(`Starting the translation…`);case`expecting`:return x.value;case`updated`:return S.value;case`running`:return i.value.failure?__(`The translations stopped: :message`,{message:i.value.failure}):i.value.stalled??x.value;case`error`:return i.value?.error??``;default:return i.value?.result?.text??``}});function w(){window.location.reload()}return(t,n)=>(F(),j(`div`,Mc,[M(`p`,Nc,R(C.value),1),o.value?(F(),j(`div`,Pc,[e.origin.translateInto?(F(),k(z(V),{key:0,variant:`primary`,size:`sm`,disabled:e.dirty,"data-tolk-action":`translate-into`,onClick:_},{default:B(()=>[N(R(t.__(`Translate into…`)),1)]),_:1},8,[`disabled`])):A(``,!0),e.origin.update?(F(),k(z(V),{key:1,size:`sm`,disabled:e.dirty,"data-tolk-action":`update-translations`,onClick:b},{default:B(()=>[N(R(t.__(`Update translations`)),1)]),_:1},8,[`disabled`])):A(``,!0),h.value?(F(),k(z(U),{key:2,"data-tolk-save-first":``},{default:B(()=>[N(R(h.value),1)]),_:1})):A(``,!0)])):A(``,!0),r.value?.phase===`starting`?(F(),k(z(q),{key:1,as:`p`,"data-tolk-push-phase":`starting`},{default:B(()=>[N(R(t.__(`Starting the translation…`)),1)]),_:1})):A(``,!0),r.value?.phase===`expecting`?(F(),k(z(q),{key:2,as:`p`,"data-tolk-push-phase":`expecting`},{default:B(()=>[N(R(x.value),1)]),_:1})):A(``,!0),r.value?.phase===`updated`?(F(),j(`div`,Fc,[P(z(q),null,{default:B(()=>[N(R(S.value),1)]),_:1}),P(z(V),{size:`sm`,variant:`ghost`,"data-tolk-action":`push-close`,onClick:n[0]||=t=>z(tc).dismiss(e.containerName)},{default:B(()=>[N(R(t.__(`Close`)),1)]),_:1})])):A(``,!0),r.value?.phase===`running`?(F(),j(`div`,Ic,[M(`div`,Lc,[r.value.cancelling?(F(),k(z(q),{key:0},{default:B(()=>[N(R(t.__(`Cancelling. Translations already being saved are still saved.`)),1)]),_:1})):(F(),k(z(q),{key:1,"data-tolk-push-working":``},{default:B(()=>[N(R(x.value),1)]),_:1})),P(z(V),{size:`sm`,variant:`ghost`,disabled:r.value.cancelling,"data-tolk-action":`push-cancel`,onClick:n[1]||=t=>z(tc).cancel(e.containerName)},{default:B(()=>[N(R(t.__(`Cancel`)),1)]),_:1},8,[`disabled`])]),P(Ba,{value:i.value.progress.finished,max:i.value.progress.total,label:t.__(`Translation progress`)},null,8,[`value`,`max`,`label`]),P(z(U),{"data-tolk-push-progress":``},{default:B(()=>[N(R(t.__(`:finished of :total translations finished.`,{finished:i.value.progress.finished,total:i.value.progress.total})),1)]),_:1}),i.value.keepOpen?(F(),k(z(U),{key:0},{default:B(()=>[N(R(p.value?t.__(`Keep this page open until the translations are saved. If you leave, they continue when you open this term again.`):t.__(`Keep this page open until the translations are saved. If you leave, they continue when you open this entry again.`)),1)]),_:1})):A(``,!0),i.value.stalled?(F(),j(`div`,Rc,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-amber-600`,"aria-hidden":`true`}),P(z(q),null,{default:B(()=>[N(R(i.value.stalled),1)]),_:1}),i.value.takeOver?(F(),k(z(V),{key:0,size:`sm`,disabled:r.value.takingOver||r.value.cancelling,loading:r.value.takingOver,"data-tolk-action":`push-take-over`,onClick:n[2]||=t=>z(tc).takeOver(e.containerName)},{default:B(()=>[N(R(t.__(`Translate in this page instead`)),1)]),_:1},8,[`disabled`,`loading`])):A(``,!0)])):A(``,!0),i.value.failure?(F(),j(`div`,zc,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-red-600`,"aria-hidden":`true`}),P(z(q),{variant:`danger`},{default:B(()=>[N(R(t.__(`The translations stopped: :message`,{message:i.value.failure})),1)]),_:1}),P(z(V),{size:`sm`,"data-tolk-action":`push-resume`,onClick:n[3]||=t=>z(tc).resume(e.containerName)},{default:B(()=>[N(R(t.__(`Try again`)),1)]),_:1})])):A(``,!0)])):A(``,!0),i.value?.result?(F(),j(`div`,{key:5,class:`space-y-2`,"data-tolk-push-result":``,"data-tolk-push-status":i.value.result.status},[P(z(q),{as:`p`},{default:B(()=>[N(R(i.value.result.text),1)]),_:1}),i.value.result.error?(F(),k(z(q),{key:0,as:`p`,variant:`danger`},{default:B(()=>[N(R(i.value.result.error),1)]),_:1})):A(``,!0),M(`ul`,Vc,[(F(!0),j(m,null,L(i.value.result.items,e=>(F(),j(`li`,{key:e.index,class:`flex flex-wrap items-center gap-2`,"data-tolk-push-item":e.handle,"data-tolk-push-item-status":e.status},[e.editUrl?(F(),j(`a`,{key:0,href:e.editUrl,class:`text-sm font-medium underline`},R(e.site),9,Uc)):(F(),k(z(q),{key:1,variant:`strong`},{default:B(()=>[N(R(e.site),1)]),_:2},1024)),P(z(Pn),{text:e.statusLabel,color:e.statusColor},null,8,[`text`,`color`]),e.error||e.reason?(F(),k(z(U),{key:2},{default:B(()=>[N(R(e.error??e.reason)+` `,1),e.rootPage?(F(),j(`a`,{key:0,href:e.rootPage.url,class:`font-medium underline`,"data-tolk-root-page":``},R(t.__(`Open :title`,{title:e.rootPage.title})),9,Wc)):A(``,!0)]),_:2},1024)):A(``,!0)],8,Hc))),128))]),i.value.reload?(F(),k(z(U),{key:1},{default:B(()=>[N(R(t.__(`Reload the page to see the new localizations in the Sites panel.`)),1)]),_:1})):A(``,!0),M(`div`,Gc,[i.value.reload?(F(),k(z(V),{key:0,size:`sm`,variant:`primary`,"data-tolk-action":`reload`,onClick:w},{default:B(()=>[N(R(t.__(`Reload`)),1)]),_:1})):A(``,!0),P(z(V),{size:`sm`,variant:`ghost`,"data-tolk-action":`push-close`,onClick:n[4]||=t=>z(tc).dismiss(e.containerName)},{default:B(()=>[N(R(t.__(`Close`)),1)]),_:1})])],8,Bc)):A(``,!0),r.value?.phase===`error`?(F(),j(`div`,Kc,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-red-600`,"aria-hidden":`true`}),P(z(q),{variant:`danger`,"data-tolk-push-error":``},{default:B(()=>[N(R(i.value.error),1)]),_:1}),P(z(V),{size:`sm`,variant:`ghost`,"data-tolk-action":`push-close`,onClick:n[5]||=t=>z(tc).dismiss(e.containerName)},{default:B(()=>[N(R(t.__(`Close`)),1)]),_:1})])):A(``,!0),z(c).open?(F(),k(z(Wr),{key:7,open:``,title:t.__(`Translate into other languages`),icon:`dictionary-language-book`,"data-tolk-push-modal":``,onDismissed:n[9]||=e=>z(c).dismissed(),"onUpdate:open":n[10]||=e=>z(c).closed(e)},{footer:B(()=>[M(`div`,Xc,[P(z(V),{variant:`ghost`,text:t.__(`Cancel`),"data-tolk-push-action":`close`,onClick:n[8]||=e=>z(c).hide()},null,8,[`text`]),P(z(V),{variant:`primary`,text:t.__(`Translate`),disabled:l.value.length===0,"data-tolk-push-action":`translate`,onClick:y},null,8,[`text`,`disabled`])])]),default:B(()=>[M(`div`,qc,[P(z(q),{as:`p`},{default:B(()=>[N(R(g.value),1)]),_:1}),M(`div`,Jc,[(F(!0),j(m,null,L(s.value,e=>(F(),j(`div`,{key:e.site,"data-tolk-push-site":e.site},[P(z(Vn),{"model-value":l.value.includes(e.site),label:e.name,description:e.summary,"onUpdate:modelValue":t=>v(e.site,t)},null,8,[`model-value`,`label`,`description`,`onUpdate:modelValue`])],8,Yc))),128))]),f.value?(F(),k(z(yr),{key:0,id:`tolk-push-status`,label:t.__(`New localizations`)},{default:B(()=>[P(z(ui),{modelValue:u.value,"onUpdate:modelValue":n[6]||=e=>u.value=e,appearance:`inline`,"data-tolk-push-new-status":``},{default:B(()=>[P(z(li),{value:`draft`,label:t.__(`Drafts`)},null,8,[`label`]),P(z(li),{value:`mirror`,label:t.__(`Same as origin`)},null,8,[`label`])]),_:1},8,[`modelValue`])]),_:1},8,[`label`])):A(``,!0),P(z(Vn),{modelValue:d.value,"onUpdate:modelValue":n[7]||=e=>d.value=e,label:t.__(`Review after translating`),description:t.__(`A second model checks each translation and corrects it before it is saved.`)},null,8,[`modelValue`,`label`,`description`])])]),_:1},8,[`title`])):A(``,!0)]))}},Qc=`tolk.offer`,$c=null;function el(e,t,{preferences:n=()=>Statamic.$preferences,toast:r=()=>Statamic.$toast}={}){let i=()=>new Promise(r=>r(n().set(e,t))).then(()=>!0,()=>(r().error(__(`Your choice could not be saved.`)),!1)),a=$c?$c.then(i):i();return $c=a,a.then(()=>{$c===a&&($c=null)}),a}function tl(e=Statamic.$preferences){return e.get(Qc,!0)!==!1}function nl(e,t=Statamic.$preferences){return e?.offer===!0&&tl(t)&&ua(e).localization?.translate===!0}function rl(e){let t=ua(e);return{count:e?.localization?.counts?.untranslated??0,source:t.localization?.source?.name??``,target:t.localization?.target?.name??``,translator:t.translator}}var il=350;function al({store:e=Hs,registry:t=Ha,translations:n=$,preferences:r=()=>Statamic.$preferences,toast:i=()=>Statamic.$toast,openAfterMs:a=il,clock:o=()=>Date.now(),wait:s=(e,t)=>setTimeout(e,t)}={}){let c=null,l=!1;function u(e=Statamic.$events){l||(l=!0,e.$on(`localization.created`,d))}function d(n){let r=n?.container?.name,i=t.context(r)?.reference?.value;if(r!==`base`||!i)return;m();let s=e(),l=o()+a;if(f(s,r,i,l))return;let u=bn(()=>{let e=s.containers[r];return[e?.reference,e?.status]},()=>{f(s,r,i,l)&&(u(),c===u&&(c=null))});c=u}function f(e,n,r,i){let a=e.containers[n];return a?.reference===r?(a.created=!0,a.status!==null&&(p(e,n,r,i),!0)):t.context(n)?.reference?.value!==r}function p(e,t,n,i){let a=i-o();if(a>0){s(()=>p(e,t,n,i),a);return}let c=e.containers[t];c?.reference===n&&c.phase===`idle`&&nl(c.status,r())&&e.setPhase(t,`offer`)}function m(){c?.(),c=null}function h(t,n){let a=e();return a.phaseOf(t)===`offer`&&(n&&el(Qc,!1,{preferences:r,toast:i}),a.setPhase(t,`idle`),!0)}function g(e,{dontOfferAgain:t=!1}={}){return h(e,t)?n.translate(e,{mode:`missing`}):null}function _(e,{dontOfferAgain:t=!1}={}){h(e,t)}return{listen:u,created:d,accept:g,decline:_,waiting:e=>e===`base`&&c!==null}}var ol=al(),sl={class:`space-y-1`},cl={class:`flex items-center justify-end gap-3 pt-3 pb-1`},ll={__name:`TranslateOffer`,props:{containerName:{type:String,required:!0},status:{type:Object,default:null},open:{type:Boolean,default:!1}},setup(e){let t=e,n=I(!1),r=O(()=>rl(t.status));bn(()=>t.open,e=>{e&&(n.value=!1)});function i(){ol.accept(t.containerName,{dontOfferAgain:n.value})}function a(){ol.decline(t.containerName,{dontOfferAgain:n.value})}return(t,o)=>(F(),k(z(Wr),{open:e.open,title:t.__(`Translate this entry?`),icon:`dictionary-language-book`,"data-tolk-offer":``,onDismissed:a},{footer:B(()=>[M(`div`,cl,[P(z(V),{variant:`ghost`,text:t.__(`Not now`),"data-tolk-offer-action":`decline`,onClick:a},null,8,[`text`]),P(z(V),{variant:`primary`,text:t.__(`Translate`),"data-tolk-offer-action":`translate`,onClick:i},null,8,[`text`])])]),default:B(()=>[M(`div`,sl,[P(z(q),{as:`p`,"data-tolk-offer-text":``},{default:B(()=>[N(R(t.__n(`Translate :count field from :source into :target. Nothing is saved until you press Save.|Translate :count fields from :source into :target. Nothing is saved until you press Save.`,r.value.count,{source:r.value.source,target:r.value.target})),1)]),_:1}),r.value.translator?(F(),k(z(U),{key:0,"data-tolk-offer-model":``},{default:B(()=>[N(R(t.__(`Model: :model`,{model:z(ba)(r.value.translator)})),1)]),_:1})):A(``,!0)]),P(z(Vn),{modelValue:n.value,"onUpdate:modelValue":o[0]||=e=>n.value=e,label:t.__(`Don't offer again`)},null,8,[`modelValue`,`label`])]),_:1},8,[`open`,`title`]))}},ul=`automatic`;function dl(e){return typeof e==`string`&&e.trim()!==``?e.trim():null}function fl(e){return/^[^\s:]+:\S+$/.test(e)}function pl(e){return{quality:__(`Quality`),fast:__(`Fast`)}[e]??null}function ml(e,t){return{value:e,label:e,note:Y(t)[e.split(`:`)[0]]?.[0]?.configured===!1?__(`No API key`):__(`Custom model`),disabled:!1}}function hl(e,t){let n=[{value:ul,label:e?.automatic||__(`Automatic`),note:null,disabled:!1}],r=e?.fake_engine===!0;for(let t of Object.values(Y(e?.catalog)).flat())n.push({value:t.value,label:t.label,note:t.configured?pl(t.tier):__(`No API key`),disabled:!t.configured&&!r});let i=dl(t);return i&&!n.some(e=>e.value===i)&&n.push(ml(i,e?.catalog)),n}function gl(e,t){if(e===null||e===`automatic`)return null;let n=t.find(t=>t.value===e);if(n)return n.disabled?void 0:n.value;let r=typeof e==`string`?e.trim():``;return fl(r)?r:void 0}var _l=`tolk.editor.translator`,vl=`tolk.editor.reviewer`;function yl(e,t){let n=e.get(t,null);return typeof n==`string`&&n!==``?n:null}function bl(e=Statamic.$preferences,t=_l){let n=yl(e,t);return n!==null&&fl(n)?n:null}function xl(e,{fakeEngine:t=!1,defaultModel:n=null,extra:r=[]}={}){let i=[];for(let r of Object.values(Y(e)).flat())(r.configured||t)&&i.push({value:r.value,label:r.value===n?__(`:model (default)`,{model:r.label}):r.label});for(let e of r)e&&!i.some(t=>t.value===e)&&i.push({value:e,label:e===n?__(`:model (default)`,{model:e}):e});return i}function Sl(e,t,n){if(t.some(t=>t.value===e))return e;let r=typeof e==`string`?e.trim():``;return fl(r)?r:n}function Cl(e,{remembered:t=null,defaultModel:n=null}={}){let r=t=>t!==null&&e.some(e=>e.value===t);return r(t)?t:r(n)?n:e[0]?.value??null}function wl(e,t){return e&&e!==t?e:null}function Tl(e,t,n){return n?e||null:wl(e,t)}function El({model:e=null,defaultModel:t=null,retranslate:n=!1,overwriteManual:r=!1,review:i=null,reviewer:a=null,defaultReviewer:o=null}={}){let s=wl(e,t);return{mode:n?`all`:`update`,overwriteManual:r,translator:s,review:i,reviewer:i===!0?Tl(a,o,s):null}}function Dl({reviewer:e=null,defaultReviewer:t=null,overwriteManual:n=!1}={}){return{overwriteManual:n,reviewer:wl(e,t)}}function Ol(e){let t=e?.localization?.counts??{},n=Object.values(e?.localization?.fields??{}).filter(e=>e.incomplete).length;return{markCurrent:(t.attention??0)+(t.untracked??0)>0,protect:(t.current??0)+(t.outdated??0)-n>0}}function kl(e,t){return e===0?__(`No field needed changing.`):t?__n(`:count field is now protected from updates.|:count fields are now protected from updates.`,e):__n(`:count field marked as up to date.|:count fields marked as up to date.`,e)}function Al({store:e=Hs,registry:t=Ha,api:n=J,translations:r=$,preferences:i=()=>Statamic.$preferences,toast:a=()=>Statamic.$toast}={}){let o=null;function s(){return o??=n.get(`models`).catch(e=>{throw o=null,e}),o}function c(e,t){t!==yl(i(),e)&&el(e,t,{preferences:i,toast:a})}function l(t,n={}){let i=El(n);return nc.includes(e().phaseOf(t))?null:(c(_l,i.translator),i.review===!0&&c(vl,wl(n.reviewer,n.defaultReviewer)),r.translate(t,i))}function u(t,n={}){let i=Dl(n);return nc.includes(e().phaseOf(t))?null:(c(vl,i.reviewer),r.review(t,i))}async function d(r,{protect:i=!1}={}){let o=e().containers[r],s=t.context(r)?.reference?.value??null;if(!o||!s||o.reference!==s||nc.includes(o.phase))return null;try{let{baselined:e=0,...t}=await n.post(`editor/baseline`,{reference:s,protect:i});return o.status=t,a().success(kl(e,i)),e}catch(e){return a().error(e?.message||__(`Something went wrong.`)),null}}function f(e){return el(Qc,e,{preferences:i,toast:a})}return{loadModels:s,translate:l,review:u,baseline:d,setOffers:f}}var jl=Al(),Ml={class:`space-y-4`},Nl={class:`space-y-3`},Pl={class:`grid gap-4 sm:grid-cols-2`},Fl={class:`space-y-3`},Il={key:0,class:`space-y-3 border-t border-gray-200 pt-4 dark:border-gray-700`,"aria-labelledby":`tolk-options-state-heading`,"data-tolk-options-state":``},Ll={key:0,class:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4`},Rl={key:1,class:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4`},zl={key:1,class:`flex items-start justify-between gap-4 border-t border-gray-200 pt-4 dark:border-gray-700`,"data-tolk-options-offer":``},Bl={class:`space-y-0.5`},Vl={class:`flex items-center justify-end gap-3 pt-3 pb-1`},Hl={__name:`TranslateOptions`,props:{containerName:{type:String,required:!0},status:{type:Object,default:null}},setup(e){let t=e,n=Hs(),r=O(()=>Tc(n.containers[t.containerName]?.reference)),i=jc(),a=I(!1),o=I(null),s=I(null),c=I(null),l=I(null),u=I(!1),d=I(!1),f=I(!1),p=I(!0),h=I(!1),g=!!Statamic.$config.get(`tolk.settingsUrl`),_=O(()=>s.value?.defaults?.translator??t.status?.defaults?.translator??null),v=O(()=>s.value?.defaults?.reviewer??null),y=O(()=>bl()),b=O(()=>bl(Statamic.$preferences,vl));function x(e,n,r){return xl(s.value?.catalog,{fakeEngine:t.status?.defaults?.fake_engine===!0,defaultModel:e,extra:g?[e,n,r]:[e]})}let S=O(()=>x(_.value,y.value,c.value)),C=O(()=>x(v.value,b.value,l.value)),w=O(()=>uc(n.containers[t.containerName],{overwriteManual:f.value})),ee=O(()=>u.value||w.value),T=O(()=>Ol(t.status)),E=O(()=>t.status?.offer===!0);async function te(){d.value=!1,f.value=!1,u.value=t.status?.defaults?.review===!0,o.value=null,p.value=tl(),i.show(),a.value=!0;try{s.value=await jl.loadModels()}catch(e){o.value=e.message}finally{a.value=!1}c.value=Cl(S.value,{remembered:y.value,defaultModel:_.value}),l.value=Cl(C.value,{remembered:b.value,defaultModel:v.value})}function D(){i.hide(),jl.translate(t.containerName,{model:c.value,defaultModel:_.value,retranslate:d.value,overwriteManual:f.value,review:u.value,reviewer:l.value,defaultReviewer:v.value})}function ne(){i.hide(),jl.review(t.containerName,{reviewer:l.value,defaultReviewer:v.value,overwriteManual:f.value})}async function re(e){h.value=!0;try{await jl.baseline(t.containerName,{protect:e})!==null&&i.hide()}finally{h.value=!1}}async function ie(e){p.value=e,await jl.setOffers(e)||(p.value=!e)}return(e,t)=>(F(),j(m,null,[P(z(V),{size:`sm`,variant:`ghost`,icon:`sliders-horizontal`,text:e.__(`Options`),"data-tolk-action":`options`,onClick:te},null,8,[`text`]),z(i).open?(F(),k(z(Wr),{key:0,open:``,title:e.__(`Translation options`),icon:`sliders-horizontal`,"data-tolk-options":``,onDismissed:t[8]||=e=>z(i).dismissed(),"onUpdate:open":t[9]||=e=>z(i).closed(e)},{footer:B(()=>[M(`div`,Vl,[P(z(V),{variant:`ghost`,text:e.__(`Close`),"data-tolk-options-action":`close`,onClick:t[7]||=e=>z(i).hide()},null,8,[`text`]),w.value?(F(),k(z(V),{key:0,text:e.__(`Review`),disabled:a.value||!l.value,"data-tolk-options-action":`review`,onClick:ne},null,8,[`text`,`disabled`])):A(``,!0),P(z(V),{variant:`primary`,text:e.__(`Translate`),disabled:a.value||!c.value,"data-tolk-options-action":`translate`,onClick:D},null,8,[`text`,`disabled`])])]),default:B(()=>[M(`div`,Ml,[M(`div`,Nl,[M(`div`,Pl,[P(z(yr),{id:`tolk-options-model`,label:e.__(`Model`)},{default:B(()=>[P(z(Wn),{id:`tolk-options-model`,"model-value":c.value,options:S.value,taggable:z(g),disabled:a.value,placeholder:a.value?e.__(`Loading…`):e.__(`Choose a model`),"data-tolk-options-model":``,"onUpdate:modelValue":t[0]||=e=>c.value=z(Sl)(e,S.value,c.value)},null,8,[`model-value`,`options`,`taggable`,`disabled`,`placeholder`])]),_:1},8,[`label`]),P(z(yr),{id:`tolk-options-reviewer`,label:e.__(`Reviewer`),"data-tolk-options-review":``},{default:B(()=>[P(z(Wn),{id:`tolk-options-reviewer`,"model-value":l.value,options:C.value,taggable:z(g),disabled:a.value||!ee.value,placeholder:a.value?e.__(`Loading…`):e.__(`Choose a model`),"data-tolk-options-reviewer":``,"onUpdate:modelValue":t[1]||=e=>l.value=z(Sl)(e,C.value,l.value)},null,8,[`model-value`,`options`,`taggable`,`disabled`,`placeholder`])]),_:1},8,[`label`])]),z(g)?(F(),k(z(U),{key:0},{default:B(()=>[N(R(e.__(`You may also type a model outside the list, as provider:model.`)),1)]),_:1})):A(``,!0),o.value?(F(),k(z(q),{key:1,as:`p`,variant:`danger`,"data-tolk-options-failure":``},{default:B(()=>[N(R(e.__(`The models could not be loaded: :message`,{message:o.value})),1)]),_:1})):A(``,!0)]),M(`div`,Fl,[P(z(Vn),{modelValue:d.value,"onUpdate:modelValue":t[2]||=e=>d.value=e,label:e.__(`Retranslate everything`),description:e.__(`Also translates the fields that are up to date again.`)},null,8,[`modelValue`,`label`,`description`]),P(z(Vn),{modelValue:f.value,"onUpdate:modelValue":t[3]||=e=>f.value=e,label:e.__(`Overwrite manual edits`),description:e.__(`Also replaces the text of fields edited by hand.`)},null,8,[`modelValue`,`label`,`description`]),P(z(Vn),{modelValue:u.value,"onUpdate:modelValue":t[4]||=e=>u.value=e,label:e.__(`Review after translating`),description:e.__(`The reviewer checks the new translation and corrects it.`)},null,8,[`modelValue`,`label`,`description`])]),T.value.markCurrent||T.value.protect?(F(),j(`section`,Il,[P(z(W),{id:`tolk-options-state-heading`,level:2,text:e.__(`Translation status`)},null,8,[`text`]),T.value.markCurrent?(F(),j(`div`,Ll,[P(z(U),null,{default:B(()=>[N(R(e.__(`Records that the fields edited by hand match the current source, so a later change to the source is flagged.`)),1)]),_:1}),P(z(V),{size:`sm`,class:`shrink-0 self-start sm:self-auto`,text:e.__(`Mark manual fields as up to date`),disabled:h.value,"data-tolk-action":`mark-current`,onClick:t[5]||=e=>re(!1)},null,8,[`text`,`disabled`])])):A(``,!0),T.value.protect?(F(),j(`div`,Rl,[P(z(U),null,{default:B(()=>[N(R(e.__(`Treats the translated fields as edited by hand, so Translate and Update leave them alone.`)),1)]),_:1}),P(z(V),{size:`sm`,class:`shrink-0 self-start sm:self-auto`,text:r.value?e.__(`Protect this term from updates`):e.__(`Protect this entry from updates`),disabled:h.value,"data-tolk-action":`protect`,onClick:t[6]||=e=>re(!0)},null,8,[`text`,`disabled`])])):A(``,!0)])):A(``,!0),E.value&&!r.value?(F(),j(`div`,zl,[M(`div`,Bl,[P(z(Dr),{for:`tolk-options-offer`,text:e.__(`Offer to translate new localizations`)},null,8,[`text`]),P(z(U),{id:`tolk-options-offer-description`},{default:B(()=>[N(R(e.__(`Asks whether to translate each localization you create. Only for your account.`)),1)]),_:1})]),P(z(bi),{id:`tolk-options-offer`,"model-value":p.value,"aria-describedby":`tolk-options-offer-description`,"onUpdate:modelValue":ie},null,8,[`model-value`])])):A(``,!0)])]),_:1},8,[`title`])):A(``,!0)],64))}},Ul=`localizable`,Wl={ok:{color:`green`,icon:`checkmark`,class:`text-green-600`},warning:{color:`amber`,icon:`alert-warning-exclamation-mark`,class:`text-amber-600`},error:{color:`red`,icon:`warning-diamond`,class:`text-red-600`}};function Gl(e){return`tolk-audit-${e}`}function Kl(e){return e?`${e}#${Gl(Ul)}`:null}function ql(e){return{ok:__(`OK`),warning:__(`Warning`),error:__(`Error`)}[e]??e}function Jl(e){return{label:ql(e),...Wl[e]??Wl.warning}}function Yl(e){let t=(Array.isArray(e)?e:[]).flatMap(e=>e.items??[]),n=t.filter(e=>e.level===`error`).length,r=t.filter(e=>e.level===`warning`).length;if(n===0&&r===0)return{level:`ok`,text:__(`Everything is set up. Tolk found nothing to change.`)};let i=[n>0?__n(`:count error|:count errors`,n):null,r>0?__n(`:count warning|:count warnings`,r):null].filter(Boolean);return{level:n>0?`error`:`warning`,text:__(`The audit found :problems. Errors keep Tolk from translating; warnings leave something untranslated or slower than it could be.`,{problems:i.join(`, `)})}}function Xl(e,t){return e?.id===`localizable`?t?__(`A text field that is not localizable is shared by every site, so Tolk does not translate it. Choose the fields that hold text in each language and make them localizable.`):__(`A text field that is not localizable is shared by every site, so Tolk does not translate it. Someone who may edit the Tolk settings and blueprints can make them localizable here, or with php please tolk:doctor --fix-localizable.`):e?.detail??``}function Zl(e){return typeof e?.namespace==`string`&&typeof e?.blueprint==`string`&&Array.isArray(e?.fields)}function Ql(e){return`${e.namespace}|${e.blueprint}`}function $l(e){let t=Array.isArray(e?.fields)?e.fields:[];return{editable:t.filter(e=>!e.fieldset),imported:t.filter(e=>!!e.fieldset)}}function eu(e){return e.label&&e.label!==e.handle?`${e.label} (${e.handle})`:e.handle}function tu(e){return __(`From the fieldset :fieldset: make it localizable in the fieldset, which changes every blueprint that imports it.`,{fieldset:e.fieldset})}function nu(e,t){let n=new Set(Array.isArray(t)?t:[]);return $l(e).editable.map(e=>e.handle).filter(e=>n.has(e))}function ru(e,t){let n=$l(e).editable.filter(e=>t.includes(e.handle)).map(eu).join(`, `);return __n(`This changes the blueprint file of :blueprint: :fields becomes localizable, so each site keeps its own value and Tolk translates it. Existing localizations keep the value they inherit until they are translated or edited.|This changes the blueprint file of :blueprint: :fields become localizable, so each site keeps its own value and Tolk translates them. Existing localizations keep the values they inherit until they are translated or edited.`,t.length,{blueprint:e.name,fields:n})}function iu(e){return e>0?__n(`:count field is now localizable.|:count fields are now localizable.`,e):__(`Nothing changed: the fields were already localizable.`)}function au(e,t){return __n(`:fields was not saved because it was hidden when you saved. Show it and translate it again.|:fields were not saved because they were hidden when you saved. Show them and translate them again.`,e.length,{fields:xa(e,t)})}function ou({PipelineStopped:e,store:t=Hs,registry:n=Ha,api:r=J,now:i=Date.now,running:a=e=>$.current(e),stop:o=e=>$.abort(e),onConfirmed:s=(e,t,n)=>tc.afterSave(e,t,n)}){let c=!1,l=null;function u(e=Statamic.$hooks){if(!c){c=!0;for(let t of[`entry`,`term`])e.on(`${t}.saving`,d),e.on(`${t}.saved`,f);e.on(`entry.published`,m)}}function d(r,i){let o=t(),s=a(X);if(nc.includes(o.phaseOf(`base`))&&s){l!==s&&(l=s,Statamic.$toast.error(__(`A translation is in progress. Wait for it to finish, or cancel it.`))),i(new e);return}let c=n.context(X),u=o.containers[X];c&&u?.reference&&u.reference===c.reference.value&&_o(c,u.delivered),r()}async function f(e,t,n){try{await p(n)}catch(e){console.error(e)}finally{e()}}async function p(e){let a=t(),o=a.containers[X],c=su(e,o);if(!o?.reference||c!==o.reference)return;let l=n.context(X),u=a.saved(X,i()),d=l?.reference.value===c?vo(l,u):Object.keys(u);n.refreshClean(X),(o.phase===`done`||o.phase===`error`)&&a.clearResult(X);try{let{not_saved:e=[],...t}=await r.post(`editor/confirm`,{reference:c,delivered:d}),n=a.containers[X];n?.reference===c&&(n.status=t,n.notSaved=e,s(X,t)),e.length&&Statamic.$toast.error(au(e,t),{duration:1e4})}catch(e){e?.status!==403&&Statamic.$toast.error(__(`The translation status could not be updated: :message`,{message:e?.message??``}))}}function m(e,t,n){try{h(n)}catch(e){console.error(e)}g(n).catch(e=>console.error(e)),e()}function h(e){let r=t(),s=r.containers[X];if(!s?.reference||su(e,s)!==s.reference)return;let c=s.phase,l=nc.includes(c)&&!!a(`base`),u=Object.keys(s.delivered),d=n.context(X);o(X),d&&u.length&&Co(d,s.snapshot,u),r.saved(X,i()),(u.length||![`idle`,`offer`].includes(c))&&r.clearResult(X),(u.length||l)&&Statamic.$toast.info(__(`Publishing discarded the unsaved translation. Translate again to fill in the form.`))}async function g(e){let n=t().containers[X],i=su(e,n);if(n?.reference&&i===n.reference)try{let e=await r.get(`editor/status`,{reference:i}),n=t().containers[X];n?.reference===i&&(n.status=e,s(X,e,{published:!0}))}catch(e){e?.status!==403&&Statamic.$toast.error(__(`The translation status could not be updated: :message`,{message:e?.message??``}))}}return{listen:u,saving:d,saved:f,published:m}}function su(e,t){let n=e?.response?.data?.data;return typeof n?.reference==`string`?n.reference:typeof n?.id==`string`&&t?.reference?.startsWith(`term::${n.id}::`)?t.reference:e?.reference??null}var cu=`[data-tolk-offer], [data-tolk-options], [data-tolk-changes], [data-tolk-push-modal]`,lu=`[data-tolk-action]:not([disabled])`,uu=`[data-tolk-focus]`,du=`button:not([disabled]), [href], [tabindex="0"]`;function fu(e,{modals:t=null,doc:n=globalThis.document,wait:r=setTimeout,delays:i=[0,400]}={}){let a=null;function o(){let r=n?.activeElement,i=e();return!!(r&&i&&(i.contains(r)||t&&r.closest?.(t)))}function s(){return!n.activeElement||n.activeElement===n.body||n.activeElement===a}function c(){let t=e();if(!t?.isConnected||!s())return;let n=t.querySelector(lu),r=n??t.querySelector(uu)??t.querySelector(du);r?.focus(),a=n?null:r}return{holds:o,restore:c,changing(){o()&&i.forEach(e=>r(c,e))}}}var pu={class:`sr-only`,"aria-live":`polite`,"data-tolk-announcement":``},mu={key:0,class:`flex items-center gap-2`},hu={key:0,class:`space-y-2`,"data-tolk-localization":``},gu={class:`flex flex-wrap items-center justify-between gap-x-6 gap-y-3`},_u={class:`flex flex-wrap items-center gap-2`},vu={key:0,class:`flex flex-wrap items-center gap-2`,"data-tolk-actions":``},yu={key:2,class:`flex flex-wrap items-center gap-2`,"data-tolk-copies":``},bu=[`href`],xu={key:1,class:`flex items-center gap-2`,tabindex:`-1`,"data-tolk-focus":``,"data-tolk-phase":`planning`},Su={key:2,class:`space-y-2`,"data-tolk-phase":`working`},Cu={class:`flex flex-wrap items-center justify-between gap-2`},wu={key:3,class:`space-y-1`,"data-tolk-phase":`error`},Tu={class:`flex items-center gap-2`},Eu={key:4,class:`space-y-1`,"data-tolk-summary":``},Du={key:1,class:`flex flex-wrap items-center gap-2`},Ou={key:5,class:`flex flex-wrap gap-2`},ku={key:6,class:`flex items-center gap-2`,"data-tolk-not-saved":``},Au={key:7,class:`space-y-2`,"data-tolk-origin":``},ju={class:`flex items-center gap-2`},Mu={class:`grid grid-cols-[auto_auto_minmax(0,1fr)] items-center gap-x-3 gap-y-1.5 ps-6`},Nu=[`data-tolk-site`],Pu=[`href`],Fu=[`href`],Iu={__name:`EditorBanner`,props:{containerName:{type:String,required:!0}},setup(e){let t=e,n=ti(),r=Hs(),i=t.containerName,{failure:a,stop:o}=Ac({name:i,ctx:n,store:r});lt(o);let s=O(()=>r.containers[i]??null),c=O(()=>s.value?.phase??`idle`),l=Kl(Statamic.$config.get(`tolk.auditUrl`)),u=O(()=>ua(s.value?.status??null)),d=O(()=>mc(s.value)),f=O(()=>fc(s.value)),p=O(()=>rc.includes(s.value?.error?.code)),h=O(()=>Sa(s.value?.summary??null,s.value?.status??null,{retry:f.value&&!p.value})),g=O(()=>s.value?.notSaved?.length?au(s.value.notSaved,s.value.status):null),_=O(()=>Ec(c.value,u.value)),v=O(()=>uc(s.value)),y=O(()=>{let e=s.value?.request;return e?.kind===`translate`&&e.fields?.length===1?xa(e.fields,s.value.status):null}),b=O(()=>{let e=u.value.localization?.target?.name??``;return s.value?.progress?.cancelling?__(`Cancelling. Fields already on their way are still filled in.`):s.value?.request?.kind===`review`?__(`Reviewing the translation…`):y.value?__(`Translating :field into :site…`,{field:y.value,site:e}):__(`Translating into :site…`,{site:e})}),x=O(()=>{switch(c.value){case`planning`:return __(`Preparing the translation…`);case`working`:return b.value;case`error`:return s.value?.error?.message??``;case`done`:return[h.value?.translated,h.value?.reviewed].filter(Boolean).join(` `);default:return``}}),S=jc();bn(()=>s.value?.summary,()=>S.hide());let C=O(()=>!!u.value.origin?.upToDate&&!u.value.localization&&!s.value?.push),w=O(()=>!n.readOnly.value&&(a.value!==null||u.value.visible&&!C.value)),ee=O(()=>Ha.dirtyHandles(i).length>0),T=Statamic.$config.get(`tolk.settingsUrl`),E=O(()=>Tc(s.value?.reference)),te=I(null),D=fu(()=>te.value?.$el??null,{modals:cu});bn([c,()=>s.value?.push?.phase],()=>D.changing()),bn(w,e=>{!e&&D.holds()&&nt(()=>document.getElementById(`content-card`)?.focus())});function ne(e){$.translate(i,{mode:e})}function re(){$.translate(i,{mode:`all`,fields:u.value.localization.copies.map(e=>e.handle),overwriteManual:!0})}async function ie(){let e=D.holds(),t=await $.undo(i);e&&(await nt(),D.restore()),t?.kept.length&&Statamic.$toast.info(hc(t.kept,s.value?.status))}return(e,t)=>{let n=Nt(`tooltip`);return w.value?(F(),k(z(H),{key:0,ref_key:`card`,ref:te,class:`mb-6 space-y-3`,"data-tolk-banner":``},{default:B(()=>[M(`p`,pu,R(x.value),1),z(a)?(F(),j(`div`,mu,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-red-600`,"aria-hidden":`true`}),P(z(q),{variant:`danger`},{default:B(()=>[N(R(e.__(`The translation status could not be loaded: :message`,{message:z(a).message})),1)]),_:1})])):(F(),j(m,{key:1},[u.value.localization?(F(),j(`div`,hu,[M(`div`,gu,[M(`div`,_u,[P(z(Sr),{name:`dictionary-language-book`,class:`size-4 shrink-0 text-gray-500`,"aria-hidden":`true`}),P(z(q),null,{default:B(()=>[N(R(u.value.localization.lead),1)]),_:1}),(F(!0),j(m,null,L(u.value.localization.parts,e=>En((F(),k(z(Pn),{key:e.key,text:e.text,color:z(oa)(e.key),tabindex:`0`,"data-tolk-part":e.key},null,8,[`text`,`color`,`data-tolk-part`])),[[n,e.description]])),128))]),_.value?(F(),j(`div`,vu,[c.value===`idle`?(F(),j(m,{key:0},[u.value.localization.translate?(F(),k(z(V),{key:0,variant:`primary`,size:`sm`,"data-tolk-action":`translate`,onClick:t[0]||=e=>ne(`missing`)},{default:B(()=>[N(R(e.__(`Translate`)),1)]),_:1})):A(``,!0),u.value.localization.update?(F(),k(z(V),{key:1,size:`sm`,"data-tolk-action":`update`,onClick:t[1]||=e=>ne(`update`)},{default:B(()=>[N(R(e.__(`Update`)),1)]),_:1})):A(``,!0)],64)):A(``,!0),v.value?(F(),k(z(V),{key:1,size:`sm`,"data-tolk-action":`review`,onClick:t[2]||=e=>z($).review(z(i))},{default:B(()=>[N(R(e.__(`Review`)),1)]),_:1})):A(``,!0),P(Hl,{"container-name":z(i),status:s.value.status},null,8,[`container-name`,`status`])])):A(``,!0)]),u.value.localization.autoUpdated?(F(),k(z(U),{key:0,"data-tolk-auto-updated":``},{default:B(()=>[N(R(u.value.localization.autoUpdated),1)]),_:1})):A(``,!0),u.value.localization.incompleteNote?(F(),k(z(U),{key:1},{default:B(()=>[N(R(u.value.localization.incompleteNote),1)]),_:1})):A(``,!0),u.value.localization.copiesNote?(F(),j(`div`,yu,[P(z(U),null,{default:B(()=>[N(R(u.value.localization.copiesNote),1)]),_:1}),_.value&&c.value===`idle`&&u.value.localization.translateCopies?(F(),k(z(V),{key:0,size:`sm`,"data-tolk-action":`translate-copies`,onClick:re},{default:B(()=>[N(R(u.value.localization.translateCopiesLabel),1)]),_:1})):A(``,!0)])):A(``,!0),u.value.localization.hint?(F(),k(z(U),{key:3,"data-tolk-not-localizable":``},{default:B(()=>[N(R(u.value.localization.hint)+` `,1),z(l)?(F(),j(`a`,{key:0,href:z(l),"data-tolk-audit-link":``},R(e.__(`Open the setup audit`)),9,bu)):(F(),j(m,{key:1},[N(R(e.__(`Run php please tolk:doctor for details.`)),1)],64))]),_:1})):A(``,!0)])):A(``,!0),c.value===`planning`?(F(),j(`div`,xu,[P(z(q),null,{default:B(()=>[N(R(e.__(`Preparing the translation…`)),1)]),_:1})])):A(``,!0),c.value===`working`?(F(),j(`div`,Su,[M(`div`,Cu,[P(z(q),{"data-tolk-working-field":y.value?``:null},{default:B(()=>[N(R(b.value),1)]),_:1},8,[`data-tolk-working-field`]),P(z(V),{size:`sm`,variant:`ghost`,disabled:s.value.progress.cancelling,"data-tolk-action":`cancel`,onClick:t[3]||=e=>z($).cancel(z(i))},{default:B(()=>[N(R(e.__(`Cancel`)),1)]),_:1},8,[`disabled`])]),P(Ba,{value:s.value.progress.done,max:s.value.progress.total,label:s.value.request?.kind===`review`?e.__(`Review progress`):e.__(`Translation progress`)},null,8,[`value`,`max`,`label`]),s.value.progress.waiting?(F(),k(z(U),{key:0},{default:B(()=>[N(R(e.__(`The provider asked to wait. Trying again shortly.`)),1)]),_:1})):A(``,!0)])):A(``,!0),c.value===`error`?(F(),j(`div`,wu,[M(`div`,Tu,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-red-600`,"aria-hidden":`true`}),P(z(q),{variant:`danger`,"data-tolk-error":``},{default:B(()=>[N(R(s.value.error?.message),1)]),_:1})])])):A(``,!0),h.value&&(c.value===`done`||c.value===`error`)?(F(),j(`div`,Eu,[h.value.translated?(F(),k(z(q),{key:0,as:`p`,"data-tolk-summary-translated":``},{default:B(()=>[N(R(h.value.translated),1)]),_:1})):A(``,!0),h.value.reviewed?(F(),j(`div`,Du,[P(z(q),{"data-tolk-summary-reviewed":``},{default:B(()=>[N(R(h.value.reviewed),1)]),_:1}),h.value.corrections?(F(),k(z(V),{key:0,size:`sm`,variant:`ghost`,"data-tolk-action":`view-changes`,onClick:t[4]||=e=>z(S).show()},{default:B(()=>[N(R(e.__(`View changes`)),1)]),_:1})):A(``,!0)])):A(``,!0),h.value.reviewSkipped?(F(),k(z(U),{key:2,"data-tolk-summary-review-skipped":``},{default:B(()=>[N(R(h.value.reviewSkipped),1)]),_:1})):A(``,!0),h.value.cancelled?(F(),k(z(U),{key:3},{default:B(()=>[N(R(h.value.cancelled),1)]),_:1})):A(``,!0),h.value.incomplete?(F(),k(z(U),{key:4,"data-tolk-summary-incomplete":``},{default:B(()=>[N(R(h.value.incomplete),1)]),_:1})):A(``,!0),h.value.edited?(F(),k(z(U),{key:5,"data-tolk-summary-edited":``},{default:B(()=>[N(R(h.value.edited),1)]),_:1})):A(``,!0),h.value.hidden?(F(),k(z(U),{key:6,"data-tolk-summary-hidden":``},{default:B(()=>[N(R(h.value.hidden),1)]),_:1})):A(``,!0),h.value.manual?(F(),k(z(U),{key:7,"data-tolk-summary-manual":``},{default:B(()=>[N(R(h.value.manual),1)]),_:1})):A(``,!0),h.value.failed?(F(),k(z(U),{key:8,"data-tolk-summary-failed":``},{default:B(()=>[N(R(h.value.failed),1)]),_:1})):A(``,!0),h.value.unsaved?(F(),k(z(U),{key:9,"data-tolk-summary-unsaved":``},{default:B(()=>[N(R(h.value.unsaved),1)]),_:1})):A(``,!0)])):A(``,!0),f.value||c.value===`done`&&d.value?(F(),j(`div`,Ou,[f.value?(F(),k(z(V),{key:0,size:`sm`,variant:`primary`,"data-tolk-action":`retry`,onClick:t[5]||=e=>z($).retry(z(i))},{default:B(()=>[N(R(p.value?e.__(`Start again`):e.__(`Retry`)),1)]),_:1})):A(``,!0),d.value?(F(),k(z(V),{key:1,size:`sm`,"data-tolk-action":`undo`,onClick:ie},{default:B(()=>[N(R(e.__(`Undo`)),1)]),_:1})):A(``,!0)])):A(``,!0),g.value?(F(),j(`div`,ku,[P(z(Sr),{name:`warning-diamond`,class:`size-4 shrink-0 text-amber-600`,"aria-hidden":`true`}),P(z(q),null,{default:B(()=>[N(R(g.value),1)]),_:1})])):A(``,!0),u.value.origin?(F(),j(`div`,Au,[M(`div`,ju,[P(z(Sr),{name:`dictionary-language-book`,class:`size-4 shrink-0 text-gray-500`,"aria-hidden":`true`}),P(z(q),null,{default:B(()=>[N(R(E.value?e.__(`Translations of this term:`):e.__(`Translations of this entry:`)),1)]),_:1})]),M(`ul`,Mu,[(F(!0),j(m,null,L(u.value.origin.localizations,e=>(F(),j(`li`,{key:e.site,class:`col-span-3 grid grid-cols-subgrid items-center`,"data-tolk-site":e.site},[e.editUrl?(F(),j(`a`,{key:0,href:e.editUrl,class:`text-sm font-medium underline`},R(e.name),9,Pu)):(F(),k(z(q),{key:1,variant:`strong`},{default:B(()=>[N(R(e.name),1)]),_:2},1024)),P(z(Pn),{text:e.label,color:e.color,class:`justify-self-start`},null,8,[`text`,`color`]),e.exists&&e.summary?(F(),k(z(U),{key:2},{default:B(()=>[N(R(e.summary),1)]),_:2},1024)):A(``,!0)],8,Nu))),128))]),u.value.origin.autoUpdate?(F(),k(z(U),{key:0,class:`ps-6`,"data-tolk-auto-update":``},{default:B(()=>[N(R(u.value.origin.autoUpdate),1)]),_:1})):A(``,!0),P(Zc,{"container-name":z(i),reference:s.value.reference,origin:u.value.origin,status:s.value.status,dirty:ee.value},null,8,[`container-name`,`reference`,`origin`,`status`,`dirty`])])):A(``,!0),u.value.localization?(F(),k(ll,{key:8,"container-name":z(i),status:s.value.status,open:c.value===`offer`},null,8,[`container-name`,`status`,`open`])):A(``,!0),z(S).open?(F(),k(Ra,{key:9,modal:z(S),corrections:s.value.summary?.corrections??[],reviewer:s.value.summary?.reviewer??null},null,8,[`modal`,`corrections`,`reviewer`])):A(``,!0),u.value.setup?(F(),k(z(U),{key:10,"data-tolk-setup":``},{default:B(()=>[N(R(e.__(`Translation is not set up yet.`))+` `,1),z(T)?(F(),j(`a`,{key:0,href:z(T)},R(e.__(`Open the Tolk settings`)),9,Fu)):(F(),j(m,{key:1},[N(R(e.__(`Ask an administrator to configure a provider in the Tolk settings.`)),1)],64))]),_:1})):A(``,!0)],64))]),_:1},512)):A(``,!0)}}},Lu={class:`flex items-center justify-end gap-3 pt-3 pb-1`},Ru={__name:`TranslateFieldConfirm`,emits:[`confirm`,`cancel`],setup(e,{emit:t}){let n=t,r=jc(),i=!1;pt(()=>r.show());function a(e){i||(i=!0,n(e))}function o(e){r.hide(),a(e)}function s(e){r.closed(e),e||a(`cancel`)}return(e,t)=>z(r).open?(F(),k(z(Wr),{key:0,open:``,title:e.__(`Translate from origin`),"data-tolk-field-confirm":``,onDismissed:t[2]||=e=>z(r).dismissed(),"onUpdate:open":s},{footer:B(()=>[M(`div`,Lu,[P(z(V),{variant:`ghost`,text:e.__(`Cancel`),"data-tolk-field-confirm-action":`cancel`,onClick:t[0]||=e=>o(`cancel`)},null,8,[`text`]),P(z(V),{variant:`primary`,text:e.__(`Translate`),"data-tolk-field-confirm-action":`translate`,onClick:t[1]||=e=>o(`confirm`)},null,8,[`text`])])]),default:B(()=>[P(z(q),{as:`p`},{default:B(()=>[N(R(e.__(`The current content of this field will be replaced.`)),1)]),_:1})]),_:1},8,[`title`])):A(``,!0)}},zu=`tolk-translate-field-confirm`;function Bu(e,t){if(e===t)return!0;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>Bu(e,t[n]));if(e===null||t===null||typeof e!=`object`||typeof t!=`object`)return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.hasOwn(t,n)&&Bu(e[n],t[n]))}function Vu({registry:e=Ha,store:t=Hs,translations:n=$,fieldActions:r=()=>Statamic.$fieldActions,config:i=()=>Statamic.$config,permissions:a=()=>Statamic.$permissions,toast:o=()=>Statamic.$toast,components:s=()=>Statamic.$components,doc:c=()=>globalThis.document,wait:l=setTimeout}={}){let u=!1;function d({vm:n,fieldPathPrefix:r,handle:i,config:o,isReadOnly:s}){if(r||s||!o?.localizable||!a().has(`translate content`)||n&&n.publishContainer?.name!==`base`||e.others().length>0)return!1;let c=e.base(),l=t().containers[X],u=l?.status;if(!c||c.readOnly?.value||!u?.localization||l.reference!==c.reference.value)return!1;let d=Y(u.localization.fields)[i];return!la(u)&&Object.hasOwn(c.originValues?.value??{},i)&&!!d&&d.status!==`not_applicable`}function f(){return nc.includes(t().containers[X]?.phase)}function p({handle:t,value:n}){let r=e.base()?.originValues?.value??{};return Ja(n)!==null&&!no(n,r[t])}async function m({handle:r,value:i}){let a=e.base(),s=t();if(!a||!Bu(i,a.values.value[r])){o().error(Tc(s.containers.base?.reference)?__(`This field is not part of the term being translated.`):__(`This field is not part of the entry being translated.`));return}if(nc.includes(s.phaseOf(`base`))||n.running(`base`)){o().error(__(`A translation is already running. Try again when it has finished.`));return}if(n.saving(`base`)){o().error(oc());return}let c=s.containers[X],l=await n.translate(X,{mode:`all`,fields:[r],overwriteManual:!0,replace:!0});if(s.containers.base===c){if(c.phase===`error`){o().error(c.error?.message||__(`Something went wrong.`));return}if(l&&!l.cancelled&&!l.delivered.includes(r)){let e=Sa(l,c.status);o().error(e.failed??e.edited??e.hidden??e.translated)}}}function h(e){return[...([...c()?.querySelectorAll(`label[for]`)??[]].find(t=>t.getAttribute(`for`)===`field_${e}`)?.closest(`[data-ui-input-group]`)?.querySelector(`[data-ui-field-header]`))?.querySelectorAll(`button[aria-label]`)??[]].find(e=>e.getAttribute(`aria-label`)===b())??null}function g(){let e=c()?.querySelector(`[data-tolk-banner]`);return e?.querySelector(`[data-tolk-action="cancel"]`)??e?.querySelector(`[data-tolk-focus]`)??null}function _(e){for(let t of[0,400])l(()=>{let t=c()?.activeElement;(!t||t===c().body)&&e()?.focus()},t)}function v(e){m(e).catch(()=>o().error(__(`Something went wrong.`))),_(()=>g()??h(e.handle))}function y(e){if(!p(e)){v(e);return}let t=s().append(zu,{props:{}});t.on(`confirm`,()=>{t.destroy(),v(e)}),t.on(`cancel`,()=>{t.destroy(),_(()=>h(e.handle))})}function b(){return __(`Translate from origin`)}let x={get title(){return b()},quick:!0,icon:`dictionary-language-book`,visible:d,disabled:f,run:y};function S(){if(!u){u=!0;for(let e of i().get(`tolk.fieldtypes`)??[])r().add(`${e}-fieldtype`,x)}}return{register:S,action:x,visible:d,disabled:f,run:y}}var Hu=Vu(),{Fieldtype:Uu,IndexFieldtype:Wu,FieldtypeMixin:Gu,HasActionsMixin:Ku,HasInputOptionsMixin:qu,HasPreferencesMixin:Ju,IndexFieldtypeMixin:Yu,InlineEditForm:Xu,DateFormatter:Zu,NumberFormatter:Qu,ItemActions:$u,RelatedItem:ed,RestoreRevision:td,RevisionHistory:nd,RevisionPreview:rd,SaveButtonOptions:id,SortableList:ad,requireElevatedSession:od,requireElevatedSessionIf:sd,clone:cd,debounce:ld,deepClone:ud,resetValuesFromResponse:dd}=__STATAMIC__.core,fd=[`data-tolk-model-note`],pd={__name:`ModelSelect`,props:Uu.props,emits:Uu.emits,setup(e,{expose:t,emit:n}){let r=n,i=e,{expose:a,isReadOnly:o,update:s}=Uu.use(r,i),c=O(()=>hl(i.meta,i.value)),l=O(()=>dl(i.value)??`automatic`);function u(e){let t=gl(e,c.value);t!==void 0&&t!==dl(i.value)&&s(t)}return t(a),(e,t)=>(F(),k(z(Wn),{id:e.id,"model-value":l.value,options:c.value,"read-only":z(o),placeholder:e.__(`Choose a model`),taggable:``,"data-tolk-model-select":``,"onUpdate:modelValue":u},{option:B(e=>[M(`span`,{class:it([`truncate`,{"opacity-50":e.disabled}])},R(e.label),3),e.note?(F(),j(`span`,{key:0,class:it([`ms-auto shrink-0 text-xs text-gray-500 dark:text-gray-400`,{"opacity-50":e.disabled}]),"data-tolk-model-note":e.value},R(e.note),11,fd)):A(``,!0)]),_:1},8,[`id`,`model-value`,`options`,`read-only`,`placeholder`]))}};function md(e){let t=e?.fake_engine===!0;return(Array.isArray(e?.providers)?e.providers:[]).map(e=>{let n=e.configured===!0;return{provider:e.provider,label:e.label,badge:hd(n),source:gd(e.source),hint:n?null:_d(e.env),testable:n||t}})}function hd(e){return e?{text:__(`Configured`),color:`green`}:{text:__(`No API key`),color:`default`}}function gd(e){return{ai:__(`The key comes from config/ai.php, which Tolk shares with the rest of the site.`),addon:__(`The key is Tolk's own, from the addon's config.`)}[e]??null}function _d(e){return e?.ai?__(`Add :variable to the .env file, or :override to give Tolk a key of its own.`,{variable:e.ai,override:e.addon}):null}function vd(e){if(e?.ok!==!0)return{ok:!1,text:e?.error||__(`The test failed.`)};let t={model:e.label||e.model,ms:e.latency_ms};return{ok:!0,text:e.fake?__(`The fake engine answered for :model in :ms ms, without calling the provider.`,t):__(`:model answered in :ms ms.`,t)}}async function yd(e,t=J){try{return await t.post(`providers/test`,{provider:e})}catch(e){return{ok:!1,error:e.message}}}var bd={class:`divide-y divide-gray-200 dark:divide-gray-700`,"data-tolk-providers":``},xd=[`data-tolk-provider`],Sd={class:`flex flex-wrap items-center gap-2`},Cd={__name:`ProvidersStatus`,props:Uu.props,emits:Uu.emits,setup(e,{expose:t,emit:n}){let r=n,i=e,{expose:a}=Uu.use(r,i),o=O(()=>md(i.meta)),s=Dt({}),c=Dt({});async function l(e){s[e]=!0,c[e]=null;try{c[e]=vd(await yd(e))}finally{s[e]=!1}}return t(a),(e,t)=>(F(),j(`div`,bd,[(F(!0),j(m,null,L(o.value,t=>(F(),j(`div`,{key:t.provider,class:`space-y-1 py-3 first:pt-0 last:pb-0`,"data-tolk-provider":t.provider},[M(`div`,Sd,[P(z(q),{variant:`strong`},{default:B(()=>[N(R(t.label),1)]),_:2},1024),P(z(Pn),{text:t.badge.text,color:t.badge.color,"data-tolk-provider-status":``},null,8,[`text`,`color`]),t.testable?(F(),k(z(V),{key:0,class:`ms-auto`,size:`sm`,text:e.__(`Test connection`),loading:!!s[t.provider],disabled:!!s[t.provider],"data-tolk-provider-test":``,onClick:e=>l(t.provider)},null,8,[`text`,`loading`,`disabled`,`onClick`])):A(``,!0)]),t.source?(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.source),1)]),_:2},1024)):A(``,!0),t.hint?(F(),k(z(U),{key:1},{default:B(()=>[N(R(t.hint),1)]),_:2},1024)):A(``,!0),c[t.provider]?(F(),k(z(q),{key:2,variant:c[t.provider].ok?`success`:`danger`,"data-tolk-provider-result":c[t.provider].ok?`ok`:`failed`},{default:B(()=>[N(R(c[t.provider].text),1)]),_:2},1032,[`variant`,`data-tolk-provider-result`])):A(``,!0)],8,xd))),128))]))}},{asMap:wd}=J,Td=`glossary`;function Ed(e,t=J){let n=wd(e),r=Object.hasOwn(n,`translator_model`)?{model:n.translator_model||null}:{};return t.post(`site-profile/generate`,r)}function Dd(e){return typeof e==`string`&&e.trim()!==``}function Od(e){return String(e??``).normalize(`NFKD`).toLowerCase().replace(/\p{Mn}+/gu,``).replace(/[\s\p{Z}]+/gu,` `).trim()}function kd(e){let t=e?.site;return Array.isArray(t)?t.length===0:!t}function Ad(e){return new Set((Array.isArray(e)?e:[]).filter(kd).map(e=>Od(e?.term)).filter(e=>e!==``))}function jd(e,t,n={}){let r=Ad(t);return(Array.isArray(e)?e:[]).map(e=>{let t=r.has(Od(e));return{term:e,inGlossary:t,chosen:!t&&n[e]!==!0}})}function Md(){return Array.from(crypto.getRandomValues(new Uint8Array(12)),e=>`abcdefghijklmnopqrstuvwxyz0123456789`[e%36]).join(``)}function Nd(e){return JSON.parse(JSON.stringify(e??{}))}function Pd(e,t,n,r=Md){let i=Array.isArray(t)?t:[],a=wd(n),o=Ad(i),s={...wd(a.existing)},c=[];for(let t of e){let e=Od(t);if(e===``||o.has(e))continue;let n=r();o.add(e),s[n]=Nd(wd(a.new)),c.push({...Nd(wd(a.defaults)),term:t.trim(),do_not_translate:!0,_id:n})}return{rows:[...i,...c],meta:{...a,existing:s},added:c.map(e=>e.term)}}var Fd={class:`space-y-3`,"data-tolk-site-profile":``},Id={key:0,class:`flex flex-wrap items-center gap-3`},Ld={key:3,class:`space-y-2`,"data-tolk-site-profile-terms":``},Rd={class:`space-y-1`},zd=[`data-tolk-site-profile-term`],Bd={class:`flex flex-wrap items-center gap-3`},Vd={class:`list-disc ps-5 text-sm`},Hd=[`data-tolk-site-profile-term`],Ud={__name:`SiteProfile`,props:Uu.props,emits:Uu.emits,setup(e,{expose:t,emit:n}){let r=n,i=e,{expose:a,isReadOnly:o,update:s}=Uu.use(r,i),c=ti(),l=I(!1),u=I(!1),d=I(null),f=I(null),p=I(null),h=Dt({}),g=O(()=>Y(c?.values.value)),_=O(()=>!o.value&&Object.hasOwn(g.value,`glossary`)&&Object.hasOwn(Y(c?.meta.value),`glossary`)),v=O(()=>jd(f.value?.terms,g.value[Td],h)),y=O(()=>v.value.filter(e=>e.chosen).map(e=>e.term));function b(){Dd(i.value)?u.value=!0:x()}async function x(){u.value=!1,l.value=!0,d.value=null;try{let e=await Ed(g.value);s(e.profile),f.value={label:e.label||e.model,terms:Array.isArray(e.terms)?e.terms:[]},p.value=null,Object.keys(h).forEach(e=>delete h[e])}catch(e){d.value=e.message}finally{l.value=!1}}function S(e,t){h[e]=!t}function C(){let e=Pd(y.value,g.value[Td],c.meta.value[Td]);c.setFieldMeta(Td,e.meta),c.setFieldValue(Td,e.rows),p.value=e.added.length}return t(a),(e,t)=>(F(),j(`div`,Fd,[P(z(Fi),{id:e.id,name:e.handle,"model-value":e.value,"read-only":z(o),rows:8,"onUpdate:modelValue":z(s)},null,8,[`id`,`name`,`model-value`,`read-only`,`onUpdate:modelValue`]),z(o)?A(``,!0):(F(),j(`div`,Id,[P(z(V),{size:`sm`,icon:`ai-sparks`,text:e.__(`Generate`),loading:l.value,disabled:l.value,"data-tolk-site-profile-generate":``,onClick:b},null,8,[`text`,`loading`,`disabled`]),P(z(U),null,{default:B(()=>[N(R(e.__(`Has the translator write a profile from the content of the default site. Check it before you save.`)),1)]),_:1})])),d.value?(F(),k(z(q),{key:1,variant:`danger`,"data-tolk-site-profile-error":``},{default:B(()=>[N(R(d.value),1)]),_:1})):A(``,!0),f.value?(F(),k(z(U),{key:2,"data-tolk-site-profile-written":``},{default:B(()=>[N(R(e.__(`Written by :model. It is not saved until you save the settings.`,{model:f.value.label})),1)]),_:1})):A(``,!0),v.value.length?(F(),j(`div`,Ld,[P(z(q),{variant:`strong`},{default:B(()=>[N(R(e.__(`Names to keep untranslated`)),1)]),_:1}),_.value?(F(),j(m,{key:0},[M(`div`,Rd,[(F(!0),j(m,null,L(v.value,t=>(F(),j(`div`,{key:t.term,"data-tolk-site-profile-term":t.term},[P(z(Vn),{"model-value":t.chosen,label:t.term,description:t.inGlossary?e.__(`Already in the glossary`):null,disabled:t.inGlossary,"onUpdate:modelValue":e=>S(t.term,e)},null,8,[`model-value`,`label`,`description`,`disabled`,`onUpdate:modelValue`])],8,zd))),128))]),M(`div`,Bd,[P(z(V),{size:`sm`,text:e.__(`Add to glossary`),disabled:y.value.length===0,"data-tolk-site-profile-add":``,onClick:C},null,8,[`text`,`disabled`]),p.value===null?A(``,!0):(F(),k(z(U),{key:0,"data-tolk-site-profile-added":``},{default:B(()=>[N(R(e.__n(`Added :count name to the glossary with Do not translate on. Save the settings to keep it.|Added :count names to the glossary with Do not translate on. Save the settings to keep them.`,p.value)),1)]),_:1}))])],64)):(F(),j(m,{key:1},[M(`ul`,Vd,[(F(!0),j(m,null,L(v.value,e=>(F(),j(`li`,{key:e.term,"data-tolk-site-profile-term":e.term},R(e.term),9,Hd))),128))]),P(z(U),null,{default:B(()=>[N(R(e.__(`Add them to the glossary with Do not translate on, so that every translation keeps them.`)),1)]),_:1})],64))])):A(``,!0),u.value?(F(),k(z(Kn),{key:4,open:``,"onUpdate:open":t[0]||=e=>u.value=e,title:e.__(`Replace the site profile?`),"body-text":e.__(`A new profile replaces the text in this field. Nothing is saved until you save the settings.`),"button-text":e.__(`Generate`),onConfirm:x},null,8,[`title`,`body-text`,`button-text`])):A(``,!0)]))}},{Form:Wd,Head:Gd,Link:Kd,router:qd,toggleArchitecturalBackground:Jd,useArchitecturalBackground:Yd,useForm:Xd,usePage:Zd,usePoll:Qd}=__STATAMIC__.inertia,$d={class:`mx-auto max-w-page space-y-6`,"data-tolk-audit":``},ef={class:`flex flex-wrap items-center gap-2`},tf={key:1,class:`space-y-3`},nf=[`data-tolk-item-level`],rf=[`data-tolk-blueprint`],af={class:`flex flex-wrap items-center justify-between gap-2`},of={class:`flex items-center gap-2`},sf=[`href`],cf={class:`space-y-2`},lf=[`data-tolk-field`],uf=[`data-tolk-field-imported`],df=[`href`],ff={key:1,class:`space-y-1 ps-6`},pf=[`data-tolk-field`],mf={class:`text-xs text-gray-600 dark:text-gray-400`},hf={key:1,class:`flex items-start gap-2`},gf={__name:`Audit`,props:{checks:{type:Array,default:()=>[]},canMakeLocalizable:{type:Boolean,default:!1},urls:{type:Object,required:!0}},setup(e){let t=e,n=I(t.checks),r=Dt({}),i=I(null),a=I(null),o=O(()=>Yl(n.value));bn(()=>t.checks,e=>n.value=e);function s(e,t){return(r[Ql(e)]??[]).includes(t)}function c(e,t,n){let i=Ql(e),a=(r[i]??[]).filter(e=>e!==t);r[i]=n?[...a,t]:a}function l(e){let t=nu(e,r[Ql(e)]);t.length>0&&(i.value={item:e,fields:t,text:ru(e,t)})}async function u(){let{item:e,fields:o}=i.value,s=Ql(e);i.value=null,a.value=s;try{let i=await $i(t.urls.localizable,{namespace:e.namespace,blueprint:e.blueprint,fields:o});n.value=i.checks,delete r[s],Statamic.$toast.success(iu(i.changed))}catch(e){Statamic.$toast.error(e.message)}finally{a.value=null}}return(t,d)=>(F(),j(`div`,$d,[P(z(Gd),{title:t.__(`Audit`)},null,8,[`title`]),P(z(br),{title:t.__(`Setup audit`),icon:`clipboard-check`},{default:B(()=>[P(z(Kd),{href:e.urls.overview,class:`text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200`},{default:B(()=>[N(R(t.__(`Overview`)),1)]),_:1},8,[`href`]),P(z(V),{text:t.__(`Check again`),icon:`sync`,"data-tolk-audit-reload":``,onClick:d[0]||=e=>z(qd).reload()},null,8,[`text`])]),_:1},8,[`title`]),P(z(H),{class:`flex items-start gap-3`,"data-tolk-audit-summary":``,"data-tolk-audit-level":o.value.level},{default:B(()=>[P(z(Sr),{name:z(Jl)(o.value.level).icon,class:it([`mt-0.5 size-5 shrink-0`,z(Jl)(o.value.level).class]),"aria-hidden":`true`},null,8,[`name`,`class`]),P(z(q),null,{default:B(()=>[N(R(o.value.text),1)]),_:1})]),_:1},8,[`data-tolk-audit-level`]),(F(!0),j(m,null,L(n.value,n=>(F(),k(z(H),{id:z(Gl)(n.id),key:n.id,class:`space-y-3`,"data-tolk-check":n.id,"data-tolk-check-level":n.level},{default:B(()=>[M(`div`,ef,[P(z(Sr),{name:z(Jl)(n.level).icon,class:it([`size-4 shrink-0`,z(Jl)(n.level).class]),"aria-hidden":`true`},null,8,[`name`,`class`]),P(z(W),{size:`lg`,level:2},{default:B(()=>[N(R(n.title),1)]),_:2},1024),P(z(Pn),{text:z(Jl)(n.level).label,color:z(Jl)(n.level).color},null,8,[`text`,`color`])]),P(z(U),null,{default:B(()=>[N(R(z(Xl)(n,e.canMakeLocalizable)),1)]),_:2},1024),n.items.length===0?(F(),k(z(q),{key:0,"data-tolk-audit-nothing":``},{default:B(()=>[N(R(n.id===z(`localizable`)?t.__(`Every text field Tolk could translate is localizable.`):t.__(`Nothing to report.`)),1)]),_:2},1024)):(F(),j(`ul`,tf,[(F(!0),j(m,null,L(n.items,(i,o)=>(F(),j(`li`,{key:o,"data-tolk-item":``,"data-tolk-item-level":i.level},[z(Zl)(i)?(F(),j(`div`,{key:0,class:`space-y-2 rounded-lg border border-gray-200 p-3 dark:border-gray-700`,"data-tolk-blueprint":z(Ql)(i)},[M(`div`,af,[M(`div`,of,[P(z(Sr),{name:z(Jl)(i.level).icon,class:it([`size-4 shrink-0`,z(Jl)(i.level).class]),role:`img`,"aria-label":z(Jl)(i.level).label},null,8,[`name`,`class`,`aria-label`]),P(z(q),{class:`font-medium`},{default:B(()=>[N(R(i.name),1)]),_:2},1024)]),i.edit_url?(F(),j(`a`,{key:0,href:i.edit_url,class:`text-sm text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-blueprint-link":``},R(t.__(`Edit blueprint`)),9,sf)):A(``,!0)]),n.id===z(`localizable`)?(F(),j(m,{key:0},[M(`div`,cf,[(F(!0),j(m,null,L(z($l)(i).editable,t=>(F(),j(`div`,{key:t.handle,"data-tolk-field":t.handle},[e.canMakeLocalizable?(F(),k(z(Vn),{key:0,"model-value":s(i,t.handle),label:z(eu)(t),disabled:a.value!==null,"onUpdate:modelValue":e=>c(i,t.handle,e)},null,8,[`model-value`,`label`,`disabled`,`onUpdate:modelValue`])):(F(),k(z(q),{key:1},{default:B(()=>[N(R(z(eu)(t)),1)]),_:2},1024))],8,lf))),128)),(F(!0),j(m,null,L(z($l)(i).imported,n=>(F(),j(`div`,{key:n.handle,"data-tolk-field-imported":n.handle},[e.canMakeLocalizable?(F(),k(z(Vn),{key:0,"model-value":!1,label:z(eu)(n),description:z(tu)(n),disabled:``},null,8,[`label`,`description`])):(F(),j(m,{key:1},[P(z(q),null,{default:B(()=>[N(R(z(eu)(n)),1)]),_:2},1024),P(z(U),null,{default:B(()=>[N(R(z(tu)(n)),1)]),_:2},1024)],64)),n.fieldset_url?(F(),j(`a`,{key:2,href:n.fieldset_url,class:`ms-6 text-sm text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-fieldset-link":``},R(t.__(`Edit fieldset`)),9,df)):A(``,!0)],8,uf))),128))]),e.canMakeLocalizable&&z($l)(i).editable.length>0?(F(),k(z(V),{key:0,size:`sm`,variant:`primary`,text:t.__(`Make localizable`),loading:a.value===z(Ql)(i),disabled:a.value!==null||z(nu)(i,r[z(Ql)(i)]).length===0,"data-tolk-make-localizable":``,onClick:e=>l(i)},null,8,[`text`,`loading`,`disabled`,`onClick`])):A(``,!0)],64)):(F(),j(`ul`,ff,[(F(!0),j(m,null,L(i.fields,e=>(F(),j(`li`,{key:e.path??e.handle,"data-tolk-field":e.path??e.handle},[P(z(q),null,{default:B(()=>[N(R(e.label)+` `,1),M(`code`,mf,R(e.path??e.handle),1)]),_:2},1024)],8,pf))),128))]))],8,rf)):(F(),j(`div`,hf,[P(z(Sr),{name:z(Jl)(i.level).icon,class:it([`mt-0.5 size-4 shrink-0`,z(Jl)(i.level).class]),role:`img`,"aria-label":z(Jl)(i.level).label},null,8,[`name`,`class`,`aria-label`]),P(z(q),null,{default:B(()=>[N(R(i.text),1)]),_:2},1024)]))],8,nf))),128))]))]),_:2},1032,[`id`,`data-tolk-check`,`data-tolk-check-level`]))),128)),i.value?(F(),k(z(Kn),{key:0,open:``,title:t.__(`Make these fields localizable?`),"button-text":t.__(`Make localizable`),"data-tolk-localizable-confirm":``,"onUpdate:open":d[1]||=e=>i.value=e?i.value:null,onConfirm:u},{default:B(()=>[P(z(q),null,{default:B(()=>[N(R(i.value.text),1)]),_:1})]),_:1},8,[`title`,`button-text`])):A(``,!0)]))}},_f={class:`overflow-x-auto`},vf={__name:`RunsTable`,props:{runs:{type:Array,default:()=>[]}},setup(e){let t=e,n=vs(Statamic.$config.get(`sites`)),r=O(()=>t.runs.map(e=>{let t=xs({counts:e.counts}),r=js(e),i=Os(e.scope,n);return{id:e.id,url:e.url,status:e.status,what:i.what,automatic:i.automatic,sites:i.sites,progress:__(`:finished of :total`,{finished:Q(t.finished),total:Q(t.total)}),failed:t.counts.failed,tokens:r.input+r.output,cost:r.cost,date:bs(e.created_at),by:e.created_by?.name??(i.automatic?__(`Automatic update`):__(`Command line`))}}));return(e,t)=>(F(),j(`div`,_f,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(e.__(`Status`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Content`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Sites`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Items finished`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Usage`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(e.__(`Created`)),1)]),_:1})]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(r.value,t=>(F(),k(z(ki),{key:t.id,"data-tolk-run-row":``,"data-tolk-run-id":t.id},{default:B(()=>[P(z(G),null,{default:B(()=>[P(z(Kd),{href:t.url,class:`inline-flex`},{default:B(()=>[P(z(Pn),{text:z(ps)(t.status),color:z(ms)(t.status)},null,8,[`text`,`color`])]),_:2},1032,[`href`])]),_:2},1024),P(z(G),null,{default:B(()=>[P(z(Kd),{href:t.url,class:`text-blue-600 hover:underline dark:text-blue-400`},{default:B(()=>[N(R(t.what),1)]),_:2},1032,[`href`]),t.automatic?(F(),k(z(U),{key:0,"data-tolk-run-automatic":``},{default:B(()=>[N(R(e.__(`Automatic update`)),1)]),_:1})):A(``,!0)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(t.sites),1)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(t.progress)+` `,1),t.failed>0?(F(),k(z(U),{key:0},{default:B(()=>[N(R(e.__n(`:count failed|:count failed`,t.failed)),1)]),_:2},1024)):A(``,!0)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(e.__(`:tokens tokens`,{tokens:z(Q)(t.tokens)}))+` `,1),P(z(U),null,{default:B(()=>[N(R(t.cost===null?e.__(`Cost unknown`):z(ys)(t.cost)),1)]),_:2},1024)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(t.date)+` `,1),P(z(U),null,{default:B(()=>[N(R(t.by),1)]),_:2},1024)]),_:2},1024)]),_:2},1032,[`data-tolk-run-id`]))),128))]),_:1})]),_:1})]))}};function yf({scan:e,onChange:t=()=>{},concurrency:n=3}){let r=[],i=0,a=0,o=!1;function s(e){return e.generation===a}function c(){for(;i0;)l(r.shift())}async function l(n){i++,t(n.cell.key,{status:`loading`});try{let r=null;do{let i=await e({...n.cell,cursor:r,fresh:n.fresh});if(!s(n))return;r=i.cursor??null,t(n.cell.key,{...i,status:r===null?`done`:`loading`})}while(r!==null)}catch(e){s(n)&&t(n.cell.key,{status:`failed`,error:e?.message??String(e)})}finally{i--,c()}}function u(){a++,r=[]}function d(e,n){for(let i of e)r.push({cell:i,fresh:n,generation:a}),t(i.key,{status:`waiting`});c()}return{load(e,t={}){u(),o=t.fresh??!1,d(e,o)},retry(e){d([e],o)},stop:u,get active(){return i}}}var bf=[`entry`,`term`,`globals`,`nav`],xf=[`missing`,`untranslated`,`outdated`,`attention`,`current`],Sf={entry:`collections`,term:`taxonomies`,globals:`globals`,nav:`navs`};function Cf(e){return e===`current`?__(`Current`):sa(e)}function wf(e){return{entry:__(`Collections`),term:__(`Taxonomies`),globals:__(`Global sets`),nav:__(`Navigation`)}[e]??e}function Tf(e,t,n){return`${e}|${t}|${n}`}function Ef(e,t){let n=new Set((Array.isArray(e)?e:[]).flatMap(e=>e.sites??[]));return(Array.isArray(t)?t:[]).filter(e=>n.has(e.handle))}function Df(e){let t=Array.isArray(e)?e:[];return bf.map(e=>({type:e,label:wf(e),rows:t.filter(t=>t.type===e)})).filter(e=>e.rows.length>0)}function Of(e,t){return{key:Tf(e.type,e.handle,t),type:e.type,container:e.handle,site:t}}function kf(e){return(Array.isArray(e)?e:[]).flatMap(e=>(e.sites??[]).map(t=>Of(e,t)))}function Af(e){let t=Y(e?.counts),n=e=>Number(t[e])||0;return{counts:Object.fromEntries(xf.map(e=>[e,n(e)])),untracked:Number(e?.untracked)||0,unreadable:Number(e?.unreadable)||0,scanned:Number(e?.scanned)||0,missing:n(`missing`)+n(`untranslated`),outdated:n(`outdated`)}}function jf(e){let t=Af(e);return{...t,badges:xf.filter(e=>t.counts[e]>0).map(e=>({status:e,text:`${Cf(e)} ${t.counts[e]}`,color:oa(e)})),finished:e?.status===`done`,loading:e?.status===`waiting`||e?.status===`loading`,failed:e?.status===`failed`,error:e?.error??null}}function Mf(e,t,n,r){return{sites:[n],[Sf[e]]:[t],options:{mode:r}}}function Nf(e,t,n){let r={};for(let i of Array.isArray(e)?e:[]){if(!(i.sites??[]).includes(n))continue;let e=Y(t)[Tf(i.type,i.handle,n)];(e?.status!==`done`||Af(e).missing!==0)&&(r[Sf[i.type]]??=[]).push(i.handle)}return Object.keys(r).length>0?{sites:[n],...r,options:{mode:`missing`}}:null}function Pf({multisite:e,providers:t,fakeEngine:n}){return e?(Array.isArray(t)?t:[]).some(e=>e.configured)||n?null:`no_provider`:`single_site`}function Ff(e){let t=Y(e?.labels),n=Object.entries(Y(e?.models)).map(([e,n])=>({reference:e,model:t[e]??e,calls:Number(n?.calls)||0,input:Number(n?.input)||0,output:Number(n?.output)||0,cost:n?.cost===null||n?.cost===void 0?null:Number(n.cost),sources:Object.keys(Y(n?.sources))}));return{month:e?.month??``,rows:n,calls:n.reduce((e,t)=>e+t.calls,0),cost:n.some(e=>e.cost===null)?null:n.reduce((e,t)=>e+t.cost,0)}}function If(e){return{editor:__(`Editor`),run:__(`Runs`),cli:__(`Command line`),auto:__(`Automatic updates`)}[e]??e}function Lf(e,t=void 0){let n=/^(\d{4})-(\d{2})$/.exec(e??``);return n?new Intl.DateTimeFormat(t,{month:`long`,year:`numeric`}).format(Date.UTC(n[1],n[2]-1,15)):``}var Rf={class:`mx-auto max-w-page space-y-6`,"data-tolk-overview":``},zf={class:`flex flex-wrap gap-4 text-sm`},Bf=[`href`],Vf={class:`overflow-x-auto`},Hf={class:`flex flex-col items-start gap-1`},Uf={key:1,class:`space-y-1.5`},Wf={key:0,class:`flex flex-wrap gap-1`},Gf={key:5,class:`space-y-1`},Kf={key:6,class:`flex flex-wrap gap-1`},qf={class:`grid gap-6 lg:grid-cols-2`},Jf={class:`flex flex-wrap items-center justify-between gap-2`},Yf={class:`overflow-x-auto`},Xf={class:`space-y-2`},Zf=[`data-tolk-provider`],Qf=[`href`],$f={class:`flex flex-wrap items-baseline justify-between gap-2`},ep={__name:`Overview`,props:{multisite:{type:Boolean,default:!1},sites:{type:Array,default:()=>[]},rows:{type:Array,default:()=>[]},providers:{type:Array,default:()=>[]},fakeEngine:{type:Boolean,default:!1},usage:{type:Object,default:()=>({})},canResetUsage:{type:Boolean,default:!1},runs:{type:Array,default:()=>[]},urls:{type:Object,required:!0}},setup(e){let t=e,n=Dt({}),r=I(null),i=I(t.usage),a=I(!1),o=I(!1),s=Statamic.$config.get(`tolk`)?.settingsUrl??null,c=O(()=>Pf(t)),l=O(()=>Ef(t.rows,t.sites)),u=O(()=>Df(t.rows).map(e=>({...e,rows:e.rows.map(e=>({...e,cells:l.value.map(t=>{let r=Of(e,t.handle),i=e.sites.includes(t.handle),a=n[r.key];return{site:t,cell:r,status:i?a?.status??`waiting`:`none`,view:i?jf(a):null}})}))}))),d=O(()=>kf(t.rows)),f=O(()=>Ff(i.value)),p=O(()=>Object.values(n).some(e=>Number(e?.untracked)>0)),h=O(()=>Object.values(n).some(e=>Number(e?.unreadable)>0)),g=O(()=>Object.fromEntries(l.value.map(e=>[e.handle,Nf(t.rows,n,e.handle)]))),_=yf({scan:({key:e,...n})=>$i(t.urls.scan,n),onChange:(e,t)=>n[e]=t});pt(()=>{c.value===null&&_.load(d.value)}),lt(()=>_.stop());function v(){_.load(d.value,{fresh:!0})}async function y(e,n){r.value=e;try{let{url:e}=await $i(t.urls.store,n);_.stop(),qd.visit(e)}catch(e){Statamic.$toast.error(e.message),r.value=null}}async function b(){let e=Lf(f.value.month);a.value=!1,o.value=!0;try{i.value=(await $i(t.urls.resetUsage,{month:f.value.month})).usage,Statamic.$toast.success(__(`The usage of :month was reset.`,{month:e}))}catch(e){Statamic.$toast.error(e.message)}finally{o.value=!1}}return(t,n)=>(F(),j(`div`,Rf,[P(z(Gd),{title:t.__(`Translations`)},null,8,[`title`]),P(z(br),{title:t.__(`Translations`),icon:`dictionary-language-book`},{default:B(()=>[P(z(Kd),{href:e.urls.runs,class:`text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200`,"data-tolk-runs-link":``},{default:B(()=>[N(R(t.__(`All runs`)),1)]),_:1},8,[`href`]),c.value===null&&d.value.length>0?(F(),k(z(V),{key:0,text:t.__(`Count again`),icon:`sync`,"data-tolk-count-again":``,onClick:v},null,8,[`text`])):A(``,!0)]),_:1},8,[`title`]),c.value===`single_site`?(F(),k(z(H),{key:0,class:`space-y-3`,"data-tolk-overview-empty":`single_site`},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`This site has one language`)},null,8,[`text`]),P(z(q),null,{default:B(()=>[N(R(t.__(`Tolk translates the content of one site into the languages of the others. Add a site for each language in Statamic first; the overview then shows what is translated into each.`)),1)]),_:1}),P(z(Kd),{href:e.urls.audit,class:`text-sm text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-audit-link":``},{default:B(()=>[N(R(t.__(`Check the setup`)),1)]),_:1},8,[`href`])]),_:1})):c.value===`no_provider`?(F(),k(z(H),{key:1,class:`space-y-3`,"data-tolk-overview-empty":`no_provider`},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`No AI provider is set up`)},null,8,[`text`]),P(z(q),null,{default:B(()=>[N(R(t.__(`Tolk needs an API key of Anthropic, OpenAI or Google Gemini in the .env file before it can translate. The settings list the variables to set.`)),1)]),_:1}),M(`div`,zf,[z(s)?(F(),j(`a`,{key:0,href:z(s),class:`text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-settings-link":``},R(t.__(`Open the settings`)),9,Bf)):A(``,!0),P(z(Kd),{href:e.urls.audit,class:`text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-audit-link":``},{default:B(()=>[N(R(t.__(`Check the setup`)),1)]),_:1},8,[`href`])])]),_:1})):e.rows.length===0?(F(),k(z(H),{key:2,"data-tolk-overview-nothing":``},{default:B(()=>[P(z(q),null,{default:B(()=>[N(R(t.__(`No collection, taxonomy, global set or navigation has more than one site yet, so there is nothing to translate.`)),1)]),_:1})]),_:1})):(F(),k(z(H),{key:3,class:`space-y-3`,"data-tolk-matrix":``},{default:B(()=>[M(`div`,Vf,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(t.__(`Content`)),1)]),_:1}),(F(!0),j(m,null,L(l.value,e=>(F(),k(z(K),{key:e.handle,"data-tolk-column":e.handle},{default:B(()=>[M(`div`,Hf,[M(`span`,null,R(e.name),1),g.value[e.handle]?(F(),k(z(V),{key:0,size:`xs`,text:t.__(`Translate everything missing`),"aria-label":t.__(`Translate everything missing into :site`,{site:e.name}),loading:r.value===`site|${e.handle}`,disabled:r.value!==null,"data-tolk-site-action":e.handle,onClick:t=>y(`site|${e.handle}`,g.value[e.handle])},null,8,[`text`,`aria-label`,`loading`,`disabled`,`data-tolk-site-action`,`onClick`])):A(``,!0)])]),_:2},1032,[`data-tolk-column`]))),128))]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(u.value,e=>(F(),j(m,{key:e.type},[P(z(ki),{"data-tolk-group":e.type},{default:B(()=>[P(z(G),{colspan:l.value.length+1,class:`bg-gray-50 dark:bg-gray-900`},{default:B(()=>[P(z(W),{text:e.label},null,8,[`text`])]),_:2},1032,[`colspan`])]),_:2},1032,[`data-tolk-group`]),(F(!0),j(m,null,L(e.rows,e=>(F(),k(z(ki),{key:`${e.type}|${e.handle}`,"data-tolk-row":`${e.type}|${e.handle}`},{default:B(()=>[P(z(G),null,{default:B(()=>[P(z(q),null,{default:B(()=>[N(R(e.title),1)]),_:2},1024),P(z(U),null,{default:B(()=>[N(R(e.handle),1)]),_:2},1024)]),_:2},1024),(F(!0),j(m,null,L(e.cells,({site:i,cell:a,status:o,view:s})=>(F(),k(z(G),{key:i.handle,class:`align-top`,"data-tolk-cell":a.key,"data-tolk-cell-status":o},{default:B(()=>[s?(F(),j(`div`,Uf,[s.badges.length?(F(),j(`div`,Wf,[(F(!0),j(m,null,L(s.badges,e=>(F(),k(z(Pn),{key:e.status,text:e.text,color:e.color,"data-tolk-count":e.status},null,8,[`text`,`color`,`data-tolk-count`]))),128))])):A(``,!0),s.loading?(F(),k(z(U),{key:1},{default:B(()=>[N(R(t.__(`Counting…`)),1)]),_:1})):s.finished&&s.scanned===0?(F(),k(z(U),{key:2},{default:B(()=>[N(R(t.__(`Nothing to translate`)),1)]),_:1})):A(``,!0),s.untracked>0?(F(),k(z(U),{key:3,"data-tolk-untracked":``},{default:B(()=>[N(R(t.__n(`:count untracked field|:count untracked fields`,s.untracked)),1)]),_:2},1024)):A(``,!0),s.unreadable>0?(F(),k(z(U),{key:4,"data-tolk-unreadable":``},{default:B(()=>[N(R(t.__n(`:count item with unreadable state|:count items with unreadable state`,s.unreadable)),1)]),_:2},1024)):A(``,!0),s.failed?(F(),j(`div`,Gf,[P(z(q),{size:`sm`,variant:`danger`,"data-tolk-cell-error":``},{default:B(()=>[N(R(s.error),1)]),_:2},1024),P(z(V),{size:`xs`,text:t.__(`Try again`),"data-tolk-cell-retry":``,onClick:e=>z(_).retry(a)},null,8,[`text`,`onClick`])])):A(``,!0),s.missing>0||s.outdated>0?(F(),j(`div`,Kf,[s.missing>0?(F(),k(z(V),{key:0,size:`xs`,text:t.__(`Translate missing`),"aria-label":t.__(`Translate missing :content into :site`,{content:e.title,site:i.name}),loading:r.value===`${a.key}|missing`,disabled:r.value!==null,"data-tolk-cell-action":`missing`,onClick:t=>y(`${a.key}|missing`,z(Mf)(e.type,e.handle,i.handle,`missing`))},null,8,[`text`,`aria-label`,`loading`,`disabled`,`onClick`])):A(``,!0),s.outdated>0?(F(),k(z(V),{key:1,size:`xs`,text:t.__(`Update outdated`),"aria-label":t.__(`Update outdated :content in :site`,{content:e.title,site:i.name}),loading:r.value===`${a.key}|update`,disabled:r.value!==null,"data-tolk-cell-action":`update`,onClick:t=>y(`${a.key}|update`,z(Mf)(e.type,e.handle,i.handle,`update`))},null,8,[`text`,`aria-label`,`loading`,`disabled`,`onClick`])):A(``,!0)])):A(``,!0)])):(F(),k(z(U),{key:0},{default:B(()=>[...n[2]||=[N(`—`,-1)]]),_:1}))]),_:2},1032,[`data-tolk-cell`,`data-tolk-cell-status`]))),128))]),_:2},1032,[`data-tolk-row`]))),128))],64))),128))]),_:1})]),_:1})]),p.value?(F(),k(z(U),{key:0,"data-tolk-baseline-hint":``},{default:B(()=>[N(R(t.__(`Untracked fields were translated by hand without a record of their origin, so a change to the origin goes unnoticed. Run php please tolk:baseline to record the origin of each.`)),1)]),_:1})):A(``,!0),h.value?(F(),k(z(U),{key:1,"data-tolk-unreadable-hint":``},{default:B(()=>[N(R(t.__(`The translation state of some items cannot be read, so their status is unknown and translating them fails. Run php please tolk:doctor to list the files.`)),1)]),_:1})):A(``,!0)]),_:1})),M(`div`,qf,[P(z(H),{class:`space-y-3`,"data-tolk-usage":``},{default:B(()=>[M(`div`,Jf,[P(z(W),{size:`lg`,text:t.__(`Usage in :month`,{month:z(Lf)(f.value.month)})},null,8,[`text`]),e.canResetUsage&&f.value.rows.length>0?(F(),k(z(V),{key:0,size:`sm`,text:t.__(`Reset`),"aria-label":t.__(`Reset the usage of :month`,{month:z(Lf)(f.value.month)}),loading:o.value,"data-tolk-usage-reset":``,onClick:n[0]||=e=>a.value=!0},null,8,[`text`,`aria-label`,`loading`])):A(``,!0)]),f.value.rows.length===0?(F(),k(z(q),{key:0},{default:B(()=>[N(R(t.__(`No model was called this month.`)),1)]),_:1})):(F(),j(m,{key:1},[M(`div`,Yf,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(t.__(`Model`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Calls`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Tokens`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Cost`)),1)]),_:1})]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(f.value.rows,e=>(F(),k(z(ki),{key:e.reference,"data-tolk-usage-model":e.reference},{default:B(()=>[P(z(G),null,{default:B(()=>[N(R(e.model)+` `,1),P(z(U),null,{default:B(()=>[N(R(e.sources.map(z(If)).join(`, `)),1)]),_:2},1024)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(z(Q)(e.calls)),1)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(t.__(`:input in, :output out`,{input:z(Q)(e.input),output:z(Q)(e.output)})),1)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(e.cost===null?t.__(`Unknown`):z(ys)(e.cost)),1)]),_:2},1024)]),_:2},1032,[`data-tolk-usage-model`]))),128))]),_:1})]),_:1})]),P(z(U),{"data-tolk-usage-total":``},{default:B(()=>[N(R(f.value.cost===null?t.__n(`:calls call this month. The cost is unknown: a model without a price was called.|:calls calls this month. The cost is unknown: a model without a price was called.`,f.value.calls,{calls:z(Q)(f.value.calls)}):t.__n(`:calls call this month, an estimated :cost.|:calls calls this month, an estimated :cost.`,f.value.calls,{calls:z(Q)(f.value.calls),cost:z(ys)(f.value.cost)})),1)]),_:1})],64))]),_:1}),P(z(H),{class:`space-y-3`,"data-tolk-providers":``},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`Providers`)},null,8,[`text`]),M(`ul`,Xf,[(F(!0),j(m,null,L(e.providers,e=>(F(),j(`li`,{key:e.provider,class:`flex items-center justify-between gap-2`,"data-tolk-provider":e.provider},[P(z(q),null,{default:B(()=>[N(R(e.label),1)]),_:2},1024),P(z(Pn),tt({ref_for:!0},z(hd)(e.configured)),null,16)],8,Zf))),128))]),e.fakeEngine?(F(),k(z(U),{key:0,"data-tolk-fake-engine":``},{default:B(()=>[N(R(t.__(`The fake engine is on: translations are made up without calling a provider.`)),1)]),_:1})):A(``,!0),z(s)?(F(),j(`a`,{key:1,href:z(s),class:`text-sm text-blue-600 hover:underline dark:text-blue-400`},R(t.__(`Settings`)),9,Qf)):A(``,!0)]),_:1})]),P(z(H),{class:`space-y-3`,"data-tolk-latest-runs":``},{default:B(()=>[M(`div`,$f,[P(z(W),{size:`lg`,text:t.__(`Latest runs`)},null,8,[`text`]),e.runs.length>0?(F(),k(z(Kd),{key:0,href:e.urls.runs,class:`text-sm text-blue-600 hover:underline dark:text-blue-400`},{default:B(()=>[N(R(t.__(`All runs`)),1)]),_:1},8,[`href`])):A(``,!0)]),e.runs.length===0?(F(),k(z(q),{key:0},{default:B(()=>[N(R(t.__(`No translation runs yet.`)),1)]),_:1})):(F(),k(vf,{key:1,runs:e.runs},null,8,[`runs`]))]),_:1}),a.value?(F(),k(z(Kn),{key:4,open:``,danger:``,title:t.__(`Reset the usage of :month?`,{month:z(Lf)(f.value.month)}),"body-text":t.__(`The calls, tokens and costs counted this month are deleted, and counting starts again from zero. The runs keep their own usage.`),"button-text":t.__(`Reset`),"data-tolk-usage-reset-confirm":``,"onUpdate:open":n[1]||=e=>a.value=e,onConfirm:b},null,8,[`title`,`body-text`,`button-text`])):A(``,!0)]))}},tp={class:`mx-auto max-w-page space-y-6`,"data-tolk-runs":``},np={__name:`Index`,props:{runs:{type:Array,default:()=>[]},canReset:{type:Boolean,default:!1},urls:{type:Object,default:()=>({})}},setup(e){let t=e,n=I(!1),r=I(!1),i=O(()=>t.runs.some(e=>Vo.includes(e.status)));async function a(){n.value=!1,r.value=!0;try{let{deleted:e}=await $i(t.urls.reset);Statamic.$toast.success(__n(`:count run was deleted.|:count runs were deleted.`,e)),qd.reload({only:[`runs`]})}catch(e){Statamic.$toast.error(e.message)}finally{r.value=!1}}return(t,o)=>(F(),j(`div`,tp,[P(z(Gd),{title:t.__(`Translation runs`)},null,8,[`title`]),P(z(br),{title:t.__(`Translation runs`),icon:`dictionary-language-book`},{default:B(()=>[e.canReset&&i.value?(F(),k(z(V),{key:0,text:t.__(`Reset`),loading:r.value,"data-tolk-runs-reset":``,onClick:o[0]||=e=>n.value=!0},null,8,[`text`,`loading`])):A(``,!0)]),_:1},8,[`title`]),e.runs.length===0?(F(),k(z(H),{key:0,"data-tolk-runs-empty":``},{default:B(()=>[P(z(q),null,{default:B(()=>[N(R(t.__(`No translation runs yet. Runs started from a listing, the overview or the command line appear here.`)),1)]),_:1})]),_:1})):(F(),k(z(H),{key:1},{default:B(()=>[P(vf,{runs:e.runs},null,8,[`runs`])]),_:1})),n.value?(F(),k(z(Kn),{key:2,open:``,danger:``,title:t.__(`Delete the finished runs?`),"body-text":t.__(`Every completed, cancelled and aborted run is deleted with its results, and can no longer be resumed or retried. Pending and running runs stay. The translations they saved stay too.`),"button-text":t.__(`Delete`),"data-tolk-runs-reset-confirm":``,"onUpdate:open":o[1]||=e=>n.value=e,onConfirm:a},null,8,[`title`,`body-text`,`button-text`])):A(``,!0)]))}},rp=[`data-tolk-run-status`],ip={class:`flex flex-wrap items-center gap-2`},ap={class:`flex flex-wrap items-center gap-x-4 gap-y-1`,"data-tolk-run-counts":``},op={class:`space-y-3`},sp={class:`flex flex-wrap gap-2`},cp={class:`flex flex-wrap items-center justify-between gap-2`},lp={class:`space-y-3`},up={key:1,class:`flex flex-wrap gap-2`},dp={class:`grid gap-6 lg:grid-cols-2`},fp={class:`overflow-x-auto`},pp={class:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm`},mp={class:`text-gray-600 dark:text-gray-400`},hp=[`data-tolk-option`],gp={class:`flex flex-wrap items-baseline justify-between gap-2`},_p={key:0,class:`flex flex-wrap gap-x-10 gap-y-2 text-sm`},vp={class:`text-gray-600 dark:text-gray-400`},yp={"data-tolk-estimate-segments":``},bp={class:`text-gray-600 dark:text-gray-400`},xp={"data-tolk-estimate-chars":``},Sp={class:`text-gray-600 dark:text-gray-400`},Cp={"data-tolk-estimate-input":``},wp={class:`text-gray-600 dark:text-gray-400`},Tp={"data-tolk-estimate-output":``},Ep={class:`text-gray-600 dark:text-gray-400`},Dp={"data-tolk-estimate-cost":``},Op={class:`flex flex-wrap items-center justify-between gap-2`},kp={class:`w-56`},Ap={class:`overflow-x-auto`},jp=[`href`],Mp={key:1},Np={key:1,class:`flex flex-wrap items-center gap-2`},Pp=[`href`],Fp={key:1,class:`flex items-center justify-end gap-2`,"data-tolk-items-pages":``},Ip={__name:`Show`,props:{state:{type:Object,required:!0},urls:{type:Object,required:!0},models:{type:Object,default:()=>({})},lanes:{type:Number,default:1}},setup(e){let t=e,n=I(t.state),r=I(t.state.run?.estimate??null),i=I([]),a=I(null),o=I(t.state.pagination?.page??1),s=t.state.pagination?.per_page??50,c=I(`all`),l=vs(Statamic.$config.get(`sites`)),u=tc.following(t.state.run?.id),d=Ls({urls:t.urls,lanes:t.lanes,dirty:u?null:`tolk-run`,onState:e=>{n.value=e,r.value=e.run?.estimate??r.value,o.value=Is(o.value,e.pagination)},onEstimate:e=>r.value=e,onFailures:e=>i.value=e,query:()=>({page:o.value,per_page:s,...c.value===`all`?{}:{status:c.value}})});function f(e){d.driving&&(e.preventDefault(),e.returnValue=``)}let p=()=>{};pt(()=>{p=tc.lend(t.state.run?.id),d.follow(t.state),window.addEventListener(`beforeunload`,f)}),lt(()=>{d.stop(),p(n.value),window.removeEventListener(`beforeunload`,f)});let h=O(()=>n.value.run??{}),g=O(()=>h.value.status),_=O(()=>xs(n.value)),v=O(()=>Ss(n.value)),y=O(()=>ws(n.value)),b=O(()=>Os(h.value.scope,l)),x=O(()=>Ts(n.value.breakdown,l)),S=O(()=>Es(h.value.scope)),C=Kl(Statamic.$config.get(`tolk.auditUrl`)),w=O(()=>Ds(h.value.scope)),ee=O(()=>ks(h.value.options,t.models)),T=O(()=>As(r.value,_.value.total)),E=O(()=>js(h.value,t.models)),te=O(()=>(n.value.items??[]).map(e=>Fs(e,l))),D=O(()=>n.value.pagination??{page:1,last_page:1,total:0}),ne=O(()=>g.value===`running`&&h.value.driver===`browser`),re=O(()=>g.value===`running`&&!!n.value.stalled),ie=O(()=>ls.filter(e=>_.value.counts[e]>0).map(e=>({key:e,text:`${Q(_.value.counts[e])} ${hs(e).toLowerCase()}`}))),ae=O(()=>[{label:__(`All items`),value:`all`},...ls.map(e=>({label:hs(e),value:e}))]),oe=I(null),se=fu(()=>oe.value),ce=jc(),le=I([]);function ue(e){le.value=e.corrections,ce.show()}bn(g,()=>se.changing());let de=O(()=>{let e=h.value.created_by?.name,t=bs(h.value.created_at);return b.value.automatic?e?__(`Started automatically on :date, when :name saved the entry.`,{name:e,date:t}):__(`Started automatically on :date, when the entry was saved.`,{date:t}):e?__(`Created by :name on :date`,{name:e,date:t}):__(`Created on :date from the command line`,{date:t})});async function fe(e,t){let n=se.holds();a.value=e;try{let n=await t();e===`retry`&&n?.retried===0&&Statamic.$toast.info(__(`No item failed, so nothing was retried.`))}catch(e){Statamic.$toast.error(e.message)}finally{a.value=null,n&&nt(se.restore)}}async function pe(e){o.value=Math.max(1,e);try{await d.refresh()}catch(e){Statamic.$toast.error(e.message)}}function me(e){c.value=e??`all`,pe(1)}return(t,r)=>(F(),j(`div`,{ref_key:`root`,ref:oe,class:`mx-auto max-w-page space-y-6`,"data-tolk-run":``,"data-tolk-run-status":g.value},[P(z(Gd),{title:t.__(`Translation run`)},null,8,[`title`]),P(z(br),{title:t.__(`Translation run`),icon:`dictionary-language-book`},{default:B(()=>[P(z(Kd),{href:e.urls.index,class:`text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200`,"data-tolk-runs-link":``},{default:B(()=>[N(R(t.__(`All runs`)),1)]),_:1},8,[`href`]),v.value.cancel?(F(),k(z(V),{key:0,text:t.__(`Cancel`),loading:a.value===`cancel`,disabled:a.value!==null,"data-tolk-action":`cancel`,onClick:r[0]||=e=>fe(`cancel`,z(d).cancel)},null,8,[`text`,`loading`,`disabled`])):A(``,!0),v.value.start?(F(),k(z(V),{key:1,variant:`primary`,text:t.__(`Start`),loading:a.value===`start`,disabled:a.value!==null,"data-tolk-action":`start`,onClick:r[1]||=e=>fe(`start`,z(d).start)},null,8,[`text`,`loading`,`disabled`])):A(``,!0)]),_:1},8,[`title`]),P(z(H),{class:`space-y-3`,"data-tolk-run-summary":``},{default:B(()=>[M(`div`,ip,[P(z(Pn),{text:z(ps)(g.value),color:z(ms)(g.value),"data-tolk-run-status-badge":``},null,8,[`text`,`color`]),P(z(q),null,{default:B(()=>[N(R(b.value.sites?t.__(`:what into :sites`,{what:b.value.what,sites:b.value.sites}):b.value.what),1)]),_:1})]),P(z(U),null,{default:B(()=>[N(R(de.value),1)]),_:1}),g.value===`pending`?A(``,!0):(F(),j(m,{key:0},[P(Ba,{value:_.value.finished,max:_.value.total,label:t.__(`Run progress`)},null,8,[`value`,`max`,`label`]),M(`div`,ap,[P(z(q),null,{default:B(()=>[N(R(t.__(`:finished of :total items finished`,{finished:z(Q)(_.value.finished),total:z(Q)(_.value.total)})),1)]),_:1}),(F(!0),j(m,null,L(ie.value,e=>(F(),k(z(U),{key:e.key,"data-tolk-count":e.key},{default:B(()=>[N(R(e.text),1)]),_:2},1032,[`data-tolk-count`]))),128))]),P(z(U),{"data-tolk-run-usage":``},{default:B(()=>[N(R(t.__n(`:input input and :output output tokens in :calls call.|:input input and :output output tokens in :calls calls.`,E.value.calls,{input:z(Q)(E.value.input),output:z(Q)(E.value.output),calls:z(Q)(E.value.calls)}))+` `+R(E.value.cost===null?t.__(`The cost is unknown: a model without a price was called.`):t.__(`Estimated cost so far: :cost.`,{cost:z(ys)(E.value.cost)})),1)]),_:1})],64))]),_:1}),ne.value?(F(),k(z(jn),{key:0,variant:`default`,icon:`info`,"data-tolk-keep-open":``},{default:B(()=>[N(R(z(u)?t.__(`Keep this tab open while the run is in progress. Closing it pauses the run until you open it again.`):t.__(`Keep this page open while the run is in progress. Leaving it pauses the run until you open it again.`)),1)]),_:1})):A(``,!0),re.value?(F(),k(z(jn),{key:1,variant:`warning`,heading:t.__(`This run is not moving`),"data-tolk-stalled":``},{default:B(()=>[M(`div`,op,[h.value.driver===`cli`&&b.value.automatic?(F(),k(z(q),{key:0},{default:B(()=>[N(R(t.__(`The process that updates these translations has not worked on them for a while and may have stopped. Resume continues the run from here.`)),1)]),_:1})):h.value.driver===`cli`?(F(),k(z(q),{key:1},{default:B(()=>[N(R(t.__(`The command running this run has not worked on it for a while and may have stopped. Resume continues the run from here.`)),1)]),_:1})):(F(),k(z(q),{key:2},{default:B(()=>[N(R(t.__(`No queue worker has worked on this run for a while. Start a worker for the queue, or run it in this browser instead.`)),1)]),_:1})),M(`div`,sp,[P(z(V),{size:`sm`,text:t.__(`Resume`),loading:a.value===`resume`,disabled:a.value!==null,"data-tolk-action":`resume`,onClick:r[2]||=e=>fe(`resume`,z(d).resume)},null,8,[`text`,`loading`,`disabled`]),v.value.takeOver?(F(),k(z(V),{key:0,size:`sm`,variant:`primary`,text:t.__(`Run in this browser instead`),loading:a.value===`take-over`,disabled:a.value!==null,"data-tolk-action":`take-over`,onClick:r[3]||=e=>fe(`take-over`,z(d).takeOver)},null,8,[`text`,`loading`,`disabled`])):A(``,!0)])])]),_:1},8,[`heading`])):A(``,!0),(F(!0),j(m,null,L(i.value,(e,i)=>(F(),k(z(jn),{key:i,variant:`error`,"data-tolk-run-failure":``},{default:B(()=>[M(`div`,cp,[P(z(q),null,{default:B(()=>[N(R(t.__(`Following the run stopped: :message`,{message:e.error?.message??``})),1)]),_:2},1024),i===0?(F(),k(z(V),{key:0,size:`sm`,text:t.__(`Try again`),"data-tolk-action":`follow-again`,onClick:r[4]||=e=>z(d).follow(n.value)},null,8,[`text`])):A(``,!0)])]),_:2},1024))),128)),y.value?(F(),k(z(jn),{key:2,variant:y.value.variant,"data-tolk-run-result":``},{default:B(()=>[M(`div`,lp,[P(z(q),{as:`p`},{default:B(()=>[N(R(y.value.text),1)]),_:1}),y.value.error?(F(),k(z(q),{key:0,as:`p`,variant:`danger`},{default:B(()=>[N(R(y.value.error),1)]),_:1})):A(``,!0),v.value.retry||v.value.resume?(F(),j(`div`,up,[v.value.retry?(F(),k(z(V),{key:0,size:`sm`,text:t.__(`Retry failed`),loading:a.value===`retry`,disabled:a.value!==null,"data-tolk-action":`retry`,onClick:r[5]||=e=>fe(`retry`,z(d).retry)},null,8,[`text`,`loading`,`disabled`])):A(``,!0),v.value.resume?(F(),k(z(V),{key:1,size:`sm`,text:t.__(`Resume`),loading:a.value===`resume`,disabled:a.value!==null,"data-tolk-action":`resume`,onClick:r[6]||=e=>fe(`resume`,z(d).resume)},null,8,[`text`,`loading`,`disabled`])):A(``,!0)])):A(``,!0)])]),_:1},8,[`variant`])):A(``,!0),M(`div`,dp,[P(z(H),{class:`space-y-3`,"data-tolk-breakdown":``},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`What it translates`)},null,8,[`text`]),M(`div`,fp,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(t.__(`Content`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Site`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Items`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Skipped`)),1)]),_:1})]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(x.value,e=>(F(),k(z(ki),{key:e.key,"data-tolk-breakdown-row":e.key},{default:B(()=>[P(z(G),null,{default:B(()=>[N(R(e.type),1)]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(e.site),1)]),_:2},1024),P(z(G),{"data-tolk-breakdown-total":``},{default:B(()=>[N(R(z(Q)(e.total)),1)]),_:2},1024),P(z(G),{"data-tolk-breakdown-skipped":``},{default:B(()=>[N(R(z(Q)(e.skipped)),1)]),_:2},1024)]),_:2},1032,[`data-tolk-breakdown-row`]))),128))]),_:1})]),_:1})]),x.value.length===0?(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.__(`This run has nothing to translate.`)),1)]),_:1})):A(``,!0),(F(!0),j(m,null,L(S.value,e=>(F(),k(z(U),{key:e.reason,"data-tolk-left-out":e.reason},{default:B(()=>[N(R(e.text),1)]),_:2},1032,[`data-tolk-left-out`]))),128)),w.value?(F(),k(z(U),{key:1,"data-tolk-not-localizable":``},{default:B(()=>[N(R(w.value)+` `,1),z(C)?(F(),k(z(Kd),{key:0,href:z(C),class:`text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-audit-link":``},{default:B(()=>[N(R(t.__(`Open the setup audit`)),1)]),_:1},8,[`href`])):(F(),j(m,{key:1},[N(R(t.__(`Run php please tolk:doctor for details.`)),1)],64))]),_:1})):A(``,!0)]),_:1}),P(z(H),{class:`space-y-3`,"data-tolk-settings":``},{default:B(()=>[P(z(W),{size:`lg`,text:t.__(`Settings`)},null,8,[`text`]),M(`dl`,pp,[(F(!0),j(m,null,L(ee.value,e=>(F(),j(m,{key:e.key},[M(`dt`,mp,R(e.label),1),M(`dd`,{"data-tolk-option":e.key},R(e.value),9,hp)],64))),128))])]),_:1})]),g.value===`pending`||T.value?(F(),k(z(H),{key:3,class:`space-y-3`,"data-tolk-estimate":``,"data-tolk-estimate-finished":T.value?.finished?`true`:`false`},{default:B(()=>[M(`div`,gp,[P(z(W),{size:`lg`,text:t.__(`Estimate`)},null,8,[`text`]),T.value?!T.value.finished&&g.value===`pending`?(F(),k(z(U),{key:1},{default:B(()=>[N(R(t.__(`Estimating… :progress`,{progress:T.value.progress})),1)]),_:1})):T.value.finished?A(``,!0):(F(),k(z(U),{key:2,"data-tolk-estimate-partial":``},{default:B(()=>[N(R(T.value.partial),1)]),_:1})):(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.__(`Estimating…`)),1)]),_:1}))]),T.value?(F(),j(`dl`,_p,[M(`div`,null,[M(`dt`,vp,R(t.__(`Segments`)),1),M(`dd`,yp,R(z(Q)(T.value.segments)),1)]),M(`div`,null,[M(`dt`,bp,R(t.__(`Characters`)),1),M(`dd`,xp,R(z(Q)(T.value.chars)),1)]),M(`div`,null,[M(`dt`,Sp,R(t.__(`Input tokens`)),1),M(`dd`,Cp,R(z(Q)(T.value.inputTokens)),1)]),M(`div`,null,[M(`dt`,wp,R(t.__(`Output tokens`)),1),M(`dd`,Tp,R(z(Q)(T.value.outputTokens)),1)]),M(`div`,null,[M(`dt`,Ep,R(t.__(`Cost`)),1),M(`dd`,Dp,R(T.value.cost===null?t.__(`Unknown`):z(ys)(T.value.cost)),1)])])):A(``,!0),P(z(U),null,{default:B(()=>[N(R(t.__(`An estimate: the tokens a language takes vary, and so does what a model writes.`))+` `,1),T.value&&T.value.cost===null?(F(),j(m,{key:0},[N(R(t.__(`The cost is unknown because a model has no price.`)),1)],64)):A(``,!0)]),_:1})]),_:1},8,[`data-tolk-estimate-finished`])):A(``,!0),P(z(H),{class:`space-y-3`,"data-tolk-items":``},{default:B(()=>[M(`div`,Op,[P(z(W),{size:`lg`,text:t.__(`Items`)},null,8,[`text`]),M(`div`,kp,[P(z(di),{"model-value":c.value,options:ae.value,size:`sm`,"data-tolk-items-filter":``,"onUpdate:modelValue":me},null,8,[`model-value`,`options`])])]),M(`div`,Ap,[P(z(Di),null,{default:B(()=>[P(z(Oi),null,{default:B(()=>[P(z(K),null,{default:B(()=>[N(R(t.__(`Title`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Site`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Status`)),1)]),_:1}),P(z(K),null,{default:B(()=>[N(R(t.__(`Result`)),1)]),_:1})]),_:1}),P(z(Ai),null,{default:B(()=>[(F(!0),j(m,null,L(te.value,e=>(F(),k(z(ki),{key:e.index,"data-tolk-item":``,"data-tolk-item-status":e.status},{default:B(()=>[P(z(G),null,{default:B(()=>[e.editUrl?(F(),j(`a`,{key:0,href:e.editUrl,class:`text-blue-600 hover:underline dark:text-blue-400`},R(e.title),9,jp)):(F(),j(`span`,Mp,R(e.title),1))]),_:2},1024),P(z(G),null,{default:B(()=>[N(R(e.site),1)]),_:2},1024),P(z(G),null,{default:B(()=>[P(z(Pn),{text:e.statusLabel,color:e.statusColor},null,8,[`text`,`color`])]),_:2},1024),P(z(G),{class:`space-y-1`},{default:B(()=>[e.applied?(F(),k(z(q),{key:0,size:`sm`},{default:B(()=>[N(R(e.applied),1)]),_:2},1024)):A(``,!0),e.corrections.length?(F(),j(`div`,Np,[P(z(q),{size:`sm`},{default:B(()=>[N(R(e.corrected),1)]),_:2},1024),P(z(V),{size:`sm`,variant:`ghost`,text:t.__(`View changes`),"aria-label":t.__(`View changes to :title in :site`,{title:e.title,site:e.site}),"data-tolk-item-changes":``,onClick:t=>ue(e)},null,8,[`text`,`aria-label`,`onClick`])])):A(``,!0),e.incomplete.length?(F(),k(z(U),{key:2},{default:B(()=>[N(R(t.__(`Left incomplete: :fields`,{fields:e.incomplete.join(`, `)})),1)]),_:2},1024)):A(``,!0),e.failed.length?(F(),k(z(U),{key:3,"data-tolk-item-failed":``},{default:B(()=>[N(R(t.__(`Could not be translated: :fields`,{fields:e.failed.map(e=>`${e.handle} (${e.reason})`).join(`, `)})),1)]),_:2},1024)):A(``,!0),e.notReviewed.length?(F(),k(z(U),{key:4},{default:B(()=>[N(R(t.__(`Not reviewed in full: :fields`,{fields:e.notReviewed.join(`, `)})),1)]),_:2},1024)):A(``,!0),e.kept.length?(F(),k(z(U),{key:5},{default:B(()=>[N(R(t.__(`Not changed: :fields`,{fields:e.kept.map(e=>`${e.handle} (${e.reason})`).join(`, `)})),1)]),_:2},1024)):A(``,!0),e.reason?(F(),k(z(U),{key:6},{default:B(()=>[N(R(e.reason),1)]),_:2},1024)):A(``,!0),e.error?(F(),k(z(q),{key:7,size:`sm`,variant:`danger`,"data-tolk-item-error":``},{default:B(()=>[N(R(e.error)+` `,1),e.rootPage?(F(),j(`a`,{key:0,href:e.rootPage.url,class:`text-blue-600 hover:underline dark:text-blue-400`,"data-tolk-root-page":``},R(t.__(`Open :title`,{title:e.rootPage.title})),9,Pp)):A(``,!0)]),_:2},1024)):A(``,!0),(F(!0),j(m,null,L(e.warnings,(e,t)=>(F(),k(z(U),{key:t},{default:B(()=>[N(R(e),1)]),_:2},1024))),128))]),_:2},1024)]),_:2},1032,[`data-tolk-item-status`]))),128))]),_:1})]),_:1})]),te.value.length===0?(F(),k(z(U),{key:0},{default:B(()=>[N(R(t.__(`No items.`)),1)]),_:1})):A(``,!0),D.value.last_page>1?(F(),j(`div`,Fp,[P(z(U),null,{default:B(()=>[N(R(t.__(`Page :page of :pages`,{page:D.value.page,pages:D.value.last_page})),1)]),_:1}),P(z(V),{size:`sm`,icon:`chevron-left`,"aria-label":t.__(`Previous page`),disabled:D.value.page<=1,onClick:r[7]||=e=>pe(D.value.page-1)},null,8,[`aria-label`,`disabled`]),P(z(V),{size:`sm`,icon:`chevron-right`,"aria-label":t.__(`Next page`),disabled:D.value.page>=D.value.last_page,onClick:r[8]||=e=>pe(D.value.page+1)},null,8,[`aria-label`,`disabled`])])):A(``,!0),z(ce).open?(F(),k(Ra,{key:2,modal:z(ce),corrections:le.value},null,8,[`modal`,`corrections`])):A(``,!0)]),_:1})],8,rp))}};Statamic.booting(()=>{Statamic.$components.register(wc,Iu),Statamic.$components.register(zu,Ru),Statamic.$components.register(`tolk_model-fieldtype`,pd),Statamic.$components.register(`tolk_providers-fieldtype`,Cd),Statamic.$components.register(`tolk_site_profile-fieldtype`,Ud),Statamic.$inertia.register(`tolk::Audit`,gf),Statamic.$inertia.register(`tolk::Overview`,ep),Statamic.$inertia.register(`tolk::Runs/Index`,np),Statamic.$inertia.register(`tolk::Runs/Show`,Ip),Ha.listen(),kc.listen(),ol.listen(),ou({PipelineStopped:a}).listen(),Hu.register()}); \ No newline at end of file diff --git a/resources/dist/build/manifest.json b/resources/dist/build/manifest.json index d1e7fb0..07281e2 100644 --- a/resources/dist/build/manifest.json +++ b/resources/dist/build/manifest.json @@ -9,7 +9,7 @@ "isEntry": true }, "resources/js/cp.js": { - "file": "assets/cp-7pjkSVYi.js", + "file": "assets/cp-CtqImns9.js", "name": "cp", "src": "resources/js/cp.js", "isEntry": true diff --git a/resources/js/editor/fieldActions.js b/resources/js/editor/fieldActions.js index 621f0a4..0515a9f 100644 --- a/resources/js/editor/fieldActions.js +++ b/resources/js/editor/fieldActions.js @@ -1,7 +1,7 @@ import { asMap } from '../api.js'; import { CORE_CLOSE_MS } from '../modal.js'; import { isTermReference } from './banner.js'; -import { BASE, registry as sharedRegistry } from './registry.js'; +import { BASE, registry as sharedRegistry, sameText, textsOf } from './registry.js'; import { describeSummary, needsSetup } from './statuses.js'; import { useEditorStore } from './store.js'; import { BUSY, savingMessage, translations as sharedTranslations } from './translate.js'; @@ -28,8 +28,9 @@ function sameValue(a, b) { return keys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && sameValue(a[key], b[key])); } -// "Translate from origin" on the top-level fields of a localization's own form (§A13 2). Core registers field actions -// per fieldtype, so the action also renders in stacked editors, global sets and the addon's settings form. +// "Translate from origin", a button in the header of the top-level fields of a localization's own form (§A13 2). Core +// registers field actions per fieldtype, so the action also renders in stacked editors, global sets and the addon's +// settings form. export function createFieldActions({ registry = sharedRegistry, store = useEditorStore, @@ -44,9 +45,9 @@ export function createFieldActions({ } = {}) { let registered = false; - // Evaluated inside core's cached computed, so everything it reads is reactive: the registry's containers, the - // store's status and phase. A `text` field's payload does not say which form it belongs to (R3 §3.3), so while any - // container other than `base` is mounted the action shows nowhere. + // Evaluated inside core's cached computed, so everything it reads is reactive: the registry's containers and the + // store's status. A `text` field's payload does not say which form it belongs to (R3 §3.3), so while any container + // other than `base` is mounted the action shows nowhere. function visible({ vm, fieldPathPrefix, handle, config: field, isReadOnly }) { if (fieldPathPrefix || isReadOnly || !field?.localizable || !permissions().has('translate content')) { return false; @@ -69,13 +70,25 @@ export function createFieldActions({ return ( !needsSetup(status) && - !BUSY.includes(container.phase) && Object.hasOwn(ctx.originValues?.value ?? {}, handle) && Boolean(inScope) && inScope.status !== 'not_applicable' ); } + // Read while core renders the button, so the store's phase is reactive here too. + function disabled() { + return BUSY.includes(store().containers[BASE]?.phase); + } + + // Whether the translation could replace text the editor would miss: the field has text, and not the origin's, which + // an untranslated field shows. + function replacesText({ handle, value }) { + const origin = registry.base()?.originValues?.value ?? {}; + + return textsOf(value) !== null && !sameText(value, origin[handle]); + } + // The field is replaced even when the editor typed into it, so it is not sent as an unsaved edit to skip. async function translateField({ handle, value }) { const ctx = registry.base(); @@ -125,11 +138,12 @@ export function createFieldActions({ } } - // The field's actions menu: core's dropdown trigger in the header of the field its label names. + // The action's button in the header of the field its label names, which core labels with the action's title. function trigger(handle) { const label = [...(doc()?.querySelectorAll('label[for]') ?? [])].find((element) => element.getAttribute('for') === `field_${handle}`); + const header = label?.closest('[data-ui-input-group]')?.querySelector('[data-ui-field-header]'); - return label?.closest('[data-ui-input-group]')?.querySelector('[data-ui-field-header] [data-ui-dropdown-trigger]') ?? null; + return [...(header?.querySelectorAll('button[aria-label]') ?? [])].find((button) => button.getAttribute('aria-label') === title()) ?? null; } // The banner shows the progress, and keeps the focus on its Cancel while the translation runs. @@ -152,16 +166,28 @@ export function createFieldActions({ } } + // The button is disabled while the translation runs, which drops its focus, and the confirmation leaves the focus + // on the page's body: either way it goes to the banner. + function start(payload) { + translateField(payload).catch(() => toast().error(__('Something went wrong.'))); + moveFocus(() => progress() ?? trigger(payload.handle)); + } + // Not async: core reads a returned promise from `payload.vm`, which composition-API fieldtypes such as `text` do - // not have (R3 §3.4). Progress shows in the banner. The action asks first itself: core's confirmation leaves the - // focus on the page's body when it closes. + // not have (R3 §3.4). Progress shows in the banner. The action asks first itself, and only before it replaces text: + // core's confirmation leaves the focus on the page's body when it closes. function run(payload) { + if (!replacesText(payload)) { + start(payload); + + return; + } + const confirmation = components().append(CONFIRM, { props: {} }); confirmation.on('confirm', () => { confirmation.destroy(); - translateField(payload).catch(() => toast().error(__('Something went wrong.'))); - moveFocus(() => progress() ?? trigger(payload.handle)); + start(payload); }); confirmation.on('cancel', () => { confirmation.destroy(); @@ -169,11 +195,18 @@ export function createFieldActions({ }); } + function title() { + return __('Translate from origin'); + } + const action = { get title() { - return __('Translate from origin'); + return title(); }, + quick: true, + icon: 'dictionary-language-book', visible, + disabled, run, }; @@ -189,7 +222,7 @@ export function createFieldActions({ } } - return { register, action, visible, run }; + return { register, action, visible, disabled, run }; } export const fieldActions = createFieldActions(); diff --git a/resources/js/editor/fieldActions.test.js b/resources/js/editor/fieldActions.test.js index a0d970f..a4de96c 100644 --- a/resources/js/editor/fieldActions.test.js +++ b/resources/js/editor/fieldActions.test.js @@ -62,14 +62,17 @@ const status = (fields = {}, extra = {}) => ({ const values = () => ({ title: 'Startseite', intro: 'A family-run hotel.', content: '[{"type":"paragraph"}]', empty: null, css_class: 'hero' }); +// The English origin's: the German title is a translation, the other fields are not translated yet. +const originValues = () => ({ ...values(), title: 'Home' }); + // The German home page's base container, created and attached as the banner attaches it, with its status loaded. -function mount({ reference = 'entry::de', loaded = status(), readOnly = false, originValues = values() } = {}) { +function mount({ reference = 'entry::de', loaded = status(), readOnly = false, origin = originValues() } = {}) { const ctx = { name: ref('base'), reference: ref(reference), site: ref('de'), values: ref(values()), - originValues: ref(originValues), + originValues: ref(origin), meta: ref({}), localizedFields: ref(['title']), readOnly: ref(readOnly), @@ -138,7 +141,8 @@ function fakeComponents(answer = 'confirm') { }; } -// The page as far as the focus goes: the title field, whose header holds its actions menu, and the banner. +// The page as far as the focus goes: the title field, whose header holds the action's button next to another of core's, +// and the banner. function page() { const doc = { body: { name: 'body' }, activeElement: null }; const element = (name, find = {}) => ({ @@ -150,9 +154,17 @@ function page() { querySelector(selector) { return this.find[selector] ?? null; }, + querySelectorAll(selector) { + return this.find[`all ${selector}`] ?? []; + }, + getAttribute(name) { + return this.find[`@${name}`] ?? null; + }, }); - const menu = element('actions menu'); - const field = element('title field', { '[data-ui-field-header] [data-ui-dropdown-trigger]': menu }); + const button = element('action button', { '@aria-label': 'Translate from origin' }); + const fullscreen = element('fullscreen button', { '@aria-label': 'Toggle Fullscreen Mode' }); + const header = element('title header', { 'all button[aria-label]': [fullscreen, button] }); + const field = element('title field', { '[data-ui-field-header]': header }); const label = (target, group = null) => ({ getAttribute: () => target, closest: (selector) => (selector === '[data-ui-input-group]' ? group : null) }); const planning = element('planning'); const cancel = element('cancel'); @@ -162,7 +174,7 @@ function page() { doc.querySelector = (selector) => (selector === '[data-tolk-banner]' ? banner : null); doc.activeElement = doc.body; - return { doc, menu, banner, planning, cancel }; + return { doc, button, banner, planning, cancel }; } function actions(overrides = {}) { @@ -199,13 +211,14 @@ describe('register', () => { }); // Core's confirmation leaves the focus on the page's body when it closes; the action asks itself. - it('is titled, and asks for confirmation itself', () => { + it('is a titled button with the addon\'s icon, and asks for confirmation itself', () => { const { action } = actions(); expect(action.title).toBe('Translate from origin'); + expect(action.quick).toBe(true); + expect(action.icon).toBe('dictionary-language-book'); expect(action.confirm).toBeUndefined(); expect(action.visibleWhenReadOnly).toBeUndefined(); - expect(action.quick).toBeUndefined(); }); }); @@ -291,7 +304,7 @@ describe('visible', () => { }); it('needs the field in scope, in the origin and with text there', () => { - mount({ originValues: { ...values(), intro: undefined } }); + mount({ origin: { ...originValues(), intro: undefined } }); delete registry.base().originValues.value.intro; const { visible } = actions(); @@ -301,17 +314,23 @@ describe('visible', () => { expect(visible(payload('title'))).toBe(true); }); - it('does not show while a translation is under way', () => { + // Unlike a dropdown item, a quick action's button honours `disabled`, so the field's header keeps its buttons. + it('stays, disabled, while a translation is under way', () => { mount(); - const { visible } = actions(); + const { visible, disabled } = actions(); - for (const [phase, shown] of [['planning', false], ['working', false], ['offer', true], ['done', true], ['error', true], ['idle', true]]) { + for (const [phase, busy] of [['planning', true], ['working', true], ['offer', false], ['done', false], ['error', false], ['idle', false]]) { store.setPhase('base', phase); - expect(visible(payload())).toBe(shown); + expect(visible(payload())).toBe(true); + expect(disabled(payload())).toBe(busy); } }); - it('is re-evaluated by a computed when a stack opens, the status arrives or the phase changes', async () => { + it('is enabled without a base form', () => { + expect(actions().disabled(payload())).toBe(false); + }); + + it('is re-evaluated by a computed when a stack opens or the status arrives, and disabled when the phase changes', async () => { mount({ loaded: null }); const { visible } = actions(); const shown = computed(() => visible(payload())); @@ -328,8 +347,17 @@ describe('visible', () => { events['publish-container-destroyed']({ name: 'relate-fieldtype-inline-7' }); expect(shown.value).toBe(true); + const { disabled } = actions(); + const off = computed(() => disabled(payload())); + + expect(off.value).toBe(false); + store.setPhase('base', 'working'); - expect(shown.value).toBe(false); + expect(shown.value).toBe(true); + expect(off.value).toBe(true); + + store.setPhase('base', 'done'); + expect(off.value).toBe(false); }); }); @@ -366,10 +394,79 @@ describe('run', () => { expect(translations.translate).toHaveBeenCalledOnce(); }); - it('translates nothing on Cancel or Esc, and gives the focus back to the field\'s actions menu', async () => { + it('translates at once, without asking, a field without text or with the origin\'s', async () => { + const ctx = mount(); + const translations = fakeTranslations(); + const { run } = actions({ translations }); + + // Bard's value of an empty field: a paragraph without text. + ctx.values.value.title = ''; + ctx.values.value.content = [{ type: 'paragraph', attrs: { textAlign: null } }]; + run(payload('title', { value: '' })); + run(payload('content', { value: [{ type: 'paragraph', attrs: { textAlign: null } }] })); + await flush(); + ctx.values.value.title = null; + run(payload('title', { value: null })); + await flush(); + // An untranslated field shows the origin's text. + run(payload('intro')); + await flush(); + + expect(confirmations.append).not.toHaveBeenCalled(); + expect(translations.translate.mock.calls.map(([, { fields }]) => fields)).toEqual([['title'], ['content'], ['title'], ['intro']]); + }); + + it('asks first before it replaces text of the localization\'s own, typed text included', async () => { + const ctx = mount(); + const translations = fakeTranslations(); + confirmations = fakeComponents(null); + const { run } = actions({ translations }); + + run(payload('title')); + ctx.values.value.intro = 'Ein Familienhotel.'; + run(payload('intro', { value: 'Ein Familienhotel.' })); + await flush(); + + expect(confirmations.appended.map(({ name }) => name)).toEqual([CONFIRM, CONFIRM]); + expect(translations.translate).not.toHaveBeenCalled(); + }); + + it('asks first when the base form has gone, and then reports it', async () => { + const translations = fakeTranslations(); + const { run } = actions({ translations }); + + run(payload('intro')); + await flush(); + + expect(confirmations.append).toHaveBeenCalledOnce(); + expect(translations.translate).not.toHaveBeenCalled(); + expect(toast.error).toHaveBeenCalledExactlyOnceWith('This field is not part of the entry being translated.'); + }); + + it('moves a focus the disabled button lost into the banner after a translation that did not ask', async () => { + mount(); + const { doc, button, planning } = page(); + const wait = vi.fn(); + + doc.activeElement = button; + actions({ doc: () => doc, wait }).run(payload('intro')); + await flush(); + + expect(wait.mock.calls.map(([, delay]) => delay)).toEqual([0, 400]); + + // A browser that keeps the focus on the disabled button. + wait.mock.calls[0][0](); + expect(doc.activeElement).toBe(button); + + doc.activeElement = doc.body; + wait.mock.calls[1][0](); + expect(doc.activeElement).toBe(planning); + }); + + it('translates nothing on Cancel or Esc, and gives the focus back to the action\'s button', async () => { mount(); const translations = fakeTranslations(); - const { doc, menu } = page(); + const { doc, button } = page(); const wait = vi.fn(); confirmations = fakeComponents('cancel'); @@ -381,7 +478,7 @@ describe('run', () => { wait.mock.calls[0][0](); - expect(doc.activeElement).toBe(menu); + expect(doc.activeElement).toBe(button); expect(translations.translate).not.toHaveBeenCalled(); }); @@ -406,7 +503,7 @@ describe('run', () => { it('leaves a focus that is somewhere once the confirmation has closed', async () => { mount(); - const { doc, menu } = page(); + const { doc, button } = page(); const wait = vi.fn(); confirmations = fakeComponents('cancel'); @@ -417,7 +514,7 @@ describe('run', () => { wait.mock.calls.forEach(([callback]) => callback()); expect(doc.activeElement).toBe(field); - expect(doc.activeElement).not.toBe(menu); + expect(doc.activeElement).not.toBe(button); }); it('does nothing but report it when the value is not the base form\'s', async () => { diff --git a/tests/Browser/field-action.spec.js b/tests/Browser/field-action.spec.js index 9e54c1b..f8355af 100644 --- a/tests/Browser/field-action.spec.js +++ b/tests/Browser/field-action.spec.js @@ -20,49 +20,29 @@ test.afterAll(() => { reset(); }); -// The header of a field: its label and its actions. `scope` is the page's own form (`main`) or a stack. +// The header of a field: its label and its buttons. `scope` is the page's own form (`main`) or a stack. const header = (scope, selector) => scope.locator(`[data-ui-field-header]:has(label${selector})`); -const dropdown = (scope, selector) => header(scope, selector).getByRole('button', { name: 'Open dropdown menu' }); +const button = (scope, selector) => header(scope, selector).getByRole('button', { name: TITLE, exact: true }); -// The titles in a field's action dropdown; none when the field has no dropdown. -async function actionTitles(page, scope, selector) { - await expect(header(scope, selector)).toBeVisible(); - - if ((await dropdown(scope, selector).count()) === 0) { - return []; - } - - await dropdown(scope, selector).click(); - - const menu = page.getByRole('menu'); - - await expect(menu).toBeVisible(); - - const titles = await menu.getByRole('menuitem').allTextContents(); - - await page.keyboard.press('Escape'); - await expect(menu).toHaveCount(0); - - return titles; -} - -async function expectAction(page, scope, selector) { - await expect(dropdown(scope, selector)).toBeVisible(); - expect(await actionTitles(page, scope, selector)).toContain(TITLE); +async function expectAction(scope, selector) { + await expect(button(scope, selector)).toBeVisible(); } -async function expectNoAction(page, scope, selector) { - expect(await actionTitles(page, scope, selector)).not.toContain(TITLE); +async function expectNoAction(scope, selector) { + await expect(header(scope, selector)).toBeVisible(); + await expect(button(scope, selector)).toHaveCount(0); } -async function runAction(page, selector) { - await dropdown(page.locator('main'), selector).click(); - await page.getByRole('menu').getByRole('menuitem', { name: TITLE }).click(); +// Presses the field's button and, with `confirm`, answers the confirmation it asks first with. +async function runAction(page, selector, { confirm = false } = {}) { + await button(page.locator('main'), selector).click(); - const modal = page.getByRole('dialog'); + if (confirm) { + const modal = page.getByRole('dialog'); - await expect(modal).toContainText('The current content of this field will be replaced.'); - await modal.getByRole('button', { name: 'Translate' }).click(); + await expect(modal).toContainText('The current content of this field will be replaced.'); + await modal.getByRole('button', { name: 'Translate' }).click(); + } } test('shows on the localizable text, Bard and Replicator fields of a localization only', async ({ page, browserErrors }) => { @@ -72,12 +52,12 @@ test('shows on the localizable text, Bard and Replicator fields of a localizatio await openEntry(page, 'pages', 'home', 'de'); await expect(banner(page).locator('[data-tolk-part="untranslated"]')).toBeVisible(); - await expectAction(page, main, '[for="field_title"]'); - await expectAction(page, main, '[for="field_intro"]'); - await expectAction(page, main, '[for="field_content"]'); - await expectNoAction(page, main, '[for^="field_content_"][for$="_attrs_values_text"]'); - await expectNoAction(page, main, '[for^="field_content_"][for$="_attrs_values_author"]'); - await expectNoAction(page, main, '[for="field_css_class"]'); + await expectAction(main, '[for="field_title"]'); + await expectAction(main, '[for="field_intro"]'); + await expectAction(main, '[for="field_content"]'); + await expectNoAction(main, '[for^="field_content_"][for$="_attrs_values_text"]'); + await expectNoAction(main, '[for^="field_content_"][for$="_attrs_values_author"]'); + await expectNoAction(main, '[for="field_css_class"]'); // A Greek article: the Replicator body, the heading of its text set, the set's Bard field, whose handle `body` is also // the Replicator's, and a text field that is not localizable. @@ -85,23 +65,24 @@ test('shows on the localizable text, Bard and Replicator fields of a localizatio await openEntry(page, 'articles', ARTICLE, 'el'); await expect(banner(page).locator('[data-tolk-part="untranslated"]')).toBeVisible(); - await expectAction(page, main, '[for="field_title"]'); - await expectAction(page, main, '[for="field_body"]'); - await expectNoAction(page, main, '[for="field_body_0_heading"]'); - await expectNoAction(page, main, '[for="field_body_0_body"]'); - await expectNoAction(page, main, '[for="field_internal_note"]'); + await expectAction(main, '[for="field_title"]'); + await expectAction(main, '[for="field_body"]'); + await expectNoAction(main, '[for="field_body_0_heading"]'); + await expectNoAction(main, '[for="field_body_0_body"]'); + await expectNoAction(main, '[for="field_internal_note"]'); // The English origin of the home page. await openEntry(page, 'pages', 'home', 'en'); await expect(banner(page).locator('[data-tolk-origin]')).toBeVisible(); - await expectNoAction(page, main, '[for="field_title"]'); - await expectNoAction(page, main, '[for="field_intro"]'); - await expectNoAction(page, main, '[for="field_content"]'); + await expectNoAction(main, '[for="field_title"]'); + await expectNoAction(main, '[for="field_intro"]'); + await expectNoAction(main, '[for="field_content"]'); expect(browserErrors()).toEqual([]); }); -test('running it replaces only that field, typed text included, and leaves the form unsaved', async ({ page, browserErrors }) => { +test('running it replaces only that field, typed text included, asks first only then, and leaves the form unsaved', async ({ page, browserErrors }) => { + const main = page.locator('main'); const origin = entryFile('pages', 'en', 'home'); const before = entryFile('pages', 'de', 'home'); @@ -122,23 +103,33 @@ test('running it replaces only that field, typed text included, and leaves the f }); const planned = page.waitForRequest((request) => request.url().includes('/tolk/editor/plan')); - await runAction(page, '[for="field_title"]'); + await runAction(page, '[for="field_title"]', { confirm: true }); const plan = (await planned).postDataJSON(); expect(plan).toMatchObject({ mode: 'all', fields: ['title'], overwrite_manual: true }); expect(plan.skip).not.toContain('title'); await expect(banner(page).locator('[data-tolk-working-field]')).toHaveText('Translating Title into German…'); + + // The buttons stay in their headers while the translation runs, disabled. + await expect(button(main, '[for="field_title"]')).toBeDisabled(); + await expect(button(main, '[for="field_content"]')).toBeDisabled(); release(); await expect(banner(page).locator('[data-tolk-summary-translated]')).toHaveText(/^1 field translated with .+\.$/); + await expect(button(main, '[for="field_content"]')).toBeEnabled(); await expect(page.locator('#field_title')).toHaveValue(`[de] ${origin.title}`); await expect(page.locator('#field_intro')).toHaveValue(origin.intro); await expect(page.locator('#field_content .ProseMirror h2')).toHaveText('Welcome to Kyma Bay'); - // The Bard field next: the title keeps its translation. + // The Bard field next, untranslated, so it shows the origin's text: no confirmation, and the focus the disabled button + // lost goes to the banner. The title keeps its translation. + const direct = page.waitForRequest((request) => request.url().includes('/tolk/editor/plan')); await runAction(page, '[for="field_content"]'); + expect((await direct).postDataJSON()).toMatchObject({ fields: ['content'] }); + await expect(page.getByRole('dialog')).toHaveCount(0); await expect(page.locator('#field_content .ProseMirror h2')).toHaveText('[de] Welcome to Kyma Bay'); + await expect.poll(() => page.evaluate(() => Boolean(document.activeElement?.closest('[data-tolk-banner]')))).toBe(true); await expect(page.locator('#field_title')).toHaveValue(`[de] ${origin.title}`); await expect(page.locator('#field_intro')).toHaveValue(origin.intro); @@ -166,18 +157,18 @@ test('with a related entry open in a stack, the stacked form\'s fields have no a await openEntry(page, 'pages', 'home', 'de'); await expect(banner(page).locator('[data-tolk-part="untranslated"]')).toBeVisible(); - await expectAction(page, main, '[for="field_title"]'); + await expectAction(main, '[for="field_title"]'); await main.locator('.entries-fieldtype').getByRole('link', { name: about.title }).click(); await expect(stack.locator('#field_title')).toHaveValue(about.title); - await expectNoAction(page, stack, '[for="field_title"]'); - await expectNoAction(page, stack, '[for="field_intro"]'); - await expectNoAction(page, stack, '[for="field_content"]'); + await expectNoAction(stack, '[for="field_title"]'); + await expectNoAction(stack, '[for="field_intro"]'); + await expectNoAction(stack, '[for="field_content"]'); // Closing the stack brings the action back to the page's own form. await page.keyboard.press('Escape'); await expect(stack).toHaveCount(0); - await expectAction(page, main, '[for="field_title"]'); + await expectAction(main, '[for="field_title"]'); expect(browserErrors()).toEqual([]); });