<?php
/**
 * Per-SKU merchandising copy for PDPs and cards.
 *
 * @package Foliora
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Catalog of merchandising fields keyed by parent SKU.
 *
 * @return array<string, array<string, mixed>>
 */
function foliora_product_copy_map() {
	$shipping = 'Most orders leave within 2–4 business days. Free shipping on $50+.';
	$returns  = '30 days, unused and in original condition.';
	$personal = 'We emboss the exact line you type at checkout. Please check spelling — custom pieces are made to order.';

	return array(
		'FOL-EMB-001' => array(
			'eyebrow'         => 'FOLIORA READER FAVORITE',
			'badge'           => 'Reader Favorite',
			'rating_display'  => '4.8 (126)',
			'short'           => 'A tiny press that leaves your name in the page — no ink, just a raised mark that makes a book feel like it belongs to you.',
			'image'           => 'embosser-hero.jpg',
			'hover'           => 'embosser-press.jpg',
			'benefits'        => array(
				array( 'No ink needed', 'A clean raised impression — nothing to smudge, nothing to refill.' ),
				array( 'Made to gift', 'A small object that feels considered the moment it is unwrapped.' ),
				array( 'Yours alone', 'Your name, or a short line, pressed into the page you love.' ),
			),
			'story_h2'        => 'A mark that stays with the book.',
			'story'           => 'The embosser is the quiet ritual at the start of a new volume: a name, a date, a line that says this copy is part of your library.',
			'how_it_works'    => array(
				array( 'Personalize it', 'Add your name or custom text.' ),
				array( 'Place the page', 'Insert a book page into the embosser.' ),
				array( 'Press', 'Create your permanent raised mark.' ),
			),
			'dimensions'      => 'Impression plate ≈ 4 × 2 cm.',
			'faq'             => array(
				'Will my book fit?'              => 'The press works on most paperbacks and hardcovers. Leave a small margin from the edge of the page.',
				'Is it padded?'                  => 'The handles are comfortable for a firm press; the plate itself is solid brass-toned metal.',
				'Can I wash it?'                 => 'Wipe with a dry cloth. Do not soak.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => $personal,
			),
		),
		'FOL-SLV-VIN' => array(
			'eyebrow'         => 'FOLIORA READER FAVORITE',
			'badge'           => 'Bestseller',
			'rating_display'  => '4.8 (126)',
			'short'           => 'A softly padded home for the book you can\'t stop carrying around.',
			'image'           => 'sleeve-burgundy.jpg',
			'hover'           => 'sleeve-feature.jpg',
			'benefits'        => array(
				array( 'Soft protection', 'Light padding helps protect your book from scratches and everyday wear.' ),
				array( 'Secure closure', 'A button-and-elastic hold that keeps your book tucked in your bag.' ),
				array( 'Made for everyday reading', 'Perfect for commuting, cafés and weekend trips.' ),
			),
			'story_h2'        => 'Because your favorite book shouldn\'t live at the bottom of your bag.',
			'story'           => 'Slip it in on the way to the café, the train, the weekend away. The sleeve is the quiet habit that keeps the book you love looking like itself.',
			'dimensions'      => 'Paperback 24 × 18 cm · Hardcover 28 × 21 cm · Kindle 18 × 13 cm.',
			'dim_sizes'       => array(
				'Paperback' => '24 × 18 cm',
				'Hardcover' => '28 × 21 cm',
				'Kindle'    => '18 × 13 cm',
			),
			'faq'             => array(
				'Will my book fit?'              => 'Choose Paperback, Hardcover or Kindle. When in doubt, size up — a little room is kinder than a tight fit.',
				'Is it padded?'                  => 'Yes. Soft padding on both sides, with a zip that keeps the book tucked in.',
				'Can I wash it?'                 => 'Spot-clean with a damp cloth. Air dry, out of direct sun.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'Sleeves are not personalized. For a named gift, pair with the book embosser.',
			),
		),
		'FOL-LGT-001' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => 'Gift Pick',
			'rating_display'  => '4.8 (126)',
			'short'           => 'A warm clip-on glow for late chapters, without lighting the whole room.',
			'image'           => 'product-light-scene.jpg',
			'hover'           => 'cat-lights.jpg',
			'benefits'        => array(
				array( 'Warm, not harsh', 'A small pool of light on the page — the rest of the room can stay dim.' ),
				array( 'Clips quietly', 'Sits on the cover without marking the paper.' ),
				array( 'Evening-ready', 'Made for the chapter you promised would be the last.' ),
			),
			'story_h2'        => 'Keep the lamp off. Keep the chapter going.',
			'story'           => 'A clip-on light is the difference between closing the book and staying for one more page — without waking the house.',
			'dimensions'      => 'Clip opening 2.5 cm.',
			'faq'             => array(
				'Will my book fit?'              => 'The clip opens to 2.5 cm — most paperbacks and slim hardcovers.',
				'Is it padded?'                  => 'Soft pads on the clip protect the cover.',
				'Can I wash it?'                 => 'Wipe only. Keep the light away from water.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'This light is not personalized.',
			),
		),
		'FOL-ANN-KIT' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => '',
			'rating_display'  => '4.8 (126)',
			'short'           => 'Tabs, flags and a fine highlighter set for the readers who write in the margins.',
			'image'           => 'cat-annotate.jpg',
			'hover'           => 'still-life-desk.jpg',
			'benefits'        => array(
				array( 'Soft colors', 'Tabs and ink that sit quietly on the page.' ),
				array( 'Ready to mark', 'Flags, tabs and a fine highlighter in one small kit.' ),
				array( 'Desk or bag', 'Compact enough to live beside the book you are in.' ),
			),
			'story_h2'        => 'For the readers who talk back to the page.',
			'story'           => 'A small kit for underlining, flagging and keeping the thought that a paragraph left behind.',
			'dimensions'      => 'Tin 14 × 9 cm.',
			'faq'             => array(
				'Will my book fit?'              => 'The kit is for any book you annotate — paperbacks, hardcovers, journals.',
				'Is it padded?'                  => 'The tin is rigid; the tabs inside are paper-soft.',
				'Can I wash it?'                 => 'Keep paper goods dry.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'The kit is not personalized.',
			),
		),
		'FOL-BMK-MAG' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => '',
			'rating_display'  => '4.8 (126)',
			'short'           => 'A slim magnetic hold that keeps your place without leaving a crease.',
			'image'           => 'cat-bookmarks.jpg',
			'hover'           => 'cat-bookmarks.jpg',
			'benefits'        => array(
				array( 'No crease', 'Holds the page without folding a corner.' ),
				array( 'Slim profile', 'Sits almost flush when the book is closed.' ),
				array( 'Everyday companion', 'The smallest thing that makes rereading easier.' ),
			),
			'story_h2'        => 'A place held, gently.',
			'story'           => 'A magnetic bookmark is the opposite of a dog-ear: a small, considered pause.',
			'dimensions'      => '7 × 2 cm.',
			'faq'             => array(
				'Will my book fit?'              => 'Works on paperbacks and hardcovers of any thickness you can close.',
				'Is it padded?'                  => 'A thin leather-and-brass stack, not a padded sleeve.',
				'Can I wash it?'                 => 'Wipe dry. Keep magnets away from water.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'Bookmarks are not personalized.',
			),
		),
		'FOL-JRN-001' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => '',
			'rating_display'  => '4.8 (126)',
			'short'           => 'A quiet place for quotes, lists and the thoughts a chapter leaves behind.',
			'image'           => 'still-life-desk.jpg',
			'hover'           => 'cat-annotate.jpg',
			'benefits'        => array(
				array( 'Cream paper', 'Soft pages that take pencil and fine ink.' ),
				array( 'Unlined enough', 'Room for quotes, lists and the odd sketch.', ),
				array( 'A year of reading', 'Sized for a bag, not a desk drawer.' ),
			),
			'story_h2'        => 'Keep the sentences that stay with you.',
			'story'           => 'A reading journal is less a diary than a pocket library of the lines you do not want to lose.',
			'dimensions'      => '21 × 13 cm.',
			'faq'             => array(
				'Will my book fit?'              => 'The journal is A5-ish — it sits beside, not around, your book.',
				'Is it padded?'                  => 'A linen-wrap cover, lightly structured.',
				'Can I wash it?'                 => 'Spot-clean the cover. Keep pages dry.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'Journals ship blank. Pair with the embosser to mark the flyleaf.',
			),
		),
		'FOL-STD-001' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => '',
			'rating_display'  => '4.8 (126)',
			'short'           => 'Hands-free pages for tea, notes and long weekend sessions.',
			'image'           => 'cat-comfort.jpg',
			'hover'           => 'cat-comfort.jpg',
			'benefits'        => array(
				array( 'Hands free', 'The page stays open while you pour tea or take a note.' ),
				array( 'Kind to spines', 'A gentle angle — not a forced crack.' ),
				array( 'Weekend scale', 'Holds up to a 28 cm hardcover.' ),
			),
			'story_h2'        => 'Let the book stand. You sit.',
			'story'           => 'A stand turns a long session into something the body can keep: tea in one hand, nothing in the other.',
			'dimensions'      => 'Holds up to 28 cm hardcover.',
			'faq'             => array(
				'Will my book fit?'              => 'Most hardcovers up to 28 cm tall. Very heavy art books may need a table.',
				'Is it padded?'                  => 'Felt pads under the rest protect the cover.',
				'Can I wash it?'                 => 'Wipe wood with a dry or barely damp cloth.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'The stand is not personalized.',
			),
		),
		'FOL-GFT-SET' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => 'Gift Pick',
			'rating_display'  => '4.8 (126)',
			'short'           => 'A ready-to-wrap trio for the person who always says just one more chapter.',
			'image'           => 'gift-chapter.jpg',
			'hover'           => 'cat-gifts.jpg',
			'benefits'        => array(
				array( 'Ready to wrap', 'A complete small stack — no last-minute pairing.' ),
				array( 'Actually used', 'Bookmark, sleeve and a little extra they will reach for.' ),
				array( 'For collectors', 'Chosen for people whose shelves are already full.' ),
			),
			'story_h2'        => 'For the person who always says just one more chapter.',
			'story'           => 'A gift that does not add another novel they have not started — only better ways to stay with the ones they love.',
			'dimensions'      => 'Gift-ready box, ~28 × 22 cm.',
			'faq'             => array(
				'Will my book fit?'              => 'The bundle is accessories, not a book. Sleeve size defaults to paperback.',
				'Is it padded?'                  => 'The sleeve inside is padded; the outer wrap is cream linen.',
				'Can I wash it?'                 => 'See individual pieces. The wrap is decorative.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'Add a note at checkout. For a named mark, add the embosser.',
			),
		),
		'FOL-BND-COZY' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => '',
			'rating_display'  => '4.8 (126)',
			'short'           => 'Book Sleeve · Magnetic Bookmark · Clip-on Reading Light.',
			'image'           => 'hero-nook.jpg',
			'hover'           => 'cat-lights.jpg',
			'benefits'        => array(
				array( 'A full evening', 'Light, sleeve and a place held — the cozy night kit.' ),
				array( 'Save 15%', 'The set is $89 instead of $108.' ),
				array( 'One add to bag', 'No hunting across the shop.' ),
			),
			'story_h2'        => 'Build a cozy night in.',
			'story'           => 'The three things that turn a sofa into a reading nook.',
			'dimensions'      => 'See individual pieces.',
			'includes'        => array( 'FOL-SLV-VIN', 'FOL-BMK-MAG', 'FOL-LGT-001' ),
			'faq'             => array(
				'Will my book fit?'              => 'Sleeve defaults to paperback. Other sizes available separately.',
				'Is it padded?'                  => 'The sleeve is padded.',
				'Can I wash it?'                 => 'See each piece.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'This set is not personalized.',
			),
		),
		'FOL-BND-ANNO' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => '',
			'rating_display'  => '4.8 (126)',
			'short'           => 'Annotation Kit · Reading Journal · Magnetic Bookmark.',
			'image'           => 'still-life-desk.jpg',
			'hover'           => 'cat-annotate.jpg',
			'benefits'        => array(
				array( 'For margin notes', 'Kit, journal and a bookmark that stays put.' ),
				array( 'Save 15%', 'The set is $48 instead of $56.' ),
				array( 'Study-ready', 'A weekend of close reading, packed.' ),
			),
			'story_h2'        => 'For the annotators.',
			'story'           => 'Everything you reach for when a book asks to be written in.',
			'dimensions'      => 'See individual pieces.',
			'includes'        => array( 'FOL-ANN-KIT', 'FOL-JRN-001', 'FOL-BMK-MAG' ),
			'faq'             => array(
				'Will my book fit?'              => 'These are tools for any book you annotate.',
				'Is it padded?'                  => 'The journal has a structured cover.',
				'Can I wash it?'                 => 'Keep paper goods dry.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => 'This set is not personalized.',
			),
		),
		'FOL-BND-LIB' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => '',
			'rating_display'  => '4.8 (126)',
			'short'           => 'Personalized Book Embosser · Vintage Book Sleeve · Magnetic Bookmark.',
			'image'           => 'embosser-hero.jpg',
			'hover'           => 'embosser-press.jpg',
			'benefits'        => array(
				array( 'A library, marked', 'Embosser, sleeve and bookmark — yours.' ),
				array( 'Save 15%', 'The set is $82 instead of $96.' ),
				array( 'Gift-ready', 'For someone building a shelf they care about.' ),
			),
			'story_h2'        => 'Make the library feel like yours.',
			'story'           => 'A name in the page, a sleeve on the go, a place held between chapters.',
			'dimensions'      => 'See individual pieces.',
			'includes'        => array( 'FOL-EMB-001', 'FOL-SLV-VIN', 'FOL-BMK-MAG' ),
			'how_it_works'    => array(
				array( 'Personalize it', 'Add your name or custom text.' ),
				array( 'Place the page', 'Insert a book page into the embosser.' ),
				array( 'Press', 'Create your permanent raised mark.' ),
			),
			'faq'             => array(
				'Will my book fit?'              => 'Sleeve defaults to paperback.',
				'Is it padded?'                  => 'The sleeve is padded.',
				'Can I wash it?'                 => 'See each piece.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => $personal,
			),
		),
		'FOL-BND-ULT' => array(
			'eyebrow'         => 'FOLIORA',
			'badge'           => '',
			'rating_display'  => '4.8 (126)',
			'short'           => 'Embosser · Book Sleeve · Book Light · Bookmark · Annotation Kit.',
			'image'           => 'ritual-nook.jpg',
			'hover'           => 'hero-nook.jpg',
			'benefits'        => array(
				array( 'The full ritual', 'Five pieces that cover evening, travel and notes.' ),
				array( 'Save 20%', 'The set is $96 instead of $120.' ),
				array( 'One bag', 'Everything we would pack for a long reading month.' ),
			),
			'story_h2'        => 'The reading ritual, complete.',
			'story'           => 'For the person who already knows they will stay up too late with a book — and would like that hour to feel considered.',
			'dimensions'      => 'See individual pieces.',
			'includes'        => array( 'FOL-EMB-001', 'FOL-SLV-VIN', 'FOL-LGT-001', 'FOL-BMK-MAG', 'FOL-ANN-KIT' ),
			'how_it_works'    => array(
				array( 'Personalize it', 'Add your name or custom text.' ),
				array( 'Place the page', 'Insert a book page into the embosser.' ),
				array( 'Press', 'Create your permanent raised mark.' ),
			),
			'faq'             => array(
				'Will my book fit?'              => 'Sleeve defaults to paperback. Light clip opens to 2.5 cm.',
				'Is it padded?'                  => 'The sleeve is padded.',
				'Can I wash it?'                 => 'See each piece.',
				'How long does shipping take?'   => $shipping,
				'Can I return it?'               => $returns,
				'How does personalization work?' => $personal,
			),
		),
	);
}

