"use client";

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

export const SiteDomainsPage = createExperienceListPage({
  title: "دامنه‌های سایت",
  description: "دامنهٔ سفارشی یا ساب‌دامین برای هر سایت — API نیازمند site_id است.",
  breadcrumb: "دامنه‌های سایت",
  resourceKey: "siteDomains",
  permission: "experience.domains.view",
  api: experienceApi.siteDomains,
  listRequires: ["site"],
  optimisticLocking: false,
  columns: [
    { key: "host", header: "هاست" },
    { key: "domain_kind", header: "نوع" },
    { key: "is_primary", header: "اصلی", type: "boolean" },
    { key: "is_verified", header: "تأیید", type: "boolean" },
    { 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: "host", label: "هاست (مثلاً shop.example.com)", required: true, placeholder: "example.torbatyar.ir" },
    {
      name: "domain_kind",
      label: "نوع دامنه",
      type: "select",
      required: true,
      options: [
        { value: "subdomain", label: "ساب‌دامین" },
        { value: "custom", label: "سفارشی" },
        { value: "path", label: "مسیر" },
      ],
    },
    { name: "is_primary", label: "دامنه اصلی", type: "boolean" },
    { name: "path_prefix", label: "پیشوند مسیر (اختیاری)", placeholder: "/shop" },
  ],
  editFields: [
    { name: "host", label: "هاست", required: true },
    {
      name: "domain_kind",
      label: "نوع دامنه",
      type: "select",
      options: [
        { value: "subdomain", label: "ساب‌دامین" },
        { value: "custom", label: "سفارشی" },
        { value: "path", label: "مسیر" },
      ],
    },
    { name: "is_primary", label: "دامنه اصلی", type: "boolean" },
    { name: "is_verified", label: "تأیید شده", type: "boolean" },
    { name: "path_prefix", label: "پیشوند مسیر" },
  ],
});

export default SiteDomainsPage;
