import{r as N,J as ge,j as e,U as Ne,t as b,a as C,S as v}from"./app-BBZbvTSO.js";import{s as ve}from"./utils-YhN_nlHn.js";import{c as R,B as l}from"./button-CZmOQP7j.js";import{D as Q,a as W,b as Z,g as I}from"./dropdown-menu-DkvU_mzU.js";import{renderField as we}from"./index-Clw9qok5.js";import{C as E,c as ee}from"./card-LUGiYPFK.js";import{S as K}from"./separator-BzKY_P4f.js";import{B as se}from"./badge-BR_GnIty.js";import{D as L,a as P,b as B,c as O,d as $,e as z}from"./dialog-D_v2qgP5.js";import{S as ye}from"./Select-BSWSW26d.js";import{C as ae}from"./chevron-down-DDM9YQ48.js";import{C as M}from"./circle-alert-bp8tLLkJ.js";import{T as re}from"./trash-2-BBs2y9vd.js";import{X as te}from"./index-C0VDnRYN.js";import{C as J}from"./copy-MGAttPaC.js";import{F as Ce}from"./file-text-DfpLAAwR.js";import{K as ke}from"./index-BnKWxTXF.js";import{C as le}from"./calendar-DoGBS4zB.js";import{C as De}from"./clock-gA1FmRyJ.js";/* empty css            */import"./index-CbDI-tXU.js";import"./index-13DH8-b5.js";import"./index-IvSACaye.js";import"./index-BosTFUDi.js";import"./Combination-9YgcTppv.js";import"./index-hDbW6ayQ.js";import"./floating-ui.dom-DtF1XweH.js";import"./index-AiAmtg3H.js";import"./index-C1VwruLz.js";import"./index-Dbn6AP0q.js";import"./TextField-LBrTau12.js";import"./FieldBase-C0gzKbbb.js";import"./label-BPDCCRHl.js";import"./input-error-Bz7f2c6i.js";import"./input-dmj4QjAp.js";import"./plus-D8fMMvfS.js";import"./LongTextField-C9tMvW5a.js";import"./textarea-DorjplNc.js";import"./RichTextField-Bnuab5_-.js";import"./AssetUploader-Dc0DPvOY.js";import"./scroll-area-hNGxDuJk.js";import"./image-BEhzBCM8.js";import"./file-rNzbEzLm.js";import"./MediaFieldSelectModal-JGV1H8zK.js";import"./tabs-DQOAKbqS.js";import"./search-bar-FrEZMnbC.js";import"./pagination-tuDq0xKj.js";import"./chevron-left-CbuOobkA.js";import"./chevron-right-fDICdnKB.js";import"./alert-dialog-Ct4MX6gw.js";import"./AssetGrid-CipfNuNT.js";import"./checkbox-B0_9jnY6.js";import"./index-BCYyBCUm.js";import"./check-yuW7wFtQ.js";import"./tooltip-CRkL5R4V.js";import"./AssetDetailsModal-UyBE7M0a.js";import"./download-grDUn2Jg.js";import"./lock-C-nUbAQc.js";import"./file-image-DFth2BDy.js";import"./AssetActionMenu-D0cCgiLZ.js";import"./ellipsis-vertical-DoJR9-bA.js";import"./eye-v-dyI3tg.js";import"./trash-O7-xigMm.js";import"./AssetTable-BIkMwJ85.js";import"./table-BDtwArHp.js";import"./format-C_TaVLmE.js";import"./layout-grid-CF44vN4j.js";import"./SlugField-DBd9JWV2.js";import"./EmailField-Cr_qDQjf.js";import"./at-sign-Czm704vp.js";import"./PasswordField-Cn5acjoj.js";import"./eye-off-qvZp0TuQ.js";import"./key-round-Dk1wKoA3.js";import"./NumberField-Dtg0_Sb3.js";import"./hash-CTCupukW.js";import"./EnumerationField-ia4yj4TC.js";import"./BooleanField-Cd-YtFRr.js";import"./switch-9bH0NbTy.js";import"./ColorField-BBlXKqFa.js";import"./DateField-BBTSxLtY.js";import"./moment-C5S46NFB.js";import"./date-picker-D96g6NFs.js";import"./TimeField-BijwhWA8.js";import"./MediaField-q8GzfT_6.js";import"./RelationField-PXdUZ_O7.js";import"./RelationModal-CHnhLkJe.js";import"./data-table-Bvm7bdmo.js";import"./select-KQeGfQXO.js";import"./loader-circle-BqAFTH1R.js";import"./relation-entries-table-032v1tqy.js";import"./JSONField-DOODBO3X.js";import"./code-aABRHl_L.js";/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const _e=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Se=R("CircleCheck",_e);/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ae=[["path",{d:"M21.54 15H17a2 2 0 0 0-2 2v4.54",key:"1djwo0"}],["path",{d:"M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",key:"1tzkfa"}],["path",{d:"M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05",key:"14pb5j"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],ie=R("Earth",Ae);/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Te=[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]],ne=R("User",Te);function ua({project:m,collection:i,contentEntry:a,formData:y,isEditMode:p}){var q,G;const[k,D]=N.useState({}),[n,j]=N.useState(!1),[oe,X]=N.useState({}),[ce,_]=N.useState(!1),[de,S]=N.useState(!1),[me,A]=N.useState(!1),[pe,T]=N.useState(!1),u=ge().props.userCan,U=i.is_singleton,H=m.locales,Y=Array.isArray(H)&&H.length?H:[m.default_locale||"en"],[F,he]=N.useState((a==null?void 0:a.locale)||m.default_locale||Y[0]);N.useEffect(()=>{if(y&&Object.keys(y).length>0){const r={...y};i.fields.forEach(d=>{var o,h,c;if(d.type==="media"){const t=y[d.name],g=x=>x&&typeof x=="object"?x.id??null:x??null;if(!!((o=d.options)!=null&&o.multiple)||((c=(h=d.options)==null?void 0:h.media)==null?void 0:c.type)===2||Array.isArray(t))r[d.name]=Array.isArray(t)?t.map(g).filter(x=>x!==null):[];else{const x=Array.isArray(t)?g(t[0]):g(t);r[d.name]=x!==null?[x]:[]}}}),D(r);return}const s={};i.fields.forEach(r=>{var d,o;(d=r.options)!=null&&d.repeatable?s[r.name]=[{value:null}]:r.type==="enumeration"&&((o=r.options)!=null&&o.multiple)?s[r.name]=[]:r.type==="boolean"?s[r.name]=!1:r.type==="media"?s[r.name]=[]:r.type==="relation"?s[r.name]=[]:r.type==="json"?s[r.name]=null:s[r.name]=""}),D(s)},[i,y]);const f=async(s,r)=>{var d,o;j(!0),X({});try{let h;if(p&&a?h=await C.put(route("projects.collections.content.update",{project:m.id,collection:i.id,contentEntry:a.id}),{data:k,status:r,locale:F}):h=await C.post(route("projects.collections.content.store",{project:m.id,collection:i.id}),{data:k,status:r,locale:F}),b.success(h.data.message||"Content saved successfully"),s==="close"||!p&&!u.update_content)v.visit(route("projects.collections.show",{project:m.id,collection:i.id}));else if(s==="new"){const c={};i.fields.forEach(t=>{var g,w;(g=t.options)!=null&&g.repeatable?c[t.name]=[{value:null}]:t.type==="enumeration"&&((w=t.options)!=null&&w.multiple)?c[t.name]=[]:t.type==="boolean"?c[t.name]=!1:t.type==="media"?c[t.name]=[]:t.type==="relation"?c[t.name]=[]:t.type==="json"?c[t.name]=null:c[t.name]=""}),D(c),window.scrollTo(0,0)}else if(s==="stay"&&!p&&u.update_content&&h.data.entry_id){const c=h.data.entry_id;setTimeout(()=>{v.visit(route("projects.collections.content.edit",{project:m.id,collection:i.id,contentEntry:c}))},100)}else s==="stay"&&p&&v.reload()}catch(h){(o=(d=h.response)==null?void 0:d.data)!=null&&o.errors?(X(h.response.data.errors),b.error("Failed to save content. Please check the form for errors.")):b.error("An error occurred while saving content.")}finally{j(!1)}},xe=async()=>{j(!0);try{await f("stay","draft"),_(!1)}catch{}finally{j(!1)}},ue=async()=>{j(!0);try{const s=await C.delete(route("projects.collections.content.destroy",{project:m.id,collection:i.id,contentEntry:a.id}));b.success(s.data.message||"Content moved to trash successfully"),v.visit(route("projects.collections.show",{project:m.id,collection:i.id}))}catch{b.error("Failed to move content to trash.")}finally{j(!1),S(!1)}},je=async()=>{j(!0);try{const s=await C.delete(route("projects.collections.content.forceDestroy",{project:m.id,collection:i.id,contentEntry:a.id}));b.success(s.data.message||"Content permanently deleted"),v.visit(route("projects.collections.show",{project:m.id,collection:i.id}))}catch{b.error("Failed to delete content.")}finally{j(!1),A(!1)}},fe=async()=>{j(!0);try{const s=await C.post(route("projects.collections.content.duplicate",{project:m.id,collection:i.id,contentEntry:a.id}));b.success(s.data.message||"Content duplicated");const r=s.data.entry_id;r?v.visit(route("projects.collections.content.edit",{project:m.id,collection:i.id,contentEntry:r})):v.reload()}catch{b.error("Failed to duplicate content")}finally{j(!1),T(!1)}},be=(s,r,d)=>{var c,t;const o={...k};(c=s.options)!=null&&c.repeatable?typeof d=="number"?(Array.isArray(o[s.name])||(o[s.name]=[{value:null}]),o[s.name][d].value=r):o[s.name]=r:s.type==="media"?o[s.name]=Array.isArray(r)?r:r?[r]:[]:o[s.name]=r;const h=i.fields.find(g=>{var w,x;return g.type==="slug"&&((x=(w=g.options)==null?void 0:w.slug)==null?void 0:x.field)===s.name});h&&!((t=s.options)!=null&&t.repeatable)&&(o[h.name]=ve(r)),D(o)},V=s=>s?new Date(s).toLocaleString():"N/A";return e.jsxs("div",{children:[e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"flex justify-between space-x-4",children:[e.jsxs("div",{className:"space-y-4 w-3/4",children:[U&&e.jsx("div",{className:"mb-3",children:e.jsxs("h1",{className:"text-xl font-bold",children:[i.name,e.jsxs("span",{className:"text-sm font-normal text-muted-foreground ml-2",children:["#",e.jsx("span",{className:"select-all",children:i.slug})]})]})}),i.fields.map(s=>e.jsx("div",{className:"border border-gray-200 dark:border-gray-800 border-dashed w-full p-4 rounded-md",children:e.jsx(Ne.Fragment,{children:we({field:s,value:k[s.name],onChange:be,processing:n,errors:oe})})},s.id))]}),e.jsx("div",{className:"flex-1 w-1/4",children:e.jsxs("aside",{className:"space-y-4 sticky top-4",children:[!U&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col space-y-3",children:[p&&a.status==="draft"&&e.jsx("div",{className:"flex space-x-2",children:e.jsx(l,{onClick:()=>f("stay","draft"),disabled:n,className:"flex-grow",children:"Save as draft"})}),!p&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(l,{onClick:()=>f("stay","draft"),disabled:n,className:"flex-grow",children:"Save as draft"}),!p&&e.jsxs(Q,{children:[e.jsx(W,{asChild:!0,children:e.jsx(l,{variant:"outline",size:"icon",className:"px-2",children:e.jsx(ae,{className:"h-4 w-4"})})}),e.jsxs(Z,{align:"end",children:[e.jsx(I,{onClick:()=>f("close","draft"),children:"Save and close"}),e.jsx(I,{onClick:()=>f("new","draft"),children:"Save and create new"})]})]})]}),p&&u.publish_content&&e.jsx("div",{className:"flex space-x-2",children:e.jsx(l,{onClick:()=>f("stay","published"),disabled:n,className:"flex-grow bg-green-600 hover:bg-green-700 text-white",children:"Save & Publish"})}),!p&&u.publish_content&&e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(l,{onClick:()=>f("stay","published"),disabled:n,className:"flex-grow bg-green-600 hover:bg-green-700 text-white",children:"Save & Publish"}),!p&&e.jsxs(Q,{children:[e.jsx(W,{asChild:!0,children:e.jsx(l,{variant:"outline",size:"icon",className:"px-2",children:e.jsx(ae,{className:"h-4 w-4"})})}),e.jsxs(Z,{align:"end",children:[e.jsx(I,{onClick:()=>f("close","published"),children:"Save, publish and close"}),e.jsx(I,{onClick:()=>f("new","published"),children:"Save, publish and create new"})]})]})]})]}),p&&a&&e.jsxs("div",{className:`p-3 rounded-md flex items-center justify-between ${a.status==="published"?"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800":"bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800"}`,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[a.status==="published"?e.jsx(Se,{className:"h-5 w-5 text-green-600 dark:text-green-400"}):e.jsx(M,{className:"h-5 w-5 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{children:[e.jsx("h3",{className:`font-medium ${a.status==="published"?"text-green-700 dark:text-green-400":"text-amber-700 dark:text-amber-400"}`,children:a.status==="published"?"Published":"Draft"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.status==="published"?`Published on ${new Date(a.published_at).toLocaleDateString()}`:"This entry is not yet published"})]})]}),e.jsx(se,{variant:a.status==="published"?"default":"outline",className:a.status==="published"?"bg-green-600 hover:bg-green-700":"text-amber-600 border-amber-300 dark:border-amber-600",children:a.status==="published"?"Live":"Draft"})]}),p&&a&&a.status==="published"&&u.unpublish_content&&e.jsxs(l,{onClick:()=>_(!0),disabled:n,variant:"outline",className:"w-full border-amber-300 text-amber-700 hover:bg-amber-50 dark:border-amber-600 dark:text-amber-400 dark:hover:bg-amber-900/20",children:[e.jsx(M,{className:"mr-2 h-4 w-4"}),"Unpublish"]}),p&&a&&(u.create_content||u.move_content_to_trash||u.delete_content)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex space-x-2",children:[u.move_content_to_trash&&e.jsxs(l,{onClick:()=>S(!0),variant:"outline",className:"flex-1 border-red-200 text-red-600 hover:bg-red-50 hover:text-red-700",children:[e.jsx(re,{className:"mr-2 h-4 w-4"}),"Move to Trash"]}),u.delete_content&&e.jsxs(l,{onClick:()=>A(!0),variant:"outline",className:"flex-1 border-red-200 text-red-600 hover:bg-red-50 hover:text-red-700",children:[e.jsx(te,{className:"mr-2 h-4 w-4"}),"Delete"]})]}),e.jsx("div",{className:"flex space-x-2",children:u.create_content&&e.jsxs(l,{onClick:()=>T(!0),variant:"outline",className:"flex-1",disabled:n,children:[e.jsx(J,{className:"mr-2 h-4 w-4"}),"Duplicate"]})})]})]}),U&&e.jsx("div",{className:"flex space-x-2",children:e.jsx(l,{onClick:()=>f("stay","published"),disabled:n,className:"flex-grow bg-green-600 hover:bg-green-700 text-white",children:"Save Content"})}),U&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"This is a single entry collection. Only one content entry is allowed."}),e.jsx(E,{className:"py-2",children:e.jsx(ee,{className:"py-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center space-x-2",children:[e.jsx(ie,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{children:"Locale"})]}),e.jsx(ye,{isMulti:!1,value:{value:F,label:F.toUpperCase()},onChange:s=>he((s==null?void 0:s.value)||m.default_locale),options:Y.map(s=>({value:s,label:s.toUpperCase()})),isDisabled:n})]})})}),p&&a&&e.jsx(E,{className:"py-2",children:e.jsxs(ee,{className:"py-3",children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Content Details"}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ce,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"ID:"})]}),e.jsx("span",{className:"font-medium",children:a.id})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ke,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"UUID:"})]}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx("span",{className:"font-medium",children:a.uuid?`${a.uuid.substring(0,8)}...`:"N/A"}),a.uuid&&e.jsx(l,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>{navigator.clipboard.writeText(a.uuid),b.success("UUID copied to clipboard")},children:e.jsx(J,{className:"h-3 w-3"})})]})]}),e.jsx(K,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(le,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Created:"})]}),e.jsx("span",{className:"font-medium",children:V(a.created_at)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ne,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"By:"})]}),e.jsx("span",{className:"font-medium",children:((q=a.creator)==null?void 0:q.name)||"Unknown"})]}),e.jsx(K,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(De,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Updated:"})]}),e.jsx("span",{className:"font-medium",children:V(a.updated_at)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ne,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"By:"})]}),e.jsx("span",{className:"font-medium",children:((G=a.updater)==null?void 0:G.name)||"Unknown"})]}),e.jsx(K,{}),a.status==="published"&&a.published_at&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(le,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Published:"})]}),e.jsx("span",{className:"font-medium",children:V(a.published_at)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ie,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Locale:"})]}),e.jsx(se,{variant:"outline",className:"uppercase",children:a.locale||"en"})]})]})]})})]})})]})}),e.jsx(L,{open:ce,onOpenChange:_,children:e.jsxs(P,{className:"sm:max-w-md",children:[e.jsxs(B,{children:[e.jsx(O,{children:"Unpublish Content"}),e.jsx($,{children:"Are you sure you want to unpublish this content? It will no longer be visible to users."})]}),e.jsxs(z,{children:[e.jsx(l,{variant:"outline",onClick:()=>_(!1),disabled:n,children:"Cancel"}),e.jsxs(l,{variant:"default",onClick:xe,disabled:n,className:"bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(M,{className:"mr-2 h-4 w-4"}),"Unpublish"]})]})]})}),e.jsx(L,{open:de,onOpenChange:S,children:e.jsxs(P,{className:"sm:max-w-md",children:[e.jsxs(B,{children:[e.jsx(O,{children:"Move to Trash"}),e.jsx($,{children:"Are you sure you want to move this content to trash? You can restore it later."})]}),e.jsxs(z,{children:[e.jsx(l,{variant:"outline",onClick:()=>S(!1),disabled:n,children:"Cancel"}),e.jsxs(l,{variant:"destructive",onClick:ue,disabled:n,children:[e.jsx(re,{className:"mr-2 h-4 w-4"}),"Move to Trash"]})]})]})}),e.jsx(L,{open:me,onOpenChange:A,children:e.jsxs(P,{className:"sm:max-w-md",children:[e.jsxs(B,{children:[e.jsx(O,{children:"Delete Content Permanently"}),e.jsx($,{children:"Are you sure you want to permanently delete this content? This action cannot be undone."})]}),e.jsxs(z,{children:[e.jsx(l,{variant:"outline",onClick:()=>A(!1),disabled:n,children:"Cancel"}),e.jsxs(l,{variant:"destructive",onClick:je,disabled:n,children:[e.jsx(te,{className:"mr-2 h-4 w-4"}),"Delete Permanently"]})]})]})}),e.jsx(L,{open:pe,onOpenChange:T,children:e.jsxs(P,{className:"sm:max-w-md",children:[e.jsxs(B,{children:[e.jsx(O,{children:"Duplicate Content"}),e.jsx($,{children:"This will create a new draft copy of the current entry. Continue?"})]}),e.jsxs(z,{children:[e.jsx(l,{variant:"outline",onClick:()=>T(!1),disabled:n,children:"Cancel"}),e.jsxs(l,{onClick:fe,disabled:n,children:[e.jsx(J,{className:"mr-2 h-4 w-4"}),"Duplicate"]})]})]})})]})}export{ua as default};