/**
 * Copy for a product (parent SKU).
 *
 * @param string $sku SKU.
 * @return array<string, mixed>
 */
function foliora_product_copy( $sku ) {
	$map = foliora_product_copy_map();
	$key = foliora_parent_sku( $sku );
	if ( isset( $map[ $key ] ) ) {
		return $map[ $key ];
	}
	return array(
		'eyebrow'        => 'FOLIORA',
		'badge'          => '',
		'rating_display' => '4.8 (126)',
		'short'          => '',
		'image'          => 'hero-nook.jpg',
		'hover'          => 'ritual-nook.jpg',
		'benefits'       => array(),
		'story_h2'       => '',
		'story'          => '',
		'dimensions'     => '',
		'faq'            => array(
			'How long does shipping take?' => 'Most orders leave within 2–4 business days. Free shipping on $50+.',
			'Can I return it?'             => '30 days, unused and in original condition.',
		),
	);
}

/**
 * Copy from a WC product object.
 *
 * @param WC_Product $product Product.
 * @return array<string, mixed>
 */
function foliora_copy_for_product( $product ) {
	$sku = $product ? $product->get_sku() : '';
	if ( $product && $product->is_type( 'variation' ) ) {
		$parent = wc_get_product( $product->get_parent_id() );
		$sku    = $parent ? $parent->get_sku() : $sku;
	}
	$copy   = foliora_product_copy( $sku );
	$stored = $product ? $product->get_meta( '_foliora_eyebrow' ) : '';
	if ( $stored ) {
		$copy['eyebrow'] = $stored;
	}
	$badge = $product ? $product->get_meta( '_foliora_badge' ) : '';
	if ( $badge ) {
		$copy['badge'] = $badge;
	}
	$rating = $product ? $product->get_meta( '_foliora_rating_display' ) : '';
	if ( $rating ) {
		$copy['rating_display'] = $rating;
	}
	return $copy;
}

