import { DRAFT_STATUS, ID_PREFIX } from "./constants";
import { parseJsonSafely } from "./utils";

// applySetting assumes setting & columns are the same length
export function applySetting(setting, columns) {
  setting = parseJsonSafely(setting);
  setting = setting.sort((a, b) => a.defaultOrder - b.defaultOrder);
  return columns.filter((_, idx) => setting[idx]?.shouldShow).sort((a, b) => setting[a.defaultOrder].orderNumber - setting[b.defaultOrder].orderNumber);
}

export const adminColumns = {
  admin_user: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 0,
      idPrefix: ID_PREFIX.USER,
    },
    {
      header: "First Name",
      accessor: "first_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Last Name",
      accessor: "last_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Email",
      accessor: "email",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "DOB",
      accessor: "dob",
      defaultOrder: 4,
    },
    {
      header: "Role",
      accessor: "role",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 5,
    },
    {
      header: "Preferences",
      accessor: "settings",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 6,
    },
    {
      header: "Status",
      accessor: "status",
      statusMapping: ["Inactive", "Active", "Suspend"],
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 7,
    },
    {
      header: "Profile",
      accessor: "",
      defaultOrder: 8,
    },
    {
      header: "Photo Status",
      accessor: "is_photo_approved",
      mapping: ["IN REVIEW", "APPROVED", "REJECTED"],
      default: "No Photo",
      defaultOrder: 9,
    },
  ],
  admin_host: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.HOST,
      defaultOrder: 0,
    },
    {
      header: "Name",
      accessor: "first_name,last_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Email",
      accessor: "email",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Status",
      accessor: "status",
      statusMapping: ["Inactive", "Active", "Suspend"],
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "Total Payout",
      accessor: "total_payout",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 4,
    },
    {
      header: "Properties",
      accessor: "num_properties",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 5,
    },
    {
      header: "Profile",
      accessor: "",
      defaultOrder: 6,
    },
  ],
  admin_customer: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.CUSTOMER,
      defaultOrder: 0,
    },
    {
      header: "First Name",
      accessor: "first_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Last Name",
      accessor: "last_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Email",
      accessor: "email",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "Verified",
      accessor: "verify",
      mapping: ["No", "Yes"],
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 4,
    },
    {
      header: "Payment Set",
      accessor: "payment_method_set",
      mapping: ["No", "Yes"],
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 5,
    },
    {
      header: "Status",
      accessor: "status",
      statusMapping: ["Inactive", "Active", "Suspend"],
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 6,
    },
    {
      header: "Profile",
      accessor: "",
      defaultOrder: 7,
    },
  ],
  admin_id_verification: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.ID_VERIFICATION,
      defaultOrder: 0,
    },
    {
      header: "User ID",
      accessor: "user_id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.USER,
      defaultOrder: 1,
    },
    {
      header: "Email",
      accessor: "email",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Date of Birth",
      accessor: "dob",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "ID Photo Front",
      accessor: "image_front",
      defaultOrder: 4,
    },
    {
      header: "ID Photo Back",
      accessor: "image_back",
      defaultOrder: 5,
    },
    {
      header: "Expiry Date",
      accessor: "expiry_date",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 6,
    },
    {
      header: "ID Type",
      accessor: "type",
      isSorted: false,
      isSortedDesc: false,
      defaultOrder: 7,
    },
    {
      header: "Status",
      accessor: "status",
      isSorted: true,
      isSortedDesc: true,
      mapping: ["Pending", "Verified", "Declined"],
      defaultOrder: 8,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 9,
    },
  ],
  admin_space_categories: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.SPACE_CATEGORY,
      defaultOrder: 0,
    },
    {
      header: "Category",
      accessor: "category",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Image",
      accessor: "image",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Icon",
      accessor: "icon",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Has Sizes",
      accessor: "has_sizes",
      mapping: ["NO", "YES"],
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 4,
    },
  ],
  admin_addon_categories: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.ADDON_CATEGORY,
      defaultOrder: 0,
    },
    {
      header: "Space Category",
      nested: "spaces",
      accessor: "category",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Name",
      accessor: "name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Cost ($)",
      accessor: "cost",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 4,
    },
  ],
  host_addon_categories: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.ADDON_CATEGORY,
      defaultOrder: 0,
    },
    {
      header: "Name",
      accessor: "name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Cost ($)",
      accessor: "cost",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 3,
    },
  ],
  admin_amenity_categories: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.AMENITY_CATEGORY,
      defaultOrder: 0,
    },
    {
      header: "Space Category",
      nested: "spaces",
      accessor: "category",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Name",
      accessor: "name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 3,
    },
  ],
  host_amenity_categories: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.AMENITY_CATEGORY,
      defaultOrder: 0,
    },
    {
      header: "Name",
      accessor: "name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 2,
    },
  ],
  admin_property: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.PROPERTY,
      defaultOrder: 0,
    },
    {
      header: "Property Name",
      accessor: "name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Host's Email",
      accessor: "email",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Address",
      accessor: "address_line_1, address_line_2",
      multiline: true,
      defaultOrder: 3,
    },
    {
      header: "City",
      accessor: "city",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 4,
    },
    {
      header: "Zip Code",
      accessor: "zip",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 5,
    },
    {
      header: "Country",
      accessor: "country",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 6,
    },
    {
      header: "Spaces",
      accessor: "spaces",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 7,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 8,
    },
  ],
  admin_property_space: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.PROPERTY_SPACE,
      defaultOrder: 0,
    },
    {
      header: "Property",
      accessor: "property_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Space",
      accessor: "space_category",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Max Capacity",
      accessor: "max_capacity",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "Rate ( Hourly )",
      accessor: "rate",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 4,
    },
    {
      header: "Additional guest rate ( hourly )",
      accessor: "additional_guest_rate",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 5,
    },
    {
      header: "Date Updated",
      accessor: "update_at",
      isSorted: true,
      isSortedDesc: true,
      formatDate: true,
      defaultOrder: 6,
    },
    {
      header: "Is Draft",
      accessor: "draft_status",
      isSorted: true,
      isSortedDesc: true,
      format: (raw) => (raw === DRAFT_STATUS.COMPLETED ? "NO" : "YES"),
      defaultOrder: 7,
    },
    {
      header: "Status",
      accessor: "space_status",
      isSorted: true,
      isSortedDesc: true,
      mapping: ["UNDER REVIEW", "APPROVED", "DECLINED"],
      defaultOrder: 8,
    },
    {
      header: "Visibility",
      accessor: "availability",
      isSorted: true,
      isSortedDesc: true,
      mapping: ["HIDDEN", "VISIBLE"],
      defaultOrder: 9,
    },
    {
      header: "Size",
      accessor: "size",
      isSorted: true,
      isSortedDesc: true,
      mapping: ["Small", "Medium", "Large", "X-Large"],
      defaultOrder: 10,
    },
    {
      header: "Actions",
      accessor: "",
      viewProperty: true,
      defaultOrder: 11,
    },
  ],
  admin_property_space_images: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.PROPERTY_SPACE_IMAGES,
      defaultOrder: 0,
    },
    {
      header: "Property",
      accessor: "property_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Property Space",
      accessor: "space_category",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Host Email",
      accessor: "email",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "Image",
      accessor: "photo_url",
      defaultOrder: 4,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 5,
    },
    {
      header: "Status",
      accessor: "is_approved",
      defaultOrder: 6,
      mapping: ["IN REVIEW", "APPROVED", "REJECTED"],
    },
  ],
  admin_property_space_amenities: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.PROPERTY_SPACE_AMENITIES,
      defaultOrder: 0,
    },
    {
      header: "Property Name",
      accessor: "property_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Property Space",
      accessor: "space_category",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Amenity",
      accessor: "amenity_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 4,
    },
  ],
  admin_property_space_faqs: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.PROPERTY_SPACE_FAQS,
      defaultOrder: 0,
    },
    {
      header: "Property Space ID",
      accessor: "property_space_id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.PROPERTY_SPACE,
      defaultOrder: 1,
    },
    {
      header: "Questions",
      accessor: "question",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 3,
    },
  ],
  admin_booking_addons: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.BOOKING_ADDON,
      defaultOrder: 0,
    },
    {
      header: "Booking Id",
      accessor: "booking_id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.BOOKINGS,
      defaultOrder: 1,
    },
    {
      header: "Property Add-on",
      accessor: "add_on_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 3,
    },
  ],
  admin_hashtag: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.HASHTAGS,
      defaultOrder: 0,
    },
    {
      header: "Name",
      accessor: "name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Actions",
      accessor: "",
      defaultOrder: 2,
    },
  ],
  admin_host_reviews: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.REVIEWS,
      defaultOrder: 0,
    },
    {
      header: "Host",
      accessor: "host_first_name , host_last_name",
      type: "single",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Space",
      accessor: "name,category",
      multiline: true,
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Post Date",
      accessor: "create_at",
      defaultOrder: 3,
    },
    {
      header: "Rating",
      accessor: "rating",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 4,
    },
    {
      header: "Type",
      accessor: "type",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 5,
    },
    {
      header: "Status",
      accessor: "status",
      mapping: ["Under Review", "Posted", "Declined"],
      defaultOrder: 6,
    },
    {
      header: "Action",
      accessor: "",
      defaultOrder: 7,
    },
  ],
  admin_customer_reviews: [
    {
      header: "ID",
      accessor: "id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.REVIEWS,
      defaultOrder: 0,
    },
    {
      header: "Customer",
      accessor: "customer_first_name , customer_last_name",
      type: "single",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Space",
      accessor: "name,category",
      multiline: true,
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 2,
    },
    {
      header: "Post Date",
      accessor: "create_at",
      defaultOrder: 3,
    },
    {
      header: "Rating",
      accessor: "rating",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 4,
    },
    {
      header: "Type",
      accessor: "type",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 5,
    },
    {
      header: "Status",
      accessor: "status",
      mapping: ["Under Review", "Posted", "Declined"],
      defaultOrder: 6,
    },
    {
      header: "Action",
      accessor: "",
      defaultOrder: 7,
    },
  ],
  admin_booking_report: [
    {
      header: "Booking ID",
      accessor: "id",
      idPrefix: ID_PREFIX.BOOKINGS,
      defaultOrder: 0,
    },
    {
      header: "Host ID",
      accessor: "host_id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.HOST,
      defaultOrder: 1,
    },
    {
      header: "Customer ID",
      accessor: "customer_id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.CUSTOMER,
      defaultOrder: 2,
    },
    {
      header: "Property ID",
      accessor: "property_id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.PROPERTY,
      defaultOrder: 3,
    },
    {
      header: "Property Space ID",
      accessor: "property_space_id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.PROPERTY_SPACE,
      defaultOrder: 4,
    },
    {
      header: "Addon Cost",
      accessor: "addon_cost",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 5,
    },
    {
      header: "Property name",
      accessor: "property_name",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 6,
    },
    {
      header: "Space Category",
      accessor: "space_category",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 7,
    },
    {
      header: "Hourly rate",
      accessor: "rate",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 8,
    },
    {
      header: "Space Address",
      accessor: "address_line_1, address_line_2",
      joinFields: true,
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 9,
    },
    {
      header: "Customer name",
      accessor: "customer_first_name, customer_last_name",
      joinFields: true,
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 10,
    },
    {
      header: "Host name",
      accessor: "host_first_name, host_last_name",
      joinFields: true,
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 11,
    },
    {
      header: "Booking date",
      accessor: "booking_start_time",
      isSorted: true,
      isSortedDesc: true,
      formatDate: true,
      defaultOrder: 12,
    },
    {
      header: "Booking status",
      accessor: "status",
      isSorted: true,
      isSortedDesc: true,
      mapping: ["Pending", "Upcoming", "Ongoing", "Completed", "Declined", "Cancelled"],
      defaultOrder: 13,
    },
  ],
  admin_analytics: [
    {
      header: "User ID",
      accessor: "user_id",
      isSorted: true,
      isSortedDesc: true,
      idPrefix: ID_PREFIX.CUSTOMER,
      defaultOrder: 0,
    },
    {
      header: "Url",
      accessor: "path",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 1,
    },
    {
      header: "Country",
      accessor: "country",
      isSorted: true,
      isSortedDesc: true,
      isCountry: true,
      defaultOrder: 2,
    },
    {
      header: "Role",
      accessor: "role",
      isSorted: true,
      isSortedDesc: true,
      defaultOrder: 3,
    },
    {
      header: "Date",
      accessor: "create_at",
      isSorted: true,
      isSortedDesc: true,
      formatDate: true,
      defaultOrder: 4,
    },
  ],
};
