"use client";

import { createExperienceListPage } from "@/modules/experience/components/ExperienceListCrudPage";
import { experienceApi } from "@/modules/experience/services/experience-api";

export const PagesPage = createExperienceListPage({
  title: "صفحات",
  breadcrumb: "صفحات",
  resourceKey: "pages",
  permission: "experience.pages.view",
  api: experienceApi.pages,
  columns: [
    { key: "title", header: "عنوان" },
    { key: "slug", header: "اسلاگ" },
    { key: "page_type", header: "نوع" },
    { key: "publish_status", header: "انتشار", type: "status" },
    { key: "created_at", header: "ایجاد", type: "datetime" },
  ],
  createFields: [
    { name: "workspace_id", label: "فضای کاری", type: "workspace", required: true, createOnly: true },
    { name: "site_id", label: "سایت", type: "site", required: true, createOnly: true },
    { name: "code", label: "کد یکتا", required: true, placeholder: "home", hint: "لاتین/عدد/_/- حداقل ۲ کاراکتر (مثل: home). فارسی و فاصله مجاز نیست." },
    { name: "title", label: "عنوان", required: true },
    { name: "slug", label: "اسلاگ", required: true, placeholder: "home", hint: "آدرس کوتاه صفحه با حروف لاتین (مثل: home یا about-us)" },
    { name: "summary", label: "خلاصه", type: "textarea" },
    {
      name: "page_type",
      label: "نوع صفحه",
      type: "select",
      required: true,
      options: [
        { value: "landing", label: "لندینگ" },
        { value: "business_website", label: "وب‌سایت کسب‌وکار" },
        { value: "mini_site", label: "مینی‌سایت" },
        { value: "form", label: "فرم" },
        { value: "blog", label: "بلاگ" },
        { value: "custom", label: "سفارشی" },
      ],
    },
    {
      name: "publish_status",
      label: "وضعیت انتشار",
      type: "select",
      options: [
        { value: "draft", label: "پیش‌نویس" },
        { value: "published", label: "منتشر" },
        { value: "archived", label: "بایگانی" },
      ],
    },
    { name: "locale", label: "زبان", placeholder: "fa" },
    {
      name: "text_direction",
      label: "جهت",
      type: "select",
      options: [
        { value: "rtl", label: "راست‌به‌چپ" },
        { value: "ltr", label: "چپ‌به‌راست" },
      ],
    },
  ],
  editFields: [
    { name: "title", label: "عنوان", required: true },
    { name: "slug", label: "اسلاگ", required: true },
    { name: "summary", label: "خلاصه", type: "textarea" },
    {
      name: "page_type",
      label: "نوع صفحه",
      type: "select",
      options: [
        { value: "landing", label: "لندینگ" },
        { value: "business_website", label: "وب‌سایت کسب‌وکار" },
        { value: "mini_site", label: "مینی‌سایت" },
        { value: "form", label: "فرم" },
        { value: "blog", label: "بلاگ" },
        { value: "custom", label: "سفارشی" },
      ],
    },
    { name: "locale", label: "زبان" },
    {
      name: "text_direction",
      label: "جهت",
      type: "select",
      options: [
        { value: "rtl", label: "راست‌به‌چپ" },
        { value: "ltr", label: "چپ‌به‌راست" },
      ],
    },
    { name: "version", label: "نسخه", type: "number", required: true, editOnly: true },
  ],
  detailHref: (row) => (row.id ? `/experience/pages/${row.id}/builder` : null),
});

export default PagesPage;
