ultimatehuman 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -4
- package/dist/cli.mjs +1085 -631
- package/dist/dashboard/assets/ConversationWorkspace-C_HyzEg6.js +16 -0
- package/dist/dashboard/assets/{ConversationWorkspace-De5tnYl0.css → ConversationWorkspace-DPeUP7L6.css} +1 -1
- package/dist/dashboard/assets/{data-provider-CZ2WwK6_.js → data-provider-TNBGds5H.js} +1 -1
- package/dist/dashboard/assets/{index-pC0URNNS.js → index-C7UNg0WM.js} +2 -2
- package/dist/dashboard/assets/{page-CYCU6xk1.js → page-C_4oHSxK.js} +1 -1
- package/dist/dashboard/index.html +1 -1
- package/package.json +3 -2
- package/dist/dashboard/assets/ConversationWorkspace-6m6xkkC1.js +0 -16
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r,j as t}from"./fmt-BRV4RZz4.js";import{PlatformClaim as Xa,PipelineTicket as Ja,PipelineBundles as Va}from"./data-provider-CZ2WwK6_.js";import{F as pe,a as fe,b as Pn,L as Ya}from"./ConversationWorkspace-6m6xkkC1.js";import{r as Bn}from"./index-CIpIMh38.js";import"./index-pC0URNNS.js";function Ka({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M10 3.75a2 2 0 1 0-4 0 2 2 0 0 0 4 0ZM17.25 4.5a.75.75 0 0 0 0-1.5h-5.5a.75.75 0 0 0 0 1.5h5.5ZM5 3.75a.75.75 0 0 1-.75.75h-1.5a.75.75 0 0 1 0-1.5h1.5a.75.75 0 0 1 .75.75ZM4.25 17a.75.75 0 0 0 0-1.5h-1.5a.75.75 0 0 0 0 1.5h1.5ZM17.25 17a.75.75 0 0 0 0-1.5h-5.5a.75.75 0 0 0 0 1.5h5.5ZM9 10a.75.75 0 0 1-.75.75h-5.5a.75.75 0 0 1 0-1.5h5.5A.75.75 0 0 1 9 10ZM17.25 10.75a.75.75 0 0 0 0-1.5h-1.5a.75.75 0 0 0 0 1.5h1.5ZM14 10a2 2 0 1 0-4 0 2 2 0 0 0 4 0ZM10 16.25a2 2 0 1 0-4 0 2 2 0 0 0 4 0Z"}))}const Ua=r.forwardRef(Ka);function Qa({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M15.312 11.424a5.5 5.5 0 0 1-9.201 2.466l-.312-.311h2.433a.75.75 0 0 0 0-1.5H3.989a.75.75 0 0 0-.75.75v4.242a.75.75 0 0 0 1.5 0v-2.43l.31.31a7 7 0 0 0 11.712-3.138.75.75 0 0 0-1.449-.39Zm1.23-3.723a.75.75 0 0 0 .219-.53V2.929a.75.75 0 0 0-1.5 0V5.36l-.31-.31A7 7 0 0 0 3.239 8.188a.75.75 0 1 0 1.448.389A5.5 5.5 0 0 1 13.89 6.11l.311.31h-2.432a.75.75 0 0 0 0 1.5h4.243a.75.75 0 0 0 .53-.219Z",clipRule:"evenodd"}))}const On=r.forwardRef(Qa);function es({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M4.25 5.5a.75.75 0 0 0-.75.75v8.5c0 .414.336.75.75.75h8.5a.75.75 0 0 0 .75-.75v-4a.75.75 0 0 1 1.5 0v4A2.25 2.25 0 0 1 12.75 17h-8.5A2.25 2.25 0 0 1 2 14.75v-8.5A2.25 2.25 0 0 1 4.25 4h5a.75.75 0 0 1 0 1.5h-5Z",clipRule:"evenodd"}),r.createElement("path",{fillRule:"evenodd",d:"M6.194 12.753a.75.75 0 0 0 1.06.053L16.5 4.44v2.81a.75.75 0 0 0 1.5 0v-4.5a.75.75 0 0 0-.75-.75h-4.5a.75.75 0 0 0 0 1.5h2.553l-9.056 8.194a.75.75 0 0 0-.053 1.06Z",clipRule:"evenodd"}))}const Le=r.forwardRef(es);function ts({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 17a.75.75 0 0 1-.75-.75V5.612L5.29 9.77a.75.75 0 0 1-1.08-1.04l5.25-5.5a.75.75 0 0 1 1.08 0l5.25 5.5a.75.75 0 1 1-1.08 1.04l-3.96-4.158V16.25A.75.75 0 0 1 10 17Z",clipRule:"evenodd"}))}const ns=r.forwardRef(ts);function as({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M7.793 2.232a.75.75 0 0 1-.025 1.06L3.622 7.25h10.003a5.375 5.375 0 0 1 0 10.75H10.75a.75.75 0 0 1 0-1.5h2.875a3.875 3.875 0 0 0 0-7.75H3.622l4.146 3.957a.75.75 0 0 1-1.036 1.085l-5.5-5.25a.75.75 0 0 1 0-1.085l5.5-5.25a.75.75 0 0 1 1.06.025Z",clipRule:"evenodd"}))}const Ln=r.forwardRef(as);function ss({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M3.28 2.22a.75.75 0 0 0-1.06 1.06L5.44 6.5H2.75a.75.75 0 0 0 0 1.5h4.5A.75.75 0 0 0 8 7.25v-4.5a.75.75 0 0 0-1.5 0v2.69L3.28 2.22ZM13.5 2.75a.75.75 0 0 0-1.5 0v4.5c0 .414.336.75.75.75h4.5a.75.75 0 0 0 0-1.5h-2.69l3.22-3.22a.75.75 0 0 0-1.06-1.06L13.5 5.44V2.75ZM3.28 17.78l3.22-3.22v2.69a.75.75 0 0 0 1.5 0v-4.5a.75.75 0 0 0-.75-.75h-4.5a.75.75 0 0 0 0 1.5h2.69l-3.22 3.22a.75.75 0 1 0 1.06 1.06ZM13.5 14.56l3.22 3.22a.75.75 0 1 0 1.06-1.06l-3.22-3.22h2.69a.75.75 0 0 0 0-1.5h-4.5a.75.75 0 0 0-.75.75v4.5a.75.75 0 0 0 1.5 0v-2.69Z"}))}const st=r.forwardRef(ss);function rs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"m13.28 7.78 3.22-3.22v2.69a.75.75 0 0 0 1.5 0v-4.5a.75.75 0 0 0-.75-.75h-4.5a.75.75 0 0 0 0 1.5h2.69l-3.22 3.22a.75.75 0 0 0 1.06 1.06ZM2 17.25v-4.5a.75.75 0 0 1 1.5 0v2.69l3.22-3.22a.75.75 0 0 1 1.06 1.06L4.56 16.5h2.69a.75.75 0 0 1 0 1.5h-4.5a.747.747 0 0 1-.75-.75ZM12.22 13.28l3.22 3.22h-2.69a.75.75 0 0 0 0 1.5h4.5a.747.747 0 0 0 .75-.75v-4.5a.75.75 0 0 0-1.5 0v2.69l-3.22-3.22a.75.75 0 1 0-1.06 1.06ZM3.5 4.56l3.22 3.22a.75.75 0 0 0 1.06-1.06L4.56 3.5h2.69a.75.75 0 0 0 0-1.5h-4.5a.75.75 0 0 0-.75.75v4.5a.75.75 0 0 0 1.5 0V4.56Z"}))}const ls=r.forwardRef(rs);function is({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M13.2 2.24a.75.75 0 0 0 .04 1.06l2.1 1.95H6.75a.75.75 0 0 0 0 1.5h8.59l-2.1 1.95a.75.75 0 1 0 1.02 1.1l3.5-3.25a.75.75 0 0 0 0-1.1l-3.5-3.25a.75.75 0 0 0-1.06.04Zm-6.4 8a.75.75 0 0 0-1.06-.04l-3.5 3.25a.75.75 0 0 0 0 1.1l3.5 3.25a.75.75 0 1 0 1.02-1.1l-2.1-1.95h8.59a.75.75 0 0 0 0-1.5H4.66l2.1-1.95a.75.75 0 0 0 .04-1.06Z",clipRule:"evenodd"}))}const os=r.forwardRef(is);function ds({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M2.24 6.8a.75.75 0 0 0 1.06-.04l1.95-2.1v8.59a.75.75 0 0 0 1.5 0V4.66l1.95 2.1a.75.75 0 1 0 1.1-1.02l-3.25-3.5a.75.75 0 0 0-1.1 0L2.2 5.74a.75.75 0 0 0 .04 1.06Zm8 6.4a.75.75 0 0 0-.04 1.06l3.25 3.5a.75.75 0 0 0 1.1 0l3.25-3.5a.75.75 0 1 0-1.1-1.02l-1.95 2.1V6.75a.75.75 0 0 0-1.5 0v8.59l-1.95-2.1a.75.75 0 0 0-1.06-.04Z",clipRule:"evenodd"}))}const cs=r.forwardRef(ds);function us({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M8.5 3.528v4.644c0 .729-.29 1.428-.805 1.944l-1.217 1.216a8.75 8.75 0 0 1 3.55.621l.502.201a7.25 7.25 0 0 0 4.178.365l-2.403-2.403a2.75 2.75 0 0 1-.805-1.944V3.528a40.205 40.205 0 0 0-3 0Zm4.5.084.19.015a.75.75 0 1 0 .12-1.495 41.364 41.364 0 0 0-6.62 0 .75.75 0 0 0 .12 1.495L7 3.612v4.56c0 .331-.132.649-.366.883L2.6 13.09c-1.496 1.496-.817 4.15 1.403 4.475C5.961 17.852 7.963 18 10 18s4.039-.148 5.997-.436c2.22-.325 2.9-2.979 1.403-4.475l-4.034-4.034A1.25 1.25 0 0 1 13 8.172v-4.56Z",clipRule:"evenodd"}))}const Ie=r.forwardRef(us);function ms({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M11.983 1.907a.75.75 0 0 0-1.292-.657l-8.5 9.5A.75.75 0 0 0 2.75 12h6.572l-1.305 6.093a.75.75 0 0 0 1.292.657l8.5-9.5A.75.75 0 0 0 17.25 8h-6.572l1.305-6.093Z"}))}const Rt=r.forwardRef(ms);function xs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M3.505 2.365A41.369 41.369 0 0 1 9 2c1.863 0 3.697.124 5.495.365 1.247.167 2.18 1.108 2.435 2.268a4.45 4.45 0 0 0-.577-.069 43.141 43.141 0 0 0-4.706 0C9.229 4.696 7.5 6.727 7.5 8.998v2.24c0 1.413.67 2.735 1.76 3.562l-2.98 2.98A.75.75 0 0 1 5 17.25v-3.443c-.501-.048-1-.106-1.495-.172C2.033 13.438 1 12.162 1 10.72V5.28c0-1.441 1.033-2.717 2.505-2.914Z"}),r.createElement("path",{d:"M14 6c-.762 0-1.52.02-2.271.062C10.157 6.148 9 7.472 9 8.998v2.24c0 1.519 1.147 2.839 2.71 2.935.214.013.428.024.642.034.2.009.385.09.518.224l2.35 2.35a.75.75 0 0 0 1.28-.531v-2.07c1.453-.195 2.5-1.463 2.5-2.915V8.998c0-1.526-1.157-2.85-2.729-2.936A41.645 41.645 0 0 0 14 6Z"}))}const Fn=r.forwardRef(xs);function hs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm3.857-9.809a.75.75 0 0 0-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 1 0-1.06 1.061l2.5 2.5a.75.75 0 0 0 1.137-.089l4-5.5Z",clipRule:"evenodd"}))}const Ze=r.forwardRef(hs);function gs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z",clipRule:"evenodd"}))}const Dn=r.forwardRef(gs);function ps({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const qn=r.forwardRef(ps);function fs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M11.78 5.22a.75.75 0 0 1 0 1.06L8.06 10l3.72 3.72a.75.75 0 1 1-1.06 1.06l-4.25-4.25a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const In=r.forwardRef(fs);function bs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm.75-13a.75.75 0 0 0-1.5 0v5c0 .414.336.75.75.75h4a.75.75 0 0 0 0-1.5h-3.25V5Z",clipRule:"evenodd"}))}const Fe=r.forwardRef(bs);function ys({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M4.5 2A1.5 1.5 0 0 0 3 3.5v13A1.5 1.5 0 0 0 4.5 18h11a1.5 1.5 0 0 0 1.5-1.5V7.621a1.5 1.5 0 0 0-.44-1.06l-4.12-4.122A1.5 1.5 0 0 0 11.378 2H4.5Zm2.25 8.5a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5h-6.5Zm0 3a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5h-6.5Z",clipRule:"evenodd"}))}const ws=r.forwardRef(ys);function js({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495ZM10 5a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 10 5Zm0 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z",clipRule:"evenodd"}))}const ae=r.forwardRef(js);function vs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5Z"}),r.createElement("path",{fillRule:"evenodd",d:"M.664 10.59a1.651 1.651 0 0 1 0-1.186A10.004 10.004 0 0 1 10 3c4.257 0 7.893 2.66 9.336 6.41.147.381.146.804 0 1.186A10.004 10.004 0 0 1 10 17c-4.257 0-7.893-2.66-9.336-6.41ZM14 10a4 4 0 1 1-8 0 4 4 0 0 1 8 0Z",clipRule:"evenodd"}))}const Ns=r.forwardRef(vs);function ks({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M2.628 1.601C5.028 1.206 7.49 1 10 1s4.973.206 7.372.601a.75.75 0 0 1 .628.74v2.288a2.25 2.25 0 0 1-.659 1.59l-4.682 4.683a2.25 2.25 0 0 0-.659 1.59v3.037c0 .684-.31 1.33-.844 1.757l-1.937 1.55A.75.75 0 0 1 8 18.25v-5.757a2.25 2.25 0 0 0-.659-1.591L2.659 6.22A2.25 2.25 0 0 1 2 4.629V2.34a.75.75 0 0 1 .628-.74Z",clipRule:"evenodd"}))}const _s=r.forwardRef(ks);function Cs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 1a4.5 4.5 0 0 0-4.5 4.5V9H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2h-.5V5.5A4.5 4.5 0 0 0 10 1Zm3 8V5.5a3 3 0 1 0-6 0V9h6Z",clipRule:"evenodd"}))}const $s=r.forwardRef(Cs);function Es({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M6.75 8.25a.75.75 0 0 0 0 1.5h4.5a.75.75 0 0 0 0-1.5h-4.5Z"}),r.createElement("path",{fillRule:"evenodd",d:"M9 2a7 7 0 1 0 4.391 12.452l3.329 3.328a.75.75 0 1 0 1.06-1.06l-3.328-3.329A7 7 0 0 0 9 2ZM3.5 9a5.5 5.5 0 1 1 11 0 5.5 5.5 0 0 1-11 0Z",clipRule:"evenodd"}))}const Ss=r.forwardRef(Es);function Rs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M9 6a.75.75 0 0 1 .75.75v1.5h1.5a.75.75 0 0 1 0 1.5h-1.5v1.5a.75.75 0 0 1-1.5 0v-1.5h-1.5a.75.75 0 0 1 0-1.5h1.5v-1.5A.75.75 0 0 1 9 6Z"}),r.createElement("path",{fillRule:"evenodd",d:"M2 9a7 7 0 1 1 12.452 4.391l3.328 3.329a.75.75 0 1 1-1.06 1.06l-3.329-3.328A7 7 0 0 1 2 9Zm7-5.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11Z",clipRule:"evenodd"}))}const Ms=r.forwardRef(Rs);function Ts({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M9 3.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM2 9a7 7 0 1 1 12.452 4.391l3.328 3.329a.75.75 0 1 1-1.06 1.06l-3.329-3.328A7 7 0 0 1 2 9Z",clipRule:"evenodd"}))}const As=r.forwardRef(Ts);function Ps({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M5.75 3a.75.75 0 0 0-.75.75v12.5c0 .414.336.75.75.75h1.5a.75.75 0 0 0 .75-.75V3.75A.75.75 0 0 0 7.25 3h-1.5ZM12.75 3a.75.75 0 0 0-.75.75v12.5c0 .414.336.75.75.75h1.5a.75.75 0 0 0 .75-.75V3.75a.75.75 0 0 0-.75-.75h-1.5Z"}))}const Mt=r.forwardRef(Ps);function Bs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M1 5.25A2.25 2.25 0 0 1 3.25 3h13.5A2.25 2.25 0 0 1 19 5.25v9.5A2.25 2.25 0 0 1 16.75 17H3.25A2.25 2.25 0 0 1 1 14.75v-9.5Zm1.5 5.81v3.69c0 .414.336.75.75.75h13.5a.75.75 0 0 0 .75-.75v-2.69l-2.22-2.219a.75.75 0 0 0-1.06 0l-1.91 1.909.47.47a.75.75 0 1 1-1.06 1.06L6.53 8.091a.75.75 0 0 0-1.06 0l-2.97 2.97ZM12 7a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z",clipRule:"evenodd"}))}const Os=r.forwardRef(Bs);function Ls({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z"}))}const Fs=r.forwardRef(Ls);function Ds({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M5.127 3.502 5.25 3.5h9.5c.041 0 .082 0 .123.002A2.251 2.251 0 0 0 12.75 2h-5.5a2.25 2.25 0 0 0-2.123 1.502ZM1 10.25A2.25 2.25 0 0 1 3.25 8h13.5A2.25 2.25 0 0 1 19 10.25v5.5A2.25 2.25 0 0 1 16.75 18H3.25A2.25 2.25 0 0 1 1 15.75v-5.5ZM3.25 6.5c-.04 0-.082 0-.123.002A2.25 2.25 0 0 1 5.25 5h9.5c.98 0 1.814.627 2.123 1.502a3.819 3.819 0 0 0-.123-.002H3.25Z"}))}const Tt=r.forwardRef(Ds);function qs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 2a.75.75 0 0 1 .75.75v.258a33.186 33.186 0 0 1 6.668.83.75.75 0 0 1-.336 1.461 31.28 31.28 0 0 0-1.103-.232l1.702 7.545a.75.75 0 0 1-.387.832A4.981 4.981 0 0 1 15 14c-.825 0-1.606-.2-2.294-.556a.75.75 0 0 1-.387-.832l1.77-7.849a31.743 31.743 0 0 0-3.339-.254v11.505a20.01 20.01 0 0 1 3.78.501.75.75 0 1 1-.339 1.462A18.558 18.558 0 0 0 10 17.5c-1.442 0-2.845.165-4.191.477a.75.75 0 0 1-.338-1.462 20.01 20.01 0 0 1 3.779-.501V4.509c-1.129.026-2.243.112-3.34.254l1.771 7.85a.75.75 0 0 1-.387.83A4.98 4.98 0 0 1 5 14a4.98 4.98 0 0 1-2.294-.556.75.75 0 0 1-.387-.832L4.02 5.067c-.37.07-.738.148-1.103.232a.75.75 0 0 1-.336-1.462 32.845 32.845 0 0 1 6.668-.829V2.75A.75.75 0 0 1 10 2ZM5 7.543 3.92 12.33a3.499 3.499 0 0 0 2.16 0L5 7.543Zm10 0-1.08 4.787a3.498 3.498 0 0 0 2.16 0L15 7.543Z",clipRule:"evenodd"}))}const Is=r.forwardRef(qs);function Zs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M15.98 1.804a1 1 0 0 0-1.96 0l-.24 1.192a1 1 0 0 1-.784.785l-1.192.238a1 1 0 0 0 0 1.962l1.192.238a1 1 0 0 1 .785.785l.238 1.192a1 1 0 0 0 1.962 0l.238-1.192a1 1 0 0 1 .785-.785l1.192-.238a1 1 0 0 0 0-1.962l-1.192-.238a1 1 0 0 1-.785-.785l-.238-1.192ZM6.949 5.684a1 1 0 0 0-1.898 0l-.683 2.051a1 1 0 0 1-.633.633l-2.051.683a1 1 0 0 0 0 1.898l2.051.684a1 1 0 0 1 .633.632l.683 2.051a1 1 0 0 0 1.898 0l.683-2.051a1 1 0 0 1 .633-.633l2.051-.683a1 1 0 0 0 0-1.898l-2.051-.683a1 1 0 0 1-.633-.633L6.95 5.684ZM13.949 13.684a1 1 0 0 0-1.898 0l-.184.551a1 1 0 0 1-.632.633l-.551.183a1 1 0 0 0 0 1.898l.551.183a1 1 0 0 1 .633.633l.183.551a1 1 0 0 0 1.898 0l.184-.551a1 1 0 0 1 .632-.633l.551-.183a1 1 0 0 0 0-1.898l-.551-.184a1 1 0 0 1-.633-.632l-.183-.551Z"}))}const Zn=r.forwardRef(Zs);function Hs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M4.5 2A2.5 2.5 0 0 0 2 4.5v3.879a2.5 2.5 0 0 0 .732 1.767l7.5 7.5a2.5 2.5 0 0 0 3.536 0l3.878-3.878a2.5 2.5 0 0 0 0-3.536l-7.5-7.5A2.5 2.5 0 0 0 8.38 2H4.5ZM5 6a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z",clipRule:"evenodd"}))}const Ws=r.forwardRef(Hs);function zs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M14.5 10a4.5 4.5 0 0 0 4.284-5.882c-.105-.324-.51-.391-.752-.15L15.34 6.66a.454.454 0 0 1-.493.11 3.01 3.01 0 0 1-1.618-1.616.455.455 0 0 1 .11-.494l2.694-2.692c.24-.241.174-.647-.15-.752a4.5 4.5 0 0 0-5.873 4.575c.055.873-.128 1.808-.8 2.368l-7.23 6.024a2.724 2.724 0 1 0 3.837 3.837l6.024-7.23c.56-.672 1.495-.855 2.368-.8.096.007.193.01.291.01ZM5 16a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z",clipRule:"evenodd"}),r.createElement("path",{d:"M14.5 11.5c.173 0 .345-.007.514-.022l3.754 3.754a2.5 2.5 0 0 1-3.536 3.536l-4.41-4.41 2.172-2.607c.052-.063.147-.138.342-.196.202-.06.469-.087.777-.067.128.008.257.012.387.012ZM6 4.586l2.33 2.33a.452.452 0 0 1-.08.09L6.8 8.214 4.586 6H3.309a.5.5 0 0 1-.447-.276l-1.7-3.402a.5.5 0 0 1 .093-.577l.49-.49a.5.5 0 0 1 .577-.094l3.402 1.7A.5.5 0 0 1 6 3.31v1.277Z"}))}const ue=r.forwardRef(zs),_t="uh:navigate",Hn=e=>(window.addEventListener("popstate",e),window.addEventListener(_t,e),()=>{window.removeEventListener("popstate",e),window.removeEventListener(_t,e)}),Kt=e=>n=>{window.history[e](null,"",n),window.dispatchEvent(new Event(_t))},Gs={push:Kt("pushState"),replace:Kt("replaceState"),back:()=>window.history.back(),refresh:()=>window.location.reload(),prefetch:()=>{}};function Xs(){return Gs}function Js(){return r.useSyncExternalStore(Hn,()=>window.location.pathname)}function Wn(){const e=r.useSyncExternalStore(Hn,()=>window.location.search);return r.useMemo(()=>new URLSearchParams(e),[e])}function Vs(e){throw window.location.replace(e),new Error(`redirect to ${e}`)}async function Ys(){return{user:{isAdmin:!0,isSuperAdmin:!0}}}async function Ks(){}const Ut={magify_agents_api:0,magify_next:1},zn=10*1024*1024,Ve=5,Us={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},Gn=[{id:"waiting-response",label:"Waiting for response"},{id:"wait-conflict-fix",label:"Wait for conflict fix"},{id:"warning",label:"Warning"},{id:"priority",label:"Priority"},{id:"later",label:"Later"},{id:"watch-after-ship",label:"Watch after ship"}],Qs=40;function er(e,n){const a=new Set(n?.flags||[]);return(e||[]).filter(s=>{const l=(s.flags||[]).map(i=>i.id);return n?.only==="none"?l.length===0:n?.only==="flagged"&&!l.length?!1:!a.size||l.some(i=>a.has(i))})}function tr(e){const n={flagged:0,none:0};return(e||[]).forEach(a=>{const s=a.flags||[];s.length?n.flagged+=1:n.none+=1,s.forEach(l=>{n[l.id]=(n[l.id]||0)+1})}),n}const Ct=[{key:"default",label:"Default order"},{key:"created-desc",label:"Newest created",field:"jira_created",dir:-1},{key:"created-asc",label:"Oldest created",field:"jira_created",dir:1},{key:"updated-desc",label:"Recently updated",field:"jira_updated",dir:-1},{key:"updated-asc",label:"Least recently updated",field:"jira_updated",dir:1}],Qe=e=>Ct.find(n=>n.key===e)||Ct[0],Qt=e=>{const n=e?new Date(e).getTime():NaN;return Number.isNaN(n)?null:n};function Xn(e,n){const{field:a,dir:s}=Qe(n);return a?[...e].sort((l,i)=>{const o=Qt(l[a]),c=Qt(i[a]);return o===null||c===null?(o===null)-(c===null):(o-c)*s}):e}function rt(e){const n=(e||[]).filter(s=>s.kind!=="directive");let a=-1;return n.forEach((s,l)=>{if(s.role!=="assistant"||Ne(s))return;const i=s.reply_to?n.findIndex(o=>o.id===s.reply_to):-1;a=Math.max(a,i>=0?i:l)}),n.some((s,l)=>s.role==="vincent"&&l>a)}function He(e){return(e||[]).filter(n=>n.kind==="directive").sort((n,a)=>new Date(n.at)-new Date(a.at)).pop()||null}const nr=/^\s*Fix (delivered|failed):/;function Ne(e){return e?.role!=="assistant"||!e.reply_to?null:(nr.exec(e.text||"")||[])[1]||null}function At(e){const n=He(e?.chat);if(!n)return null;const a=(e.chat||[]).find(s=>s.reply_to===n.id&&Ne(s));return a?{kind:Ne(a),message:a,request:n}:null}function ar(e){const n=[...e||[]].sort((i,o)=>new Date(i.at)-new Date(o.at)),a=new Set(n.filter(i=>i.kind==="directive").map(i=>i.id)),s=n.filter(i=>a.has(i.reply_to)&&Ne(i)),l=[];for(const i of n)s.includes(i)||(l.push(i),i.kind==="directive"&&l.push(...s.filter(o=>o.reply_to===i.id)));return l}function me(e){const n=He(e?.chat);if(!n)return null;if(!n.acked_at)return n;if(n.ack_error||At(e))return null;if(e.fix_round?.request_id===n.id)return n;const a=e.synced_at?new Date(e.synced_at).getTime():0;return new Date(n.acked_at).getTime()>=a?n:null}function sr(e){const n=new Map(e.map(s=>[s.head,s])),a=(s,l=0)=>{const i=n.get(s.base);return i&&i!==s&&l<e.length?1+a(i,l+1):0};return[...e].sort((s,l)=>a(s)-a(l)||(Ut[s.repo]??9)-(Ut[l.repo]??9)||s.number-l.number)}function lt(e){const n=new Map(e.map(a=>[a.head,a]));return sr(e).map((a,s)=>{const l=n.get(a.base);return{pr:a,step:s+1,parent:l&&l!==a?l:null}})}function rr(e,n){if(!e)return null;const a=!e.input_hash||e.input_hash!==e.live_hash,s=new Set((e.dismissed||[]).filter(i=>i.input_hash===e.input_hash).map(i=>i.id)),l=a?[]:(e.groups||[]).filter(i=>!s.has(i.id)&&i.keys.every(o=>n.has(o)));return{stale:a,running:!!e.running,generated_at:e.generated_at||null,input_hash:e.input_hash,groups:l}}const lr="https://magifyfun.atlassian.net/browse/",ir=[{key:"open",label:"Needs ruling"},{key:"confirmed",label:"Confirmed"},{key:"wrong",label:"Wrong"},{key:"all",label:"All"}],en={TRUE:{label:"Pipeline: true",cls:"bg-emerald-50 text-emerald-700 ring-emerald-600/20"},FALSE:{label:"Pipeline: false",cls:"bg-red-50 text-red-700 ring-red-600/20"},"FOR-RULING":{label:"Pipeline: unsure",cls:"bg-amber-50 text-amber-800 ring-amber-600/25"}},or=new Set(["done","terminé","closed","resolved","validé sur test"]),je=e=>e.vincent_ruling?.status||null,tn=e=>parseInt(e.claim_id.replace(/\D/g,""),10)||0;function $t(e){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function Jn(e,n){const a=new Map;return(e||[]).forEach(s=>{const l=n?.[s.key],i=l||s.key,o=a.get(i)||{key:i,status:l?null:s.status,merged_from:[]};l?o.merged_from.push(s.key):o.status=s.status,a.set(i,o)}),[...a.values()]}function Vn({ticket:e}){const n=or.has((e.status||"").toLowerCase());return t.jsxs("a",{href:lr+e.key,target:"_blank",rel:"noopener noreferrer","data-ticket":e.key,"data-merged-from":e.merged_from?.length?e.merged_from.join(","):void 0,title:e.merged_from?.length?`Merged from ${e.merged_from.join(", ")}`:void 0,className:`inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs font-medium transition-colors ${n?"border-gray-200 bg-gray-50 text-gray-500 hover:bg-gray-100":"border-indigo-200 bg-indigo-50 text-indigo-700 hover:bg-indigo-100"}`,children:[t.jsx("span",{className:"font-mono",children:e.key}),e.status&&t.jsxs("span",{className:n?"text-gray-400":"text-indigo-500",children:["· ",e.status]}),e.merged_from?.length>0&&t.jsxs("span",{className:n?"text-gray-400":"text-indigo-500",children:["· merged from ",e.merged_from.join(", ")]})]})}const dr=e=>!!e&&["situation","quote","platform_truth","stakes"].some(n=>e[n]);function yt({label:e,children:n}){return t.jsxs("div",{children:[t.jsx("h3",{className:"text-xs font-semibold text-gray-500",children:e}),t.jsx("p",{className:"mt-1 whitespace-pre-line",children:n})]})}function cr({id:e,context:n}){return t.jsxs("div",{id:e,"data-claim-context":!0,className:"mt-3 space-y-3.5 rounded-lg bg-gray-50 px-3 py-3 text-sm leading-relaxed text-gray-700 [overflow-wrap:anywhere] sm:px-4",children:[n.situation&&t.jsx(yt,{label:"Situation",children:n.situation}),n.quote&&t.jsxs("blockquote",{className:"border-l-2 border-indigo-300 pl-3 text-[15px] italic text-gray-900",children:["“",n.quote,"”"]}),n.platform_truth&&t.jsx(yt,{label:"What the platform really does",children:n.platform_truth}),n.stakes&&t.jsx(yt,{label:"What your ruling decides",children:n.stakes})]})}function ur({request:e,mergedInto:n}){return t.jsxs("div",{"data-build-request":!0,className:"mt-4 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2.5 text-sm text-amber-950",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1.5",children:[t.jsxs("p",{className:"inline-flex items-center gap-1.5 font-medium",children:[t.jsx(ue,{className:"h-4 w-4 text-amber-600","aria-hidden":!0}),"Build requested",t.jsxs("span",{className:"font-normal opacity-70",children:["· ",$t(e.requested_at)]})]}),e.ticket?.key?t.jsx(Vn,{ticket:Jn([e.ticket],n)[0]}):t.jsx("span",{className:"text-xs text-amber-800/80",children:"Ticket filed on the next sync"})]}),t.jsx("p",{className:"mt-1.5 whitespace-pre-line [overflow-wrap:anywhere]",children:e.text})]})}function nn({disabled:e,onClick:n}){return t.jsxs("button",{type:"button",disabled:e,onClick:n,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg border border-amber-300 bg-amber-50 px-4 text-sm font-semibold text-amber-900 hover:bg-amber-100 focus:outline-none focus:ring-2 focus:ring-amber-500 focus:ring-offset-2 disabled:opacity-50",children:[t.jsx(ue,{className:"h-4 w-4 text-amber-600","aria-hidden":!0}),"Build this"]})}function mr({claim:e,onRule:n,onBuild:a,mergedInto:s}){const l=je(e),i=e.build_request?.requested_at?e.build_request:null,o=!i&&l!=="wrong",[c,d]=r.useState("idle"),[m,p]=r.useState(e.vincent_ruling?.correction||""),[u,g]=r.useState(""),[h,$]=r.useState(!1),[N,b]=r.useState(null),[f,x]=r.useState(!1),j=dr(e.context),S=`context-${e.claim_id}`,B=en[e.verdict]||en["FOR-RULING"],k=!l||c==="editing",E=async A=>{if(A==="wrong"&&!m.trim()){b("Write what is actually true before saving.");return}$(!0),b(null);try{await n(e.claim_id,A,A==="wrong"?m.trim():""),d("idle")}catch(M){b(M.message)}finally{$(!1)}},R=async()=>{if(!u.trim()){b("Describe what should exist before saving.");return}$(!0),b(null);try{await a(e.claim_id,u.trim()),d("idle")}catch(A){b(A.message)}finally{$(!1)}},F=l==="wrong"?"border-red-200":l==="confirmed"?"border-emerald-200":"border-gray-200";return t.jsxs("article",{"data-claim":e.claim_id,className:`rounded-xl border bg-white p-4 shadow-sm sm:p-5 ${F}`,children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1.5 text-xs",children:[t.jsx("span",{className:"font-mono font-semibold text-gray-500",children:e.claim_id}),t.jsx("span",{className:"text-gray-300","aria-hidden":!0,children:"·"}),t.jsx("span",{className:"font-medium text-gray-700",children:e.topic}),t.jsx("span",{className:`ml-auto inline-flex items-center rounded-full px-2 py-0.5 font-medium ring-1 ring-inset ${B.cls}`,children:B.label})]}),t.jsx("p",{className:"mt-3 text-[15px] leading-relaxed text-gray-900",children:e.canonical_claim}),t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[t.jsxs("p",{className:"text-xs text-gray-400",children:["Said ",e.occurrences," ",e.occurrences===1?"time":"times",e.first_seen?` · first on ${$t(e.first_seen)}`:""]}),j&&t.jsxs("button",{type:"button","aria-expanded":f,"aria-controls":S,onClick:()=>x(A=>!A),className:"-my-2 inline-flex shrink-0 items-center gap-0.5 rounded-md py-2 pl-2 text-xs font-medium text-indigo-600 hover:text-indigo-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:["Details",t.jsx(pe,{className:`h-4 w-4 transition-transform ${f?"rotate-90":""}`,"aria-hidden":!0})]})]}),j&&f&&t.jsx(cr,{id:S,context:e.context}),e.tickets?.length>0&&t.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:Jn(e.tickets,s).map(A=>t.jsx(Vn,{ticket:A},A.key))}),l&&c!=="editing"&&t.jsxs("div",{className:`mt-4 rounded-lg px-3 py-2.5 text-sm ${l==="wrong"?"bg-red-50 text-red-900":"bg-emerald-50 text-emerald-900"}`,children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("p",{className:"font-medium",children:[l==="wrong"?"You marked this wrong":"You confirmed this",t.jsxs("span",{className:"font-normal opacity-70",children:[" · ",$t(e.vincent_ruling?.ruled_at)]})]}),!i&&t.jsx("button",{type:"button",onClick:()=>{d("editing"),b(null)},className:"shrink-0 text-xs font-medium underline underline-offset-2 opacity-70 hover:opacity-100",children:"Change"})]}),l==="wrong"&&e.vincent_ruling?.correction&&t.jsx("p",{className:"mt-1.5 whitespace-pre-line",children:e.vincent_ruling.correction})]}),i&&t.jsx(ur,{request:i,mergedInto:s}),l==="confirmed"&&o&&c==="idle"&&t.jsx("div",{className:"mt-3",children:t.jsx(nn,{onClick:()=>{d("building"),b(null)}})}),k&&c!=="correcting"&&c!=="building"&&t.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",disabled:h,onClick:()=>E("confirmed"),className:"inline-flex min-h-[40px] items-center rounded-lg bg-indigo-600 px-4 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:opacity-50",children:h?"Saving…":"Confirm"}),t.jsx("button",{type:"button",disabled:h,onClick:()=>{d("correcting"),b(null)},className:"inline-flex min-h-[40px] items-center rounded-lg border border-red-200 bg-white px-4 text-sm font-semibold text-red-700 hover:bg-red-50 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 disabled:opacity-50",children:"Wrong"}),!l&&o&&t.jsx(nn,{disabled:h,onClick:()=>{d("building"),b(null)}}),c==="editing"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",disabled:h,onClick:()=>E(null),className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Clear ruling"}),t.jsx("button",{type:"button",onClick:()=>d("idle"),className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Cancel"})]})]}),c==="correcting"&&t.jsxs("div",{className:"mt-4",children:[t.jsx("label",{htmlFor:`correction-${e.claim_id}`,className:"block text-sm font-medium text-gray-800",children:"What is actually true?"}),t.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:"MAX will be corrected to say this. A fix ticket is filed on the next sync."}),t.jsx("textarea",{id:`correction-${e.claim_id}`,value:m,onChange:A=>p(A.target.value),rows:4,required:!0,autoFocus:!0,className:"mt-2 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500",placeholder:"The correct fact, worded the way MAX should say it."}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",disabled:h||!m.trim(),onClick:()=>E("wrong"),className:"inline-flex min-h-[40px] items-center rounded-lg bg-red-600 px-4 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 disabled:opacity-50",children:h?"Saving…":"Save correction"}),t.jsx("button",{type:"button",onClick:()=>{d(l?"editing":"idle"),b(null)},className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Cancel"})]})]}),c==="building"&&t.jsxs("div",{className:"mt-4",children:[t.jsx("label",{htmlFor:`build-${e.claim_id}`,className:"block text-sm font-medium text-gray-800",children:"What should exist instead?"}),t.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:["Your words become the spec of a feature ticket, filed on the next sync.",!l&&" Saving also confirms this claim."]}),t.jsx("textarea",{id:`build-${e.claim_id}`,value:u,onChange:A=>g(A.target.value),rows:4,required:!0,autoFocus:!0,className:"mt-2 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-amber-500 focus:outline-none focus:ring-1 focus:ring-amber-500",placeholder:"The capability, described the way it should work for a creator."}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",disabled:h||!u.trim(),onClick:R,className:"inline-flex min-h-[40px] items-center rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 disabled:opacity-50",children:h?"Saving…":"Request build"}),t.jsx("button",{type:"button",onClick:()=>{d("idle"),b(null)},className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Cancel"})]})]}),N&&t.jsx("p",{className:"mt-2 text-sm text-red-700",role:"alert",children:N})]})}function an({initialClaims:e,embedded:n=!1,mergedInto:a={}}){const[s,l]=r.useState(e||[]),[i,o]=r.useState("open"),[c,d]=r.useState(""),[m,p]=r.useState(()=>new Set),u=x=>{o(x),p(new Set)},g=r.useMemo(()=>({open:s.filter(x=>!je(x)).length,confirmed:s.filter(x=>je(x)==="confirmed").length,wrong:s.filter(x=>je(x)==="wrong").length,all:s.length}),[s]),h=r.useMemo(()=>{const x=c.trim().toLowerCase();return s.filter(j=>{const S=je(j);return i==="open"&&S&&!m.has(j.claim_id)||i==="confirmed"&&S!=="confirmed"||i==="wrong"&&S!=="wrong"?!1:x?[j.claim_id,j.topic,j.canonical_claim,j.vincent_ruling?.correction,j.build_request?.text,j.build_request?.ticket?.key,...(j.tickets||[]).map(B=>B.key)].some(B=>B&&B.toLowerCase().includes(x)):!0}).sort((j,S)=>{const B=k=>!!je(k)&&!m.has(k.claim_id);return B(j)-B(S)||tn(S)-tn(j)})},[s,i,c,m]),$=async(x,j)=>{const S=await fetch(x,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)}),B=await S.json().catch(()=>({}));if(!S.ok)throw new Error(B.error||`Could not save (${S.status})`);l(k=>k.map(E=>E.claim_id===j.claim_id?B.claim:E)),p(k=>new Set(k).add(j.claim_id))},N=(x,j,S)=>$("/api/admin/claims/ruling",{claim_id:x,status:j,correction:S}),b=(x,j)=>$("/api/admin/claims/build-request",{claim_id:x,text:j}),f=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"-mx-4 mt-5 bg-gray-50/95 px-4 pb-3 pt-2 backdrop-blur sm:-mx-8 sm:px-8 md:sticky md:top-0 md:z-10 xl:flex xl:items-center xl:gap-3",children:[t.jsx("div",{role:"tablist","aria-label":"Filter claims",className:"grid grid-cols-4 gap-1 rounded-lg bg-gray-200/70 p-1 xl:w-[40rem] xl:shrink-0",children:ir.map(x=>{const j=i===x.key;return t.jsxs("button",{type:"button",role:"tab","aria-selected":j,onClick:()=>u(x.key),className:`flex min-h-[44px] flex-col items-center justify-center whitespace-nowrap rounded-md px-1 text-[13px] font-medium leading-tight transition-colors sm:min-h-[36px] sm:flex-row sm:gap-1.5 sm:px-3 sm:text-sm ${j?"bg-white text-gray-900 shadow-sm":"text-gray-600 hover:text-gray-900"}`,children:[x.label,t.jsx("span",{className:`tabular-nums text-xs ${j?"text-indigo-600":"text-gray-400"}`,children:g[x.key]})]},x.key)})}),t.jsx("input",{type:"search",value:c,onChange:x=>d(x.target.value),placeholder:"Search claims, topics, tickets","aria-label":"Search claims",className:"mt-2 block w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm xl:mt-0 xl:max-w-md text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"})]}),t.jsxs("div",{className:`mt-2 grid grid-cols-1 items-start gap-3 ${n?"2xl:grid-cols-2":""}`,children:[h.map(x=>t.jsx(mr,{claim:x,onRule:N,onBuild:b,mergedInto:a},x.claim_id)),h.length===0&&t.jsx("p",{className:"col-span-full rounded-xl border border-dashed border-gray-300 bg-white px-4 py-10 text-center text-sm text-gray-500",children:s.length===0?"No claims yet. They arrive with the next pipeline sync.":c?`Nothing matches "${c}".`:i==="open"?"Every claim has a ruling.":"No claims here yet."})]})]});return n?f:t.jsx("div",{className:"min-h-full bg-gray-50",children:t.jsxs("div",{className:"mx-auto max-w-3xl px-4 pb-8 pt-16 sm:px-8 md:pt-8",children:[t.jsxs("header",{children:[t.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"MAX claims"}),t.jsx("p",{className:"mt-1 text-sm text-gray-600",children:"Platform facts MAX told creators, with the pipeline's verdict. Your ruling is the truth MAX gets corrected to."})]}),f]})})}const Yn="(max-width: 1023.98px)",xr=e=>{const n=window.matchMedia(Yn);return n.addEventListener("change",e),()=>n.removeEventListener("change",e)};function Kn(){return r.useSyncExternalStore(xr,()=>window.matchMedia(Yn).matches,()=>null)}const hr="https://magifyfun.atlassian.net/browse/",gr=e=>`/api/admin/pipeline/evidence?k=${encodeURIComponent(e.s3_key)}`;function sn(e){const n=e?new Date(e):null;return n&&!Number.isNaN(n.getTime())?n.toLocaleDateString("en-GB",{day:"numeric",month:"short"}):""}const Un=r.createContext(null),it=()=>r.useContext(Un),Qn=r.createContext(null);function ea(){const e=r.useContext(Qn),n=it();return r.useCallback((a,s)=>{e?.advance(a),s&&n?.toast(s)},[e,n])}function pr(){return it()?.defer}const fr=4e3,br=":where(html, body, body *){touch-action:pan-x pan-y}";function yr(){r.useEffect(()=>{const e=s=>{s.cancelable&&s.preventDefault()},n=s=>{s.touches.length>1&&s.cancelable&&s.preventDefault()},a={passive:!1};return document.addEventListener("gesturestart",e,a),document.addEventListener("gesturechange",e,a),document.addEventListener("touchmove",n,a),()=>{document.removeEventListener("gesturestart",e,a),document.removeEventListener("gesturechange",e,a),document.removeEventListener("touchmove",n,a)}},[])}function ce({title:e,onClose:n,children:a,tall:s=!1,label:l}){const i=r.useRef(null),o=r.useRef(null),[c,d]=r.useState(0);r.useEffect(()=>{const g=document.activeElement;i.current?.focus({preventScroll:!0});const h=$=>{$.key==="Escape"&&!document.querySelector("[data-lightbox], [data-cancel-dialog], [data-dismiss-dialog], [data-merge-dialog]")&&n()};return window.addEventListener("keydown",h),()=>{window.removeEventListener("keydown",h),g&&typeof g.focus=="function"&&g.focus({preventScroll:!0})}},[n]);const m=g=>{o.current=g.touches[0].clientY},p=g=>{o.current!=null&&d(Math.max(0,g.touches[0].clientY-o.current))},u=()=>{const g=c>90;o.current=null,d(0),g&&n()};return Bn.createPortal(t.jsxs("div",{className:"fixed inset-0 z-[45] flex flex-col justify-end","data-phone-sheet":l,children:[t.jsx("button",{type:"button","aria-label":"Close",tabIndex:-1,onClick:n,className:"absolute inset-0 bg-gray-950/50 motion-safe:animate-[phoneFade_160ms_ease-out]"}),t.jsxs("div",{ref:i,role:"dialog","aria-modal":"true","aria-label":e,tabIndex:-1,style:c?{transform:`translateY(${c}px)`}:void 0,className:`relative flex w-full flex-col rounded-t-2xl bg-white shadow-2xl outline-none motion-safe:animate-[phoneRise_200ms_ease-out] ${s?"h-[92dvh]":"max-h-[92dvh]"}`,children:[t.jsxs("div",{onTouchStart:m,onTouchMove:p,onTouchEnd:u,className:"shrink-0 touch-none",children:[t.jsx("div",{className:"mx-auto mt-2 h-1.5 w-10 rounded-full bg-gray-300","aria-hidden":!0}),t.jsxs("div",{className:"flex items-center gap-2 pl-4 pr-1.5",children:[t.jsx("h2",{className:"min-w-0 flex-1 truncate py-2 text-base font-semibold text-gray-900",children:e}),t.jsx("button",{type:"button","data-sheet-close":!0,onClick:n,"aria-label":"Close",className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-full text-gray-500 hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:t.jsx(fe,{className:"h-6 w-6","aria-hidden":!0})})]})]}),t.jsxs("div",{"data-sheet-body":!0,className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-[max(1rem,env(safe-area-inset-bottom))]",children:[a,t.jsx("div",{className:"pointer-events-none sticky bottom-0 -mx-4 -mt-6 h-6 bg-gradient-to-t from-white to-transparent","aria-hidden":!0})]})]})]}),document.body)}function ot({children:e}){return e?Bn.createPortal(e,document.body):null}function wt({children:e,className:n="",...a}){return t.jsx("button",{type:"button",className:`inline-flex h-11 shrink-0 items-center justify-center rounded-lg text-gray-700 hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 ${n}`,...a,children:e})}function wr({tab:e,tabs:n,counts:a,onTab:s,filterActive:l,renderFilters:i,children:o}){const[c,d]=r.useState(null),[m,p]=r.useState(null),[u,g]=r.useState(null),h=r.useCallback(()=>d(null),[]),$=r.useRef(null);yr();const N=r.useMemo(()=>({report:p,toast:x=>g({text:x,at:Date.now()}),defer:({text:x,run:j})=>{$.current&&(clearTimeout($.current.timer),$.current.run());const S={run:j};S.timer=setTimeout(()=>{$.current=null,g(null),j()},fr),$.current=S,g({text:x,at:Date.now(),undo:()=>{clearTimeout(S.timer),$.current=null,g({text:"Undone: nothing was sent.",at:Date.now()})}})}}),[]);r.useEffect(()=>{if(!u||u.undo)return;const x=setTimeout(()=>g(null),2800);return()=>clearTimeout(x)},[u]);const b=n.find(x=>x.key===e),f=m?.total?(m.index+1)/m.total*100:0;return t.jsxs(Un.Provider,{value:N,children:[t.jsxs("div",{"data-phone-cockpit":!0,className:"flex h-dvh flex-col overflow-hidden bg-gray-100",children:[t.jsx("style",{children:`@keyframes phoneRise{from{transform:translateY(100%)}to{transform:none}}@keyframes phoneFade{from{opacity:0}to{opacity:1}}${br}`}),t.jsxs("header",{"data-phone-header":!0,className:"relative z-20 shrink-0 border-b border-gray-200 bg-white",children:[t.jsxs("div",{className:"flex h-16 items-center gap-1 pl-[60px] pr-1.5 pt-2 md:h-14 md:pl-3 md:pt-0",children:[t.jsxs(wt,{"data-phone-tabs":!0,onClick:()=>d("tabs"),"aria-haspopup":"dialog",className:"min-w-0 flex-1 justify-start gap-1.5 px-2 text-left",children:[t.jsx("span",{className:"truncate text-[15px] font-semibold text-gray-900",children:b?.label}),!m?.total&&a[e]>0&&t.jsx("span",{className:"shrink-0 rounded-full bg-gray-900 px-1.5 text-xs font-semibold tabular-nums text-white",children:a[e]}),t.jsx(qn,{className:"h-5 w-5 shrink-0 text-gray-400","aria-hidden":!0})]}),m?.total>0&&t.jsxs(wt,{"data-phone-position":!0,onClick:()=>d("jump"),"aria-label":`Ticket ${m.index+1} of ${m.total}. Jump to a ticket`,className:"min-w-[64px] px-2 text-sm font-semibold tabular-nums",children:[m.index+1,t.jsxs("span",{className:"font-normal text-gray-400",children:["/",m.total]})]}),i&&t.jsxs(wt,{"data-phone-filters":!0,onClick:()=>d("filters"),"aria-label":l?"Filters (on)":"Filters",className:"relative w-11",children:[t.jsx(Ua,{className:"h-5 w-5","aria-hidden":!0}),l&&t.jsx("span",{className:"absolute right-2 top-2 h-2 w-2 rounded-full bg-indigo-600","aria-hidden":!0})]})]}),t.jsx("div",{className:"h-0.5 bg-gray-100","aria-hidden":!0,children:t.jsx("div",{"data-phone-progress":!0,className:"h-full origin-left bg-gray-900 transition-transform duration-200 motion-reduce:transition-none",style:{transform:`scaleX(${f/100})`}})})]}),t.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[o,u&&t.jsxs("div",{"data-phone-toast":!0,role:"status",className:"absolute inset-x-3 bottom-[calc(76px+env(safe-area-inset-bottom))] z-30 flex min-h-[48px] items-center gap-3 rounded-xl bg-gray-900 py-1 pl-3.5 pr-1 text-sm font-medium text-white shadow-lg motion-safe:animate-[phoneFade_160ms_ease-out]",children:[t.jsx("span",{className:"min-w-0 flex-1",children:u.text}),u.undo&&t.jsx("button",{type:"button","data-toast-undo":!0,onClick:u.undo,className:"h-11 shrink-0 rounded-lg px-3 font-semibold text-amber-300 hover:bg-white/10",children:"Undo"})]},u.at)]})]}),c==="tabs"&&t.jsx(ce,{title:"Review",label:"tabs",onClose:h,children:t.jsx("ul",{className:"-mx-1 pb-2",children:n.map(x=>{const j=x.key===e;return t.jsx("li",{children:t.jsxs("button",{type:"button","data-phone-tab":x.key,"aria-current":j?"page":void 0,onClick:()=>{s(x.key),h()},className:`flex min-h-[52px] w-full items-center gap-3 rounded-xl px-3 text-left text-[15px] ${j?"bg-gray-900 font-semibold text-white":"text-gray-800 hover:bg-gray-50"}`,children:[t.jsx("span",{className:"flex-1",children:x.label}),a[x.key]>0&&t.jsx("span",{className:`text-sm tabular-nums ${j?"text-white/70":"text-gray-400"}`,children:a[x.key]})]})},x.key)})})}),c==="filters"&&i&&t.jsx(ce,{title:"Filter",label:"filters",onClose:h,children:t.jsx("div",{className:"pb-3 [&_button]:min-h-[44px]",children:i()})}),c==="jump"&&m?.items&&t.jsx(ce,{title:`${b?.label} · ${m.total}`,label:"jump",onClose:h,children:t.jsx(jr,{pos:m,onPick:x=>{m.jump(x),h()}})})]})}function jr({pos:e,onPick:n}){const a=r.useRef(null);return r.useEffect(()=>{a.current?.querySelector('[aria-current="true"]')?.scrollIntoView({block:"center"})},[]),t.jsx("ol",{ref:a,className:"-mx-1 pb-2",children:e.items.map((s,l)=>t.jsx("li",{children:t.jsxs("button",{type:"button","data-phone-jump":s.key,"aria-current":l===e.index?"true":void 0,onClick:()=>n(l),className:`flex min-h-[52px] w-full items-center gap-3 rounded-xl px-3 py-2 text-left ${l===e.index?"bg-gray-100":"hover:bg-gray-50"}`,children:[t.jsx("span",{className:"w-7 shrink-0 text-right text-xs tabular-nums text-gray-400",children:l+1}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block font-mono text-[11px] text-gray-500",children:s.key}),t.jsx("span",{className:"block truncate text-sm text-gray-900",children:s.summary})]})]})},s.key))})}const vr=2;function ta({items:e,renderPage:n,empty:a}){const s=r.useRef(null),l=it(),[i,o]=r.useState(0),c=r.useRef(e[0]?.key),d=r.useRef(0),m=r.useRef(!1),p=r.useMemo(()=>({advance:b=>{m.current=b}}),[]),u=r.useCallback((b,f=!1)=>{const x=s.current;x&&x.scrollTo({top:b*x.clientHeight,behavior:f?"smooth":"instant"})},[]);r.useLayoutEffect(()=>{const b=m.current&&m.current===c.current?-1:e.findIndex(j=>j.key===c.current);m.current=null;const f=b>=0?b:Math.min(i,Math.max(0,e.length-1));c.current=e[f]?.key,f!==i&&o(f);const x=s.current;x&&Math.round(x.scrollTop/(x.clientHeight||1))!==f&&(x.scrollTop=f*x.clientHeight)},[e]),r.useEffect(()=>{const b=s.current;if(!b||typeof ResizeObserver>"u")return;const f=new ResizeObserver(()=>{const x=e.findIndex(j=>j.key===c.current);x>=0&&(b.scrollTop=x*b.clientHeight)});return f.observe(b),()=>f.disconnect()},[e]);const g=r.useRef(null),h=()=>{g.current=s.current?.scrollTop??null},$=()=>{const b=s.current,f=g.current;if(g.current=null,!b||f==null)return;const x=b.clientHeight||1,j=b.scrollTop-f;if(Math.abs(j)<x*.15)return;const S=Math.max(0,Math.min(e.length-1,Math.round(f/x)+Math.sign(j)));b.scrollTo({top:S*x,behavior:"smooth"})},N=()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(()=>{const b=s.current;if(!b)return;const f=Math.max(0,Math.min(e.length-1,Math.round(b.scrollTop/(b.clientHeight||1))));f!==i&&(c.current=e[f]?.key,o(f))})};return r.useEffect(()=>{l?.report(e.length?{index:i,total:e.length,items:e,jump:u}:null)},[i,e,u,l]),r.useEffect(()=>()=>l?.report(null),[l]),e.length?t.jsx(Qn.Provider,{value:p,children:t.jsx("div",{ref:s,"data-phone-feed":!0,onScroll:N,onTouchStart:h,onTouchEnd:$,onTouchCancel:$,className:"min-h-0 flex-1 snap-y snap-mandatory overflow-y-auto overscroll-y-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:e.map((b,f)=>t.jsx("section",{"data-phone-page":b.key,"data-page-index":f,"data-page-active":f===i?"true":void 0,"aria-label":`Ticket ${f+1} of ${e.length}: ${b.key}`,className:"h-full snap-start snap-always overflow-hidden [content-visibility:auto]",children:Math.abs(f-i)<=vr?n(b,f===i):null},b.key))})}):t.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:a})}function Pt({images:e,onOpen:n,eager:a=!1,grow:s=!1}){const l=r.useRef(null),[i,o]=r.useState(!1);r.useLayoutEffect(()=>{const m=s&&l.current?.parentElement;if(!m||typeof ResizeObserver>"u")return;const p=new ResizeObserver(()=>o(m.clientHeight>=170));return p.observe(m),()=>p.disconnect()},[s]);const c=e.length;if(!c)return null;const d=gr(e[0]);return t.jsxs("button",{ref:l,type:"button","data-proof-button":!0,"data-proof-big":i?"true":void 0,"aria-haspopup":"dialog",onClick:()=>n(0),className:`mx-4 flex w-[calc(100%-2rem)] flex-col overflow-hidden rounded-xl border border-gray-300 bg-white text-left shadow-sm active:bg-gray-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 ${i?"min-h-0 flex-1":"shrink-0"}`,children:[i&&t.jsx("span",{className:"relative block min-h-0 w-full flex-1 bg-gray-50",children:t.jsx("img",{src:d,alt:"",loading:a?"eager":"lazy",decoding:"async",draggable:!1,className:"absolute inset-0 h-full w-full object-contain"})}),t.jsxs("span",{className:`flex h-14 w-full shrink-0 items-center gap-3 pr-3 ${i?"border-t border-gray-200 pl-4":"pl-1.5"}`,children:[!i&&t.jsx("span",{className:"h-11 w-16 shrink-0 overflow-hidden rounded-lg bg-gray-100 ring-1 ring-inset ring-gray-200",children:t.jsx("img",{src:d,alt:"",loading:a?"eager":"lazy",decoding:"async",draggable:!1,className:"h-full w-full object-cover object-left-top"})}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-[15px] font-semibold text-gray-900",children:c===1?"See the proof image":`See the ${c} proof images`}),t.jsx(ls,{className:"h-5 w-5 shrink-0 text-gray-500","aria-hidden":!0})]})]})}function Bt({grow:e=!1,children:n}){return t.jsx("div",{"data-proof-zone":!0,className:`pb-2 pt-1.5 ${e?"flex min-h-[72px] flex-1 flex-col justify-end":"shrink-0"}`,children:n})}function ke({children:e,onMore:n,keepAll:a=!1,hug:s=!1,className:l=""}){const i=r.useRef(null),[o,c]=r.useState(null),[d,m]=r.useState(0);r.useLayoutEffect(()=>{const u=i.current;if(!u)return;const g=()=>{const N=[...u.children];if(N.forEach(R=>{R.style.display=""}),u.querySelectorAll("li").forEach(R=>{Object.assign(R.style,{display:"",maxHeight:"",overflow:""})}),u.querySelectorAll("[data-fit-body]").forEach(R=>{Object.assign(R.style,{display:"",WebkitLineClamp:"",WebkitBoxOrient:"",overflow:""})}),u.scrollHeight<=u.clientHeight+1){c(null);return}const b=u.clientHeight-44,f=R=>R.getBoundingClientRect().top-u.getBoundingClientRect().top,x=R=>R.getBoundingClientRect().bottom-u.getBoundingClientRect().top,j=R=>parseFloat(getComputedStyle(R).lineHeight)||20;if(a){const R=N.map(C=>C.querySelector("[data-fit-body]")).filter(Boolean),F=R.map(j),A=R.map((C,O)=>Math.max(1,Math.round(C.getBoundingClientRect().height/F[O]))),M=u.scrollHeight-R.reduce((C,O)=>C+O.getBoundingClientRect().height,0);let W=b-M;const v=R.map(()=>0);for(let C=!0;C;)C=!1,R.forEach((O,y)=>{v[y]<A[y]&&(v[y]===0||W>=F[y])&&(v[y]+=1,W-=F[y],C=!0)});R.forEach((C,O)=>{v[O]<A[O]&&Object.assign(C.style,{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:String(v[O]),overflow:"hidden"})}),c([]),m(Math.min(b,Math.ceil(x(N[N.length-1]))));return}const S=[];let B=!1,k=!1;N.forEach(R=>{const F=R.querySelector("[data-fit-label]")?.textContent;if(k){R.style.display="none",F&&S.push(F);return}if(x(R)<=b){B=!0;return}k=!0;const A=R.querySelector("[data-fit-body]"),M=A?[...A.querySelectorAll("li")]:[],W=M.filter(O=>x(O)<=b);if(M.length&&W.length){M.forEach(O=>{x(O)>b&&(O.style.display="none")}),F&&S.push(`the rest of ${F.toLowerCase()}`);return}if(B||!A){R.style.display="none",F&&S.push(F);return}const v=M[0]||A,C=Math.max(1,Math.floor((b-f(v))/j(v)));Object.assign(v.style,{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:String(C),overflow:"hidden"})}),c(S);const E=N.filter(R=>R.style.display!=="none");m(E.length?Math.min(b,Math.ceil(x(E[E.length-1]))):0)};if(g(),typeof ResizeObserver>"u")return;let h=u.clientHeight;const $=new ResizeObserver(()=>{u.clientHeight!==h&&(h=u.clientHeight,g())});return $.observe(u),()=>$.disconnect()},[e,a]);const p=o&&(o.length?`${o.join(", ")} in Details`:"Read all in Details");return t.jsxs("div",{className:`relative flex min-h-0 flex-col ${s?"flex-[0_1_auto]":"flex-1"} ${l}`,style:s&&p?{minHeight:d+44}:void 0,children:[t.jsx("div",{ref:i,"data-fit-text":!0,"data-overflowing":o?"true":void 0,className:"relative min-h-0 flex-1 overflow-hidden",children:e}),p&&t.jsxs("button",{type:"button","data-fit-more":!0,onClick:n,style:{top:d},className:"absolute left-4 inline-flex h-11 max-w-[calc(100%-2rem)] items-center gap-1 text-sm font-medium text-indigo-700",children:[t.jsx("span",{className:"truncate first-letter:uppercase",children:p}),t.jsx(pe,{className:"h-4 w-4 shrink-0","aria-hidden":!0})]})]})}function J({label:e,strong:n=!1,children:a}){return a?t.jsxs("div",{className:"mt-2.5 first:mt-0",children:[t.jsx("p",{"data-fit-label":!0,className:"text-[11px] font-semibold uppercase tracking-wide text-gray-500",children:e}),t.jsx("div",{"data-fit-body":!0,className:`mt-0.5 leading-snug text-gray-900 [overflow-wrap:anywhere] ${n?"text-base font-semibold":"text-[15px]"}`,children:a})]}):null}const Nr={ok:"bg-emerald-50 text-emerald-800 ring-emerald-200",warn:"bg-amber-50 text-amber-900 ring-amber-300",bad:"bg-red-50 text-red-800 ring-red-200",info:"bg-indigo-50 text-indigo-800 ring-indigo-200",muted:"bg-gray-100 text-gray-600 ring-gray-200"};function _e({ticket:e,pill:n,dates:a,summary:s,chips:l,select:i,lines:o=3}){return t.jsxs("div",{className:"shrink-0 px-4 pt-2.5",children:[t.jsxs("div",{className:"-my-2 flex items-center gap-1.5",children:[i,t.jsx("a",{href:hr+e.key,target:"_blank",rel:"noopener noreferrer","data-jira-key":e.key,"aria-label":`Open ${e.key} in Jira`,className:"flex h-11 shrink-0 items-center",children:t.jsx("span",{className:"rounded border border-gray-200 bg-gray-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-gray-600",children:e.key})}),n&&t.jsxs("span",{"data-phone-pill":n.kind,className:`inline-flex min-w-0 items-center gap-1 truncate rounded-full px-2 py-0.5 text-[11px] font-semibold ring-1 ring-inset ${Nr[n.kind]}`,children:[n.icon&&t.jsx(n.icon,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),t.jsx("span",{className:"truncate",children:n.label})]}),a&&t.jsx("span",{"data-phone-dates":!0,className:"ml-auto shrink-0 text-[11px] tabular-nums text-gray-500",children:a})]}),s&&t.jsx("h3",{"data-phone-summary":!0,className:`mt-1.5 text-[17px] font-semibold leading-snug text-gray-900 [overflow-wrap:anywhere] ${{3:"line-clamp-3",4:"line-clamp-4",5:"line-clamp-5",6:"line-clamp-6"}[o]}`,children:s}),l]})}function We(e){const n=sn(e.jira_created),a=sn(e.jira_updated);return n&&a&&a!==n?`Filed ${n} · updated ${a}`:n?`Filed ${n}`:""}function et({tone:e="bad",children:n}){const a=e==="bad"?"border-red-200 bg-red-50 text-red-900":"border-amber-300 bg-amber-50 text-amber-950";return t.jsxs("p",{"data-phone-banner":e,role:"status",className:`mx-4 mt-2 flex shrink-0 items-center gap-1.5 truncate rounded-lg border px-2.5 py-1.5 text-[13px] ${a}`,children:[t.jsx(ae,{className:`h-4 w-4 shrink-0 ${e==="bad"?"text-red-600":"text-amber-600"}`,"aria-hidden":!0}),t.jsx("span",{className:"truncate",children:n})]})}function Ce({actions:e=[],primary:n}){return t.jsx("nav",{"data-thumb-bar":!0,"aria-label":"Ticket actions",className:"mt-auto shrink-0 border-t border-gray-200 bg-white px-2 pb-[max(0.5rem,env(safe-area-inset-bottom))] pt-2",children:t.jsxs("div",{className:"grid grid-cols-5 gap-1.5",children:[e.map(a=>{const s=a.href?"a":"button";return t.jsxs(s,{"data-thumb-action":a.id,...a.href?{href:a.href,target:"_blank",rel:"noopener noreferrer"}:{type:"button",onClick:a.onClick,disabled:a.disabled},className:`relative flex min-h-[52px] flex-col items-center justify-center gap-0.5 rounded-xl px-1 text-[11px] font-medium leading-tight focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 disabled:opacity-40 ${a.tone==="danger"?"text-red-700 hover:bg-red-50":a.tone==="fix"?"text-amber-800 hover:bg-amber-50":"text-gray-700 hover:bg-gray-100"}`,children:[t.jsx(a.icon,{className:"h-5 w-5","aria-hidden":!0}),t.jsx("span",{className:"max-w-full truncate",children:a.label}),a.badge>0&&t.jsx("span",{className:"absolute right-2 top-1 min-w-[18px] rounded-full bg-indigo-600 px-1 text-[10px] font-semibold tabular-nums text-white",children:a.badge})]},a.id)}),n&&(()=>{const a=n.href?"a":"button",s=5-e.length;return t.jsxs(a,{"data-thumb-action":n.id,"data-thumb-primary":!0,...n.href?{href:n.href,target:"_blank",rel:"noopener noreferrer"}:{type:"button",onClick:n.onClick,disabled:n.disabled},style:{gridColumn:`span ${s} / span ${s}`},className:`flex min-h-[52px] items-center justify-center gap-1.5 rounded-xl px-2 text-[14px] font-semibold shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-40 ${n.muted?"bg-white text-gray-800 ring-1 ring-inset ring-gray-300 focus-visible:ring-gray-400":"bg-gray-900 text-white focus-visible:ring-gray-900"}`,children:[n.icon&&t.jsx(n.icon,{className:"h-4 w-4 shrink-0 max-[379px]:hidden","aria-hidden":!0}),t.jsx("span",{className:"truncate",children:n.label})]})})()]})})}const H={details:ws,chat:Fn,fix:ue,open:Le,check:Dn,later:Fe,dismiss:fe,bundles:Tt};function $e(){const[e,n]=r.useState(null),a=r.useCallback(()=>n(null),[]);return{sheet:e,open:n,close:a}}function rn({children:e}){return t.jsx("div",{"data-phone-strip":!0,className:"flex min-h-[48px] shrink-0 items-center gap-2 border-b border-gray-200 bg-white px-3 py-1",children:e})}function jt({children:e,primary:n=!1,className:a="",...s}){return t.jsx("button",{type:"button",className:`inline-flex min-h-[44px] shrink-0 items-center gap-1.5 rounded-lg px-3 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 disabled:opacity-40 ${n?"bg-gray-900 text-white":"text-gray-800 ring-1 ring-inset ring-gray-300"} ${a}`,...s,children:e})}function kr({selected:e,disabled:n,onToggle:a,ticketKey:s}){return t.jsx("label",{className:"-my-2 -ml-2 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center",title:"Select to merge",children:t.jsx("input",{type:"checkbox","data-select":s,checked:e,disabled:n&&!e,onChange:a,"aria-label":`Select ${s} to merge`,className:"h-5 w-5 rounded border-gray-300 text-gray-900 focus:ring-gray-900 disabled:opacity-40"})})}function _r(){return!!it()}const ln=e=>`/api/admin/pipeline/evidence?k=${encodeURIComponent(e.s3_key)}`,Cr=8,$r=300,on=280,Er=40,we=2.5,dn=5,Sr=.8,Rr=.22,cn=.45,Mr=.28,Tr=110,Ar="transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1)",Je=(e,n,a)=>Math.min(a,Math.max(n,e));function Pr({images:e,index:n,onIndex:a,onClose:s}){const l=e.length,i=e[n],o=r.useRef(null),c=r.useRef(null),d=r.useRef(null),m=r.useRef(null),[p,u]=r.useState(!1),[g,h]=r.useState(0),[$,N]=r.useState(null),b=r.useRef(!1),f=r.useRef({s:1,tx:0,ty:0}),x=r.useRef(null),j=r.useRef(null),S=r.useRef({index:n,n:l,onIndex:a,onClose:s});S.current={index:n,n:l,onIndex:a,onClose:s};const[,B]=r.useState(null),k=r.useCallback(y=>B(()=>{throw y}),[]),E=r.useCallback(()=>{const y=c.current,_=d.current;if(!y||!_)return null;const L=y.getBoundingClientRect();return x.current={W:window.innerWidth,H:window.innerHeight,cx:L.left+L.width/2,cy:L.top+L.height/2,w:_.offsetWidth||1,h:_.offsetHeight||1},x.current},[]),R=y=>{const _=x.current;if(!_)return{x0:0,x1:0,y0:0,y1:0};const L=y*_.w,D=y*_.h,Z=L>_.W?_.W-_.cx-L/2:0,I=L>_.W?L/2-_.cx:0,V=D>_.H?_.H-_.cy-D/2:0,ie=D>_.H?D/2-_.cy:0;return{x0:Math.min(Z,0),x1:Math.max(I,0),y0:Math.min(V,0),y1:Math.max(ie,0)}},F=y=>{const _=R(y.s);return{s:y.s,tx:Je(y.tx,_.x0,_.x1),ty:Je(y.ty,_.y0,_.y1)}},A=(y,{animate:_=!1,fade:L=null}={})=>{f.current=y;const D=d.current,Z=o.current;if(D){const V=window.matchMedia("(prefers-reduced-motion: reduce)").matches;D.style.transition=_&&!V?Ar:"none",D.style.transform=`translate3d(${y.tx}px, ${y.ty}px, 0) scale(${y.s})`}Z&&(Z.dataset.viewerScale=y.s.toFixed(3),Z.dataset.viewerTx=Math.round(y.tx),Z.dataset.viewerTy=Math.round(y.ty),Z.style.backgroundColor=L==null?"":`rgba(3, 7, 18, ${L})`,L==null?delete Z.dataset.closing:Z.dataset.closing="");const I=y.s>1.01;I!==b.current&&(b.current=I,u(I))},M=r.useCallback((y,_=!0)=>{const{index:L,n:D,onIndex:Z}=S.current;if(D<2)return;const I=f.current,V=x.current;j.current=_&&I.s>1.01&&V?{s:I.s,u:(V.W/2-V.cx-I.tx)/I.s/V.w,v:(V.H/2-V.cy-I.ty)/I.s/V.h}:null,Z((L+y+D)%D)},[]),W=r.useCallback(()=>{if(!E())return;const y=j.current,_=x.current;if(!y){A({s:1,tx:0,ty:0});return}A(F({s:y.s,tx:_.W/2-_.cx-y.s*y.u*_.w,ty:_.H/2-_.cy-y.s*y.v*_.h}))},[]);r.useLayoutEffect(()=>{const y=d.current;if(!y)return;y.complete&&y.naturalWidth?W():A({s:j.current?.s||1,tx:0,ty:0});const _=()=>{try{W()}catch(L){k(L)}};return y.addEventListener("load",_),()=>y.removeEventListener("load",_)},[n,g,W,k]),r.useEffect(()=>{l<2||[e[(n+1)%l],e[(n-1+l)%l]].forEach(y=>{new window.Image().src=ln(y)})},[e,n,l]),r.useEffect(()=>{const y=document.activeElement;m.current?.focus({preventScroll:!0});const _=L=>{L.key==="Escape"?S.current.onClose():L.key==="ArrowLeft"?(L.preventDefault(),M(-1)):L.key==="ArrowRight"&&(L.preventDefault(),M(1))};return window.addEventListener("keydown",_),()=>{window.removeEventListener("keydown",_),y?.focus?.({preventScroll:!0})}},[M]),r.useEffect(()=>{const y=[...document.querySelectorAll("[data-phone-feed], [data-sheet-body]")].map(_=>({el:_,overflow:_.style.overflow,top:_.scrollTop}));return y.forEach(({el:_})=>{_.style.overflow="hidden"}),()=>y.forEach(({el:_,overflow:L,top:D})=>{_.style.overflow=L,_.scrollTop=D})},[]),r.useEffect(()=>{const y=()=>{try{E()&&A(F(f.current))}catch(_){k(_)}};return window.addEventListener("resize",y),()=>window.removeEventListener("resize",y)},[E,k]),r.useEffect(()=>{const y=o.current,_=new Map;let L="idle",D=!1,Z=null,I=null,V=null,ie=null,se=[],ne=null,w=0,T=0;const K=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,xe=(P,q,G)=>{if(K()){G();return}A(P,{animate:!0,fade:q}),clearTimeout(T),T=setTimeout(()=>{try{G()}catch(z){k(z)}},180)},Q=()=>{clearTimeout(w),w=0},Da=()=>{const P=performance.now(),q=se.filter(Y=>P-Y.t<100);if(q.length<2)return{vx:0,vy:0};const G=q[0],z=q[q.length-1],X=Math.max(1,z.t-G.t);return{vx:(z.x-G.x)/X,vy:(z.y-G.y)/X}},Ht=()=>{const[P,q]=[..._.values()];return{a:P,b:q,d:Math.hypot(q.x-P.x,q.y-P.y)||1,mx:(P.x+q.x)/2,my:(P.y+q.y)/2}},qa=()=>{E();const{d:P,mx:q,my:G}=Ht(),z=f.current,X=x.current;I={...z},V={d:P,qx:(q-X.cx-z.tx)/z.s,qy:(G-X.cy-z.ty)/z.s},L="pinch",D=!0,Q()},Wt=P=>{E(),I={...f.current},Z={x:P.x,y:P.y,t:performance.now()};const q=R(I.s);ie={left:I.tx>=q.x1-1,right:I.tx<=q.x0+1},L="pan"},Re=()=>A(F({...f.current,s:Je(f.current.s,1,dn)}),{animate:!0}),zt=()=>A({s:1,tx:0,ty:0},{animate:!0}),Ia=(P,q)=>{if(!E())return;if(f.current.s>1.01){zt();return}const G=x.current;A(F({s:we,tx:(1-we)*(P-G.cx),ty:(1-we)*(q-G.cy)}),{animate:!0})},Za=(P,q,G)=>{if(ne&&G-ne.t<on&&Math.hypot(P-ne.x,q-ne.y)<Er){Q(),ne=null,Ia(P,q);return}ne={x:P,y:q,t:G},Q(),w=setTimeout(()=>{w=0,ne=null;const z=window.innerWidth;try{P<z/3?M(-1):P>z*2/3?M(1):"chromeHidden"in y.dataset?delete y.dataset.chromeHidden:y.dataset.chromeHidden=""}catch(X){k(X)}},on)},Ha=P=>{P.pointerType==="mouse"&&P.button!==0||P.target.closest?.("[data-viewer-control]")||_.size>=2||(_.set(P.pointerId,{x:P.clientX,y:P.clientY}),P.pointerType==="mouse"&&y.setPointerCapture?.(P.pointerId),_.size===1?(E(),D=!1,L="pending",Z={x:P.clientX,y:P.clientY,t:performance.now()},I={...f.current},se=[{t:Z.t,x:P.clientX,y:P.clientY}],A(f.current)):qa())},Wa=P=>{const q=_.get(P.pointerId);if(!q)return;if(q.x=P.clientX,q.y=P.clientY,L==="pinch"&&_.size===2){const{d:Y,mx:he,my:oe}=Ht(),ee=x.current,U=Je(I.s*(Y/V.d),Sr,dn);A({s:U,tx:he-ee.cx-U*V.qx,ty:oe-ee.cy-U*V.qy});return}if(_.size!==1)return;se.push({t:performance.now(),x:q.x,y:q.y}),se.length>12&&se.shift();const G=q.x-Z.x,z=q.y-Z.y;if(L==="pending"){if(Math.hypot(G,z)<Cr)return;Q(),ne=null,f.current.s>1.01?Wt(Z):D?L="none":Math.abs(G)>Math.abs(z)?L=S.current.n>1?"swipe":"none":L=z>0?"dismiss":"none"}const X=x.current;if(L==="pan"){const Y=R(I.s),he=(oe,ee,U)=>oe<ee?ee+(oe-ee)*.35:oe>U?U+(oe-U)*.35:oe;A({s:I.s,tx:he(I.tx+G,Y.x0,Y.x1),ty:he(I.ty+z,Y.y0,Y.y1)})}else if(L==="swipe")A({s:1,tx:G,ty:0});else if(L==="dismiss"){const Y=Math.max(0,z);A({s:1-Math.min(Y/X.H,1)*.25,tx:G*.3,ty:Y},{fade:Math.max(.2,1-Y/400)})}},za=P=>{if(!_.has(P.pointerId))return;const q=_.get(P.pointerId);_.delete(P.pointerId);const G=P.type==="pointercancel";if(L==="pinch"){if(_.size===1){const[U]=[..._.values()];f.current.s>1.01?Wt(U):L="none",se=[];return}_.size===0&&(Re(),L="idle");return}if(_.size>0)return;const z=window.innerWidth,X=q.x-Z.x,Y=q.y-Z.y,{vx:he,vy:oe}=Da(),ee=L;if(L="idle",G){ee!=="pending"&&Re();return}if(ee==="pending")!D&&performance.now()-Z.t<$r&&Za(q.x,q.y,performance.now());else if(ee==="pan"){const U=Ga=>{const Yt=R(I.s);return Ga==="left"?I.tx+X-Yt.x1:Yt.x0-(I.tx+X)},Vt=z*Mr;D?Re():ie.left&&X>0&&Math.abs(X)>Math.abs(Y)&&U("left")>Vt?M(-1):ie.right&&X<0&&Math.abs(X)>Math.abs(Y)&&U("right")>Vt?M(1):Re()}else ee==="swipe"?Math.abs(X)>z*Rr||Math.abs(he)>cn&&Math.abs(X)>40&&Math.sign(he)===Math.sign(X)?xe({s:1,tx:X<0?-z:z,ty:0},null,()=>M(X<0?1:-1,!1)):zt():ee==="dismiss"?Y>Tr||oe>cn&&Y>40?xe({s:.8,tx:X*.3,ty:x.current.H},0,()=>S.current.onClose()):A({s:1,tx:0,ty:0},{animate:!0}):Re()},be=P=>P.preventDefault(),Gt=P=>{P.touches.length>1&&P.preventDefault()},bt=P=>q=>{try{P(q)}catch(G){_.clear(),L="idle",Q(),k(G)}},Xt=bt(Ha),Jt=bt(Wa),ye=bt(za);return y.addEventListener("pointerdown",Xt),y.addEventListener("pointermove",Jt),y.addEventListener("pointerup",ye),y.addEventListener("pointercancel",ye),y.addEventListener("lostpointercapture",ye),y.addEventListener("touchmove",be,{passive:!1}),y.addEventListener("touchstart",Gt,{passive:!1}),y.addEventListener("gesturestart",be,{passive:!1}),y.addEventListener("gesturechange",be,{passive:!1}),()=>{Q(),clearTimeout(T),y.removeEventListener("pointerdown",Xt),y.removeEventListener("pointermove",Jt),y.removeEventListener("pointerup",ye),y.removeEventListener("pointercancel",ye),y.removeEventListener("lostpointercapture",ye),y.removeEventListener("touchmove",be),y.removeEventListener("touchstart",Gt),y.removeEventListener("gesturestart",be),y.removeEventListener("gesturechange",be)}},[M,E,k]);const v=()=>{if(E())if(f.current.s>1.01)A({s:1,tx:0,ty:0},{animate:!0});else{const y=x.current;A(F({s:we,tx:(1-we)*(y.W/2-y.cx),ty:(1-we)*(y.H/2-y.cy)}),{animate:!0})}},C=y=>y.stopPropagation(),O="flex items-center justify-center rounded-full bg-gray-900/75 text-white shadow-lg ring-1 ring-white/20 active:bg-gray-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-white";return t.jsxs("div",{ref:o,role:"dialog","aria-modal":"true","aria-label":i.caption||i.name,"data-lightbox":!0,"data-lightbox-phone":!0,"data-lightbox-index":n,"data-lightbox-kind":i.chat?"chat":"proof",onClick:C,onPointerDown:C,onPointerMove:C,onPointerUp:C,onTouchStart:C,onTouchMove:C,onTouchEnd:C,onTouchCancel:C,className:"group fixed inset-0 z-50 select-none overflow-hidden overscroll-none bg-gray-950 text-white [-webkit-touch-callout:none] [touch-action:none]",children:[t.jsx("div",{ref:c,"data-viewer-stage":!0,className:`absolute inset-x-0 ${l>1?"bottom-[calc(9.5rem+env(safe-area-inset-bottom))]":"bottom-[calc(5rem+env(safe-area-inset-bottom))]"} top-[calc(4rem+env(safe-area-inset-top))] flex items-center justify-center px-3`,children:t.jsx("img",{ref:d,"data-viewer-img":!0,onError:()=>N(i.sha256),src:ln(i),alt:i.caption||i.name,draggable:!1,className:"block max-h-full max-w-full origin-center rounded-lg bg-white object-contain shadow-2xl will-change-transform"},`${i.sha256}-${g}`)}),$===i.sha256&&t.jsxs("div",{"data-viewer-broken":!0,className:"absolute inset-0 flex flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx("p",{className:"text-sm text-gray-300",children:"This image did not load."}),t.jsx("button",{type:"button","data-viewer-control":!0,onClick:()=>{N(null),h(y=>y+1)},className:"h-11 rounded-lg bg-white/15 px-4 text-sm font-semibold text-white active:bg-white/25",children:"Try again"})]}),t.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-0 flex items-center justify-between gap-2 bg-gradient-to-b from-gray-950/90 to-transparent px-3 pb-6 pt-[max(0.75rem,env(safe-area-inset-top))] transition-[opacity,visibility] duration-150 group-data-[closing]:opacity-0 group-data-[chrome-hidden]:invisible group-data-[chrome-hidden]:opacity-0",children:[t.jsx("button",{type:"button","data-viewer-control":!0,"data-lightbox-zoom":!0,onClick:v,"aria-label":p?"Zoom out":"Zoom in",className:`pointer-events-auto h-11 w-11 ${O}`,children:p?t.jsx(Ss,{className:"h-5 w-5","aria-hidden":!0}):t.jsx(Ms,{className:"h-5 w-5","aria-hidden":!0})}),t.jsx("p",{"data-viewer-hint":!0,className:"min-w-0 truncate rounded-full bg-gray-900/75 px-3 py-1.5 text-xs text-gray-200",children:p?l>1?"Tap a side to switch · double-tap to fit":"Double-tap to fit":"Pinch or double-tap to zoom"}),t.jsx("button",{ref:m,type:"button","data-viewer-control":!0,onClick:s,"aria-label":"Close",className:`pointer-events-auto h-11 w-11 ${O}`,children:t.jsx(fe,{className:"h-6 w-6","aria-hidden":!0})})]}),t.jsxs("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-gray-950 via-gray-950/90 to-transparent px-3 pb-[max(1rem,env(safe-area-inset-bottom))] pt-8 transition-[opacity,visibility] duration-150 group-data-[closing]:opacity-0 group-data-[chrome-hidden]:invisible group-data-[chrome-hidden]:opacity-0",children:[t.jsx("p",{"data-lightbox-caption":!0,className:"mx-auto mb-3 line-clamp-2 max-w-xl text-center text-sm text-gray-200",children:i.caption||i.name}),l>1&&t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("button",{type:"button","data-viewer-control":!0,"data-lightbox-prev":!0,"aria-label":"Previous image",onClick:()=>M(-1),className:`pointer-events-auto h-14 w-14 ${O}`,children:t.jsx(In,{className:"h-7 w-7","aria-hidden":!0})}),t.jsxs("p",{"data-lightbox-position":!0,"aria-live":"polite",className:"rounded-full bg-gray-900/75 px-3.5 py-2 text-base font-semibold tabular-nums",children:[n+1," / ",l]}),t.jsx("button",{type:"button","data-viewer-control":!0,"data-lightbox-next":!0,"aria-label":"Next image",onClick:()=>M(1),className:`pointer-events-auto h-14 w-14 ${O}`,children:t.jsx(pe,{className:"h-7 w-7","aria-hidden":!0})})]})]})]})}class Br extends r.Component{constructor(n){super(n),this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(n,a){console.error("[cockpit viewer] closed after an error",n,a?.componentStack)}render(){return this.state.failed?t.jsxs("div",{role:"alert","data-viewer-failed":!0,className:"fixed inset-x-3 bottom-[max(1rem,env(safe-area-inset-bottom))] z-50 flex items-center gap-3 rounded-xl bg-gray-900 px-4 py-3 text-sm text-white shadow-2xl",children:[t.jsx("span",{className:"min-w-0 flex-1",children:"The image viewer hit a problem and closed. Your ticket is still here."}),t.jsx("button",{type:"button",onClick:this.props.onClose,className:"h-11 shrink-0 rounded-lg bg-white/15 px-4 font-semibold active:bg-white/25",children:"OK"})]}):this.props.children}}const ze="https://magifyfun.atlassian.net/browse/",Or={magify_agents_api:"api",magify_next:"next"},De=e=>`${Or[e.repo]||e.repo}#${e.number}`,na=e=>e&&e.charAt(0).toUpperCase()+e.slice(1),Ot=e=>(e.evidence||[]).filter(n=>n.s3_key);function qe(e){const n=e?new Date(e):null;return n&&!Number.isNaN(n.getTime())?n.toLocaleDateString("en-GB",{day:"numeric",month:"short"}):""}async function aa(e,n){const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),s=await a.json().catch(()=>({}));if(!a.ok)throw new Error(s.error||`The server answered ${a.status}`);return s}function Ge({ticket:e,kit:n}){const a=e.flags||[];return!a.length&&!e.hold?null:t.jsxs("div",{"data-phone-flags":!0,className:"mt-1.5 flex h-6 items-center gap-1 overflow-hidden",children:[t.jsx(n.AutoChips,{ticket:e}),a.map(s=>t.jsx(n.FlagChip,{flag:s,size:"sm"},s.id))]})}function Lr(e){r.useEffect(()=>{if(!e)return;const n=setTimeout(()=>document.querySelector(`[data-sheet-body] ${e}`)?.scrollIntoView({block:"start"}),60);return()=>clearTimeout(n)},[e])}function Ee({ticket:e,onClose:n,focus:a,children:s}){return Lr(a),t.jsx(ce,{title:`${e.key} · Details`,label:"details",tall:!0,onClose:n,children:t.jsx("div",{"data-phone-details":e.key,className:"-mx-4 [&>article]:rounded-none [&>article]:border-0 [&>article]:shadow-none",children:s})})}function sa({ticket:e,onClose:n,children:a}){return t.jsx(ce,{title:`${e.key} · Conversation`,label:"chat",tall:!0,onClose:n,children:t.jsx("div",{className:"pt-1",children:a})})}const ra=e=>(e.chat||[]).length;function la(e,n,a){return n.fixRequestAllowed(e)?[{id:"fix",label:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"max-[379px]:hidden",children:"Request fix"}),t.jsx("span",{className:"hidden max-[379px]:inline",children:"Fix"})]}),icon:H.fix,tone:"fix",onClick:()=>a("fix")}]:[]}function Fr({ticket:e,active:n,onUpdate:a,kit:s}){s.useTicketRefresh(e,a);const l=s.useGallery(e),{sheet:i,open:o,close:c}=$e(),d=!!(e.cancel&&!e.cancel.ack_error),m=s.openFixRequest(e),p=m?null:s.fixOutcome(e),u=s.mergePlan(e.prs),g=Ot(e),h=(e.prs||[]).reduce((x,j)=>({files:x.files+(j.changed_files||0),add:x.add+(j.additions||0),del:x.del+(j.deletions||0)}),{files:0,add:0,del:0}),$=d?{kind:"muted",label:e.cancel.acked_at?"Cancelled":"Cancel requested"}:m?{kind:"warn",icon:H.fix,label:m.acked_at?"Fix in progress":"Fix requested"}:e.hold?{kind:"bad",icon:ae,label:"On hold"}:p?.kind==="failed"?{kind:"bad",icon:ae,label:"Fix failed, needs you"}:{kind:"ok",label:"Ready to merge"},N=d?null:m?t.jsx(et,{children:"Do not merge yet: you requested a fix."}):e.hold?t.jsxs(et,{children:["On hold, do not merge. ",e.hold]}):null,b=!!(m||e.hold),f=d||!u.length?null:u.length===1?{id:"github",label:`Open ${De(u[0].pr)}`,icon:H.open,href:u[0].pr.url,muted:b}:{id:"github",label:`Open ${u.length} PRs`,icon:H.open,onClick:()=>o("details:[data-github-links]"),muted:b};return t.jsxs("article",{"data-phone-card":"merge","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:$,dates:We(e),summary:e.plain?.improves?null:e.title,chips:t.jsx(Ge,{ticket:e,kit:s})}),t.jsxs(ke,{keepAll:!0,hug:g.length>0,className:"mt-2 px-4",onMore:()=>o("details"),children:[t.jsx(J,{label:"What improves",strong:!0,children:e.plain?.improves}),t.jsx(J,{label:"Problem it solves",children:e.plain?.problem}),t.jsx(J,{label:"How it solves it",children:e.plain?.how}),!e.plain?.problem&&!e.plain?.how&&e.plain?.improves&&t.jsx("p",{className:"mt-2.5 text-[15px] text-gray-700",children:e.title})]}),u.length>0&&t.jsxs("p",{"data-phone-prs":!0,className:"shrink-0 truncate px-4 pb-2 pt-1 text-xs text-gray-500",children:[u.map(({pr:x})=>De(x)).join(", ")," · ",h.files," files",t.jsxs("span",{className:"text-emerald-700",children:[" +",h.add]}),t.jsxs("span",{className:"text-red-700",children:[" −",h.del]})]}),g.length>0&&t.jsx(Bt,{grow:!0,children:t.jsx(Pt,{grow:!0,images:g,onOpen:l.openProof,eager:n})}),N,t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},{id:"chat",label:"Chat",icon:H.chat,badge:ra(e),onClick:()=>o("chat")},...d?[]:la(e,s,o)],primary:f}),t.jsx(ot,{children:l.viewer}),i?.startsWith("details")&&t.jsx(Ee,{ticket:e,onClose:c,focus:i.split(":")[1],children:t.jsx(s.MergeCard,{ticket:e,proofSize:"small",onUpdate:a})}),i==="chat"&&t.jsx(sa,{ticket:e,onClose:c,children:t.jsx(s.TicketThread,{ticket:e,onUpdate:a,locked:d,onOpenImage:l.openShot,hint:"Chat is for questions. It never merges or changes the fix: use Request a fix for that."})}),i==="fix"&&t.jsx(ce,{title:`${e.key} · Request a fix`,label:"fix",onClose:c,children:t.jsx(s.FixRequestBar,{ticket:e,onUpdate:a,startOpen:!0,onDone:c})})]})}function Dr({ticket:e,active:n,onUpdate:a,kit:s}){s.useTicketRefresh(e,a);const l=s.useGallery(e),{sheet:i,open:o,close:c}=$e(),d=e.decision||{},m=s.recommendedLetter(d),p=!!(e.cancel&&!e.cancel.ack_error),u=s.openFixRequest(e),g=p||!!u,h=!!(e.answer?.acked_at&&!e.answer.ack_error),[$,N]=r.useState(null),[b,f]=r.useState(!1),[x,j]=r.useState(null),S=Ot(e),B=d.options||[],k=!g&&!e.answer&&B.length>0,E=ea(),R=async()=>{f(!0),j(null);try{const M=await aa("/api/admin/pipeline/answer",{key:e.key,option:$,text:""});E(e.key,`${e.key}: option ${$} sent to the pipeline`),a(M.ticket)}catch(M){j(M.message)}finally{f(!1)}},F=p?{kind:"muted",label:"Cancel requested"}:u?{kind:"warn",icon:H.fix,label:"Fix requested"}:e.answer?{kind:"ok",label:h?"Answer posted":"Answered"}:{kind:"info",label:"Needs decision"},A=k?{id:"answer",label:b?"Sending…":$?`Send ${$}`:`Pick ${B.map(M=>M.letter).join(" or ")}`,icon:H.check,onClick:R,disabled:b||!$}:!g&&!h?{id:"answer",label:e.answer?"Change answer":"Answer",icon:H.check,onClick:()=>o("details"),muted:!!e.answer}:null;return t.jsxs("article",{"data-phone-card":"decide","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:F,dates:We(e),lines:5,summary:d.question||"This ticket needs your decision. The question is on the Jira ticket.",chips:t.jsx(Ge,{ticket:e,kit:s})}),k&&t.jsxs("div",{role:"radiogroup","aria-label":"Options","data-phone-options":!0,className:"mt-2 shrink-0 space-y-1.5 px-4",children:[B.map(M=>{const W=$===M.letter;return t.jsxs("button",{type:"button",role:"radio","aria-checked":W,"data-option":M.letter,onClick:()=>N(W?null:M.letter),className:`flex min-h-[44px] w-full items-center gap-2.5 rounded-xl border px-2.5 py-1.5 text-left ${W?"border-indigo-500 bg-indigo-50 ring-1 ring-indigo-500":"border-gray-200"}`,children:[t.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-xs font-bold ${W?"bg-indigo-600 text-white":"bg-gray-100 text-gray-600"}`,children:M.letter}),t.jsx("span",{className:"line-clamp-2 min-w-0 flex-1 text-sm font-medium leading-snug text-gray-900",children:M.label}),M.letter===m&&t.jsx("span",{className:"shrink-0 rounded-full bg-emerald-50 px-1.5 py-0.5 text-[10px] font-semibold text-emerald-700 ring-1 ring-inset ring-emerald-600/20",children:"Recommended"})]},M.letter)}),x&&t.jsx("p",{role:"alert",className:"text-sm text-red-700",children:x})]}),e.answer&&t.jsx("div",{className:"mt-2 shrink-0 px-4",children:t.jsx(s.AnswerStatus,{answer:e.answer})}),t.jsxs(ke,{className:"mt-2 px-4",onMore:()=>o("details"),children:[d.recommendation&&m&&t.jsx(J,{label:"Why recommended",children:na(d.recommendation.replace(/^\s*[A-Z]\b[\s:.,-]*/,""))}),d.context?.length>0&&t.jsx(J,{label:"Why you are asked",children:t.jsx("ul",{className:"list-disc space-y-0.5 pl-4 text-sm",children:d.context.map((M,W)=>t.jsx("li",{children:M},W))})}),B.length>0&&!k&&t.jsx(J,{label:"Options",children:B.map(M=>t.jsxs("span",{className:"block text-sm",children:[M.letter,". ",M.label]},M.letter))})]}),S.length>0&&t.jsx(Bt,{children:t.jsx(Pt,{images:S,onOpen:l.openProof,eager:n})}),p?null:u?t.jsx(et,{tone:"warn",children:"Fix requested: it answers this decision."}):null,t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},{id:"chat",label:"Chat",icon:H.chat,badge:ra(e),onClick:()=>o("chat")},...d.question?[]:[{id:"jira",label:"Jira",icon:H.open,href:ze+e.key}],...p||!d.question?[]:la(e,s,o)],primary:A}),t.jsx(ot,{children:l.viewer}),i==="details"&&t.jsx(Ee,{ticket:e,onClose:c,focus:!g&&!h?"[data-send-answer]":null,children:t.jsx(s.DecisionCard,{ticket:e,onAnswered:a,onUpdate:a,proofSize:"small"})}),i==="chat"&&t.jsx(sa,{ticket:e,onClose:c,children:t.jsx(s.TicketThread,{ticket:e,onUpdate:a,locked:p,onOpenImage:l.openShot,hint:"Chat is for questions. It never decides: send your decision with the form, or use Request a fix."})}),i==="fix"&&t.jsx(ce,{title:`${e.key} · Request a fix`,label:"fix",onClose:c,children:t.jsx(s.FixRequestBar,{ticket:e,onUpdate:a,startOpen:!0,onDone:c})})]})}const qr=e=>`$${e.toFixed(2)}`;function Ir({ticket:e,onUpdate:n,kit:a}){const{sheet:s,open:l,close:i}=$e(),o=e.manual||{},c=a.mergePlan(e.prs)[0]?.pr;return t.jsxs("article",{"data-phone-card":"manual","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:{kind:"bad",icon:Mt,label:"Stopped over budget"},dates:qe(o.stopped_at),summary:e.plain?.improves||e.title||e.plain?.problem,chips:t.jsx(Ge,{ticket:e,kit:a})}),t.jsxs(ke,{className:"mt-2 px-4",onMore:()=>l("details"),children:[t.jsxs(J,{label:"Automation spent",children:[t.jsx("span",{className:"font-semibold tabular-nums",children:o.spend_usd==null?"not metered":qr(o.spend_usd)}),t.jsxs("span",{className:"text-sm text-gray-500",children:[" ",[o.leg_kind&&`on its ${o.leg_kind} round`,o.spend_note].filter(Boolean).join(", ")]})]}),t.jsx(J,{label:"Why it stopped",children:t.jsx("span",{className:"whitespace-pre-line",children:o.reason})})]}),t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>l("details")},{id:"jira",label:"Jira",icon:H.open,href:ze+e.key},...c?[{id:"pr",label:De(c),icon:H.open,href:c.url}]:[]],primary:e.plan?.on?{id:"plan",label:"Plan a test",icon:Ie,onClick:()=>l("plan")}:null}),s==="details"&&t.jsx(Ee,{ticket:e,onClose:i,children:t.jsx(a.ManualList,{tickets:[e],onUpdate:n})}),s==="plan"&&t.jsxs(ce,{title:`${e.key} · Plan a cheaper test`,label:"plan",tall:!0,onClose:i,children:[t.jsx(a.StrategyBlock,{strategy:e.plan.strategy}),t.jsx(a.PlanThread,{ticket:e,onUpdate:n,manual:!0})]})]})}function Zr({ticket:e,active:n,onUpdate:a,kit:s}){const l=s.useGallery(e),{sheet:i,open:o,close:c}=$e(),d=e.queue==="cancelled",m=s.mergePlan(e.prs)[0]?.pr,p=Ot(e);return t.jsxs("article",{"data-phone-card":"shipped","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:d?{kind:"muted",label:`Cancelled ${qe(e.cancelled_at)}`}:{kind:"ok",label:`Merged ${qe(e.merged_at)}`},dates:We(e),summary:e.plain?.improves?null:e.title,chips:t.jsx(Ge,{ticket:e,kit:s})}),t.jsxs(ke,{keepAll:!0,hug:p.length>0,className:"mt-2 px-4",onMore:()=>o("details"),children:[d&&e.cancel?.reason&&t.jsx(J,{label:"Why cancelled",children:e.cancel.reason}),t.jsx(J,{label:"What improved",strong:!0,children:e.plain?.improves}),t.jsx(J,{label:"Problem it solved",children:e.plain?.problem}),t.jsx(J,{label:"How it solved it",children:e.plain?.how}),(e.prs||[]).length>0&&t.jsx(J,{label:"PRs",children:s.mergePlan(e.prs).map(({pr:u})=>`${De(u)}${d?" (closed)":""}`).join(", ")})]}),p.length>0&&t.jsx(Bt,{grow:!0,children:t.jsx(Pt,{grow:!0,images:p,onOpen:l.openProof,eager:n})}),t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},{id:"jira",label:"Jira",icon:H.open,href:ze+e.key}],primary:m?{id:"pr",label:`Open ${De(m)}`,icon:H.open,href:m.url,muted:!0}:null}),t.jsx(ot,{children:l.viewer}),i==="details"&&t.jsx(Ee,{ticket:e,onClose:c,children:t.jsx(s.ShippedList,{tickets:[e],onUpdate:a})})]})}function Hr({ticket:e,onUpdate:n,kit:a}){const{sheet:s,open:l,close:i}=$e(),o=a.latestDirective(e.chat);return t.jsxs("article",{"data-phone-card":"building","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:{kind:"warn",icon:H.fix,label:o?`Fix in progress since ${qe(o.at)}`:"Fix in progress"},dates:We(e),summary:e.plain?.improves||e.title,chips:t.jsx(Ge,{ticket:e,kit:a})}),t.jsxs(ke,{className:"mt-2 px-4",onMore:()=>l("details"),children:[t.jsx(J,{label:"Where it stands",children:a.FIX_STAGE_TEXT[e.fix_round?.stage]||"The fix round is building. It comes back to Ready to merge once re-checked."}),o&&t.jsx(J,{label:"Your request",children:o.text})]}),t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>l("details")},{id:"jira",label:"Jira",icon:H.open,href:ze+e.key}]}),s==="details"&&t.jsx(Ee,{ticket:e,onClose:i,children:t.jsx(a.BuildingList,{tickets:[e],onUpdate:n})})]})}const Wr={merge:Fr,decide:Dr,manual:Ir,shipped:Zr,building:Hr};function zr({items:e,empty:n,onUpdate:a,kit:s}){return t.jsx(ta,{items:e,empty:n,renderPage:(l,i)=>{const o=Wr[l.kind];return t.jsx(o,{ticket:l.ticket,active:i,onUpdate:a,kit:s})}})}function Me(e,n){return e.map(a=>({key:a.key,kind:n==="shipped"||n==="building"||n==="manual"||n==="decide"?n:"merge",ticket:a,summary:n==="decide"?a.decision?.question||a.title:a.plain?.improves||a.title||a.key}))}const un={pending:e=>e.max_related?{kind:"warn",label:"Costs MAX runs · awaits you"}:{kind:"muted",label:"No MAX cost"},later:e=>({kind:"muted",label:`Later · since ${qe(e.gate_at)}`}),validated:e=>e.gate_jira_at?{kind:"ok",label:"Validated · in the fix queue"}:{kind:"warn",label:"Validated · not queued yet"},auto:()=>({kind:"muted",label:"Flows on its own"}),dismissed:()=>({kind:"muted",label:"Dismissed"})};function Gr({ticket:e,gate:n,sel:a,onUpdate:s,kit:l}){const{sheet:i,open:o,close:c}=$e(),[d,m]=r.useState(null),[p,u]=r.useState(null),[g,h]=r.useState(!1),$=e.gate==="pending"||e.gate==="later",N=!!(e.merge&&!e.merge.done_at),b=e.merge?.blocks||[],f=n.planHostOf(e),x=ea(),j=pr(),S=async k=>{m(k),u(null);try{const E=await aa("/api/admin/pipeline/gate",{key:e.key,action:k});x(e.key,`${e.key}: ${{validate:"validated, sent to the fix queue",later:"moved to Later",back:"back to waiting"}[k]}`),s(E.ticket)}catch(E){u(E.message)}finally{m(null)}},B=e.gate==="later";return t.jsxs("article",{"data-phone-card":"gate","data-ticket":e.key,"data-gate":e.gate,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,select:n.mergeable(e)?t.jsx(kr,{ticketKey:e.key,selected:a.isSel(e.key),disabled:a.full,onToggle:()=>a.toggle(e.key)}):null,pill:(un[e.gate]||un.auto)(e),dates:We(e),summary:e.title||e.key,lines:6,chips:t.jsxs("div",{"data-phone-flags":!0,className:"mt-1.5 flex h-6 items-center gap-1 overflow-hidden",children:[t.jsx(n.SourceChips,{ticket:e}),n.inPlanOf(e)&&t.jsxs("span",{className:"shrink-0 rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-800 ring-1 ring-inset ring-emerald-200",children:["In the test plan on ",n.inPlanOf(e)]})]})}),t.jsxs(ke,{className:"mt-2 px-4",onMore:()=>o("details"),children:[b.length>1?t.jsx(J,{label:`${b.length} problems`,children:b.map((k,E)=>t.jsxs("span",{className:"block text-sm",children:[E+1,". ",k.title||k.key]},k.key))}):t.jsx(J,{label:"What is wrong",children:na(e.plain?.problem||e.excerpt)}),b.length<2&&(e.claim_ids||[]).length>0&&t.jsx(J,{label:"Why it exists",children:e.claim_ids.map(k=>t.jsxs("span",{className:"block",children:["From claim ",k,"."]},k))}),e.gate!=="pending"&&t.jsx(J,{label:"Cost",children:e.max_related?"Uses MAX: fixing it and checking the fix run real MAX conversations.":"Uses MAX: no. It goes to the fix queue on its own."}),e.gate_note&&t.jsx(J,{label:"Reason",children:e.gate_note})]}),f&&n.renderPlanEntry&&t.jsx("div",{className:"shrink-0 px-4 [&_button]:min-h-[44px]",children:n.renderPlanEntry(e)}),p&&t.jsx("p",{role:"alert",className:"mx-4 mt-1 shrink-0 text-sm text-red-700",children:p}),(e.gate_jira_error||e.merge&&!e.merge.done_at&&e.merge.error)&&t.jsx(et,{children:"Jira was not updated. Retry in Details."}),t.jsx(Ce,{actions:$?[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},B?{id:"back",label:d==="back"?"Moving…":"Back",icon:Ln,onClick:()=>S("back"),disabled:!!d}:{id:"later",label:d==="later"?"Moving…":"Later",icon:H.later,onClick:()=>S("later"),disabled:!!d},{id:"dismiss",label:"Dismiss",icon:H.dismiss,tone:"danger",onClick:()=>h(!0),disabled:!!d||N}]:[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},{id:"jira",label:"Jira",icon:H.open,href:ze+e.key}],primary:$?{id:"validate",label:d==="validate"?"Validating…":"Validate",icon:H.check,disabled:!!d||N,onClick:()=>j?j({text:`Validating ${e.key}…`,run:()=>S("validate")}):S("validate")}:null}),g&&t.jsx(ot,{children:t.jsx(n.DismissDialog,{ticket:e,onClose:()=>h(!1),onDone:k=>{x(e.key,`${e.key}: dismissed`),s(k)}})}),i==="details"&&t.jsx(Ee,{ticket:e,onClose:c,children:n.renderDetails(e)})]})}function Xr({lists:e,gate:n,sel:a,bundleCount:s,renderBundles:l,onUpdate:i,dialogs:o}){const[c,d]=r.useState(!1),m=()=>d(!1),u=["pending","later","validated","auto","dismissed"].flatMap($=>e[$].map(N=>({key:N.key,ticket:N,summary:N.title||N.key}))),g=a.selected,h=!!a.onPlan&&g.length>0&&g.every($=>$.plan?.on);return t.jsxs(t.Fragment,{children:[g.length>0?t.jsxs(rn,{children:[t.jsxs("p",{"data-phone-selected":!0,className:"min-w-0 flex-1 truncate text-sm font-semibold text-gray-900",children:[g.length," selected"]}),t.jsx(jt,{onClick:a.onClear,className:"ring-0 text-gray-500",children:"Clear"}),h&&t.jsxs(jt,{"data-plan-open":!0,onClick:a.onPlan,children:[t.jsx(Ie,{className:"h-4 w-4","aria-hidden":!0}),"Plan"]}),t.jsx(jt,{primary:!0,"data-merge-open":!0,onClick:a.onMerge,disabled:g.length<2,children:"Merge"})]}):s>0?t.jsx(rn,{children:t.jsxs("button",{type:"button","data-phone-bundles":!0,onClick:()=>d(!0),className:"flex min-h-[44px] min-w-0 flex-1 items-center gap-2 rounded-lg px-1 text-left text-sm font-medium text-gray-800",children:[t.jsx(H.bundles,{className:"h-5 w-5 shrink-0 text-emerald-600","aria-hidden":!0}),t.jsxs("span",{className:"truncate",children:[s," suggested bundle",s===1?"":"s"]}),t.jsx("span",{className:"ml-auto shrink-0 text-indigo-700",children:"Review"})]})}):null,t.jsx(ta,{items:u,empty:t.jsx("p",{className:"rounded-xl border border-dashed border-gray-300 bg-white px-4 py-10 text-center text-sm text-gray-500",children:"No MAX fix is waiting for your validation."}),renderPage:$=>t.jsx(Gr,{ticket:$.ticket,gate:n,sel:a,onUpdate:i})}),c&&t.jsx(ce,{title:"Suggested bundles",label:"bundles",tall:!0,onClose:m,children:t.jsx("div",{className:"-mx-4 pt-1",children:l(m)})}),o]})}const Jr="max-go",Vr=10,mn=300;function Ye(e){return!!e&&e.queue==="backlog"&&!e.merged_into&&["pending","later","auto"].includes(e.gate)&&!(e.labels||[]).includes(Jr)&&!(e.merge&&!e.merge.done_at)}function dt(e,n=e){const a=Math.max(0,e-1);if(!a)return"";const s=a===1?"":"s";return`Saves ${a} fix round${s} and ${a} exam${s}: one round and one exam cover ${n===2?"both":`all ${n}`} problems.`}const Yr=e=>{const n=e?new Date(e):null;return n&&!Number.isNaN(n.getTime())?n.toLocaleDateString("en-GB",{day:"numeric",month:"short"}):null};function ct({strategy:e}){if(!e)return null;const n=Yr(e.agreed_at);return t.jsxs("section",{"data-strategy":!0,"aria-label":"Agreed test strategy",className:"mt-4 rounded-lg border border-emerald-200 bg-emerald-50/60 p-3 sm:p-4",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[t.jsx(Ie,{className:"h-4 w-4 text-emerald-700","aria-hidden":!0}),t.jsx("h4",{className:"text-sm font-semibold text-emerald-900",children:"Agreed test strategy"}),t.jsxs("span",{className:"text-xs text-emerald-800/80",children:[n?`agreed ${n}, `:"","binding for the next fix round and exam"]})]}),t.jsxs("dl",{className:"mt-2.5 grid grid-cols-3 gap-2 font-mono text-[13px]",children:[t.jsxs("div",{"data-strategy-field":"max_fix_runs",className:"rounded-md bg-white/80 px-2 py-1.5 ring-1 ring-inset ring-emerald-100",children:[t.jsx("dt",{className:"text-[11px] text-emerald-800/80",children:"max_fix_runs"}),t.jsx("dd",{className:"font-semibold tabular-nums text-gray-900",children:e.max_fix_runs})]}),t.jsxs("div",{"data-strategy-field":"max_exam_runs",className:"rounded-md bg-white/80 px-2 py-1.5 ring-1 ring-inset ring-emerald-100",children:[t.jsx("dt",{className:"text-[11px] text-emerald-800/80",children:"max_exam_runs"}),t.jsx("dd",{className:"font-semibold tabular-nums text-gray-900",children:e.max_exam_runs})]}),t.jsxs("div",{"data-strategy-field":"budget_usd",className:"rounded-md bg-white/80 px-2 py-1.5 ring-1 ring-inset ring-emerald-100",children:[t.jsx("dt",{className:"text-[11px] text-emerald-800/80",children:"budget_usd"}),t.jsxs("dd",{className:"font-semibold tabular-nums text-gray-900",children:["$",Number(e.budget_usd).toFixed(2)]})]})]}),t.jsx("p",{className:"mt-2.5 font-mono text-[11px] text-emerald-800/80",children:"scenarios"}),t.jsx("ol",{"data-strategy-field":"scenarios",className:"mt-1 list-decimal space-y-1 pl-5 text-sm leading-snug text-gray-800",children:(e.scenarios||[]).map((a,s)=>t.jsx("li",{children:a},s))})]})}function ia(e){return[...e||[]].filter(n=>n.role==="assistant"&&n.plan_close).sort((n,a)=>new Date(n.at)-new Date(a.at)).pop()||null}function Kr({message:e}){const n=e?.plan_close;if(!n)return null;const a=(n.tickets||[]).filter(l=>l!==n.survivor);let s;return n.mode==="manual"?s=`Plan recorded: ${n.survivor} goes back to the queue under this strategy.`:n.merge_error?s=`Plan recorded on ${n.tickets.join(", ")}, but the merge failed: ${n.merge_error}`:n.merged_at?s=`Plan recorded: ${a.join(", ")} merged into ${n.survivor}. Validate ${n.survivor} to start it.`:a.length?s=`Plan recorded on ${n.tickets.join(", ")}; merging them…`:s=`Plan recorded on ${n.survivor}. Validate it to start it.`,t.jsx("p",{"data-plan-outcome":!0,role:"status",className:`mt-3 rounded-lg px-3 py-2 text-sm ${n.merge_error?"bg-red-50 text-red-900":"bg-emerald-50 text-emerald-900"}`,children:s})}const vt=e=>`$${(Math.round((e||0)*10)/10).toFixed(1)}`,Ur=/^(MAX claims ground-truth correction|Feature from claims page):\s*/i,Qr=e=>(e||"").replace(Ur,""),xn=e=>parseInt(String(e).split("-")[1],10)||0,Lt=e=>[...e||[]].sort((n,a)=>new Date(n.at)-new Date(a.at)),el='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function tt(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function hn(e,n){return n?.keys?.length?n.keys[0]:[...e].sort((a,s)=>xn(a)-xn(s))[0]}function oa(e){const n=Lt(e).filter(a=>a.role==="assistant"&&!a.plan_close);for(let a=n.length-1;a>=0;a-=1){const s=n[a].text||"",l=[...s.matchAll(/^[\s*>_-]*tickets\W*:(.*)$/gim)].pop(),i=l?[...new Set(l[1].split("(")[0].match(/[A-Z][A-Z0-9]+-\d+/g)||[])]:[],o=[...s.matchAll(/^[\s*>_-]*survivor\W*:\W*([A-Z][A-Z0-9]+-\d+)/gim)].pop()?.[1];if(i.length)return{keys:i,survivor:i.includes(o)?o:i[0]}}return null}function tl(e){const n=[document.documentElement];for(let a=e?.parentElement;a&&a!==document.body;a=a.parentElement)/(auto|scroll)/.test(getComputedStyle(a).overflowY)&&n.push(a);return n}function nl(e,n){const a=r.useRef(n);a.current=n,r.useEffect(()=>{const s=document.activeElement,l=tl(e.current).map(o=>({el:o,overflow:o.style.overflowY}));l.forEach(({el:o})=>{o.style.overflowY="hidden"}),e.current?.focus({preventScroll:!0});const i=o=>{if(document.querySelector("[data-lightbox]"))return;if(o.key==="Escape"){o.preventDefault(),a.current();return}if(o.key!=="Tab"||!e.current)return;const c=[...e.current.querySelectorAll(el)].filter(u=>u.offsetParent!==null);if(!c.length)return;const d=c[0],m=c[c.length-1],p=e.current.contains(document.activeElement);o.shiftKey&&(document.activeElement===d||!p||document.activeElement===e.current)?(o.preventDefault(),m.focus()):!o.shiftKey&&(document.activeElement===m||!p)&&(o.preventDefault(),d.focus())};return document.addEventListener("keydown",i),()=>{document.removeEventListener("keydown",i),l.forEach(({el:o,overflow:c})=>{o.style.overflowY=c}),s&&document.contains(s)&&s.focus({preventScroll:!0})}},[e])}function Ke({children:e}){return t.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:e})}function al({keys:e,plan:n,changed:a,group:s,ticketOf:l}){const i=s?.mode==="relevance",{keys:o,survivor:c}=n,d=[c,...o.filter(m=>m!==c),...e.filter(m=>!o.includes(m))];return t.jsxs("div",{className:"space-y-5",children:[t.jsxs("section",{"aria-labelledby":"plan-tickets",children:[t.jsx(Ke,{children:t.jsxs("span",{id:"plan-tickets",children:[o.length," ticket",o.length===1?"":"s",a?", as the pipeline now proposes":""]})}),a&&t.jsx("p",{"data-plan-changed":!0,role:"status",className:"mt-1 text-sm leading-relaxed text-gray-700",children:"The conversation changed the suggestion. Agreeing now means agreeing to this version."}),t.jsx("ul",{"data-plan-tickets":!0,className:"mt-2 divide-y divide-gray-100 rounded-xl border border-gray-200",children:d.map(m=>{const p=l(m),u=m===c,g=!o.includes(m),h=!e.includes(m);return t.jsxs("li",{"data-plan-ticket":m,"data-plan-ticket-state":g?"left-out":h?"added":"in",className:"flex flex-wrap items-start gap-x-3 gap-y-1 px-3.5 py-2.5 sm:flex-nowrap",children:[t.jsx("span",{className:"mt-0.5 shrink-0 font-mono text-xs text-gray-500 sm:w-[5.75rem]",children:m}),t.jsx("span",{className:`order-last min-w-0 basis-full text-sm leading-snug sm:order-none sm:flex-1 sm:basis-auto ${g?"text-gray-500 line-through decoration-gray-400":"text-gray-900"}`,children:Qr(p?.title)||m}),g&&t.jsx("span",{title:"The pipeline proposes to test this one on its own",className:"ml-auto shrink-0 rounded-full bg-gray-100 px-2 py-0.5 text-[11px] font-semibold text-gray-600 sm:ml-0",children:"Left out"}),h&&!u&&t.jsx("span",{className:"ml-auto shrink-0 rounded-full bg-emerald-100 px-2 py-0.5 text-[11px] font-semibold text-emerald-900 sm:ml-0",children:"Added"}),u&&t.jsx("span",{"data-plan-kept":!0,title:"This ticket stays open. The others merge into it as extra problems.",className:"ml-auto shrink-0 rounded-full bg-gray-900 px-2 py-0.5 text-[11px] font-semibold text-white sm:ml-0",children:"Stays"})]},m)})})]}),t.jsxs("div",{className:"grid gap-5 sm:grid-cols-[1fr_11rem]",children:[t.jsxs("section",{"aria-labelledby":"plan-why",className:"min-w-0 space-y-3",children:[t.jsx(Ke,{children:t.jsx("span",{id:"plan-why",children:"Why together"})}),t.jsxs("p",{"data-plan-why":!0,className:"text-sm leading-relaxed text-gray-800",children:[s?t.jsxs(t.Fragment,{children:[e.length===2?"Both change":"They all change"," one part of MAX",s.name?t.jsxs(t.Fragment,{children:[": ",t.jsx("span",{className:"font-medium",children:s.name})]}):"",". One fix round and one test can cover them."]}):"You picked them together. The pipeline checks whether one fix round and one test can cover them.",i&&" The pipeline thinks they may already be fixed, so the test mainly checks that."]}),s?.scenario&&t.jsxs("p",{"data-plan-scenario":!0,className:"text-sm leading-relaxed text-gray-800",children:[t.jsx("span",{className:"font-medium text-gray-900",children:"The shared test:"})," ",s.scenario]}),s?.surface&&t.jsxs("details",{"data-plan-surface":!0,className:"group text-xs leading-relaxed text-gray-600",children:[t.jsx("summary",{className:"cursor-pointer select-none font-medium text-gray-600 hover:text-gray-900",children:"The code they share"}),t.jsx("p",{className:"mt-1 [overflow-wrap:anywhere]",children:s.surface})]})]}),t.jsxs("section",{"aria-labelledby":"plan-saving","data-plan-saving":!0,className:"self-start rounded-xl bg-emerald-50 px-4 py-3 ring-1 ring-inset ring-emerald-100",children:[t.jsx(Ke,{children:t.jsx("span",{id:"plan-saving",children:a?"First estimate":"Estimated saving"})}),s?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:`mt-1 font-semibold tabular-nums text-emerald-900 ${a?"text-base":"text-2xl"}`,children:["~",vt(s.est.savings_usd)]}),t.jsxs("p",{className:"mt-0.5 text-xs tabular-nums leading-relaxed text-emerald-900/80",children:[vt(s.est.bundle_usd)," together instead of ",vt(s.est.apart_usd)," apart",i?", if fixed":""]})]}):t.jsx("p",{className:"mt-1 text-sm leading-relaxed text-emerald-900",children:dt(o.length)}),a&&s&&t.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-emerald-900/80",children:"For the first suggestion. The latest reply gives its own estimate."})]})]})]})}function sl({close:e,survivorTicket:n}){const a=(e.tickets||[]).filter(o=>o!==e.survivor),s=!!e.merge_error,l=n?.plan?.strategy||e.strategy;let i;return e.mode==="manual"?i=`Plan agreed: ${e.survivor} goes back to the queue`:s?i="Plan agreed, but the merge did not go through":e.merged_at?i=a.length?`Merged into ${e.survivor}`:`Plan agreed on ${e.survivor}`:i=a.length?`Merging into ${e.survivor}…`:`Plan agreed on ${e.survivor}`,t.jsxs("section",{"data-plan-result":s?"error":e.merged_at?"merged":"pending","aria-live":"polite",className:"space-y-4",children:[t.jsxs("div",{className:`flex gap-3 rounded-xl px-4 py-3.5 ring-1 ring-inset ${s?"bg-red-50 ring-red-200":"bg-emerald-50 ring-emerald-200"}`,children:[s?t.jsx(ae,{className:"mt-0.5 h-5 w-5 shrink-0 text-red-600","aria-hidden":!0}):t.jsx(Ze,{className:"mt-0.5 h-5 w-5 shrink-0 text-emerald-600","aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 text-sm leading-relaxed",children:[t.jsx("p",{className:`font-semibold ${s?"text-red-900":"text-emerald-900"}`,children:i}),s?t.jsxs("p",{className:"text-red-900 [overflow-wrap:anywhere]",children:[e.merge_error," The strategy is recorded on each ticket; you can still merge them with the merge button."]}):e.mode==="manual"?t.jsx("p",{className:"text-emerald-900",children:"The next fix round and test follow the strategy below."}):t.jsxs("p",{className:"text-emerald-900",children:[a.length?t.jsxs(t.Fragment,{children:[tt(a)," ",a.length>1?"are":"is"," now part of ",e.survivor,". "]}):null,"It waits in ",t.jsx("span",{className:"font-medium",children:"Awaiting validation"})," as ",e.survivor,": validate it there to start one fix round and one test under the strategy below."]})]})]}),t.jsx(ct,{strategy:l})]})}function rl({keys:e,group:n,host:a,opening:s,error:l,ticketOf:i,renderPlan:o,onUpdate:c,onClose:d,onDismiss:m,onShow:p}){const u=r.useRef(null),g=r.useRef(null);nl(u,d);const[h,$]=r.useState(!1);r.useEffect(()=>{const D=requestAnimationFrame(()=>$(!0));return()=>cancelAnimationFrame(D)},[]);const[N,b]=r.useState(null),[f,x]=r.useState(null),j=ia(a?.chat)?.plan_close||null,S=Lt(a?.chat),B=rt(S),k=oa(a?.chat),E=k||{keys:e,survivor:hn(e,n)},R=!!k&&(k.keys.length!==e.length||k.keys.some(D=>!e.includes(D))||k.survivor!==hn(e,n)),F=j?.survivor||E.survivor,A=E.keys.filter(D=>D!==F),M=a&&o?r.cloneElement(o(a),{inModal:!0}):null,W=r.useRef(null);r.useEffect(()=>{S.length&&g.current&&(g.current.scrollTop=g.current.scrollHeight)},[!!a]),r.useEffect(()=>{const D=S.length+(B?1:0);W.current!=null&&D!==W.current&&g.current&&g.current.scrollTo({top:g.current.scrollHeight,behavior:"smooth"}),W.current=D},[S.length,B]);const v=async()=>{b("agree"),x(null);const D=`Agreed${k?", with your last proposal":""}. ${A.length?`Merge ${tt(A)} into ${F} and test them as one.`:`Test ${F} on its own, as proposed.`}`;try{const Z=await fetch("/api/admin/pipeline/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:a.key,text:D})}),I=await Z.json().catch(()=>({}));if(!Z.ok)throw new Error(I.error||`Could not send (${Z.status})`);c(I)}catch(Z){x(Z.message)}finally{b(null)}},C=async()=>{b("dismiss"),x(null);try{await m(n),d()}catch(D){x(D.message),b(null)}},O=j?"Test plan agreed":A.length?`Test these ${E.keys.length} tickets as one`:`Test ${F} on its own`,y=A.length?`Agree: merge into ${F} and test as one`:`Agree: test ${F} on its own`,_="inline-flex min-h-[44px] items-center justify-center gap-1.5 whitespace-nowrap rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",L="inline-flex min-h-[44px] items-center justify-center whitespace-nowrap rounded-lg px-4 text-sm font-medium text-gray-800 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900";return t.jsx("div",{"data-plan-modal-backdrop":!0,className:`fixed inset-0 z-50 flex items-stretch justify-center bg-gray-950/50 transition-opacity duration-200 ease-out motion-reduce:transition-none sm:items-center sm:p-6 ${h?"opacity-100":"opacity-0"}`,onMouseDown:D=>{D.target===D.currentTarget&&!N&&d()},children:t.jsxs("div",{ref:u,role:"dialog","aria-modal":"true","aria-labelledby":"plan-modal-title",tabIndex:-1,"data-plan-modal":a?.key||"","data-plan-modal-keys":e.join(","),className:`flex h-full w-full flex-col bg-white shadow-2xl transition-transform duration-200 ease-out focus:outline-none motion-reduce:transition-none sm:h-auto sm:max-h-[min(90vh,880px)] sm:max-w-[52rem] sm:rounded-2xl sm:ring-1 sm:ring-black/5 ${h?"translate-y-0":"translate-y-2"}`,children:[t.jsxs("header",{className:"flex items-start gap-3 border-b border-gray-100 px-5 pb-4 pt-[max(1rem,env(safe-area-inset-top))] sm:px-6 sm:pt-5",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:"flex min-w-0 items-center gap-1.5 text-xs font-medium text-gray-500",children:[t.jsx(Tt,{className:"h-3.5 w-3.5 shrink-0 text-gray-400","aria-hidden":!0}),t.jsx("span",{className:"shrink-0",children:n?"Suggested by the pipeline":"Your selection"}),n?.name&&t.jsxs("span",{className:"min-w-0 truncate",children:["· ",n.name]})]}),t.jsx("h2",{id:"plan-modal-title",className:"mt-1 text-lg font-semibold leading-snug text-gray-900",children:O})]}),t.jsx("button",{type:"button","data-plan-modal-x":!0,onClick:d,"aria-label":"Close",className:"-mr-2 -mt-1 flex h-11 w-11 items-center justify-center rounded-lg text-gray-500 hover:bg-gray-100 hover:text-gray-800 sm:h-9 sm:w-9 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900",children:t.jsx(fe,{className:"h-5 w-5","aria-hidden":!0})})]}),t.jsxs("div",{ref:g,"data-plan-modal-body":!0,className:"min-h-0 flex-1 space-y-7 overflow-y-auto overscroll-contain px-5 py-5 sm:px-6",children:[j?t.jsx(sl,{close:j,survivorTicket:i(j.survivor)}):t.jsx(al,{keys:e,plan:E,changed:R,group:n,ticketOf:i}),t.jsxs("section",{"aria-labelledby":"plan-talk","data-plan-talk":!0,children:[t.jsx(Ke,{children:t.jsx("span",{id:"plan-talk",children:j?"The conversation":"Adjust it with the pipeline"})}),!j&&t.jsx("p",{className:"mt-1 text-sm leading-relaxed text-gray-600",children:"Ask why, add or drop a ticket, or change the test. The pipeline answers here in a few minutes. Nothing is merged or spent until you agree."}),M,!a&&s&&t.jsx("p",{role:"status",className:"mt-3 text-sm text-gray-500",children:"Opening the conversation…"}),l&&t.jsx("p",{role:"alert",className:"mt-3 text-sm text-red-700",children:l})]})]}),t.jsxs("footer",{className:"border-t border-gray-100 px-5 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-3 sm:px-6",children:[f&&t.jsx("p",{role:"alert",className:"mb-2 text-sm text-red-700",children:f}),!j&&R&&!B&&t.jsxs("p",{"data-plan-agree-means":!0,className:"mb-2 text-sm leading-snug text-gray-700",children:["Agree accepts the pipeline's latest proposal: ",tt(E.keys),". To change it, reply first."]}),j?t.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[t.jsx("button",{type:"button","data-plan-done":!0,onClick:d,className:L,children:"Done"}),!j.merge_error&&j.mode!=="manual"&&t.jsxs("button",{type:"button","data-plan-show":j.survivor,onClick:()=>p(j.survivor),className:_,children:["Show ",j.survivor," on the page",t.jsx(Pn,{className:"h-4 w-4","aria-hidden":!0})]})]}):t.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:flex sm:items-center",children:[t.jsxs("button",{type:"button","data-plan-agree":!0,onClick:v,disabled:!a||!!N||B,className:`${_} col-span-2 sm:order-4`,children:[t.jsx(st,{className:"hidden h-4 w-4 shrink-0 sm:block","aria-hidden":!0}),N==="agree"?"Sending…":B?"The pipeline is answering…":y]}),n&&t.jsx("button",{type:"button","data-plan-dismiss":n.id,onClick:C,disabled:!!N,title:"Hide this suggestion. The tickets stay as they are.",className:"inline-flex min-h-[44px] items-center justify-center whitespace-nowrap rounded-lg px-3 text-sm font-medium text-gray-600 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 disabled:opacity-50 sm:order-1 sm:-ml-3",children:N==="dismiss"?"Dismissing…":"Dismiss suggestion"}),t.jsx("span",{className:"hidden sm:order-2 sm:block sm:flex-1"}),t.jsx("button",{type:"button","data-plan-close":!0,onClick:d,title:"The conversation stays open: reopen it from the bundle or from the ticket card",className:`${L} sm:order-3 ${n?"":"col-span-2"}`,children:"Close for now"})]})]})]})})}function Ft(e){const n=Lt(e.chat);return{key:e.key,messages:n.length,awaiting:rt(n),lastFrom:n.length?n[n.length-1].role:null,closed:!!e.plan_thread?.closed_at,proposal:oa(n)}}const ll=30*1e3;function il(e,n,a){const s=!a&&Ft(e).awaiting;r.useEffect(()=>{if(!s)return;let l=!1;const i=async()=>{if(document.visibilityState==="visible")try{const c=await fetch(`/api/admin/pipeline/chat?key=${encodeURIComponent(e.key)}`,{cache:"no-store"});c.ok&&!l&&n(await c.json())}catch{}},o=setInterval(i,ll);return window.addEventListener("focus",i),()=>{l=!0,clearInterval(o),window.removeEventListener("focus",i)}},[s,e.key,n])}function da({host:e,onOpen:n,onUpdate:a,shown:s}){il(e,a,s);const l=Ft(e),i=(e.plan_thread?.keys||[]).filter(c=>c!==e.key);let o;return l.closed?o="Test plan agreed. The conversation is kept.":l.awaiting?o="The pipeline is answering.":l.messages?o=`${l.messages} message${l.messages===1?"":"s"}${l.lastFrom==="assistant"?", the pipeline replied.":"."}`:o="Nothing said yet.",t.jsxs("div",{"data-plan-entry":e.key,className:"mt-4 flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg bg-emerald-50/70 px-3 py-2.5 ring-1 ring-inset ring-emerald-200",children:[t.jsxs("p",{className:"min-w-0 flex-1 text-sm leading-snug text-emerald-950",children:[t.jsx("span",{className:"font-semibold",children:l.closed?"Test plan":"Test plan in discussion"}),i.length>0&&t.jsxs(t.Fragment,{children:[" with ",tt(i)]}),t.jsx("span",{className:"block text-xs text-emerald-900/80",children:o})]}),t.jsxs("button",{type:"button","data-plan-entry-open":e.key,onClick:()=>n(e),className:"inline-flex min-h-[36px] items-center gap-1 rounded-lg bg-white px-3 text-xs font-semibold text-emerald-900 ring-1 ring-inset ring-emerald-300 hover:bg-emerald-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-700",children:[l.closed?"View the plan":"Open the plan",t.jsx(Pn,{className:"h-3.5 w-3.5","aria-hidden":!0})]})]})}const ve=e=>`$${(Math.round((e||0)*10)/10).toFixed(1)}`,ol=/^(MAX claims ground-truth correction|Feature from claims page):\s*/i,dl=(e,n=64)=>{const a=(e||"").replace(ol,"");return a.length>n?`${a.slice(0,n-1).trimEnd()}…`:a};function cl(e){const n=e?new Date(e):null;return n&&!Number.isNaN(n.getTime())?n.toLocaleString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}):""}function ul(e,n){const a=e.proposal;if(a&&(a.keys.length!==n.keys.length||a.keys.some(i=>!n.keys.includes(i)))&&!e.awaiting)return`In discussion · the pipeline now proposes ${a.keys.length} ticket${a.keys.length===1?"":"s"}: ${a.keys.join(", ")}`;if(e.awaiting)return"In discussion · the pipeline is answering";if(!e.messages)return"Conversation open · nothing said yet";const l=`${e.messages} message${e.messages===1?"":"s"}`;return e.lastFrom==="assistant"?`In discussion · ${l} · the pipeline replied`:`In discussion · ${l}`}function ml({group:e,titleOf:n,active:a,canPlan:s,thread:l,onPick:i,onReview:o,onDismiss:c}){const[d,m]=r.useState(!1),[p,u]=r.useState(null),g=e.mode==="relevance",h=async N=>{N.stopPropagation(),m(!0),u(null);try{await c(e)}catch(b){u(b.message),m(!1)}},$=a||!!l;return t.jsxs("li",{"data-bundle":e.id,"data-bundle-active":a?"true":"false","data-bundle-thread":l?l.key:void 0,className:`group relative px-4 py-3.5 sm:px-5 ${$?"bg-emerald-50/70 hover:bg-emerald-50":"hover:bg-gray-50"}`,children:[t.jsxs("div",{className:"flex flex-wrap items-start gap-x-4 gap-y-2",children:[t.jsxs("div",{className:"min-w-0 flex-1 basis-80",children:[t.jsxs("p",{className:"flex flex-wrap items-center gap-1.5",children:[t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:e.name||"Bundle"}),g&&t.jsx("span",{className:"rounded-full bg-sky-50 px-2 py-0.5 text-[11px] font-medium text-sky-700 ring-1 ring-inset ring-sky-200",children:"relevance check only"})]}),t.jsx("ul",{className:"mt-1 space-y-0.5",children:e.keys.map((N,b)=>t.jsxs("li",{"data-bundle-member":N,className:"flex items-baseline gap-2 text-[13px] leading-snug text-gray-700",children:[t.jsxs("span",{className:"w-[5.5rem] shrink-0 font-mono text-[11px] text-gray-500",title:b===0?"Stays when they merge: the others join it":void 0,children:[N,b===0?" ★":""]}),t.jsx("span",{className:"min-w-0 truncate",children:dl(n(N))})]},N))}),e.surface&&t.jsxs("p",{"data-bundle-surface":!0,className:"mt-1.5 text-xs leading-relaxed text-gray-500",children:["Shared: ",e.surface]}),l&&t.jsxs("p",{"data-bundle-thread-state":!0,className:"mt-2 flex items-center gap-1.5 text-xs font-medium text-emerald-800",children:[t.jsx(Fn,{className:"h-3.5 w-3.5","aria-hidden":!0}),ul(l,e)]})]}),t.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:shrink-0 sm:flex-col sm:items-end",children:[t.jsxs("span",{"data-bundle-saves":!0,title:`Estimated MAX spend: ${ve(e.est.bundle_usd)} together vs ${ve(e.est.apart_usd)} apart (desk model, ±40%)`,className:"whitespace-nowrap rounded-full bg-emerald-100 px-2.5 py-1 text-xs font-semibold text-emerald-900",children:["saves ~",ve(e.est.savings_usd),g?" if fixed":""]}),t.jsxs("span",{className:"hidden text-[11px] tabular-nums text-gray-500 sm:inline",children:[ve(e.est.bundle_usd)," vs ",ve(e.est.apart_usd)," apart"]}),t.jsxs("div",{className:"ml-auto flex items-center gap-1 sm:ml-0",children:[t.jsx("button",{type:"button","data-bundle-dismiss":e.id,onClick:h,disabled:d,className:"relative z-10 inline-flex min-h-[36px] items-center rounded-lg px-2.5 text-xs font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800 disabled:opacity-50",children:d?"Dismissing…":"Dismiss"}),s?t.jsxs("button",{type:"button","data-bundle-review":e.id,onClick:()=>o(e),"aria-label":`${l?"Continue the plan":"Review proposal"}: ${e.name||e.keys.join(", ")}`,className:`inline-flex min-h-[36px] items-center gap-1 rounded-lg px-3 text-xs font-semibold after:absolute after:inset-0 after:content-[''] focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 ${l?"bg-gray-900 text-white group-hover:bg-gray-700":"bg-white text-gray-900 ring-1 ring-inset ring-gray-300 group-hover:bg-gray-50 group-hover:ring-gray-400"}`,children:[l?"Continue the plan":"Review proposal",t.jsx(pe,{className:"h-4 w-4","aria-hidden":!0})]}):t.jsx("button",{type:"button","data-bundle-pick":e.id,onClick:()=>i(e),"aria-pressed":a,className:"inline-flex min-h-[36px] items-center rounded-lg px-3 text-xs font-semibold text-gray-800 ring-1 ring-inset ring-gray-300 after:absolute after:inset-0 after:content-[''] hover:bg-gray-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900",children:a?"Untick them":"Tick them below"})]})]})]}),p&&t.jsx("p",{role:"alert",className:"relative z-10 mt-1 text-xs text-red-700",children:p})]})}function gn({view:e,titleOf:n,activeId:a,canPlan:s,threadOf:l,onPick:i,onReview:o,onDismiss:c}){if(!e)return null;const d=e.groups.reduce((m,p)=>m+(p.est.savings_usd||0),0);return t.jsxs("section",{"data-bundles":!0,"aria-labelledby":"gate-bundles",className:"space-y-3",children:[t.jsxs("h2",{id:"gate-bundles",className:"flex flex-wrap items-center gap-x-1 text-xs font-medium uppercase tracking-wide text-gray-400",children:[t.jsx(Tt,{className:"mr-0.5 h-3.5 w-3.5 text-gray-400","aria-hidden":!0}),"Suggested bundles",!e.stale&&e.groups.length>0&&t.jsxs("span",{className:"normal-case tracking-normal",children:[" · ",e.groups.length," · ~",ve(d)," saved if you take them all"]}),!e.stale&&e.generated_at&&t.jsxs("span",{className:"normal-case tracking-normal",children:[" · analysed ",cl(e.generated_at)]})]}),e.stale?t.jsxs("p",{"data-bundles-stale":!0,className:"flex items-center gap-2 rounded-xl border border-dashed border-gray-300 bg-white px-4 py-4 text-sm text-gray-600",children:[t.jsx(On,{className:"h-4 w-4 shrink-0 animate-spin text-gray-400","aria-hidden":!0}),"Re-analyzing… the waiting tickets changed since the last suggestions. New ones appear here on their own."]}):e.groups.length?t.jsx("ul",{className:"divide-y divide-gray-100 overflow-hidden rounded-xl border border-emerald-200 bg-white shadow-sm",children:e.groups.map(m=>t.jsx(ml,{group:m,titleOf:n,active:a===m.id,canPlan:s(m),thread:l(m),onPick:i,onReview:o,onDismiss:c},m.id))}):t.jsx("p",{"data-bundles-empty":!0,className:"rounded-xl border border-dashed border-gray-300 bg-white px-4 py-4 text-sm text-gray-500",children:"No bundle to suggest: the waiting tickets are best tested one by one."})]})}const Nt="cockpit.ticketSort",ca=r.createContext("default"),xl=ca.Provider;function hl(){const[e,n]=r.useState("default");r.useEffect(()=>{try{const s=localStorage.getItem(Nt);s&&n(Qe(s).key)}catch{}},[]);const a=r.useCallback(s=>{const l=Qe(s).key;n(l);try{l==="default"?localStorage.removeItem(Nt):localStorage.setItem(Nt,l)}catch{}},[]);return[e,a]}function pn(e){const n=e?new Date(e):null;if(!n||Number.isNaN(n.getTime()))return null;const a=n.getFullYear()===new Date().getFullYear();return n.toLocaleDateString("en-GB",{day:"numeric",month:"short",...a?{}:{year:"numeric"}})}function fn(e){return new Date(e).toLocaleString("en-GB",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})}const gl=()=>()=>{};function Se({ticket:e,className:n=""}){const a=r.useContext(ca);if(!r.useSyncExternalStore(gl,()=>!0,()=>!1))return null;const l=pn(e.jira_created),i=Qe(a).field==="jira_updated"?pn(e.jira_updated):null;return!l&&!i?null:t.jsxs("span",{"data-ticket-dates":!0,className:`shrink-0 whitespace-nowrap text-xs tabular-nums text-gray-500 ${n}`,children:[l&&t.jsxs("span",{"data-created":!0,title:`Created in Jira ${fn(e.jira_created)}`,children:["Created ",l]}),l&&i&&" · ",i&&t.jsxs("span",{"data-updated":!0,title:`Last updated in Jira ${fn(e.jira_updated)}`,children:["Updated ",i]})]})}function pl({value:e,onChange:n,className:a=""}){const s=e!=="default";return t.jsxs("div",{"data-sort-control":!0,className:`flex shrink-0 items-center gap-1.5 ${a}`,children:[t.jsxs("label",{htmlFor:"cockpit-ticket-sort",className:"inline-flex items-center gap-1 text-xs font-medium text-gray-500",children:[t.jsx(cs,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Sort"]}),t.jsxs("div",{className:"relative",children:[t.jsx("select",{id:"cockpit-ticket-sort","data-ticket-sort":e,value:e,onChange:l=>n(l.target.value),className:`min-h-[30px] cursor-pointer appearance-none rounded-full py-0 pl-3 pr-7 text-xs font-medium ring-1 ring-inset transition-colors focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-1 ${s?"bg-gray-900 text-white ring-gray-900":"bg-white text-gray-700 ring-gray-300 hover:ring-gray-400"}`,children:Ct.map(l=>t.jsx("option",{value:l.key,className:"bg-white text-gray-900",children:l.label},l.key))}),t.jsx(qn,{className:`pointer-events-none absolute right-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 ${s?"text-white/80":"text-gray-400"}`,"aria-hidden":!0})]})]})}const fl="https://magifyfun.atlassian.net/browse/",ua=7,bn=e=>parseInt(String(e).split("-")[1],10)||0,Be=(e,n)=>bn(e.key)-bn(n.key),ma=e=>e&&e.charAt(0).toUpperCase()+e.slice(1),yn=e=>(e||"").toLowerCase().replace(/[^a-z0-9]+/g," ").trim();function xa(e){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?"":n.toLocaleString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})}function bl(e){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?"":n.toLocaleDateString("en-GB",{day:"numeric",month:"short"})}function Xe({ticketKey:e}){return t.jsx("a",{href:fl+e,target:"_blank",rel:"noopener noreferrer","data-jira-key":e,className:"shrink-0 whitespace-nowrap rounded border border-gray-200 bg-gray-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-gray-500 hover:border-gray-300 hover:text-gray-800",children:e})}const yl="inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium ring-1 ring-inset";function re({kind:e,icon:n,children:a,title:s}){const l={max:"bg-amber-50 text-amber-800 ring-amber-300",nomax:"bg-gray-50 text-gray-600 ring-gray-200",source:"bg-indigo-50 text-indigo-700 ring-indigo-200",merged:"bg-violet-50 text-violet-700 ring-violet-200",later:"bg-sky-50 text-sky-700 ring-sky-200",plan:"bg-emerald-50 text-emerald-800 ring-emerald-200",ok:"bg-emerald-50 text-emerald-700 ring-emerald-600/20"}[e];return t.jsxs("span",{"data-chip":e,title:s,className:`${yl} ${l}`,children:[n&&t.jsx(n,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),a]})}function Dt({ticket:e}){const n=e.claim_ids||[],a=e.merge?.blocks?.length||0;return t.jsxs(t.Fragment,{children:[e.max_related===!0&&t.jsx(re,{kind:"max",icon:Rt,title:"Fixing and checking it runs MAX conversations",children:"Uses MAX"}),e.max_related===!1&&t.jsx(re,{kind:"nomax",title:"No MAX conversation to fix or check it",children:"No MAX cost"}),a>1&&t.jsxs(re,{kind:"merged",icon:st,children:["Merged · ",a," problems"]}),n.slice(0,3).map(s=>t.jsxs(re,{kind:"source",icon:Is,children:["Claim ",s]},s)),!n.length&&a<2&&t.jsx(re,{kind:"source",icon:As,children:"Found by the radar"})]})}function Te({label:e,children:n}){return n?t.jsxs("div",{className:"grid gap-0.5 sm:grid-cols-[8.5rem_1fr] sm:gap-4",children:[t.jsx("dt",{className:"text-xs font-medium uppercase tracking-wide text-gray-400 sm:pt-0.5",children:e}),t.jsx("dd",{className:"min-w-0 text-[15px] leading-relaxed text-gray-900 [overflow-wrap:anywhere]",children:n})]}):null}function wn({links:e}){return e?.length?t.jsx("span",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-1 text-sm",children:e.map((n,a)=>t.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"text-indigo-700 hover:text-indigo-900",children:["Evidence ",a+1]},n))}):null}function wl({ticket:e,claimsById:n}){const a=(e.claim_ids||[]).map(s=>n.get(s)||{claim_id:s});return a.length?t.jsxs("span",{className:"block space-y-2",children:[a.map(s=>t.jsxs("span",{"data-why-claim":s.claim_id,className:"block",children:[s.canonical_claim&&!yn(e.excerpt).includes(yn(s.canonical_claim))?t.jsxs(t.Fragment,{children:["MAX said: “",s.canonical_claim,"” (claim ",s.claim_id,")"]}):t.jsxs(t.Fragment,{children:["From claim ",s.claim_id,"."]}),s.vincent_ruling?.status==="wrong"&&t.jsxs("span",{className:"block text-gray-600",children:["You ruled it wrong",s.vincent_ruling.correction?`: ${s.vincent_ruling.correction}`:"."]}),s.build_request?.text&&t.jsxs("span",{className:"block text-gray-600",children:["You asked for: ",s.build_request.text]})]},s.claim_id)),t.jsx(wn,{links:e.links})]}):t.jsxs(t.Fragment,{children:["The radar found this problem in your product's signals.",t.jsx(wn,{links:e.links})]})}function jl({maxRelated:e}){return e?t.jsxs("span",{"data-cost":"max",children:[t.jsx("span",{className:"font-semibold",children:"Uses MAX: yes."})," Fixing it and checking the fix run real MAX conversations. That is what costs money, so it waits for you."]}):t.jsxs("span",{"data-cost":"none",children:[t.jsx("span",{className:"font-semibold",children:"Uses MAX: no."})," It goes to the fix queue on its own."]})}function vl({ticket:e,claimsById:n}){const a=e.merge?.blocks||[];return a.length<2?null:t.jsx("ol",{"data-merged-blocks":!0,className:"mt-1 space-y-2",children:a.map((s,l)=>t.jsxs("li",{"data-block":s.key,className:"flex gap-2.5",children:[t.jsx("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-violet-100 text-[11px] font-bold text-violet-700",children:l+1}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block text-[15px] text-gray-900",children:s.title||s.key}),t.jsxs("span",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-gray-500",children:[t.jsx(Xe,{ticketKey:s.key}),s.key===e.key?"this ticket":"closed as superseded",(s.claim_ids||[]).map(i=>{const o=n.get(i);return t.jsxs("span",{title:o?.canonical_claim||"",children:["· claim ",i]},i)}),s.max_related&&t.jsx("span",{className:"text-amber-700",children:"· uses MAX"})]})]})]},s.key))})}async function ge(e,n){const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),s=await a.json().catch(()=>({}));if(!a.ok)throw new Error(s.error||`The server answered ${a.status}`);return s}function ha(e,n){r.useEffect(()=>{const a=s=>{s.key==="Escape"&&!n&&e()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[e,n])}function ga({ticket:e,onClose:n,onDone:a}){const[s,l]=r.useState(""),[i,o]=r.useState(!1),[c,d]=r.useState(null);ha(n,i);const m=async()=>{o(!0),d(null);try{const p=await ge("/api/admin/pipeline/gate",{key:e.key,action:"dismiss",note:s});a(p.ticket),n()}catch(p){d(p.message),o(!1)}};return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-gray-950/50 p-4",onClick:()=>!i&&n(),children:t.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":`dismiss-title-${e.key}`,"data-dismiss-dialog":e.key,onClick:p=>p.stopPropagation(),className:"w-full max-w-md rounded-xl bg-white p-5 shadow-2xl",children:[t.jsxs("h2",{id:`dismiss-title-${e.key}`,className:"text-base font-semibold text-gray-900",children:["Dismiss ",e.key,"?"]}),t.jsx("p",{className:"mt-2 text-sm leading-relaxed text-gray-700",children:"The ticket closes on Jira as declined. It is not fixed, and it costs nothing."}),t.jsx("label",{htmlFor:`dismiss-note-${e.key}`,className:"mt-4 block text-sm font-medium text-gray-800",children:"Why?"}),t.jsx("textarea",{id:`dismiss-note-${e.key}`,"data-dismiss-note":!0,autoFocus:!0,rows:3,maxLength:mn,value:s,onChange:p=>l(p.target.value),placeholder:"For example: not worth a MAX test round, the creator found a way around it.",className:"mt-1.5 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-red-500 focus:outline-none focus:ring-1 focus:ring-red-500"}),t.jsxs("p",{className:"mt-1 text-right text-xs tabular-nums text-gray-400",children:[s.length,"/",mn]}),c&&t.jsx("p",{role:"alert",className:"mt-1 text-sm text-red-700",children:c}),t.jsxs("div",{className:"mt-3 flex justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:n,disabled:i,className:"inline-flex min-h-[40px] items-center rounded-lg px-3 text-sm font-medium text-gray-700 hover:bg-gray-100",children:"Keep it"}),t.jsx("button",{type:"button","data-dismiss-confirm":!0,onClick:m,disabled:i||!s.trim(),className:"inline-flex min-h-[40px] items-center rounded-lg bg-red-600 px-4 text-sm font-semibold text-white shadow-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-600 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",children:i?"Dismissing…":"Dismiss ticket"})]})]})})}function qt({ticket:e,onUpdate:n}){const[a,s]=r.useState(!1),[l,i]=r.useState(null),o=e.merge&&!e.merge.done_at?e.merge.error:null,c=!e.gate_jira_at&&["validated","dismissed"].includes(e.gate)?e.gate_jira_error:null;if(!o&&!c)return null;const d=async()=>{s(!0),i(null);try{const m=o?await ge("/api/admin/pipeline/merge-tickets",{retry:e.key}):await ge("/api/admin/pipeline/gate",{key:e.key,action:"retry"});n(m.ticket)}catch(m){i(m.message)}finally{s(!1)}};return t.jsxs("div",{role:"alert","data-jira-problem":o?"merge":"gate",className:"mt-4 flex flex-wrap items-start gap-x-3 gap-y-2 rounded-lg border border-red-200 bg-red-50 px-3 py-2.5 text-sm text-red-900",children:[t.jsx(ae,{className:"mt-0.5 h-4 w-4 shrink-0 text-red-600","aria-hidden":!0}),t.jsxs("p",{className:"min-w-0 flex-1 [overflow-wrap:anywhere]",children:[t.jsx("span",{className:"font-semibold",children:o?"The merge is not finished on Jira.":"Jira was not updated."})," ",o||c,l&&t.jsx("span",{className:"block",children:l})]}),t.jsxs("button",{type:"button","data-retry":!0,onClick:d,disabled:a,className:"inline-flex min-h-[32px] items-center gap-1 rounded-lg bg-white px-2.5 text-xs font-semibold text-red-800 ring-1 ring-inset ring-red-300 hover:bg-red-100 disabled:opacity-50",children:[t.jsx(On,{className:`h-3.5 w-3.5 ${a?"animate-spin":""}`,"aria-hidden":!0}),a?"Retrying…":"Retry"]})]})}function pa({ticket:e,selected:n,onToggle:a,disabled:s}){return Ye(e)?t.jsx("label",{className:"-m-2 flex shrink-0 cursor-pointer items-center p-2",title:"Select to merge",children:t.jsx("input",{type:"checkbox","data-select":e.key,checked:n,disabled:s&&!n,onChange:()=>a(e.key),"aria-label":`Select ${e.key} to merge`,className:"h-4 w-4 rounded border-gray-300 text-gray-900 focus:ring-gray-900 disabled:opacity-40"})}):null}function Nl({ticket:e,claimsById:n,selected:a,onToggle:s,selectionFull:l,onUpdate:i,planHost:o,inPlanOf:c,onOpenPlan:d,planShown:m}){const[p,u]=r.useState(null),[g,h]=r.useState(null),[$,N]=r.useState(!1),b=r.useCallback(()=>N(!1),[]),f=e.gate==="later",x=!!(e.merge&&!e.merge.done_at),j=e.merge?.blocks?.length||0,S=async B=>{u(B),h(null);try{const k=await ge("/api/admin/pipeline/gate",{key:e.key,action:B});i(k.ticket)}catch(k){h(k.message)}finally{u(null)}};return t.jsxs("article",{"data-gate-card":e.key,"data-gate":e.gate,className:`rounded-xl border bg-white p-4 shadow-sm sm:p-6 ${a?"border-gray-900 ring-1 ring-gray-900":"border-gray-200"}`,children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx(pa,{ticket:e,selected:a,onToggle:s,disabled:l}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.jsx(Xe,{ticketKey:e.key}),e.repo&&t.jsx("span",{"data-repo-badge":e.repo,className:"shrink-0 whitespace-nowrap rounded border border-indigo-200 bg-indigo-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-indigo-700",children:e.repo}),t.jsx(Dt,{ticket:e}),f&&t.jsxs(re,{kind:"later",icon:Fe,children:["Later · since ",bl(e.gate_at)]}),c&&t.jsxs(re,{kind:"plan",icon:Ie,title:"This ticket is in an open Plan testing thread",children:["In the test plan on ",c]}),t.jsx(Se,{ticket:e})]}),t.jsx("h3",{className:"mt-2 text-base font-semibold leading-snug text-gray-900",children:e.title||e.key})]})]}),t.jsxs("dl",{className:"mt-4 space-y-3",children:[j>1?t.jsx(Te,{label:`${j} problems`,children:t.jsx(vl,{ticket:e,claimsById:n})}):t.jsx(Te,{label:"What is wrong",children:ma(e.plain?.problem||e.excerpt)}),j<2&&t.jsx(Te,{label:"Why it exists",children:t.jsx(wl,{ticket:e,claimsById:n})}),"max_related"in e&&t.jsx(Te,{label:"Cost",children:t.jsx(jl,{maxRelated:e.max_related})}),j>1&&t.jsx(Te,{label:"Saved",children:t.jsx("span",{"data-merge-saved":!0,children:dt(j)})})]}),t.jsx(ct,{strategy:e.plan?.strategy}),t.jsx(qt,{ticket:e,onUpdate:i}),t.jsxs("div",{className:"mt-5 flex flex-wrap items-center gap-2 border-t border-gray-100 pt-4",children:[t.jsxs("button",{type:"button","data-gate-action":"validate",onClick:()=>S("validate"),disabled:!!p||x,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",children:[t.jsx(Dn,{className:"h-4 w-4","aria-hidden":!0}),p==="validate"?"Validating…":"Validate"]}),f?t.jsxs("button",{type:"button","data-gate-action":"back",onClick:()=>S("back"),disabled:!!p,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg px-3 text-sm font-medium text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 disabled:opacity-50",children:[t.jsx(Ln,{className:"h-4 w-4 text-gray-400","aria-hidden":!0}),p==="back"?"Moving…":"Back to waiting"]}):t.jsxs("button",{type:"button","data-gate-action":"later",onClick:()=>S("later"),disabled:!!p,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg px-3 text-sm font-medium text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 disabled:opacity-50",children:[t.jsx(Fe,{className:"h-4 w-4 text-gray-400","aria-hidden":!0}),p==="later"?"Moving…":"Later"]}),t.jsx("button",{type:"button","data-gate-action":"dismiss",onClick:()=>N(!0),disabled:!!p||x,className:"ml-auto inline-flex min-h-[40px] items-center rounded-lg px-3 text-sm font-medium text-red-600 hover:bg-red-50 hover:text-red-800 disabled:opacity-50",children:"Dismiss"}),f&&t.jsx("p",{className:"basis-full text-xs text-gray-500",children:"Parked: it stays out of the fix queue and costs nothing until you validate it."}),g&&t.jsx("p",{role:"alert",className:"basis-full text-sm text-red-700",children:g})]}),o&&d&&t.jsx(da,{host:o,onOpen:d,onUpdate:i,shown:m}),$&&t.jsx(ga,{ticket:e,onClose:b,onDone:i})]})}function Ae({id:e,title:n,hint:a,count:s,children:l}){return t.jsxs("section",{"data-gate-section":e,"aria-labelledby":`gate-${e}`,className:"space-y-3",children:[t.jsxs("h2",{id:`gate-${e}`,className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:[n,s>0&&t.jsxs("span",{className:"normal-case tracking-normal",children:[" · ",s]}),a&&t.jsxs("span",{className:"normal-case tracking-normal",children:[" · ",a]})]}),l]})}function kl({ticket:e,onUpdate:n}){const a=!!e.gate_jira_at;return t.jsxs("li",{"data-validated":e.key,className:"px-4 py-3 sm:px-5",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Xe,{ticketKey:e.key}),a?t.jsx(re,{kind:"ok",icon:Ze,children:"Validated · in the fix queue"}):t.jsx(re,{kind:"max",icon:Fe,children:"Validated · not queued yet"}),e.max_related&&t.jsx(re,{kind:"max",icon:Rt,children:"Uses MAX"}),t.jsx("span",{className:"text-xs text-gray-500",children:xa(e.gate_at)}),t.jsx(Se,{ticket:e,className:"ml-auto"})]}),t.jsx("p",{className:"mt-1 text-sm font-medium text-gray-900",children:e.title||e.key}),t.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:a?"Label max-go is on the Jira ticket. The fix queue takes it on its next run, then it moves to Ready to merge.":e.gate_jira_error?"The fix queue takes it only once the label max-go is on Jira.":"Adding the label max-go on Jira…"}),t.jsx(qt,{ticket:e,onUpdate:n})]})}function _l({ticket:e,selected:n,onToggle:a,selectionFull:s}){return t.jsxs("li",{"data-auto":e.key,className:`flex items-start gap-3 px-4 py-3 sm:px-5 ${n?"bg-gray-50":""}`,children:[t.jsx(pa,{ticket:e,selected:n,onToggle:a,disabled:s}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.jsx(Xe,{ticketKey:e.key}),t.jsx(Dt,{ticket:e}),t.jsx(Se,{ticket:e,className:"ml-auto"})]}),t.jsx("p",{className:"mt-1 text-sm font-medium text-gray-900",children:e.title||e.key}),(e.plain?.problem||e.excerpt)&&t.jsx("p",{className:"mt-0.5 line-clamp-2 text-sm text-gray-600",children:ma(e.plain?.problem||e.excerpt)})]})]})}function Cl({ticket:e,onUpdate:n}){return t.jsxs("li",{"data-dismissed":e.key,className:"bg-gray-50/70 px-4 py-3 sm:px-5",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Xe,{ticketKey:e.key}),t.jsx("span",{className:"rounded-full bg-gray-200 px-1.5 py-0.5 text-[11px] font-medium text-gray-600",children:"Dismissed"}),t.jsx("span",{className:"text-xs text-gray-500",children:xa(e.gate_at)}),t.jsx(Se,{ticket:e,className:"ml-auto"})]}),t.jsx("p",{className:"mt-1 text-sm text-gray-500",children:e.title||e.key}),e.gate_note&&t.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:["Reason: ",e.gate_note]}),t.jsx("p",{className:"mt-0.5 text-xs text-gray-400",children:e.gate_jira_at?"Closed on Jira as declined.":"Closing on Jira…"}),t.jsx(qt,{ticket:e,onUpdate:n})]})}function $l({tickets:e,onClose:n,onDone:a}){const s=[...e].sort(Be)[0].key,[l,i]=r.useState(s),[o,c]=r.useState(!1),[d,m]=r.useState(null);ha(n,o);const p=e.reduce((h,$)=>h+Math.max(1,$.merge?.blocks?.length||0),0),u=e.some(h=>h.max_related),g=async()=>{c(!0),m(null);try{const h=await ge("/api/admin/pipeline/merge-tickets",{keys:e.map($=>$.key),survivor:l});a(h.ticket,h.absorbed),n()}catch(h){m(h.message),c(!1)}};return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-gray-950/50 p-4",onClick:()=>!o&&n(),children:t.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"merge-title","data-merge-dialog":!0,onClick:h=>h.stopPropagation(),className:"flex max-h-[90vh] w-full max-w-lg flex-col rounded-xl bg-white p-5 shadow-2xl",children:[t.jsxs("h2",{id:"merge-title",className:"text-base font-semibold text-gray-900",children:["Merge ",e.length," tickets into one?"]}),t.jsx("p",{className:"mt-2 text-sm leading-relaxed text-gray-700",children:"One ticket keeps every problem as its own block, with where it came from. The others close as superseded and point to it on Jira."}),t.jsx("p",{"data-merge-savings":!0,className:"mt-3 rounded-lg bg-emerald-50 px-3 py-2.5 text-sm font-medium text-emerald-900",children:dt(e.length,p)}),t.jsxs("fieldset",{className:"mt-4 min-h-0 overflow-y-auto",children:[t.jsx("legend",{className:"text-sm font-medium text-gray-800",children:"Which ticket stays?"}),t.jsx("div",{className:"mt-2 space-y-1.5",children:[...e].sort(Be).map(h=>t.jsxs("label",{className:`flex cursor-pointer items-start gap-3 rounded-lg border px-3 py-2 text-sm ${l===h.key?"border-gray-900 bg-gray-50":"border-gray-200 hover:border-gray-300"}`,children:[t.jsx("input",{type:"radio",name:"merge-survivor","data-survivor":h.key,checked:l===h.key,onChange:()=>i(h.key),className:"mt-0.5 h-4 w-4 border-gray-300 text-gray-900 focus:ring-gray-900"}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"font-mono text-xs text-gray-500",children:h.key}),h.max_related&&t.jsx("span",{className:"ml-2 text-xs text-amber-700",children:"uses MAX"}),t.jsx("span",{className:"block text-gray-900",children:h.title||h.key})]})]},h.key))})]}),t.jsx("p",{className:"mt-3 text-xs leading-relaxed text-gray-500",children:u?"At least one problem uses MAX, so the merged ticket comes back here for your validation.":"No problem uses MAX, so the merged ticket goes to the fix queue on its own."}),d&&t.jsx("p",{role:"alert",className:"mt-2 text-sm text-red-700",children:d}),t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:n,disabled:o,className:"inline-flex min-h-[40px] items-center rounded-lg px-3 text-sm font-medium text-gray-700 hover:bg-gray-100",children:"Keep separate"}),t.jsxs("button",{type:"button","data-merge-confirm":!0,onClick:g,disabled:o,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 disabled:opacity-50",children:[t.jsx(st,{className:"h-4 w-4","aria-hidden":!0}),o?"Merging…":"Merge into one ticket"]})]})]})})}function El({selected:e,onClear:n,onMerge:a,onPlan:s}){if(!e.length)return null;const l=!!s&&e.every(o=>o.plan?.on),i=e.reduce((o,c)=>o+Math.max(1,c.merge?.blocks?.length||0),0);return t.jsxs("div",{"data-merge-bar":!0,className:"sticky bottom-4 z-30 mt-6 flex flex-wrap items-center gap-x-4 gap-y-2 rounded-xl bg-gray-900 px-4 py-3 text-white shadow-xl sm:px-5",children:[t.jsxs("p",{className:"text-sm font-semibold",children:[e.length," selected"]}),t.jsx("p",{"data-merge-bar-savings":!0,className:"min-w-0 flex-1 text-sm text-gray-300",children:e.length<2?"Pick at least one more to merge.":dt(e.length,i)}),t.jsx("button",{type:"button",onClick:n,className:"text-sm font-medium text-gray-300 underline underline-offset-2 hover:text-white",children:"Clear"}),l&&t.jsxs("button",{type:"button","data-plan-open":!0,onClick:s,title:"Debate with the pipeline which of these to test together and how, before any test money is spent",className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg px-4 text-sm font-semibold text-white ring-1 ring-inset ring-white/40 hover:bg-white/10 disabled:cursor-not-allowed disabled:opacity-40",children:[t.jsx(Ie,{className:"h-4 w-4","aria-hidden":!0}),"Plan testing"]}),t.jsxs("button",{type:"button","data-merge-open":!0,onClick:a,disabled:e.length<2,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg bg-white px-4 text-sm font-semibold text-gray-900 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40",children:[t.jsx(st,{className:"h-4 w-4","aria-hidden":!0}),"Merge into one ticket"]})]})}function fa(e){const n=Date.now()-ua*24*3600*1e3,a=e.filter(s=>s.queue==="backlog"&&!s.merged_into);return{pending:a.filter(s=>s.gate==="pending").sort(Be),later:a.filter(s=>s.gate==="later").sort(Be),validated:a.filter(s=>s.gate==="validated").sort((s,l)=>new Date(l.gate_at)-new Date(s.gate_at)),auto:a.filter(s=>s.gate==="auto").sort(Be),dismissed:a.filter(s=>s.gate==="dismissed"&&new Date(s.gate_at).getTime()>=n).sort((s,l)=>new Date(l.gate_at)-new Date(s.gate_at))}}function jn({tickets:e,claims:n,onUpdate:a,onMerged:s,renderPlan:l,bundles:i,sort:o="default"}){const c=r.useMemo(()=>Object.fromEntries(Object.entries(fa(e)).map(([w,T])=>[w,Xn(T,o)])),[e,o]),d=r.useMemo(()=>new Map((n||[]).map(w=>[w.claim_id,w])),[n]),[m,p]=r.useState([]),[u,g]=r.useState(!1),h=r.useCallback(()=>g(!1),[]),$=r.useMemo(()=>new Map(e.map(w=>[w.key,w])),[e]),N=m.map(w=>$.get(w)).filter(w=>Ye(w)),b=N.length>=Vr,f=r.useCallback(w=>p(T=>T.includes(w)?T.filter(K=>K!==w):[...T,w]),[]),x=w=>N.some(T=>T.key===w),j=(w,T)=>{s(w,T),p([])},S=_r(),B=r.useMemo(()=>e.filter(w=>w.queue==="backlog"&&w.plan_thread&&w.plan?.on),[e]),k=w=>B.find(T=>T.key===w.key&&!T.merged_into)||B.find(T=>T.merged_into===w.key),E=w=>B.find(T=>T.key!==w.key&&!T.merged_into&&!T.plan_thread.closed_at&&T.plan_thread.keys.includes(w.key))?.key,[R,F]=r.useState(null),A=r.useCallback(()=>F(null),[]),M=(w,T)=>w.length===T.length&&w.every(K=>T.includes(K)),W=w=>(_?.groups||[]).find(T=>M(T.keys,w))||null,v=w=>B.find(T=>!T.merged_into&&!T.plan_thread.closed_at&&w.some(K=>T.plan_thread.keys.includes(K))),C=async(w=N.map(K=>K.key),T=W(w))=>{p([]);const K=v(w);if(K&&M(K.plan_thread.keys,w)){F({keys:w,group:T,hostKey:K.key});return}F({keys:w,group:T,hostKey:null,opening:!0});try{const xe=await ge("/api/admin/pipeline/plan",{keys:w});a(xe.ticket),F(Q=>Q&&{...Q,hostKey:xe.ticket.key,opening:!1})}catch(xe){F(Q=>Q&&{...Q,opening:!1,error:xe.message})}},O=w=>F({keys:w.plan_thread.keys,group:W(w.plan_thread.keys),hostKey:w.key}),y=w=>{F(null),setTimeout(()=>{document.querySelector(`[data-gate-card="${w}"], [data-phone-page="${w}"]`)?.scrollIntoView({behavior:"smooth",block:"center"})},50)},[_,L]=r.useState(i||null),D=r.useMemo(()=>rr(_,new Set(e.filter(Ye).map(w=>w.key))),[_,e]),Z=D?.groups.find(w=>w.keys.length===N.length&&w.keys.every(T=>x(T)))?.id,I=w=>p(Z===w.id?[]:[...w.keys]),V=w=>{const T=v(w.keys);return T?Ft(T):null},ie=async w=>{const T=await ge("/api/admin/pipeline/bundles",{id:w.id,input_hash:D.input_hash});L(T.bundles),Z===w.id&&p([])},se=w=>t.jsx(Nl,{ticket:w,claimsById:d,selected:x(w.key),onToggle:f,selectionFull:b,onUpdate:a,planHost:k(w),inPlanOf:E(w),onOpenPlan:l?O:null,planShown:!!R?.hostKey&&R.hostKey===k(w)?.key},w.key),ne=t.jsxs(t.Fragment,{children:[u&&N.length>=2&&t.jsx($l,{tickets:N,onClose:h,onDone:j}),R&&t.jsx(rl,{keys:R.keys,group:R.group,host:R.hostKey?$.get(R.hostKey):null,opening:R.opening,error:R.error,ticketOf:w=>$.get(w),renderPlan:l,onUpdate:a,onClose:A,onDismiss:ie,onShow:y})]});return S?t.jsx(Xr,{lists:c,onUpdate:a,dialogs:ne,bundleCount:D?.groups.length||0,renderBundles:w=>t.jsx(gn,{view:D,titleOf:T=>$.get(T)?.title||T,activeId:Z,canPlan:T=>!!l&&T.keys.every(K=>$.get(K)?.plan?.on),threadOf:V,onPick:T=>{I(T),w()},onReview:T=>{w(),C(T.keys,T)},onDismiss:ie}),sel:{selected:N,full:b,isSel:x,toggle:f,onClear:()=>p([]),onMerge:()=>g(!0),onPlan:l?()=>C():null},gate:{DismissDialog:ga,SourceChips:Dt,mergeable:Ye,inPlanOf:E,planHostOf:k,renderDetails:se,renderPlanEntry:l?w=>t.jsx(da,{host:k(w),onOpen:O,onUpdate:a,shown:!1}):null}}):t.jsxs("div",{"data-gate-tab":!0,children:[t.jsxs("div",{className:"space-y-8",children:[t.jsx(gn,{view:D,titleOf:w=>$.get(w)?.title||w,activeId:Z,canPlan:w=>!!l&&w.keys.every(T=>$.get(T)?.plan?.on),threadOf:V,onPick:I,onReview:w=>C(w.keys,w),onDismiss:ie}),t.jsx("p",{className:"max-w-3xl text-sm leading-relaxed text-gray-600",children:"With the validation gate on, new tickets wait here for your go: nothing moves on until you validate. Validate promotes one to the next stage; Later keeps it here; Dismiss drops it with your reason. Select several to merge them into one ticket."}),t.jsx(Ae,{id:"pending",title:"Awaiting your validation",count:c.pending.length,children:c.pending.length?t.jsx("div",{className:"grid grid-cols-1 items-start gap-4 2xl:grid-cols-2",children:c.pending.map(se)}):t.jsx("p",{className:"rounded-xl border border-dashed border-gray-300 bg-white px-4 py-10 text-center text-sm text-gray-500",children:"Nothing is waiting for your validation."})}),c.later.length>0&&t.jsx(Ae,{id:"later",title:"Later",hint:"parked, costs nothing",count:c.later.length,children:t.jsx("div",{className:"grid grid-cols-1 items-start gap-4 2xl:grid-cols-2",children:c.later.map(se)})}),c.validated.length>0&&t.jsx(Ae,{id:"validated",title:"Validated",hint:"your go",count:c.validated.length,children:t.jsx("ul",{className:"divide-y divide-gray-100 rounded-xl border border-emerald-200 bg-white shadow-sm",children:c.validated.map(w=>t.jsx(kl,{ticket:w,onUpdate:a},w.key))})}),c.auto.length>0&&t.jsx(Ae,{id:"auto",title:"Flowing on their own",hint:"no validation needed",count:c.auto.length,children:t.jsx("ul",{className:"divide-y divide-gray-100 rounded-xl border border-gray-200 bg-white shadow-sm",children:c.auto.map(w=>t.jsx(_l,{ticket:w,selected:x(w.key),onToggle:f,selectionFull:b},w.key))})}),c.dismissed.length>0&&t.jsx(Ae,{id:"dismissed",title:"Dismissed",hint:`last ${ua} days`,count:c.dismissed.length,children:t.jsx("ul",{className:"divide-y divide-gray-100 overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm",children:c.dismissed.map(w=>t.jsx(Cl,{ticket:w,onUpdate:a},w.key))})})]}),t.jsx(El,{selected:N,onClear:()=>p([]),onMerge:()=>g(!0),onPlan:l?()=>C():null}),ne]})}const ba="https://magifyfun.atlassian.net/browse/",Sl={magify_agents_api:"api",magify_next:"next"},kt=[{key:"validate",label:"Awaiting validation"},{key:"merge",label:"Ready to merge"},{key:"decide",label:"Needs decision"},{key:"manual",label:"Manual"},{key:"claims",label:"Claims"},{key:"shipped",label:"Shipped"}],nt=e=>`/api/admin/pipeline/evidence?k=${encodeURIComponent(e.s3_key)}`,te=e=>`${Sl[e.repo]||e.repo}#${e.number}`;function at(e){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?"":n.toLocaleString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})}function ut({ticketKey:e}){return t.jsx("a",{href:ba+e,target:"_blank",rel:"noopener noreferrer","data-jira-key":e,className:"shrink-0 whitespace-nowrap rounded border border-gray-200 bg-gray-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-gray-500 hover:border-gray-300 hover:text-gray-800",children:e})}function mt({repo:e}){return e?t.jsx("span",{"data-repo-badge":e,title:`Repo: ${e}`,className:"shrink-0 whitespace-nowrap rounded border border-indigo-200 bg-indigo-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-indigo-700",children:e}):null}function Oe({label:e,children:n}){return n?t.jsxs("div",{className:"grid gap-0.5 sm:grid-cols-[10.5rem_1fr] sm:gap-4 xl:grid-cols-1 xl:gap-1",children:[t.jsx("dt",{className:"text-xs font-medium uppercase tracking-wide text-gray-400 sm:pt-0.5 xl:pt-0",children:e}),t.jsx("dd",{className:"text-[15px] leading-relaxed text-gray-900",children:n})]}):null}const Rl=50;function Ml({images:e,index:n,onIndex:a,onClose:s}){const l=e.length,i=e[n],o=r.useCallback(u=>a((n+u+l)%l),[n,l,a]),c=r.useRef(null);r.useEffect(()=>{const u=g=>{g.key==="Escape"?s():l>1&&g.key==="ArrowLeft"?(g.preventDefault(),o(-1)):l>1&&g.key==="ArrowRight"&&(g.preventDefault(),o(1))};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,o,l]),r.useEffect(()=>{l<2||[e[(n+1)%l],e[(n-1+l)%l]].forEach(u=>{new window.Image().src=nt(u)})},[e,n,l]);const d=u=>{c.current=u.touches[0]?.clientX??null},m=u=>{const g=c.current;c.current=null;const h=g==null?0:(u.changedTouches[0]?.clientX??g)-g;l>1&&Math.abs(h)>Rl&&o(h<0?1:-1)},p="absolute top-1/2 z-10 -translate-y-1/2 rounded-full bg-gray-900/70 p-2.5 text-white shadow-lg ring-1 ring-white/20 hover:bg-gray-900/90 focus:outline-none focus-visible:ring-2 focus-visible:ring-white sm:p-3";return t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":i.caption||i.name,"data-lightbox":!0,"data-lightbox-index":n,"data-lightbox-kind":i.chat?"chat":"proof",onClick:s,onTouchStart:d,onTouchEnd:m,className:"fixed inset-0 z-50 flex flex-col items-center justify-center gap-3 bg-gray-950/85 p-4 sm:px-20 sm:py-8",children:[t.jsx("button",{type:"button",onClick:s,"aria-label":"Close",className:"absolute right-3 top-3 z-10 rounded-full bg-white/10 p-2 text-white hover:bg-white/20",children:t.jsx(fe,{className:"h-5 w-5","aria-hidden":!0})}),l>1&&t.jsxs(t.Fragment,{children:[t.jsxs("p",{"data-lightbox-position":!0,className:"absolute left-4 top-4 z-10 rounded-full bg-gray-900/70 px-2.5 py-1 text-xs font-medium tabular-nums text-white","aria-live":"polite",children:[n+1," / ",l]}),t.jsx("button",{type:"button","data-lightbox-prev":!0,"aria-label":"Previous image",onClick:u=>{u.stopPropagation(),o(-1)},className:`${p} left-2 sm:left-5`,children:t.jsx(In,{className:"h-6 w-6","aria-hidden":!0})}),t.jsx("button",{type:"button","data-lightbox-next":!0,"aria-label":"Next image",onClick:u=>{u.stopPropagation(),o(1)},className:`${p} right-2 sm:right-5`,children:t.jsx(pe,{className:"h-6 w-6","aria-hidden":!0})})]}),t.jsx("img",{src:nt(i),alt:i.caption||i.name,onClick:u=>u.stopPropagation(),className:"max-h-[82vh] max-w-full rounded-lg bg-white object-contain shadow-2xl"},i.sha256),t.jsx("p",{"data-lightbox-caption":!0,className:"max-w-3xl text-center text-sm text-gray-200",children:i.caption||i.name})]})}const Tl="1440 / 992";function Al({image:e,onOpen:n,small:a}){const[s,l]=r.useState(!1),i=a?" sm:aspect-[4/3] sm:w-full sm:max-h-none sm:object-cover sm:object-left-top":"";return t.jsxs("figure",{"data-evidence":e.name,className:"min-w-0",children:[t.jsx("button",{type:"button",onClick:n,"aria-label":`Open full size: ${e.caption||e.name}`,className:"group block w-full cursor-zoom-in overflow-hidden rounded-lg border border-gray-200 bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:t.jsx("img",{src:nt(e),alt:e.caption||e.name,loading:"lazy",onLoad:()=>l(!0),style:s?void 0:{aspectRatio:Tl},className:`mx-auto block transition-opacity group-hover:opacity-90 ${s?"h-auto max-h-[75vh] w-auto max-w-full":"w-full"}${i}`})}),t.jsx("figcaption",{className:`mt-2 text-sm leading-snug text-gray-700${a?" sm:mt-1 sm:line-clamp-2 sm:text-xs sm:text-gray-500":""}`,children:e.caption||e.name})]})}function ya({evidence:e,size:n,onOpen:a}){const s=n==="small",l=e.filter(i=>i.s3_key);return e.length?t.jsxs("section",{className:"mt-5","aria-label":"Proof screenshots",children:[t.jsxs("h3",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:["Proof ",t.jsxs("span",{className:"normal-case tracking-normal text-gray-400",children:["· ",e.length," screenshots"]})]}),l.length===0?t.jsx("p",{className:"mt-2 text-sm text-gray-500",children:"The screenshots upload on the next pipeline sync."}):t.jsx("div",{"data-proof-grid":!0,"data-proof-size":s?"small":"large",className:`mt-3 grid items-start ${s?"grid-cols-1 gap-x-5 gap-y-6 sm:grid-cols-3 sm:gap-3 xl:grid-cols-4":"gap-x-5 gap-y-6 [grid-template-columns:repeat(auto-fill,minmax(min(100%,600px),1fr))]"}`,children:l.map((i,o)=>t.jsx(Al,{image:i,onOpen:()=>a(o),small:s},i.sha256))})]}):null}function Pl(e){const n=(e.evidence||[]).filter(s=>s.s3_key),a=It(e.chat).flatMap(s=>{const l=s.images||[],i=s.kind==="directive"?"Screenshot with your fix request":"Your screenshot in the chat";return l.map((o,c)=>({...o,chat:s.id,caption:`${i} · ${le(s.at)}${l.length>1?` · ${c+1} of ${l.length}`:""}${o.name?` · ${o.name}`:""}`}))});return[...n,...a]}function xt(e){const n=Kn(),a=r.useMemo(()=>Pl(e),[e]),[s,l]=r.useState(null),i=r.useCallback(()=>l(null),[]),o=r.useCallback(m=>l(m),[]),c=r.useCallback((m,p)=>{const u=a.findIndex(g=>g.chat===m&&g.sha256===p);u>=0&&l(u)},[a]);let d=null;return s!=null&&a[s]&&(d=n?t.jsx(Br,{onClose:i,children:t.jsx(Pr,{images:a,index:s,onIndex:l,onClose:i})}):t.jsx(Ml,{images:a,index:s,onIndex:l,onClose:i})),{openProof:o,openShot:c,viewer:d}}function Bl({ticket:e}){const[n,a]=r.useState(!1),s=e.prs.reduce((i,o)=>({files:i.files+(o.changed_files||0),add:i.add+(o.additions||0),del:i.del+(o.deletions||0)}),{files:0,add:0,del:0}),l=`dev-${e.key}`;return t.jsxs("section",{className:"mt-5 border-t border-gray-100 pt-3",children:[t.jsxs("button",{type:"button","aria-expanded":n,"aria-controls":l,onClick:()=>a(i=>!i),className:"-mx-1 flex w-full items-center gap-1 rounded px-1 py-1 text-left text-sm font-medium text-gray-700 hover:text-gray-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:[t.jsx(pe,{className:`h-4 w-4 text-gray-400 transition-transform ${n?"rotate-90":""}`,"aria-hidden":!0}),"Development",t.jsxs("span",{className:"ml-2 font-normal text-gray-400",children:[e.prs.map(te).join(", ")," · ",s.files," files",t.jsxs("span",{className:"text-emerald-600",children:[" +",s.add]}),t.jsxs("span",{className:"text-red-600",children:[" −",s.del]})]})]}),n&&t.jsxs("div",{id:l,"data-development":!0,className:"mt-3 space-y-4 text-sm",children:[e.prs.map(i=>t.jsxs("div",{children:[t.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 font-medium text-indigo-700 hover:text-indigo-900",children:[te(i),t.jsx(Le,{className:"h-3.5 w-3.5","aria-hidden":!0})]}),t.jsx("span",{className:"ml-2 text-gray-700",children:i.title}),t.jsxs("p",{className:"mt-0.5 text-xs text-gray-400",children:[t.jsx("span",{className:"font-mono",children:i.head})," into ",t.jsx("span",{className:"font-mono",children:i.base})]}),i.files?.length>0&&t.jsx("ul",{className:"mt-1.5 divide-y divide-gray-100 rounded-md border border-gray-100 font-mono text-xs",children:i.files.map(o=>t.jsxs("li",{className:"flex items-center gap-3 px-2.5 py-1",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-gray-700",title:o.path,children:o.path}),t.jsxs("span",{className:"shrink-0 tabular-nums text-emerald-600",children:["+",o.additions]}),t.jsxs("span",{className:"w-10 shrink-0 text-right tabular-nums text-red-600",children:["−",o.deletions]})]},o.path))})]},`${i.repo}#${i.number}`)),e.verdict&&t.jsxs("div",{"data-verdict":!0,children:[t.jsxs("h4",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:["Hostile check",e.fix_class?` · ${e.fix_class.toLowerCase()} fix`:""]}),t.jsx("p",{className:"mt-1 whitespace-pre-line leading-relaxed text-gray-700 [overflow-wrap:anywhere]",children:e.verdict})]})]})]})}const vn=e=>`${e}${{1:"st",2:"nd",3:"rd"}[e]||"th"}`;function Ol({ticket:e,held:n=!1}){const a=lt(e.prs),s=a.length>1,l=!!e.hold||n;return t.jsxs("section",{"data-github-links":!0,"aria-label":"Merge on GitHub",className:"space-y-2",children:[s&&t.jsxs("p",{"data-merge-order":!0,className:"text-sm font-semibold text-gray-900",children:["Merge order: ",a.length," PRs, one at a time, top to bottom"]}),t.jsx("ol",{className:"space-y-2",children:a.map(({pr:i,step:o,parent:c})=>{const d=o>1?a[o-2].pr:null;return t.jsxs("li",{"data-pr-step":o,"data-pr":te(i),className:"flex flex-col gap-2 rounded-lg border border-gray-200 px-3 py-2.5 sm:flex-row sm:items-center sm:gap-3",children:[s&&t.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-gray-900 text-sm font-bold text-white","aria-hidden":!0,children:o}),t.jsxs("div",{className:"min-w-0 flex-1 text-sm",children:[t.jsxs("p",{className:"truncate text-gray-900",title:i.title,children:[t.jsx("span",{className:"font-semibold",children:te(i)}),t.jsxs("span",{className:"text-gray-500",children:[" · ",i.title]})]}),s&&t.jsxs("p",{"data-step-note":!0,className:`mt-0.5 text-xs ${c?"font-medium text-amber-800":"text-gray-500"}`,children:[o===1&&"Merge 1st.",o>1&&c&&`Merge ${vn(o)}, after its parent ${te(c)} (stacked on it). If GitHub still shows this PR into ${c.head}, change its base to ${c.base} first.`,o>1&&!c&&`Merge ${vn(o)}, after ${te(d)}.`]})]}),t.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer","data-open-github":te(i),className:`inline-flex min-h-[40px] shrink-0 items-center justify-center gap-1.5 rounded-lg px-4 text-sm font-semibold shadow-sm focus:outline-none focus:ring-2 focus:ring-offset-2 ${l?"border border-gray-300 bg-white text-gray-700 hover:bg-gray-50 focus:ring-gray-400":"bg-gray-900 text-white hover:bg-gray-700 focus:ring-gray-900"}`,children:["Open ",te(i)," on GitHub",t.jsx(Le,{className:"h-4 w-4","aria-hidden":!0})]})]},`${i.repo}#${i.number}`)})})]})}const Ll=30*1e3,Fl=1200*1e3;function le(e){const n=new Date(e);if(Number.isNaN(n.getTime()))return"";const a=n.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return n.toDateString()===new Date().toDateString()?a:`${n.toLocaleDateString("en-GB",{day:"numeric",month:"short"})}, ${a}`}const It=e=>[...e||[]].sort((n,a)=>new Date(n.at)-new Date(a.at)),Nn=/^\s*[-•]\s+/;function kn({text:e}){return e.split(/(`[^`\n]+`)/).map((n,a)=>/^`[^`]+`$/.test(n)?t.jsx("code",{className:"rounded bg-black/[0.06] px-1 py-px font-mono text-[12.5px]",children:n.slice(1,-1)},a):n)}function wa({text:e}){const n=[];return(e||"").split(/\n\s*\n/).forEach((a,s)=>{let l=[],i=[];const o=()=>{l.length&&n.push(t.jsx("p",{className:"whitespace-pre-line",children:t.jsx(kn,{text:l.join(`
|
|
1
|
+
import{r,j as t}from"./fmt-BRV4RZz4.js";import{PlatformClaim as Xa,PipelineTicket as Ja,PipelineBundles as Va}from"./data-provider-TNBGds5H.js";import{F as pe,a as fe,b as Pn,L as Ya}from"./ConversationWorkspace-C_HyzEg6.js";import{r as Bn}from"./index-CIpIMh38.js";import"./index-C7UNg0WM.js";function Ka({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M10 3.75a2 2 0 1 0-4 0 2 2 0 0 0 4 0ZM17.25 4.5a.75.75 0 0 0 0-1.5h-5.5a.75.75 0 0 0 0 1.5h5.5ZM5 3.75a.75.75 0 0 1-.75.75h-1.5a.75.75 0 0 1 0-1.5h1.5a.75.75 0 0 1 .75.75ZM4.25 17a.75.75 0 0 0 0-1.5h-1.5a.75.75 0 0 0 0 1.5h1.5ZM17.25 17a.75.75 0 0 0 0-1.5h-5.5a.75.75 0 0 0 0 1.5h5.5ZM9 10a.75.75 0 0 1-.75.75h-5.5a.75.75 0 0 1 0-1.5h5.5A.75.75 0 0 1 9 10ZM17.25 10.75a.75.75 0 0 0 0-1.5h-1.5a.75.75 0 0 0 0 1.5h1.5ZM14 10a2 2 0 1 0-4 0 2 2 0 0 0 4 0ZM10 16.25a2 2 0 1 0-4 0 2 2 0 0 0 4 0Z"}))}const Ua=r.forwardRef(Ka);function Qa({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M15.312 11.424a5.5 5.5 0 0 1-9.201 2.466l-.312-.311h2.433a.75.75 0 0 0 0-1.5H3.989a.75.75 0 0 0-.75.75v4.242a.75.75 0 0 0 1.5 0v-2.43l.31.31a7 7 0 0 0 11.712-3.138.75.75 0 0 0-1.449-.39Zm1.23-3.723a.75.75 0 0 0 .219-.53V2.929a.75.75 0 0 0-1.5 0V5.36l-.31-.31A7 7 0 0 0 3.239 8.188a.75.75 0 1 0 1.448.389A5.5 5.5 0 0 1 13.89 6.11l.311.31h-2.432a.75.75 0 0 0 0 1.5h4.243a.75.75 0 0 0 .53-.219Z",clipRule:"evenodd"}))}const On=r.forwardRef(Qa);function es({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M4.25 5.5a.75.75 0 0 0-.75.75v8.5c0 .414.336.75.75.75h8.5a.75.75 0 0 0 .75-.75v-4a.75.75 0 0 1 1.5 0v4A2.25 2.25 0 0 1 12.75 17h-8.5A2.25 2.25 0 0 1 2 14.75v-8.5A2.25 2.25 0 0 1 4.25 4h5a.75.75 0 0 1 0 1.5h-5Z",clipRule:"evenodd"}),r.createElement("path",{fillRule:"evenodd",d:"M6.194 12.753a.75.75 0 0 0 1.06.053L16.5 4.44v2.81a.75.75 0 0 0 1.5 0v-4.5a.75.75 0 0 0-.75-.75h-4.5a.75.75 0 0 0 0 1.5h2.553l-9.056 8.194a.75.75 0 0 0-.053 1.06Z",clipRule:"evenodd"}))}const Le=r.forwardRef(es);function ts({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 17a.75.75 0 0 1-.75-.75V5.612L5.29 9.77a.75.75 0 0 1-1.08-1.04l5.25-5.5a.75.75 0 0 1 1.08 0l5.25 5.5a.75.75 0 1 1-1.08 1.04l-3.96-4.158V16.25A.75.75 0 0 1 10 17Z",clipRule:"evenodd"}))}const ns=r.forwardRef(ts);function as({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M7.793 2.232a.75.75 0 0 1-.025 1.06L3.622 7.25h10.003a5.375 5.375 0 0 1 0 10.75H10.75a.75.75 0 0 1 0-1.5h2.875a3.875 3.875 0 0 0 0-7.75H3.622l4.146 3.957a.75.75 0 0 1-1.036 1.085l-5.5-5.25a.75.75 0 0 1 0-1.085l5.5-5.25a.75.75 0 0 1 1.06.025Z",clipRule:"evenodd"}))}const Ln=r.forwardRef(as);function ss({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M3.28 2.22a.75.75 0 0 0-1.06 1.06L5.44 6.5H2.75a.75.75 0 0 0 0 1.5h4.5A.75.75 0 0 0 8 7.25v-4.5a.75.75 0 0 0-1.5 0v2.69L3.28 2.22ZM13.5 2.75a.75.75 0 0 0-1.5 0v4.5c0 .414.336.75.75.75h4.5a.75.75 0 0 0 0-1.5h-2.69l3.22-3.22a.75.75 0 0 0-1.06-1.06L13.5 5.44V2.75ZM3.28 17.78l3.22-3.22v2.69a.75.75 0 0 0 1.5 0v-4.5a.75.75 0 0 0-.75-.75h-4.5a.75.75 0 0 0 0 1.5h2.69l-3.22 3.22a.75.75 0 1 0 1.06 1.06ZM13.5 14.56l3.22 3.22a.75.75 0 1 0 1.06-1.06l-3.22-3.22h2.69a.75.75 0 0 0 0-1.5h-4.5a.75.75 0 0 0-.75.75v4.5a.75.75 0 0 0 1.5 0v-2.69Z"}))}const st=r.forwardRef(ss);function rs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"m13.28 7.78 3.22-3.22v2.69a.75.75 0 0 0 1.5 0v-4.5a.75.75 0 0 0-.75-.75h-4.5a.75.75 0 0 0 0 1.5h2.69l-3.22 3.22a.75.75 0 0 0 1.06 1.06ZM2 17.25v-4.5a.75.75 0 0 1 1.5 0v2.69l3.22-3.22a.75.75 0 0 1 1.06 1.06L4.56 16.5h2.69a.75.75 0 0 1 0 1.5h-4.5a.747.747 0 0 1-.75-.75ZM12.22 13.28l3.22 3.22h-2.69a.75.75 0 0 0 0 1.5h4.5a.747.747 0 0 0 .75-.75v-4.5a.75.75 0 0 0-1.5 0v2.69l-3.22-3.22a.75.75 0 1 0-1.06 1.06ZM3.5 4.56l3.22 3.22a.75.75 0 0 0 1.06-1.06L4.56 3.5h2.69a.75.75 0 0 0 0-1.5h-4.5a.75.75 0 0 0-.75.75v4.5a.75.75 0 0 0 1.5 0V4.56Z"}))}const ls=r.forwardRef(rs);function is({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M13.2 2.24a.75.75 0 0 0 .04 1.06l2.1 1.95H6.75a.75.75 0 0 0 0 1.5h8.59l-2.1 1.95a.75.75 0 1 0 1.02 1.1l3.5-3.25a.75.75 0 0 0 0-1.1l-3.5-3.25a.75.75 0 0 0-1.06.04Zm-6.4 8a.75.75 0 0 0-1.06-.04l-3.5 3.25a.75.75 0 0 0 0 1.1l3.5 3.25a.75.75 0 1 0 1.02-1.1l-2.1-1.95h8.59a.75.75 0 0 0 0-1.5H4.66l2.1-1.95a.75.75 0 0 0 .04-1.06Z",clipRule:"evenodd"}))}const os=r.forwardRef(is);function ds({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M2.24 6.8a.75.75 0 0 0 1.06-.04l1.95-2.1v8.59a.75.75 0 0 0 1.5 0V4.66l1.95 2.1a.75.75 0 1 0 1.1-1.02l-3.25-3.5a.75.75 0 0 0-1.1 0L2.2 5.74a.75.75 0 0 0 .04 1.06Zm8 6.4a.75.75 0 0 0-.04 1.06l3.25 3.5a.75.75 0 0 0 1.1 0l3.25-3.5a.75.75 0 1 0-1.1-1.02l-1.95 2.1V6.75a.75.75 0 0 0-1.5 0v8.59l-1.95-2.1a.75.75 0 0 0-1.06-.04Z",clipRule:"evenodd"}))}const cs=r.forwardRef(ds);function us({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M8.5 3.528v4.644c0 .729-.29 1.428-.805 1.944l-1.217 1.216a8.75 8.75 0 0 1 3.55.621l.502.201a7.25 7.25 0 0 0 4.178.365l-2.403-2.403a2.75 2.75 0 0 1-.805-1.944V3.528a40.205 40.205 0 0 0-3 0Zm4.5.084.19.015a.75.75 0 1 0 .12-1.495 41.364 41.364 0 0 0-6.62 0 .75.75 0 0 0 .12 1.495L7 3.612v4.56c0 .331-.132.649-.366.883L2.6 13.09c-1.496 1.496-.817 4.15 1.403 4.475C5.961 17.852 7.963 18 10 18s4.039-.148 5.997-.436c2.22-.325 2.9-2.979 1.403-4.475l-4.034-4.034A1.25 1.25 0 0 1 13 8.172v-4.56Z",clipRule:"evenodd"}))}const Ie=r.forwardRef(us);function ms({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M11.983 1.907a.75.75 0 0 0-1.292-.657l-8.5 9.5A.75.75 0 0 0 2.75 12h6.572l-1.305 6.093a.75.75 0 0 0 1.292.657l8.5-9.5A.75.75 0 0 0 17.25 8h-6.572l1.305-6.093Z"}))}const Rt=r.forwardRef(ms);function xs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M3.505 2.365A41.369 41.369 0 0 1 9 2c1.863 0 3.697.124 5.495.365 1.247.167 2.18 1.108 2.435 2.268a4.45 4.45 0 0 0-.577-.069 43.141 43.141 0 0 0-4.706 0C9.229 4.696 7.5 6.727 7.5 8.998v2.24c0 1.413.67 2.735 1.76 3.562l-2.98 2.98A.75.75 0 0 1 5 17.25v-3.443c-.501-.048-1-.106-1.495-.172C2.033 13.438 1 12.162 1 10.72V5.28c0-1.441 1.033-2.717 2.505-2.914Z"}),r.createElement("path",{d:"M14 6c-.762 0-1.52.02-2.271.062C10.157 6.148 9 7.472 9 8.998v2.24c0 1.519 1.147 2.839 2.71 2.935.214.013.428.024.642.034.2.009.385.09.518.224l2.35 2.35a.75.75 0 0 0 1.28-.531v-2.07c1.453-.195 2.5-1.463 2.5-2.915V8.998c0-1.526-1.157-2.85-2.729-2.936A41.645 41.645 0 0 0 14 6Z"}))}const Fn=r.forwardRef(xs);function hs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm3.857-9.809a.75.75 0 0 0-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 1 0-1.06 1.061l2.5 2.5a.75.75 0 0 0 1.137-.089l4-5.5Z",clipRule:"evenodd"}))}const Ze=r.forwardRef(hs);function gs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z",clipRule:"evenodd"}))}const Dn=r.forwardRef(gs);function ps({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const qn=r.forwardRef(ps);function fs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M11.78 5.22a.75.75 0 0 1 0 1.06L8.06 10l3.72 3.72a.75.75 0 1 1-1.06 1.06l-4.25-4.25a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const In=r.forwardRef(fs);function bs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm.75-13a.75.75 0 0 0-1.5 0v5c0 .414.336.75.75.75h4a.75.75 0 0 0 0-1.5h-3.25V5Z",clipRule:"evenodd"}))}const Fe=r.forwardRef(bs);function ys({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M4.5 2A1.5 1.5 0 0 0 3 3.5v13A1.5 1.5 0 0 0 4.5 18h11a1.5 1.5 0 0 0 1.5-1.5V7.621a1.5 1.5 0 0 0-.44-1.06l-4.12-4.122A1.5 1.5 0 0 0 11.378 2H4.5Zm2.25 8.5a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5h-6.5Zm0 3a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5h-6.5Z",clipRule:"evenodd"}))}const ws=r.forwardRef(ys);function js({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495ZM10 5a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 10 5Zm0 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z",clipRule:"evenodd"}))}const ae=r.forwardRef(js);function vs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5Z"}),r.createElement("path",{fillRule:"evenodd",d:"M.664 10.59a1.651 1.651 0 0 1 0-1.186A10.004 10.004 0 0 1 10 3c4.257 0 7.893 2.66 9.336 6.41.147.381.146.804 0 1.186A10.004 10.004 0 0 1 10 17c-4.257 0-7.893-2.66-9.336-6.41ZM14 10a4 4 0 1 1-8 0 4 4 0 0 1 8 0Z",clipRule:"evenodd"}))}const Ns=r.forwardRef(vs);function ks({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M2.628 1.601C5.028 1.206 7.49 1 10 1s4.973.206 7.372.601a.75.75 0 0 1 .628.74v2.288a2.25 2.25 0 0 1-.659 1.59l-4.682 4.683a2.25 2.25 0 0 0-.659 1.59v3.037c0 .684-.31 1.33-.844 1.757l-1.937 1.55A.75.75 0 0 1 8 18.25v-5.757a2.25 2.25 0 0 0-.659-1.591L2.659 6.22A2.25 2.25 0 0 1 2 4.629V2.34a.75.75 0 0 1 .628-.74Z",clipRule:"evenodd"}))}const _s=r.forwardRef(ks);function Cs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 1a4.5 4.5 0 0 0-4.5 4.5V9H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2h-.5V5.5A4.5 4.5 0 0 0 10 1Zm3 8V5.5a3 3 0 1 0-6 0V9h6Z",clipRule:"evenodd"}))}const $s=r.forwardRef(Cs);function Es({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M6.75 8.25a.75.75 0 0 0 0 1.5h4.5a.75.75 0 0 0 0-1.5h-4.5Z"}),r.createElement("path",{fillRule:"evenodd",d:"M9 2a7 7 0 1 0 4.391 12.452l3.329 3.328a.75.75 0 1 0 1.06-1.06l-3.328-3.329A7 7 0 0 0 9 2ZM3.5 9a5.5 5.5 0 1 1 11 0 5.5 5.5 0 0 1-11 0Z",clipRule:"evenodd"}))}const Ss=r.forwardRef(Es);function Rs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M9 6a.75.75 0 0 1 .75.75v1.5h1.5a.75.75 0 0 1 0 1.5h-1.5v1.5a.75.75 0 0 1-1.5 0v-1.5h-1.5a.75.75 0 0 1 0-1.5h1.5v-1.5A.75.75 0 0 1 9 6Z"}),r.createElement("path",{fillRule:"evenodd",d:"M2 9a7 7 0 1 1 12.452 4.391l3.328 3.329a.75.75 0 1 1-1.06 1.06l-3.329-3.328A7 7 0 0 1 2 9Zm7-5.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11Z",clipRule:"evenodd"}))}const Ms=r.forwardRef(Rs);function Ts({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M9 3.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM2 9a7 7 0 1 1 12.452 4.391l3.328 3.329a.75.75 0 1 1-1.06 1.06l-3.329-3.328A7 7 0 0 1 2 9Z",clipRule:"evenodd"}))}const As=r.forwardRef(Ts);function Ps({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M5.75 3a.75.75 0 0 0-.75.75v12.5c0 .414.336.75.75.75h1.5a.75.75 0 0 0 .75-.75V3.75A.75.75 0 0 0 7.25 3h-1.5ZM12.75 3a.75.75 0 0 0-.75.75v12.5c0 .414.336.75.75.75h1.5a.75.75 0 0 0 .75-.75V3.75a.75.75 0 0 0-.75-.75h-1.5Z"}))}const Mt=r.forwardRef(Ps);function Bs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M1 5.25A2.25 2.25 0 0 1 3.25 3h13.5A2.25 2.25 0 0 1 19 5.25v9.5A2.25 2.25 0 0 1 16.75 17H3.25A2.25 2.25 0 0 1 1 14.75v-9.5Zm1.5 5.81v3.69c0 .414.336.75.75.75h13.5a.75.75 0 0 0 .75-.75v-2.69l-2.22-2.219a.75.75 0 0 0-1.06 0l-1.91 1.909.47.47a.75.75 0 1 1-1.06 1.06L6.53 8.091a.75.75 0 0 0-1.06 0l-2.97 2.97ZM12 7a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z",clipRule:"evenodd"}))}const Os=r.forwardRef(Bs);function Ls({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z"}))}const Fs=r.forwardRef(Ls);function Ds({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M5.127 3.502 5.25 3.5h9.5c.041 0 .082 0 .123.002A2.251 2.251 0 0 0 12.75 2h-5.5a2.25 2.25 0 0 0-2.123 1.502ZM1 10.25A2.25 2.25 0 0 1 3.25 8h13.5A2.25 2.25 0 0 1 19 10.25v5.5A2.25 2.25 0 0 1 16.75 18H3.25A2.25 2.25 0 0 1 1 15.75v-5.5ZM3.25 6.5c-.04 0-.082 0-.123.002A2.25 2.25 0 0 1 5.25 5h9.5c.98 0 1.814.627 2.123 1.502a3.819 3.819 0 0 0-.123-.002H3.25Z"}))}const Tt=r.forwardRef(Ds);function qs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M10 2a.75.75 0 0 1 .75.75v.258a33.186 33.186 0 0 1 6.668.83.75.75 0 0 1-.336 1.461 31.28 31.28 0 0 0-1.103-.232l1.702 7.545a.75.75 0 0 1-.387.832A4.981 4.981 0 0 1 15 14c-.825 0-1.606-.2-2.294-.556a.75.75 0 0 1-.387-.832l1.77-7.849a31.743 31.743 0 0 0-3.339-.254v11.505a20.01 20.01 0 0 1 3.78.501.75.75 0 1 1-.339 1.462A18.558 18.558 0 0 0 10 17.5c-1.442 0-2.845.165-4.191.477a.75.75 0 0 1-.338-1.462 20.01 20.01 0 0 1 3.779-.501V4.509c-1.129.026-2.243.112-3.34.254l1.771 7.85a.75.75 0 0 1-.387.83A4.98 4.98 0 0 1 5 14a4.98 4.98 0 0 1-2.294-.556.75.75 0 0 1-.387-.832L4.02 5.067c-.37.07-.738.148-1.103.232a.75.75 0 0 1-.336-1.462 32.845 32.845 0 0 1 6.668-.829V2.75A.75.75 0 0 1 10 2ZM5 7.543 3.92 12.33a3.499 3.499 0 0 0 2.16 0L5 7.543Zm10 0-1.08 4.787a3.498 3.498 0 0 0 2.16 0L15 7.543Z",clipRule:"evenodd"}))}const Is=r.forwardRef(qs);function Zs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{d:"M15.98 1.804a1 1 0 0 0-1.96 0l-.24 1.192a1 1 0 0 1-.784.785l-1.192.238a1 1 0 0 0 0 1.962l1.192.238a1 1 0 0 1 .785.785l.238 1.192a1 1 0 0 0 1.962 0l.238-1.192a1 1 0 0 1 .785-.785l1.192-.238a1 1 0 0 0 0-1.962l-1.192-.238a1 1 0 0 1-.785-.785l-.238-1.192ZM6.949 5.684a1 1 0 0 0-1.898 0l-.683 2.051a1 1 0 0 1-.633.633l-2.051.683a1 1 0 0 0 0 1.898l2.051.684a1 1 0 0 1 .633.632l.683 2.051a1 1 0 0 0 1.898 0l.683-2.051a1 1 0 0 1 .633-.633l2.051-.683a1 1 0 0 0 0-1.898l-2.051-.683a1 1 0 0 1-.633-.633L6.95 5.684ZM13.949 13.684a1 1 0 0 0-1.898 0l-.184.551a1 1 0 0 1-.632.633l-.551.183a1 1 0 0 0 0 1.898l.551.183a1 1 0 0 1 .633.633l.183.551a1 1 0 0 0 1.898 0l.184-.551a1 1 0 0 1 .632-.633l.551-.183a1 1 0 0 0 0-1.898l-.551-.184a1 1 0 0 1-.633-.632l-.183-.551Z"}))}const Zn=r.forwardRef(Zs);function Hs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M4.5 2A2.5 2.5 0 0 0 2 4.5v3.879a2.5 2.5 0 0 0 .732 1.767l7.5 7.5a2.5 2.5 0 0 0 3.536 0l3.878-3.878a2.5 2.5 0 0 0 0-3.536l-7.5-7.5A2.5 2.5 0 0 0 8.38 2H4.5ZM5 6a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z",clipRule:"evenodd"}))}const Ws=r.forwardRef(Hs);function zs({title:e,titleId:n,...a},s){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":n},a),e?r.createElement("title",{id:n},e):null,r.createElement("path",{fillRule:"evenodd",d:"M14.5 10a4.5 4.5 0 0 0 4.284-5.882c-.105-.324-.51-.391-.752-.15L15.34 6.66a.454.454 0 0 1-.493.11 3.01 3.01 0 0 1-1.618-1.616.455.455 0 0 1 .11-.494l2.694-2.692c.24-.241.174-.647-.15-.752a4.5 4.5 0 0 0-5.873 4.575c.055.873-.128 1.808-.8 2.368l-7.23 6.024a2.724 2.724 0 1 0 3.837 3.837l6.024-7.23c.56-.672 1.495-.855 2.368-.8.096.007.193.01.291.01ZM5 16a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z",clipRule:"evenodd"}),r.createElement("path",{d:"M14.5 11.5c.173 0 .345-.007.514-.022l3.754 3.754a2.5 2.5 0 0 1-3.536 3.536l-4.41-4.41 2.172-2.607c.052-.063.147-.138.342-.196.202-.06.469-.087.777-.067.128.008.257.012.387.012ZM6 4.586l2.33 2.33a.452.452 0 0 1-.08.09L6.8 8.214 4.586 6H3.309a.5.5 0 0 1-.447-.276l-1.7-3.402a.5.5 0 0 1 .093-.577l.49-.49a.5.5 0 0 1 .577-.094l3.402 1.7A.5.5 0 0 1 6 3.31v1.277Z"}))}const ue=r.forwardRef(zs),_t="uh:navigate",Hn=e=>(window.addEventListener("popstate",e),window.addEventListener(_t,e),()=>{window.removeEventListener("popstate",e),window.removeEventListener(_t,e)}),Kt=e=>n=>{window.history[e](null,"",n),window.dispatchEvent(new Event(_t))},Gs={push:Kt("pushState"),replace:Kt("replaceState"),back:()=>window.history.back(),refresh:()=>window.location.reload(),prefetch:()=>{}};function Xs(){return Gs}function Js(){return r.useSyncExternalStore(Hn,()=>window.location.pathname)}function Wn(){const e=r.useSyncExternalStore(Hn,()=>window.location.search);return r.useMemo(()=>new URLSearchParams(e),[e])}function Vs(e){throw window.location.replace(e),new Error(`redirect to ${e}`)}async function Ys(){return{user:{isAdmin:!0,isSuperAdmin:!0}}}async function Ks(){}const Ut={magify_agents_api:0,magify_next:1},zn=10*1024*1024,Ve=5,Us={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},Gn=[{id:"waiting-response",label:"Waiting for response"},{id:"wait-conflict-fix",label:"Wait for conflict fix"},{id:"warning",label:"Warning"},{id:"priority",label:"Priority"},{id:"later",label:"Later"},{id:"watch-after-ship",label:"Watch after ship"}],Qs=40;function er(e,n){const a=new Set(n?.flags||[]);return(e||[]).filter(s=>{const l=(s.flags||[]).map(i=>i.id);return n?.only==="none"?l.length===0:n?.only==="flagged"&&!l.length?!1:!a.size||l.some(i=>a.has(i))})}function tr(e){const n={flagged:0,none:0};return(e||[]).forEach(a=>{const s=a.flags||[];s.length?n.flagged+=1:n.none+=1,s.forEach(l=>{n[l.id]=(n[l.id]||0)+1})}),n}const Ct=[{key:"default",label:"Default order"},{key:"created-desc",label:"Newest created",field:"jira_created",dir:-1},{key:"created-asc",label:"Oldest created",field:"jira_created",dir:1},{key:"updated-desc",label:"Recently updated",field:"jira_updated",dir:-1},{key:"updated-asc",label:"Least recently updated",field:"jira_updated",dir:1}],Qe=e=>Ct.find(n=>n.key===e)||Ct[0],Qt=e=>{const n=e?new Date(e).getTime():NaN;return Number.isNaN(n)?null:n};function Xn(e,n){const{field:a,dir:s}=Qe(n);return a?[...e].sort((l,i)=>{const o=Qt(l[a]),c=Qt(i[a]);return o===null||c===null?(o===null)-(c===null):(o-c)*s}):e}function rt(e){const n=(e||[]).filter(s=>s.kind!=="directive");let a=-1;return n.forEach((s,l)=>{if(s.role!=="assistant"||Ne(s))return;const i=s.reply_to?n.findIndex(o=>o.id===s.reply_to):-1;a=Math.max(a,i>=0?i:l)}),n.some((s,l)=>s.role==="vincent"&&l>a)}function He(e){return(e||[]).filter(n=>n.kind==="directive").sort((n,a)=>new Date(n.at)-new Date(a.at)).pop()||null}const nr=/^\s*Fix (delivered|failed):/;function Ne(e){return e?.role!=="assistant"||!e.reply_to?null:(nr.exec(e.text||"")||[])[1]||null}function At(e){const n=He(e?.chat);if(!n)return null;const a=(e.chat||[]).find(s=>s.reply_to===n.id&&Ne(s));return a?{kind:Ne(a),message:a,request:n}:null}function ar(e){const n=[...e||[]].sort((i,o)=>new Date(i.at)-new Date(o.at)),a=new Set(n.filter(i=>i.kind==="directive").map(i=>i.id)),s=n.filter(i=>a.has(i.reply_to)&&Ne(i)),l=[];for(const i of n)s.includes(i)||(l.push(i),i.kind==="directive"&&l.push(...s.filter(o=>o.reply_to===i.id)));return l}function me(e){const n=He(e?.chat);if(!n)return null;if(!n.acked_at)return n;if(n.ack_error||At(e))return null;if(e.fix_round?.request_id===n.id)return n;const a=e.synced_at?new Date(e.synced_at).getTime():0;return new Date(n.acked_at).getTime()>=a?n:null}function sr(e){const n=new Map(e.map(s=>[s.head,s])),a=(s,l=0)=>{const i=n.get(s.base);return i&&i!==s&&l<e.length?1+a(i,l+1):0};return[...e].sort((s,l)=>a(s)-a(l)||(Ut[s.repo]??9)-(Ut[l.repo]??9)||s.number-l.number)}function lt(e){const n=new Map(e.map(a=>[a.head,a]));return sr(e).map((a,s)=>{const l=n.get(a.base);return{pr:a,step:s+1,parent:l&&l!==a?l:null}})}function rr(e,n){if(!e)return null;const a=!e.input_hash||e.input_hash!==e.live_hash,s=new Set((e.dismissed||[]).filter(i=>i.input_hash===e.input_hash).map(i=>i.id)),l=a?[]:(e.groups||[]).filter(i=>!s.has(i.id)&&i.keys.every(o=>n.has(o)));return{stale:a,running:!!e.running,generated_at:e.generated_at||null,input_hash:e.input_hash,groups:l}}const lr="https://magifyfun.atlassian.net/browse/",ir=[{key:"open",label:"Needs ruling"},{key:"confirmed",label:"Confirmed"},{key:"wrong",label:"Wrong"},{key:"all",label:"All"}],en={TRUE:{label:"Pipeline: true",cls:"bg-emerald-50 text-emerald-700 ring-emerald-600/20"},FALSE:{label:"Pipeline: false",cls:"bg-red-50 text-red-700 ring-red-600/20"},"FOR-RULING":{label:"Pipeline: unsure",cls:"bg-amber-50 text-amber-800 ring-amber-600/25"}},or=new Set(["done","terminé","closed","resolved","validé sur test"]),je=e=>e.vincent_ruling?.status||null,tn=e=>parseInt(e.claim_id.replace(/\D/g,""),10)||0;function $t(e){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function Jn(e,n){const a=new Map;return(e||[]).forEach(s=>{const l=n?.[s.key],i=l||s.key,o=a.get(i)||{key:i,status:l?null:s.status,merged_from:[]};l?o.merged_from.push(s.key):o.status=s.status,a.set(i,o)}),[...a.values()]}function Vn({ticket:e}){const n=or.has((e.status||"").toLowerCase());return t.jsxs("a",{href:lr+e.key,target:"_blank",rel:"noopener noreferrer","data-ticket":e.key,"data-merged-from":e.merged_from?.length?e.merged_from.join(","):void 0,title:e.merged_from?.length?`Merged from ${e.merged_from.join(", ")}`:void 0,className:`inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs font-medium transition-colors ${n?"border-gray-200 bg-gray-50 text-gray-500 hover:bg-gray-100":"border-indigo-200 bg-indigo-50 text-indigo-700 hover:bg-indigo-100"}`,children:[t.jsx("span",{className:"font-mono",children:e.key}),e.status&&t.jsxs("span",{className:n?"text-gray-400":"text-indigo-500",children:["· ",e.status]}),e.merged_from?.length>0&&t.jsxs("span",{className:n?"text-gray-400":"text-indigo-500",children:["· merged from ",e.merged_from.join(", ")]})]})}const dr=e=>!!e&&["situation","quote","platform_truth","stakes"].some(n=>e[n]);function yt({label:e,children:n}){return t.jsxs("div",{children:[t.jsx("h3",{className:"text-xs font-semibold text-gray-500",children:e}),t.jsx("p",{className:"mt-1 whitespace-pre-line",children:n})]})}function cr({id:e,context:n}){return t.jsxs("div",{id:e,"data-claim-context":!0,className:"mt-3 space-y-3.5 rounded-lg bg-gray-50 px-3 py-3 text-sm leading-relaxed text-gray-700 [overflow-wrap:anywhere] sm:px-4",children:[n.situation&&t.jsx(yt,{label:"Situation",children:n.situation}),n.quote&&t.jsxs("blockquote",{className:"border-l-2 border-indigo-300 pl-3 text-[15px] italic text-gray-900",children:["“",n.quote,"”"]}),n.platform_truth&&t.jsx(yt,{label:"What the platform really does",children:n.platform_truth}),n.stakes&&t.jsx(yt,{label:"What your ruling decides",children:n.stakes})]})}function ur({request:e,mergedInto:n}){return t.jsxs("div",{"data-build-request":!0,className:"mt-4 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2.5 text-sm text-amber-950",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1.5",children:[t.jsxs("p",{className:"inline-flex items-center gap-1.5 font-medium",children:[t.jsx(ue,{className:"h-4 w-4 text-amber-600","aria-hidden":!0}),"Build requested",t.jsxs("span",{className:"font-normal opacity-70",children:["· ",$t(e.requested_at)]})]}),e.ticket?.key?t.jsx(Vn,{ticket:Jn([e.ticket],n)[0]}):t.jsx("span",{className:"text-xs text-amber-800/80",children:"Ticket filed on the next sync"})]}),t.jsx("p",{className:"mt-1.5 whitespace-pre-line [overflow-wrap:anywhere]",children:e.text})]})}function nn({disabled:e,onClick:n}){return t.jsxs("button",{type:"button",disabled:e,onClick:n,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg border border-amber-300 bg-amber-50 px-4 text-sm font-semibold text-amber-900 hover:bg-amber-100 focus:outline-none focus:ring-2 focus:ring-amber-500 focus:ring-offset-2 disabled:opacity-50",children:[t.jsx(ue,{className:"h-4 w-4 text-amber-600","aria-hidden":!0}),"Build this"]})}function mr({claim:e,onRule:n,onBuild:a,mergedInto:s}){const l=je(e),i=e.build_request?.requested_at?e.build_request:null,o=!i&&l!=="wrong",[c,d]=r.useState("idle"),[m,p]=r.useState(e.vincent_ruling?.correction||""),[u,g]=r.useState(""),[h,$]=r.useState(!1),[N,b]=r.useState(null),[f,x]=r.useState(!1),j=dr(e.context),S=`context-${e.claim_id}`,B=en[e.verdict]||en["FOR-RULING"],k=!l||c==="editing",E=async A=>{if(A==="wrong"&&!m.trim()){b("Write what is actually true before saving.");return}$(!0),b(null);try{await n(e.claim_id,A,A==="wrong"?m.trim():""),d("idle")}catch(M){b(M.message)}finally{$(!1)}},R=async()=>{if(!u.trim()){b("Describe what should exist before saving.");return}$(!0),b(null);try{await a(e.claim_id,u.trim()),d("idle")}catch(A){b(A.message)}finally{$(!1)}},F=l==="wrong"?"border-red-200":l==="confirmed"?"border-emerald-200":"border-gray-200";return t.jsxs("article",{"data-claim":e.claim_id,className:`rounded-xl border bg-white p-4 shadow-sm sm:p-5 ${F}`,children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1.5 text-xs",children:[t.jsx("span",{className:"font-mono font-semibold text-gray-500",children:e.claim_id}),t.jsx("span",{className:"text-gray-300","aria-hidden":!0,children:"·"}),t.jsx("span",{className:"font-medium text-gray-700",children:e.topic}),t.jsx("span",{className:`ml-auto inline-flex items-center rounded-full px-2 py-0.5 font-medium ring-1 ring-inset ${B.cls}`,children:B.label})]}),t.jsx("p",{className:"mt-3 text-[15px] leading-relaxed text-gray-900",children:e.canonical_claim}),t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[t.jsxs("p",{className:"text-xs text-gray-400",children:["Said ",e.occurrences," ",e.occurrences===1?"time":"times",e.first_seen?` · first on ${$t(e.first_seen)}`:""]}),j&&t.jsxs("button",{type:"button","aria-expanded":f,"aria-controls":S,onClick:()=>x(A=>!A),className:"-my-2 inline-flex shrink-0 items-center gap-0.5 rounded-md py-2 pl-2 text-xs font-medium text-indigo-600 hover:text-indigo-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:["Details",t.jsx(pe,{className:`h-4 w-4 transition-transform ${f?"rotate-90":""}`,"aria-hidden":!0})]})]}),j&&f&&t.jsx(cr,{id:S,context:e.context}),e.tickets?.length>0&&t.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:Jn(e.tickets,s).map(A=>t.jsx(Vn,{ticket:A},A.key))}),l&&c!=="editing"&&t.jsxs("div",{className:`mt-4 rounded-lg px-3 py-2.5 text-sm ${l==="wrong"?"bg-red-50 text-red-900":"bg-emerald-50 text-emerald-900"}`,children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("p",{className:"font-medium",children:[l==="wrong"?"You marked this wrong":"You confirmed this",t.jsxs("span",{className:"font-normal opacity-70",children:[" · ",$t(e.vincent_ruling?.ruled_at)]})]}),!i&&t.jsx("button",{type:"button",onClick:()=>{d("editing"),b(null)},className:"shrink-0 text-xs font-medium underline underline-offset-2 opacity-70 hover:opacity-100",children:"Change"})]}),l==="wrong"&&e.vincent_ruling?.correction&&t.jsx("p",{className:"mt-1.5 whitespace-pre-line",children:e.vincent_ruling.correction})]}),i&&t.jsx(ur,{request:i,mergedInto:s}),l==="confirmed"&&o&&c==="idle"&&t.jsx("div",{className:"mt-3",children:t.jsx(nn,{onClick:()=>{d("building"),b(null)}})}),k&&c!=="correcting"&&c!=="building"&&t.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",disabled:h,onClick:()=>E("confirmed"),className:"inline-flex min-h-[40px] items-center rounded-lg bg-indigo-600 px-4 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:opacity-50",children:h?"Saving…":"Confirm"}),t.jsx("button",{type:"button",disabled:h,onClick:()=>{d("correcting"),b(null)},className:"inline-flex min-h-[40px] items-center rounded-lg border border-red-200 bg-white px-4 text-sm font-semibold text-red-700 hover:bg-red-50 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 disabled:opacity-50",children:"Wrong"}),!l&&o&&t.jsx(nn,{disabled:h,onClick:()=>{d("building"),b(null)}}),c==="editing"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",disabled:h,onClick:()=>E(null),className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Clear ruling"}),t.jsx("button",{type:"button",onClick:()=>d("idle"),className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Cancel"})]})]}),c==="correcting"&&t.jsxs("div",{className:"mt-4",children:[t.jsx("label",{htmlFor:`correction-${e.claim_id}`,className:"block text-sm font-medium text-gray-800",children:"What is actually true?"}),t.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:"MAX will be corrected to say this. A fix ticket is filed on the next sync."}),t.jsx("textarea",{id:`correction-${e.claim_id}`,value:m,onChange:A=>p(A.target.value),rows:4,required:!0,autoFocus:!0,className:"mt-2 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500",placeholder:"The correct fact, worded the way MAX should say it."}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",disabled:h||!m.trim(),onClick:()=>E("wrong"),className:"inline-flex min-h-[40px] items-center rounded-lg bg-red-600 px-4 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 disabled:opacity-50",children:h?"Saving…":"Save correction"}),t.jsx("button",{type:"button",onClick:()=>{d(l?"editing":"idle"),b(null)},className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Cancel"})]})]}),c==="building"&&t.jsxs("div",{className:"mt-4",children:[t.jsx("label",{htmlFor:`build-${e.claim_id}`,className:"block text-sm font-medium text-gray-800",children:"What should exist instead?"}),t.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:["Your words become the spec of a feature ticket, filed on the next sync.",!l&&" Saving also confirms this claim."]}),t.jsx("textarea",{id:`build-${e.claim_id}`,value:u,onChange:A=>g(A.target.value),rows:4,required:!0,autoFocus:!0,className:"mt-2 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-amber-500 focus:outline-none focus:ring-1 focus:ring-amber-500",placeholder:"The capability, described the way it should work for a creator."}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",disabled:h||!u.trim(),onClick:R,className:"inline-flex min-h-[40px] items-center rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 disabled:opacity-50",children:h?"Saving…":"Request build"}),t.jsx("button",{type:"button",onClick:()=>{d("idle"),b(null)},className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Cancel"})]})]}),N&&t.jsx("p",{className:"mt-2 text-sm text-red-700",role:"alert",children:N})]})}function an({initialClaims:e,embedded:n=!1,mergedInto:a={}}){const[s,l]=r.useState(e||[]),[i,o]=r.useState("open"),[c,d]=r.useState(""),[m,p]=r.useState(()=>new Set),u=x=>{o(x),p(new Set)},g=r.useMemo(()=>({open:s.filter(x=>!je(x)).length,confirmed:s.filter(x=>je(x)==="confirmed").length,wrong:s.filter(x=>je(x)==="wrong").length,all:s.length}),[s]),h=r.useMemo(()=>{const x=c.trim().toLowerCase();return s.filter(j=>{const S=je(j);return i==="open"&&S&&!m.has(j.claim_id)||i==="confirmed"&&S!=="confirmed"||i==="wrong"&&S!=="wrong"?!1:x?[j.claim_id,j.topic,j.canonical_claim,j.vincent_ruling?.correction,j.build_request?.text,j.build_request?.ticket?.key,...(j.tickets||[]).map(B=>B.key)].some(B=>B&&B.toLowerCase().includes(x)):!0}).sort((j,S)=>{const B=k=>!!je(k)&&!m.has(k.claim_id);return B(j)-B(S)||tn(S)-tn(j)})},[s,i,c,m]),$=async(x,j)=>{const S=await fetch(x,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)}),B=await S.json().catch(()=>({}));if(!S.ok)throw new Error(B.error||`Could not save (${S.status})`);l(k=>k.map(E=>E.claim_id===j.claim_id?B.claim:E)),p(k=>new Set(k).add(j.claim_id))},N=(x,j,S)=>$("/api/admin/claims/ruling",{claim_id:x,status:j,correction:S}),b=(x,j)=>$("/api/admin/claims/build-request",{claim_id:x,text:j}),f=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"-mx-4 mt-5 bg-gray-50/95 px-4 pb-3 pt-2 backdrop-blur sm:-mx-8 sm:px-8 md:sticky md:top-0 md:z-10 xl:flex xl:items-center xl:gap-3",children:[t.jsx("div",{role:"tablist","aria-label":"Filter claims",className:"grid grid-cols-4 gap-1 rounded-lg bg-gray-200/70 p-1 xl:w-[40rem] xl:shrink-0",children:ir.map(x=>{const j=i===x.key;return t.jsxs("button",{type:"button",role:"tab","aria-selected":j,onClick:()=>u(x.key),className:`flex min-h-[44px] flex-col items-center justify-center whitespace-nowrap rounded-md px-1 text-[13px] font-medium leading-tight transition-colors sm:min-h-[36px] sm:flex-row sm:gap-1.5 sm:px-3 sm:text-sm ${j?"bg-white text-gray-900 shadow-sm":"text-gray-600 hover:text-gray-900"}`,children:[x.label,t.jsx("span",{className:`tabular-nums text-xs ${j?"text-indigo-600":"text-gray-400"}`,children:g[x.key]})]},x.key)})}),t.jsx("input",{type:"search",value:c,onChange:x=>d(x.target.value),placeholder:"Search claims, topics, tickets","aria-label":"Search claims",className:"mt-2 block w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm xl:mt-0 xl:max-w-md text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"})]}),t.jsxs("div",{className:`mt-2 grid grid-cols-1 items-start gap-3 ${n?"2xl:grid-cols-2":""}`,children:[h.map(x=>t.jsx(mr,{claim:x,onRule:N,onBuild:b,mergedInto:a},x.claim_id)),h.length===0&&t.jsx("p",{className:"col-span-full rounded-xl border border-dashed border-gray-300 bg-white px-4 py-10 text-center text-sm text-gray-500",children:s.length===0?"No claims yet. They arrive with the next pipeline sync.":c?`Nothing matches "${c}".`:i==="open"?"Every claim has a ruling.":"No claims here yet."})]})]});return n?f:t.jsx("div",{className:"min-h-full bg-gray-50",children:t.jsxs("div",{className:"mx-auto max-w-3xl px-4 pb-8 pt-16 sm:px-8 md:pt-8",children:[t.jsxs("header",{children:[t.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"MAX claims"}),t.jsx("p",{className:"mt-1 text-sm text-gray-600",children:"Platform facts MAX told creators, with the pipeline's verdict. Your ruling is the truth MAX gets corrected to."})]}),f]})})}const Yn="(max-width: 1023.98px)",xr=e=>{const n=window.matchMedia(Yn);return n.addEventListener("change",e),()=>n.removeEventListener("change",e)};function Kn(){return r.useSyncExternalStore(xr,()=>window.matchMedia(Yn).matches,()=>null)}const hr="https://magifyfun.atlassian.net/browse/",gr=e=>`/api/admin/pipeline/evidence?k=${encodeURIComponent(e.s3_key)}`;function sn(e){const n=e?new Date(e):null;return n&&!Number.isNaN(n.getTime())?n.toLocaleDateString("en-GB",{day:"numeric",month:"short"}):""}const Un=r.createContext(null),it=()=>r.useContext(Un),Qn=r.createContext(null);function ea(){const e=r.useContext(Qn),n=it();return r.useCallback((a,s)=>{e?.advance(a),s&&n?.toast(s)},[e,n])}function pr(){return it()?.defer}const fr=4e3,br=":where(html, body, body *){touch-action:pan-x pan-y}";function yr(){r.useEffect(()=>{const e=s=>{s.cancelable&&s.preventDefault()},n=s=>{s.touches.length>1&&s.cancelable&&s.preventDefault()},a={passive:!1};return document.addEventListener("gesturestart",e,a),document.addEventListener("gesturechange",e,a),document.addEventListener("touchmove",n,a),()=>{document.removeEventListener("gesturestart",e,a),document.removeEventListener("gesturechange",e,a),document.removeEventListener("touchmove",n,a)}},[])}function ce({title:e,onClose:n,children:a,tall:s=!1,label:l}){const i=r.useRef(null),o=r.useRef(null),[c,d]=r.useState(0);r.useEffect(()=>{const g=document.activeElement;i.current?.focus({preventScroll:!0});const h=$=>{$.key==="Escape"&&!document.querySelector("[data-lightbox], [data-cancel-dialog], [data-dismiss-dialog], [data-merge-dialog]")&&n()};return window.addEventListener("keydown",h),()=>{window.removeEventListener("keydown",h),g&&typeof g.focus=="function"&&g.focus({preventScroll:!0})}},[n]);const m=g=>{o.current=g.touches[0].clientY},p=g=>{o.current!=null&&d(Math.max(0,g.touches[0].clientY-o.current))},u=()=>{const g=c>90;o.current=null,d(0),g&&n()};return Bn.createPortal(t.jsxs("div",{className:"fixed inset-0 z-[45] flex flex-col justify-end","data-phone-sheet":l,children:[t.jsx("button",{type:"button","aria-label":"Close",tabIndex:-1,onClick:n,className:"absolute inset-0 bg-gray-950/50 motion-safe:animate-[phoneFade_160ms_ease-out]"}),t.jsxs("div",{ref:i,role:"dialog","aria-modal":"true","aria-label":e,tabIndex:-1,style:c?{transform:`translateY(${c}px)`}:void 0,className:`relative flex w-full flex-col rounded-t-2xl bg-white shadow-2xl outline-none motion-safe:animate-[phoneRise_200ms_ease-out] ${s?"h-[92dvh]":"max-h-[92dvh]"}`,children:[t.jsxs("div",{onTouchStart:m,onTouchMove:p,onTouchEnd:u,className:"shrink-0 touch-none",children:[t.jsx("div",{className:"mx-auto mt-2 h-1.5 w-10 rounded-full bg-gray-300","aria-hidden":!0}),t.jsxs("div",{className:"flex items-center gap-2 pl-4 pr-1.5",children:[t.jsx("h2",{className:"min-w-0 flex-1 truncate py-2 text-base font-semibold text-gray-900",children:e}),t.jsx("button",{type:"button","data-sheet-close":!0,onClick:n,"aria-label":"Close",className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-full text-gray-500 hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:t.jsx(fe,{className:"h-6 w-6","aria-hidden":!0})})]})]}),t.jsxs("div",{"data-sheet-body":!0,className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-[max(1rem,env(safe-area-inset-bottom))]",children:[a,t.jsx("div",{className:"pointer-events-none sticky bottom-0 -mx-4 -mt-6 h-6 bg-gradient-to-t from-white to-transparent","aria-hidden":!0})]})]})]}),document.body)}function ot({children:e}){return e?Bn.createPortal(e,document.body):null}function wt({children:e,className:n="",...a}){return t.jsx("button",{type:"button",className:`inline-flex h-11 shrink-0 items-center justify-center rounded-lg text-gray-700 hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 ${n}`,...a,children:e})}function wr({tab:e,tabs:n,counts:a,onTab:s,filterActive:l,renderFilters:i,children:o}){const[c,d]=r.useState(null),[m,p]=r.useState(null),[u,g]=r.useState(null),h=r.useCallback(()=>d(null),[]),$=r.useRef(null);yr();const N=r.useMemo(()=>({report:p,toast:x=>g({text:x,at:Date.now()}),defer:({text:x,run:j})=>{$.current&&(clearTimeout($.current.timer),$.current.run());const S={run:j};S.timer=setTimeout(()=>{$.current=null,g(null),j()},fr),$.current=S,g({text:x,at:Date.now(),undo:()=>{clearTimeout(S.timer),$.current=null,g({text:"Undone: nothing was sent.",at:Date.now()})}})}}),[]);r.useEffect(()=>{if(!u||u.undo)return;const x=setTimeout(()=>g(null),2800);return()=>clearTimeout(x)},[u]);const b=n.find(x=>x.key===e),f=m?.total?(m.index+1)/m.total*100:0;return t.jsxs(Un.Provider,{value:N,children:[t.jsxs("div",{"data-phone-cockpit":!0,className:"flex h-dvh flex-col overflow-hidden bg-gray-100",children:[t.jsx("style",{children:`@keyframes phoneRise{from{transform:translateY(100%)}to{transform:none}}@keyframes phoneFade{from{opacity:0}to{opacity:1}}${br}`}),t.jsxs("header",{"data-phone-header":!0,className:"relative z-20 shrink-0 border-b border-gray-200 bg-white",children:[t.jsxs("div",{className:"flex h-16 items-center gap-1 pl-[60px] pr-1.5 pt-2 md:h-14 md:pl-3 md:pt-0",children:[t.jsxs(wt,{"data-phone-tabs":!0,onClick:()=>d("tabs"),"aria-haspopup":"dialog",className:"min-w-0 flex-1 justify-start gap-1.5 px-2 text-left",children:[t.jsx("span",{className:"truncate text-[15px] font-semibold text-gray-900",children:b?.label}),!m?.total&&a[e]>0&&t.jsx("span",{className:"shrink-0 rounded-full bg-gray-900 px-1.5 text-xs font-semibold tabular-nums text-white",children:a[e]}),t.jsx(qn,{className:"h-5 w-5 shrink-0 text-gray-400","aria-hidden":!0})]}),m?.total>0&&t.jsxs(wt,{"data-phone-position":!0,onClick:()=>d("jump"),"aria-label":`Ticket ${m.index+1} of ${m.total}. Jump to a ticket`,className:"min-w-[64px] px-2 text-sm font-semibold tabular-nums",children:[m.index+1,t.jsxs("span",{className:"font-normal text-gray-400",children:["/",m.total]})]}),i&&t.jsxs(wt,{"data-phone-filters":!0,onClick:()=>d("filters"),"aria-label":l?"Filters (on)":"Filters",className:"relative w-11",children:[t.jsx(Ua,{className:"h-5 w-5","aria-hidden":!0}),l&&t.jsx("span",{className:"absolute right-2 top-2 h-2 w-2 rounded-full bg-indigo-600","aria-hidden":!0})]})]}),t.jsx("div",{className:"h-0.5 bg-gray-100","aria-hidden":!0,children:t.jsx("div",{"data-phone-progress":!0,className:"h-full origin-left bg-gray-900 transition-transform duration-200 motion-reduce:transition-none",style:{transform:`scaleX(${f/100})`}})})]}),t.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[o,u&&t.jsxs("div",{"data-phone-toast":!0,role:"status",className:"absolute inset-x-3 bottom-[calc(76px+env(safe-area-inset-bottom))] z-30 flex min-h-[48px] items-center gap-3 rounded-xl bg-gray-900 py-1 pl-3.5 pr-1 text-sm font-medium text-white shadow-lg motion-safe:animate-[phoneFade_160ms_ease-out]",children:[t.jsx("span",{className:"min-w-0 flex-1",children:u.text}),u.undo&&t.jsx("button",{type:"button","data-toast-undo":!0,onClick:u.undo,className:"h-11 shrink-0 rounded-lg px-3 font-semibold text-amber-300 hover:bg-white/10",children:"Undo"})]},u.at)]})]}),c==="tabs"&&t.jsx(ce,{title:"Review",label:"tabs",onClose:h,children:t.jsx("ul",{className:"-mx-1 pb-2",children:n.map(x=>{const j=x.key===e;return t.jsx("li",{children:t.jsxs("button",{type:"button","data-phone-tab":x.key,"aria-current":j?"page":void 0,onClick:()=>{s(x.key),h()},className:`flex min-h-[52px] w-full items-center gap-3 rounded-xl px-3 text-left text-[15px] ${j?"bg-gray-900 font-semibold text-white":"text-gray-800 hover:bg-gray-50"}`,children:[t.jsx("span",{className:"flex-1",children:x.label}),a[x.key]>0&&t.jsx("span",{className:`text-sm tabular-nums ${j?"text-white/70":"text-gray-400"}`,children:a[x.key]})]})},x.key)})})}),c==="filters"&&i&&t.jsx(ce,{title:"Filter",label:"filters",onClose:h,children:t.jsx("div",{className:"pb-3 [&_button]:min-h-[44px]",children:i()})}),c==="jump"&&m?.items&&t.jsx(ce,{title:`${b?.label} · ${m.total}`,label:"jump",onClose:h,children:t.jsx(jr,{pos:m,onPick:x=>{m.jump(x),h()}})})]})}function jr({pos:e,onPick:n}){const a=r.useRef(null);return r.useEffect(()=>{a.current?.querySelector('[aria-current="true"]')?.scrollIntoView({block:"center"})},[]),t.jsx("ol",{ref:a,className:"-mx-1 pb-2",children:e.items.map((s,l)=>t.jsx("li",{children:t.jsxs("button",{type:"button","data-phone-jump":s.key,"aria-current":l===e.index?"true":void 0,onClick:()=>n(l),className:`flex min-h-[52px] w-full items-center gap-3 rounded-xl px-3 py-2 text-left ${l===e.index?"bg-gray-100":"hover:bg-gray-50"}`,children:[t.jsx("span",{className:"w-7 shrink-0 text-right text-xs tabular-nums text-gray-400",children:l+1}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block font-mono text-[11px] text-gray-500",children:s.key}),t.jsx("span",{className:"block truncate text-sm text-gray-900",children:s.summary})]})]})},s.key))})}const vr=2;function ta({items:e,renderPage:n,empty:a}){const s=r.useRef(null),l=it(),[i,o]=r.useState(0),c=r.useRef(e[0]?.key),d=r.useRef(0),m=r.useRef(!1),p=r.useMemo(()=>({advance:b=>{m.current=b}}),[]),u=r.useCallback((b,f=!1)=>{const x=s.current;x&&x.scrollTo({top:b*x.clientHeight,behavior:f?"smooth":"instant"})},[]);r.useLayoutEffect(()=>{const b=m.current&&m.current===c.current?-1:e.findIndex(j=>j.key===c.current);m.current=null;const f=b>=0?b:Math.min(i,Math.max(0,e.length-1));c.current=e[f]?.key,f!==i&&o(f);const x=s.current;x&&Math.round(x.scrollTop/(x.clientHeight||1))!==f&&(x.scrollTop=f*x.clientHeight)},[e]),r.useEffect(()=>{const b=s.current;if(!b||typeof ResizeObserver>"u")return;const f=new ResizeObserver(()=>{const x=e.findIndex(j=>j.key===c.current);x>=0&&(b.scrollTop=x*b.clientHeight)});return f.observe(b),()=>f.disconnect()},[e]);const g=r.useRef(null),h=()=>{g.current=s.current?.scrollTop??null},$=()=>{const b=s.current,f=g.current;if(g.current=null,!b||f==null)return;const x=b.clientHeight||1,j=b.scrollTop-f;if(Math.abs(j)<x*.15)return;const S=Math.max(0,Math.min(e.length-1,Math.round(f/x)+Math.sign(j)));b.scrollTo({top:S*x,behavior:"smooth"})},N=()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(()=>{const b=s.current;if(!b)return;const f=Math.max(0,Math.min(e.length-1,Math.round(b.scrollTop/(b.clientHeight||1))));f!==i&&(c.current=e[f]?.key,o(f))})};return r.useEffect(()=>{l?.report(e.length?{index:i,total:e.length,items:e,jump:u}:null)},[i,e,u,l]),r.useEffect(()=>()=>l?.report(null),[l]),e.length?t.jsx(Qn.Provider,{value:p,children:t.jsx("div",{ref:s,"data-phone-feed":!0,onScroll:N,onTouchStart:h,onTouchEnd:$,onTouchCancel:$,className:"min-h-0 flex-1 snap-y snap-mandatory overflow-y-auto overscroll-y-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:e.map((b,f)=>t.jsx("section",{"data-phone-page":b.key,"data-page-index":f,"data-page-active":f===i?"true":void 0,"aria-label":`Ticket ${f+1} of ${e.length}: ${b.key}`,className:"h-full snap-start snap-always overflow-hidden [content-visibility:auto]",children:Math.abs(f-i)<=vr?n(b,f===i):null},b.key))})}):t.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:a})}function Pt({images:e,onOpen:n,eager:a=!1,grow:s=!1}){const l=r.useRef(null),[i,o]=r.useState(!1);r.useLayoutEffect(()=>{const m=s&&l.current?.parentElement;if(!m||typeof ResizeObserver>"u")return;const p=new ResizeObserver(()=>o(m.clientHeight>=170));return p.observe(m),()=>p.disconnect()},[s]);const c=e.length;if(!c)return null;const d=gr(e[0]);return t.jsxs("button",{ref:l,type:"button","data-proof-button":!0,"data-proof-big":i?"true":void 0,"aria-haspopup":"dialog",onClick:()=>n(0),className:`mx-4 flex w-[calc(100%-2rem)] flex-col overflow-hidden rounded-xl border border-gray-300 bg-white text-left shadow-sm active:bg-gray-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 ${i?"min-h-0 flex-1":"shrink-0"}`,children:[i&&t.jsx("span",{className:"relative block min-h-0 w-full flex-1 bg-gray-50",children:t.jsx("img",{src:d,alt:"",loading:a?"eager":"lazy",decoding:"async",draggable:!1,className:"absolute inset-0 h-full w-full object-contain"})}),t.jsxs("span",{className:`flex h-14 w-full shrink-0 items-center gap-3 pr-3 ${i?"border-t border-gray-200 pl-4":"pl-1.5"}`,children:[!i&&t.jsx("span",{className:"h-11 w-16 shrink-0 overflow-hidden rounded-lg bg-gray-100 ring-1 ring-inset ring-gray-200",children:t.jsx("img",{src:d,alt:"",loading:a?"eager":"lazy",decoding:"async",draggable:!1,className:"h-full w-full object-cover object-left-top"})}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-[15px] font-semibold text-gray-900",children:c===1?"See the proof image":`See the ${c} proof images`}),t.jsx(ls,{className:"h-5 w-5 shrink-0 text-gray-500","aria-hidden":!0})]})]})}function Bt({grow:e=!1,children:n}){return t.jsx("div",{"data-proof-zone":!0,className:`pb-2 pt-1.5 ${e?"flex min-h-[72px] flex-1 flex-col justify-end":"shrink-0"}`,children:n})}function ke({children:e,onMore:n,keepAll:a=!1,hug:s=!1,className:l=""}){const i=r.useRef(null),[o,c]=r.useState(null),[d,m]=r.useState(0);r.useLayoutEffect(()=>{const u=i.current;if(!u)return;const g=()=>{const N=[...u.children];if(N.forEach(R=>{R.style.display=""}),u.querySelectorAll("li").forEach(R=>{Object.assign(R.style,{display:"",maxHeight:"",overflow:""})}),u.querySelectorAll("[data-fit-body]").forEach(R=>{Object.assign(R.style,{display:"",WebkitLineClamp:"",WebkitBoxOrient:"",overflow:""})}),u.scrollHeight<=u.clientHeight+1){c(null);return}const b=u.clientHeight-44,f=R=>R.getBoundingClientRect().top-u.getBoundingClientRect().top,x=R=>R.getBoundingClientRect().bottom-u.getBoundingClientRect().top,j=R=>parseFloat(getComputedStyle(R).lineHeight)||20;if(a){const R=N.map(C=>C.querySelector("[data-fit-body]")).filter(Boolean),F=R.map(j),A=R.map((C,O)=>Math.max(1,Math.round(C.getBoundingClientRect().height/F[O]))),M=u.scrollHeight-R.reduce((C,O)=>C+O.getBoundingClientRect().height,0);let W=b-M;const v=R.map(()=>0);for(let C=!0;C;)C=!1,R.forEach((O,y)=>{v[y]<A[y]&&(v[y]===0||W>=F[y])&&(v[y]+=1,W-=F[y],C=!0)});R.forEach((C,O)=>{v[O]<A[O]&&Object.assign(C.style,{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:String(v[O]),overflow:"hidden"})}),c([]),m(Math.min(b,Math.ceil(x(N[N.length-1]))));return}const S=[];let B=!1,k=!1;N.forEach(R=>{const F=R.querySelector("[data-fit-label]")?.textContent;if(k){R.style.display="none",F&&S.push(F);return}if(x(R)<=b){B=!0;return}k=!0;const A=R.querySelector("[data-fit-body]"),M=A?[...A.querySelectorAll("li")]:[],W=M.filter(O=>x(O)<=b);if(M.length&&W.length){M.forEach(O=>{x(O)>b&&(O.style.display="none")}),F&&S.push(`the rest of ${F.toLowerCase()}`);return}if(B||!A){R.style.display="none",F&&S.push(F);return}const v=M[0]||A,C=Math.max(1,Math.floor((b-f(v))/j(v)));Object.assign(v.style,{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:String(C),overflow:"hidden"})}),c(S);const E=N.filter(R=>R.style.display!=="none");m(E.length?Math.min(b,Math.ceil(x(E[E.length-1]))):0)};if(g(),typeof ResizeObserver>"u")return;let h=u.clientHeight;const $=new ResizeObserver(()=>{u.clientHeight!==h&&(h=u.clientHeight,g())});return $.observe(u),()=>$.disconnect()},[e,a]);const p=o&&(o.length?`${o.join(", ")} in Details`:"Read all in Details");return t.jsxs("div",{className:`relative flex min-h-0 flex-col ${s?"flex-[0_1_auto]":"flex-1"} ${l}`,style:s&&p?{minHeight:d+44}:void 0,children:[t.jsx("div",{ref:i,"data-fit-text":!0,"data-overflowing":o?"true":void 0,className:"relative min-h-0 flex-1 overflow-hidden",children:e}),p&&t.jsxs("button",{type:"button","data-fit-more":!0,onClick:n,style:{top:d},className:"absolute left-4 inline-flex h-11 max-w-[calc(100%-2rem)] items-center gap-1 text-sm font-medium text-indigo-700",children:[t.jsx("span",{className:"truncate first-letter:uppercase",children:p}),t.jsx(pe,{className:"h-4 w-4 shrink-0","aria-hidden":!0})]})]})}function J({label:e,strong:n=!1,children:a}){return a?t.jsxs("div",{className:"mt-2.5 first:mt-0",children:[t.jsx("p",{"data-fit-label":!0,className:"text-[11px] font-semibold uppercase tracking-wide text-gray-500",children:e}),t.jsx("div",{"data-fit-body":!0,className:`mt-0.5 leading-snug text-gray-900 [overflow-wrap:anywhere] ${n?"text-base font-semibold":"text-[15px]"}`,children:a})]}):null}const Nr={ok:"bg-emerald-50 text-emerald-800 ring-emerald-200",warn:"bg-amber-50 text-amber-900 ring-amber-300",bad:"bg-red-50 text-red-800 ring-red-200",info:"bg-indigo-50 text-indigo-800 ring-indigo-200",muted:"bg-gray-100 text-gray-600 ring-gray-200"};function _e({ticket:e,pill:n,dates:a,summary:s,chips:l,select:i,lines:o=3}){return t.jsxs("div",{className:"shrink-0 px-4 pt-2.5",children:[t.jsxs("div",{className:"-my-2 flex items-center gap-1.5",children:[i,t.jsx("a",{href:hr+e.key,target:"_blank",rel:"noopener noreferrer","data-jira-key":e.key,"aria-label":`Open ${e.key} in Jira`,className:"flex h-11 shrink-0 items-center",children:t.jsx("span",{className:"rounded border border-gray-200 bg-gray-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-gray-600",children:e.key})}),n&&t.jsxs("span",{"data-phone-pill":n.kind,className:`inline-flex min-w-0 items-center gap-1 truncate rounded-full px-2 py-0.5 text-[11px] font-semibold ring-1 ring-inset ${Nr[n.kind]}`,children:[n.icon&&t.jsx(n.icon,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),t.jsx("span",{className:"truncate",children:n.label})]}),a&&t.jsx("span",{"data-phone-dates":!0,className:"ml-auto shrink-0 text-[11px] tabular-nums text-gray-500",children:a})]}),s&&t.jsx("h3",{"data-phone-summary":!0,className:`mt-1.5 text-[17px] font-semibold leading-snug text-gray-900 [overflow-wrap:anywhere] ${{3:"line-clamp-3",4:"line-clamp-4",5:"line-clamp-5",6:"line-clamp-6"}[o]}`,children:s}),l]})}function We(e){const n=sn(e.jira_created),a=sn(e.jira_updated);return n&&a&&a!==n?`Filed ${n} · updated ${a}`:n?`Filed ${n}`:""}function et({tone:e="bad",children:n}){const a=e==="bad"?"border-red-200 bg-red-50 text-red-900":"border-amber-300 bg-amber-50 text-amber-950";return t.jsxs("p",{"data-phone-banner":e,role:"status",className:`mx-4 mt-2 flex shrink-0 items-center gap-1.5 truncate rounded-lg border px-2.5 py-1.5 text-[13px] ${a}`,children:[t.jsx(ae,{className:`h-4 w-4 shrink-0 ${e==="bad"?"text-red-600":"text-amber-600"}`,"aria-hidden":!0}),t.jsx("span",{className:"truncate",children:n})]})}function Ce({actions:e=[],primary:n}){return t.jsx("nav",{"data-thumb-bar":!0,"aria-label":"Ticket actions",className:"mt-auto shrink-0 border-t border-gray-200 bg-white px-2 pb-[max(0.5rem,env(safe-area-inset-bottom))] pt-2",children:t.jsxs("div",{className:"grid grid-cols-5 gap-1.5",children:[e.map(a=>{const s=a.href?"a":"button";return t.jsxs(s,{"data-thumb-action":a.id,...a.href?{href:a.href,target:"_blank",rel:"noopener noreferrer"}:{type:"button",onClick:a.onClick,disabled:a.disabled},className:`relative flex min-h-[52px] flex-col items-center justify-center gap-0.5 rounded-xl px-1 text-[11px] font-medium leading-tight focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 disabled:opacity-40 ${a.tone==="danger"?"text-red-700 hover:bg-red-50":a.tone==="fix"?"text-amber-800 hover:bg-amber-50":"text-gray-700 hover:bg-gray-100"}`,children:[t.jsx(a.icon,{className:"h-5 w-5","aria-hidden":!0}),t.jsx("span",{className:"max-w-full truncate",children:a.label}),a.badge>0&&t.jsx("span",{className:"absolute right-2 top-1 min-w-[18px] rounded-full bg-indigo-600 px-1 text-[10px] font-semibold tabular-nums text-white",children:a.badge})]},a.id)}),n&&(()=>{const a=n.href?"a":"button",s=5-e.length;return t.jsxs(a,{"data-thumb-action":n.id,"data-thumb-primary":!0,...n.href?{href:n.href,target:"_blank",rel:"noopener noreferrer"}:{type:"button",onClick:n.onClick,disabled:n.disabled},style:{gridColumn:`span ${s} / span ${s}`},className:`flex min-h-[52px] items-center justify-center gap-1.5 rounded-xl px-2 text-[14px] font-semibold shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-40 ${n.muted?"bg-white text-gray-800 ring-1 ring-inset ring-gray-300 focus-visible:ring-gray-400":"bg-gray-900 text-white focus-visible:ring-gray-900"}`,children:[n.icon&&t.jsx(n.icon,{className:"h-4 w-4 shrink-0 max-[379px]:hidden","aria-hidden":!0}),t.jsx("span",{className:"truncate",children:n.label})]})})()]})})}const H={details:ws,chat:Fn,fix:ue,open:Le,check:Dn,later:Fe,dismiss:fe,bundles:Tt};function $e(){const[e,n]=r.useState(null),a=r.useCallback(()=>n(null),[]);return{sheet:e,open:n,close:a}}function rn({children:e}){return t.jsx("div",{"data-phone-strip":!0,className:"flex min-h-[48px] shrink-0 items-center gap-2 border-b border-gray-200 bg-white px-3 py-1",children:e})}function jt({children:e,primary:n=!1,className:a="",...s}){return t.jsx("button",{type:"button",className:`inline-flex min-h-[44px] shrink-0 items-center gap-1.5 rounded-lg px-3 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 disabled:opacity-40 ${n?"bg-gray-900 text-white":"text-gray-800 ring-1 ring-inset ring-gray-300"} ${a}`,...s,children:e})}function kr({selected:e,disabled:n,onToggle:a,ticketKey:s}){return t.jsx("label",{className:"-my-2 -ml-2 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center",title:"Select to merge",children:t.jsx("input",{type:"checkbox","data-select":s,checked:e,disabled:n&&!e,onChange:a,"aria-label":`Select ${s} to merge`,className:"h-5 w-5 rounded border-gray-300 text-gray-900 focus:ring-gray-900 disabled:opacity-40"})})}function _r(){return!!it()}const ln=e=>`/api/admin/pipeline/evidence?k=${encodeURIComponent(e.s3_key)}`,Cr=8,$r=300,on=280,Er=40,we=2.5,dn=5,Sr=.8,Rr=.22,cn=.45,Mr=.28,Tr=110,Ar="transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1)",Je=(e,n,a)=>Math.min(a,Math.max(n,e));function Pr({images:e,index:n,onIndex:a,onClose:s}){const l=e.length,i=e[n],o=r.useRef(null),c=r.useRef(null),d=r.useRef(null),m=r.useRef(null),[p,u]=r.useState(!1),[g,h]=r.useState(0),[$,N]=r.useState(null),b=r.useRef(!1),f=r.useRef({s:1,tx:0,ty:0}),x=r.useRef(null),j=r.useRef(null),S=r.useRef({index:n,n:l,onIndex:a,onClose:s});S.current={index:n,n:l,onIndex:a,onClose:s};const[,B]=r.useState(null),k=r.useCallback(y=>B(()=>{throw y}),[]),E=r.useCallback(()=>{const y=c.current,_=d.current;if(!y||!_)return null;const L=y.getBoundingClientRect();return x.current={W:window.innerWidth,H:window.innerHeight,cx:L.left+L.width/2,cy:L.top+L.height/2,w:_.offsetWidth||1,h:_.offsetHeight||1},x.current},[]),R=y=>{const _=x.current;if(!_)return{x0:0,x1:0,y0:0,y1:0};const L=y*_.w,D=y*_.h,Z=L>_.W?_.W-_.cx-L/2:0,I=L>_.W?L/2-_.cx:0,V=D>_.H?_.H-_.cy-D/2:0,ie=D>_.H?D/2-_.cy:0;return{x0:Math.min(Z,0),x1:Math.max(I,0),y0:Math.min(V,0),y1:Math.max(ie,0)}},F=y=>{const _=R(y.s);return{s:y.s,tx:Je(y.tx,_.x0,_.x1),ty:Je(y.ty,_.y0,_.y1)}},A=(y,{animate:_=!1,fade:L=null}={})=>{f.current=y;const D=d.current,Z=o.current;if(D){const V=window.matchMedia("(prefers-reduced-motion: reduce)").matches;D.style.transition=_&&!V?Ar:"none",D.style.transform=`translate3d(${y.tx}px, ${y.ty}px, 0) scale(${y.s})`}Z&&(Z.dataset.viewerScale=y.s.toFixed(3),Z.dataset.viewerTx=Math.round(y.tx),Z.dataset.viewerTy=Math.round(y.ty),Z.style.backgroundColor=L==null?"":`rgba(3, 7, 18, ${L})`,L==null?delete Z.dataset.closing:Z.dataset.closing="");const I=y.s>1.01;I!==b.current&&(b.current=I,u(I))},M=r.useCallback((y,_=!0)=>{const{index:L,n:D,onIndex:Z}=S.current;if(D<2)return;const I=f.current,V=x.current;j.current=_&&I.s>1.01&&V?{s:I.s,u:(V.W/2-V.cx-I.tx)/I.s/V.w,v:(V.H/2-V.cy-I.ty)/I.s/V.h}:null,Z((L+y+D)%D)},[]),W=r.useCallback(()=>{if(!E())return;const y=j.current,_=x.current;if(!y){A({s:1,tx:0,ty:0});return}A(F({s:y.s,tx:_.W/2-_.cx-y.s*y.u*_.w,ty:_.H/2-_.cy-y.s*y.v*_.h}))},[]);r.useLayoutEffect(()=>{const y=d.current;if(!y)return;y.complete&&y.naturalWidth?W():A({s:j.current?.s||1,tx:0,ty:0});const _=()=>{try{W()}catch(L){k(L)}};return y.addEventListener("load",_),()=>y.removeEventListener("load",_)},[n,g,W,k]),r.useEffect(()=>{l<2||[e[(n+1)%l],e[(n-1+l)%l]].forEach(y=>{new window.Image().src=ln(y)})},[e,n,l]),r.useEffect(()=>{const y=document.activeElement;m.current?.focus({preventScroll:!0});const _=L=>{L.key==="Escape"?S.current.onClose():L.key==="ArrowLeft"?(L.preventDefault(),M(-1)):L.key==="ArrowRight"&&(L.preventDefault(),M(1))};return window.addEventListener("keydown",_),()=>{window.removeEventListener("keydown",_),y?.focus?.({preventScroll:!0})}},[M]),r.useEffect(()=>{const y=[...document.querySelectorAll("[data-phone-feed], [data-sheet-body]")].map(_=>({el:_,overflow:_.style.overflow,top:_.scrollTop}));return y.forEach(({el:_})=>{_.style.overflow="hidden"}),()=>y.forEach(({el:_,overflow:L,top:D})=>{_.style.overflow=L,_.scrollTop=D})},[]),r.useEffect(()=>{const y=()=>{try{E()&&A(F(f.current))}catch(_){k(_)}};return window.addEventListener("resize",y),()=>window.removeEventListener("resize",y)},[E,k]),r.useEffect(()=>{const y=o.current,_=new Map;let L="idle",D=!1,Z=null,I=null,V=null,ie=null,se=[],ne=null,w=0,T=0;const K=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,xe=(P,q,G)=>{if(K()){G();return}A(P,{animate:!0,fade:q}),clearTimeout(T),T=setTimeout(()=>{try{G()}catch(z){k(z)}},180)},Q=()=>{clearTimeout(w),w=0},Da=()=>{const P=performance.now(),q=se.filter(Y=>P-Y.t<100);if(q.length<2)return{vx:0,vy:0};const G=q[0],z=q[q.length-1],X=Math.max(1,z.t-G.t);return{vx:(z.x-G.x)/X,vy:(z.y-G.y)/X}},Ht=()=>{const[P,q]=[..._.values()];return{a:P,b:q,d:Math.hypot(q.x-P.x,q.y-P.y)||1,mx:(P.x+q.x)/2,my:(P.y+q.y)/2}},qa=()=>{E();const{d:P,mx:q,my:G}=Ht(),z=f.current,X=x.current;I={...z},V={d:P,qx:(q-X.cx-z.tx)/z.s,qy:(G-X.cy-z.ty)/z.s},L="pinch",D=!0,Q()},Wt=P=>{E(),I={...f.current},Z={x:P.x,y:P.y,t:performance.now()};const q=R(I.s);ie={left:I.tx>=q.x1-1,right:I.tx<=q.x0+1},L="pan"},Re=()=>A(F({...f.current,s:Je(f.current.s,1,dn)}),{animate:!0}),zt=()=>A({s:1,tx:0,ty:0},{animate:!0}),Ia=(P,q)=>{if(!E())return;if(f.current.s>1.01){zt();return}const G=x.current;A(F({s:we,tx:(1-we)*(P-G.cx),ty:(1-we)*(q-G.cy)}),{animate:!0})},Za=(P,q,G)=>{if(ne&&G-ne.t<on&&Math.hypot(P-ne.x,q-ne.y)<Er){Q(),ne=null,Ia(P,q);return}ne={x:P,y:q,t:G},Q(),w=setTimeout(()=>{w=0,ne=null;const z=window.innerWidth;try{P<z/3?M(-1):P>z*2/3?M(1):"chromeHidden"in y.dataset?delete y.dataset.chromeHidden:y.dataset.chromeHidden=""}catch(X){k(X)}},on)},Ha=P=>{P.pointerType==="mouse"&&P.button!==0||P.target.closest?.("[data-viewer-control]")||_.size>=2||(_.set(P.pointerId,{x:P.clientX,y:P.clientY}),P.pointerType==="mouse"&&y.setPointerCapture?.(P.pointerId),_.size===1?(E(),D=!1,L="pending",Z={x:P.clientX,y:P.clientY,t:performance.now()},I={...f.current},se=[{t:Z.t,x:P.clientX,y:P.clientY}],A(f.current)):qa())},Wa=P=>{const q=_.get(P.pointerId);if(!q)return;if(q.x=P.clientX,q.y=P.clientY,L==="pinch"&&_.size===2){const{d:Y,mx:he,my:oe}=Ht(),ee=x.current,U=Je(I.s*(Y/V.d),Sr,dn);A({s:U,tx:he-ee.cx-U*V.qx,ty:oe-ee.cy-U*V.qy});return}if(_.size!==1)return;se.push({t:performance.now(),x:q.x,y:q.y}),se.length>12&&se.shift();const G=q.x-Z.x,z=q.y-Z.y;if(L==="pending"){if(Math.hypot(G,z)<Cr)return;Q(),ne=null,f.current.s>1.01?Wt(Z):D?L="none":Math.abs(G)>Math.abs(z)?L=S.current.n>1?"swipe":"none":L=z>0?"dismiss":"none"}const X=x.current;if(L==="pan"){const Y=R(I.s),he=(oe,ee,U)=>oe<ee?ee+(oe-ee)*.35:oe>U?U+(oe-U)*.35:oe;A({s:I.s,tx:he(I.tx+G,Y.x0,Y.x1),ty:he(I.ty+z,Y.y0,Y.y1)})}else if(L==="swipe")A({s:1,tx:G,ty:0});else if(L==="dismiss"){const Y=Math.max(0,z);A({s:1-Math.min(Y/X.H,1)*.25,tx:G*.3,ty:Y},{fade:Math.max(.2,1-Y/400)})}},za=P=>{if(!_.has(P.pointerId))return;const q=_.get(P.pointerId);_.delete(P.pointerId);const G=P.type==="pointercancel";if(L==="pinch"){if(_.size===1){const[U]=[..._.values()];f.current.s>1.01?Wt(U):L="none",se=[];return}_.size===0&&(Re(),L="idle");return}if(_.size>0)return;const z=window.innerWidth,X=q.x-Z.x,Y=q.y-Z.y,{vx:he,vy:oe}=Da(),ee=L;if(L="idle",G){ee!=="pending"&&Re();return}if(ee==="pending")!D&&performance.now()-Z.t<$r&&Za(q.x,q.y,performance.now());else if(ee==="pan"){const U=Ga=>{const Yt=R(I.s);return Ga==="left"?I.tx+X-Yt.x1:Yt.x0-(I.tx+X)},Vt=z*Mr;D?Re():ie.left&&X>0&&Math.abs(X)>Math.abs(Y)&&U("left")>Vt?M(-1):ie.right&&X<0&&Math.abs(X)>Math.abs(Y)&&U("right")>Vt?M(1):Re()}else ee==="swipe"?Math.abs(X)>z*Rr||Math.abs(he)>cn&&Math.abs(X)>40&&Math.sign(he)===Math.sign(X)?xe({s:1,tx:X<0?-z:z,ty:0},null,()=>M(X<0?1:-1,!1)):zt():ee==="dismiss"?Y>Tr||oe>cn&&Y>40?xe({s:.8,tx:X*.3,ty:x.current.H},0,()=>S.current.onClose()):A({s:1,tx:0,ty:0},{animate:!0}):Re()},be=P=>P.preventDefault(),Gt=P=>{P.touches.length>1&&P.preventDefault()},bt=P=>q=>{try{P(q)}catch(G){_.clear(),L="idle",Q(),k(G)}},Xt=bt(Ha),Jt=bt(Wa),ye=bt(za);return y.addEventListener("pointerdown",Xt),y.addEventListener("pointermove",Jt),y.addEventListener("pointerup",ye),y.addEventListener("pointercancel",ye),y.addEventListener("lostpointercapture",ye),y.addEventListener("touchmove",be,{passive:!1}),y.addEventListener("touchstart",Gt,{passive:!1}),y.addEventListener("gesturestart",be,{passive:!1}),y.addEventListener("gesturechange",be,{passive:!1}),()=>{Q(),clearTimeout(T),y.removeEventListener("pointerdown",Xt),y.removeEventListener("pointermove",Jt),y.removeEventListener("pointerup",ye),y.removeEventListener("pointercancel",ye),y.removeEventListener("lostpointercapture",ye),y.removeEventListener("touchmove",be),y.removeEventListener("touchstart",Gt),y.removeEventListener("gesturestart",be),y.removeEventListener("gesturechange",be)}},[M,E,k]);const v=()=>{if(E())if(f.current.s>1.01)A({s:1,tx:0,ty:0},{animate:!0});else{const y=x.current;A(F({s:we,tx:(1-we)*(y.W/2-y.cx),ty:(1-we)*(y.H/2-y.cy)}),{animate:!0})}},C=y=>y.stopPropagation(),O="flex items-center justify-center rounded-full bg-gray-900/75 text-white shadow-lg ring-1 ring-white/20 active:bg-gray-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-white";return t.jsxs("div",{ref:o,role:"dialog","aria-modal":"true","aria-label":i.caption||i.name,"data-lightbox":!0,"data-lightbox-phone":!0,"data-lightbox-index":n,"data-lightbox-kind":i.chat?"chat":"proof",onClick:C,onPointerDown:C,onPointerMove:C,onPointerUp:C,onTouchStart:C,onTouchMove:C,onTouchEnd:C,onTouchCancel:C,className:"group fixed inset-0 z-50 select-none overflow-hidden overscroll-none bg-gray-950 text-white [-webkit-touch-callout:none] [touch-action:none]",children:[t.jsx("div",{ref:c,"data-viewer-stage":!0,className:`absolute inset-x-0 ${l>1?"bottom-[calc(9.5rem+env(safe-area-inset-bottom))]":"bottom-[calc(5rem+env(safe-area-inset-bottom))]"} top-[calc(4rem+env(safe-area-inset-top))] flex items-center justify-center px-3`,children:t.jsx("img",{ref:d,"data-viewer-img":!0,onError:()=>N(i.sha256),src:ln(i),alt:i.caption||i.name,draggable:!1,className:"block max-h-full max-w-full origin-center rounded-lg bg-white object-contain shadow-2xl will-change-transform"},`${i.sha256}-${g}`)}),$===i.sha256&&t.jsxs("div",{"data-viewer-broken":!0,className:"absolute inset-0 flex flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx("p",{className:"text-sm text-gray-300",children:"This image did not load."}),t.jsx("button",{type:"button","data-viewer-control":!0,onClick:()=>{N(null),h(y=>y+1)},className:"h-11 rounded-lg bg-white/15 px-4 text-sm font-semibold text-white active:bg-white/25",children:"Try again"})]}),t.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-0 flex items-center justify-between gap-2 bg-gradient-to-b from-gray-950/90 to-transparent px-3 pb-6 pt-[max(0.75rem,env(safe-area-inset-top))] transition-[opacity,visibility] duration-150 group-data-[closing]:opacity-0 group-data-[chrome-hidden]:invisible group-data-[chrome-hidden]:opacity-0",children:[t.jsx("button",{type:"button","data-viewer-control":!0,"data-lightbox-zoom":!0,onClick:v,"aria-label":p?"Zoom out":"Zoom in",className:`pointer-events-auto h-11 w-11 ${O}`,children:p?t.jsx(Ss,{className:"h-5 w-5","aria-hidden":!0}):t.jsx(Ms,{className:"h-5 w-5","aria-hidden":!0})}),t.jsx("p",{"data-viewer-hint":!0,className:"min-w-0 truncate rounded-full bg-gray-900/75 px-3 py-1.5 text-xs text-gray-200",children:p?l>1?"Tap a side to switch · double-tap to fit":"Double-tap to fit":"Pinch or double-tap to zoom"}),t.jsx("button",{ref:m,type:"button","data-viewer-control":!0,onClick:s,"aria-label":"Close",className:`pointer-events-auto h-11 w-11 ${O}`,children:t.jsx(fe,{className:"h-6 w-6","aria-hidden":!0})})]}),t.jsxs("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-gray-950 via-gray-950/90 to-transparent px-3 pb-[max(1rem,env(safe-area-inset-bottom))] pt-8 transition-[opacity,visibility] duration-150 group-data-[closing]:opacity-0 group-data-[chrome-hidden]:invisible group-data-[chrome-hidden]:opacity-0",children:[t.jsx("p",{"data-lightbox-caption":!0,className:"mx-auto mb-3 line-clamp-2 max-w-xl text-center text-sm text-gray-200",children:i.caption||i.name}),l>1&&t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("button",{type:"button","data-viewer-control":!0,"data-lightbox-prev":!0,"aria-label":"Previous image",onClick:()=>M(-1),className:`pointer-events-auto h-14 w-14 ${O}`,children:t.jsx(In,{className:"h-7 w-7","aria-hidden":!0})}),t.jsxs("p",{"data-lightbox-position":!0,"aria-live":"polite",className:"rounded-full bg-gray-900/75 px-3.5 py-2 text-base font-semibold tabular-nums",children:[n+1," / ",l]}),t.jsx("button",{type:"button","data-viewer-control":!0,"data-lightbox-next":!0,"aria-label":"Next image",onClick:()=>M(1),className:`pointer-events-auto h-14 w-14 ${O}`,children:t.jsx(pe,{className:"h-7 w-7","aria-hidden":!0})})]})]})]})}class Br extends r.Component{constructor(n){super(n),this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(n,a){console.error("[cockpit viewer] closed after an error",n,a?.componentStack)}render(){return this.state.failed?t.jsxs("div",{role:"alert","data-viewer-failed":!0,className:"fixed inset-x-3 bottom-[max(1rem,env(safe-area-inset-bottom))] z-50 flex items-center gap-3 rounded-xl bg-gray-900 px-4 py-3 text-sm text-white shadow-2xl",children:[t.jsx("span",{className:"min-w-0 flex-1",children:"The image viewer hit a problem and closed. Your ticket is still here."}),t.jsx("button",{type:"button",onClick:this.props.onClose,className:"h-11 shrink-0 rounded-lg bg-white/15 px-4 font-semibold active:bg-white/25",children:"OK"})]}):this.props.children}}const ze="https://magifyfun.atlassian.net/browse/",Or={magify_agents_api:"api",magify_next:"next"},De=e=>`${Or[e.repo]||e.repo}#${e.number}`,na=e=>e&&e.charAt(0).toUpperCase()+e.slice(1),Ot=e=>(e.evidence||[]).filter(n=>n.s3_key);function qe(e){const n=e?new Date(e):null;return n&&!Number.isNaN(n.getTime())?n.toLocaleDateString("en-GB",{day:"numeric",month:"short"}):""}async function aa(e,n){const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),s=await a.json().catch(()=>({}));if(!a.ok)throw new Error(s.error||`The server answered ${a.status}`);return s}function Ge({ticket:e,kit:n}){const a=e.flags||[];return!a.length&&!e.hold?null:t.jsxs("div",{"data-phone-flags":!0,className:"mt-1.5 flex h-6 items-center gap-1 overflow-hidden",children:[t.jsx(n.AutoChips,{ticket:e}),a.map(s=>t.jsx(n.FlagChip,{flag:s,size:"sm"},s.id))]})}function Lr(e){r.useEffect(()=>{if(!e)return;const n=setTimeout(()=>document.querySelector(`[data-sheet-body] ${e}`)?.scrollIntoView({block:"start"}),60);return()=>clearTimeout(n)},[e])}function Ee({ticket:e,onClose:n,focus:a,children:s}){return Lr(a),t.jsx(ce,{title:`${e.key} · Details`,label:"details",tall:!0,onClose:n,children:t.jsx("div",{"data-phone-details":e.key,className:"-mx-4 [&>article]:rounded-none [&>article]:border-0 [&>article]:shadow-none",children:s})})}function sa({ticket:e,onClose:n,children:a}){return t.jsx(ce,{title:`${e.key} · Conversation`,label:"chat",tall:!0,onClose:n,children:t.jsx("div",{className:"pt-1",children:a})})}const ra=e=>(e.chat||[]).length;function la(e,n,a){return n.fixRequestAllowed(e)?[{id:"fix",label:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"max-[379px]:hidden",children:"Request fix"}),t.jsx("span",{className:"hidden max-[379px]:inline",children:"Fix"})]}),icon:H.fix,tone:"fix",onClick:()=>a("fix")}]:[]}function Fr({ticket:e,active:n,onUpdate:a,kit:s}){s.useTicketRefresh(e,a);const l=s.useGallery(e),{sheet:i,open:o,close:c}=$e(),d=!!(e.cancel&&!e.cancel.ack_error),m=s.openFixRequest(e),p=m?null:s.fixOutcome(e),u=s.mergePlan(e.prs),g=Ot(e),h=(e.prs||[]).reduce((x,j)=>({files:x.files+(j.changed_files||0),add:x.add+(j.additions||0),del:x.del+(j.deletions||0)}),{files:0,add:0,del:0}),$=d?{kind:"muted",label:e.cancel.acked_at?"Cancelled":"Cancel requested"}:m?{kind:"warn",icon:H.fix,label:m.acked_at?"Fix in progress":"Fix requested"}:e.hold?{kind:"bad",icon:ae,label:"On hold"}:p?.kind==="failed"?{kind:"bad",icon:ae,label:"Fix failed, needs you"}:{kind:"ok",label:"Ready to merge"},N=d?null:m?t.jsx(et,{children:"Do not merge yet: you requested a fix."}):e.hold?t.jsxs(et,{children:["On hold, do not merge. ",e.hold]}):null,b=!!(m||e.hold),f=d||!u.length?null:u.length===1?{id:"github",label:`Open ${De(u[0].pr)}`,icon:H.open,href:u[0].pr.url,muted:b}:{id:"github",label:`Open ${u.length} PRs`,icon:H.open,onClick:()=>o("details:[data-github-links]"),muted:b};return t.jsxs("article",{"data-phone-card":"merge","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:$,dates:We(e),summary:e.plain?.improves?null:e.title,chips:t.jsx(Ge,{ticket:e,kit:s})}),t.jsxs(ke,{keepAll:!0,hug:g.length>0,className:"mt-2 px-4",onMore:()=>o("details"),children:[t.jsx(J,{label:"What improves",strong:!0,children:e.plain?.improves}),t.jsx(J,{label:"Problem it solves",children:e.plain?.problem}),t.jsx(J,{label:"How it solves it",children:e.plain?.how}),!e.plain?.problem&&!e.plain?.how&&e.plain?.improves&&t.jsx("p",{className:"mt-2.5 text-[15px] text-gray-700",children:e.title})]}),u.length>0&&t.jsxs("p",{"data-phone-prs":!0,className:"shrink-0 truncate px-4 pb-2 pt-1 text-xs text-gray-500",children:[u.map(({pr:x})=>De(x)).join(", ")," · ",h.files," files",t.jsxs("span",{className:"text-emerald-700",children:[" +",h.add]}),t.jsxs("span",{className:"text-red-700",children:[" −",h.del]})]}),g.length>0&&t.jsx(Bt,{grow:!0,children:t.jsx(Pt,{grow:!0,images:g,onOpen:l.openProof,eager:n})}),N,t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},{id:"chat",label:"Chat",icon:H.chat,badge:ra(e),onClick:()=>o("chat")},...d?[]:la(e,s,o)],primary:f}),t.jsx(ot,{children:l.viewer}),i?.startsWith("details")&&t.jsx(Ee,{ticket:e,onClose:c,focus:i.split(":")[1],children:t.jsx(s.MergeCard,{ticket:e,proofSize:"small",onUpdate:a})}),i==="chat"&&t.jsx(sa,{ticket:e,onClose:c,children:t.jsx(s.TicketThread,{ticket:e,onUpdate:a,locked:d,onOpenImage:l.openShot,hint:"Chat is for questions. It never merges or changes the fix: use Request a fix for that."})}),i==="fix"&&t.jsx(ce,{title:`${e.key} · Request a fix`,label:"fix",onClose:c,children:t.jsx(s.FixRequestBar,{ticket:e,onUpdate:a,startOpen:!0,onDone:c})})]})}function Dr({ticket:e,active:n,onUpdate:a,kit:s}){s.useTicketRefresh(e,a);const l=s.useGallery(e),{sheet:i,open:o,close:c}=$e(),d=e.decision||{},m=s.recommendedLetter(d),p=!!(e.cancel&&!e.cancel.ack_error),u=s.openFixRequest(e),g=p||!!u,h=!!(e.answer?.acked_at&&!e.answer.ack_error),[$,N]=r.useState(null),[b,f]=r.useState(!1),[x,j]=r.useState(null),S=Ot(e),B=d.options||[],k=!g&&!e.answer&&B.length>0,E=ea(),R=async()=>{f(!0),j(null);try{const M=await aa("/api/admin/pipeline/answer",{key:e.key,option:$,text:""});E(e.key,`${e.key}: option ${$} sent to the pipeline`),a(M.ticket)}catch(M){j(M.message)}finally{f(!1)}},F=p?{kind:"muted",label:"Cancel requested"}:u?{kind:"warn",icon:H.fix,label:"Fix requested"}:e.answer?{kind:"ok",label:h?"Answer posted":"Answered"}:{kind:"info",label:"Needs decision"},A=k?{id:"answer",label:b?"Sending…":$?`Send ${$}`:`Pick ${B.map(M=>M.letter).join(" or ")}`,icon:H.check,onClick:R,disabled:b||!$}:!g&&!h?{id:"answer",label:e.answer?"Change answer":"Answer",icon:H.check,onClick:()=>o("details"),muted:!!e.answer}:null;return t.jsxs("article",{"data-phone-card":"decide","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:F,dates:We(e),lines:5,summary:d.question||"This ticket needs your decision. The question is on the Jira ticket.",chips:t.jsx(Ge,{ticket:e,kit:s})}),k&&t.jsxs("div",{role:"radiogroup","aria-label":"Options","data-phone-options":!0,className:"mt-2 shrink-0 space-y-1.5 px-4",children:[B.map(M=>{const W=$===M.letter;return t.jsxs("button",{type:"button",role:"radio","aria-checked":W,"data-option":M.letter,onClick:()=>N(W?null:M.letter),className:`flex min-h-[44px] w-full items-center gap-2.5 rounded-xl border px-2.5 py-1.5 text-left ${W?"border-indigo-500 bg-indigo-50 ring-1 ring-indigo-500":"border-gray-200"}`,children:[t.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-xs font-bold ${W?"bg-indigo-600 text-white":"bg-gray-100 text-gray-600"}`,children:M.letter}),t.jsx("span",{className:"line-clamp-2 min-w-0 flex-1 text-sm font-medium leading-snug text-gray-900",children:M.label}),M.letter===m&&t.jsx("span",{className:"shrink-0 rounded-full bg-emerald-50 px-1.5 py-0.5 text-[10px] font-semibold text-emerald-700 ring-1 ring-inset ring-emerald-600/20",children:"Recommended"})]},M.letter)}),x&&t.jsx("p",{role:"alert",className:"text-sm text-red-700",children:x})]}),e.answer&&t.jsx("div",{className:"mt-2 shrink-0 px-4",children:t.jsx(s.AnswerStatus,{answer:e.answer})}),t.jsxs(ke,{className:"mt-2 px-4",onMore:()=>o("details"),children:[d.recommendation&&m&&t.jsx(J,{label:"Why recommended",children:na(d.recommendation.replace(/^\s*[A-Z]\b[\s:.,-]*/,""))}),d.context?.length>0&&t.jsx(J,{label:"Why you are asked",children:t.jsx("ul",{className:"list-disc space-y-0.5 pl-4 text-sm",children:d.context.map((M,W)=>t.jsx("li",{children:M},W))})}),B.length>0&&!k&&t.jsx(J,{label:"Options",children:B.map(M=>t.jsxs("span",{className:"block text-sm",children:[M.letter,". ",M.label]},M.letter))})]}),S.length>0&&t.jsx(Bt,{children:t.jsx(Pt,{images:S,onOpen:l.openProof,eager:n})}),p?null:u?t.jsx(et,{tone:"warn",children:"Fix requested: it answers this decision."}):null,t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},{id:"chat",label:"Chat",icon:H.chat,badge:ra(e),onClick:()=>o("chat")},...d.question?[]:[{id:"jira",label:"Jira",icon:H.open,href:ze+e.key}],...p||!d.question?[]:la(e,s,o)],primary:A}),t.jsx(ot,{children:l.viewer}),i==="details"&&t.jsx(Ee,{ticket:e,onClose:c,focus:!g&&!h?"[data-send-answer]":null,children:t.jsx(s.DecisionCard,{ticket:e,onAnswered:a,onUpdate:a,proofSize:"small"})}),i==="chat"&&t.jsx(sa,{ticket:e,onClose:c,children:t.jsx(s.TicketThread,{ticket:e,onUpdate:a,locked:p,onOpenImage:l.openShot,hint:"Chat is for questions. It never decides: send your decision with the form, or use Request a fix."})}),i==="fix"&&t.jsx(ce,{title:`${e.key} · Request a fix`,label:"fix",onClose:c,children:t.jsx(s.FixRequestBar,{ticket:e,onUpdate:a,startOpen:!0,onDone:c})})]})}const qr=e=>`$${e.toFixed(2)}`;function Ir({ticket:e,onUpdate:n,kit:a}){const{sheet:s,open:l,close:i}=$e(),o=e.manual||{},c=a.mergePlan(e.prs)[0]?.pr;return t.jsxs("article",{"data-phone-card":"manual","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:{kind:"bad",icon:Mt,label:"Stopped over budget"},dates:qe(o.stopped_at),summary:e.plain?.improves||e.title||e.plain?.problem,chips:t.jsx(Ge,{ticket:e,kit:a})}),t.jsxs(ke,{className:"mt-2 px-4",onMore:()=>l("details"),children:[t.jsxs(J,{label:"Automation spent",children:[t.jsx("span",{className:"font-semibold tabular-nums",children:o.spend_usd==null?"not metered":qr(o.spend_usd)}),t.jsxs("span",{className:"text-sm text-gray-500",children:[" ",[o.leg_kind&&`on its ${o.leg_kind} round`,o.spend_note].filter(Boolean).join(", ")]})]}),t.jsx(J,{label:"Why it stopped",children:t.jsx("span",{className:"whitespace-pre-line",children:o.reason})})]}),t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>l("details")},{id:"jira",label:"Jira",icon:H.open,href:ze+e.key},...c?[{id:"pr",label:De(c),icon:H.open,href:c.url}]:[]],primary:e.plan?.on?{id:"plan",label:"Plan a test",icon:Ie,onClick:()=>l("plan")}:null}),s==="details"&&t.jsx(Ee,{ticket:e,onClose:i,children:t.jsx(a.ManualList,{tickets:[e],onUpdate:n})}),s==="plan"&&t.jsxs(ce,{title:`${e.key} · Plan a cheaper test`,label:"plan",tall:!0,onClose:i,children:[t.jsx(a.StrategyBlock,{strategy:e.plan.strategy}),t.jsx(a.PlanThread,{ticket:e,onUpdate:n,manual:!0})]})]})}function Zr({ticket:e,active:n,onUpdate:a,kit:s}){const l=s.useGallery(e),{sheet:i,open:o,close:c}=$e(),d=e.queue==="cancelled",m=s.mergePlan(e.prs)[0]?.pr,p=Ot(e);return t.jsxs("article",{"data-phone-card":"shipped","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:d?{kind:"muted",label:`Cancelled ${qe(e.cancelled_at)}`}:{kind:"ok",label:`Merged ${qe(e.merged_at)}`},dates:We(e),summary:e.plain?.improves?null:e.title,chips:t.jsx(Ge,{ticket:e,kit:s})}),t.jsxs(ke,{keepAll:!0,hug:p.length>0,className:"mt-2 px-4",onMore:()=>o("details"),children:[d&&e.cancel?.reason&&t.jsx(J,{label:"Why cancelled",children:e.cancel.reason}),t.jsx(J,{label:"What improved",strong:!0,children:e.plain?.improves}),t.jsx(J,{label:"Problem it solved",children:e.plain?.problem}),t.jsx(J,{label:"How it solved it",children:e.plain?.how}),(e.prs||[]).length>0&&t.jsx(J,{label:"PRs",children:s.mergePlan(e.prs).map(({pr:u})=>`${De(u)}${d?" (closed)":""}`).join(", ")})]}),p.length>0&&t.jsx(Bt,{grow:!0,children:t.jsx(Pt,{grow:!0,images:p,onOpen:l.openProof,eager:n})}),t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},{id:"jira",label:"Jira",icon:H.open,href:ze+e.key}],primary:m?{id:"pr",label:`Open ${De(m)}`,icon:H.open,href:m.url,muted:!0}:null}),t.jsx(ot,{children:l.viewer}),i==="details"&&t.jsx(Ee,{ticket:e,onClose:c,children:t.jsx(s.ShippedList,{tickets:[e],onUpdate:a})})]})}function Hr({ticket:e,onUpdate:n,kit:a}){const{sheet:s,open:l,close:i}=$e(),o=a.latestDirective(e.chat);return t.jsxs("article",{"data-phone-card":"building","data-ticket":e.key,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,pill:{kind:"warn",icon:H.fix,label:o?`Fix in progress since ${qe(o.at)}`:"Fix in progress"},dates:We(e),summary:e.plain?.improves||e.title,chips:t.jsx(Ge,{ticket:e,kit:a})}),t.jsxs(ke,{className:"mt-2 px-4",onMore:()=>l("details"),children:[t.jsx(J,{label:"Where it stands",children:a.FIX_STAGE_TEXT[e.fix_round?.stage]||"The fix round is building. It comes back to Ready to merge once re-checked."}),o&&t.jsx(J,{label:"Your request",children:o.text})]}),t.jsx(Ce,{actions:[{id:"details",label:"Details",icon:H.details,onClick:()=>l("details")},{id:"jira",label:"Jira",icon:H.open,href:ze+e.key}]}),s==="details"&&t.jsx(Ee,{ticket:e,onClose:i,children:t.jsx(a.BuildingList,{tickets:[e],onUpdate:n})})]})}const Wr={merge:Fr,decide:Dr,manual:Ir,shipped:Zr,building:Hr};function zr({items:e,empty:n,onUpdate:a,kit:s}){return t.jsx(ta,{items:e,empty:n,renderPage:(l,i)=>{const o=Wr[l.kind];return t.jsx(o,{ticket:l.ticket,active:i,onUpdate:a,kit:s})}})}function Me(e,n){return e.map(a=>({key:a.key,kind:n==="shipped"||n==="building"||n==="manual"||n==="decide"?n:"merge",ticket:a,summary:n==="decide"?a.decision?.question||a.title:a.plain?.improves||a.title||a.key}))}const un={pending:e=>e.max_related?{kind:"warn",label:"Costs MAX runs · awaits you"}:{kind:"muted",label:"No MAX cost"},later:e=>({kind:"muted",label:`Later · since ${qe(e.gate_at)}`}),validated:e=>e.gate_jira_at?{kind:"ok",label:"Validated · in the fix queue"}:{kind:"warn",label:"Validated · not queued yet"},auto:()=>({kind:"muted",label:"Flows on its own"}),dismissed:()=>({kind:"muted",label:"Dismissed"})};function Gr({ticket:e,gate:n,sel:a,onUpdate:s,kit:l}){const{sheet:i,open:o,close:c}=$e(),[d,m]=r.useState(null),[p,u]=r.useState(null),[g,h]=r.useState(!1),$=e.gate==="pending"||e.gate==="later",N=!!(e.merge&&!e.merge.done_at),b=e.merge?.blocks||[],f=n.planHostOf(e),x=ea(),j=pr(),S=async k=>{m(k),u(null);try{const E=await aa("/api/admin/pipeline/gate",{key:e.key,action:k});x(e.key,`${e.key}: ${{validate:"validated, sent to the fix queue",later:"moved to Later",back:"back to waiting"}[k]}`),s(E.ticket)}catch(E){u(E.message)}finally{m(null)}},B=e.gate==="later";return t.jsxs("article",{"data-phone-card":"gate","data-ticket":e.key,"data-gate":e.gate,className:"flex h-full flex-col bg-white",children:[t.jsx(_e,{ticket:e,select:n.mergeable(e)?t.jsx(kr,{ticketKey:e.key,selected:a.isSel(e.key),disabled:a.full,onToggle:()=>a.toggle(e.key)}):null,pill:(un[e.gate]||un.auto)(e),dates:We(e),summary:e.title||e.key,lines:6,chips:t.jsxs("div",{"data-phone-flags":!0,className:"mt-1.5 flex h-6 items-center gap-1 overflow-hidden",children:[t.jsx(n.SourceChips,{ticket:e}),n.inPlanOf(e)&&t.jsxs("span",{className:"shrink-0 rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-800 ring-1 ring-inset ring-emerald-200",children:["In the test plan on ",n.inPlanOf(e)]})]})}),t.jsxs(ke,{className:"mt-2 px-4",onMore:()=>o("details"),children:[b.length>1?t.jsx(J,{label:`${b.length} problems`,children:b.map((k,E)=>t.jsxs("span",{className:"block text-sm",children:[E+1,". ",k.title||k.key]},k.key))}):t.jsx(J,{label:"What is wrong",children:na(e.plain?.problem||e.excerpt)}),b.length<2&&(e.claim_ids||[]).length>0&&t.jsx(J,{label:"Why it exists",children:e.claim_ids.map(k=>t.jsxs("span",{className:"block",children:["From claim ",k,"."]},k))}),e.gate!=="pending"&&t.jsx(J,{label:"Cost",children:e.max_related?"Uses MAX: fixing it and checking the fix run real MAX conversations.":"Uses MAX: no. It goes to the fix queue on its own."}),e.gate_note&&t.jsx(J,{label:"Reason",children:e.gate_note})]}),f&&n.renderPlanEntry&&t.jsx("div",{className:"shrink-0 px-4 [&_button]:min-h-[44px]",children:n.renderPlanEntry(e)}),p&&t.jsx("p",{role:"alert",className:"mx-4 mt-1 shrink-0 text-sm text-red-700",children:p}),(e.gate_jira_error||e.merge&&!e.merge.done_at&&e.merge.error)&&t.jsx(et,{children:"Jira was not updated. Retry in Details."}),t.jsx(Ce,{actions:$?[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},B?{id:"back",label:d==="back"?"Moving…":"Back",icon:Ln,onClick:()=>S("back"),disabled:!!d}:{id:"later",label:d==="later"?"Moving…":"Later",icon:H.later,onClick:()=>S("later"),disabled:!!d},{id:"dismiss",label:"Dismiss",icon:H.dismiss,tone:"danger",onClick:()=>h(!0),disabled:!!d||N}]:[{id:"details",label:"Details",icon:H.details,onClick:()=>o("details")},{id:"jira",label:"Jira",icon:H.open,href:ze+e.key}],primary:$?{id:"validate",label:d==="validate"?"Validating…":"Validate",icon:H.check,disabled:!!d||N,onClick:()=>j?j({text:`Validating ${e.key}…`,run:()=>S("validate")}):S("validate")}:null}),g&&t.jsx(ot,{children:t.jsx(n.DismissDialog,{ticket:e,onClose:()=>h(!1),onDone:k=>{x(e.key,`${e.key}: dismissed`),s(k)}})}),i==="details"&&t.jsx(Ee,{ticket:e,onClose:c,children:n.renderDetails(e)})]})}function Xr({lists:e,gate:n,sel:a,bundleCount:s,renderBundles:l,onUpdate:i,dialogs:o}){const[c,d]=r.useState(!1),m=()=>d(!1),u=["pending","later","validated","auto","dismissed"].flatMap($=>e[$].map(N=>({key:N.key,ticket:N,summary:N.title||N.key}))),g=a.selected,h=!!a.onPlan&&g.length>0&&g.every($=>$.plan?.on);return t.jsxs(t.Fragment,{children:[g.length>0?t.jsxs(rn,{children:[t.jsxs("p",{"data-phone-selected":!0,className:"min-w-0 flex-1 truncate text-sm font-semibold text-gray-900",children:[g.length," selected"]}),t.jsx(jt,{onClick:a.onClear,className:"ring-0 text-gray-500",children:"Clear"}),h&&t.jsxs(jt,{"data-plan-open":!0,onClick:a.onPlan,children:[t.jsx(Ie,{className:"h-4 w-4","aria-hidden":!0}),"Plan"]}),t.jsx(jt,{primary:!0,"data-merge-open":!0,onClick:a.onMerge,disabled:g.length<2,children:"Merge"})]}):s>0?t.jsx(rn,{children:t.jsxs("button",{type:"button","data-phone-bundles":!0,onClick:()=>d(!0),className:"flex min-h-[44px] min-w-0 flex-1 items-center gap-2 rounded-lg px-1 text-left text-sm font-medium text-gray-800",children:[t.jsx(H.bundles,{className:"h-5 w-5 shrink-0 text-emerald-600","aria-hidden":!0}),t.jsxs("span",{className:"truncate",children:[s," suggested bundle",s===1?"":"s"]}),t.jsx("span",{className:"ml-auto shrink-0 text-indigo-700",children:"Review"})]})}):null,t.jsx(ta,{items:u,empty:t.jsx("p",{className:"rounded-xl border border-dashed border-gray-300 bg-white px-4 py-10 text-center text-sm text-gray-500",children:"No MAX fix is waiting for your validation."}),renderPage:$=>t.jsx(Gr,{ticket:$.ticket,gate:n,sel:a,onUpdate:i})}),c&&t.jsx(ce,{title:"Suggested bundles",label:"bundles",tall:!0,onClose:m,children:t.jsx("div",{className:"-mx-4 pt-1",children:l(m)})}),o]})}const Jr="max-go",Vr=10,mn=300;function Ye(e){return!!e&&e.queue==="backlog"&&!e.merged_into&&["pending","later","auto"].includes(e.gate)&&!(e.labels||[]).includes(Jr)&&!(e.merge&&!e.merge.done_at)}function dt(e,n=e){const a=Math.max(0,e-1);if(!a)return"";const s=a===1?"":"s";return`Saves ${a} fix round${s} and ${a} exam${s}: one round and one exam cover ${n===2?"both":`all ${n}`} problems.`}const Yr=e=>{const n=e?new Date(e):null;return n&&!Number.isNaN(n.getTime())?n.toLocaleDateString("en-GB",{day:"numeric",month:"short"}):null};function ct({strategy:e}){if(!e)return null;const n=Yr(e.agreed_at);return t.jsxs("section",{"data-strategy":!0,"aria-label":"Agreed test strategy",className:"mt-4 rounded-lg border border-emerald-200 bg-emerald-50/60 p-3 sm:p-4",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[t.jsx(Ie,{className:"h-4 w-4 text-emerald-700","aria-hidden":!0}),t.jsx("h4",{className:"text-sm font-semibold text-emerald-900",children:"Agreed test strategy"}),t.jsxs("span",{className:"text-xs text-emerald-800/80",children:[n?`agreed ${n}, `:"","binding for the next fix round and exam"]})]}),t.jsxs("dl",{className:"mt-2.5 grid grid-cols-3 gap-2 font-mono text-[13px]",children:[t.jsxs("div",{"data-strategy-field":"max_fix_runs",className:"rounded-md bg-white/80 px-2 py-1.5 ring-1 ring-inset ring-emerald-100",children:[t.jsx("dt",{className:"text-[11px] text-emerald-800/80",children:"max_fix_runs"}),t.jsx("dd",{className:"font-semibold tabular-nums text-gray-900",children:e.max_fix_runs})]}),t.jsxs("div",{"data-strategy-field":"max_exam_runs",className:"rounded-md bg-white/80 px-2 py-1.5 ring-1 ring-inset ring-emerald-100",children:[t.jsx("dt",{className:"text-[11px] text-emerald-800/80",children:"max_exam_runs"}),t.jsx("dd",{className:"font-semibold tabular-nums text-gray-900",children:e.max_exam_runs})]}),t.jsxs("div",{"data-strategy-field":"budget_usd",className:"rounded-md bg-white/80 px-2 py-1.5 ring-1 ring-inset ring-emerald-100",children:[t.jsx("dt",{className:"text-[11px] text-emerald-800/80",children:"budget_usd"}),t.jsxs("dd",{className:"font-semibold tabular-nums text-gray-900",children:["$",Number(e.budget_usd).toFixed(2)]})]})]}),t.jsx("p",{className:"mt-2.5 font-mono text-[11px] text-emerald-800/80",children:"scenarios"}),t.jsx("ol",{"data-strategy-field":"scenarios",className:"mt-1 list-decimal space-y-1 pl-5 text-sm leading-snug text-gray-800",children:(e.scenarios||[]).map((a,s)=>t.jsx("li",{children:a},s))})]})}function ia(e){return[...e||[]].filter(n=>n.role==="assistant"&&n.plan_close).sort((n,a)=>new Date(n.at)-new Date(a.at)).pop()||null}function Kr({message:e}){const n=e?.plan_close;if(!n)return null;const a=(n.tickets||[]).filter(l=>l!==n.survivor);let s;return n.mode==="manual"?s=`Plan recorded: ${n.survivor} goes back to the queue under this strategy.`:n.merge_error?s=`Plan recorded on ${n.tickets.join(", ")}, but the merge failed: ${n.merge_error}`:n.merged_at?s=`Plan recorded: ${a.join(", ")} merged into ${n.survivor}. Validate ${n.survivor} to start it.`:a.length?s=`Plan recorded on ${n.tickets.join(", ")}; merging them…`:s=`Plan recorded on ${n.survivor}. Validate it to start it.`,t.jsx("p",{"data-plan-outcome":!0,role:"status",className:`mt-3 rounded-lg px-3 py-2 text-sm ${n.merge_error?"bg-red-50 text-red-900":"bg-emerald-50 text-emerald-900"}`,children:s})}const vt=e=>`$${(Math.round((e||0)*10)/10).toFixed(1)}`,Ur=/^(MAX claims ground-truth correction|Feature from claims page):\s*/i,Qr=e=>(e||"").replace(Ur,""),xn=e=>parseInt(String(e).split("-")[1],10)||0,Lt=e=>[...e||[]].sort((n,a)=>new Date(n.at)-new Date(a.at)),el='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function tt(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function hn(e,n){return n?.keys?.length?n.keys[0]:[...e].sort((a,s)=>xn(a)-xn(s))[0]}function oa(e){const n=Lt(e).filter(a=>a.role==="assistant"&&!a.plan_close);for(let a=n.length-1;a>=0;a-=1){const s=n[a].text||"",l=[...s.matchAll(/^[\s*>_-]*tickets\W*:(.*)$/gim)].pop(),i=l?[...new Set(l[1].split("(")[0].match(/[A-Z][A-Z0-9]+-\d+/g)||[])]:[],o=[...s.matchAll(/^[\s*>_-]*survivor\W*:\W*([A-Z][A-Z0-9]+-\d+)/gim)].pop()?.[1];if(i.length)return{keys:i,survivor:i.includes(o)?o:i[0]}}return null}function tl(e){const n=[document.documentElement];for(let a=e?.parentElement;a&&a!==document.body;a=a.parentElement)/(auto|scroll)/.test(getComputedStyle(a).overflowY)&&n.push(a);return n}function nl(e,n){const a=r.useRef(n);a.current=n,r.useEffect(()=>{const s=document.activeElement,l=tl(e.current).map(o=>({el:o,overflow:o.style.overflowY}));l.forEach(({el:o})=>{o.style.overflowY="hidden"}),e.current?.focus({preventScroll:!0});const i=o=>{if(document.querySelector("[data-lightbox]"))return;if(o.key==="Escape"){o.preventDefault(),a.current();return}if(o.key!=="Tab"||!e.current)return;const c=[...e.current.querySelectorAll(el)].filter(u=>u.offsetParent!==null);if(!c.length)return;const d=c[0],m=c[c.length-1],p=e.current.contains(document.activeElement);o.shiftKey&&(document.activeElement===d||!p||document.activeElement===e.current)?(o.preventDefault(),m.focus()):!o.shiftKey&&(document.activeElement===m||!p)&&(o.preventDefault(),d.focus())};return document.addEventListener("keydown",i),()=>{document.removeEventListener("keydown",i),l.forEach(({el:o,overflow:c})=>{o.style.overflowY=c}),s&&document.contains(s)&&s.focus({preventScroll:!0})}},[e])}function Ke({children:e}){return t.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:e})}function al({keys:e,plan:n,changed:a,group:s,ticketOf:l}){const i=s?.mode==="relevance",{keys:o,survivor:c}=n,d=[c,...o.filter(m=>m!==c),...e.filter(m=>!o.includes(m))];return t.jsxs("div",{className:"space-y-5",children:[t.jsxs("section",{"aria-labelledby":"plan-tickets",children:[t.jsx(Ke,{children:t.jsxs("span",{id:"plan-tickets",children:[o.length," ticket",o.length===1?"":"s",a?", as the pipeline now proposes":""]})}),a&&t.jsx("p",{"data-plan-changed":!0,role:"status",className:"mt-1 text-sm leading-relaxed text-gray-700",children:"The conversation changed the suggestion. Agreeing now means agreeing to this version."}),t.jsx("ul",{"data-plan-tickets":!0,className:"mt-2 divide-y divide-gray-100 rounded-xl border border-gray-200",children:d.map(m=>{const p=l(m),u=m===c,g=!o.includes(m),h=!e.includes(m);return t.jsxs("li",{"data-plan-ticket":m,"data-plan-ticket-state":g?"left-out":h?"added":"in",className:"flex flex-wrap items-start gap-x-3 gap-y-1 px-3.5 py-2.5 sm:flex-nowrap",children:[t.jsx("span",{className:"mt-0.5 shrink-0 font-mono text-xs text-gray-500 sm:w-[5.75rem]",children:m}),t.jsx("span",{className:`order-last min-w-0 basis-full text-sm leading-snug sm:order-none sm:flex-1 sm:basis-auto ${g?"text-gray-500 line-through decoration-gray-400":"text-gray-900"}`,children:Qr(p?.title)||m}),g&&t.jsx("span",{title:"The pipeline proposes to test this one on its own",className:"ml-auto shrink-0 rounded-full bg-gray-100 px-2 py-0.5 text-[11px] font-semibold text-gray-600 sm:ml-0",children:"Left out"}),h&&!u&&t.jsx("span",{className:"ml-auto shrink-0 rounded-full bg-emerald-100 px-2 py-0.5 text-[11px] font-semibold text-emerald-900 sm:ml-0",children:"Added"}),u&&t.jsx("span",{"data-plan-kept":!0,title:"This ticket stays open. The others merge into it as extra problems.",className:"ml-auto shrink-0 rounded-full bg-gray-900 px-2 py-0.5 text-[11px] font-semibold text-white sm:ml-0",children:"Stays"})]},m)})})]}),t.jsxs("div",{className:"grid gap-5 sm:grid-cols-[1fr_11rem]",children:[t.jsxs("section",{"aria-labelledby":"plan-why",className:"min-w-0 space-y-3",children:[t.jsx(Ke,{children:t.jsx("span",{id:"plan-why",children:"Why together"})}),t.jsxs("p",{"data-plan-why":!0,className:"text-sm leading-relaxed text-gray-800",children:[s?t.jsxs(t.Fragment,{children:[e.length===2?"Both change":"They all change"," one part of MAX",s.name?t.jsxs(t.Fragment,{children:[": ",t.jsx("span",{className:"font-medium",children:s.name})]}):"",". One fix round and one test can cover them."]}):"You picked them together. The pipeline checks whether one fix round and one test can cover them.",i&&" The pipeline thinks they may already be fixed, so the test mainly checks that."]}),s?.scenario&&t.jsxs("p",{"data-plan-scenario":!0,className:"text-sm leading-relaxed text-gray-800",children:[t.jsx("span",{className:"font-medium text-gray-900",children:"The shared test:"})," ",s.scenario]}),s?.surface&&t.jsxs("details",{"data-plan-surface":!0,className:"group text-xs leading-relaxed text-gray-600",children:[t.jsx("summary",{className:"cursor-pointer select-none font-medium text-gray-600 hover:text-gray-900",children:"The code they share"}),t.jsx("p",{className:"mt-1 [overflow-wrap:anywhere]",children:s.surface})]})]}),t.jsxs("section",{"aria-labelledby":"plan-saving","data-plan-saving":!0,className:"self-start rounded-xl bg-emerald-50 px-4 py-3 ring-1 ring-inset ring-emerald-100",children:[t.jsx(Ke,{children:t.jsx("span",{id:"plan-saving",children:a?"First estimate":"Estimated saving"})}),s?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:`mt-1 font-semibold tabular-nums text-emerald-900 ${a?"text-base":"text-2xl"}`,children:["~",vt(s.est.savings_usd)]}),t.jsxs("p",{className:"mt-0.5 text-xs tabular-nums leading-relaxed text-emerald-900/80",children:[vt(s.est.bundle_usd)," together instead of ",vt(s.est.apart_usd)," apart",i?", if fixed":""]})]}):t.jsx("p",{className:"mt-1 text-sm leading-relaxed text-emerald-900",children:dt(o.length)}),a&&s&&t.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-emerald-900/80",children:"For the first suggestion. The latest reply gives its own estimate."})]})]})]})}function sl({close:e,survivorTicket:n}){const a=(e.tickets||[]).filter(o=>o!==e.survivor),s=!!e.merge_error,l=n?.plan?.strategy||e.strategy;let i;return e.mode==="manual"?i=`Plan agreed: ${e.survivor} goes back to the queue`:s?i="Plan agreed, but the merge did not go through":e.merged_at?i=a.length?`Merged into ${e.survivor}`:`Plan agreed on ${e.survivor}`:i=a.length?`Merging into ${e.survivor}…`:`Plan agreed on ${e.survivor}`,t.jsxs("section",{"data-plan-result":s?"error":e.merged_at?"merged":"pending","aria-live":"polite",className:"space-y-4",children:[t.jsxs("div",{className:`flex gap-3 rounded-xl px-4 py-3.5 ring-1 ring-inset ${s?"bg-red-50 ring-red-200":"bg-emerald-50 ring-emerald-200"}`,children:[s?t.jsx(ae,{className:"mt-0.5 h-5 w-5 shrink-0 text-red-600","aria-hidden":!0}):t.jsx(Ze,{className:"mt-0.5 h-5 w-5 shrink-0 text-emerald-600","aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 text-sm leading-relaxed",children:[t.jsx("p",{className:`font-semibold ${s?"text-red-900":"text-emerald-900"}`,children:i}),s?t.jsxs("p",{className:"text-red-900 [overflow-wrap:anywhere]",children:[e.merge_error," The strategy is recorded on each ticket; you can still merge them with the merge button."]}):e.mode==="manual"?t.jsx("p",{className:"text-emerald-900",children:"The next fix round and test follow the strategy below."}):t.jsxs("p",{className:"text-emerald-900",children:[a.length?t.jsxs(t.Fragment,{children:[tt(a)," ",a.length>1?"are":"is"," now part of ",e.survivor,". "]}):null,"It waits in ",t.jsx("span",{className:"font-medium",children:"Awaiting validation"})," as ",e.survivor,": validate it there to start one fix round and one test under the strategy below."]})]})]}),t.jsx(ct,{strategy:l})]})}function rl({keys:e,group:n,host:a,opening:s,error:l,ticketOf:i,renderPlan:o,onUpdate:c,onClose:d,onDismiss:m,onShow:p}){const u=r.useRef(null),g=r.useRef(null);nl(u,d);const[h,$]=r.useState(!1);r.useEffect(()=>{const D=requestAnimationFrame(()=>$(!0));return()=>cancelAnimationFrame(D)},[]);const[N,b]=r.useState(null),[f,x]=r.useState(null),j=ia(a?.chat)?.plan_close||null,S=Lt(a?.chat),B=rt(S),k=oa(a?.chat),E=k||{keys:e,survivor:hn(e,n)},R=!!k&&(k.keys.length!==e.length||k.keys.some(D=>!e.includes(D))||k.survivor!==hn(e,n)),F=j?.survivor||E.survivor,A=E.keys.filter(D=>D!==F),M=a&&o?r.cloneElement(o(a),{inModal:!0}):null,W=r.useRef(null);r.useEffect(()=>{S.length&&g.current&&(g.current.scrollTop=g.current.scrollHeight)},[!!a]),r.useEffect(()=>{const D=S.length+(B?1:0);W.current!=null&&D!==W.current&&g.current&&g.current.scrollTo({top:g.current.scrollHeight,behavior:"smooth"}),W.current=D},[S.length,B]);const v=async()=>{b("agree"),x(null);const D=`Agreed${k?", with your last proposal":""}. ${A.length?`Merge ${tt(A)} into ${F} and test them as one.`:`Test ${F} on its own, as proposed.`}`;try{const Z=await fetch("/api/admin/pipeline/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:a.key,text:D})}),I=await Z.json().catch(()=>({}));if(!Z.ok)throw new Error(I.error||`Could not send (${Z.status})`);c(I)}catch(Z){x(Z.message)}finally{b(null)}},C=async()=>{b("dismiss"),x(null);try{await m(n),d()}catch(D){x(D.message),b(null)}},O=j?"Test plan agreed":A.length?`Test these ${E.keys.length} tickets as one`:`Test ${F} on its own`,y=A.length?`Agree: merge into ${F} and test as one`:`Agree: test ${F} on its own`,_="inline-flex min-h-[44px] items-center justify-center gap-1.5 whitespace-nowrap rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",L="inline-flex min-h-[44px] items-center justify-center whitespace-nowrap rounded-lg px-4 text-sm font-medium text-gray-800 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900";return t.jsx("div",{"data-plan-modal-backdrop":!0,className:`fixed inset-0 z-50 flex items-stretch justify-center bg-gray-950/50 transition-opacity duration-200 ease-out motion-reduce:transition-none sm:items-center sm:p-6 ${h?"opacity-100":"opacity-0"}`,onMouseDown:D=>{D.target===D.currentTarget&&!N&&d()},children:t.jsxs("div",{ref:u,role:"dialog","aria-modal":"true","aria-labelledby":"plan-modal-title",tabIndex:-1,"data-plan-modal":a?.key||"","data-plan-modal-keys":e.join(","),className:`flex h-full w-full flex-col bg-white shadow-2xl transition-transform duration-200 ease-out focus:outline-none motion-reduce:transition-none sm:h-auto sm:max-h-[min(90vh,880px)] sm:max-w-[52rem] sm:rounded-2xl sm:ring-1 sm:ring-black/5 ${h?"translate-y-0":"translate-y-2"}`,children:[t.jsxs("header",{className:"flex items-start gap-3 border-b border-gray-100 px-5 pb-4 pt-[max(1rem,env(safe-area-inset-top))] sm:px-6 sm:pt-5",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:"flex min-w-0 items-center gap-1.5 text-xs font-medium text-gray-500",children:[t.jsx(Tt,{className:"h-3.5 w-3.5 shrink-0 text-gray-400","aria-hidden":!0}),t.jsx("span",{className:"shrink-0",children:n?"Suggested by the pipeline":"Your selection"}),n?.name&&t.jsxs("span",{className:"min-w-0 truncate",children:["· ",n.name]})]}),t.jsx("h2",{id:"plan-modal-title",className:"mt-1 text-lg font-semibold leading-snug text-gray-900",children:O})]}),t.jsx("button",{type:"button","data-plan-modal-x":!0,onClick:d,"aria-label":"Close",className:"-mr-2 -mt-1 flex h-11 w-11 items-center justify-center rounded-lg text-gray-500 hover:bg-gray-100 hover:text-gray-800 sm:h-9 sm:w-9 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900",children:t.jsx(fe,{className:"h-5 w-5","aria-hidden":!0})})]}),t.jsxs("div",{ref:g,"data-plan-modal-body":!0,className:"min-h-0 flex-1 space-y-7 overflow-y-auto overscroll-contain px-5 py-5 sm:px-6",children:[j?t.jsx(sl,{close:j,survivorTicket:i(j.survivor)}):t.jsx(al,{keys:e,plan:E,changed:R,group:n,ticketOf:i}),t.jsxs("section",{"aria-labelledby":"plan-talk","data-plan-talk":!0,children:[t.jsx(Ke,{children:t.jsx("span",{id:"plan-talk",children:j?"The conversation":"Adjust it with the pipeline"})}),!j&&t.jsx("p",{className:"mt-1 text-sm leading-relaxed text-gray-600",children:"Ask why, add or drop a ticket, or change the test. The pipeline answers here in a few minutes. Nothing is merged or spent until you agree."}),M,!a&&s&&t.jsx("p",{role:"status",className:"mt-3 text-sm text-gray-500",children:"Opening the conversation…"}),l&&t.jsx("p",{role:"alert",className:"mt-3 text-sm text-red-700",children:l})]})]}),t.jsxs("footer",{className:"border-t border-gray-100 px-5 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-3 sm:px-6",children:[f&&t.jsx("p",{role:"alert",className:"mb-2 text-sm text-red-700",children:f}),!j&&R&&!B&&t.jsxs("p",{"data-plan-agree-means":!0,className:"mb-2 text-sm leading-snug text-gray-700",children:["Agree accepts the pipeline's latest proposal: ",tt(E.keys),". To change it, reply first."]}),j?t.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[t.jsx("button",{type:"button","data-plan-done":!0,onClick:d,className:L,children:"Done"}),!j.merge_error&&j.mode!=="manual"&&t.jsxs("button",{type:"button","data-plan-show":j.survivor,onClick:()=>p(j.survivor),className:_,children:["Show ",j.survivor," on the page",t.jsx(Pn,{className:"h-4 w-4","aria-hidden":!0})]})]}):t.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:flex sm:items-center",children:[t.jsxs("button",{type:"button","data-plan-agree":!0,onClick:v,disabled:!a||!!N||B,className:`${_} col-span-2 sm:order-4`,children:[t.jsx(st,{className:"hidden h-4 w-4 shrink-0 sm:block","aria-hidden":!0}),N==="agree"?"Sending…":B?"The pipeline is answering…":y]}),n&&t.jsx("button",{type:"button","data-plan-dismiss":n.id,onClick:C,disabled:!!N,title:"Hide this suggestion. The tickets stay as they are.",className:"inline-flex min-h-[44px] items-center justify-center whitespace-nowrap rounded-lg px-3 text-sm font-medium text-gray-600 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 disabled:opacity-50 sm:order-1 sm:-ml-3",children:N==="dismiss"?"Dismissing…":"Dismiss suggestion"}),t.jsx("span",{className:"hidden sm:order-2 sm:block sm:flex-1"}),t.jsx("button",{type:"button","data-plan-close":!0,onClick:d,title:"The conversation stays open: reopen it from the bundle or from the ticket card",className:`${L} sm:order-3 ${n?"":"col-span-2"}`,children:"Close for now"})]})]})]})})}function Ft(e){const n=Lt(e.chat);return{key:e.key,messages:n.length,awaiting:rt(n),lastFrom:n.length?n[n.length-1].role:null,closed:!!e.plan_thread?.closed_at,proposal:oa(n)}}const ll=30*1e3;function il(e,n,a){const s=!a&&Ft(e).awaiting;r.useEffect(()=>{if(!s)return;let l=!1;const i=async()=>{if(document.visibilityState==="visible")try{const c=await fetch(`/api/admin/pipeline/chat?key=${encodeURIComponent(e.key)}`,{cache:"no-store"});c.ok&&!l&&n(await c.json())}catch{}},o=setInterval(i,ll);return window.addEventListener("focus",i),()=>{l=!0,clearInterval(o),window.removeEventListener("focus",i)}},[s,e.key,n])}function da({host:e,onOpen:n,onUpdate:a,shown:s}){il(e,a,s);const l=Ft(e),i=(e.plan_thread?.keys||[]).filter(c=>c!==e.key);let o;return l.closed?o="Test plan agreed. The conversation is kept.":l.awaiting?o="The pipeline is answering.":l.messages?o=`${l.messages} message${l.messages===1?"":"s"}${l.lastFrom==="assistant"?", the pipeline replied.":"."}`:o="Nothing said yet.",t.jsxs("div",{"data-plan-entry":e.key,className:"mt-4 flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg bg-emerald-50/70 px-3 py-2.5 ring-1 ring-inset ring-emerald-200",children:[t.jsxs("p",{className:"min-w-0 flex-1 text-sm leading-snug text-emerald-950",children:[t.jsx("span",{className:"font-semibold",children:l.closed?"Test plan":"Test plan in discussion"}),i.length>0&&t.jsxs(t.Fragment,{children:[" with ",tt(i)]}),t.jsx("span",{className:"block text-xs text-emerald-900/80",children:o})]}),t.jsxs("button",{type:"button","data-plan-entry-open":e.key,onClick:()=>n(e),className:"inline-flex min-h-[36px] items-center gap-1 rounded-lg bg-white px-3 text-xs font-semibold text-emerald-900 ring-1 ring-inset ring-emerald-300 hover:bg-emerald-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-700",children:[l.closed?"View the plan":"Open the plan",t.jsx(Pn,{className:"h-3.5 w-3.5","aria-hidden":!0})]})]})}const ve=e=>`$${(Math.round((e||0)*10)/10).toFixed(1)}`,ol=/^(MAX claims ground-truth correction|Feature from claims page):\s*/i,dl=(e,n=64)=>{const a=(e||"").replace(ol,"");return a.length>n?`${a.slice(0,n-1).trimEnd()}…`:a};function cl(e){const n=e?new Date(e):null;return n&&!Number.isNaN(n.getTime())?n.toLocaleString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}):""}function ul(e,n){const a=e.proposal;if(a&&(a.keys.length!==n.keys.length||a.keys.some(i=>!n.keys.includes(i)))&&!e.awaiting)return`In discussion · the pipeline now proposes ${a.keys.length} ticket${a.keys.length===1?"":"s"}: ${a.keys.join(", ")}`;if(e.awaiting)return"In discussion · the pipeline is answering";if(!e.messages)return"Conversation open · nothing said yet";const l=`${e.messages} message${e.messages===1?"":"s"}`;return e.lastFrom==="assistant"?`In discussion · ${l} · the pipeline replied`:`In discussion · ${l}`}function ml({group:e,titleOf:n,active:a,canPlan:s,thread:l,onPick:i,onReview:o,onDismiss:c}){const[d,m]=r.useState(!1),[p,u]=r.useState(null),g=e.mode==="relevance",h=async N=>{N.stopPropagation(),m(!0),u(null);try{await c(e)}catch(b){u(b.message),m(!1)}},$=a||!!l;return t.jsxs("li",{"data-bundle":e.id,"data-bundle-active":a?"true":"false","data-bundle-thread":l?l.key:void 0,className:`group relative px-4 py-3.5 sm:px-5 ${$?"bg-emerald-50/70 hover:bg-emerald-50":"hover:bg-gray-50"}`,children:[t.jsxs("div",{className:"flex flex-wrap items-start gap-x-4 gap-y-2",children:[t.jsxs("div",{className:"min-w-0 flex-1 basis-80",children:[t.jsxs("p",{className:"flex flex-wrap items-center gap-1.5",children:[t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:e.name||"Bundle"}),g&&t.jsx("span",{className:"rounded-full bg-sky-50 px-2 py-0.5 text-[11px] font-medium text-sky-700 ring-1 ring-inset ring-sky-200",children:"relevance check only"})]}),t.jsx("ul",{className:"mt-1 space-y-0.5",children:e.keys.map((N,b)=>t.jsxs("li",{"data-bundle-member":N,className:"flex items-baseline gap-2 text-[13px] leading-snug text-gray-700",children:[t.jsxs("span",{className:"w-[5.5rem] shrink-0 font-mono text-[11px] text-gray-500",title:b===0?"Stays when they merge: the others join it":void 0,children:[N,b===0?" ★":""]}),t.jsx("span",{className:"min-w-0 truncate",children:dl(n(N))})]},N))}),e.surface&&t.jsxs("p",{"data-bundle-surface":!0,className:"mt-1.5 text-xs leading-relaxed text-gray-500",children:["Shared: ",e.surface]}),l&&t.jsxs("p",{"data-bundle-thread-state":!0,className:"mt-2 flex items-center gap-1.5 text-xs font-medium text-emerald-800",children:[t.jsx(Fn,{className:"h-3.5 w-3.5","aria-hidden":!0}),ul(l,e)]})]}),t.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:shrink-0 sm:flex-col sm:items-end",children:[t.jsxs("span",{"data-bundle-saves":!0,title:`Estimated MAX spend: ${ve(e.est.bundle_usd)} together vs ${ve(e.est.apart_usd)} apart (desk model, ±40%)`,className:"whitespace-nowrap rounded-full bg-emerald-100 px-2.5 py-1 text-xs font-semibold text-emerald-900",children:["saves ~",ve(e.est.savings_usd),g?" if fixed":""]}),t.jsxs("span",{className:"hidden text-[11px] tabular-nums text-gray-500 sm:inline",children:[ve(e.est.bundle_usd)," vs ",ve(e.est.apart_usd)," apart"]}),t.jsxs("div",{className:"ml-auto flex items-center gap-1 sm:ml-0",children:[t.jsx("button",{type:"button","data-bundle-dismiss":e.id,onClick:h,disabled:d,className:"relative z-10 inline-flex min-h-[36px] items-center rounded-lg px-2.5 text-xs font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800 disabled:opacity-50",children:d?"Dismissing…":"Dismiss"}),s?t.jsxs("button",{type:"button","data-bundle-review":e.id,onClick:()=>o(e),"aria-label":`${l?"Continue the plan":"Review proposal"}: ${e.name||e.keys.join(", ")}`,className:`inline-flex min-h-[36px] items-center gap-1 rounded-lg px-3 text-xs font-semibold after:absolute after:inset-0 after:content-[''] focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 ${l?"bg-gray-900 text-white group-hover:bg-gray-700":"bg-white text-gray-900 ring-1 ring-inset ring-gray-300 group-hover:bg-gray-50 group-hover:ring-gray-400"}`,children:[l?"Continue the plan":"Review proposal",t.jsx(pe,{className:"h-4 w-4","aria-hidden":!0})]}):t.jsx("button",{type:"button","data-bundle-pick":e.id,onClick:()=>i(e),"aria-pressed":a,className:"inline-flex min-h-[36px] items-center rounded-lg px-3 text-xs font-semibold text-gray-800 ring-1 ring-inset ring-gray-300 after:absolute after:inset-0 after:content-[''] hover:bg-gray-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900",children:a?"Untick them":"Tick them below"})]})]})]}),p&&t.jsx("p",{role:"alert",className:"relative z-10 mt-1 text-xs text-red-700",children:p})]})}function gn({view:e,titleOf:n,activeId:a,canPlan:s,threadOf:l,onPick:i,onReview:o,onDismiss:c}){if(!e)return null;const d=e.groups.reduce((m,p)=>m+(p.est.savings_usd||0),0);return t.jsxs("section",{"data-bundles":!0,"aria-labelledby":"gate-bundles",className:"space-y-3",children:[t.jsxs("h2",{id:"gate-bundles",className:"flex flex-wrap items-center gap-x-1 text-xs font-medium uppercase tracking-wide text-gray-400",children:[t.jsx(Tt,{className:"mr-0.5 h-3.5 w-3.5 text-gray-400","aria-hidden":!0}),"Suggested bundles",!e.stale&&e.groups.length>0&&t.jsxs("span",{className:"normal-case tracking-normal",children:[" · ",e.groups.length," · ~",ve(d)," saved if you take them all"]}),!e.stale&&e.generated_at&&t.jsxs("span",{className:"normal-case tracking-normal",children:[" · analysed ",cl(e.generated_at)]})]}),e.stale?t.jsxs("p",{"data-bundles-stale":!0,className:"flex items-center gap-2 rounded-xl border border-dashed border-gray-300 bg-white px-4 py-4 text-sm text-gray-600",children:[t.jsx(On,{className:"h-4 w-4 shrink-0 animate-spin text-gray-400","aria-hidden":!0}),"Re-analyzing… the waiting tickets changed since the last suggestions. New ones appear here on their own."]}):e.groups.length?t.jsx("ul",{className:"divide-y divide-gray-100 overflow-hidden rounded-xl border border-emerald-200 bg-white shadow-sm",children:e.groups.map(m=>t.jsx(ml,{group:m,titleOf:n,active:a===m.id,canPlan:s(m),thread:l(m),onPick:i,onReview:o,onDismiss:c},m.id))}):t.jsx("p",{"data-bundles-empty":!0,className:"rounded-xl border border-dashed border-gray-300 bg-white px-4 py-4 text-sm text-gray-500",children:"No bundle to suggest: the waiting tickets are best tested one by one."})]})}const Nt="cockpit.ticketSort",ca=r.createContext("default"),xl=ca.Provider;function hl(){const[e,n]=r.useState("default");r.useEffect(()=>{try{const s=localStorage.getItem(Nt);s&&n(Qe(s).key)}catch{}},[]);const a=r.useCallback(s=>{const l=Qe(s).key;n(l);try{l==="default"?localStorage.removeItem(Nt):localStorage.setItem(Nt,l)}catch{}},[]);return[e,a]}function pn(e){const n=e?new Date(e):null;if(!n||Number.isNaN(n.getTime()))return null;const a=n.getFullYear()===new Date().getFullYear();return n.toLocaleDateString("en-GB",{day:"numeric",month:"short",...a?{}:{year:"numeric"}})}function fn(e){return new Date(e).toLocaleString("en-GB",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})}const gl=()=>()=>{};function Se({ticket:e,className:n=""}){const a=r.useContext(ca);if(!r.useSyncExternalStore(gl,()=>!0,()=>!1))return null;const l=pn(e.jira_created),i=Qe(a).field==="jira_updated"?pn(e.jira_updated):null;return!l&&!i?null:t.jsxs("span",{"data-ticket-dates":!0,className:`shrink-0 whitespace-nowrap text-xs tabular-nums text-gray-500 ${n}`,children:[l&&t.jsxs("span",{"data-created":!0,title:`Created in Jira ${fn(e.jira_created)}`,children:["Created ",l]}),l&&i&&" · ",i&&t.jsxs("span",{"data-updated":!0,title:`Last updated in Jira ${fn(e.jira_updated)}`,children:["Updated ",i]})]})}function pl({value:e,onChange:n,className:a=""}){const s=e!=="default";return t.jsxs("div",{"data-sort-control":!0,className:`flex shrink-0 items-center gap-1.5 ${a}`,children:[t.jsxs("label",{htmlFor:"cockpit-ticket-sort",className:"inline-flex items-center gap-1 text-xs font-medium text-gray-500",children:[t.jsx(cs,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Sort"]}),t.jsxs("div",{className:"relative",children:[t.jsx("select",{id:"cockpit-ticket-sort","data-ticket-sort":e,value:e,onChange:l=>n(l.target.value),className:`min-h-[30px] cursor-pointer appearance-none rounded-full py-0 pl-3 pr-7 text-xs font-medium ring-1 ring-inset transition-colors focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-1 ${s?"bg-gray-900 text-white ring-gray-900":"bg-white text-gray-700 ring-gray-300 hover:ring-gray-400"}`,children:Ct.map(l=>t.jsx("option",{value:l.key,className:"bg-white text-gray-900",children:l.label},l.key))}),t.jsx(qn,{className:`pointer-events-none absolute right-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 ${s?"text-white/80":"text-gray-400"}`,"aria-hidden":!0})]})]})}const fl="https://magifyfun.atlassian.net/browse/",ua=7,bn=e=>parseInt(String(e).split("-")[1],10)||0,Be=(e,n)=>bn(e.key)-bn(n.key),ma=e=>e&&e.charAt(0).toUpperCase()+e.slice(1),yn=e=>(e||"").toLowerCase().replace(/[^a-z0-9]+/g," ").trim();function xa(e){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?"":n.toLocaleString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})}function bl(e){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?"":n.toLocaleDateString("en-GB",{day:"numeric",month:"short"})}function Xe({ticketKey:e}){return t.jsx("a",{href:fl+e,target:"_blank",rel:"noopener noreferrer","data-jira-key":e,className:"shrink-0 whitespace-nowrap rounded border border-gray-200 bg-gray-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-gray-500 hover:border-gray-300 hover:text-gray-800",children:e})}const yl="inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium ring-1 ring-inset";function re({kind:e,icon:n,children:a,title:s}){const l={max:"bg-amber-50 text-amber-800 ring-amber-300",nomax:"bg-gray-50 text-gray-600 ring-gray-200",source:"bg-indigo-50 text-indigo-700 ring-indigo-200",merged:"bg-violet-50 text-violet-700 ring-violet-200",later:"bg-sky-50 text-sky-700 ring-sky-200",plan:"bg-emerald-50 text-emerald-800 ring-emerald-200",ok:"bg-emerald-50 text-emerald-700 ring-emerald-600/20"}[e];return t.jsxs("span",{"data-chip":e,title:s,className:`${yl} ${l}`,children:[n&&t.jsx(n,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),a]})}function Dt({ticket:e}){const n=e.claim_ids||[],a=e.merge?.blocks?.length||0;return t.jsxs(t.Fragment,{children:[e.max_related===!0&&t.jsx(re,{kind:"max",icon:Rt,title:"Fixing and checking it runs MAX conversations",children:"Uses MAX"}),e.max_related===!1&&t.jsx(re,{kind:"nomax",title:"No MAX conversation to fix or check it",children:"No MAX cost"}),a>1&&t.jsxs(re,{kind:"merged",icon:st,children:["Merged · ",a," problems"]}),n.slice(0,3).map(s=>t.jsxs(re,{kind:"source",icon:Is,children:["Claim ",s]},s)),!n.length&&a<2&&t.jsx(re,{kind:"source",icon:As,children:"Found by the radar"})]})}function Te({label:e,children:n}){return n?t.jsxs("div",{className:"grid gap-0.5 sm:grid-cols-[8.5rem_1fr] sm:gap-4",children:[t.jsx("dt",{className:"text-xs font-medium uppercase tracking-wide text-gray-400 sm:pt-0.5",children:e}),t.jsx("dd",{className:"min-w-0 text-[15px] leading-relaxed text-gray-900 [overflow-wrap:anywhere]",children:n})]}):null}function wn({links:e}){return e?.length?t.jsx("span",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-1 text-sm",children:e.map((n,a)=>t.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"text-indigo-700 hover:text-indigo-900",children:["Evidence ",a+1]},n))}):null}function wl({ticket:e,claimsById:n}){const a=(e.claim_ids||[]).map(s=>n.get(s)||{claim_id:s});return a.length?t.jsxs("span",{className:"block space-y-2",children:[a.map(s=>t.jsxs("span",{"data-why-claim":s.claim_id,className:"block",children:[s.canonical_claim&&!yn(e.excerpt).includes(yn(s.canonical_claim))?t.jsxs(t.Fragment,{children:["MAX said: “",s.canonical_claim,"” (claim ",s.claim_id,")"]}):t.jsxs(t.Fragment,{children:["From claim ",s.claim_id,"."]}),s.vincent_ruling?.status==="wrong"&&t.jsxs("span",{className:"block text-gray-600",children:["You ruled it wrong",s.vincent_ruling.correction?`: ${s.vincent_ruling.correction}`:"."]}),s.build_request?.text&&t.jsxs("span",{className:"block text-gray-600",children:["You asked for: ",s.build_request.text]})]},s.claim_id)),t.jsx(wn,{links:e.links})]}):t.jsxs(t.Fragment,{children:["The radar found this problem in your product's signals.",t.jsx(wn,{links:e.links})]})}function jl({maxRelated:e}){return e?t.jsxs("span",{"data-cost":"max",children:[t.jsx("span",{className:"font-semibold",children:"Uses MAX: yes."})," Fixing it and checking the fix run real MAX conversations. That is what costs money, so it waits for you."]}):t.jsxs("span",{"data-cost":"none",children:[t.jsx("span",{className:"font-semibold",children:"Uses MAX: no."})," It goes to the fix queue on its own."]})}function vl({ticket:e,claimsById:n}){const a=e.merge?.blocks||[];return a.length<2?null:t.jsx("ol",{"data-merged-blocks":!0,className:"mt-1 space-y-2",children:a.map((s,l)=>t.jsxs("li",{"data-block":s.key,className:"flex gap-2.5",children:[t.jsx("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-violet-100 text-[11px] font-bold text-violet-700",children:l+1}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block text-[15px] text-gray-900",children:s.title||s.key}),t.jsxs("span",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-gray-500",children:[t.jsx(Xe,{ticketKey:s.key}),s.key===e.key?"this ticket":"closed as superseded",(s.claim_ids||[]).map(i=>{const o=n.get(i);return t.jsxs("span",{title:o?.canonical_claim||"",children:["· claim ",i]},i)}),s.max_related&&t.jsx("span",{className:"text-amber-700",children:"· uses MAX"})]})]})]},s.key))})}async function ge(e,n){const a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),s=await a.json().catch(()=>({}));if(!a.ok)throw new Error(s.error||`The server answered ${a.status}`);return s}function ha(e,n){r.useEffect(()=>{const a=s=>{s.key==="Escape"&&!n&&e()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[e,n])}function ga({ticket:e,onClose:n,onDone:a}){const[s,l]=r.useState(""),[i,o]=r.useState(!1),[c,d]=r.useState(null);ha(n,i);const m=async()=>{o(!0),d(null);try{const p=await ge("/api/admin/pipeline/gate",{key:e.key,action:"dismiss",note:s});a(p.ticket),n()}catch(p){d(p.message),o(!1)}};return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-gray-950/50 p-4",onClick:()=>!i&&n(),children:t.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":`dismiss-title-${e.key}`,"data-dismiss-dialog":e.key,onClick:p=>p.stopPropagation(),className:"w-full max-w-md rounded-xl bg-white p-5 shadow-2xl",children:[t.jsxs("h2",{id:`dismiss-title-${e.key}`,className:"text-base font-semibold text-gray-900",children:["Dismiss ",e.key,"?"]}),t.jsx("p",{className:"mt-2 text-sm leading-relaxed text-gray-700",children:"The ticket closes on Jira as declined. It is not fixed, and it costs nothing."}),t.jsx("label",{htmlFor:`dismiss-note-${e.key}`,className:"mt-4 block text-sm font-medium text-gray-800",children:"Why?"}),t.jsx("textarea",{id:`dismiss-note-${e.key}`,"data-dismiss-note":!0,autoFocus:!0,rows:3,maxLength:mn,value:s,onChange:p=>l(p.target.value),placeholder:"For example: not worth a MAX test round, the creator found a way around it.",className:"mt-1.5 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-red-500 focus:outline-none focus:ring-1 focus:ring-red-500"}),t.jsxs("p",{className:"mt-1 text-right text-xs tabular-nums text-gray-400",children:[s.length,"/",mn]}),c&&t.jsx("p",{role:"alert",className:"mt-1 text-sm text-red-700",children:c}),t.jsxs("div",{className:"mt-3 flex justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:n,disabled:i,className:"inline-flex min-h-[40px] items-center rounded-lg px-3 text-sm font-medium text-gray-700 hover:bg-gray-100",children:"Keep it"}),t.jsx("button",{type:"button","data-dismiss-confirm":!0,onClick:m,disabled:i||!s.trim(),className:"inline-flex min-h-[40px] items-center rounded-lg bg-red-600 px-4 text-sm font-semibold text-white shadow-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-600 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",children:i?"Dismissing…":"Dismiss ticket"})]})]})})}function qt({ticket:e,onUpdate:n}){const[a,s]=r.useState(!1),[l,i]=r.useState(null),o=e.merge&&!e.merge.done_at?e.merge.error:null,c=!e.gate_jira_at&&["validated","dismissed"].includes(e.gate)?e.gate_jira_error:null;if(!o&&!c)return null;const d=async()=>{s(!0),i(null);try{const m=o?await ge("/api/admin/pipeline/merge-tickets",{retry:e.key}):await ge("/api/admin/pipeline/gate",{key:e.key,action:"retry"});n(m.ticket)}catch(m){i(m.message)}finally{s(!1)}};return t.jsxs("div",{role:"alert","data-jira-problem":o?"merge":"gate",className:"mt-4 flex flex-wrap items-start gap-x-3 gap-y-2 rounded-lg border border-red-200 bg-red-50 px-3 py-2.5 text-sm text-red-900",children:[t.jsx(ae,{className:"mt-0.5 h-4 w-4 shrink-0 text-red-600","aria-hidden":!0}),t.jsxs("p",{className:"min-w-0 flex-1 [overflow-wrap:anywhere]",children:[t.jsx("span",{className:"font-semibold",children:o?"The merge is not finished on Jira.":"Jira was not updated."})," ",o||c,l&&t.jsx("span",{className:"block",children:l})]}),t.jsxs("button",{type:"button","data-retry":!0,onClick:d,disabled:a,className:"inline-flex min-h-[32px] items-center gap-1 rounded-lg bg-white px-2.5 text-xs font-semibold text-red-800 ring-1 ring-inset ring-red-300 hover:bg-red-100 disabled:opacity-50",children:[t.jsx(On,{className:`h-3.5 w-3.5 ${a?"animate-spin":""}`,"aria-hidden":!0}),a?"Retrying…":"Retry"]})]})}function pa({ticket:e,selected:n,onToggle:a,disabled:s}){return Ye(e)?t.jsx("label",{className:"-m-2 flex shrink-0 cursor-pointer items-center p-2",title:"Select to merge",children:t.jsx("input",{type:"checkbox","data-select":e.key,checked:n,disabled:s&&!n,onChange:()=>a(e.key),"aria-label":`Select ${e.key} to merge`,className:"h-4 w-4 rounded border-gray-300 text-gray-900 focus:ring-gray-900 disabled:opacity-40"})}):null}function Nl({ticket:e,claimsById:n,selected:a,onToggle:s,selectionFull:l,onUpdate:i,planHost:o,inPlanOf:c,onOpenPlan:d,planShown:m}){const[p,u]=r.useState(null),[g,h]=r.useState(null),[$,N]=r.useState(!1),b=r.useCallback(()=>N(!1),[]),f=e.gate==="later",x=!!(e.merge&&!e.merge.done_at),j=e.merge?.blocks?.length||0,S=async B=>{u(B),h(null);try{const k=await ge("/api/admin/pipeline/gate",{key:e.key,action:B});i(k.ticket)}catch(k){h(k.message)}finally{u(null)}};return t.jsxs("article",{"data-gate-card":e.key,"data-gate":e.gate,className:`rounded-xl border bg-white p-4 shadow-sm sm:p-6 ${a?"border-gray-900 ring-1 ring-gray-900":"border-gray-200"}`,children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx(pa,{ticket:e,selected:a,onToggle:s,disabled:l}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.jsx(Xe,{ticketKey:e.key}),e.repo&&t.jsx("span",{"data-repo-badge":e.repo,className:"shrink-0 whitespace-nowrap rounded border border-indigo-200 bg-indigo-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-indigo-700",children:e.repo}),t.jsx(Dt,{ticket:e}),f&&t.jsxs(re,{kind:"later",icon:Fe,children:["Later · since ",bl(e.gate_at)]}),c&&t.jsxs(re,{kind:"plan",icon:Ie,title:"This ticket is in an open Plan testing thread",children:["In the test plan on ",c]}),t.jsx(Se,{ticket:e})]}),t.jsx("h3",{className:"mt-2 text-base font-semibold leading-snug text-gray-900",children:e.title||e.key})]})]}),t.jsxs("dl",{className:"mt-4 space-y-3",children:[j>1?t.jsx(Te,{label:`${j} problems`,children:t.jsx(vl,{ticket:e,claimsById:n})}):t.jsx(Te,{label:"What is wrong",children:ma(e.plain?.problem||e.excerpt)}),j<2&&t.jsx(Te,{label:"Why it exists",children:t.jsx(wl,{ticket:e,claimsById:n})}),"max_related"in e&&t.jsx(Te,{label:"Cost",children:t.jsx(jl,{maxRelated:e.max_related})}),j>1&&t.jsx(Te,{label:"Saved",children:t.jsx("span",{"data-merge-saved":!0,children:dt(j)})})]}),t.jsx(ct,{strategy:e.plan?.strategy}),t.jsx(qt,{ticket:e,onUpdate:i}),t.jsxs("div",{className:"mt-5 flex flex-wrap items-center gap-2 border-t border-gray-100 pt-4",children:[t.jsxs("button",{type:"button","data-gate-action":"validate",onClick:()=>S("validate"),disabled:!!p||x,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",children:[t.jsx(Dn,{className:"h-4 w-4","aria-hidden":!0}),p==="validate"?"Validating…":"Validate"]}),f?t.jsxs("button",{type:"button","data-gate-action":"back",onClick:()=>S("back"),disabled:!!p,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg px-3 text-sm font-medium text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 disabled:opacity-50",children:[t.jsx(Ln,{className:"h-4 w-4 text-gray-400","aria-hidden":!0}),p==="back"?"Moving…":"Back to waiting"]}):t.jsxs("button",{type:"button","data-gate-action":"later",onClick:()=>S("later"),disabled:!!p,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg px-3 text-sm font-medium text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 disabled:opacity-50",children:[t.jsx(Fe,{className:"h-4 w-4 text-gray-400","aria-hidden":!0}),p==="later"?"Moving…":"Later"]}),t.jsx("button",{type:"button","data-gate-action":"dismiss",onClick:()=>N(!0),disabled:!!p||x,className:"ml-auto inline-flex min-h-[40px] items-center rounded-lg px-3 text-sm font-medium text-red-600 hover:bg-red-50 hover:text-red-800 disabled:opacity-50",children:"Dismiss"}),f&&t.jsx("p",{className:"basis-full text-xs text-gray-500",children:"Parked: it stays out of the fix queue and costs nothing until you validate it."}),g&&t.jsx("p",{role:"alert",className:"basis-full text-sm text-red-700",children:g})]}),o&&d&&t.jsx(da,{host:o,onOpen:d,onUpdate:i,shown:m}),$&&t.jsx(ga,{ticket:e,onClose:b,onDone:i})]})}function Ae({id:e,title:n,hint:a,count:s,children:l}){return t.jsxs("section",{"data-gate-section":e,"aria-labelledby":`gate-${e}`,className:"space-y-3",children:[t.jsxs("h2",{id:`gate-${e}`,className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:[n,s>0&&t.jsxs("span",{className:"normal-case tracking-normal",children:[" · ",s]}),a&&t.jsxs("span",{className:"normal-case tracking-normal",children:[" · ",a]})]}),l]})}function kl({ticket:e,onUpdate:n}){const a=!!e.gate_jira_at;return t.jsxs("li",{"data-validated":e.key,className:"px-4 py-3 sm:px-5",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Xe,{ticketKey:e.key}),a?t.jsx(re,{kind:"ok",icon:Ze,children:"Validated · in the fix queue"}):t.jsx(re,{kind:"max",icon:Fe,children:"Validated · not queued yet"}),e.max_related&&t.jsx(re,{kind:"max",icon:Rt,children:"Uses MAX"}),t.jsx("span",{className:"text-xs text-gray-500",children:xa(e.gate_at)}),t.jsx(Se,{ticket:e,className:"ml-auto"})]}),t.jsx("p",{className:"mt-1 text-sm font-medium text-gray-900",children:e.title||e.key}),t.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:a?"Label max-go is on the Jira ticket. The fix queue takes it on its next run, then it moves to Ready to merge.":e.gate_jira_error?"The fix queue takes it only once the label max-go is on Jira.":"Adding the label max-go on Jira…"}),t.jsx(qt,{ticket:e,onUpdate:n})]})}function _l({ticket:e,selected:n,onToggle:a,selectionFull:s}){return t.jsxs("li",{"data-auto":e.key,className:`flex items-start gap-3 px-4 py-3 sm:px-5 ${n?"bg-gray-50":""}`,children:[t.jsx(pa,{ticket:e,selected:n,onToggle:a,disabled:s}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.jsx(Xe,{ticketKey:e.key}),t.jsx(Dt,{ticket:e}),t.jsx(Se,{ticket:e,className:"ml-auto"})]}),t.jsx("p",{className:"mt-1 text-sm font-medium text-gray-900",children:e.title||e.key}),(e.plain?.problem||e.excerpt)&&t.jsx("p",{className:"mt-0.5 line-clamp-2 text-sm text-gray-600",children:ma(e.plain?.problem||e.excerpt)})]})]})}function Cl({ticket:e,onUpdate:n}){return t.jsxs("li",{"data-dismissed":e.key,className:"bg-gray-50/70 px-4 py-3 sm:px-5",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Xe,{ticketKey:e.key}),t.jsx("span",{className:"rounded-full bg-gray-200 px-1.5 py-0.5 text-[11px] font-medium text-gray-600",children:"Dismissed"}),t.jsx("span",{className:"text-xs text-gray-500",children:xa(e.gate_at)}),t.jsx(Se,{ticket:e,className:"ml-auto"})]}),t.jsx("p",{className:"mt-1 text-sm text-gray-500",children:e.title||e.key}),e.gate_note&&t.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:["Reason: ",e.gate_note]}),t.jsx("p",{className:"mt-0.5 text-xs text-gray-400",children:e.gate_jira_at?"Closed on Jira as declined.":"Closing on Jira…"}),t.jsx(qt,{ticket:e,onUpdate:n})]})}function $l({tickets:e,onClose:n,onDone:a}){const s=[...e].sort(Be)[0].key,[l,i]=r.useState(s),[o,c]=r.useState(!1),[d,m]=r.useState(null);ha(n,o);const p=e.reduce((h,$)=>h+Math.max(1,$.merge?.blocks?.length||0),0),u=e.some(h=>h.max_related),g=async()=>{c(!0),m(null);try{const h=await ge("/api/admin/pipeline/merge-tickets",{keys:e.map($=>$.key),survivor:l});a(h.ticket,h.absorbed),n()}catch(h){m(h.message),c(!1)}};return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-gray-950/50 p-4",onClick:()=>!o&&n(),children:t.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"merge-title","data-merge-dialog":!0,onClick:h=>h.stopPropagation(),className:"flex max-h-[90vh] w-full max-w-lg flex-col rounded-xl bg-white p-5 shadow-2xl",children:[t.jsxs("h2",{id:"merge-title",className:"text-base font-semibold text-gray-900",children:["Merge ",e.length," tickets into one?"]}),t.jsx("p",{className:"mt-2 text-sm leading-relaxed text-gray-700",children:"One ticket keeps every problem as its own block, with where it came from. The others close as superseded and point to it on Jira."}),t.jsx("p",{"data-merge-savings":!0,className:"mt-3 rounded-lg bg-emerald-50 px-3 py-2.5 text-sm font-medium text-emerald-900",children:dt(e.length,p)}),t.jsxs("fieldset",{className:"mt-4 min-h-0 overflow-y-auto",children:[t.jsx("legend",{className:"text-sm font-medium text-gray-800",children:"Which ticket stays?"}),t.jsx("div",{className:"mt-2 space-y-1.5",children:[...e].sort(Be).map(h=>t.jsxs("label",{className:`flex cursor-pointer items-start gap-3 rounded-lg border px-3 py-2 text-sm ${l===h.key?"border-gray-900 bg-gray-50":"border-gray-200 hover:border-gray-300"}`,children:[t.jsx("input",{type:"radio",name:"merge-survivor","data-survivor":h.key,checked:l===h.key,onChange:()=>i(h.key),className:"mt-0.5 h-4 w-4 border-gray-300 text-gray-900 focus:ring-gray-900"}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"font-mono text-xs text-gray-500",children:h.key}),h.max_related&&t.jsx("span",{className:"ml-2 text-xs text-amber-700",children:"uses MAX"}),t.jsx("span",{className:"block text-gray-900",children:h.title||h.key})]})]},h.key))})]}),t.jsx("p",{className:"mt-3 text-xs leading-relaxed text-gray-500",children:u?"At least one problem uses MAX, so the merged ticket comes back here for your validation.":"No problem uses MAX, so the merged ticket goes to the fix queue on its own."}),d&&t.jsx("p",{role:"alert",className:"mt-2 text-sm text-red-700",children:d}),t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:n,disabled:o,className:"inline-flex min-h-[40px] items-center rounded-lg px-3 text-sm font-medium text-gray-700 hover:bg-gray-100",children:"Keep separate"}),t.jsxs("button",{type:"button","data-merge-confirm":!0,onClick:g,disabled:o,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 disabled:opacity-50",children:[t.jsx(st,{className:"h-4 w-4","aria-hidden":!0}),o?"Merging…":"Merge into one ticket"]})]})]})})}function El({selected:e,onClear:n,onMerge:a,onPlan:s}){if(!e.length)return null;const l=!!s&&e.every(o=>o.plan?.on),i=e.reduce((o,c)=>o+Math.max(1,c.merge?.blocks?.length||0),0);return t.jsxs("div",{"data-merge-bar":!0,className:"sticky bottom-4 z-30 mt-6 flex flex-wrap items-center gap-x-4 gap-y-2 rounded-xl bg-gray-900 px-4 py-3 text-white shadow-xl sm:px-5",children:[t.jsxs("p",{className:"text-sm font-semibold",children:[e.length," selected"]}),t.jsx("p",{"data-merge-bar-savings":!0,className:"min-w-0 flex-1 text-sm text-gray-300",children:e.length<2?"Pick at least one more to merge.":dt(e.length,i)}),t.jsx("button",{type:"button",onClick:n,className:"text-sm font-medium text-gray-300 underline underline-offset-2 hover:text-white",children:"Clear"}),l&&t.jsxs("button",{type:"button","data-plan-open":!0,onClick:s,title:"Debate with the pipeline which of these to test together and how, before any test money is spent",className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg px-4 text-sm font-semibold text-white ring-1 ring-inset ring-white/40 hover:bg-white/10 disabled:cursor-not-allowed disabled:opacity-40",children:[t.jsx(Ie,{className:"h-4 w-4","aria-hidden":!0}),"Plan testing"]}),t.jsxs("button",{type:"button","data-merge-open":!0,onClick:a,disabled:e.length<2,className:"inline-flex min-h-[40px] items-center gap-1.5 rounded-lg bg-white px-4 text-sm font-semibold text-gray-900 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40",children:[t.jsx(st,{className:"h-4 w-4","aria-hidden":!0}),"Merge into one ticket"]})]})}function fa(e){const n=Date.now()-ua*24*3600*1e3,a=e.filter(s=>s.queue==="backlog"&&!s.merged_into);return{pending:a.filter(s=>s.gate==="pending").sort(Be),later:a.filter(s=>s.gate==="later").sort(Be),validated:a.filter(s=>s.gate==="validated").sort((s,l)=>new Date(l.gate_at)-new Date(s.gate_at)),auto:a.filter(s=>s.gate==="auto").sort(Be),dismissed:a.filter(s=>s.gate==="dismissed"&&new Date(s.gate_at).getTime()>=n).sort((s,l)=>new Date(l.gate_at)-new Date(s.gate_at))}}function jn({tickets:e,claims:n,onUpdate:a,onMerged:s,renderPlan:l,bundles:i,sort:o="default"}){const c=r.useMemo(()=>Object.fromEntries(Object.entries(fa(e)).map(([w,T])=>[w,Xn(T,o)])),[e,o]),d=r.useMemo(()=>new Map((n||[]).map(w=>[w.claim_id,w])),[n]),[m,p]=r.useState([]),[u,g]=r.useState(!1),h=r.useCallback(()=>g(!1),[]),$=r.useMemo(()=>new Map(e.map(w=>[w.key,w])),[e]),N=m.map(w=>$.get(w)).filter(w=>Ye(w)),b=N.length>=Vr,f=r.useCallback(w=>p(T=>T.includes(w)?T.filter(K=>K!==w):[...T,w]),[]),x=w=>N.some(T=>T.key===w),j=(w,T)=>{s(w,T),p([])},S=_r(),B=r.useMemo(()=>e.filter(w=>w.queue==="backlog"&&w.plan_thread&&w.plan?.on),[e]),k=w=>B.find(T=>T.key===w.key&&!T.merged_into)||B.find(T=>T.merged_into===w.key),E=w=>B.find(T=>T.key!==w.key&&!T.merged_into&&!T.plan_thread.closed_at&&T.plan_thread.keys.includes(w.key))?.key,[R,F]=r.useState(null),A=r.useCallback(()=>F(null),[]),M=(w,T)=>w.length===T.length&&w.every(K=>T.includes(K)),W=w=>(_?.groups||[]).find(T=>M(T.keys,w))||null,v=w=>B.find(T=>!T.merged_into&&!T.plan_thread.closed_at&&w.some(K=>T.plan_thread.keys.includes(K))),C=async(w=N.map(K=>K.key),T=W(w))=>{p([]);const K=v(w);if(K&&M(K.plan_thread.keys,w)){F({keys:w,group:T,hostKey:K.key});return}F({keys:w,group:T,hostKey:null,opening:!0});try{const xe=await ge("/api/admin/pipeline/plan",{keys:w});a(xe.ticket),F(Q=>Q&&{...Q,hostKey:xe.ticket.key,opening:!1})}catch(xe){F(Q=>Q&&{...Q,opening:!1,error:xe.message})}},O=w=>F({keys:w.plan_thread.keys,group:W(w.plan_thread.keys),hostKey:w.key}),y=w=>{F(null),setTimeout(()=>{document.querySelector(`[data-gate-card="${w}"], [data-phone-page="${w}"]`)?.scrollIntoView({behavior:"smooth",block:"center"})},50)},[_,L]=r.useState(i||null),D=r.useMemo(()=>rr(_,new Set(e.filter(Ye).map(w=>w.key))),[_,e]),Z=D?.groups.find(w=>w.keys.length===N.length&&w.keys.every(T=>x(T)))?.id,I=w=>p(Z===w.id?[]:[...w.keys]),V=w=>{const T=v(w.keys);return T?Ft(T):null},ie=async w=>{const T=await ge("/api/admin/pipeline/bundles",{id:w.id,input_hash:D.input_hash});L(T.bundles),Z===w.id&&p([])},se=w=>t.jsx(Nl,{ticket:w,claimsById:d,selected:x(w.key),onToggle:f,selectionFull:b,onUpdate:a,planHost:k(w),inPlanOf:E(w),onOpenPlan:l?O:null,planShown:!!R?.hostKey&&R.hostKey===k(w)?.key},w.key),ne=t.jsxs(t.Fragment,{children:[u&&N.length>=2&&t.jsx($l,{tickets:N,onClose:h,onDone:j}),R&&t.jsx(rl,{keys:R.keys,group:R.group,host:R.hostKey?$.get(R.hostKey):null,opening:R.opening,error:R.error,ticketOf:w=>$.get(w),renderPlan:l,onUpdate:a,onClose:A,onDismiss:ie,onShow:y})]});return S?t.jsx(Xr,{lists:c,onUpdate:a,dialogs:ne,bundleCount:D?.groups.length||0,renderBundles:w=>t.jsx(gn,{view:D,titleOf:T=>$.get(T)?.title||T,activeId:Z,canPlan:T=>!!l&&T.keys.every(K=>$.get(K)?.plan?.on),threadOf:V,onPick:T=>{I(T),w()},onReview:T=>{w(),C(T.keys,T)},onDismiss:ie}),sel:{selected:N,full:b,isSel:x,toggle:f,onClear:()=>p([]),onMerge:()=>g(!0),onPlan:l?()=>C():null},gate:{DismissDialog:ga,SourceChips:Dt,mergeable:Ye,inPlanOf:E,planHostOf:k,renderDetails:se,renderPlanEntry:l?w=>t.jsx(da,{host:k(w),onOpen:O,onUpdate:a,shown:!1}):null}}):t.jsxs("div",{"data-gate-tab":!0,children:[t.jsxs("div",{className:"space-y-8",children:[t.jsx(gn,{view:D,titleOf:w=>$.get(w)?.title||w,activeId:Z,canPlan:w=>!!l&&w.keys.every(T=>$.get(T)?.plan?.on),threadOf:V,onPick:I,onReview:w=>C(w.keys,w),onDismiss:ie}),t.jsx("p",{className:"max-w-3xl text-sm leading-relaxed text-gray-600",children:"With the validation gate on, new tickets wait here for your go: nothing moves on until you validate. Validate promotes one to the next stage; Later keeps it here; Dismiss drops it with your reason. Select several to merge them into one ticket."}),t.jsx(Ae,{id:"pending",title:"Awaiting your validation",count:c.pending.length,children:c.pending.length?t.jsx("div",{className:"grid grid-cols-1 items-start gap-4 2xl:grid-cols-2",children:c.pending.map(se)}):t.jsx("p",{className:"rounded-xl border border-dashed border-gray-300 bg-white px-4 py-10 text-center text-sm text-gray-500",children:"Nothing is waiting for your validation."})}),c.later.length>0&&t.jsx(Ae,{id:"later",title:"Later",hint:"parked, costs nothing",count:c.later.length,children:t.jsx("div",{className:"grid grid-cols-1 items-start gap-4 2xl:grid-cols-2",children:c.later.map(se)})}),c.validated.length>0&&t.jsx(Ae,{id:"validated",title:"Validated",hint:"your go",count:c.validated.length,children:t.jsx("ul",{className:"divide-y divide-gray-100 rounded-xl border border-emerald-200 bg-white shadow-sm",children:c.validated.map(w=>t.jsx(kl,{ticket:w,onUpdate:a},w.key))})}),c.auto.length>0&&t.jsx(Ae,{id:"auto",title:"Flowing on their own",hint:"no validation needed",count:c.auto.length,children:t.jsx("ul",{className:"divide-y divide-gray-100 rounded-xl border border-gray-200 bg-white shadow-sm",children:c.auto.map(w=>t.jsx(_l,{ticket:w,selected:x(w.key),onToggle:f,selectionFull:b},w.key))})}),c.dismissed.length>0&&t.jsx(Ae,{id:"dismissed",title:"Dismissed",hint:`last ${ua} days`,count:c.dismissed.length,children:t.jsx("ul",{className:"divide-y divide-gray-100 overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm",children:c.dismissed.map(w=>t.jsx(Cl,{ticket:w,onUpdate:a},w.key))})})]}),t.jsx(El,{selected:N,onClear:()=>p([]),onMerge:()=>g(!0),onPlan:l?()=>C():null}),ne]})}const ba="https://magifyfun.atlassian.net/browse/",Sl={magify_agents_api:"api",magify_next:"next"},kt=[{key:"validate",label:"Awaiting validation"},{key:"merge",label:"Ready to merge"},{key:"decide",label:"Needs decision"},{key:"manual",label:"Manual"},{key:"claims",label:"Claims"},{key:"shipped",label:"Shipped"}],nt=e=>`/api/admin/pipeline/evidence?k=${encodeURIComponent(e.s3_key)}`,te=e=>`${Sl[e.repo]||e.repo}#${e.number}`;function at(e){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?"":n.toLocaleString("en-GB",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})}function ut({ticketKey:e}){return t.jsx("a",{href:ba+e,target:"_blank",rel:"noopener noreferrer","data-jira-key":e,className:"shrink-0 whitespace-nowrap rounded border border-gray-200 bg-gray-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-gray-500 hover:border-gray-300 hover:text-gray-800",children:e})}function mt({repo:e}){return e?t.jsx("span",{"data-repo-badge":e,title:`Repo: ${e}`,className:"shrink-0 whitespace-nowrap rounded border border-indigo-200 bg-indigo-50 px-1.5 py-0.5 font-mono text-[11px] font-medium text-indigo-700",children:e}):null}function Oe({label:e,children:n}){return n?t.jsxs("div",{className:"grid gap-0.5 sm:grid-cols-[10.5rem_1fr] sm:gap-4 xl:grid-cols-1 xl:gap-1",children:[t.jsx("dt",{className:"text-xs font-medium uppercase tracking-wide text-gray-400 sm:pt-0.5 xl:pt-0",children:e}),t.jsx("dd",{className:"text-[15px] leading-relaxed text-gray-900",children:n})]}):null}const Rl=50;function Ml({images:e,index:n,onIndex:a,onClose:s}){const l=e.length,i=e[n],o=r.useCallback(u=>a((n+u+l)%l),[n,l,a]),c=r.useRef(null);r.useEffect(()=>{const u=g=>{g.key==="Escape"?s():l>1&&g.key==="ArrowLeft"?(g.preventDefault(),o(-1)):l>1&&g.key==="ArrowRight"&&(g.preventDefault(),o(1))};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,o,l]),r.useEffect(()=>{l<2||[e[(n+1)%l],e[(n-1+l)%l]].forEach(u=>{new window.Image().src=nt(u)})},[e,n,l]);const d=u=>{c.current=u.touches[0]?.clientX??null},m=u=>{const g=c.current;c.current=null;const h=g==null?0:(u.changedTouches[0]?.clientX??g)-g;l>1&&Math.abs(h)>Rl&&o(h<0?1:-1)},p="absolute top-1/2 z-10 -translate-y-1/2 rounded-full bg-gray-900/70 p-2.5 text-white shadow-lg ring-1 ring-white/20 hover:bg-gray-900/90 focus:outline-none focus-visible:ring-2 focus-visible:ring-white sm:p-3";return t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":i.caption||i.name,"data-lightbox":!0,"data-lightbox-index":n,"data-lightbox-kind":i.chat?"chat":"proof",onClick:s,onTouchStart:d,onTouchEnd:m,className:"fixed inset-0 z-50 flex flex-col items-center justify-center gap-3 bg-gray-950/85 p-4 sm:px-20 sm:py-8",children:[t.jsx("button",{type:"button",onClick:s,"aria-label":"Close",className:"absolute right-3 top-3 z-10 rounded-full bg-white/10 p-2 text-white hover:bg-white/20",children:t.jsx(fe,{className:"h-5 w-5","aria-hidden":!0})}),l>1&&t.jsxs(t.Fragment,{children:[t.jsxs("p",{"data-lightbox-position":!0,className:"absolute left-4 top-4 z-10 rounded-full bg-gray-900/70 px-2.5 py-1 text-xs font-medium tabular-nums text-white","aria-live":"polite",children:[n+1," / ",l]}),t.jsx("button",{type:"button","data-lightbox-prev":!0,"aria-label":"Previous image",onClick:u=>{u.stopPropagation(),o(-1)},className:`${p} left-2 sm:left-5`,children:t.jsx(In,{className:"h-6 w-6","aria-hidden":!0})}),t.jsx("button",{type:"button","data-lightbox-next":!0,"aria-label":"Next image",onClick:u=>{u.stopPropagation(),o(1)},className:`${p} right-2 sm:right-5`,children:t.jsx(pe,{className:"h-6 w-6","aria-hidden":!0})})]}),t.jsx("img",{src:nt(i),alt:i.caption||i.name,onClick:u=>u.stopPropagation(),className:"max-h-[82vh] max-w-full rounded-lg bg-white object-contain shadow-2xl"},i.sha256),t.jsx("p",{"data-lightbox-caption":!0,className:"max-w-3xl text-center text-sm text-gray-200",children:i.caption||i.name})]})}const Tl="1440 / 992";function Al({image:e,onOpen:n,small:a}){const[s,l]=r.useState(!1),i=a?" sm:aspect-[4/3] sm:w-full sm:max-h-none sm:object-cover sm:object-left-top":"";return t.jsxs("figure",{"data-evidence":e.name,className:"min-w-0",children:[t.jsx("button",{type:"button",onClick:n,"aria-label":`Open full size: ${e.caption||e.name}`,className:"group block w-full cursor-zoom-in overflow-hidden rounded-lg border border-gray-200 bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:t.jsx("img",{src:nt(e),alt:e.caption||e.name,loading:"lazy",onLoad:()=>l(!0),style:s?void 0:{aspectRatio:Tl},className:`mx-auto block transition-opacity group-hover:opacity-90 ${s?"h-auto max-h-[75vh] w-auto max-w-full":"w-full"}${i}`})}),t.jsx("figcaption",{className:`mt-2 text-sm leading-snug text-gray-700${a?" sm:mt-1 sm:line-clamp-2 sm:text-xs sm:text-gray-500":""}`,children:e.caption||e.name})]})}function ya({evidence:e,size:n,onOpen:a}){const s=n==="small",l=e.filter(i=>i.s3_key);return e.length?t.jsxs("section",{className:"mt-5","aria-label":"Proof screenshots",children:[t.jsxs("h3",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:["Proof ",t.jsxs("span",{className:"normal-case tracking-normal text-gray-400",children:["· ",e.length," screenshots"]})]}),l.length===0?t.jsx("p",{className:"mt-2 text-sm text-gray-500",children:"The screenshots upload on the next pipeline sync."}):t.jsx("div",{"data-proof-grid":!0,"data-proof-size":s?"small":"large",className:`mt-3 grid items-start ${s?"grid-cols-1 gap-x-5 gap-y-6 sm:grid-cols-3 sm:gap-3 xl:grid-cols-4":"gap-x-5 gap-y-6 [grid-template-columns:repeat(auto-fill,minmax(min(100%,600px),1fr))]"}`,children:l.map((i,o)=>t.jsx(Al,{image:i,onOpen:()=>a(o),small:s},i.sha256))})]}):null}function Pl(e){const n=(e.evidence||[]).filter(s=>s.s3_key),a=It(e.chat).flatMap(s=>{const l=s.images||[],i=s.kind==="directive"?"Screenshot with your fix request":"Your screenshot in the chat";return l.map((o,c)=>({...o,chat:s.id,caption:`${i} · ${le(s.at)}${l.length>1?` · ${c+1} of ${l.length}`:""}${o.name?` · ${o.name}`:""}`}))});return[...n,...a]}function xt(e){const n=Kn(),a=r.useMemo(()=>Pl(e),[e]),[s,l]=r.useState(null),i=r.useCallback(()=>l(null),[]),o=r.useCallback(m=>l(m),[]),c=r.useCallback((m,p)=>{const u=a.findIndex(g=>g.chat===m&&g.sha256===p);u>=0&&l(u)},[a]);let d=null;return s!=null&&a[s]&&(d=n?t.jsx(Br,{onClose:i,children:t.jsx(Pr,{images:a,index:s,onIndex:l,onClose:i})}):t.jsx(Ml,{images:a,index:s,onIndex:l,onClose:i})),{openProof:o,openShot:c,viewer:d}}function Bl({ticket:e}){const[n,a]=r.useState(!1),s=e.prs.reduce((i,o)=>({files:i.files+(o.changed_files||0),add:i.add+(o.additions||0),del:i.del+(o.deletions||0)}),{files:0,add:0,del:0}),l=`dev-${e.key}`;return t.jsxs("section",{className:"mt-5 border-t border-gray-100 pt-3",children:[t.jsxs("button",{type:"button","aria-expanded":n,"aria-controls":l,onClick:()=>a(i=>!i),className:"-mx-1 flex w-full items-center gap-1 rounded px-1 py-1 text-left text-sm font-medium text-gray-700 hover:text-gray-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:[t.jsx(pe,{className:`h-4 w-4 text-gray-400 transition-transform ${n?"rotate-90":""}`,"aria-hidden":!0}),"Development",t.jsxs("span",{className:"ml-2 font-normal text-gray-400",children:[e.prs.map(te).join(", ")," · ",s.files," files",t.jsxs("span",{className:"text-emerald-600",children:[" +",s.add]}),t.jsxs("span",{className:"text-red-600",children:[" −",s.del]})]})]}),n&&t.jsxs("div",{id:l,"data-development":!0,className:"mt-3 space-y-4 text-sm",children:[e.prs.map(i=>t.jsxs("div",{children:[t.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 font-medium text-indigo-700 hover:text-indigo-900",children:[te(i),t.jsx(Le,{className:"h-3.5 w-3.5","aria-hidden":!0})]}),t.jsx("span",{className:"ml-2 text-gray-700",children:i.title}),t.jsxs("p",{className:"mt-0.5 text-xs text-gray-400",children:[t.jsx("span",{className:"font-mono",children:i.head})," into ",t.jsx("span",{className:"font-mono",children:i.base})]}),i.files?.length>0&&t.jsx("ul",{className:"mt-1.5 divide-y divide-gray-100 rounded-md border border-gray-100 font-mono text-xs",children:i.files.map(o=>t.jsxs("li",{className:"flex items-center gap-3 px-2.5 py-1",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-gray-700",title:o.path,children:o.path}),t.jsxs("span",{className:"shrink-0 tabular-nums text-emerald-600",children:["+",o.additions]}),t.jsxs("span",{className:"w-10 shrink-0 text-right tabular-nums text-red-600",children:["−",o.deletions]})]},o.path))})]},`${i.repo}#${i.number}`)),e.verdict&&t.jsxs("div",{"data-verdict":!0,children:[t.jsxs("h4",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:["Hostile check",e.fix_class?` · ${e.fix_class.toLowerCase()} fix`:""]}),t.jsx("p",{className:"mt-1 whitespace-pre-line leading-relaxed text-gray-700 [overflow-wrap:anywhere]",children:e.verdict})]})]})]})}const vn=e=>`${e}${{1:"st",2:"nd",3:"rd"}[e]||"th"}`;function Ol({ticket:e,held:n=!1}){const a=lt(e.prs),s=a.length>1,l=!!e.hold||n;return t.jsxs("section",{"data-github-links":!0,"aria-label":"Merge on GitHub",className:"space-y-2",children:[s&&t.jsxs("p",{"data-merge-order":!0,className:"text-sm font-semibold text-gray-900",children:["Merge order: ",a.length," PRs, one at a time, top to bottom"]}),t.jsx("ol",{className:"space-y-2",children:a.map(({pr:i,step:o,parent:c})=>{const d=o>1?a[o-2].pr:null;return t.jsxs("li",{"data-pr-step":o,"data-pr":te(i),className:"flex flex-col gap-2 rounded-lg border border-gray-200 px-3 py-2.5 sm:flex-row sm:items-center sm:gap-3",children:[s&&t.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-gray-900 text-sm font-bold text-white","aria-hidden":!0,children:o}),t.jsxs("div",{className:"min-w-0 flex-1 text-sm",children:[t.jsxs("p",{className:"truncate text-gray-900",title:i.title,children:[t.jsx("span",{className:"font-semibold",children:te(i)}),t.jsxs("span",{className:"text-gray-500",children:[" · ",i.title]})]}),s&&t.jsxs("p",{"data-step-note":!0,className:`mt-0.5 text-xs ${c?"font-medium text-amber-800":"text-gray-500"}`,children:[o===1&&"Merge 1st.",o>1&&c&&`Merge ${vn(o)}, after its parent ${te(c)} (stacked on it). If GitHub still shows this PR into ${c.head}, change its base to ${c.base} first.`,o>1&&!c&&`Merge ${vn(o)}, after ${te(d)}.`]})]}),t.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer","data-open-github":te(i),className:`inline-flex min-h-[40px] shrink-0 items-center justify-center gap-1.5 rounded-lg px-4 text-sm font-semibold shadow-sm focus:outline-none focus:ring-2 focus:ring-offset-2 ${l?"border border-gray-300 bg-white text-gray-700 hover:bg-gray-50 focus:ring-gray-400":"bg-gray-900 text-white hover:bg-gray-700 focus:ring-gray-900"}`,children:["Open ",te(i)," on GitHub",t.jsx(Le,{className:"h-4 w-4","aria-hidden":!0})]})]},`${i.repo}#${i.number}`)})})]})}const Ll=30*1e3,Fl=1200*1e3;function le(e){const n=new Date(e);if(Number.isNaN(n.getTime()))return"";const a=n.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return n.toDateString()===new Date().toDateString()?a:`${n.toLocaleDateString("en-GB",{day:"numeric",month:"short"})}, ${a}`}const It=e=>[...e||[]].sort((n,a)=>new Date(n.at)-new Date(a.at)),Nn=/^\s*[-•]\s+/;function kn({text:e}){return e.split(/(`[^`\n]+`)/).map((n,a)=>/^`[^`]+`$/.test(n)?t.jsx("code",{className:"rounded bg-black/[0.06] px-1 py-px font-mono text-[12.5px]",children:n.slice(1,-1)},a):n)}function wa({text:e}){const n=[];return(e||"").split(/\n\s*\n/).forEach((a,s)=>{let l=[],i=[];const o=()=>{l.length&&n.push(t.jsx("p",{className:"whitespace-pre-line",children:t.jsx(kn,{text:l.join(`
|
|
2
2
|
`)})},`${s}-p${n.length}`)),i.length&&n.push(t.jsx("ul",{className:"list-disc space-y-1 pl-4",children:i.map((c,d)=>t.jsx("li",{children:t.jsx(kn,{text:c})},d))},`${s}-u${n.length}`)),l=[],i=[]};a.split(`
|
|
3
3
|
`).forEach(c=>{Nn.test(c)?(l.length&&o(),i.push(c.replace(Nn,""))):c.trim()&&(i.length&&/^\s{2,}\S/.test(c)?i[i.length-1]+=` ${c.trim()}`:(i.length&&o(),l.push(c)))}),o()}),n}function ja({message:e,onOpen:n,align:a="end"}){const s=e.images||[];return s.length?t.jsx("div",{"data-chat-images":e.id,className:`mb-1.5 flex flex-wrap gap-1.5 ${a==="end"?"justify-end":"justify-start"}`,children:s.map((l,i)=>t.jsx("button",{type:"button","data-chat-image":l.sha256,onClick:()=>n?.(e.id,l.sha256),"aria-label":`Open screenshot ${i+1} of ${s.length} full size`,className:"group block h-24 w-32 cursor-zoom-in overflow-hidden rounded-xl border border-gray-200 bg-gray-100 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 sm:h-28 sm:w-40",children:t.jsx("img",{src:nt(l),alt:l.name||`Screenshot ${i+1}`,loading:"lazy",className:"h-full w-full object-cover object-left-top transition-opacity group-hover:opacity-90"})},l.sha256))}):null}function Dl({message:e,onOpenImage:n}){return t.jsx("li",{"data-chat-message":"directive","data-directive":e.id,className:"flex justify-end",children:t.jsxs("div",{className:"flex min-w-0 max-w-[85%] flex-col items-end",children:[t.jsx(ja,{message:e,onOpen:n}),t.jsxs("div",{className:"rounded-2xl rounded-br-md border border-amber-300 bg-amber-50 px-3.5 py-2.5 text-[14px] leading-relaxed text-amber-950 [overflow-wrap:anywhere]",children:[t.jsxs("p",{className:"mb-1 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide text-amber-800",children:[t.jsx(ue,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Fix request"]}),t.jsx("div",{className:"space-y-2",children:t.jsx(wa,{text:e.text})}),e.context&&t.jsx("p",{className:"mt-1.5 text-xs text-amber-800/80",children:"With the conversation above it as context."})]}),t.jsxs("p",{className:"mt-1 px-1 text-[11px] text-gray-400",children:["You · ",le(e.at)," · ",e.ack_error?t.jsx("span",{className:"text-red-600",children:e.ack_error}):e.acked_at?"filed on the ticket":"sent to the pipeline"]})]})})}const ql={delivered:{Icon:Ze,avatar:"bg-emerald-50 text-emerald-600 ring-emerald-200",bubble:"bg-emerald-50 text-emerald-950 ring-1 ring-inset ring-emerald-200"},failed:{Icon:ae,avatar:"bg-red-50 text-red-600 ring-red-200",bubble:"bg-red-50 text-red-950 ring-1 ring-inset ring-red-200"}};function Il({message:e,onRequestFix:n,requesting:a,onOpenImage:s}){if(e.kind==="directive")return t.jsx(Dl,{message:e,onOpenImage:s});const l=e.role==="vincent",i=ql[Ne(e)],o=i?.Icon||Zn;return t.jsxs("li",{"data-chat-message":e.role,"data-chat-id":e.id,"data-fix-outcome":Ne(e)||void 0,className:`flex gap-2.5 ${l?"justify-end":"justify-start"}`,children:[!l&&t.jsx("span",{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full ring-1 ring-inset ${i?.avatar||"bg-indigo-50 text-indigo-600 ring-indigo-100"}`,"aria-hidden":!0,children:t.jsx(o,{className:"h-4 w-4"})}),t.jsxs("div",{className:`flex min-w-0 max-w-[85%] flex-col ${l?"items-end":"items-start"}`,children:[t.jsx(ja,{message:e,onOpen:s,align:l?"end":"start"}),e.text&&t.jsx("div",{className:`space-y-2 rounded-2xl px-3.5 py-2.5 text-[14px] leading-relaxed [overflow-wrap:anywhere] ${l?"rounded-br-md bg-gray-900 text-white":`rounded-bl-md ${i?.bubble||"bg-gray-100 text-gray-900"}`}`,children:t.jsx(wa,{text:e.text})}),t.jsxs("p",{className:"mt-1 px-1 text-[11px] text-gray-400",children:[l?"You":"Pipeline"," · ",le(e.at),l&&e.source==="jira"&&" · from Jira",l&&e.ack_error&&t.jsxs("span",{className:"text-red-600",children:[" · ",e.ack_error]}),l&&n&&t.jsxs(t.Fragment,{children:[" · ",t.jsxs("button",{type:"button","data-request-this-fix":e.id,onClick:()=>n(e.id),disabled:a,className:"inline-flex items-center gap-1 rounded font-medium text-amber-700 hover:text-amber-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 disabled:opacity-50",children:[t.jsx(ue,{className:"h-3 w-3","aria-hidden":!0}),a?"Requesting…":"Request this fix"]})]})]})]})]})}function Zl({since:e}){const n=Date.now()-new Date(e).getTime()>Fl;return t.jsxs("li",{"data-chat-answering":!0,className:"flex gap-2.5","aria-live":"polite",children:[t.jsx("span",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-indigo-50 text-indigo-600 ring-1 ring-inset ring-indigo-100","aria-hidden":!0,children:t.jsx(Zn,{className:"h-4 w-4"})}),t.jsxs("div",{className:"flex flex-col items-start",children:[t.jsx("div",{className:"flex items-center gap-1 rounded-2xl rounded-bl-md bg-gray-100 px-3.5 py-3","aria-hidden":!0,children:[0,150,300].map(a=>t.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-gray-400",style:{animationDelay:`${a}ms`}},a))}),t.jsx("p",{className:"mt-1 px-1 text-[11px] text-gray-400",children:n?"Still no answer after 20 minutes. The pipeline may be busy; your message is saved.":"Answering… replies take a few minutes. You can leave this page."})]})]})}const va=Object.values(Us),Na=Math.round(zn/(1024*1024)),Hl=e=>`${(e/(1024*1024)).toFixed(1)} MB`,_n=e=>[...e||[]].filter(n=>n&&n.kind!=="string");function ka(e){const[n,a]=r.useState([]),[s,l]=r.useState(null),i=r.useRef(n);i.current=n,r.useEffect(()=>()=>i.current.forEach(u=>URL.revokeObjectURL(u.preview)),[]);const o=async(u,g)=>{const h=new FormData;h.append("key",e),h.append("file",g);let $;try{const N=await fetch("/api/admin/pipeline/chat-image",{method:"POST",body:h}),b=await N.json().catch(()=>({}));if(!N.ok)throw new Error(b.error||`Could not upload (${N.status})`);$={status:"done",image:b}}catch(N){$={status:"error",error:N.message}}a(N=>N.map(b=>b.id===u.id?{...b,...$}:b))},c=u=>{const g=_n(u);if(!g.length)return;const h=[],$=Ve-i.current.length,N=[];if(g.forEach(f=>{va.includes(f.type)?f.size>zn?h.push(`“${f.name||"This image"}” is ${Hl(f.size)}; the limit is ${Na} MB.`):N.length>=$?h.push(`Up to ${Ve} screenshots per message: “${f.name||"image"}” was left out.`):N.push(f):h.push(`“${f.name||"This file"}” is not a PNG, JPG or WebP image.`)}),l(h.length?h.join(" "):null),!N.length)return;const b=N.map(f=>({id:Et(),name:f.name||"pasted image",preview:URL.createObjectURL(f),status:"uploading",file:f}));a(f=>[...f,...b.map(({file:x,...j})=>j)]),b.forEach(({file:f,...x})=>o(x,f))};return{items:n,notice:s,add:c,remove:u=>a(g=>g.filter(h=>(h.id===u&&URL.revokeObjectURL(h.preview),h.id!==u))),reset:()=>{i.current.forEach(u=>URL.revokeObjectURL(u.preview)),a([]),l(null)},onPaste:u=>{const g=_n(u.clipboardData?.files);g.length&&(u.preventDefault(),c(g))},images:n.filter(u=>u.status==="done").map(u=>u.image),uploading:n.some(u=>u.status==="uploading"),failed:n.some(u=>u.status==="error"),full:n.length>=Ve}}function _a(e){const[n,a]=r.useState(!1),s=r.useRef(0),l=i=>[...i.dataTransfer?.types||[]].includes("Files");return{dragging:n,props:{onDragEnter:i=>{l(i)&&(i.preventDefault(),s.current+=1,a(!0))},onDragOver:i=>{l(i)&&i.preventDefault()},onDragLeave:()=>{s.current=Math.max(0,s.current-1),s.current||a(!1)},onDrop:i=>{l(i)&&(i.preventDefault(),s.current=0,a(!1),e(i.dataTransfer.files))}}}}function Ca({attachments:e,label:n="Attach screenshots"}){const a=r.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button","data-chat-attach":!0,onClick:()=>a.current?.click(),disabled:e.full,"aria-label":n,title:`${n} (PNG, JPG or WebP, up to ${Na} MB, ${Ve} per message). You can also paste or drop them here.`,className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-gray-500 hover:bg-gray-100 hover:text-gray-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 disabled:opacity-40",children:t.jsx(Os,{className:"h-5 w-5","aria-hidden":!0})}),t.jsx("input",{ref:a,type:"file","data-chat-file":!0,accept:va.join(","),multiple:!0,hidden:!0,onChange:s=>{e.add(s.target.files),s.target.value=""}})]})}function $a({attachments:e}){return!e.items.length&&!e.notice?null:t.jsxs("div",{className:"mt-2 space-y-1.5",children:[e.items.length>0&&t.jsx("ul",{"data-attach-strip":!0,className:"flex flex-wrap gap-2",children:e.items.map(n=>t.jsxs("li",{"data-attachment":n.status,className:"relative h-16 w-20 overflow-hidden rounded-lg border border-gray-200 bg-gray-100",title:n.error||n.name,children:[t.jsx("img",{src:n.preview,alt:n.name,className:`h-full w-full object-cover object-left-top ${n.status==="done"?"":"opacity-50"}`}),n.status==="uploading"&&t.jsx("span",{className:"absolute inset-0 flex items-center justify-center","aria-label":"Uploading",children:t.jsx("span",{className:"h-5 w-5 animate-spin rounded-full border-2 border-gray-400 border-t-gray-900"})}),n.status==="error"&&t.jsx("span",{className:"absolute inset-x-0 bottom-0 bg-red-600/90 px-1 py-0.5 text-center text-[10px] font-medium leading-tight text-white",children:"Not sent"}),t.jsx("button",{type:"button","data-attachment-remove":!0,onClick:()=>e.remove(n.id),"aria-label":`Remove ${n.name}`,className:"absolute right-0.5 top-0.5 rounded-full bg-gray-900/75 p-0.5 text-white hover:bg-gray-900",children:t.jsx(fe,{className:"h-3.5 w-3.5","aria-hidden":!0})})]},n.id))}),e.items.filter(n=>n.status==="error").map(n=>t.jsxs("p",{role:"alert","data-attach-error":!0,className:"text-xs text-red-700",children:["“",n.name,"”: ",n.error]},n.id)),e.notice&&t.jsx("p",{role:"status","data-attach-notice":!0,className:"text-xs text-amber-800",children:e.notice})]})}function ht({ticket:e,onUpdate:n,hint:a,locked:s,onOpenImage:l,title:i,placeholder:o,flush:c=!1}){const d=r.useMemo(()=>It(e.chat),[e.chat]),m=r.useMemo(()=>ar(e.chat),[e.chat]),[p,u]=r.useState(""),g=ka(e.key),h=_a(g.add),[$,N]=r.useState(!1),[b,f]=r.useState(null),[x,j]=r.useState(null),S=!s&&Ea(e),B=async v=>{if(!x){j(v),f(null);try{n(await Sa({key:e.key,from:v}))}catch(C){f(C.message)}finally{j(null)}}},k=r.useRef(null),E=r.useRef(null),R=rt(d),F=d[d.length-1];r.useEffect(()=>{const v=k.current;v&&(v.scrollTop=v.scrollHeight)},[d.length,R]),r.useEffect(()=>{const v=E.current;v&&(v.style.height="auto",v.style.height=`${Math.min(v.scrollHeight,160)}px`)},[p]);const A=!$&&!g.uploading&&(!!p.trim()||g.images.length>0),M=async()=>{const v=p.trim();if(A){N(!0),f(null);try{const C=await fetch("/api/admin/pipeline/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key,text:v,images:g.images})}),O=await C.json().catch(()=>({}));if(!C.ok)throw new Error(O.error||`Could not send (${C.status})`);n(O),u(""),g.reset()}catch(C){f(C.message)}finally{N(!1)}}},W=v=>{v.key==="Enter"&&!v.shiftKey&&!v.nativeEvent.isComposing&&(v.preventDefault(),M())};return s&&!d.length?null:t.jsxs("section",{"data-thread":e.key,"aria-label":"Conversation about this ticket",className:c?"":"mt-5 border-t border-gray-100 pt-4",children:[t.jsx("h3",{className:c?"sr-only":"text-xs font-medium uppercase tracking-wide text-gray-400",children:i||(d.length?"Conversation":"Ask about this ticket")}),(d.length>0||R)&&t.jsxs("ol",{ref:k,"data-chat-list":!0,className:`mt-3 space-y-3 ${c?"":"max-h-[32rem] overflow-y-auto pr-1"}`,children:[m.map(v=>t.jsx(Il,{message:v,onRequestFix:S&&v.role==="vincent"&&v.kind!=="directive"?B:null,requesting:x===v.id,onOpenImage:l},v.id)),R&&!s&&t.jsx(Zl,{since:F.at})]}),!s&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-chat-composer":!0,"data-dragging":h.dragging||void 0,...h.props,className:`relative mt-3 flex items-end gap-1 rounded-xl border bg-white py-1.5 pl-1.5 pr-1.5 shadow-sm focus-within:border-indigo-500 focus-within:ring-1 focus-within:ring-indigo-500 ${h.dragging?"border-indigo-500 ring-2 ring-indigo-300":"border-gray-300"}`,children:[h.dragging&&t.jsx("p",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-xl bg-indigo-50/95 text-sm font-medium text-indigo-800",children:"Drop the screenshots to attach them"}),t.jsx(Ca,{attachments:g}),t.jsxs("label",{htmlFor:`chat-${e.key}`,className:"sr-only",children:["Message about ",e.key]}),t.jsx("textarea",{ref:E,id:`chat-${e.key}`,"data-chat-input":!0,rows:1,value:p,onChange:v=>u(v.target.value),onKeyDown:W,onPaste:g.onPaste,placeholder:d.length?"Reply…":o||"Ask anything about this ticket…",className:"block min-h-[32px] flex-1 resize-none border-0 bg-transparent p-0 py-1.5 text-sm leading-5 text-gray-900 placeholder:text-gray-400 focus:outline-none focus:ring-0"}),t.jsx("button",{type:"button","data-chat-send":!0,onClick:M,disabled:!A,"aria-label":"Send message",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-900 text-white hover:bg-gray-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 focus-visible:ring-offset-2 disabled:bg-gray-200 disabled:text-gray-400",children:t.jsx(ns,{className:"h-4 w-4","aria-hidden":!0})})]}),t.jsx($a,{attachments:g}),b&&t.jsx("p",{role:"alert",className:"mt-2 text-sm text-red-700",children:b}),t.jsxs("p",{className:"mt-1.5 text-xs text-gray-400",children:[a," Enter sends, Shift+Enter adds a line. Paste or drop screenshots to attach them."]}),S&&t.jsx(Ra,{ticket:e,onUpdate:n})]})]})}function Ue({ticket:e,onUpdate:n,manual:a=!1,inModal:s=!1}){pt(e,n);const l=xt(e),i=a?[e.key]:e.plan_thread?.keys||[e.key],o=ia(e.chat);return t.jsxs("div",{"data-plan-thread":e.key,"data-plan-keys":i.join(","),children:[t.jsx(ht,{ticket:e,onUpdate:n,onOpenImage:l.openShot,flush:s,title:s?"Conversation with the pipeline":a?"Plan a cheaper test":`Plan testing: ${i.join(" + ")}`,placeholder:a?"How should we re-test this one without blowing the budget?":"Ask why these go together, add or drop one, or say “agreed”…",hint:s?void 0:a?"The pipeline proposes a cheaper path; when you agree it writes the strategy into the ticket and puts it back in the queue.":"The pipeline debates the plan; when you agree it merges the agreed tickets and writes the strategy into each one."}),!s&&t.jsx(Kr,{message:o}),l.viewer]})}const gt={queued:"Waiting for a free fix slot.",fixing:"The fix is being written.",checking:"The hostile check is re-testing it."};function Ea(e){return!["merge","decision"].includes(e.queue)||e.cancel&&!e.cancel.ack_error||e.queue==="decision"&&e.answer&&!e.answer.ack_error?!1:!me(e)}async function Sa(e){const n=await fetch("/api/admin/pipeline/fix-request",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),a=await n.json().catch(()=>({}));if(!n.ok)throw new Error(a.error||`Could not request the fix (${n.status})`);return a}const Et=()=>typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,12)}`;function Ra({ticket:e,onUpdate:n,startOpen:a=!1,onDone:s}){const[l,i]=r.useState(a),[o,c]=r.useState(""),[d,m]=r.useState(!1),[p,u]=r.useState(null),g=r.useRef(a?Et():null),h=ka(e.key),$=_a(h.add),N=()=>{g.current=Et(),i(!0),u(null)},b=async()=>{const f=o.trim();if(!(!f||d||h.uploading)){m(!0),u(null);try{n(await Sa({key:e.key,request_id:g.current,text:f,images:h.images})),c(""),h.reset(),i(!1),s?.()}catch(x){u(x.message)}finally{m(!1)}}};return l?t.jsxs("div",{"data-fix-box":e.key,...$.props,className:`mt-3 rounded-xl border bg-amber-50/60 p-3 ${$.dragging?"border-amber-500 ring-2 ring-amber-300":"border-amber-300"}`,children:[t.jsx("label",{htmlFor:`fix-${e.key}`,className:"text-sm font-medium text-amber-950",children:"Request a fix"}),t.jsxs("p",{className:"mt-0.5 text-xs text-amber-900/80",children:["Not chat: this becomes the spec of a new fix round on ",e.key,e.queue==="merge"?", and the PRs leave Ready to merge until it passes the hostile check again.":", and it answers this decision."]}),t.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[t.jsx("input",{id:`fix-${e.key}`,"data-fix-input":!0,autoFocus:!0,value:o,maxLength:2e3,onChange:f=>c(f.target.value),onPaste:h.onPaste,onKeyDown:f=>{f.key==="Enter"&&!f.nativeEvent.isComposing&&(f.preventDefault(),b()),f.key==="Escape"&&!d&&i(!1)},placeholder:"What should change?",className:"block min-h-[40px] w-full min-w-0 flex-1 rounded-lg border border-amber-300 bg-white px-3 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-amber-500 focus:outline-none focus:ring-1 focus:ring-amber-500"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(Ca,{attachments:h,label:"Attach screenshots to the fix request"}),t.jsx("button",{type:"button",onClick:()=>{h.reset(),i(!1)},disabled:d,className:"inline-flex min-h-[40px] items-center rounded-lg px-3 text-sm font-medium text-gray-700 hover:bg-white",children:"Never mind"}),t.jsx("button",{type:"button","data-fix-submit":!0,onClick:b,disabled:d||h.uploading||!o.trim(),className:"inline-flex min-h-[40px] items-center rounded-lg bg-amber-600 px-4 text-sm font-semibold text-white shadow-sm hover:bg-amber-700 focus:outline-none focus:ring-2 focus:ring-amber-600 focus:ring-offset-2 disabled:opacity-50",children:d?"Requesting…":"Request fix"})]})]}),t.jsx($a,{attachments:h}),p&&t.jsx("p",{role:"alert",className:"mt-2 text-sm text-red-700",children:p})]}):t.jsxs("button",{type:"button","data-request-fix":e.key,onClick:N,className:"mt-3 inline-flex min-h-[36px] items-center gap-1.5 rounded-lg border border-amber-300 bg-white px-3 text-sm font-medium text-amber-800 shadow-sm hover:bg-amber-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-amber-500",children:[t.jsx(ue,{className:"h-4 w-4","aria-hidden":!0}),"Request a fix"]})}function Ma({ticket:e}){const n=me(e),a=He(e.chat);if(!n)return a?.ack_error?t.jsxs("p",{role:"alert","data-fix-status":"error",className:"mt-4 rounded-lg bg-red-50 px-3 py-2.5 text-sm text-red-900",children:["The pipeline could not file your fix request: ",a.ack_error]}):null;const s=e.fix_round?.request_id===n.id?e.fix_round.stage:null;return t.jsxs("div",{"data-fix-status":n.acked_at?"building":"sent","data-fix-stage":s||void 0,className:"mt-4 flex items-start gap-2 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2.5 text-sm text-amber-950",children:[t.jsx(ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600","aria-hidden":!0}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("p",{children:[t.jsx("span",{className:"font-semibold",children:n.acked_at?"Fix in progress.":"Fix requested."})," ",n.acked_at?gt[s]||"Filed on the ticket as your directive; a new fix round starts on the next pipeline run.":"The pipeline files it on the ticket within a few minutes.",t.jsxs("span",{className:"text-amber-800/70",children:[" · ",le(n.at)]})]}),t.jsxs("p",{className:"mt-0.5 truncate text-amber-900/80",title:n.text,children:["“",n.text,"”"]})]})]})}function pt(e,n){const a=rt(It(e.chat))||!!(e.cancel&&!e.cancel.acked_at)||!!me(e);r.useEffect(()=>{if(!a)return;let s=!1;const l=async()=>{if(document.visibilityState==="visible")try{const o=await fetch(`/api/admin/pipeline/chat?key=${encodeURIComponent(e.key)}`,{cache:"no-store"});o.ok&&!s&&n(await o.json())}catch{}},i=setInterval(l,Ll);return window.addEventListener("focus",l),document.addEventListener("visibilitychange",l),()=>{s=!0,clearInterval(i),window.removeEventListener("focus",l),document.removeEventListener("visibilitychange",l)}},[a,e.key,n])}const St={"waiting-response":{icon:Fe,cls:"bg-sky-50 text-sky-800 ring-sky-300",hint:"You wait for someone to answer."},"wait-conflict-fix":{icon:os,cls:"bg-orange-50 text-orange-800 ring-orange-300",hint:"Merge after the conflict is fixed."},warning:{icon:ae,cls:"bg-rose-50 text-rose-800 ring-rose-300",hint:"Something to be careful about."},priority:{icon:Rt,cls:"bg-violet-50 text-violet-800 ring-violet-300",hint:"Handle this one first."},later:{icon:Mt,cls:"bg-slate-100 text-slate-700 ring-slate-300",hint:"Parked: the pipeline starts no automatic round on it until you remove this flag."},"watch-after-ship":{icon:Ns,cls:"bg-emerald-50 text-emerald-800 ring-emerald-300",hint:"Check it again once it is live."}},Cn=["bg-teal-50 text-teal-800 ring-teal-300","bg-fuchsia-50 text-fuchsia-800 ring-fuchsia-300","bg-lime-50 text-lime-800 ring-lime-400","bg-indigo-50 text-indigo-800 ring-indigo-300","bg-cyan-50 text-cyan-800 ring-cyan-300"];function Zt(e){if(St[e])return St[e];let n=0;for(const a of e||"")n=n*31+a.charCodeAt(0)>>>0;return{icon:Ws,cls:Cn[n%Cn.length],hint:"Your own flag."}}async function Wl(e){const n=await fetch("/api/admin/pipeline/flags",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),a=await n.json().catch(()=>({}));if(!n.ok)throw new Error(a.error||`Could not save the flag (${n.status})`);return a}function Ta({flag:e,onRemove:n,busy:a,size:s="md"}){const{icon:l,cls:i,hint:o}=Zt(e.id);return t.jsxs("span",{"data-flag":e.id,title:o,className:`inline-flex items-center gap-1 rounded-full font-medium ring-1 ring-inset ${i} ${s==="sm"?"py-0.5 pl-1.5 pr-1 text-[11px]":"py-0.5 pl-2 pr-1 text-xs"}`,children:[t.jsx(l,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),t.jsx("span",{className:"max-w-[14rem] truncate",children:e.label}),n?t.jsx("button",{type:"button","data-flag-remove":e.id,onClick:()=>n(e.id),disabled:a,"aria-label":`Remove the flag ${e.label}`,className:"rounded-full p-0.5 opacity-60 hover:bg-black/10 hover:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-current disabled:opacity-30",children:t.jsx(fe,{className:"h-3 w-3","aria-hidden":!0})}):t.jsx("span",{className:"w-1"})]})}function Aa({ticket:e}){const n=[];return e.hold&&!me(e)&&n.push({id:"hold",label:"On hold",title:`Set by the pipeline: ${e.hold}`}),n.map(a=>t.jsxs("span",{"data-auto-chip":a.id,title:a.title,className:"inline-flex items-center gap-1 rounded-full border border-dashed border-gray-300 bg-white px-2 py-0.5 text-[11px] font-medium text-gray-500",children:[t.jsx($s,{className:"h-3 w-3","aria-hidden":!0}),a.label]},a.id))}function zl({ticket:e,onAdd:n,busy:a}){const[s,l]=r.useState(!1),[i,o]=r.useState(""),c=r.useRef(null),d=new Set((e.flags||[]).map(u=>u.id)),m=Gn.filter(u=>!d.has(u.id));r.useEffect(()=>{if(!s)return;const u=h=>{c.current&&!c.current.contains(h.target)&&l(!1)},g=h=>{h.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",u),window.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",u),window.removeEventListener("keydown",g)}},[s]);const p=async u=>{await n(u)&&(l(!1),o(""))};return t.jsxs("div",{ref:c,className:"relative",children:[t.jsxs("button",{type:"button","data-flag-add":e.key,"aria-expanded":s,onClick:()=>l(u=>!u),className:"inline-flex items-center gap-0.5 rounded-full border border-gray-300 bg-white py-0.5 pl-1.5 pr-2 text-xs font-medium text-gray-600 hover:border-gray-400 hover:text-gray-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500",children:[t.jsx(Fs,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Flag"]}),s&&t.jsxs("div",{"data-flag-menu":e.key,className:"absolute left-0 top-full z-30 mt-1.5 w-64 rounded-xl border border-gray-200 bg-white p-1.5 shadow-xl",children:[m.length>0&&t.jsx("ul",{className:"space-y-0.5",children:m.map(u=>{const{icon:g,cls:h,hint:$}=Zt(u.id);return t.jsx("li",{children:t.jsxs("button",{type:"button","data-flag-option":u.id,disabled:a,onClick:()=>p({id:u.id}),title:$,className:"flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-sm text-gray-800 hover:bg-gray-50 disabled:opacity-50",children:[t.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-full ring-1 ring-inset ${h}`,children:t.jsx(g,{className:"h-3.5 w-3.5","aria-hidden":!0})}),u.label]})},u.id)})}),t.jsxs("form",{className:`flex gap-1.5 ${m.length?"mt-1.5 border-t border-gray-100 pt-2":""}`,onSubmit:u=>{u.preventDefault(),i.trim()&&p({label:i})},children:[t.jsx("label",{htmlFor:`flag-custom-${e.key}`,className:"sr-only",children:"Custom flag"}),t.jsx("input",{id:`flag-custom-${e.key}`,"data-flag-custom":!0,value:i,maxLength:Qs,onChange:u=>o(u.target.value),placeholder:"+ custom flag",className:"block min-h-[34px] w-full min-w-0 flex-1 rounded-lg border border-gray-300 px-2.5 text-sm text-gray-900 placeholder:text-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"}),t.jsx("button",{type:"submit","data-flag-custom-add":!0,disabled:a||!i.trim(),className:"shrink-0 rounded-lg bg-gray-900 px-3 text-sm font-medium text-white hover:bg-gray-700 disabled:opacity-40",children:"Add"})]})]})]})}function ft({ticket:e,onUpdate:n,size:a}){const[s,l]=r.useState(!1),[i,o]=r.useState(null),c=async d=>{l(!0),o(null);try{return n(await Wl({key:e.key,...d})),!0}catch(m){return o(m.message),!1}finally{l(!1)}};return t.jsxs("div",{"data-flags":e.key,className:"flex flex-wrap items-center gap-1.5",children:[(e.flags||[]).map(d=>t.jsx(Ta,{flag:d,busy:s,size:a,onRemove:m=>c({remove:m})},d.id)),t.jsx(Aa,{ticket:e}),t.jsx(zl,{ticket:e,busy:s,onAdd:d=>c({add:d})}),i&&t.jsx("span",{role:"alert",className:"text-xs text-red-700",children:i})]})}function Gl(e){const n=(e||"").split(",").map(a=>a.trim()).filter(Boolean);return n.includes("none")?{flags:[],only:"none"}:n.includes("any")?{flags:[],only:"flagged"}:{flags:n,only:null}}function Xl(e){return e.only==="none"?"none":e.only==="flagged"?"any":e.flags.join(",")}const Pa=e=>!!(e.only||e.flags.length);function $n({tickets:e,filter:n,onChange:a}){const s=tr(e),l=[...new Map(e.flatMap(d=>d.flags||[]).filter(d=>!St[d.id]).map(d=>[d.id,d])).values()].sort((d,m)=>d.label.localeCompare(m.label)),i=d=>{const m=n.flags.includes(d);a({only:null,flags:m?n.flags.filter(p=>p!==d):[...n.flags,d]})},o=d=>`inline-flex min-h-[30px] items-center gap-1 rounded-full px-2.5 text-xs font-medium ring-1 ring-inset transition-colors ${d?"bg-gray-900 text-white ring-gray-900":"bg-white text-gray-700 ring-gray-300 hover:ring-gray-400"}`,c=(d,m)=>t.jsx("span",{className:`tabular-nums ${m?"text-white/70":"text-gray-400"}`,children:d||0});return t.jsxs("div",{"data-flag-filter":!0,className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5",children:[t.jsxs("span",{className:"mr-1 inline-flex items-center gap-1 text-xs font-medium text-gray-500",children:[t.jsx(_s,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Flags"]}),[["flagged","Flagged"],["none","No flags"]].map(([d,m])=>{const p=n.only===d;return t.jsxs("button",{type:"button","data-filter-only":d,"aria-pressed":p,className:o(p),onClick:()=>a({flags:[],only:p?null:d}),children:[m," ",c(s[d],p)]},d)}),t.jsx("span",{className:"mx-1 h-4 w-px bg-gray-300","aria-hidden":!0}),[...Gn,...l].map(d=>{const m=n.flags.includes(d.id),{icon:p,cls:u}=Zt(d.id);return t.jsxs("button",{type:"button","data-filter-flag":d.id,"aria-pressed":m,onClick:()=>i(d.id),className:m?o(!0):`inline-flex min-h-[30px] items-center gap-1 rounded-full px-2.5 text-xs font-medium ring-1 ring-inset ${u} ${s[d.id]?"":"opacity-50"}`,children:[t.jsx(p,{className:"h-3.5 w-3.5","aria-hidden":!0}),d.label," ",c(s[d.id],m)]},d.id)}),Pa(n)&&t.jsx("button",{type:"button","data-filter-clear":!0,onClick:()=>a({flags:[],only:null}),className:"ml-1 text-xs font-medium text-gray-500 underline underline-offset-2 hover:text-gray-900",children:"Clear"})]})}function Jl({ticket:e,onClose:n,onDone:a}){const[s,l]=r.useState(""),[i,o]=r.useState(!1),[c,d]=r.useState(null),m=(e.prs||[]).filter(u=>!u.merged_at);r.useEffect(()=>{const u=g=>{g.key==="Escape"&&!i&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n,i]);const p=async()=>{o(!0),d(null);try{const u=await fetch("/api/admin/pipeline/cancel",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key,reason:s})}),g=await u.json().catch(()=>({}));if(!u.ok)throw new Error(g.error||`Could not cancel (${u.status})`);a(g.ticket),n()}catch(u){d(u.message),o(!1)}};return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-gray-950/50 p-4",onClick:()=>!i&&n(),children:t.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":`cancel-title-${e.key}`,"data-cancel-dialog":e.key,onClick:u=>u.stopPropagation(),className:"w-full max-w-md rounded-xl bg-white p-5 shadow-2xl",children:[t.jsxs("h2",{id:`cancel-title-${e.key}`,className:"text-base font-semibold text-gray-900",children:["Cancel ",e.key,"?"]}),t.jsxs("p",{className:"mt-2 text-sm leading-relaxed text-gray-700",children:["This closes the ticket and its PRs without merging.",m.length>0&&t.jsxs(t.Fragment,{children:[" PRs closed: ",m.map(te).join(", "),"."]})]}),t.jsxs("label",{htmlFor:`cancel-reason-${e.key}`,className:"mt-4 block text-sm font-medium text-gray-800",children:["Why? ",t.jsx("span",{className:"font-normal text-gray-400",children:"(optional)"})]}),t.jsx("textarea",{id:`cancel-reason-${e.key}`,"data-cancel-reason":!0,autoFocus:!0,rows:3,value:s,onChange:u=>l(u.target.value),placeholder:"For example: not needed after all, the behaviour is fine.",className:"mt-1.5 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-red-500 focus:outline-none focus:ring-1 focus:ring-red-500"}),c&&t.jsx("p",{role:"alert",className:"mt-2 text-sm text-red-700",children:c}),t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:n,disabled:i,className:"inline-flex min-h-[40px] items-center rounded-lg px-3 text-sm font-medium text-gray-700 hover:bg-gray-100",children:"Keep ticket"}),t.jsx("button",{type:"button","data-cancel-confirm":!0,onClick:p,disabled:i,className:"inline-flex min-h-[40px] items-center rounded-lg bg-red-600 px-4 text-sm font-semibold text-white shadow-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-600 focus:ring-offset-2 disabled:opacity-50",children:i?"Cancelling…":"Cancel ticket"})]})]})})}function Vl({ticket:e,onUpdate:n}){const[a,s]=r.useState(!1),l=r.useCallback(()=>s(!1),[]);return e.cancel&&!e.cancel.ack_error?null:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button","data-cancel-ticket":e.key,onClick:()=>s(!0),className:"ml-auto shrink-0 rounded px-1.5 py-0.5 text-xs font-medium text-red-600 hover:bg-red-50 hover:text-red-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-red-500",children:"Cancel ticket"}),a&&t.jsx(Jl,{ticket:e,onClose:l,onDone:n})]})}function Ba({cancel:e}){return e?e.ack_error?t.jsxs("p",{role:"alert","data-cancel-status":"error",className:"mt-4 rounded-lg bg-red-50 px-3 py-2.5 text-sm text-red-900",children:["The pipeline could not cancel this ticket: ",e.ack_error]}):t.jsxs("div",{"data-cancel-status":e.acked_at?"done":"pending",className:"mt-4 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2.5 text-sm text-gray-700",children:[t.jsxs("p",{children:[t.jsx("span",{className:"font-semibold text-gray-900",children:e.acked_at?"Cancelled.":"Cancel requested."})," ",e.acked_at?"The ticket and its PRs are closed without merging. It moves to Shipped as cancelled.":"The pipeline closes the ticket and its PRs within a few minutes.",t.jsxs("span",{className:"text-gray-400",children:[" · ",le(e.requested_at)]})]}),e.reason&&t.jsxs("p",{className:"mt-1 text-gray-500",children:["Reason: ",e.reason]})]}):null}const Pe="inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-xs font-semibold ring-1 ring-inset";function Yl({ticket:e}){const n=me(e),a=n?null:At(e);if(n){const s=e.fix_round?.request_id===n.id?gt[e.fix_round.stage]:null;return t.jsxs("div",{"data-fix-badge":"in-progress",role:"status",className:"mt-2.5 flex flex-wrap items-center gap-1.5",children:[t.jsxs("span",{className:`${Pe} bg-amber-50 text-amber-900 ring-amber-300`,children:[t.jsx(ue,{className:"h-3.5 w-3.5 text-amber-600","aria-hidden":!0}),n.acked_at?`Fix in progress, requested ${le(n.at)}`:`Fix requested ${le(n.at)}`]}),e.queue==="merge"&&t.jsxs("span",{"data-fix-badge-hold":!0,className:`${Pe} bg-red-50 text-red-800 ring-red-200`,children:[t.jsx(ae,{className:"h-3.5 w-3.5 text-red-600","aria-hidden":!0}),"Do not merge yet"]}),t.jsx("span",{className:"text-xs text-gray-500",children:n.acked_at?s:"Waiting for the pipeline to pick it up."})]})}return a?.kind==="failed"?t.jsxs("div",{"data-fix-badge":"failed",role:"status",className:"mt-2.5 flex flex-wrap items-center gap-1.5",children:[t.jsxs("span",{className:`${Pe} bg-red-50 text-red-800 ring-red-200`,children:[t.jsx(ae,{className:"h-3.5 w-3.5 text-red-600","aria-hidden":!0}),"Fix failed, needs you"]}),t.jsx("span",{className:"text-xs text-gray-500",children:le(a.message.at)})]}):a?.kind==="delivered"&&e.queue==="merge"&&!e.hold?t.jsxs("div",{"data-fix-badge":"delivered",role:"status",className:"mt-2.5 flex flex-wrap items-center gap-1.5",children:[t.jsxs("span",{className:`${Pe} bg-emerald-50 text-emerald-800 ring-emerald-200`,children:[t.jsx(Ze,{className:"h-3.5 w-3.5 text-emerald-600","aria-hidden":!0}),"Ready to merge"]}),t.jsxs("span",{className:"text-xs text-gray-500",children:["Fix delivered ",le(a.message.at)]})]}):null}function Oa({ticket:e,onUpdate:n}){return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ut,{ticketKey:e.key}),t.jsx(mt,{repo:e.repo}),t.jsx("p",{className:"min-w-0 flex-1 truncate text-xs text-gray-400",title:e.title,children:e.title}),t.jsx(Se,{ticket:e}),t.jsx(Vl,{ticket:e,onUpdate:n})]}),t.jsx(Yl,{ticket:e}),t.jsx("div",{className:"mt-2.5",children:t.jsx(ft,{ticket:e,onUpdate:n})})]})}function En({ticket:e,proofSize:n,onUpdate:a}){pt(e,a);const s=xt(e),l=!!(e.cancel&&!e.cancel.ack_error),i=!!me(e);return t.jsxs("article",{"data-ticket-card":e.key,className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm sm:p-6",children:[t.jsx(Oa,{ticket:e,onUpdate:a}),t.jsxs("dl",{className:"mt-4 space-y-3 xl:grid xl:grid-cols-3 xl:gap-8 xl:space-y-0",children:[t.jsx(Oe,{label:"What improves",children:e.plain?.improves}),t.jsx(Oe,{label:"Problem it solves",children:e.plain?.problem}),t.jsx(Oe,{label:"How it solves it",children:e.plain?.how})]}),t.jsx(ya,{evidence:e.evidence||[],size:n,onOpen:s.openProof}),t.jsx(Bl,{ticket:e}),t.jsx(Ba,{cancel:e.cancel}),t.jsx(Ma,{ticket:e}),!l&&t.jsxs("div",{className:"mt-4 space-y-3 border-t border-gray-100 pt-4",children:[i&&t.jsxs("div",{"data-hold":"fix-request",role:"alert",className:"flex items-start gap-2 rounded-lg border border-red-200 bg-red-50 px-3 py-2.5 text-sm text-red-900",children:[t.jsx(ae,{className:"mt-0.5 h-4 w-4 shrink-0 text-red-600","aria-hidden":!0}),t.jsxs("p",{children:[t.jsx("span",{className:"font-semibold",children:"Do not merge yet."})," You requested a fix: these PRs change in this round and are re-checked before they are ready again."]})]}),e.hold&&!i&&t.jsxs("div",{"data-hold":!0,role:"alert",className:"flex items-start gap-2 rounded-lg border border-red-200 bg-red-50 px-3 py-2.5 text-sm text-red-900",children:[t.jsx(ae,{className:"mt-0.5 h-4 w-4 shrink-0 text-red-600","aria-hidden":!0}),t.jsxs("p",{children:[t.jsx("span",{className:"font-semibold",children:"On hold, do not merge."})," ",e.hold]})]}),t.jsx(Ol,{ticket:e,held:i})]}),t.jsx(ht,{ticket:e,onUpdate:a,locked:l,onOpenImage:s.openShot,hint:"Chat is for questions. It never merges or changes the fix: use Request a fix for that."}),s.viewer]})}const La=e=>(/^\s*([A-Z])\b/.exec(e?.recommendation||"")||[])[1]||null;function Fa({answer:e}){if(!e)return null;const n=[e.option&&`Option ${e.option}`,e.text&&`"${e.text}"`].filter(Boolean).join(", ");return e.acked_at&&e.ack_error?t.jsxs("p",{role:"alert","data-answer-status":"error",className:"rounded-lg bg-red-50 px-3 py-2.5 text-sm text-red-900",children:["The pipeline could not use your answer: ",e.ack_error]}):t.jsxs("div",{"data-answer-status":e.acked_at?"posted":"sent",className:"flex items-start gap-2 rounded-lg bg-emerald-50 px-3 py-2.5 text-sm text-emerald-900",children:[t.jsx(Ze,{className:"mt-0.5 h-4 w-4 shrink-0 text-emerald-600","aria-hidden":!0}),t.jsxs("p",{children:["You answered ",n,t.jsxs("span",{className:"opacity-70",children:[" · ",at(e.answered_at),". "]}),e.acked_at?"Posted on the ticket. The fix resumes on the next pipeline run.":"The pipeline picks it up within 15 minutes."]})]})}function Sn({ticket:e,onAnswered:n,onUpdate:a,proofSize:s}){pt(e,a);const l=xt(e),i=!!(e.cancel&&!e.cancel.ack_error)||!!me(e),o=e.decision||{},c=La(o),d=!!(e.answer?.acked_at&&!e.answer.ack_error),[m,p]=r.useState(null),[u,g]=r.useState(""),[h,$]=r.useState(!1),[N,b]=r.useState(null),[f,x]=r.useState(!1),[j,S]=r.useState(!e.answer),B=async()=>{$(!0),b(null);try{const k=await fetch("/api/admin/pipeline/answer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key,option:m,text:u})}),E=await k.json().catch(()=>({}));if(!k.ok)throw new Error(E.error||`Could not save (${k.status})`);n(E.ticket),S(!1)}catch(k){b(k.message)}finally{$(!1)}};return t.jsxs("article",{"data-ticket-card":e.key,className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm sm:p-6",children:[t.jsx(Oa,{ticket:e,onUpdate:a}),t.jsx("p",{"data-question":!0,className:"mt-3 text-base font-semibold leading-snug text-gray-900",children:o.question||"This ticket needs your decision. The question is on the Jira ticket."}),o.context?.length>0&&t.jsxs("div",{className:"mt-2",children:[t.jsxs("button",{type:"button","aria-expanded":f,onClick:()=>x(k=>!k),className:"inline-flex items-center gap-0.5 text-xs font-medium text-indigo-600 hover:text-indigo-800",children:["Why you are asked",t.jsx(pe,{className:`h-4 w-4 transition-transform ${f?"rotate-90":""}`,"aria-hidden":!0})]}),f&&t.jsx("ul",{"data-context":!0,className:"mt-2 list-disc space-y-1 rounded-lg bg-gray-50 py-2.5 pl-7 pr-3 text-sm leading-relaxed text-gray-700 [overflow-wrap:anywhere]",children:o.context.map((k,E)=>t.jsx("li",{children:k},E))})]}),t.jsx(ya,{evidence:e.evidence||[],size:s,onOpen:l.openProof}),t.jsx(Ba,{cancel:e.cancel}),t.jsx(Ma,{ticket:e}),!i&&e.answer&&!j&&t.jsxs("div",{className:"mt-4 space-y-2",children:[t.jsx(Fa,{answer:e.answer}),!d&&t.jsx("button",{type:"button",onClick:()=>S(!0),className:"text-xs font-medium text-gray-500 underline underline-offset-2 hover:text-gray-800",children:"Change my answer"})]}),!i&&j&&!d&&t.jsxs("div",{className:"mt-4",children:[o.options?.length>0&&t.jsx("div",{role:"radiogroup","aria-label":"Options",className:"space-y-2",children:o.options.map(k=>{const E=m===k.letter;return t.jsxs("button",{type:"button",role:"radio","aria-checked":E,"data-option":k.letter,onClick:()=>p(E?null:k.letter),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 ${E?"border-indigo-500 bg-indigo-50/60 ring-1 ring-indigo-500":"border-gray-200 hover:border-gray-300 hover:bg-gray-50"}`,children:[t.jsx("span",{className:`mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-xs font-bold ${E?"bg-indigo-600 text-white":"bg-gray-100 text-gray-600"}`,children:k.letter}),t.jsxs("span",{className:"min-w-0 text-sm leading-relaxed",children:[t.jsx("span",{className:"font-semibold text-gray-900",children:k.label}),k.letter===c&&t.jsx("span",{className:"ml-2 rounded-full bg-emerald-50 px-1.5 py-0.5 text-[11px] font-medium text-emerald-700 ring-1 ring-inset ring-emerald-600/20",children:"Recommended"}),k.text&&t.jsx("span",{className:"block text-gray-600",children:k.text})]})]},k.letter)})}),o.recommendation&&c&&t.jsx("p",{className:"mt-2 text-xs leading-relaxed text-gray-500",children:o.recommendation.replace(/^\s*[A-Z]\b[\s:.,-]*/,"Why recommended: ")}),t.jsx("label",{htmlFor:`answer-${e.key}`,className:"mt-4 block text-sm font-medium text-gray-800",children:o.options?.length?"Anything to add? (optional)":"Your answer"}),t.jsx("textarea",{id:`answer-${e.key}`,value:u,onChange:k=>g(k.target.value),rows:3,className:"mt-1.5 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm placeholder:text-gray-400 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500",placeholder:"Your own instruction, in plain words."}),N&&t.jsx("p",{role:"alert",className:"mt-2 text-sm text-red-700",children:N}),t.jsxs("div",{className:"mt-3 flex items-center justify-end gap-2",children:[e.answer&&t.jsx("button",{type:"button",onClick:()=>S(!1),className:"inline-flex min-h-[40px] items-center px-2 text-sm text-gray-500 hover:text-gray-800",children:"Cancel"}),t.jsx("button",{type:"button","data-send-answer":!0,disabled:h||!m&&!u.trim(),onClick:B,className:"inline-flex min-h-[40px] items-center rounded-lg bg-gray-900 px-5 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 disabled:opacity-40",children:h?"Sending…":"Send answer"})]})]}),t.jsx(ht,{ticket:e,onUpdate:a,locked:!!(e.cancel&&!e.cancel.ack_error),onOpenImage:l.openShot,hint:"Chat is for questions. It never decides: send your decision with the form above, or use Request a fix."}),l.viewer]})}function Rn({tickets:e,onUpdate:n}){return e.length?t.jsxs("section",{"data-building":!0,"aria-label":"Fix rounds building",className:"pb-2",children:[t.jsxs("h2",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:["Fix rounds building ",t.jsx("span",{className:"normal-case tracking-normal",children:"· back here once re-checked"})]}),t.jsx("ul",{className:"mt-2 divide-y divide-amber-100 rounded-xl border border-amber-200 bg-white shadow-sm",children:e.map(a=>{const s=He(a.chat);return t.jsxs("li",{"data-building-row":a.key,className:"flex flex-col gap-1 px-4 py-3 sm:px-5",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(ut,{ticketKey:a.key}),t.jsx(mt,{repo:a.repo}),t.jsxs("span",{"data-fix-stage":a.fix_round?.stage,className:"inline-flex items-center gap-1 rounded-full bg-amber-50 px-2 py-0.5 text-[11px] font-medium text-amber-800 ring-1 ring-inset ring-amber-300",children:[t.jsx(ue,{className:"h-3 w-3","aria-hidden":!0}),s?`Fix in progress, requested ${le(s.at)}`:"Fix in progress"]}),t.jsx("span",{className:"text-xs text-gray-500",children:gt[a.fix_round?.stage]||""}),t.jsx(Se,{ticket:a,className:"ml-auto"})]}),t.jsx("p",{className:"text-sm font-medium text-gray-900",children:a.plain?.improves||a.title}),s&&t.jsxs("p",{className:"truncate text-xs text-amber-900/80",title:s.text,children:["Your request: “",s.text,"”"]}),t.jsx("div",{className:"mt-1",children:t.jsx(ft,{ticket:a,onUpdate:n,size:"sm"})})]},a.key)})})]}):null}function Mn({tickets:e,onUpdate:n,empty:a}){return e.length?t.jsx("ul",{className:"divide-y divide-gray-100 rounded-xl border border-gray-200 bg-white shadow-sm",children:e.map(s=>{const l=s.queue==="cancelled";return t.jsxs("li",{"data-shipped":s.key,"data-cancelled":l||void 0,className:`flex flex-col gap-1 px-4 py-3 first:rounded-t-xl last:rounded-b-xl sm:flex-row sm:items-center sm:gap-4 sm:px-5 ${l?"bg-gray-50/70":""}`,children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:`text-sm font-medium ${l?"text-gray-500":"text-gray-900"}`,children:[l&&t.jsx("span",{className:"mr-2 rounded-full bg-gray-200 px-1.5 py-0.5 align-[1px] text-[11px] font-medium text-gray-600",children:"Cancelled"}),s.plain?.improves||s.title]}),l&&s.cancel?.reason&&t.jsxs("p",{className:"mt-0.5 text-xs text-gray-500",children:["Reason: ",s.cancel.reason]}),t.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-gray-500",children:[t.jsx(ut,{ticketKey:s.key}),t.jsx(mt,{repo:s.repo}),lt(s.prs).map(({pr:i})=>t.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:l?"text-gray-500 hover:text-gray-800":"text-indigo-700 hover:text-indigo-900",children:[te(i),l&&" (closed)"]},`${i.repo}#${i.number}`))]}),t.jsx("div",{className:"mt-1.5",children:t.jsx(ft,{ticket:s,onUpdate:n,size:"sm"})})]}),t.jsx("p",{className:"shrink-0 text-xs tabular-nums text-gray-500",children:l?`Cancelled ${at(s.cancelled_at)}`:`Merged ${at(s.merged_at)}`})]},s.key)})}):a||t.jsx(de,{children:"No fix merged on GitHub or cancelled in the last 7 days."})}const Kl=e=>`$${e.toFixed(2)}`;function Tn({tickets:e,onUpdate:n,empty:a}){return e.length?t.jsx("div",{className:"grid grid-cols-1 items-start gap-4 2xl:grid-cols-2",children:e.map(s=>{const l=s.manual||{};return t.jsxs("article",{"data-manual-card":s.key,className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm sm:p-6",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(ut,{ticketKey:s.key}),t.jsx(mt,{repo:s.repo}),t.jsxs("span",{className:`${Pe} bg-red-50 text-red-800 ring-red-200`,children:[t.jsx(Mt,{className:"h-3.5 w-3.5 text-red-600","aria-hidden":!0}),"Stopped over budget"]}),t.jsx("span",{className:"text-xs text-gray-500",children:at(l.stopped_at)}),s.jira_status&&t.jsxs("span",{className:"ml-auto text-xs text-gray-400",children:["Jira: ",s.jira_status]})]}),t.jsx("p",{className:"mt-3 text-[15px] font-medium leading-relaxed text-gray-900",children:s.plain?.improves||s.title||s.plain?.problem}),t.jsxs("dl",{className:"mt-4 space-y-3",children:[t.jsxs(Oe,{label:"Automation spent",children:[t.jsx("span",{"data-manual-spend":!0,className:"font-semibold tabular-nums",children:l.spend_usd==null?"not metered":Kl(l.spend_usd)}),t.jsx("span",{className:"ml-2 text-sm text-gray-500",children:[l.leg_kind&&`on its ${l.leg_kind} round`,l.spend_note].filter(Boolean).join(", ")})]}),t.jsx(Oe,{label:"Why it stopped",children:t.jsx("span",{"data-manual-reason":!0,className:"block whitespace-pre-line border-l-2 border-red-200 pl-3 text-gray-800 [overflow-wrap:anywhere]",children:l.reason})})]}),t.jsxs("div",{"data-manual-links":!0,className:"mt-4 flex flex-wrap items-center gap-x-3 gap-y-1 border-t border-gray-100 pt-3 text-sm",children:[t.jsxs("a",{href:ba+s.key,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 font-medium text-indigo-700 hover:text-indigo-900",children:["Open ",s.key," in Jira",t.jsx(Le,{className:"h-3.5 w-3.5","aria-hidden":!0})]}),lt(s.prs).map(({pr:i})=>t.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer","data-manual-pr":te(i),className:"inline-flex items-center gap-1 text-indigo-700 hover:text-indigo-900",children:[te(i),i.title&&t.jsxs("span",{className:"text-gray-500",children:["· ",i.title]}),t.jsx(Le,{className:"h-3.5 w-3.5","aria-hidden":!0})]},`${i.repo}#${i.number}`)),!s.prs?.length&&t.jsx("span",{className:"text-gray-400",children:"No PR"})]}),t.jsx("div",{className:"mt-3",children:t.jsx(ft,{ticket:s,onUpdate:n,size:"sm"})}),s.plan?.on&&t.jsxs(t.Fragment,{children:[t.jsx(ct,{strategy:s.plan.strategy}),t.jsx(Ue,{ticket:s,onUpdate:n,manual:!0})]})]},s.key)})}):a||t.jsx(de,{children:"No ticket stopped over budget. When the cost guard stops one, it lands here for you to run by hand."})}function de({children:e,wide:n=!1}){return t.jsx("p",{"data-review-empty":!0,className:`${n?"col-span-full ":""}rounded-xl border border-dashed border-gray-300 bg-white px-4 py-10 text-center text-sm text-gray-500`,children:e})}const Ul=7,An="cockpit.proofSize",Ql=[{key:"large",label:"Large"},{key:"small",label:"Small"}];function ei({value:e,onChange:n}){return t.jsxs("div",{className:"hidden shrink-0 items-center gap-2 border-b border-gray-200 pb-1.5 pl-3 sm:flex",children:[t.jsx("span",{id:"proof-size-label",className:"text-xs text-gray-500",children:"Proofs"}),t.jsx("div",{role:"radiogroup","aria-labelledby":"proof-size-label","data-proof-toggle":!0,className:"flex gap-0.5 rounded-lg bg-gray-200/70 p-0.5",children:Ql.map(a=>{const s=e===a.key;return t.jsx("button",{type:"button",role:"radio","aria-checked":s,"data-proof-size-option":a.key,onClick:()=>n(a.key),className:`min-h-[30px] rounded-md px-3 text-[13px] font-medium transition-colors ${s?"bg-white text-gray-900 shadow-sm":"text-gray-600 hover:text-gray-900"}`,children:a.label},a.key)})})]})}function ti({initialClaims:e,initialTickets:n,initialBundles:a}){const s=Xs(),l=Js(),i=Wn(),o=kt.some(v=>v.key===i.get("tab"))?i.get("tab"):"merge",c=r.useMemo(()=>Gl(i.get("flags")),[i]),[d,m]=r.useState(n||[]),[p,u]=r.useState("large");r.useEffect(()=>{try{localStorage.getItem(An)==="small"&&u("small")}catch{}},[]);const g=r.useCallback(v=>{u(v);try{localStorage.setItem(An,v)}catch{}},[]),[h,$]=hl(),N=r.useCallback(({related:v,...C})=>m(O=>{const y=new Map((v||[]).map(_=>[_.key,_]));return O.map(_=>_.key===C.key?{..._,...C}:y.has(_.key)?{..._,...y.get(_.key)}:_)}),[]),b=r.useCallback((v,C)=>m(O=>O.map(y=>y.key===v.key?{...y,...v}:(C||[]).includes(y.key)?{...y,merged_into:v.key}:y)),[]),f=r.useMemo(()=>Object.fromEntries(d.filter(v=>v.merged_into).map(v=>[v.key,v.merged_into])),[d]),x=r.useMemo(()=>{const v=Date.now()-Ul*24*3600*1e3;return{merge:d.filter(C=>C.queue==="merge").sort((C,O)=>!!C.hold-!!O.hold||C.key.localeCompare(O.key,"en",{numeric:!0})),building:d.filter(C=>C.queue==="building").sort((C,O)=>C.key.localeCompare(O.key,"en",{numeric:!0})),decide:d.filter(C=>C.queue==="decision").sort((C,O)=>!!C.answer-!!O.answer||C.key.localeCompare(O.key,"en",{numeric:!0})),shipped:d.filter(C=>(C.queue==="shipped"||C.queue==="cancelled")&&new Date(C.merged_at||C.cancelled_at).getTime()>=v).sort((C,O)=>new Date(O.merged_at||O.cancelled_at)-new Date(C.merged_at||C.cancelled_at)),manual:d.filter(C=>C.queue==="manual").sort((C,O)=>new Date(O.manual?.stopped_at)-new Date(C.manual?.stopped_at))}},[d]),j={validate:fa(d).pending.length,merge:x.merge.length,decide:x.decide.filter(v=>!v.answer).length,manual:x.manual.length,claims:(e||[]).filter(v=>!v.vincent_ruling?.status).length,shipped:x.shipped.filter(v=>v.queue==="shipped").length},S=v=>{const C=new URLSearchParams(i.toString());C.set("tab",v),s.replace(`${l}?${C.toString()}`)},B=v=>{const C=new URLSearchParams(i.toString()),O=Xl(v);O?C.set("flags",O):C.delete("flags"),s.replace(`${l}?${C.toString()}`)},k={merge:[...x.building,...x.merge],decide:x.decide,manual:x.manual,shipped:x.shipped}[o]||[],E=v=>Xn(er(v,c),h),R=["merge","decide","manual","shipped"].includes(o),F=Pa(c)&&R,A=R||o==="validate",M=t.jsxs(de,{wide:!0,children:["No ticket in this tab matches the flag filter."," ",t.jsx("button",{type:"button",onClick:()=>B({flags:[],only:null}),className:"font-medium text-gray-700 underline underline-offset-2 hover:text-gray-900",children:"Clear the filter"})]}),W=Kn();if(W){const v={AnswerStatus:Fa,AutoChips:Aa,BuildingList:Rn,DecisionCard:Sn,FIX_STAGE_TEXT:gt,FixRequestBar:Ra,FlagChip:Ta,ManualList:Tn,MergeCard:En,PlanThread:Ue,ShippedList:Mn,StrategyBlock:ct,TicketThread:ht,fixOutcome:At,fixRequestAllowed:Ea,latestDirective:He,mergePlan:lt,openFixRequest:me,recommendedLetter:La,useGallery:xt,useTicketRefresh:pt},C={merge:[...Me(E(x.building),"building"),...Me(E(x.merge),"merge")],decide:Me(E(x.decide),"decide"),manual:Me(E(x.manual),"manual"),shipped:Me(E(x.shipped),"shipped")}[o],O=F&&k.length?M:{merge:t.jsx(de,{children:"No fix is waiting for a merge. New ones arrive with the next pipeline sync."}),decide:t.jsx(de,{children:"No ticket is waiting for your decision."}),manual:t.jsx(de,{children:"No ticket stopped over budget. When the cost guard stops one, it lands here for you to run by hand."}),shipped:t.jsx(de,{children:"No fix merged on GitHub or cancelled in the last 7 days."})}[o];return t.jsxs(wr,{tab:o,tabs:kt,counts:j,onTab:S,filterActive:F,renderFilters:R?()=>t.jsx($n,{tickets:k,filter:c,onChange:B}):null,children:[o==="validate"&&t.jsx(jn,{tickets:d,claims:e,onUpdate:N,onMerged:b,renderPlan:y=>t.jsx(Ue,{ticket:y,onUpdate:N}),bundles:a}),C&&t.jsx(zr,{items:C,empty:O,onUpdate:N,kit:v},o),t.jsx("div",{hidden:o!=="claims",className:"min-h-0 flex-1 overflow-y-auto px-3 py-4",children:t.jsx(an,{initialClaims:e,embedded:!0,mergedInto:f})})]})}return t.jsx("div",{className:`min-h-full bg-gray-50${W===null?" max-lg:invisible":""}`,children:t.jsxs("div",{className:"px-4 pb-10 pt-16 sm:px-8 md:pt-8",children:[t.jsxs("header",{children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("h1",{"data-review-title":!0,className:"text-2xl font-bold text-gray-900",children:"Review"}),t.jsxs(Ya,{href:"/administration/pipeline-live","data-live-link":!0,className:"inline-flex min-h-[36px] shrink-0 items-center gap-1.5 rounded-full bg-white px-3.5 text-sm font-medium text-gray-700 ring-1 ring-gray-200 transition-colors hover:bg-gray-100 hover:text-gray-900",children:[t.jsx("span",{className:"h-2 w-2 rounded-full bg-emerald-500","aria-hidden":!0}),"Live view"]})]}),t.jsx("p",{className:"mt-1 text-sm text-gray-600",children:"Review the evidence. Validate, redirect, or reject the proposed work."})]}),t.jsxs("div",{className:"mt-5 flex",children:[t.jsx("nav",{role:"tablist","aria-label":"Cockpit",className:"flex min-w-0 flex-1 gap-1 overflow-x-auto border-b border-gray-200",children:kt.map(v=>{const C=o===v.key;return t.jsxs("button",{type:"button",role:"tab","aria-selected":C,"data-tab":v.key,onClick:()=>S(v.key),className:`-mb-px inline-flex min-h-[44px] shrink-0 items-center gap-1.5 border-b-2 px-3 text-sm font-medium transition-colors ${C?"border-gray-900 text-gray-900":"border-transparent text-gray-500 hover:text-gray-800"}`,children:[v.label,j[v.key]>0&&t.jsx("span",{className:`rounded-full px-1.5 text-xs tabular-nums ${C?"bg-gray-900 text-white":"bg-gray-200 text-gray-600"}`,children:j[v.key]})]},v.key)})}),(o==="merge"||o==="decide")&&t.jsx(ei,{value:p,onChange:g})]}),A&&t.jsxs("div",{className:"mt-3 flex flex-col gap-2 sm:flex-row sm:items-start sm:gap-4",children:[R&&t.jsx($n,{tickets:k,filter:c,onChange:B}),t.jsx(pl,{value:h,onChange:$})]}),t.jsx(xl,{value:h,children:t.jsxs("div",{className:"mt-5",children:[o==="validate"&&t.jsx(jn,{tickets:d,claims:e,onUpdate:N,onMerged:b,renderPlan:v=>t.jsx(Ue,{ticket:v,onUpdate:N}),bundles:a,sort:h}),o==="merge"&&t.jsxs("div",{className:"space-y-4",children:[t.jsx(Rn,{tickets:E(x.building),onUpdate:N}),E(x.merge).map(v=>t.jsx(En,{ticket:v,proofSize:p,onUpdate:N},v.key)),x.merge.length===0&&!F&&t.jsx(de,{children:"No fix is waiting for a merge. New ones arrive with the next pipeline sync."}),F&&E(k).length===0&&M]}),o==="decide"&&t.jsxs("div",{className:"grid grid-cols-1 items-start gap-4 2xl:grid-cols-2",children:[E(x.decide).map(v=>t.jsx(Sn,{ticket:v,onAnswered:N,onUpdate:N,proofSize:p},v.key)),x.decide.length===0&&!F&&t.jsx(de,{wide:!0,children:"No ticket is waiting for your decision."}),F&&x.decide.length>0&&E(x.decide).length===0&&M]}),o==="manual"&&t.jsx(Tn,{tickets:E(x.manual),onUpdate:N,empty:F&&x.manual.length?M:null}),t.jsx("div",{hidden:o!=="claims",children:t.jsx(an,{initialClaims:e,embedded:!0,mergedInto:f})}),o==="shipped"&&t.jsx(Mn,{tickets:E(x.shipped),onUpdate:N,empty:F&&x.shipped.length?M:null})]})})]})})}const ni=["data-ticket-card","data-gate-card","data-building-row","data-manual-card","data-shipped","data-validated","data-auto","data-dismissed"],ai=6e3;function si(){const e=Wn(),n=e.get("focus"),a=e.get("tab");return r.useEffect(()=>{if(!n||!/^[A-Z][A-Z0-9]+-\d+$/.test(n))return;const s=ni.map(d=>`[${d}="${n}"]`).join(","),l=Date.now();let i=null,o=null;const c=()=>{const d=[...document.querySelectorAll(s)].find(p=>p.offsetParent!==null);if(!d){Date.now()-l<ai&&(o=requestAnimationFrame(c));return}d.scrollIntoView({block:"center",behavior:"smooth"}),d.setAttribute("data-focused","true");const m={outline:d.style.outline,offset:d.style.outlineOffset};d.style.outline="2px solid rgb(245 158 11)",d.style.outlineOffset="3px",i=setTimeout(()=>{d.style.outline=m.outline,d.style.outlineOffset=m.offset,d.removeAttribute("data-focused")},4e3)};return o=requestAnimationFrame(c),()=>{cancelAnimationFrame(o),clearTimeout(i)}},[n,a]),null}const ci="force-dynamic";async function ui(){(await Ys())?.user?.isSuperAdmin||Vs("/administration"),await Ks();const[n,a,s]=await Promise.all([Xa.find({},{_id:0,__v:0}).lean(),Ja.find({queue:{$ne:null}},{_id:0,__v:0,"decision.raw":0}).lean(),Va.findOne({name:"current"},{_id:0,__v:0}).lean()]);return t.jsxs(r.Suspense,{children:[t.jsx(ti,{initialClaims:JSON.parse(JSON.stringify(n)),initialTickets:JSON.parse(JSON.stringify(a)),...s?{initialBundles:JSON.parse(JSON.stringify(s))}:{}}),t.jsx(si,{})]})}export{ui as default,ci as dynamic};
|