/**
 * Hardcoded homepage catalog (works before Woo).
 *
 * @return array<string, array<string, mixed>>
 */
function foliora_catalog_fallback() {
	$map   = foliora_product_copy_map();
	$price = array(
		'FOL-EMB-001'  => array( 42, 0 ),
		'FOL-SLV-VIN'  => array( 32, 0 ),
		'FOL-LGT-001'  => array( 22, 0 ),
		'FOL-ANN-KIT'  => array( 16, 0 ),
		'FOL-BMK-MAG'  => array( 8, 0 ),
		'FOL-JRN-001'  => array( 24, 0 ),
		'FOL-STD-001'  => array( 28, 0 ),
		'FOL-GFT-SET'  => array( 68, 0 ),
		'FOL-BND-COZY' => array( 108, 89 ),
		'FOL-BND-ANNO' => array( 56, 48 ),
		'FOL-BND-LIB'  => array( 96, 82 ),
		'FOL-BND-ULT'  => array( 120, 96 ),
	);
	$names = array(
		'FOL-EMB-001'  => 'Personalized Book Embosser',
		'FOL-SLV-VIN'  => 'Vintage Book Sleeve',
		'FOL-LGT-001'  => 'Clip-on Reading Light',
		'FOL-ANN-KIT'  => 'Annotation Kit',
		'FOL-BMK-MAG'  => 'Magnetic Bookmark',
		'FOL-JRN-001'  => 'Reading Journal',
		'FOL-STD-001'  => 'Book Stand',
		'FOL-GFT-SET'  => 'Gift Bundle',
		'FOL-BND-COZY' => 'Cozy Reader Set',
		'FOL-BND-ANNO' => 'Annotation Lover Set',
		'FOL-BND-LIB'  => 'Personal Library Set',
		'FOL-BND-ULT'  => 'Ultimate Reading Ritual',
	);

	$out = array();
	foreach ( $names as $sku => $name ) {
		$copy           = $map[ $sku ];
		$copy['sku']    = $sku;
		$copy['name']   = $name;
		$copy['regular'] = $price[ $sku ][0];
		$copy['sale']    = $price[ $sku ][1];
		$out[ $sku ]     = $copy;
	}
	return $out;
}

/**
 * Default sleeve swatches for homepage + PDP.
 *
 * @return array<string, string>
 */
function foliora_sleeve_swatches() {
	return array(
		'Burgundy' => 'sleeve-burgundy.jpg',
		'Blue'     => 'sleeve-blue.jpg',
		'Sage'     => 'sleeve-sage.jpg',
		'Brown'    => 'sleeve-brown.jpg',
	);
}
